feat: add rule dispatch, cross-plugin API, and Docker integration test
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>
This commit is contained in:
33
tests/docker/client-test-plugin/index.mjs
Normal file
33
tests/docker/client-test-plugin/index.mjs
Normal file
@@ -0,0 +1,33 @@
|
||||
// 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');
|
||||
}
|
||||
13
tests/docker/client-test-plugin/openclaw.plugin.json
Normal file
13
tests/docker/client-test-plugin/openclaw.plugin.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"id": "yonexus-client-test",
|
||||
"name": "Yonexus Client Test Plugin",
|
||||
"version": "0.1.0",
|
||||
"description": "Test plugin for Yonexus.Client rule routing",
|
||||
"entry": "./index.mjs",
|
||||
"permissions": [],
|
||||
"configSchema": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user