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>
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
// Singleton guard — openclaw calls register() twice per process
|
|
let _registered = false;
|
|
|
|
export default function register(_api) {
|
|
if (_registered) return;
|
|
_registered = true;
|
|
|
|
const client = globalThis.__yonexusClient;
|
|
if (!client) {
|
|
console.error('[client-test] __yonexusClient not on globalThis — ensure Yonexus.Client loads first');
|
|
return;
|
|
}
|
|
|
|
console.log('[client-test] __yonexusClient available, keys:', Object.keys(client));
|
|
|
|
// Register test_pong rule
|
|
// Received format (plain rule message from server): test_pong::<content>
|
|
client.ruleRegistry.registerRule('test_pong', (raw) => {
|
|
const sep = raw.indexOf('::');
|
|
const content = raw.slice(sep + 2);
|
|
console.log(`[client-test] MATCH test_pong content="${content}"`);
|
|
});
|
|
|
|
// When authenticated, send one matching and one non-matching rule message to server
|
|
client.onAuthenticated.push(() => {
|
|
console.log('[client-test] Authenticated — sending test_ping + other_rule to server');
|
|
const s1 = client.sendRule('test_ping', 'hello-from-client');
|
|
const s2 = client.sendRule('other_rule', 'other-from-client');
|
|
console.log(`[client-test] sendRule results: test_ping=${s1} other_rule=${s2}`);
|
|
});
|
|
|
|
console.log('[client-test] registered test_pong rule and onAuthenticated callback');
|
|
}
|