feat: add AI machine navigation gateway
This commit is contained in:
parent
525e0ab790
commit
931f78d72f
10 changed files with 639 additions and 10 deletions
|
|
@ -2,8 +2,8 @@
|
|||
const assert = require("node:assert/strict");
|
||||
const test = require("node:test");
|
||||
const {
|
||||
createServer, loadMap, loadNodeMap, loadSubjectRegistry, loadSubjectAliasMap,
|
||||
resolveSubjectId, search, searchAll,
|
||||
createServer, loadMap, loadNodeMap, loadSubjectRegistry, loadSubjectAliasMap, loadNavigationMap,
|
||||
resolveSubjectId, compileNavigation, search, searchAll,
|
||||
} = require("./server");
|
||||
|
||||
test("repository map exposes only the three current code-channel repositories", () => {
|
||||
|
|
@ -79,6 +79,29 @@ test("searching the old id returns the canonical subject", () => {
|
|||
assert.ok(subject.legacy_ids.includes("ICE-GL-ZY001"));
|
||||
});
|
||||
|
||||
test("machine navigator compiles an exact minimal Zhuyuan runtime bundle", () => {
|
||||
const compiled = compileNavigation(
|
||||
loadNavigationMap(),
|
||||
"ICE-GL-ZY001",
|
||||
"persona_restore",
|
||||
"context_compacted,protocol_drift,context_compacted",
|
||||
);
|
||||
assert.equal(compiled.status, 200);
|
||||
assert.equal(compiled.body.canonical_subject, "ICE-P-ZY001");
|
||||
assert.equal(compiled.body.redirected, true);
|
||||
assert.equal(compiled.body.runtime_entry.id, "ZY-TCS-BRAIN-RUNTIME-0001");
|
||||
assert.deepEqual(compiled.body.explicit_signals, ["context_compacted", "protocol_drift"]);
|
||||
assert.ok(compiled.body.always_load.some(item => item.id === "BS-TCS-SYSTEM-CONTROLLER-MAP-001"));
|
||||
assert.ok(compiled.body.triggered_load.some(item => item.id === "BS-TCS-PROTOCOL-EVENT-TRIGGER-MAP-001"));
|
||||
assert.equal(compiled.body.authority, "NONE_NAVIGATION_ONLY");
|
||||
assert.ok(compiled.body.always_load.length < loadNavigationMap().routes.length);
|
||||
});
|
||||
|
||||
test("machine navigator fails closed instead of guessing", () => {
|
||||
assert.equal(compileNavigation(loadNavigationMap(), "some-ai", "persona_restore").body.error, "unknown_subject_no_guess");
|
||||
assert.equal(compileNavigation(loadNavigationMap(), "ICE-P-ZY001", "please_guess").body.error, "unknown_intent_no_guess");
|
||||
});
|
||||
|
||||
test("public endpoints are read-only and expose CORS", async () => {
|
||||
const server = createServer();
|
||||
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve));
|
||||
|
|
@ -105,6 +128,18 @@ test("public endpoints are read-only and expose CORS", async () => {
|
|||
assert.equal(legacyResolution.subject.subject_kind, "persona_system");
|
||||
const canonicalResponse = await fetch(`${base}/v1/resolve?id=ICE-P-ZY001`);
|
||||
assert.equal((await canonicalResponse.json()).redirected, false);
|
||||
const brainResponse = await fetch(`${base}/v1/resolve?id=ZY-TCS-BRAIN-RUNTIME-0001`);
|
||||
assert.equal(brainResponse.status, 200);
|
||||
assert.equal((await brainResponse.json()).kind, "executable_persona_brain");
|
||||
const navigationResponse = await fetch(`${base}/v1/navigation`);
|
||||
assert.equal((await navigationResponse.json()).map_id, "AI-MACHINE-NAV-001");
|
||||
const navigateResponse = await fetch(`${base}/v1/navigate?subject=ICE-P-ZY001&intent=persona_restore&signals=context_compacted`);
|
||||
const bundle = await navigateResponse.json();
|
||||
assert.equal(navigateResponse.status, 200);
|
||||
assert.equal(bundle.status, "COMPILED_EXACT_NO_GUESS");
|
||||
assert.equal(bundle.runtime_entry.id, "ZY-TCS-BRAIN-RUNTIME-0001");
|
||||
assert.equal((await fetch(`${base}/v1/navigate?subject=unknown&intent=persona_restore`)).status, 404);
|
||||
assert.equal((await fetch(`${base}/v1/navigate?subject=ICE-P-ZY001&intent=guess`)).status, 404);
|
||||
const humanResponse = await fetch(`${base}/v1/resolve?id=${encodeURIComponent("ICE-GL∞")}`);
|
||||
const humanResolution = await humanResponse.json();
|
||||
assert.equal(humanResponse.status, 200);
|
||||
|
|
|
|||
Loading…
Reference in a new issue