@jbkjr/relay 0.0.0-stage → 1.2.2
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/LICENSE +21 -0
- package/LICENSES/Apache-2.0.txt +201 -0
- package/LICENSES/README.md +19 -0
- package/LICENSES/codex-NOTICE.txt +6 -0
- package/README.md +393 -2
- package/SECURITY.md +145 -0
- package/adapters/briefs/claude.md +43 -0
- package/adapters/briefs/codex.md +56 -0
- package/adapters/briefs/models.json +33 -0
- package/adapters/build.mjs +8 -0
- package/adapters/claude/.claude-plugin/marketplace.json +13 -0
- package/adapters/claude/relay/.claude-plugin/plugin.json +5 -0
- package/adapters/claude/relay/agents/codex.md +21 -0
- package/adapters/claude/relay/agents/operator.md +21 -0
- package/adapters/claude/relay/skills/ask/SKILL.md +20 -0
- package/adapters/claude/relay/skills/chat/SKILL.md +13 -0
- package/adapters/claude/relay/skills/delegate/SKILL.md +21 -0
- package/adapters/claude/relay/skills/discuss/SKILL.md +19 -0
- package/adapters/claude/relay/skills/review/SKILL.md +21 -0
- package/adapters/claude/relay/skills/tree/SKILL.md +10 -0
- package/adapters/claude/relay/skills/write-for-codex/SKILL.md +78 -0
- package/adapters/codex/.agents/plugins/marketplace.json +20 -0
- package/adapters/codex/AGENTS.snippet.md +5 -0
- package/adapters/codex/relay/.codex-plugin/plugin.json +6 -0
- package/adapters/codex/relay/skills/relay-ask/SKILL.md +20 -0
- package/adapters/codex/relay/skills/relay-chat/SKILL.md +13 -0
- package/adapters/codex/relay/skills/relay-delegate/SKILL.md +21 -0
- package/adapters/codex/relay/skills/relay-discuss/SKILL.md +19 -0
- package/adapters/codex/relay/skills/relay-review/SKILL.md +21 -0
- package/adapters/codex/relay/skills/relay-tree/SKILL.md +10 -0
- package/adapters/codex/relay/skills/relay-write-for-claude/SKILL.md +66 -0
- package/adapters/generate.mjs +124 -0
- package/bin/relay +59 -0
- package/codex-pin.json +12 -0
- package/dist/backends/acp.js +1424 -0
- package/dist/backends/claude.js +890 -0
- package/dist/backends/cli-version.js +112 -0
- package/dist/backends/codex-app.js +1539 -0
- package/dist/backends/codex-daybreak.js +75 -0
- package/dist/backends/codex-env.js +656 -0
- package/dist/backends/codex-network.js +304 -0
- package/dist/backends/codex-pin.js +345 -0
- package/dist/backends/codex-shell-policy.js +182 -0
- package/dist/backends/codex-stage2.js +998 -0
- package/dist/backends/codex-subagents.js +47 -0
- package/dist/backends/codex.js +641 -0
- package/dist/backends/copilot.js +246 -0
- package/dist/backends/env.js +147 -0
- package/dist/backends/gemini.js +607 -0
- package/dist/backends/grok.js +337 -0
- package/dist/backends/index.js +8 -0
- package/dist/backends/native-temp.js +187 -0
- package/dist/backends/never-admission.js +90 -0
- package/dist/backends/run.js +67 -0
- package/dist/backends/stream.js +230 -0
- package/dist/backends/tool-discovery.js +15 -0
- package/dist/backends/types.js +264 -0
- package/dist/build-info.json +5 -0
- package/dist/cli.js +344 -0
- package/dist/confine/bridge.js +113 -0
- package/dist/confine/broker-core.js +76 -0
- package/dist/confine/broker-http.js +650 -0
- package/dist/confine/broker-names.js +9 -0
- package/dist/confine/broker.js +258 -0
- package/dist/confine/canary.js +380 -0
- package/dist/confine/diagnostics.js +122 -0
- package/dist/confine/gemini-tools-main.js +8 -0
- package/dist/confine/gemini-tools.js +181 -0
- package/dist/confine/hardlinks.js +58 -0
- package/dist/confine/harness-config.js +16 -0
- package/dist/confine/index.js +117 -0
- package/dist/confine/leases.js +217 -0
- package/dist/confine/paths.js +6 -0
- package/dist/confine/peer.js +115 -0
- package/dist/confine/port-policy.js +8 -0
- package/dist/confine/ports.js +365 -0
- package/dist/confine/private-root.js +208 -0
- package/dist/confine/probe-stage2.js +501 -0
- package/dist/confine/probe.js +1109 -0
- package/dist/confine/proxy.js +783 -0
- package/dist/confine/sbcheck.js +208 -0
- package/dist/confine/seatbelt-never.js +41 -0
- package/dist/confine/seatbelt-stage2.js +139 -0
- package/dist/confine/seatbelt.js +1129 -0
- package/dist/confine/sockets.js +36 -0
- package/dist/confine/turn-probe.js +19 -0
- package/dist/confine/turn.js +86 -0
- package/dist/core/adoption.js +124 -0
- package/dist/core/api-keys.js +423 -0
- package/dist/core/approvals.js +740 -0
- package/dist/core/build-identity.js +248 -0
- package/dist/core/caller.js +749 -0
- package/dist/core/calls.js +102 -0
- package/dist/core/claude-settings.js +1045 -0
- package/dist/core/config.js +453 -0
- package/dist/core/context.js +186 -0
- package/dist/core/db.js +753 -0
- package/dist/core/dispatch.js +110 -0
- package/dist/core/env-broker.js +505 -0
- package/dist/core/env-policy.js +182 -0
- package/dist/core/escalation-authority.js +76 -0
- package/dist/core/escalation-contract.js +13 -0
- package/dist/core/escalation-person-path.js +131 -0
- package/dist/core/escalation-policy.js +79 -0
- package/dist/core/escalation-runtime.js +135 -0
- package/dist/core/escalation-state.js +42 -0
- package/dist/core/escalations.js +191 -0
- package/dist/core/events.js +235 -0
- package/dist/core/executables.js +147 -0
- package/dist/core/extensions.js +645 -0
- package/dist/core/families.js +204 -0
- package/dist/core/git.js +657 -0
- package/dist/core/identity.js +113 -0
- package/dist/core/liveness.js +68 -0
- package/dist/core/mediated-network-provider.js +81 -0
- package/dist/core/never-checkpoint.js +76 -0
- package/dist/core/never-coverage.js +97 -0
- package/dist/core/never-network.js +49 -0
- package/dist/core/never-policy.js +302 -0
- package/dist/core/never-proxy-policy.js +109 -0
- package/dist/core/never-schema.js +61 -0
- package/dist/core/never-tools.js +56 -0
- package/dist/core/notices.js +48 -0
- package/dist/core/ops.js +959 -0
- package/dist/core/outcome.js +224 -0
- package/dist/core/params.js +32 -0
- package/dist/core/presence.js +174 -0
- package/dist/core/procs.js +546 -0
- package/dist/core/prompts.js +363 -0
- package/dist/core/protected-config.js +238 -0
- package/dist/core/raw-network.js +192 -0
- package/dist/core/redact.js +152 -0
- package/dist/core/refusal.js +33 -0
- package/dist/core/relay-command.js +310 -0
- package/dist/core/reported.js +3 -0
- package/dist/core/restart-overlay.js +651 -0
- package/dist/core/retention.js +1135 -0
- package/dist/core/secrets.js +329 -0
- package/dist/core/session-token.js +175 -0
- package/dist/core/session.js +744 -0
- package/dist/core/shell.js +2 -0
- package/dist/core/shipped-pin.js +47 -0
- package/dist/core/shown.js +42 -0
- package/dist/core/slots.js +67 -0
- package/dist/core/stage2-executors.js +453 -0
- package/dist/core/stage2-switch.js +5 -0
- package/dist/core/steering.js +149 -0
- package/dist/core/storage.js +358 -0
- package/dist/core/toml.js +175 -0
- package/dist/core/views.js +324 -0
- package/dist/core/wait.js +114 -0
- package/dist/core/wake.js +207 -0
- package/dist/core/watch.js +247 -0
- package/dist/core/worktree.js +213 -0
- package/dist/hosts/claude-desktop.js +274 -0
- package/dist/hosts/claude.js +249 -0
- package/dist/hosts/codex.js +345 -0
- package/dist/hosts/desktop-shared.js +20 -0
- package/dist/hosts/index.js +11 -0
- package/dist/hosts/types.js +4 -0
- package/dist/install/basics.js +18 -0
- package/dist/install/claude-init.js +133 -0
- package/dist/install/common.js +655 -0
- package/dist/install/doctor.js +635 -0
- package/dist/install/qualify-codex.js +205 -0
- package/dist/install.js +524 -0
- package/dist/mcp/elicit.js +209 -0
- package/dist/mcp/gateway.js +218 -0
- package/dist/mcp/host.js +253 -0
- package/dist/mcp/server.js +1124 -0
- package/dist/mcp/stdio.js +37 -0
- package/dist/modes/discussion.js +393 -0
- package/dist/modes/review.js +722 -0
- package/dist/native/relay-sbcheck +0 -0
- package/dist/targets/briefs.js +86 -0
- package/dist/targets/claude.js +94 -0
- package/dist/targets/codex.js +66 -0
- package/dist/targets/copilot.js +93 -0
- package/dist/targets/gemini.js +119 -0
- package/dist/targets/grok.js +126 -0
- package/dist/targets/index.js +192 -0
- package/dist/targets/types.js +18 -0
- package/dist/targets/verified.js +35 -0
- package/dist/worker.js +113 -0
- package/docs/UPGRADING.md +1518 -0
- package/docs/pinned-codex.md +333 -0
- package/experiments/stage2-redteam/lib/oracles.mjs +214 -0
- package/experiments/stage2-redteam/lib/report.mjs +35 -0
- package/npm-shrinkwrap.json +1632 -0
- package/package.json +82 -4
- package/scripts/codex-qualify/codex-pin-store.mjs +353 -0
- package/scripts/codex-qualify/codex-qualifier-process.mjs +265 -0
- package/scripts/codex-qualify/codex-qualifier.example.json +5 -0
- package/scripts/codex-qualify/codex-qualifier.mjs +281 -0
- package/scripts/codex-qualify/codex-shipped-pin.mjs +158 -0
- package/scripts/codex-qualify/codex-stage2-pin.mjs +48 -0
- package/scripts/codex-qualify/codex-stage2.mjs +2381 -0
- package/scripts/codex-qualify/install-codex-qualifier.mjs +98 -0
- package/scripts/codex-qualify/main-module.mjs +14 -0
- package/scripts/codex-qualify/relay-codex-qualifier.plist +37 -0
- package/scripts/codex-qualify/scratch-env.mjs +31 -0
- package/scripts/codex-qualify/session.mjs +96 -0
- package/scripts/codex-qualify/stage2-escalation-cases.mjs +125 -0
- package/test/codex-permissions.test.ts +875 -0
- package/test/fixtures/boundary-probes.mjs +17 -0
- package/test/fixtures/denial-stream-host.mjs +7 -0
- package/test/fixtures/families.json +246 -0
- package/test/fixtures/install-snapshots/claude-desktop-foreign.txt +158 -0
- package/test/fixtures/install-snapshots/claude-desktop-fresh.txt +101 -0
- package/test/fixtures/install-snapshots/claude-desktop-installed.txt +161 -0
- package/test/fixtures/install-snapshots/claude-foreign.txt +133 -0
- package/test/fixtures/install-snapshots/claude-fresh.txt +77 -0
- package/test/fixtures/install-snapshots/claude-installed.txt +133 -0
- package/test/fixtures/install-snapshots/codex-foreign.txt +159 -0
- package/test/fixtures/install-snapshots/codex-fresh.txt +107 -0
- package/test/fixtures/install-snapshots/codex-installed.txt +161 -0
- package/test/fixtures/link-parent.mjs +6 -0
- package/test/fixtures/mediated-command.cjs +72 -0
- package/test/fixtures/native-skill-isolation.json +280 -0
- package/test/fixtures/pinned-codex-app-server.mjs +25 -0
- package/test/fixtures/qualified-ext-adapters.mjs +36 -0
- package/test/fixtures/refusals/README.md +52 -0
- package/test/fixtures/refusals/claude-source-result.json +7 -0
- package/test/fixtures/refusals/openai-app-capacity.json +24 -0
- package/test/fixtures/refusals/openai-app-cyberPolicy.json +24 -0
- package/test/fixtures/refusals/openai-gpt-6-astra-max.json +12 -0
- package/test/fixtures/refusals/openai-gpt-6.1-sol-xhigh.json +12 -0
- package/test/fixtures/refusals/openai-review-capacity.json +24 -0
- package/test/fixtures/relay-0.2.0.sql +57 -0
- package/test/fixtures/relay-0.9.1.gen.mjs +212 -0
- package/test/fixtures/relay-0.9.1.sql +340 -0
- package/test/fixtures/slow-boundary-probes.mjs +37 -0
- package/test/fixtures/stable-surfaces/config.json +1122 -0
- package/test/fixtures/stable-surfaces/escalation.json +128 -0
- package/test/fixtures/stable-surfaces/events.json +37 -0
- package/test/fixtures/stable-surfaces/gemini-native-resume.json +4 -0
- package/test/fixtures/stable-surfaces/inbox.jsonl +2 -0
- package/test/fixtures/stable-surfaces/notice.txt +1 -0
- package/test/fixtures/stable-surfaces/refusal-item.json +28 -0
- package/test/fixtures/stable-surfaces/refusal-review.json +23 -0
- package/test/fixtures/stable-surfaces/registry.json +49 -0
- package/test/fixtures/stable-surfaces/tools-desktop.json +575 -0
- package/test/fixtures/stable-surfaces/tools.json +716 -0
- package/test/fixtures/stable-surfaces/usage.txt +46 -0
- package/test/fixtures/stage2-acp-native.mjs +138 -0
- package/test/fixtures/stage2-app-server.mjs +23 -0
- package/test/fixtures/stage2-catalog.json +91 -0
- package/test/fixtures/stage2-hostile-web.mjs +35 -0
- package/test/fixtures/stage2-native-network.mjs +62 -0
- package/test/fixtures/stage2-worker.ts +87 -0
- package/test/fixtures/status-views/expected.json +7825 -0
- package/test/fixtures/status-views/registries.json +1 -0
- package/test/fixtures/steering.json +209 -0
- package/test/helpers.ts +740 -0
- package/test/host-env.ts +7 -0
- package/test/keychain-decoy.ts +197 -0
- package/test/live-scope.ts +44 -0
- package/test/mediated-network.test.ts +192 -0
- package/test/mediated-proxy.test.ts +264 -0
- package/test/native-temp-alias.ts +10 -0
- package/test/never-policy.test.ts +629 -0
- package/test/never-tools.test.ts +136 -0
- package/test/process-home.ts +18 -0
- package/test/proxy.test.ts +531 -0
- package/test/restart-overlay-live.test.ts +85 -0
- package/test/restart-overlay-profile.test.ts +66 -0
- package/test/restart-overlay.test.ts +416 -0
- package/test/stable-surfaces.test.ts +249 -0
- package/test/stage2-escalation-live.test.ts +544 -0
- package/test/stage2-escalation-qualification.test.ts +170 -0
- package/test/stage2-escalation.test.ts +747 -0
- package/test/stage2-executor.test.ts +849 -0
- package/test/stage2-grant.test.ts +603 -0
- package/test/stage2-native-live.test.ts +647 -0
- package/test/stage2-network-decisions.test.ts +70 -0
- package/test/stage2-probe.test.ts +845 -0
- package/test/stage2-standing-live.test.ts +203 -0
- package/test/stubs/broker-host.mjs +59 -0
- package/test/stubs/broker-peer.mjs +20 -0
- package/test/stubs/confined-harness.mjs +91 -0
- package/test/stubs/ext-broken-server.mjs +2 -0
- package/test/stubs/ext-odd-server.mjs +21 -0
- package/test/stubs/ext-server.mjs +31 -0
- package/test/stubs/fake-host-cli.mjs +218 -0
- package/test/stubs/procargs.mjs +30 -0
- package/test/stubs/stub-acp +4 -0
- package/test/stubs/stub-agent.mjs +322 -0
- package/test/stubs/stub-claude +4 -0
- package/test/stubs/stub-codex +4 -0
- package/test/stubs/targets/acp.mjs +307 -0
- package/test/stubs/targets/claude.mjs +149 -0
- package/test/stubs/targets/codex.mjs +479 -0
- package/test/stubs/targets/gemini.mjs +604 -0
- package/test/temp-root.ts +11 -0
- package/test/wp4-adapters.test.ts +353 -0
- package/test/wp4-interlock.test.ts +136 -0
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import net from "node:net";
|
|
9
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
10
|
+
import { ConfigSchema, configDeprecations, loadConfig, withDefaults } from "../dist/core/config.js";
|
|
11
|
+
import { newInstance } from "../dist/core/caller.js";
|
|
12
|
+
import { relayServer } from "../dist/mcp/server.js";
|
|
13
|
+
import { closeDbForTests, createRun, db, getNode, insertNode, SCHEMA_VERSION } from "../dist/core/db.js";
|
|
14
|
+
import { nodeView } from "../dist/core/views.js";
|
|
15
|
+
import { postNotice } from "../dist/core/events.js";
|
|
16
|
+
import { signedNotice } from "../dist/core/notices.js";
|
|
17
|
+
import { pendingEvents } from "../dist/core/watch.js";
|
|
18
|
+
import { TESTED_MACOS, testedMacOS } from "../dist/install/doctor.js";
|
|
19
|
+
import { targetDef } from "../dist/targets/index.js";
|
|
20
|
+
import { CLI } from "./helpers.ts";
|
|
21
|
+
|
|
22
|
+
const fixtures = path.join(import.meta.dirname, "fixtures", "stable-surfaces");
|
|
23
|
+
function snapshot(name: string, value: unknown) {
|
|
24
|
+
const file = path.join(fixtures, name);
|
|
25
|
+
const text = typeof value === "string" ? value : JSON.stringify(value, null, 2) + "\n";
|
|
26
|
+
if (process.env.RELAY_UPDATE_SNAPSHOTS === "1") {
|
|
27
|
+
fs.mkdirSync(fixtures, { recursive: true });
|
|
28
|
+
fs.writeFileSync(file, text);
|
|
29
|
+
}
|
|
30
|
+
assert.ok(fs.existsSync(file), `record ${name} with RELAY_UPDATE_SNAPSHOTS=1`);
|
|
31
|
+
assert.equal(text, fs.readFileSync(file, "utf8"));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test("stable surfaces: Gemini jobs and threads withhold native resume and explain the confined continuation", () => {
|
|
35
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "relay-resume-surface-"));
|
|
36
|
+
const saved = process.env.RELAY_HOME;
|
|
37
|
+
try {
|
|
38
|
+
process.env.RELAY_HOME = tmp;
|
|
39
|
+
const runId = createRun(tmp, withDefaults({}), "surface-root");
|
|
40
|
+
for (const [id, kind] of [["j_00000001", "job"], ["t_00000001", "thread"]] as const) {
|
|
41
|
+
insertNode({ id, run_id: runId, kind, target: "gemini", mode: "read", depth: 1, task: "surface", cwd: tmp });
|
|
42
|
+
db().prepare("UPDATE nodes SET status = 'done', session_id = 'gemini-session' WHERE id = ?").run(id);
|
|
43
|
+
const native = nodeView(getNode(id)!).resume_natively;
|
|
44
|
+
assert.deepEqual(native, { command: null, note: targetDef("gemini").nativeResumeWithheld });
|
|
45
|
+
snapshot("gemini-native-resume.json", native);
|
|
46
|
+
}
|
|
47
|
+
} finally {
|
|
48
|
+
closeDbForTests();
|
|
49
|
+
if (saved === undefined) delete process.env.RELAY_HOME; else process.env.RELAY_HOME = saved;
|
|
50
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Descriptions are prose, not the wire contract. Retain names, types, required lists,
|
|
55
|
+
// nested objects, enums and constraints; do not lose the keys of a properties map.
|
|
56
|
+
function contract(value: any): any {
|
|
57
|
+
if (Array.isArray(value)) return value.map(contract);
|
|
58
|
+
if (!value || typeof value !== "object") return value;
|
|
59
|
+
return Object.fromEntries(Object.entries(value).filter(([k]) => k !== "description" && k !== "$schema").map(([k, v]) => [k,
|
|
60
|
+
k === "properties" ? Object.fromEntries(Object.entries(v as object).map(([name, schema]) => [name, contract(schema)])) : contract(v),
|
|
61
|
+
]));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test("stable surfaces: registered MCP tools (including conditional tools) and config schemas", async () => {
|
|
65
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "relay-surface-"));
|
|
66
|
+
const old = { RELAY_HOME: process.env.RELAY_HOME, RELAY_CONFIG: process.env.RELAY_CONFIG };
|
|
67
|
+
const register = McpServer.prototype.registerTool;
|
|
68
|
+
const tools: Record<string, unknown> = {};
|
|
69
|
+
// The shared desktop entry's root tools take session_token as well (docs/d9-isolation-plan.md).
|
|
70
|
+
const desktopTools: Record<string, unknown> = {};
|
|
71
|
+
let into = tools;
|
|
72
|
+
// Capture the exact schemas supplied to the SDK, including confirm, whose visibility is
|
|
73
|
+
// qualified at connection time. No host permission checks are bypassed in production.
|
|
74
|
+
McpServer.prototype.registerTool = function (name: string, config: any, cb: any) {
|
|
75
|
+
into[name] = contract(z.toJSONSchema(config.inputSchema instanceof z.ZodObject ? config.inputSchema : z.object(config.inputSchema), { io: "input" }));
|
|
76
|
+
return register.call(this, name, config, cb);
|
|
77
|
+
} as typeof register;
|
|
78
|
+
try {
|
|
79
|
+
process.env.RELAY_HOME = tmp;
|
|
80
|
+
process.env.RELAY_CONFIG = path.join(tmp, "config.json");
|
|
81
|
+
fs.writeFileSync(process.env.RELAY_CONFIG, "{}");
|
|
82
|
+
const root = relayServer(newInstance({ kind: "root" }, tmp));
|
|
83
|
+
await root.close();
|
|
84
|
+
const runId = createRun(tmp, withDefaults({}), "surface-root");
|
|
85
|
+
insertNode({ id: "j_00000001", run_id: runId, kind: "job", target: "claude", mode: "read", depth: 1, task: "surface", cwd: tmp });
|
|
86
|
+
const child = relayServer(newInstance({ kind: "child", runId, nodeId: "j_00000001", turnId: 1, depth: 1, access: "read", mayDelegate: false, mayAsk: true }, tmp));
|
|
87
|
+
await child.close();
|
|
88
|
+
// Escalation is conditional on the qualified stage-2 Codex lifecycle, while
|
|
89
|
+
// Claude's released child transport above contributes permission_prompt.
|
|
90
|
+
const stage2Run = createRun(tmp, withDefaults({ targets: { codex: { stage2: true } } }), "surface-stage2");
|
|
91
|
+
insertNode({ id: "j_00000002", run_id: stage2Run, kind: "job", target: "codex", mode: "read", depth: 1, task: "surface", cwd: tmp });
|
|
92
|
+
const stage2 = relayServer(newInstance({ kind: "child", runId: stage2Run, nodeId: "j_00000002", turnId: 2, depth: 1, access: "read", mayDelegate: false, mayAsk: true }, tmp));
|
|
93
|
+
await stage2.close();
|
|
94
|
+
into = desktopTools;
|
|
95
|
+
const desktop = relayServer(newInstance({ kind: "root" }, tmp, "claude"), { desktop: true });
|
|
96
|
+
await desktop.close();
|
|
97
|
+
snapshot("tools.json", Object.fromEntries(Object.entries(tools).sort(([a], [b]) => a.localeCompare(b))));
|
|
98
|
+
snapshot("tools-desktop.json", Object.fromEntries(Object.entries(desktopTools).sort(([a], [b]) => a.localeCompare(b))));
|
|
99
|
+
// The desktop entry differs from a dedicated root only by the optional session_token; tools.json
|
|
100
|
+
// also holds permission_prompt, a launched agent's tool.
|
|
101
|
+
assert.deepEqual(Object.keys(desktopTools).sort(), Object.keys(tools).filter((n) => !["permission_prompt", "escalate"].includes(n)).sort());
|
|
102
|
+
for (const [name, schema] of Object.entries(desktopTools) as [string, any][]) {
|
|
103
|
+
const { session_token, ...rest } = schema.properties ?? {};
|
|
104
|
+
assert.equal(Boolean(session_token), name !== "brief", name);
|
|
105
|
+
assert.deepEqual({ ...schema, properties: rest }, tools[name], name);
|
|
106
|
+
}
|
|
107
|
+
snapshot("config.json", contract(z.toJSONSchema(ConfigSchema, { io: "input" })));
|
|
108
|
+
snapshot("registry.json", {
|
|
109
|
+
version: SCHEMA_VERSION,
|
|
110
|
+
tables: db().prepare("SELECT name, sql FROM sqlite_master WHERE type = 'table' AND name NOT LIKE 'sqlite_%' ORDER BY name").all(),
|
|
111
|
+
});
|
|
112
|
+
} finally {
|
|
113
|
+
McpServer.prototype.registerTool = register;
|
|
114
|
+
closeDbForTests();
|
|
115
|
+
for (const [k, v] of Object.entries(old)) if (v === undefined) delete process.env[k]; else process.env[k] = v;
|
|
116
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("stable surfaces: CLI usage, version aliases and misuse status", () => {
|
|
121
|
+
const usage = spawnSync(process.execPath, [CLI, "--help"], { encoding: "utf8" });
|
|
122
|
+
assert.equal(usage.status, 0);
|
|
123
|
+
assert.equal(usage.stderr, "");
|
|
124
|
+
snapshot("usage.txt", usage.stdout);
|
|
125
|
+
for (const alias of ["help", "-h"]) {
|
|
126
|
+
const r = spawnSync(process.execPath, [CLI, alias], { encoding: "utf8" });
|
|
127
|
+
assert.equal(r.status, 0);
|
|
128
|
+
assert.equal(r.stdout, usage.stdout);
|
|
129
|
+
}
|
|
130
|
+
for (const alias of ["--version", "-v", "version"]) {
|
|
131
|
+
const r = spawnSync(process.execPath, [CLI, alias], { encoding: "utf8" });
|
|
132
|
+
assert.equal(r.status, 0);
|
|
133
|
+
assert.equal(r.stdout, "relay 1.2.2\n");
|
|
134
|
+
}
|
|
135
|
+
const bad = spawnSync(process.execPath, [CLI, "unknown-command"], { encoding: "utf8" });
|
|
136
|
+
assert.equal(bad.status, 2);
|
|
137
|
+
assert.match(bad.stderr, /unknown command unknown-command/);
|
|
138
|
+
// relay mcp's flags, as install registers it, are in the help.
|
|
139
|
+
assert.match(usage.stdout, /relay mcp \[--host <target>\] \[--desktop\] \[--context <file>\]/);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
test("stable surfaces: CLI errors are messages, not stack traces, and an error result exits 1", () => {
|
|
143
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "relay-cli-errors-"));
|
|
144
|
+
try {
|
|
145
|
+
const config = path.join(tmp, "config.json");
|
|
146
|
+
fs.writeFileSync(config, JSON.stringify({ max_depth: "three" }));
|
|
147
|
+
const env: NodeJS.ProcessEnv = { ...process.env, RELAY_HOME: path.join(tmp, "state"), RELAY_CONFIG: config };
|
|
148
|
+
delete env.RELAY_DEBUG;
|
|
149
|
+
for (const k of ["RELAY_RUN_ID", "RELAY_NODE_ID", "RELAY_DEPTH", "RELAY_INJECTED"]) delete env[k];
|
|
150
|
+
const run = (args: string[], extra: NodeJS.ProcessEnv = {}) => spawnSync(process.execPath, [CLI, ...args], { encoding: "utf8", env: { ...env, ...extra } });
|
|
151
|
+
// A config typo: one line saying what is wrong, no stack, unless RELAY_DEBUG asks for one.
|
|
152
|
+
const typo = run(["qualify-codex", "--shipped"]);
|
|
153
|
+
assert.equal(typo.status, 1);
|
|
154
|
+
assert.match(typo.stderr, /^relay: relay config at .* is not valid, so relay will not start with it\. max_depth: /);
|
|
155
|
+
assert.doesNotMatch(typo.stderr, /\n\s+at /, "no stack trace");
|
|
156
|
+
assert.match(run(["qualify-codex", "--shipped"], { RELAY_DEBUG: "1" }).stderr, /\n\s+at /, "RELAY_DEBUG shows it");
|
|
157
|
+
// Unknown ids: the error result, and exit 1.
|
|
158
|
+
fs.writeFileSync(config, "{}");
|
|
159
|
+
for (const args of [["approve", "r_nope"], ["deny", "r_nope"], ["cancel", "j_nope"]]) {
|
|
160
|
+
const r = run(args);
|
|
161
|
+
assert.equal(r.status, 1, `${args.join(" ")}: ${r.stdout}${r.stderr}`);
|
|
162
|
+
assert.match(JSON.parse(r.stdout).error, /unknown (request|id)/);
|
|
163
|
+
}
|
|
164
|
+
} finally {
|
|
165
|
+
closeDbForTests();
|
|
166
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("compatibility: 0.2.0 keys load with warnings, preserve values, and reject conflicting spellings", () => {
|
|
171
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "relay-legacy-"));
|
|
172
|
+
const old = process.env.RELAY_CONFIG;
|
|
173
|
+
const legacy = { bin: { claude: "/legacy/claude" }, default_model: { codex: "gpt-6.1-sol" }, default_effort: { codex: "high" }, notify: true };
|
|
174
|
+
try {
|
|
175
|
+
process.env.RELAY_CONFIG = path.join(tmp, "config.json");
|
|
176
|
+
fs.writeFileSync(process.env.RELAY_CONFIG, JSON.stringify(legacy));
|
|
177
|
+
const warnings: string[] = [];
|
|
178
|
+
const cfg = loadConfig((m) => warnings.push(m));
|
|
179
|
+
assert.equal(cfg.targets.claude.bin, legacy.bin.claude);
|
|
180
|
+
assert.equal(cfg.targets.codex.default_model, legacy.default_model.codex);
|
|
181
|
+
assert.equal(cfg.targets.codex.default_effort, "high");
|
|
182
|
+
assert.equal(cfg.desktop_notifications, true);
|
|
183
|
+
assert.equal(warnings.length, 4);
|
|
184
|
+
for (const key of Object.keys(legacy)) assert.ok(warnings.some((w) => w.includes(`key ${key} is deprecated`) && w.includes("throughout relay 1.x")));
|
|
185
|
+
assert.deepEqual(configDeprecations({}), []);
|
|
186
|
+
assert.equal(withDefaults({ notify: false }).desktop_notifications, false);
|
|
187
|
+
for (const key of ["bin", "default_model", "default_effort"]) {
|
|
188
|
+
assert.equal(ConfigSchema.safeParse({ [key]: { claude: "x" }, targets: { claude: { [key]: "y" } } }).success, false);
|
|
189
|
+
}
|
|
190
|
+
assert.equal(ConfigSchema.safeParse({ notify: false, desktop_notifications: false }).success, false);
|
|
191
|
+
// Exercise the default stderr diagnostic in a new process, rather than just its callback.
|
|
192
|
+
const script = `import {loadConfig} from ${JSON.stringify(new URL("../dist/core/config.js", import.meta.url).href)}; loadConfig();`;
|
|
193
|
+
const r = spawnSync(process.execPath, ["--input-type=module", "-e", script], { encoding: "utf8" });
|
|
194
|
+
assert.equal(r.status, 0, r.stderr);
|
|
195
|
+
for (const key of Object.keys(legacy)) assert.match(r.stderr, new RegExp(`WARNING: config key ${key} is deprecated`));
|
|
196
|
+
} finally {
|
|
197
|
+
if (old === undefined) delete process.env.RELAY_CONFIG; else process.env.RELAY_CONFIG = old;
|
|
198
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test("supported versions: speed-tested floors and exact recorded macOS releases", () => {
|
|
203
|
+
assert.deepEqual(targetDef("claude").tested, [2, 1, 302]);
|
|
204
|
+
assert.deepEqual(targetDef("codex").tested, [0, 163, 0]);
|
|
205
|
+
assert.deepEqual(TESTED_MACOS, ["27.0", "27.0.1", "27.2", "27.2.1"]);
|
|
206
|
+
for (const v of TESTED_MACOS) assert.equal(testedMacOS(v), true);
|
|
207
|
+
for (const v of ["unknown", "26.0", "27.0.2", "27.1", "27.2.2", "28.0"]) assert.equal(testedMacOS(v), false);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
test("stable surfaces: event fields and notice text and inbox wire format", async () => {
|
|
211
|
+
const tmp = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), "relay-wire-")));
|
|
212
|
+
const old = process.env.RELAY_HOME;
|
|
213
|
+
const inbox = net.createServer();
|
|
214
|
+
try {
|
|
215
|
+
process.env.RELAY_HOME = tmp;
|
|
216
|
+
const inst = newInstance({ kind: "root" }, tmp);
|
|
217
|
+
const runId = createRun(tmp, withDefaults({}), inst.token);
|
|
218
|
+
inst.since.set(runId, 0);
|
|
219
|
+
const text = "job j_00000001 finished (done). Call result j_00000001.";
|
|
220
|
+
// Pin all four kinds through the real pendingEvents projection, including the approval
|
|
221
|
+
// request check. No timestamps, run tokens or other private registry fields go on the wire.
|
|
222
|
+
insertNode({ id: "j_00000001", run_id: runId, kind: "job", target: "codex", mode: "read", depth: 1, task: "wire", cwd: tmp });
|
|
223
|
+
db().prepare("INSERT INTO requests (id, run_id, node_id, kind, summary, status, created_at) VALUES (?, ?, ?, 'web', 'fetch', 'pending', 1)").run("q_00000001", runId, "j_00000001");
|
|
224
|
+
for (const kind of ["settled", "approval", "decided", "late"]) {
|
|
225
|
+
db().prepare("INSERT INTO events (run_id, key, kind, item_id, subject, text, created_at) VALUES (?, ?, ?, ?, ?, ?, 1)")
|
|
226
|
+
.run(runId, `wire:${kind}`, kind, "j_00000001", "q_00000001", text);
|
|
227
|
+
}
|
|
228
|
+
snapshot("events.json", pendingEvents(inst, {}).events);
|
|
229
|
+
const notice = signedNotice(inst, db().prepare("SELECT * FROM events WHERE id = 1").get());
|
|
230
|
+
// The format is stable; the authenticator is deliberately fresh for each live server.
|
|
231
|
+
const normalize = (text: string) => text.replace(/[a-f0-9]{32}/g, "<notice-tag>");
|
|
232
|
+
snapshot("notice.txt", normalize(notice) + "\n");
|
|
233
|
+
const socket = path.join(tmp, "i.sock");
|
|
234
|
+
const received = new Promise<string>((resolve) => inbox.once("connection", (c) => {
|
|
235
|
+
let data = "";
|
|
236
|
+
c.setEncoding("utf8");
|
|
237
|
+
c.on("data", (part) => data += part);
|
|
238
|
+
c.on("end", () => resolve(data));
|
|
239
|
+
}));
|
|
240
|
+
await new Promise<void>((resolve, reject) => { inbox.once("error", reject); inbox.listen(socket, resolve); });
|
|
241
|
+
await postNotice(socket, "fixture-token", notice, 1);
|
|
242
|
+
snapshot("inbox.jsonl", normalize(await received));
|
|
243
|
+
} finally {
|
|
244
|
+
if (inbox.listening) await new Promise<void>((resolve, reject) => inbox.close((err) => err ? reject(err) : resolve()));
|
|
245
|
+
closeDbForTests();
|
|
246
|
+
if (old === undefined) delete process.env.RELAY_HOME; else process.env.RELAY_HOME = old;
|
|
247
|
+
fs.rmSync(tmp, { recursive: true, force: true });
|
|
248
|
+
}
|
|
249
|
+
});
|