* feat(#1944): pi extension — installable ExtensionAPI host-plugin with reachability proof The pi extension (pi/gsd.cjs) is a real, jiti-loadable ExtensionAPI module that registers /gsd (dispatches through the GSD command-routing hub) + gsd_invoke tool + tool_call event. Engine entry: in-process CJS require (Bun-compatible). The extension resolves the engine tree via walk-up (like the OpenCode plugin). tests/pi-extension-reachability.test.cjs proves the /gsd handler DISPATCHES through the hub (returns a JSON result) — the keystone-wired proof that the command is user-reachable, not just registered on a mock (#1944 AC). * docs(changeset): pi extension (#1965) * fix(#1944): add docs-exempt marker to changeset (no standalone docs file)
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* pi extension reachability test — ADR-1239 Phase D / #1944.
|
|
*
|
|
* Proves the pi extension is keystone-WIRED: the registered /gsd command
|
|
* handler dispatches through the GSD command-routing hub and returns a result
|
|
* (not just a registration on a mock). This is the "user can invoke X" proof.
|
|
*/
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const gsdPiExtension = require('../pi/gsd.cjs');
|
|
|
|
function mockPi() {
|
|
const recorded = { commands: {}, tools: {}, events: [] };
|
|
return {
|
|
registerCommand(name, def) { recorded.commands[name] = def; },
|
|
registerTool(def) { if (def && def.name) recorded.tools[def.name] = def; },
|
|
on(event) { recorded.events.push(event); },
|
|
_recorded: recorded,
|
|
};
|
|
}
|
|
|
|
test('the pi extension registers /gsd + gsd_invoke + tool_call via ExtensionAPI', () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
assert.ok(pi._recorded.commands['gsd'], 'registers /gsd command');
|
|
assert.ok(pi._recorded.tools['gsd_invoke'], 'registers gsd_invoke tool');
|
|
assert.ok(pi._recorded.events.includes('tool_call'), 'subscribes to tool_call');
|
|
});
|
|
|
|
test('REACHABILITY: the /gsd handler dispatches through the engine hub (keystone wired)', async () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
// Invoke the registered /gsd handler — it must dispatch through createHub
|
|
// and return a JSON result (not throw). This is the keystone-wired proof.
|
|
const result = await pi._recorded.commands['gsd'].execute({
|
|
family: 'query',
|
|
subcommand: 'help',
|
|
});
|
|
assert.equal(typeof result, 'string', '/gsd handler returns a string result');
|
|
const parsed = JSON.parse(result);
|
|
assert.ok(parsed !== null && typeof parsed === 'object',
|
|
'/gsd dispatch produced a result object (the engine was reached)');
|
|
});
|
|
|
|
test('REACHABILITY: the gsd_invoke tool dispatches through the engine hub', async () => {
|
|
const pi = mockPi();
|
|
gsdPiExtension(pi);
|
|
const result = await pi._recorded.tools['gsd_invoke'].execute();
|
|
assert.equal(typeof result, 'string');
|
|
JSON.parse(result); // must be valid JSON (engine was reached)
|
|
});
|
|
|
|
test('gsdPiExtension throws without pi ExtensionAPI (fail-closed)', () => {
|
|
assert.throws(() => gsdPiExtension(null), /ExtensionAPI is required/);
|
|
});
|