Wire rule registry and authenticated callbacks into both client and server runtimes; expose __yonexusClient / __yonexusServer on globalThis for cross-plugin communication. Add Docker-based integration test with server-test-plugin (test_ping echo) and client-test-plugin (test_pong receiver), plus docker-compose setup. Fix transport race condition where a stale _connections entry caused promoteToAuthenticated to silently fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.7 KiB
JavaScript
40 lines
1.7 KiB
JavaScript
// Singleton guard — openclaw calls register() twice per process
|
|
let _registered = false;
|
|
|
|
export default function register(_api) {
|
|
if (_registered) return;
|
|
_registered = true;
|
|
|
|
const server = globalThis.__yonexusServer;
|
|
if (!server) {
|
|
console.error('[server-test] __yonexusServer not on globalThis — ensure Yonexus.Server loads first');
|
|
return;
|
|
}
|
|
|
|
console.log('[server-test] __yonexusServer available, keys:', Object.keys(server));
|
|
|
|
// Register test_ping rule
|
|
// Received format (rewritten by server): test_ping::<senderIdentifier>::<content>
|
|
server.ruleRegistry.registerRule('test_ping', (raw) => {
|
|
const firstSep = raw.indexOf('::');
|
|
const rest = raw.slice(firstSep + 2);
|
|
const secondSep = rest.indexOf('::');
|
|
const sender = rest.slice(0, secondSep);
|
|
const content = rest.slice(secondSep + 2);
|
|
console.log(`[server-test] MATCH test_ping from="${sender}" content="${content}"`);
|
|
// Echo back to sender via test_pong
|
|
const sent = server.sendRule(sender, 'test_pong', `echo-${content}`);
|
|
console.log(`[server-test] echo sent=${sent}`);
|
|
});
|
|
|
|
// When a client authenticates, send one matching and one non-matching rule message
|
|
server.onClientAuthenticated.push((identifier) => {
|
|
console.log(`[server-test] Client "${identifier}" authenticated — sending test_pong + other_rule`);
|
|
const s1 = server.sendRule(identifier, 'test_pong', 'welcome-from-server');
|
|
const s2 = server.sendRule(identifier, 'other_rule', 'other-from-server');
|
|
console.log(`[server-test] sendRule results: test_pong=${s1} other_rule=${s2}`);
|
|
});
|
|
|
|
console.log('[server-test] registered test_ping rule and onClientAuthenticated callback');
|
|
}
|