ceulen 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +72 -0
- package/extensions/lib/registry.ts +16 -3
- package/extensions/modules/a2a/configPanel.ts +435 -0
- package/extensions/modules/a2a/index.ts +1117 -0
- package/extensions/modules/a2a/lib/activity.ts +173 -0
- package/extensions/modules/a2a/lib/client.ts +1061 -0
- package/extensions/modules/a2a/lib/config.ts +920 -0
- package/extensions/modules/a2a/lib/discovery.ts +158 -0
- package/extensions/modules/a2a/lib/gateway.ts +889 -0
- package/extensions/modules/a2a/lib/mdns.ts +233 -0
- package/extensions/modules/a2a/lib/outcome.ts +48 -0
- package/extensions/modules/a2a/lib/persistence.ts +123 -0
- package/extensions/modules/a2a/lib/protocol.ts +506 -0
- package/extensions/modules/a2a/lib/registry.ts +146 -0
- package/extensions/modules/a2a/lib/retry.ts +86 -0
- package/extensions/modules/a2a/lib/security.ts +394 -0
- package/extensions/modules/a2a/lib/server.ts +1436 -0
- package/extensions/modules/a2a/test/activity.test.ts +138 -0
- package/extensions/modules/a2a/test/bridge.test.ts +101 -0
- package/extensions/modules/a2a/test/broadcast-parse.test.ts +31 -0
- package/extensions/modules/a2a/test/chai.ts +101 -0
- package/extensions/modules/a2a/test/client.test.ts +856 -0
- package/extensions/modules/a2a/test/completion-guard.test.ts +73 -0
- package/extensions/modules/a2a/test/config.test.ts +1396 -0
- package/extensions/modules/a2a/test/configPanel.test.ts +393 -0
- package/extensions/modules/a2a/test/discovery.test.ts +144 -0
- package/extensions/modules/a2a/test/extension.test.ts +135 -0
- package/extensions/modules/a2a/test/gateway.test.ts +1449 -0
- package/extensions/modules/a2a/test/helpers.ts +39 -0
- package/extensions/modules/a2a/test/mdns.test.ts +131 -0
- package/extensions/modules/a2a/test/outcome.test.ts +61 -0
- package/extensions/modules/a2a/test/persistence.test.ts +92 -0
- package/extensions/modules/a2a/test/protocol.test.ts +217 -0
- package/extensions/modules/a2a/test/registry.test.ts +114 -0
- package/extensions/modules/a2a/test/retry.test.ts +136 -0
- package/extensions/modules/a2a/test/security.test.ts +281 -0
- package/extensions/modules/a2a/test/server.test.ts +1966 -0
- package/extensions/modules/a2a/test/tmp.ts +59 -0
- package/extensions/modules/a2a/test/vendor.test.ts +57 -0
- package/extensions/modules/a2a/types/bonjour-service.d.ts +22 -0
- package/extensions/modules/a2a/vendor/VENDORED.md +18 -0
- package/extensions/modules/a2a/vendor/package.json +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/LICENSE +23 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/index.js +57 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.d.ts +4 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/KeyValue.js +3 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.d.ts +13 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/bonjour.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.d.ts +41 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/browser.js +209 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.d.ts +9 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/dns-txt.js +42 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/mdns-server.js +119 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.d.ts +14 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/registry.js +142 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.d.ts +7 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service-types.js +53 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.d.ts +58 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/service.js +130 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.d.ts +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/dns-equal.js +13 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.d.ts +1 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/equal-txt.js +17 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.d.ts +4 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-service.js +22 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.d.ts +3 -0
- package/extensions/modules/a2a/vendor/vendored_deps/bonjour-service/dist/lib/utils/filter-txt.js +6 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/classes.js +23 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/index.js +1761 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/opcodes.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/optioncodes.js +59 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/rcodes.js +50 -0
- package/extensions/modules/a2a/vendor/vendored_deps/dns-packet/types.js +103 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/es6.js +73 -0
- package/extensions/modules/a2a/vendor/vendored_deps/fast-deep-equal/index.js +46 -0
- package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/ip-codec/index.cjs +250 -0
- package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/multicast-dns/index.js +205 -0
- package/extensions/modules/a2a/vendor/vendored_deps/thunky/LICENSE +21 -0
- package/extensions/modules/a2a/vendor/vendored_deps/thunky/index.js +55 -0
- package/extensions/modules/composer/test/module.test.ts +2 -2
- package/extensions/modules/config/index.ts +3 -0
- package/extensions/modules/config/test/renderTools.test.ts +1 -1
- package/extensions/modules/gh/configPanel.ts +82 -0
- package/extensions/modules/gh/index.ts +86 -0
- package/extensions/modules/gh/lib/gh-cli.ts +337 -0
- package/extensions/modules/gh/lib/ops.ts +771 -0
- package/extensions/modules/gh/test/gh.test.ts +280 -0
- package/extensions/modules/plan/lib/plan-tools.ts +8 -0
- package/extensions/modules/repair/index.ts +138 -0
- package/extensions/modules/repair/lib/guards.ts +1 -1
- package/extensions/modules/repair/lib/read-selector.ts +242 -0
- package/extensions/modules/repair/test/read-selector.test.ts +198 -0
- package/extensions/modules/steering/configPanel.ts +8 -0
- package/extensions/modules/steering/index.ts +6 -0
- package/extensions/modules/steering/lib/settings.ts +6 -2
- package/extensions/modules/steering/lib/think.ts +66 -0
- package/extensions/modules/steering/test/harness.ts +5 -0
- package/extensions/modules/steering/test/settings.test.ts +2 -0
- package/extensions/modules/steering/test/think.test.ts +77 -0
- package/extensions/modules/todo/configPanel.ts +55 -0
- package/extensions/modules/todo/index.ts +46 -13
- package/extensions/modules/todo/lib/render.ts +271 -0
- package/extensions/modules/todo/lib/settings.ts +73 -0
- package/extensions/modules/todo/test/todo.test.ts +276 -0
- package/extensions/modules/web/index.ts +37 -1
- package/extensions/modules/web/lib/a11y.ts +252 -0
- package/extensions/modules/web/test/a11y.test.ts +218 -0
- package/extensions/modules/web/test/extension.test.ts +2 -2
- package/extensions/modules/web/test/hook.test.ts +2 -2
- package/extensions/modules/web/vendor/axe/LICENSE +362 -0
- package/extensions/modules/web/vendor/axe/LICENSE-3RD-PARTY.txt +66 -0
- package/extensions/modules/web/vendor/axe/README.md +19 -0
- package/extensions/modules/web/vendor/axe/axe.min.js +12 -0
- package/package.json +2 -2
- package/skills/a2a/SKILL.md +63 -0
- package/skills/web/SKILL.md +1 -0
|
@@ -0,0 +1,856 @@
|
|
|
1
|
+
import { assert } from "./chai.js";
|
|
2
|
+
|
|
3
|
+
import { DEFAULTS } from "./helpers";
|
|
4
|
+
import { makeTempDir } from "./tmp";
|
|
5
|
+
import {
|
|
6
|
+
a2aCall,
|
|
7
|
+
a2aDiscover,
|
|
8
|
+
a2aList,
|
|
9
|
+
a2aOrchestrate,
|
|
10
|
+
a2aStatus,
|
|
11
|
+
isPrivateHost,
|
|
12
|
+
metrics,
|
|
13
|
+
rpcUrl,
|
|
14
|
+
} from "../lib/client";
|
|
15
|
+
import { buildAgentCard, STATE_COMPLETED, STATE_WORKING } from "../lib/protocol";
|
|
16
|
+
import { setGatewayRegistrationName, setGatewayPeers, gatewayKeyFromUrl } from "../lib/config";
|
|
17
|
+
import type { DiscoveredPeer } from "../lib/discovery";
|
|
18
|
+
import { describe, it, before, after, beforeEach, afterEach } from "node:test";
|
|
19
|
+
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// fetch mock helpers
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
type FetchMock = (url: string, init?: any) => Promise<any>;
|
|
25
|
+
|
|
26
|
+
function mockFetch(opts: {
|
|
27
|
+
card?: any;
|
|
28
|
+
cardStatus?: number;
|
|
29
|
+
legacyCard?: any;
|
|
30
|
+
rpcResult?: any;
|
|
31
|
+
rpcError?: { code: number; message: string };
|
|
32
|
+
rpcStatus?: number;
|
|
33
|
+
}): FetchMock {
|
|
34
|
+
return async (url: string, init?: any) => {
|
|
35
|
+
const u = String(url);
|
|
36
|
+
const method = init?.method || "GET";
|
|
37
|
+
// Agent Card discovery
|
|
38
|
+
if (method === "GET" && u.includes("/.well-known/agent-card.json")) {
|
|
39
|
+
if (opts.cardStatus && opts.cardStatus !== 200) {
|
|
40
|
+
return makeResp({}, opts.cardStatus);
|
|
41
|
+
}
|
|
42
|
+
return makeResp(opts.card ?? null, 200);
|
|
43
|
+
}
|
|
44
|
+
if (method === "GET" && u.includes("/.well-known/agent.json")) {
|
|
45
|
+
return makeResp(opts.legacyCard ?? null, 200);
|
|
46
|
+
}
|
|
47
|
+
// JSON-RPC dispatch
|
|
48
|
+
if (method === "POST") {
|
|
49
|
+
if (opts.rpcError) {
|
|
50
|
+
return makeResp({ jsonrpc: "2.0", id: 1, error: opts.rpcError }, opts.rpcStatus ?? 200);
|
|
51
|
+
}
|
|
52
|
+
return makeResp({ jsonrpc: "2.0", id: 1, result: opts.rpcResult }, opts.rpcStatus ?? 200);
|
|
53
|
+
}
|
|
54
|
+
return makeResp({}, 404);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function makeResp(body: any, status: number): any {
|
|
59
|
+
return {
|
|
60
|
+
ok: status >= 200 && status < 300,
|
|
61
|
+
status,
|
|
62
|
+
json: async () => body,
|
|
63
|
+
text: async () => (typeof body === "string" ? body : JSON.stringify(body)),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function tmpDir(): string {
|
|
68
|
+
return makeTempDir("pi-a2a-client-");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
describe("client", () => {
|
|
72
|
+
let originalFetch: typeof globalThis.fetch;
|
|
73
|
+
let piDir: string;
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
originalFetch = globalThis.fetch;
|
|
77
|
+
piDir = tmpDir();
|
|
78
|
+
metrics.reset();
|
|
79
|
+
});
|
|
80
|
+
afterEach(() => {
|
|
81
|
+
globalThis.fetch = originalFetch as any;
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("rpcUrl", () => {
|
|
85
|
+
it("prefers the card's JSONRPC interface url", () => {
|
|
86
|
+
const card = buildAgentCard({ name: "x", url: "http://h/" });
|
|
87
|
+
card.supportedInterfaces[0]!.url = "http://h/rpc";
|
|
88
|
+
assert.equal(rpcUrl("http://h/", card), "http://h/rpc");
|
|
89
|
+
});
|
|
90
|
+
it("falls back to the card top-level url", () => {
|
|
91
|
+
const card = buildAgentCard({ name: "x", url: "http://h/" });
|
|
92
|
+
assert.equal(rpcUrl("http://h/", card), "http://h/");
|
|
93
|
+
});
|
|
94
|
+
it("falls back to the base url with no card", () => {
|
|
95
|
+
assert.equal(rpcUrl("http://h/", null), "http://h");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("a2aDiscover", () => {
|
|
100
|
+
it("summarizes a v1.0 card", async () => {
|
|
101
|
+
const card = buildAgentCard({
|
|
102
|
+
name: "researcher",
|
|
103
|
+
url: "http://localhost:9900/",
|
|
104
|
+
description: "a research agent",
|
|
105
|
+
skills: [{ id: "s", name: "research", description: "web research" }],
|
|
106
|
+
});
|
|
107
|
+
globalThis.fetch = mockFetch({ card }) as any;
|
|
108
|
+
const cfg = DEFAULTS();
|
|
109
|
+
const out = await a2aDiscover({ cfg, url: "http://localhost:9900" });
|
|
110
|
+
assert.include(out, "Agent: researcher");
|
|
111
|
+
assert.include(out, "research");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("falls back to legacy agent.json on 404", async () => {
|
|
115
|
+
const legacyCard = buildAgentCard({ name: "legacy", url: "http://l/" });
|
|
116
|
+
globalThis.fetch = mockFetch({ cardStatus: 404, legacyCard }) as any;
|
|
117
|
+
const out = await a2aDiscover({ cfg: DEFAULTS(), url: "http://l" });
|
|
118
|
+
assert.include(out, "Agent: legacy");
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("reports discovery failure on connection error", async () => {
|
|
122
|
+
globalThis.fetch = (async () => {
|
|
123
|
+
throw new Error("ECONNREFUSED");
|
|
124
|
+
}) as any;
|
|
125
|
+
const out = await a2aDiscover({ cfg: DEFAULTS(), url: "http://nope" });
|
|
126
|
+
assert.include(out, "Error");
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("a2aCall", () => {
|
|
131
|
+
it("attaches X-Gateway-Caller on gateway-proxied calls", async () => {
|
|
132
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
133
|
+
let seenHeaders: Record<string, string> = {};
|
|
134
|
+
globalThis.fetch = (async (url: string, init?: any) => {
|
|
135
|
+
seenHeaders = { ...(init?.headers || {}) };
|
|
136
|
+
return {
|
|
137
|
+
ok: true,
|
|
138
|
+
status: 200,
|
|
139
|
+
text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }),
|
|
140
|
+
};
|
|
141
|
+
}) as any;
|
|
142
|
+
const cfg = DEFAULTS();
|
|
143
|
+
cfg.selfIdentity = "pi-s2-9912";
|
|
144
|
+
cfg.peers.bob = { url: "http://127.0.0.1:9920/peer/bob/", auth: { type: "bearer", token: "gw-token" }, timeout: 5000, capabilities: [], viaGateway: true };
|
|
145
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
146
|
+
assert.include(out, "ok");
|
|
147
|
+
assert.equal(seenHeaders["X-Gateway-Caller"], "pi-s2-9912");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("omits X-Gateway-Caller for non-gateway peers", async () => {
|
|
151
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
152
|
+
let seenHeaders: Record<string, string> = {};
|
|
153
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
154
|
+
seenHeaders = { ...(init?.headers || {}) };
|
|
155
|
+
return {
|
|
156
|
+
ok: true,
|
|
157
|
+
status: 200,
|
|
158
|
+
text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }),
|
|
159
|
+
};
|
|
160
|
+
}) as any;
|
|
161
|
+
const cfg = DEFAULTS();
|
|
162
|
+
cfg.selfIdentity = "pi-s2-9912";
|
|
163
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
164
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
165
|
+
assert.isUndefined(seenHeaders["X-Gateway-Caller"]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("sends the asserted X-A2A-Identity header from selfIdentity", async () => {
|
|
169
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
170
|
+
let seenHeaders: Record<string, string> = {};
|
|
171
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
172
|
+
seenHeaders = { ...(init?.headers || {}) };
|
|
173
|
+
return {
|
|
174
|
+
ok: true,
|
|
175
|
+
status: 200,
|
|
176
|
+
text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }),
|
|
177
|
+
};
|
|
178
|
+
}) as any;
|
|
179
|
+
const cfg = DEFAULTS();
|
|
180
|
+
cfg.selfIdentity = "pi-kimchi";
|
|
181
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
182
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
183
|
+
assert.include(out, "ok");
|
|
184
|
+
assert.equal(seenHeaders["X-A2A-Identity"], "pi-kimchi");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("stamps pi/session and pi/self on the outbound message metadata (fleet task #238)", async () => {
|
|
188
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
189
|
+
let body: any = null;
|
|
190
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
191
|
+
if (init?.body) body = JSON.parse(init.body);
|
|
192
|
+
return { ok: true, status: 200, text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }) };
|
|
193
|
+
}) as any;
|
|
194
|
+
const cfg = DEFAULTS();
|
|
195
|
+
cfg.selfIdentity = "pi-kimchi";
|
|
196
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
197
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi", sessionId: "sess-123" });
|
|
198
|
+
assert.deepEqual(body.params.message.metadata, { "pi/session": "sess-123", "pi/self": "pi-kimchi" });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it("omits message metadata when there is no session or identity", async () => {
|
|
202
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
203
|
+
let body: any = null;
|
|
204
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
205
|
+
if (init?.body) body = JSON.parse(init.body);
|
|
206
|
+
return { ok: true, status: 200, text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }) };
|
|
207
|
+
}) as any;
|
|
208
|
+
const cfg = DEFAULTS();
|
|
209
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
210
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
211
|
+
assert.isUndefined(body.params.message.metadata);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it("falls back to server.agentName for X-A2A-Identity", async () => {
|
|
215
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
216
|
+
let seenHeaders: Record<string, string> = {};
|
|
217
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
218
|
+
seenHeaders = { ...(init?.headers || {}) };
|
|
219
|
+
return {
|
|
220
|
+
ok: true,
|
|
221
|
+
status: 200,
|
|
222
|
+
text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }),
|
|
223
|
+
};
|
|
224
|
+
}) as any;
|
|
225
|
+
const cfg = DEFAULTS();
|
|
226
|
+
cfg.server.agentName = "pi-bingsu"; // selfIdentity unset
|
|
227
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
228
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
229
|
+
assert.equal(seenHeaders["X-A2A-Identity"], "pi-bingsu");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("omits X-A2A-Identity when no identity is configured", async () => {
|
|
233
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
234
|
+
let seenHeaders: Record<string, string> = {};
|
|
235
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
236
|
+
seenHeaders = { ...(init?.headers || {}) };
|
|
237
|
+
return {
|
|
238
|
+
ok: true,
|
|
239
|
+
status: 200,
|
|
240
|
+
text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }),
|
|
241
|
+
};
|
|
242
|
+
}) as any;
|
|
243
|
+
const cfg = DEFAULTS(); // selfIdentity and server.agentName both ""
|
|
244
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
245
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
246
|
+
assert.isUndefined(seenHeaders["X-A2A-Identity"]);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("falls back to the runtime gateway registration name for X-Gateway-Caller", async () => {
|
|
250
|
+
const result = { task: { id: "t", contextId: "c", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "ok" }] }] } };
|
|
251
|
+
let seenHeaders: Record<string, string> = {};
|
|
252
|
+
globalThis.fetch = (async (url: string, init?: any) => {
|
|
253
|
+
seenHeaders = { ...(init?.headers || {}) };
|
|
254
|
+
return {
|
|
255
|
+
ok: true,
|
|
256
|
+
status: 200,
|
|
257
|
+
text: async () => JSON.stringify({ jsonrpc: "2.0", id: 1, result }),
|
|
258
|
+
};
|
|
259
|
+
}) as any;
|
|
260
|
+
const cfg = DEFAULTS();
|
|
261
|
+
cfg.selfIdentity = ""; // no operator-pinned identity
|
|
262
|
+
cfg.discovery.gateway = { enabled: true, url: "http://127.0.0.1:9920", token: "gw-token" };
|
|
263
|
+
cfg.peers.bob = { url: "http://127.0.0.1:9920/peer/bob/", auth: { type: "bearer", token: "gw-token" }, timeout: 5000, capabilities: [], viaGateway: true };
|
|
264
|
+
// Single configured gateway → its registration name (derived key) is the
|
|
265
|
+
// fallback for unlabeled viaGateway peers.
|
|
266
|
+
setGatewayRegistrationName("pi-9910", gatewayKeyFromUrl("http://127.0.0.1:9920"));
|
|
267
|
+
try {
|
|
268
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
269
|
+
assert.include(out, "ok");
|
|
270
|
+
assert.equal(seenHeaders["X-Gateway-Caller"], "pi-9910");
|
|
271
|
+
} finally {
|
|
272
|
+
setGatewayRegistrationName(null, gatewayKeyFromUrl("http://127.0.0.1:9920"));
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("sends a task and returns the reply (wrapped {task} result)", async () => {
|
|
277
|
+
const result = {
|
|
278
|
+
task: {
|
|
279
|
+
id: "t1",
|
|
280
|
+
contextId: "ctx-1",
|
|
281
|
+
status: { state: STATE_COMPLETED },
|
|
282
|
+
artifacts: [{ parts: [{ text: "the answer" }] }],
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
globalThis.fetch = mockFetch({ rpcResult: result }) as any;
|
|
286
|
+
const cfg = DEFAULTS();
|
|
287
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
288
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
289
|
+
assert.include(out, "context ctx-1");
|
|
290
|
+
assert.include(out, "completed");
|
|
291
|
+
assert.include(out, "the answer");
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("extracts from a bare message result", async () => {
|
|
295
|
+
const result = {
|
|
296
|
+
message: { role: "ROLE_AGENT", parts: [{ text: "direct reply" }] },
|
|
297
|
+
};
|
|
298
|
+
globalThis.fetch = mockFetch({ rpcResult: result }) as any;
|
|
299
|
+
const cfg = DEFAULTS();
|
|
300
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
301
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
302
|
+
assert.include(out, "direct reply");
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
it("surfaces INPUT_REQUIRED with a context hint", async () => {
|
|
306
|
+
const result = {
|
|
307
|
+
task: {
|
|
308
|
+
id: "t2",
|
|
309
|
+
contextId: "ctx-2",
|
|
310
|
+
status: { state: "TASK_STATE_INPUT_REQUIRED", message: { parts: [{ text: "need more" }] } },
|
|
311
|
+
},
|
|
312
|
+
};
|
|
313
|
+
globalThis.fetch = mockFetch({ rpcResult: result }) as any;
|
|
314
|
+
const cfg = DEFAULTS();
|
|
315
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
316
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
317
|
+
assert.include(out, "input-required");
|
|
318
|
+
assert.include(out, "context_id 'ctx-2'");
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("returns a clear error for an unknown agent", async () => {
|
|
322
|
+
const out = await a2aCall({ cfg: DEFAULTS(), piDir, agent: "ghost", message: "hi" });
|
|
323
|
+
assert.include(out, "unknown agent 'ghost'");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("calls a discovered peer by name", async () => {
|
|
327
|
+
let postUrl = "";
|
|
328
|
+
globalThis.fetch = (async (url: string, init?: any) => {
|
|
329
|
+
if (init?.method === "POST") postUrl = String(url);
|
|
330
|
+
return makeResp(
|
|
331
|
+
{ jsonrpc: "2.0", id: 1, result: { message: { parts: [{ text: "pong" }] } } },
|
|
332
|
+
200,
|
|
333
|
+
);
|
|
334
|
+
}) as any;
|
|
335
|
+
const discoveredPeers: DiscoveredPeer[] = [
|
|
336
|
+
{ name: "pi-solo", url: "http://127.0.0.1:9912", source: "local", alive: true },
|
|
337
|
+
];
|
|
338
|
+
const out = await a2aCall({ cfg: DEFAULTS(), piDir, agent: "pi-solo", message: "hi", discoveredPeers });
|
|
339
|
+
assert.include(out, "pong");
|
|
340
|
+
assert.include(postUrl, "127.0.0.1:9912");
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
it("errors with candidate URLs for an ambiguous discovered name", async () => {
|
|
344
|
+
const discoveredPeers: DiscoveredPeer[] = [
|
|
345
|
+
{ name: "pi-s2", url: "http://127.0.0.1:9912", source: "local", alive: true },
|
|
346
|
+
{ name: "pi-s2", url: "http://127.0.0.1:9913", source: "local", alive: true },
|
|
347
|
+
];
|
|
348
|
+
const out = await a2aCall({ cfg: DEFAULTS(), piDir, agent: "pi-s2", message: "hi", discoveredPeers });
|
|
349
|
+
assert.include(out, "share the name 'pi-s2'");
|
|
350
|
+
assert.include(out, "9912");
|
|
351
|
+
assert.include(out, "9913");
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it("does not attach a bearer token to a discovered peer outside the known set", async () => {
|
|
355
|
+
let auth = "";
|
|
356
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
357
|
+
if (init?.method === "POST") auth = String(init?.headers?.Authorization ?? "");
|
|
358
|
+
return makeResp({ jsonrpc: "2.0", id: 1, result: { message: { parts: [{ text: "pong" }] } } }, 200);
|
|
359
|
+
}) as any;
|
|
360
|
+
const cfg = DEFAULTS();
|
|
361
|
+
cfg.server = { ...cfg.server, peerTokens: { anon: "secret-token" } } as any;
|
|
362
|
+
const discoveredPeers: DiscoveredPeer[] = [
|
|
363
|
+
// loopback URL but NOT in the local registry (unknown → no credential)
|
|
364
|
+
{ name: "rogue", url: "http://127.0.0.1:9999", source: "local", alive: true },
|
|
365
|
+
];
|
|
366
|
+
await a2aCall({ cfg, piDir, agent: "rogue", message: "hi", discoveredPeers });
|
|
367
|
+
assert.notInclude(auth, "secret-token");
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("surfaces peer auth rejection (401)", async () => {
|
|
371
|
+
globalThis.fetch = mockFetch({ rpcStatus: 401 }) as any;
|
|
372
|
+
const cfg = DEFAULTS();
|
|
373
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
374
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
375
|
+
assert.include(out, "rejected auth");
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it("distinguishes reply timeout from connection failure", async () => {
|
|
379
|
+
globalThis.fetch = ((_url: string, init?: any) =>
|
|
380
|
+
new Promise((_resolve, reject) => {
|
|
381
|
+
init?.signal?.addEventListener("abort", () => reject(init.signal.reason), { once: true });
|
|
382
|
+
})) as any;
|
|
383
|
+
const cfg = DEFAULTS();
|
|
384
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5, capabilities: [] };
|
|
385
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
386
|
+
assert.include(out, "reply timed out after 5ms");
|
|
387
|
+
assert.include(out, "delivery status unknown");
|
|
388
|
+
assert.include(out, "requestId=");
|
|
389
|
+
assert.notInclude(out, "This operation was aborted");
|
|
390
|
+
|
|
391
|
+
globalThis.fetch = (async () => {
|
|
392
|
+
throw new TypeError("fetch failed");
|
|
393
|
+
}) as any;
|
|
394
|
+
const connectionOut = await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
395
|
+
assert.include(connectionOut, "connection failed");
|
|
396
|
+
assert.notInclude(connectionOut, "delivery status unknown");
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
it("redacts credentials before sending", async () => {
|
|
400
|
+
let capturedBody = "";
|
|
401
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
402
|
+
capturedBody = init?.body ?? "";
|
|
403
|
+
return makeResp(
|
|
404
|
+
{ jsonrpc: "2.0", id: 1, result: { message: { parts: [{ text: "ok" }] } } },
|
|
405
|
+
200,
|
|
406
|
+
);
|
|
407
|
+
}) as any;
|
|
408
|
+
const cfg = DEFAULTS();
|
|
409
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
410
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "my key is sk-1234567890abcdefXX" });
|
|
411
|
+
assert.notInclude(capturedBody, "sk-1234567890abcdefXX");
|
|
412
|
+
assert.include(capturedBody, "sk-[redacted]");
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
describe("non-blocking dispatch (asyncDispatch + a2a_status)", () => {
|
|
417
|
+
const workingTask = {
|
|
418
|
+
id: "task-9",
|
|
419
|
+
contextId: "ctx-async",
|
|
420
|
+
status: { state: STATE_WORKING },
|
|
421
|
+
};
|
|
422
|
+
const completedTask = {
|
|
423
|
+
id: "task-9",
|
|
424
|
+
contextId: "ctx-async",
|
|
425
|
+
status: { state: STATE_COMPLETED },
|
|
426
|
+
artifacts: [{ parts: [{ text: "late result" }] }],
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
/** Sequential POST-result mock: each POST returns the next entry (last
|
|
430
|
+
* one repeats). GETs (card fetch) 404 — non-fatal, rpcUrl falls back to
|
|
431
|
+
* the base URL. */
|
|
432
|
+
function seqMock(results: any[]): { fetch: FetchMock; posts: () => number } {
|
|
433
|
+
let i = 0;
|
|
434
|
+
let n = 0;
|
|
435
|
+
const fetch = async (url: string, init?: any) => {
|
|
436
|
+
if (init?.method === "POST") {
|
|
437
|
+
n += 1;
|
|
438
|
+
const result = results[Math.min(i++, results.length - 1)];
|
|
439
|
+
return makeResp({ jsonrpc: "2.0", id: 1, result }, 200);
|
|
440
|
+
}
|
|
441
|
+
return makeResp(null, 404);
|
|
442
|
+
};
|
|
443
|
+
return { fetch, posts: () => n };
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
it("sends configuration.returnImmediately only when asyncDispatch is set", async () => {
|
|
447
|
+
const bodies: any[] = [];
|
|
448
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
449
|
+
if (init?.method === "POST") bodies.push(JSON.parse(init.body));
|
|
450
|
+
return makeResp({ jsonrpc: "2.0", id: 1, result: { task: workingTask } }, 200);
|
|
451
|
+
}) as any;
|
|
452
|
+
const cfg = DEFAULTS();
|
|
453
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
454
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi", asyncDispatch: true });
|
|
455
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi" });
|
|
456
|
+
assert.equal(bodies[0]!.params.configuration?.returnImmediately, true, "asyncDispatch must set the configuration");
|
|
457
|
+
assert.isUndefined(bodies[1]!.params.configuration, "a blocking call must not send any configuration");
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
it("formats the detached ack with the poll hint", async () => {
|
|
461
|
+
globalThis.fetch = mockFetch({ rpcResult: { task: workingTask } }) as any;
|
|
462
|
+
const cfg = DEFAULTS();
|
|
463
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
464
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi", asyncDispatch: true });
|
|
465
|
+
assert.include(out, "detached");
|
|
466
|
+
assert.include(out, "task-9");
|
|
467
|
+
assert.include(out, "non-blocking");
|
|
468
|
+
assert.include(out, 'a2a_status(agent: "bob", task_id: "task-9")');
|
|
469
|
+
assert.notInclude(out, "late result");
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("falls through to normal formatting when the task finished before the ack", async () => {
|
|
473
|
+
// A fast peer completes before the ack is serialized — the ack carries
|
|
474
|
+
// the terminal state, so the caller gets the result inline, no poll hint.
|
|
475
|
+
globalThis.fetch = mockFetch({ rpcResult: { task: completedTask } }) as any;
|
|
476
|
+
const cfg = DEFAULTS();
|
|
477
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
478
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "hi", asyncDispatch: true });
|
|
479
|
+
assert.include(out, "completed");
|
|
480
|
+
assert.include(out, "late result");
|
|
481
|
+
assert.notInclude(out, "detached");
|
|
482
|
+
assert.notInclude(out, "a2a_status(");
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
it("persists the dispatch ack marker under the conversation context", async () => {
|
|
486
|
+
const { loadConversation } = await import("../lib/persistence");
|
|
487
|
+
globalThis.fetch = mockFetch({ rpcResult: { task: workingTask } }) as any;
|
|
488
|
+
const cfg = DEFAULTS();
|
|
489
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
490
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi", asyncDispatch: true });
|
|
491
|
+
// Both sides land under the PEER's context id so a2a_history works.
|
|
492
|
+
const msgs = loadConversation(piDir, "ctx-async");
|
|
493
|
+
assert.lengthOf(msgs, 2);
|
|
494
|
+
assert.equal(msgs[0]!.role, "user");
|
|
495
|
+
assert.equal(msgs[1]!.role, "agent");
|
|
496
|
+
assert.include(msgs[1]!.text, "dispatched non-blocking");
|
|
497
|
+
assert.include(msgs[1]!.text, "task-9");
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("a2a_status: single fetch without wait_seconds", async () => {
|
|
501
|
+
const m = seqMock([{ task: workingTask }]);
|
|
502
|
+
globalThis.fetch = m.fetch as any;
|
|
503
|
+
const cfg = DEFAULTS();
|
|
504
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
505
|
+
const out = await a2aStatus({ cfg, piDir, agent: "bob", taskId: "task-9" });
|
|
506
|
+
assert.equal(m.posts(), 1, "no wait_seconds → exactly one GetTask");
|
|
507
|
+
assert.include(out, "task-9");
|
|
508
|
+
assert.include(out, "working");
|
|
509
|
+
assert.include(out, "no text yet");
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
it("a2a_status: polls to terminal with wait_seconds", async () => {
|
|
513
|
+
const m = seqMock([{ task: workingTask }, { task: completedTask }]);
|
|
514
|
+
globalThis.fetch = m.fetch as any;
|
|
515
|
+
const cfg = DEFAULTS();
|
|
516
|
+
cfg.timeouts.async = 250; // min poll interval for a fast test
|
|
517
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
518
|
+
const out = await a2aStatus({ cfg, piDir, agent: "bob", taskId: "task-9", waitSeconds: 5 });
|
|
519
|
+
assert.equal(m.posts(), 2, "WORKING then COMPLETED → exactly two GetTask polls");
|
|
520
|
+
assert.include(out, "completed");
|
|
521
|
+
assert.include(out, "late result");
|
|
522
|
+
});
|
|
523
|
+
|
|
524
|
+
it("a2a_status: expires with a clear message at the deadline", async () => {
|
|
525
|
+
const m = seqMock([{ task: workingTask }]);
|
|
526
|
+
globalThis.fetch = m.fetch as any;
|
|
527
|
+
const cfg = DEFAULTS();
|
|
528
|
+
cfg.timeouts.async = 250;
|
|
529
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
530
|
+
const out = await a2aStatus({ cfg, piDir, agent: "bob", taskId: "task-9", waitSeconds: 0.3 });
|
|
531
|
+
assert.include(out, "Still non-terminal after 0.3s of polling");
|
|
532
|
+
assert.include(out, "call a2a_status again later");
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("a2a_status: non-positive wait_seconds is a single fetch (no nonsense deadline)", async () => {
|
|
536
|
+
const m = seqMock([{ task: workingTask }]);
|
|
537
|
+
globalThis.fetch = m.fetch as any;
|
|
538
|
+
const cfg = DEFAULTS();
|
|
539
|
+
cfg.timeouts.async = 250;
|
|
540
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
541
|
+
const out = await a2aStatus({ cfg, piDir, agent: "bob", taskId: "task-9", waitSeconds: -5 });
|
|
542
|
+
assert.equal(m.posts(), 1, "negative wait_seconds must not enter the poll loop");
|
|
543
|
+
assert.notInclude(out, "-5s");
|
|
544
|
+
assert.include(out, "working");
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
it("a2a_status: maps TaskNotFoundError (-32001) to the unknown/evicted/foreign hint", async () => {
|
|
548
|
+
globalThis.fetch = mockFetch({ rpcError: { code: -32001, message: "task not found" } }) as any;
|
|
549
|
+
const cfg = DEFAULTS();
|
|
550
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
551
|
+
const out = await a2aStatus({ cfg, piDir, agent: "bob", taskId: "task-ghost" });
|
|
552
|
+
assert.include(out, "does not know task 'task-ghost'");
|
|
553
|
+
assert.include(out, "visible only to the identity that sent them");
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it("a2a_status: maps 401 to the auth error", async () => {
|
|
557
|
+
globalThis.fetch = mockFetch({ rpcStatus: 401 }) as any;
|
|
558
|
+
const cfg = DEFAULTS();
|
|
559
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
560
|
+
const out = await a2aStatus({ cfg, piDir, agent: "bob", taskId: "task-9" });
|
|
561
|
+
assert.include(out, "rejected auth");
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it("a2a_status: errors with candidate URLs for an ambiguous discovered name", async () => {
|
|
565
|
+
const discoveredPeers: DiscoveredPeer[] = [
|
|
566
|
+
{ name: "pi-s2", url: "http://127.0.0.1:9912", source: "local", alive: true },
|
|
567
|
+
{ name: "pi-s2", url: "http://127.0.0.1:9913", source: "local", alive: true },
|
|
568
|
+
];
|
|
569
|
+
const out = await a2aStatus({ cfg: DEFAULTS(), piDir, agent: "pi-s2", taskId: "task-9", discoveredPeers });
|
|
570
|
+
assert.include(out, "share the name 'pi-s2'");
|
|
571
|
+
assert.include(out, "9912");
|
|
572
|
+
assert.include(out, "9913");
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
it("a2a_status: cancels promptly when the abort signal fires mid-poll", async () => {
|
|
576
|
+
const m = seqMock([{ task: workingTask }]);
|
|
577
|
+
globalThis.fetch = m.fetch as any;
|
|
578
|
+
const cfg = DEFAULTS();
|
|
579
|
+
cfg.timeouts.async = 250;
|
|
580
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
581
|
+
const ctl = new AbortController();
|
|
582
|
+
setTimeout(() => ctl.abort(), 120);
|
|
583
|
+
const t0 = Date.now();
|
|
584
|
+
const out = await a2aStatus({
|
|
585
|
+
cfg,
|
|
586
|
+
piDir,
|
|
587
|
+
agent: "bob",
|
|
588
|
+
taskId: "task-9",
|
|
589
|
+
waitSeconds: 30, // would poll ~2min at 250ms without the signal
|
|
590
|
+
signal: ctl.signal,
|
|
591
|
+
});
|
|
592
|
+
const elapsed = Date.now() - t0;
|
|
593
|
+
assert.isBelow(elapsed, 2000, `abort must end the poll promptly (took ${elapsed}ms)`);
|
|
594
|
+
assert.include(out, "Status polling canceled");
|
|
595
|
+
assert.include(out, "call a2a_status");
|
|
596
|
+
// The last-known state is still reported — the abort only stops polling.
|
|
597
|
+
assert.include(out, "working");
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it("a2a_status: returns immediately on a pre-aborted signal (no fetch)", async () => {
|
|
601
|
+
const m = seqMock([{ task: workingTask }]);
|
|
602
|
+
globalThis.fetch = m.fetch as any;
|
|
603
|
+
const cfg = DEFAULTS();
|
|
604
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
605
|
+
const ctl = new AbortController();
|
|
606
|
+
ctl.abort();
|
|
607
|
+
const out = await a2aStatus({
|
|
608
|
+
cfg,
|
|
609
|
+
piDir,
|
|
610
|
+
agent: "bob",
|
|
611
|
+
taskId: "task-9",
|
|
612
|
+
waitSeconds: 30,
|
|
613
|
+
signal: ctl.signal,
|
|
614
|
+
});
|
|
615
|
+
assert.equal(m.posts(), 0, "a pre-aborted poll must not fetch at all");
|
|
616
|
+
assert.include(out, "Status polling canceled");
|
|
617
|
+
assert.include(out, "task-9");
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it("carries X-A2A-Identity on SendMessage AND on GetTask polls", async () => {
|
|
621
|
+
const seen: Array<Record<string, string>> = [];
|
|
622
|
+
globalThis.fetch = (async (url: string, init?: any) => {
|
|
623
|
+
if (init?.method === "POST") {
|
|
624
|
+
seen.push({ ...(init?.headers || {}) });
|
|
625
|
+
const isGetTask = JSON.parse(init.body).method === "GetTask";
|
|
626
|
+
return makeResp(
|
|
627
|
+
{ jsonrpc: "2.0", id: 1, result: { task: isGetTask ? completedTask : workingTask } },
|
|
628
|
+
200,
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
return makeResp(null, 404);
|
|
632
|
+
}) as any;
|
|
633
|
+
const cfg = DEFAULTS();
|
|
634
|
+
cfg.selfIdentity = "pi-kimchi";
|
|
635
|
+
cfg.peers.bob = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
636
|
+
await a2aCall({ cfg, piDir, agent: "bob", message: "hi", asyncDispatch: true });
|
|
637
|
+
await a2aStatus({ cfg, piDir, agent: "bob", taskId: "task-9" });
|
|
638
|
+
assert.equal(seen.length, 2, "one SendMessage + one GetTask");
|
|
639
|
+
assert.equal(seen[0]!["X-A2A-Identity"], "pi-kimchi", "SendMessage carries the identity");
|
|
640
|
+
assert.equal(seen[1]!["X-A2A-Identity"], "pi-kimchi", "GetTask polls carry the identity too");
|
|
641
|
+
});
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
describe("a2aOrchestrate", () => {
|
|
645
|
+
it("fans out to matching peers (mode all)", async () => {
|
|
646
|
+
let posts = 0;
|
|
647
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
648
|
+
if (init?.method === "POST") posts++;
|
|
649
|
+
return makeResp(
|
|
650
|
+
{
|
|
651
|
+
jsonrpc: "2.0",
|
|
652
|
+
id: 1,
|
|
653
|
+
result: { message: { parts: [{ text: `reply ${posts}` }] } },
|
|
654
|
+
},
|
|
655
|
+
200,
|
|
656
|
+
);
|
|
657
|
+
}) as any;
|
|
658
|
+
const cfg = DEFAULTS();
|
|
659
|
+
cfg.peers.a = { url: "http://a", auth: { type: "none" }, timeout: 5000, capabilities: ["research"] };
|
|
660
|
+
cfg.peers.b = { url: "http://b", auth: { type: "none" }, timeout: 5000, capabilities: ["research"] };
|
|
661
|
+
cfg.peers.c = { url: "http://c", auth: { type: "none" }, timeout: 5000, capabilities: ["coding"] };
|
|
662
|
+
const out = await a2aOrchestrate({ cfg, piDir, capability: "research", message: "go" });
|
|
663
|
+
assert.equal(posts, 2, "only the 2 research-capable peers called");
|
|
664
|
+
assert.include(out, "2/2");
|
|
665
|
+
});
|
|
666
|
+
|
|
667
|
+
it("returns a message when no peers match", async () => {
|
|
668
|
+
const out = await a2aOrchestrate({ cfg: DEFAULTS(), piDir, capability: "x", message: "go" });
|
|
669
|
+
assert.include(out, "No peers advertise capability");
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
it("fans out to gateway peers advertising the capability", async () => {
|
|
673
|
+
let gwPost = 0;
|
|
674
|
+
globalThis.fetch = (async (url: string, init?: any) => {
|
|
675
|
+
if (init?.method === "POST" && String(url).includes("gw-proxy")) gwPost++;
|
|
676
|
+
return makeResp(
|
|
677
|
+
{ jsonrpc: "2.0", id: 1, result: { message: { parts: [{ text: "gw reply" }] } } },
|
|
678
|
+
200,
|
|
679
|
+
);
|
|
680
|
+
}) as any;
|
|
681
|
+
setGatewayPeers({
|
|
682
|
+
"gw/remote/x": { url: "http://gw-proxy/peer/x/", auth: { type: "bearer", token: "t" }, timeout: 5000, capabilities: ["coding"], viaGateway: true },
|
|
683
|
+
});
|
|
684
|
+
try {
|
|
685
|
+
const out = await a2aOrchestrate({ cfg: DEFAULTS(), piDir, capability: "coding", message: "go" });
|
|
686
|
+
assert.equal(gwPost, 1, "gateway peer called at its proxy URL");
|
|
687
|
+
assert.include(out, "gw/remote/x");
|
|
688
|
+
} finally {
|
|
689
|
+
setGatewayPeers({});
|
|
690
|
+
}
|
|
691
|
+
});
|
|
692
|
+
|
|
693
|
+
it("configured peer with the same capability wins over gateway-only entries", async () => {
|
|
694
|
+
let posts = 0;
|
|
695
|
+
globalThis.fetch = (async (_url: string, init?: any) => {
|
|
696
|
+
if (init?.method === "POST") posts++;
|
|
697
|
+
return makeResp({ jsonrpc: "2.0", id: 1, result: { message: { parts: [{ text: "ok" }] } } }, 200);
|
|
698
|
+
}) as any;
|
|
699
|
+
const cfg = DEFAULTS();
|
|
700
|
+
cfg.peers.local = { url: "http://a", auth: { type: "none" }, timeout: 5000, capabilities: ["coding"] };
|
|
701
|
+
setGatewayPeers({
|
|
702
|
+
"gw/remote/local": { url: "http://gw-proxy/peer/local/", auth: { type: "bearer", token: "t" }, timeout: 5000, capabilities: ["coding"], viaGateway: true },
|
|
703
|
+
});
|
|
704
|
+
try {
|
|
705
|
+
const out = await a2aOrchestrate({ cfg, piDir, capability: "coding", message: "go" });
|
|
706
|
+
assert.equal(posts, 1, "merged by name — one entry, not two");
|
|
707
|
+
assert.include(out, "local");
|
|
708
|
+
} finally {
|
|
709
|
+
setGatewayPeers({});
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
it("reports failures when all peers error", async () => {
|
|
714
|
+
globalThis.fetch = (async () => makeResp({}, 500)) as any;
|
|
715
|
+
const cfg = DEFAULTS();
|
|
716
|
+
cfg.peers.a = { url: "http://a", auth: { type: "none" }, timeout: 5000, capabilities: ["research"] };
|
|
717
|
+
const out = await a2aOrchestrate({ cfg, piDir, capability: "research", message: "go" });
|
|
718
|
+
assert.include(out, "fail");
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
describe("SSRF guard", () => {
|
|
723
|
+
it("blocks cloud-metadata endpoint", async () => {
|
|
724
|
+
const cfg = DEFAULTS();
|
|
725
|
+
cfg.peers.meta = { url: "http://169.254.169.254/latest", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
726
|
+
const out = await a2aCall({ cfg, piDir, agent: "meta", message: "hi" });
|
|
727
|
+
assert.include(out, "SSRF");
|
|
728
|
+
});
|
|
729
|
+
|
|
730
|
+
it("blocks IPv4-mapped IPv6 SSRF bypass", async () => {
|
|
731
|
+
const cfg = DEFAULTS();
|
|
732
|
+
cfg.peers.meta6 = { url: "http://[::ffff:169.254.169.254]/latest", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
733
|
+
const out = await a2aCall({ cfg, piDir, agent: "meta6", message: "hi" });
|
|
734
|
+
assert.include(out, "SSRF");
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
it("blocks IPv6 link-local and ULA", async () => {
|
|
738
|
+
assert.isTrue(isPrivateHost(new URL("http://[fe80::1]/").hostname));
|
|
739
|
+
assert.isTrue(isPrivateHost(new URL("http://[fc00::1]/").hostname));
|
|
740
|
+
assert.isTrue(isPrivateHost(new URL("http://[fd12:3456::1]/").hostname));
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
it("blocks hex-form IPv4-mapped IPv6 (Node canonicalizes to this)", async () => {
|
|
744
|
+
// Node's URL parser turns ::ffff:169.254.169.254 into ::ffff:a9fe:a9fe.
|
|
745
|
+
assert.isTrue(isPrivateHost("::ffff:a9fe:a9fe")); // 169.254.169.254
|
|
746
|
+
assert.isTrue(isPrivateHost("::ffff:0a00:0001")); // 10.0.0.1
|
|
747
|
+
assert.isTrue(isPrivateHost("::ffff:c0a8:0101")); // 192.168.1.1
|
|
748
|
+
assert.isFalse(isPrivateHost("::ffff:7f00:0001")); // 127.0.0.1 loopback allowed
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
it("allows loopback (IPv4 + IPv6 ::1) for local peers", async () => {
|
|
752
|
+
assert.isFalse(isPrivateHost("127.0.0.1"));
|
|
753
|
+
assert.isFalse(isPrivateHost(new URL("http://[::1]/").hostname));
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
it("blocks private RFC 1918 ranges", async () => {
|
|
757
|
+
const cfg = DEFAULTS();
|
|
758
|
+
cfg.peers.internal = { url: "http://10.0.0.1:9900", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
759
|
+
const out = await a2aCall({ cfg, piDir, agent: "internal", message: "hi" });
|
|
760
|
+
assert.include(out, "SSRF");
|
|
761
|
+
});
|
|
762
|
+
|
|
763
|
+
it("allows localhost (loopback) for local peers", async () => {
|
|
764
|
+
// Should NOT throw SSRF — may fail on connection, but not with SSRF.
|
|
765
|
+
const cfg = DEFAULTS();
|
|
766
|
+
cfg.peers.local = { url: "http://127.0.0.1:9999", auth: { type: "none" }, timeout: 1000, capabilities: [] };
|
|
767
|
+
const out = await a2aCall({ cfg, piDir, agent: "local", message: "hi" });
|
|
768
|
+
assert.notInclude(out, "SSRF");
|
|
769
|
+
});
|
|
770
|
+
});
|
|
771
|
+
|
|
772
|
+
describe("gateway-origin allowlist (LAN switchboard)", () => {
|
|
773
|
+
const GW = "http://172.30.55.22:9920"; // private-range by design
|
|
774
|
+
const gwCfg = (): any => {
|
|
775
|
+
const c = DEFAULTS();
|
|
776
|
+
c.discovery = { ...(c as any).discovery, gateway: { url: GW, token: "gw-token" } };
|
|
777
|
+
return c;
|
|
778
|
+
};
|
|
779
|
+
|
|
780
|
+
it("a2a_discover on a configured gateway's proxy URL is allowed (was refused)", async () => {
|
|
781
|
+
globalThis.fetch = (async () => ({
|
|
782
|
+
ok: true,
|
|
783
|
+
status: 200,
|
|
784
|
+
json: async () => ({ name: "bob", url: `${GW}/peer/bob/`, skills: [] }),
|
|
785
|
+
})) as any;
|
|
786
|
+
const out = await a2aDiscover({ cfg: gwCfg(), url: `${GW}/peer/bob/` });
|
|
787
|
+
assert.include(out, "Agent: bob");
|
|
788
|
+
assert.notInclude(out, "SSRF");
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
it("a2a_discover on an UNCONFIGURED private host is still refused", async () => {
|
|
792
|
+
const out = await a2aDiscover({ cfg: DEFAULTS(), url: "http://10.1.2.3:1/x" });
|
|
793
|
+
assert.include(out, "SSRF");
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
it("a2a_status GetTask on a gateway-proxied peer is allowed (was refused)", async () => {
|
|
797
|
+
globalThis.fetch = (async (_u: any, init?: any) => {
|
|
798
|
+
const raw = String(init?.body ?? "");
|
|
799
|
+
if (raw.includes("GetTask")) {
|
|
800
|
+
const body = JSON.parse(raw);
|
|
801
|
+
return {
|
|
802
|
+
ok: true, status: 200,
|
|
803
|
+
text: async () => JSON.stringify({ jsonrpc: "2.0", id: body.id, result: { id: "t1", contextId: "c", status: { state: STATE_COMPLETED } } }),
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
return { ok: false, status: 404, text: async () => "no card" }; // best-effort card fetch
|
|
807
|
+
}) as any;
|
|
808
|
+
const cfg = gwCfg();
|
|
809
|
+
cfg.peers.bob = { url: `${GW}/peer/bob/`, auth: { type: "bearer", token: "gw-token" }, timeout: 5000, capabilities: [], viaGateway: true, gatewayUrl: GW };
|
|
810
|
+
const out = await a2aStatus({ cfg, piDir, agent: "bob", taskId: "t1" });
|
|
811
|
+
assert.include(out, "completed");
|
|
812
|
+
assert.notInclude(out, "SSRF");
|
|
813
|
+
});
|
|
814
|
+
});
|
|
815
|
+
|
|
816
|
+
describe("a2aList", () => {
|
|
817
|
+
it("shows up to 20 tools with a +N more suffix", () => {
|
|
818
|
+
const tools = Array.from({ length: 25 }, (_, i) => `tool_${i}`);
|
|
819
|
+
const out = a2aList({
|
|
820
|
+
cfg: DEFAULTS(),
|
|
821
|
+
piDir,
|
|
822
|
+
discoveredPeers: [{ name: "big", url: "http://127.0.0.1:1/", source: "local", tools }],
|
|
823
|
+
});
|
|
824
|
+
assert.include(out, "tool_19");
|
|
825
|
+
assert.include(out, "(+5 more)");
|
|
826
|
+
assert.notInclude(out, "tool_20");
|
|
827
|
+
});
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
describe("conversation persistence (single context)", () => {
|
|
831
|
+
it("persists user + agent reply under the SAME contextId", async () => {
|
|
832
|
+
const { loadConversation } = await import("../lib/persistence");
|
|
833
|
+
globalThis.fetch = (async () =>
|
|
834
|
+
makeResp(
|
|
835
|
+
{
|
|
836
|
+
jsonrpc: "2.0",
|
|
837
|
+
id: 1,
|
|
838
|
+
result: { task: { id: "t1", contextId: "ctx-xyz", status: { state: STATE_COMPLETED }, artifacts: [{ parts: [{ text: "reply body" }] }] } },
|
|
839
|
+
},
|
|
840
|
+
200,
|
|
841
|
+
)) as any;
|
|
842
|
+
const cfg = DEFAULTS();
|
|
843
|
+
cfg.peers.bob = { url: "http://127.0.0.1:9900", auth: { type: "none" }, timeout: 5000, capabilities: [] };
|
|
844
|
+
const out = await a2aCall({ cfg, piDir, agent: "bob", message: "my question" });
|
|
845
|
+
// The returned context must be the peer's ctx-xyz.
|
|
846
|
+
assert.include(out, "ctx-xyz");
|
|
847
|
+
// And BOTH messages live under ctx-xyz.
|
|
848
|
+
const msgs = loadConversation(piDir, "ctx-xyz");
|
|
849
|
+
assert.lengthOf(msgs, 2);
|
|
850
|
+
assert.equal(msgs[0]!.role, "user");
|
|
851
|
+
assert.equal(msgs[0]!.text, "my question");
|
|
852
|
+
assert.equal(msgs[1]!.role, "agent");
|
|
853
|
+
assert.equal(msgs[1]!.text, "reply body");
|
|
854
|
+
});
|
|
855
|
+
});
|
|
856
|
+
});
|