@jbkjr/relay 0.0.0-stage → 1.2.1
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 +386 -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 +1525 -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 +320 -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 +637 -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 +329 -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 +629 -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 +1502 -0
- package/docs/pinned-codex.md +321 -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,136 @@
|
|
|
1
|
+
import "./helpers.ts";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { test } from "node:test";
|
|
9
|
+
import { resolveNeverPolicy, neverDigest } from "../dist/core/never-policy.js";
|
|
10
|
+
import { screenExtensionCall, extensionToolProblem, neverToolAdapters, normalizeToolUrl, QUALIFIED_NEVER_TOOL_ADAPTERS, type QualifiedToolAdapter, type ExtensionToolIdentity } from "../dist/core/never-tools.js";
|
|
11
|
+
import { resolveNeverEndpoints } from "../dist/core/never-network.js";
|
|
12
|
+
import { codexFlags } from "../dist/backends/codex.js";
|
|
13
|
+
import { configProblem } from "../dist/backends/codex-app.js";
|
|
14
|
+
import { withDefaults } from "../dist/core/config.js";
|
|
15
|
+
import { targetDef } from "../dist/targets/index.js";
|
|
16
|
+
import { offerGateway, type Gateway } from "../dist/mcp/gateway.js";
|
|
17
|
+
import { runtimeEnvironment } from "../dist/core/env-policy.js";
|
|
18
|
+
|
|
19
|
+
const identity: ExtensionToolIdentity = { server: "decoy", version: "1", definitionHash: "trusted-definition", tool: "get", schemaHash: neverDigest({ type: "object" }) };
|
|
20
|
+
const adapter: QualifiedToolAdapter = {
|
|
21
|
+
identity,
|
|
22
|
+
normalize: (args) => ({ complete: true, arguments: args, effects: [{ kind: "endpoint", ...normalizeToolUrl(String(args.url)), addresses: ["192.0.2.50"] }] }),
|
|
23
|
+
};
|
|
24
|
+
const p = () => resolveNeverPolicy({ never: { hosts: ["secret.example"], paths: [{ path: "/private/decoy-secret" }], ports: [{ port: 2525 }] }, builtins: false });
|
|
25
|
+
|
|
26
|
+
test("fixture adapter registration requires both test markers, binds exact decoys and still screens their log effect", async () => {
|
|
27
|
+
const saved = { RELAY_TEST_NEVER_ADAPTERS: process.env.RELAY_TEST_NEVER_ADAPTERS, NODE_TEST_CONTEXT: process.env.NODE_TEST_CONTEXT };
|
|
28
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), "relay-adapter-test-"));
|
|
29
|
+
const log = path.join(root, "log");
|
|
30
|
+
const defs = { ext: { command: process.execPath, args: [fileURLToPath(new URL("./stubs/ext-server.mjs", import.meta.url))], env: { EXT_LOG: log } } };
|
|
31
|
+
try {
|
|
32
|
+
delete process.env.RELAY_TEST_NEVER_ADAPTERS;
|
|
33
|
+
assert.equal((await neverToolAdapters(defs)).length, 0);
|
|
34
|
+
process.env.RELAY_TEST_NEVER_ADAPTERS = "1";
|
|
35
|
+
delete process.env.NODE_TEST_CONTEXT;
|
|
36
|
+
assert.equal((await neverToolAdapters(defs)).length, 0, "a production environment flag is insufficient");
|
|
37
|
+
assert.equal(runtimeEnvironment({ RELAY_TEST_NEVER_ADAPTERS: "1" }).RELAY_TEST_NEVER_ADAPTERS, undefined);
|
|
38
|
+
process.env.NODE_TEST_CONTEXT = "child-v8";
|
|
39
|
+
const catalog = await neverToolAdapters(defs);
|
|
40
|
+
assert.equal(catalog.length, 2);
|
|
41
|
+
assert.equal(QUALIFIED_NEVER_TOOL_ADAPTERS.length, 0, "production catalog is not mutated");
|
|
42
|
+
const inherited = runtimeEnvironment({ RELAY_TEST_NEVER_ADAPTERS: "1", NODE_TEST_CONTEXT: "child-v8" });
|
|
43
|
+
assert.equal(inherited.RELAY_TEST_NEVER_ADAPTERS, "1");
|
|
44
|
+
assert.equal(inherited.NODE_TEST_CONTEXT, "child-v8");
|
|
45
|
+
const module = new URL("../dist/core/never-tools.js", import.meta.url).href;
|
|
46
|
+
const child = spawnSync(process.execPath, ["--input-type=module", "-e", `import { neverToolAdapters } from ${JSON.stringify(module)}; const catalog = await neverToolAdapters(JSON.parse(process.argv[1])); process.stdout.write(JSON.stringify(catalog.map(a => a.identity.tool)));`, JSON.stringify(defs)], { env: { ...inherited, HOME: os.homedir() }, encoding: "utf8" });
|
|
47
|
+
assert.equal(child.status, 0, child.stderr);
|
|
48
|
+
assert.deepEqual(JSON.parse(child.stdout), ["echo", "send"], "trusted worker environment carries registration across processes");
|
|
49
|
+
for (const def of [{ command: "/bin/sh", args: defs.ext.args }, { command: process.execPath, args: ["/unknown/server.mjs"] }, { command: process.execPath, args: [...defs.ext.args, "extra"] }]) {
|
|
50
|
+
assert.equal((await neverToolAdapters({ ext: def })).length, 0, "arbitrary server definitions cannot opt into fixture semantics");
|
|
51
|
+
}
|
|
52
|
+
const echo = catalog.find(a => a.identity.tool === "echo")!;
|
|
53
|
+
assert.equal((await screenExtensionCall(resolveNeverPolicy({ builtins: false }), echo.identity, { text: "decoy" }, catalog)).allow, true);
|
|
54
|
+
const denied = resolveNeverPolicy({ never: { paths: [{ path: log }] }, builtins: false });
|
|
55
|
+
assert.equal((await screenExtensionCall(denied, echo.identity, { text: "decoy" }, catalog)).allow, false);
|
|
56
|
+
assert.equal(fs.existsSync(log), false, "screening never invokes the server");
|
|
57
|
+
} finally {
|
|
58
|
+
for (const [k, v] of Object.entries(saved)) if (v === undefined) delete process.env[k]; else process.env[k] = v;
|
|
59
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("extension screen requires pinned tool semantics, withholds opaque and hosted web tools", () => {
|
|
64
|
+
assert.match(extensionToolProblem(identity, [])!, /qualified/);
|
|
65
|
+
assert.equal(extensionToolProblem(identity, [adapter]), null);
|
|
66
|
+
for (const field of ["version", "definitionHash", "schemaHash", "server", "tool"]) assert.ok(extensionToolProblem({ ...identity, [field]: "changed" }, [adapter]), field);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("semantic URL screen covers IDNA, defaults, mapped IP, ports and compound resources", async () => {
|
|
70
|
+
const policy = p();
|
|
71
|
+
const endpoints = await resolveNeverEndpoints(policy, async () => ({ addresses: ["192.0.2.40"], cnames: [] }));
|
|
72
|
+
for (const url of ["https://SECRET.example./", "http://[::ffff:192.0.2.40]/", "http://allowed.example:2525/"]) {
|
|
73
|
+
assert.equal((await screenExtensionCall(policy, identity, { url }, [adapter], endpoints)).allow, false, url);
|
|
74
|
+
}
|
|
75
|
+
assert.equal((await screenExtensionCall(policy, identity, { url: "https://allowed.example/a?url=secret.example" }, [adapter], endpoints)).allow, true);
|
|
76
|
+
const cname: QualifiedToolAdapter = { identity, normalize: args => ({ complete: true, arguments: args, effects: [{ kind: "endpoint", host: "allowed.example", cnames: ["SECRET.example."], port: 443, transport: "tcp", addresses: ["192.0.2.99"] }] }) };
|
|
77
|
+
assert.equal((await screenExtensionCall(policy, identity, {}, [cname], endpoints)).allow, false);
|
|
78
|
+
assert.equal(normalizeToolUrl("HTTPS://BÜCHER.example./").host, "xn--bcher-kva.example");
|
|
79
|
+
assert.equal(normalizeToolUrl("https://allowed.example/").port, 443);
|
|
80
|
+
const compound: QualifiedToolAdapter = { identity, normalize: args => ({ complete: true, arguments: args, effects: [{ kind: "path", path: "/tmp/allowed", access: "read" }, { kind: "path", path: "/private/decoy-secret/item", access: "read" }] }) };
|
|
81
|
+
assert.equal((await screenExtensionCall(policy, identity, {}, [compound], endpoints)).allow, false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("implicit effects, unbounded redirects, opaque commands and stale/missing endpoint sets fail closed", async () => {
|
|
85
|
+
const policy = p();
|
|
86
|
+
assert.equal((await screenExtensionCall(policy, identity, { url: "https://allowed.example" }, [adapter])).allow, false);
|
|
87
|
+
const implicit: QualifiedToolAdapter = { identity, normalize: args => ({ complete: false, arguments: args, effects: [] }) };
|
|
88
|
+
assert.equal((await screenExtensionCall(policy, identity, {}, [implicit])).allow, false);
|
|
89
|
+
const opaque: QualifiedToolAdapter = { identity, normalize: () => { throw new Error("unbounded redirects/implicit resource"); } };
|
|
90
|
+
assert.equal((await screenExtensionCall(policy, identity, {}, [opaque])).allow, false);
|
|
91
|
+
await assert.rejects(resolveNeverEndpoints(policy, async () => ({ addresses: [], cnames: [] })), /resolve/);
|
|
92
|
+
const stale = await resolveNeverEndpoints(policy, async () => ({ addresses: ["192.0.2.40"], cnames: [] }), { now: 0, ttlMs: 1 });
|
|
93
|
+
assert.equal((await screenExtensionCall(policy, identity, { url: "https://allowed.example" }, [adapter], stale)).allow, false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test("never hosts disable hosted web even with standing network, and effective readback is mandatory", () => {
|
|
97
|
+
const policy = p();
|
|
98
|
+
const spec: any = { target: targetDef("codex"), prompt: "", cwd: "/tmp", dir: "/tmp", logPath: "/tmp/log", access: "read", relay: null, config: withDefaults({}), markers: { runId: "test", nodeId: "test", depth: 1 }, grant: { network: true }, neverPolicy: policy };
|
|
99
|
+
for (const sessionId of [undefined, "resume"]) {
|
|
100
|
+
const flags = codexFlags({ ...spec, sessionId }, [], {});
|
|
101
|
+
assert.ok(flags.c.includes('web_search="disabled"'));
|
|
102
|
+
assert.equal(flags.expect.webSearch, "disabled");
|
|
103
|
+
const effective = { default_permissions: flags.expect.permissions.id, permissions: { relay: flags.expect.permissions.profile }, features: flags.expect.features, skills: { config: [] } };
|
|
104
|
+
assert.match(configProblem({ ...effective, web_search: "live" }, flags.expect)!, /web_search/);
|
|
105
|
+
assert.match(configProblem(effective, flags.expect)!, /web_search/);
|
|
106
|
+
assert.doesNotMatch(configProblem({ ...effective, web_search: "disabled" }, flags.expect) ?? "", /web_search/);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("central gateway refuses before consent and forwarding, rechecks after consent, and screens preauthorized calls", async () => {
|
|
111
|
+
const policy = resolveNeverPolicy({ never: { paths: [{ path: "/private/decoy-secret" }] }, builtins: false });
|
|
112
|
+
const local: QualifiedToolAdapter = { identity, normalize: args => ({ complete: true, arguments: args, effects: [{ kind: "path", path: String(args.path), access: "read" }] }) };
|
|
113
|
+
let called = 0, asked = 0, screens = 0, denyAfterConsent = false;
|
|
114
|
+
let handler: any;
|
|
115
|
+
const tool: any = { name: "decoy__get", server: "decoy", tool: "get", identity, description: "decoy", schema: {}, preauthorized: false, client: { callTool: async () => { called++; return { content: [] }; } } };
|
|
116
|
+
const gw: Gateway = { tools: [tool], warnings: [], close: async () => {}, screen: async (t, args) => {
|
|
117
|
+
screens++;
|
|
118
|
+
if (denyAfterConsent) return { allow: false, reason: "new never addition", policyHash: "new" };
|
|
119
|
+
return screenExtensionCall(policy, t.identity, args, [local]);
|
|
120
|
+
} };
|
|
121
|
+
const server: any = { registerTool: (_name: string, _config: unknown, h: any) => { handler = h; } };
|
|
122
|
+
const offer = (afterConsent = false) => offerGateway(server, gw, async () => { asked++; denyAfterConsent = afterConsent; return { allow: true }; }, () => undefined, () => null);
|
|
123
|
+
offer();
|
|
124
|
+
assert.equal((await handler({ path: "/private/decoy-secret/file" }, {})).isError, true);
|
|
125
|
+
assert.equal(called, 0); assert.equal(asked, 0);
|
|
126
|
+
await handler({ path: "/tmp/allowed-decoy" }, {});
|
|
127
|
+
assert.equal(called, 1); assert.equal(asked, 1);
|
|
128
|
+
offer(true);
|
|
129
|
+
assert.equal((await handler({ path: "/tmp/allowed-decoy" }, {})).isError, true);
|
|
130
|
+
assert.equal(called, 1, "a policy addition during approval reaches no server");
|
|
131
|
+
denyAfterConsent = false; tool.preauthorized = true; offer();
|
|
132
|
+
const before = screens;
|
|
133
|
+
await handler({ path: "/tmp/allowed-decoy" }, {});
|
|
134
|
+
assert.equal(called, 2); assert.equal(screens - before, 2);
|
|
135
|
+
assert.equal(asked, 2, "preauthorization does not skip the policy screen");
|
|
136
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Import before relay modules: env-policy snapshots process.env at module evaluation time.
|
|
2
|
+
// Keeping this independent of relay lets in-process root authorities and their workers use the
|
|
3
|
+
// same disposable home as the test registry, even when helpers.ts imports relay itself.
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { removeTestNativeTempAlias } from "./native-temp-alias.ts";
|
|
7
|
+
import { TEST_TEMP_ROOT } from "./temp-root.ts";
|
|
8
|
+
|
|
9
|
+
export const HOME_VARS = ["HOME", "CODEX_HOME", "CLAUDE_CONFIG_DIR", "COPILOT_HOME", "GROK_HOME", "GROK_AUTH_PATH", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME", "XDG_CACHE_HOME", "RELAY_HOME", "RELAY_WORKTREES", "RELAY_CONFIG"];
|
|
10
|
+
// Keep HOME and every fixture under the shared socket-safe temporary root.
|
|
11
|
+
export const TEST_HOME_PARENT = TEST_TEMP_ROOT;
|
|
12
|
+
const home = fs.realpathSync(fs.mkdtempSync(path.join(TEST_HOME_PARENT, "rth-")));
|
|
13
|
+
for (const k of HOME_VARS) delete process.env[k];
|
|
14
|
+
process.env.HOME = home;
|
|
15
|
+
process.on("exit", () => {
|
|
16
|
+
removeTestNativeTempAlias(home);
|
|
17
|
+
fs.rmSync(home, { recursive: true, force: true });
|
|
18
|
+
});
|