@buildanagent/harness 0.0.0-stage → 0.1.0-alpha.29
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 +54 -0
- package/LICENSE-APACHE +202 -0
- package/LICENSE-MIT +21 -0
- package/README.md +822 -2
- package/dist/ablation.d.ts +2 -0
- package/dist/ablation.js +3 -0
- package/dist/ablation.js.map +1 -0
- package/dist/completion/check.d.ts +64 -0
- package/dist/completion/check.js +152 -0
- package/dist/completion/check.js.map +1 -0
- package/dist/completion/checks.d.ts +45 -0
- package/dist/completion/checks.js +173 -0
- package/dist/completion/checks.js.map +1 -0
- package/dist/completion/flags.d.ts +25 -0
- package/dist/completion/flags.js +87 -0
- package/dist/completion/flags.js.map +1 -0
- package/dist/completion/index.d.ts +8 -0
- package/dist/completion/index.js +9 -0
- package/dist/completion/index.js.map +1 -0
- package/dist/completion/snapshot.d.ts +33 -0
- package/dist/completion/snapshot.js +83 -0
- package/dist/completion/snapshot.js.map +1 -0
- package/dist/context/cap.d.ts +32 -0
- package/dist/context/cap.js +50 -0
- package/dist/context/cap.js.map +1 -0
- package/dist/context/estimate.d.ts +18 -0
- package/dist/context/estimate.js +20 -0
- package/dist/context/estimate.js.map +1 -0
- package/dist/context/file-spill.d.ts +15 -0
- package/dist/context/file-spill.js +40 -0
- package/dist/context/file-spill.js.map +1 -0
- package/dist/context/index.d.ts +10 -0
- package/dist/context/index.js +10 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/mask.d.ts +27 -0
- package/dist/context/mask.js +71 -0
- package/dist/context/mask.js.map +1 -0
- package/dist/context/mid-turn.d.ts +40 -0
- package/dist/context/mid-turn.js +82 -0
- package/dist/context/mid-turn.js.map +1 -0
- package/dist/context/policy.d.ts +9 -0
- package/dist/context/policy.js +140 -0
- package/dist/context/policy.js.map +1 -0
- package/dist/context/spill-ledger.d.ts +25 -0
- package/dist/context/spill-ledger.js +54 -0
- package/dist/context/spill-ledger.js.map +1 -0
- package/dist/context/spill.d.ts +10 -0
- package/dist/context/spill.js +18 -0
- package/dist/context/spill.js.map +1 -0
- package/dist/context/summarize.d.ts +53 -0
- package/dist/context/summarize.js +204 -0
- package/dist/context/summarize.js.map +1 -0
- package/dist/context/summary-template.d.ts +29 -0
- package/dist/context/summary-template.js +69 -0
- package/dist/context/summary-template.js.map +1 -0
- package/dist/context/types.d.ts +150 -0
- package/dist/context/types.js +2 -0
- package/dist/context/types.js.map +1 -0
- package/dist/context/write-cap.d.ts +19 -0
- package/dist/context/write-cap.js +41 -0
- package/dist/context/write-cap.js.map +1 -0
- package/dist/create-harness.d.ts +7 -0
- package/dist/create-harness.js +21 -0
- package/dist/create-harness.js.map +1 -0
- package/dist/credentials/addresses.d.ts +14 -0
- package/dist/credentials/addresses.js +144 -0
- package/dist/credentials/addresses.js.map +1 -0
- package/dist/credentials/allowlist.d.ts +54 -0
- package/dist/credentials/allowlist.js +134 -0
- package/dist/credentials/allowlist.js.map +1 -0
- package/dist/credentials/egress-policy.d.ts +69 -0
- package/dist/credentials/egress-policy.js +170 -0
- package/dist/credentials/egress-policy.js.map +1 -0
- package/dist/credentials/egress-proxy.d.ts +82 -0
- package/dist/credentials/egress-proxy.js +650 -0
- package/dist/credentials/egress-proxy.js.map +1 -0
- package/dist/credentials/git-route.d.ts +68 -0
- package/dist/credentials/git-route.js +288 -0
- package/dist/credentials/git-route.js.map +1 -0
- package/dist/credentials/index.d.ts +13 -0
- package/dist/credentials/index.js +14 -0
- package/dist/credentials/index.js.map +1 -0
- package/dist/credentials/scrub.d.ts +23 -0
- package/dist/credentials/scrub.js +115 -0
- package/dist/credentials/scrub.js.map +1 -0
- package/dist/errors.d.ts +60 -0
- package/dist/errors.js +67 -0
- package/dist/errors.js.map +1 -0
- package/dist/extensions/compose.d.ts +27 -0
- package/dist/extensions/compose.js +83 -0
- package/dist/extensions/compose.js.map +1 -0
- package/dist/extensions/context-files-node.d.ts +28 -0
- package/dist/extensions/context-files-node.js +74 -0
- package/dist/extensions/context-files-node.js.map +1 -0
- package/dist/extensions/context-files.d.ts +68 -0
- package/dist/extensions/context-files.js +214 -0
- package/dist/extensions/context-files.js.map +1 -0
- package/dist/extensions/digest.d.ts +6 -0
- package/dist/extensions/digest.js +68 -0
- package/dist/extensions/digest.js.map +1 -0
- package/dist/extensions/index.d.ts +10 -0
- package/dist/extensions/index.js +10 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/load.d.ts +42 -0
- package/dist/extensions/load.js +211 -0
- package/dist/extensions/load.js.map +1 -0
- package/dist/extensions/lock.d.ts +8 -0
- package/dist/extensions/lock.js +95 -0
- package/dist/extensions/lock.js.map +1 -0
- package/dist/extensions/node.d.ts +10 -0
- package/dist/extensions/node.js +11 -0
- package/dist/extensions/node.js.map +1 -0
- package/dist/extensions/project-dirs.d.ts +24 -0
- package/dist/extensions/project-dirs.js +97 -0
- package/dist/extensions/project-dirs.js.map +1 -0
- package/dist/extensions/skills-node.d.ts +34 -0
- package/dist/extensions/skills-node.js +123 -0
- package/dist/extensions/skills-node.js.map +1 -0
- package/dist/extensions/skills.d.ts +51 -0
- package/dist/extensions/skills.js +175 -0
- package/dist/extensions/skills.js.map +1 -0
- package/dist/extensions/trust-file.d.ts +3 -0
- package/dist/extensions/trust-file.js +62 -0
- package/dist/extensions/trust-file.js.map +1 -0
- package/dist/extensions/trust-store-node.d.ts +10 -0
- package/dist/extensions/trust-store-node.js +33 -0
- package/dist/extensions/trust-store-node.js.map +1 -0
- package/dist/extensions/types.d.ts +42 -0
- package/dist/extensions/types.js +2 -0
- package/dist/extensions/types.js.map +1 -0
- package/dist/harness.d.ts +156 -0
- package/dist/harness.js +2 -0
- package/dist/harness.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/connection.d.ts +22 -0
- package/dist/mcp/connection.js +267 -0
- package/dist/mcp/connection.js.map +1 -0
- package/dist/mcp/content.d.ts +27 -0
- package/dist/mcp/content.js +177 -0
- package/dist/mcp/content.js.map +1 -0
- package/dist/mcp/errors.d.ts +19 -0
- package/dist/mcp/errors.js +21 -0
- package/dist/mcp/errors.js.map +1 -0
- package/dist/mcp/index.d.ts +10 -0
- package/dist/mcp/index.js +10 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/manager.d.ts +7 -0
- package/dist/mcp/manager.js +173 -0
- package/dist/mcp/manager.js.map +1 -0
- package/dist/mcp/record.d.ts +7 -0
- package/dist/mcp/record.js +20 -0
- package/dist/mcp/record.js.map +1 -0
- package/dist/mcp/stdio.d.ts +39 -0
- package/dist/mcp/stdio.js +382 -0
- package/dist/mcp/stdio.js.map +1 -0
- package/dist/mcp/types.d.ts +172 -0
- package/dist/mcp/types.js +2 -0
- package/dist/mcp/types.js.map +1 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.js +3 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/permissions/default-rules.d.ts +7 -0
- package/dist/permissions/default-rules.js +42 -0
- package/dist/permissions/default-rules.js.map +1 -0
- package/dist/permissions/errors.d.ts +11 -0
- package/dist/permissions/errors.js +14 -0
- package/dist/permissions/errors.js.map +1 -0
- package/dist/permissions/index.d.ts +9 -0
- package/dist/permissions/index.js +9 -0
- package/dist/permissions/index.js.map +1 -0
- package/dist/permissions/match.d.ts +33 -0
- package/dist/permissions/match.js +287 -0
- package/dist/permissions/match.js.map +1 -0
- package/dist/permissions/pipeline.d.ts +9 -0
- package/dist/permissions/pipeline.js +235 -0
- package/dist/permissions/pipeline.js.map +1 -0
- package/dist/permissions/rules.d.ts +22 -0
- package/dist/permissions/rules.js +74 -0
- package/dist/permissions/rules.js.map +1 -0
- package/dist/permissions/shadow.d.ts +5 -0
- package/dist/permissions/shadow.js +22 -0
- package/dist/permissions/shadow.js.map +1 -0
- package/dist/permissions/types.d.ts +104 -0
- package/dist/permissions/types.js +2 -0
- package/dist/permissions/types.js.map +1 -0
- package/dist/sandbox/base.d.ts +45 -0
- package/dist/sandbox/base.js +74 -0
- package/dist/sandbox/base.js.map +1 -0
- package/dist/sandbox/docker/index.d.ts +41 -0
- package/dist/sandbox/docker/index.js +497 -0
- package/dist/sandbox/docker/index.js.map +1 -0
- package/dist/sandbox/errors.d.ts +44 -0
- package/dist/sandbox/errors.js +57 -0
- package/dist/sandbox/errors.js.map +1 -0
- package/dist/sandbox/host-files.d.ts +65 -0
- package/dist/sandbox/host-files.js +258 -0
- package/dist/sandbox/host-files.js.map +1 -0
- package/dist/sandbox/index.d.ts +10 -0
- package/dist/sandbox/index.js +10 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/none.d.ts +17 -0
- package/dist/sandbox/none.js +108 -0
- package/dist/sandbox/none.js.map +1 -0
- package/dist/sandbox/policy.d.ts +49 -0
- package/dist/sandbox/policy.js +149 -0
- package/dist/sandbox/policy.js.map +1 -0
- package/dist/sandbox/process.d.ts +61 -0
- package/dist/sandbox/process.js +253 -0
- package/dist/sandbox/process.js.map +1 -0
- package/dist/sandbox/spawn-env.d.ts +20 -0
- package/dist/sandbox/spawn-env.js +128 -0
- package/dist/sandbox/spawn-env.js.map +1 -0
- package/dist/sandbox/srt/index.d.ts +38 -0
- package/dist/sandbox/srt/index.js +283 -0
- package/dist/sandbox/srt/index.js.map +1 -0
- package/dist/sandbox/srt/settings.d.ts +60 -0
- package/dist/sandbox/srt/settings.js +84 -0
- package/dist/sandbox/srt/settings.js.map +1 -0
- package/dist/sandbox/types.d.ts +125 -0
- package/dist/sandbox/types.js +6 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/server/answers.d.ts +16 -0
- package/dist/server/answers.js +43 -0
- package/dist/server/answers.js.map +1 -0
- package/dist/server/connection.d.ts +99 -0
- package/dist/server/connection.js +309 -0
- package/dist/server/connection.js.map +1 -0
- package/dist/server/dispatcher.d.ts +86 -0
- package/dist/server/dispatcher.js +800 -0
- package/dist/server/dispatcher.js.map +1 -0
- package/dist/server/index.d.ts +13 -0
- package/dist/server/index.js +12 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/local-transport.d.ts +44 -0
- package/dist/server/local-transport.js +103 -0
- package/dist/server/local-transport.js.map +1 -0
- package/dist/server/outbox.d.ts +31 -0
- package/dist/server/outbox.js +130 -0
- package/dist/server/outbox.js.map +1 -0
- package/dist/server/params.d.ts +25 -0
- package/dist/server/params.js +112 -0
- package/dist/server/params.js.map +1 -0
- package/dist/server/protocol.schema.json +2448 -0
- package/dist/server/rpc-session.d.ts +43 -0
- package/dist/server/rpc-session.js +167 -0
- package/dist/server/rpc-session.js.map +1 -0
- package/dist/server/stdio-streams.d.ts +67 -0
- package/dist/server/stdio-streams.js +218 -0
- package/dist/server/stdio-streams.js.map +1 -0
- package/dist/server/stdio.d.ts +59 -0
- package/dist/server/stdio.js +189 -0
- package/dist/server/stdio.js.map +1 -0
- package/dist/server/websocket.d.ts +106 -0
- package/dist/server/websocket.js +327 -0
- package/dist/server/websocket.js.map +1 -0
- package/dist/session/approvals.d.ts +81 -0
- package/dist/session/approvals.js +217 -0
- package/dist/session/approvals.js.map +1 -0
- package/dist/session/code-call-log.d.ts +42 -0
- package/dist/session/code-call-log.js +63 -0
- package/dist/session/code-call-log.js.map +1 -0
- package/dist/session/code-call-result.d.ts +19 -0
- package/dist/session/code-call-result.js +95 -0
- package/dist/session/code-call-result.js.map +1 -0
- package/dist/session/code-call.d.ts +49 -0
- package/dist/session/code-call.js +345 -0
- package/dist/session/code-call.js.map +1 -0
- package/dist/session/effect-scope.d.ts +11 -0
- package/dist/session/effect-scope.js +10 -0
- package/dist/session/effect-scope.js.map +1 -0
- package/dist/session/errors.d.ts +19 -0
- package/dist/session/errors.js +27 -0
- package/dist/session/errors.js.map +1 -0
- package/dist/session/file-index.d.ts +8 -0
- package/dist/session/file-index.js +70 -0
- package/dist/session/file-index.js.map +1 -0
- package/dist/session/file-key-store.d.ts +16 -0
- package/dist/session/file-key-store.js +169 -0
- package/dist/session/file-key-store.js.map +1 -0
- package/dist/session/file-lock.d.ts +52 -0
- package/dist/session/file-lock.js +324 -0
- package/dist/session/file-lock.js.map +1 -0
- package/dist/session/index.d.ts +22 -0
- package/dist/session/index.js +20 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/jsonl-store.d.ts +37 -0
- package/dist/session/jsonl-store.js +386 -0
- package/dist/session/jsonl-store.js.map +1 -0
- package/dist/session/jsonl.d.ts +9 -0
- package/dist/session/jsonl.js +10 -0
- package/dist/session/jsonl.js.map +1 -0
- package/dist/session/lock.d.ts +19 -0
- package/dist/session/lock.js +2 -0
- package/dist/session/lock.js.map +1 -0
- package/dist/session/memory-store.d.ts +12 -0
- package/dist/session/memory-store.js +60 -0
- package/dist/session/memory-store.js.map +1 -0
- package/dist/session/migrate.d.ts +41 -0
- package/dist/session/migrate.js +86 -0
- package/dist/session/migrate.js.map +1 -0
- package/dist/session/pointer.d.ts +15 -0
- package/dist/session/pointer.js +22 -0
- package/dist/session/pointer.js.map +1 -0
- package/dist/session/rebuild.d.ts +53 -0
- package/dist/session/rebuild.js +230 -0
- package/dist/session/rebuild.js.map +1 -0
- package/dist/session/resume.d.ts +26 -0
- package/dist/session/resume.js +128 -0
- package/dist/session/resume.js.map +1 -0
- package/dist/session/retention.d.ts +97 -0
- package/dist/session/retention.js +702 -0
- package/dist/session/retention.js.map +1 -0
- package/dist/session/runner.d.ts +156 -0
- package/dist/session/runner.js +656 -0
- package/dist/session/runner.js.map +1 -0
- package/dist/session/scheduler.d.ts +47 -0
- package/dist/session/scheduler.js +85 -0
- package/dist/session/scheduler.js.map +1 -0
- package/dist/session/secret-key-store.d.ts +47 -0
- package/dist/session/secret-key-store.js +79 -0
- package/dist/session/secret-key-store.js.map +1 -0
- package/dist/session/session.d.ts +106 -0
- package/dist/session/session.js +353 -0
- package/dist/session/session.js.map +1 -0
- package/dist/session/sticky.d.ts +48 -0
- package/dist/session/sticky.js +232 -0
- package/dist/session/sticky.js.map +1 -0
- package/dist/session/store.d.ts +108 -0
- package/dist/session/store.js +163 -0
- package/dist/session/store.js.map +1 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +3 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/testing/fake-sandbox.d.ts +52 -0
- package/dist/testing/fake-sandbox.js +370 -0
- package/dist/testing/fake-sandbox.js.map +1 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.js +11 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/key-store-conformance.d.ts +22 -0
- package/dist/testing/key-store-conformance.js +97 -0
- package/dist/testing/key-store-conformance.js.map +1 -0
- package/dist/testing/run-cases.d.ts +21 -0
- package/dist/testing/run-cases.js +20 -0
- package/dist/testing/run-cases.js.map +1 -0
- package/dist/testing/sandbox-conformance.d.ts +64 -0
- package/dist/testing/sandbox-conformance.js +468 -0
- package/dist/testing/sandbox-conformance.js.map +1 -0
- package/dist/testing/scheduler-conformance.d.ts +32 -0
- package/dist/testing/scheduler-conformance.js +72 -0
- package/dist/testing/scheduler-conformance.js.map +1 -0
- package/dist/testing/store-conformance.d.ts +21 -0
- package/dist/testing/store-conformance.js +320 -0
- package/dist/testing/store-conformance.js.map +1 -0
- package/dist/tools/builtins/bash.d.ts +9 -0
- package/dist/tools/builtins/bash.js +75 -0
- package/dist/tools/builtins/bash.js.map +1 -0
- package/dist/tools/builtins/builtins.d.ts +38 -0
- package/dist/tools/builtins/builtins.js +48 -0
- package/dist/tools/builtins/builtins.js.map +1 -0
- package/dist/tools/builtins/descriptions.d.ts +69 -0
- package/dist/tools/builtins/descriptions.js +94 -0
- package/dist/tools/builtins/descriptions.js.map +1 -0
- package/dist/tools/builtins/fetch.d.ts +12 -0
- package/dist/tools/builtins/fetch.js +157 -0
- package/dist/tools/builtins/fetch.js.map +1 -0
- package/dist/tools/builtins/files.d.ts +27 -0
- package/dist/tools/builtins/files.js +274 -0
- package/dist/tools/builtins/files.js.map +1 -0
- package/dist/tools/builtins/paths.d.ts +30 -0
- package/dist/tools/builtins/paths.js +62 -0
- package/dist/tools/builtins/paths.js.map +1 -0
- package/dist/tools/builtins/results.d.ts +15 -0
- package/dist/tools/builtins/results.js +31 -0
- package/dist/tools/builtins/results.js.map +1 -0
- package/dist/tools/builtins/search.d.ts +18 -0
- package/dist/tools/builtins/search.js +217 -0
- package/dist/tools/builtins/search.js.map +1 -0
- package/dist/tools/errors.d.ts +13 -0
- package/dist/tools/errors.js +17 -0
- package/dist/tools/errors.js.map +1 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.js +11 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/registry.d.ts +3 -0
- package/dist/tools/registry.js +234 -0
- package/dist/tools/registry.js.map +1 -0
- package/dist/tools/tool-search.d.ts +30 -0
- package/dist/tools/tool-search.js +118 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/types.d.ts +106 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/llms.txt +469 -0
- package/package.json +118 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The key store conformance suite: what every `KeyStore` must do. `load()` returns a ring a signer can use, and the
|
|
3
|
+
* same ring each time until something changes it. `rotate()` and `prune()` are optional, because a read-only secret
|
|
4
|
+
* is a valid store (ADR 0035), so their cases skip with a reason when a store leaves them out. The cases import no
|
|
5
|
+
* test runner and no Node module, so any runner can call them, in workerd too. No message names a key's bytes.
|
|
6
|
+
*/
|
|
7
|
+
import { hmacSigner } from "@buildanagent/agent-safety";
|
|
8
|
+
import { runCases } from "./run-cases.js";
|
|
9
|
+
function check(condition, message) {
|
|
10
|
+
if (!condition)
|
|
11
|
+
throw new Error(`KeyStore conformance: ${message}`);
|
|
12
|
+
}
|
|
13
|
+
const PAYLOAD = new TextEncoder().encode("key store conformance payload");
|
|
14
|
+
function sameBytes(a, b) {
|
|
15
|
+
if (a === undefined || b === undefined || a.length !== b.length)
|
|
16
|
+
return false;
|
|
17
|
+
return a.every((byte, index) => byte === b[index]);
|
|
18
|
+
}
|
|
19
|
+
function sameRing(a, b) {
|
|
20
|
+
const ids = Object.keys(a.keys).sort();
|
|
21
|
+
const other = Object.keys(b.keys).sort();
|
|
22
|
+
return (a.current === b.current &&
|
|
23
|
+
ids.length === other.length &&
|
|
24
|
+
ids.every((id, index) => id === other[index] && sameBytes(a.keys[id], b.keys[id])));
|
|
25
|
+
}
|
|
26
|
+
async function loadsUsableRing(store) {
|
|
27
|
+
const ring = await store.load();
|
|
28
|
+
check(typeof ring.current === "string", "the ring has no current key id");
|
|
29
|
+
check(ring.keys[ring.current] instanceof Uint8Array, "the current key id is not in the ring's keys");
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
async function loadsSameRing(store) {
|
|
33
|
+
check(sameRing(await store.load(), await store.load()), "two loads returned different rings");
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
async function signsAndVerifies(store) {
|
|
37
|
+
const signer = hmacSigner(await store.load());
|
|
38
|
+
const signature = await signer.sign(PAYLOAD);
|
|
39
|
+
check(await signer.verify(signer.keyId, PAYLOAD, signature), "a signature from the ring did not verify");
|
|
40
|
+
const reloaded = hmacSigner(await store.load());
|
|
41
|
+
check(await reloaded.verify(signer.keyId, PAYLOAD, signature), "a reloaded ring did not verify the signature");
|
|
42
|
+
check(!(await reloaded.verify(signer.keyId, new TextEncoder().encode("another payload"), signature)), "a signature verified for another payload");
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
async function rotates(store) {
|
|
46
|
+
if (store.rotate === undefined)
|
|
47
|
+
return { skipped: "the store is read-only: it has no rotate()" };
|
|
48
|
+
const before = await store.load();
|
|
49
|
+
const signature = await hmacSigner(before).sign(PAYLOAD);
|
|
50
|
+
const id = await store.rotate();
|
|
51
|
+
check(id !== before.current, "rotate returned the id of the key that was already current");
|
|
52
|
+
const after = await store.load();
|
|
53
|
+
check(after.current === id, "the rotated key is not current");
|
|
54
|
+
check(sameBytes(after.keys[before.current], before.keys[before.current]), "the old key left the ring");
|
|
55
|
+
check(await hmacSigner(after).verify(before.current, PAYLOAD, signature), "a signature under the old key did not verify after the rotation");
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
async function prunes(store) {
|
|
59
|
+
if (store.prune === undefined)
|
|
60
|
+
return { skipped: "the store is read-only: it has no prune()" };
|
|
61
|
+
// With rotate() the ring holds three keys: one in use, one free to remove, and the current one.
|
|
62
|
+
const inUse = new Set();
|
|
63
|
+
if (store.rotate !== undefined) {
|
|
64
|
+
inUse.add((await store.load()).current);
|
|
65
|
+
await store.rotate();
|
|
66
|
+
await store.rotate();
|
|
67
|
+
}
|
|
68
|
+
const before = await store.load();
|
|
69
|
+
const removed = await store.prune(inUse);
|
|
70
|
+
const after = await store.load();
|
|
71
|
+
check(after.current === before.current, "prune changed the current key");
|
|
72
|
+
check(after.keys[after.current] instanceof Uint8Array, "prune removed the current key");
|
|
73
|
+
check([...inUse].every((id) => sameBytes(after.keys[id], before.keys[id])), "prune removed a key that a pause still names");
|
|
74
|
+
const gone = Object.keys(before.keys)
|
|
75
|
+
.filter((id) => !(id in after.keys))
|
|
76
|
+
.sort();
|
|
77
|
+
check(removed.length === gone.length && [...removed].sort().every((id, index) => id === gone[index]), "prune's returned ids are not the ids it removed");
|
|
78
|
+
if (store.rotate !== undefined)
|
|
79
|
+
check(gone.length === 1, "prune did not remove the one key nothing names");
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
const CASES = [
|
|
83
|
+
["load returns a ring whose current key is in its keys", loadsUsableRing],
|
|
84
|
+
["load twice returns the same ring", loadsSameRing],
|
|
85
|
+
["the loaded ring signs and verifies through hmacSigner", signsAndVerifies],
|
|
86
|
+
["rotate adds a new current key and keeps the old one", rotates],
|
|
87
|
+
["prune keeps the current key and every key in use, and returns the ids it removed", prunes],
|
|
88
|
+
];
|
|
89
|
+
/** The cases, each run against a store from `factory`. */
|
|
90
|
+
export function keyStoreConformanceCases(factory) {
|
|
91
|
+
return CASES.map(([name, body]) => ({ name, run: async () => body((await factory()).store) }));
|
|
92
|
+
}
|
|
93
|
+
/** Runs every case and reports which passed, which skipped and which failed. */
|
|
94
|
+
export function runKeyStoreConformance(factory) {
|
|
95
|
+
return runCases(keyStoreConformanceCases(factory));
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=key-store-conformance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-store-conformance.js","sourceRoot":"","sources":["../../src/testing/key-store-conformance.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAA+B,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAsC,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAgB9E,SAAS,KAAK,CAAC,SAAkB,EAAE,OAAe;IAChD,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,OAAO,EAAE,CAAC,CAAC;AACtE,CAAC;AAED,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,+BAA+B,CAAC,CAAC;AAE1E,SAAS,SAAS,CAAC,CAAyB,EAAE,CAAyB;IACrE,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAC9E,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,QAAQ,CAAC,CAAU,EAAE,CAAU;IACtC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;IACvC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,C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,CAAC,IAAI,CAAC,CAAC;SACnC,IAAI,EAAE,CAAC;IACV,KAAK,CACH,OAAO,CAAC,MAAM,KAAK,IAAI,CAAC,MAAM,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC,KAAK,CAAC,CAAC,EAC9F,iDAAiD,CAClD,CAAC;IACF,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,gDAAgD,CAAC,CAAC;IAC3G,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,KAAK,GAA0E;IACnF,CAAC,sDAAsD,EAAE,eAAe,CAAC;IACzE,CAAC,kCAAkC,EAAE,aAAa,CAAC;IACnD,CAAC,uDAAuD,EAAE,gBAAgB,CAAC;IAC3E,CAAC,qDAAqD,EAAE,OAAO,CAAC;IAChE,CAAC,kFAAkF,EAAE,MAAM,CAAC;CAC7F,CAAC;AAEF,0DAA0D;AAC1D,MAAM,UAAU,wBAAwB,CAAC,OAAwB;IAC/D,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC;AACjG,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,sBAAsB,CAAC,OAAwB;IAC7D,OAAO,QAAQ,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;AACrD,CAAC","sourcesContent":["/**\n * The key store conformance suite: what every `KeyStore` must do. `load()` returns a ring a signer can use, and the\n * same ring each time until something changes it. `rotate()` and `prune()` are optional, because a read-only secret\n * is a valid store (ADR 0035), so their cases skip with a reason when a store leaves them out. The cases import no\n * test runner and no Node module, so any runner can call them, in workerd too. No message names a key's bytes.\n */\nimport { hmacSigner, type KeyRing, type KeyStore } from \"@buildanagent/agent-safety\";\nimport { type CaseReport, type RunnableCase, runCases } from \"./run-cases.js\";\n\n/** What a factory returns: the store under test. */\nexport interface KeyStoreUnderTest {\n readonly store: KeyStore;\n}\n\n/** Makes a fresh store for each case. */\nexport type KeyStoreFactory = () => KeyStoreUnderTest | Promise<KeyStoreUnderTest>;\n\n/** One key store case. */\nexport type KeyStoreCase = RunnableCase;\n\n/** What `runKeyStoreConformance()` reports. */\nexport type KeyStoreConformanceReport = CaseReport;\n\nfunction check(condition: boolean, message: string): asserts condition {\n if (!condition) throw new Error(`KeyStore conformance: ${message}`);\n}\n\nconst PAYLOAD = new TextEncoder().encode(\"key store conformance payload\");\n\nfunction sameBytes(a: Uint8Array | undefined, b: Uint8Array | undefined): boolean {\n if (a === undefined || b === undefined || a.length !== b.length) return false;\n return a.every((byte, index) => byte === b[index]);\n}\n\nfunction sameRing(a: KeyRing, b: KeyRing): boolean {\n const ids = Object.keys(a.keys).sort();\n const other = Object.keys(b.keys).sort();\n return (\n a.current === b.current &&\n ids.length === other.length &&\n ids.every((id, index) => id === other[index] && sameBytes(a.keys[id], b.keys[id]))\n );\n}\n\ntype Outcome = { readonly skipped: string } | undefined;\n\nasync function loadsUsableRing(store: KeyStore): Promise<Outcome> {\n const ring = await store.load();\n check(typeof ring.current === \"string\", \"the ring has no current key id\");\n check(ring.keys[ring.current] instanceof Uint8Array, \"the current key id is not in the ring's keys\");\n return undefined;\n}\n\nasync function loadsSameRing(store: KeyStore): Promise<Outcome> {\n check(sameRing(await store.load(), await store.load()), \"two loads returned different rings\");\n return undefined;\n}\n\nasync function signsAndVerifies(store: KeyStore): Promise<Outcome> {\n const signer = hmacSigner(await store.load());\n const signature = await signer.sign(PAYLOAD);\n check(await signer.verify(signer.keyId, PAYLOAD, signature), \"a signature from the ring did not verify\");\n const reloaded = hmacSigner(await store.load());\n check(await reloaded.verify(signer.keyId, PAYLOAD, signature), \"a reloaded ring did not verify the signature\");\n check(\n !(await reloaded.verify(signer.keyId, new TextEncoder().encode(\"another payload\"), signature)),\n \"a signature verified for another payload\",\n );\n return undefined;\n}\n\nasync function rotates(store: KeyStore): Promise<Outcome> {\n if (store.rotate === undefined) return { skipped: \"the store is read-only: it has no rotate()\" };\n const before = await store.load();\n const signature = await hmacSigner(before).sign(PAYLOAD);\n const id = await store.rotate();\n check(id !== before.current, \"rotate returned the id of the key that was already current\");\n const after = await store.load();\n check(after.current === id, \"the rotated key is not current\");\n check(sameBytes(after.keys[before.current], before.keys[before.current]), \"the old key left the ring\");\n check(\n await hmacSigner(after).verify(before.current, PAYLOAD, signature),\n \"a signature under the old key did not verify after the rotation\",\n );\n return undefined;\n}\n\nasync function prunes(store: KeyStore): Promise<Outcome> {\n if (store.prune === undefined) return { skipped: \"the store is read-only: it has no prune()\" };\n // With rotate() the ring holds three keys: one in use, one free to remove, and the current one.\n const inUse = new Set<string>();\n if (store.rotate !== undefined) {\n inUse.add((await store.load()).current);\n await store.rotate();\n await store.rotate();\n }\n const before = await store.load();\n const removed = await store.prune(inUse);\n const after = await store.load();\n check(after.current === before.current, \"prune changed the current key\");\n check(after.keys[after.current] instanceof Uint8Array, \"prune removed the current key\");\n check(\n [...inUse].every((id) => sameBytes(after.keys[id], before.keys[id])),\n \"prune removed a key that a pause still names\",\n );\n const gone = Object.keys(before.keys)\n .filter((id) => !(id in after.keys))\n .sort();\n check(\n removed.length === gone.length && [...removed].sort().every((id, index) => id === gone[index]),\n \"prune's returned ids are not the ids it removed\",\n );\n if (store.rotate !== undefined) check(gone.length === 1, \"prune did not remove the one key nothing names\");\n return undefined;\n}\n\nconst CASES: readonly (readonly [string, (store: KeyStore) => Promise<Outcome>])[] = [\n [\"load returns a ring whose current key is in its keys\", loadsUsableRing],\n [\"load twice returns the same ring\", loadsSameRing],\n [\"the loaded ring signs and verifies through hmacSigner\", signsAndVerifies],\n [\"rotate adds a new current key and keeps the old one\", rotates],\n [\"prune keeps the current key and every key in use, and returns the ids it removed\", prunes],\n];\n\n/** The cases, each run against a store from `factory`. */\nexport function keyStoreConformanceCases(factory: KeyStoreFactory): readonly KeyStoreCase[] {\n return CASES.map(([name, body]) => ({ name, run: async () => body((await factory()).store) }));\n}\n\n/** Runs every case and reports which passed, which skipped and which failed. */\nexport function runKeyStoreConformance(factory: KeyStoreFactory): Promise<KeyStoreConformanceReport> {\n return runCases(keyStoreConformanceCases(factory));\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** The report a conformance suite returns: which cases passed, which skipped with a reason and which failed. */
|
|
2
|
+
export interface CaseReport {
|
|
3
|
+
readonly passed: readonly string[];
|
|
4
|
+
readonly skipped: readonly {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly reason: string;
|
|
7
|
+
}[];
|
|
8
|
+
readonly failed: readonly {
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly error: string;
|
|
11
|
+
}[];
|
|
12
|
+
}
|
|
13
|
+
/** A case a runner can call: a name, and a check that resolves with `{ skipped }` when the case doesn't apply. */
|
|
14
|
+
export interface RunnableCase {
|
|
15
|
+
readonly name: string;
|
|
16
|
+
run(): Promise<{
|
|
17
|
+
readonly skipped: string;
|
|
18
|
+
} | undefined>;
|
|
19
|
+
}
|
|
20
|
+
/** Runs each case once and sorts the outcomes: a rejection fails the case, and `{ skipped }` skips it with its reason. */
|
|
21
|
+
export declare function runCases(cases: readonly RunnableCase[]): Promise<CaseReport>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Runs each case once and sorts the outcomes: a rejection fails the case, and `{ skipped }` skips it with its reason. */
|
|
2
|
+
export async function runCases(cases) {
|
|
3
|
+
const passed = [];
|
|
4
|
+
const skipped = [];
|
|
5
|
+
const failed = [];
|
|
6
|
+
for (const conformance of cases) {
|
|
7
|
+
try {
|
|
8
|
+
const outcome = await conformance.run();
|
|
9
|
+
if (outcome === undefined)
|
|
10
|
+
passed.push(conformance.name);
|
|
11
|
+
else
|
|
12
|
+
skipped.push({ name: conformance.name, reason: outcome.skipped });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
failed.push({ name: conformance.name, error: error instanceof Error ? error.message : String(error) });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return { passed, skipped, failed };
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=run-cases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-cases.js","sourceRoot":"","sources":["../../src/testing/run-cases.ts"],"names":[],"mappings":"AAaA,0HAA0H;AAC1H,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,KAA8B;IAC3D,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,OAAO,GAAuC,EAAE,CAAC;IACvD,MAAM,MAAM,GAAsC,EAAE,CAAC;IACrD,KAAK,MAAM,WAAW,IAAI,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,GAAG,EAAE,CAAC;YACxC,IAAI,OAAO,KAAK,SAAS;gBAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;;gBACpD,OAAO,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACzE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzG,CAAC;IACH,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC;AACrC,CAAC","sourcesContent":["/** The report a conformance suite returns: which cases passed, which skipped with a reason and which failed. */\nexport interface CaseReport {\n readonly passed: readonly string[];\n readonly skipped: readonly { readonly name: string; readonly reason: string }[];\n readonly failed: readonly { readonly name: string; readonly error: string }[];\n}\n\n/** A case a runner can call: a name, and a check that resolves with `{ skipped }` when the case doesn't apply. */\nexport interface RunnableCase {\n readonly name: string;\n run(): Promise<{ readonly skipped: string } | undefined>;\n}\n\n/** Runs each case once and sorts the outcomes: a rejection fails the case, and `{ skipped }` skips it with its reason. */\nexport async function runCases(cases: readonly RunnableCase[]): Promise<CaseReport> {\n const passed: string[] = [];\n const skipped: { name: string; reason: string }[] = [];\n const failed: { name: string; error: string }[] = [];\n for (const conformance of cases) {\n try {\n const outcome = await conformance.run();\n if (outcome === undefined) passed.push(conformance.name);\n else skipped.push({ name: conformance.name, reason: outcome.skipped });\n } catch (error) {\n failed.push({ name: conformance.name, error: error instanceof Error ? error.message : String(error) });\n }\n }\n return { passed, skipped, failed };\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The sandbox conformance suite: what every `SandboxClient` must do, whatever its tier. The cases that need a backend to
|
|
3
|
+
* enforce something run only when its `stops` claim it, so a `none` backend passes the rest and an honest `srt` or
|
|
4
|
+
* Docker backend passes them all. A backend that can't start makes every case skip with its reason, never fail. The cases
|
|
5
|
+
* import no test runner and no Node module, so any runner can call them, in workerd too.
|
|
6
|
+
*/
|
|
7
|
+
import type { SandboxClient } from "../sandbox/types.js";
|
|
8
|
+
import { type CaseReport, type RunnableCase } from "./run-cases.js";
|
|
9
|
+
/** What a factory returns: the backend, and the absolute folder to use as the workspace root. */
|
|
10
|
+
export interface SandboxUnderTest {
|
|
11
|
+
readonly client: SandboxClient;
|
|
12
|
+
/** An absolute folder that exists, empty. A sibling named `<root>-outside` stands for a path the policy refuses. */
|
|
13
|
+
readonly root: string;
|
|
14
|
+
/**
|
|
15
|
+
* Makes `link` an absolute path inside the workspace that stands for `target`, as a symlink does, before or after the
|
|
16
|
+
* sandbox starts. Without it the symlink case skips, because a portable command to make one doesn't exist.
|
|
17
|
+
*/
|
|
18
|
+
readonly symlink?: (link: string, target: string) => void | Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
/** Makes a fresh backend and workspace for each case. */
|
|
21
|
+
export type SandboxFactory = () => SandboxUnderTest | Promise<SandboxUnderTest>;
|
|
22
|
+
/** The options of the suite. */
|
|
23
|
+
export interface SandboxConformanceOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The network case: `command(host)` is a command that exits 0 if it reaches `host`. The policy allows only `allowed`,
|
|
26
|
+
* so both hosts must accept a connection from the test, such as two loopback listeners the test owns: a host that never
|
|
27
|
+
* resolves would fail with no policy at all and prove nothing. The case checks that `allowed` is reached and `blocked`
|
|
28
|
+
* is not. Without it that case skips, because a portable command to open a connection doesn't exist.
|
|
29
|
+
*/
|
|
30
|
+
readonly network?: {
|
|
31
|
+
readonly allowed: string;
|
|
32
|
+
readonly blocked: string;
|
|
33
|
+
/** The command that exits 0 if it reaches `host`. */
|
|
34
|
+
readonly command: (host: string) => readonly string[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Variables the backend adds to a command's environment on its own, such as the proxy variables an OS sandbox sets so a
|
|
38
|
+
* program finds its network proxy. The environment case accepts these besides the given ones, and still fails on any
|
|
39
|
+
* other variable and on any credential.
|
|
40
|
+
*/
|
|
41
|
+
readonly addedEnvironment?: readonly string[];
|
|
42
|
+
/**
|
|
43
|
+
* The case that checks an abort and a timeout end the command's whole tree. `command` starts a background process,
|
|
44
|
+
* writes its process id to the file `pid` in the workspace and then waits for it, and `isAlive` says whether a process
|
|
45
|
+
* is still running. Without it the case skips, because a portable command that forks doesn't exist.
|
|
46
|
+
*/
|
|
47
|
+
readonly processTree?: {
|
|
48
|
+
/** The command that starts a background process, writes its id to `pid` and waits for it. */
|
|
49
|
+
readonly command: readonly string[];
|
|
50
|
+
/** Whether the process with id `pid` is still running. */
|
|
51
|
+
readonly isAlive: (pid: number) => boolean | Promise<boolean>;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** One case of the sandbox conformance suite, which a runner can register as a test of its own. */
|
|
55
|
+
export type SandboxCase = RunnableCase;
|
|
56
|
+
/** The report the sandbox conformance suite returns: which cases passed, which skipped with a reason and which failed. */
|
|
57
|
+
export type SandboxConformanceReport = CaseReport;
|
|
58
|
+
/** The cases, for a backend from `factory`. Run each one; a case that doesn't apply resolves with `{ skipped }`. */
|
|
59
|
+
export declare function sandboxConformanceCases(factory: SandboxFactory, options?: SandboxConformanceOptions): readonly SandboxCase[];
|
|
60
|
+
/**
|
|
61
|
+
* Runs every case against backends from `factory` and reports which passed, which skipped with a reason and which
|
|
62
|
+
* failed. A backend that reports itself unavailable skips; any other error fails the case.
|
|
63
|
+
*/
|
|
64
|
+
export declare function runSandboxConformance(factory: SandboxFactory, options?: SandboxConformanceOptions): Promise<SandboxConformanceReport>;
|