@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,52 @@
|
|
|
1
|
+
import type { SandboxClient, SandboxPolicy, SandboxStop } from "../sandbox/types.js";
|
|
2
|
+
/** The options of `fakeSandbox()`. */
|
|
3
|
+
export interface FakeSandboxOptions {
|
|
4
|
+
/** Makes `provision()` throw `SandboxUnavailableError` with this reason, as a backend that can't start does. */
|
|
5
|
+
readonly unavailable?: string;
|
|
6
|
+
/**
|
|
7
|
+
* The policy the fake applies and reads back instead of the requested one, as a hosted provider's account-wide
|
|
8
|
+
* override would. `provision()` then throws `SandboxPolicyMismatchError` when the two differ.
|
|
9
|
+
*/
|
|
10
|
+
readonly applied?: (requested: SandboxPolicy) => SandboxPolicy;
|
|
11
|
+
/** The stops the fake claims. Defaults to `mistakes` and `exfiltration`, which its in-memory checks deliver. */
|
|
12
|
+
readonly stops?: readonly SandboxStop[];
|
|
13
|
+
}
|
|
14
|
+
/** One command the fake received, with what the caller passed. */
|
|
15
|
+
export interface RecordedExec {
|
|
16
|
+
readonly command: readonly string[];
|
|
17
|
+
readonly cwd: string | undefined;
|
|
18
|
+
readonly env: Readonly<Record<string, string>>;
|
|
19
|
+
readonly timeoutMs: number | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** A fake backend, and what it has seen. */
|
|
22
|
+
export interface FakeSandboxClient extends SandboxClient {
|
|
23
|
+
/** Every command run through any sandbox this client provisioned, in order. */
|
|
24
|
+
readonly execs: readonly RecordedExec[];
|
|
25
|
+
/** The files of the latest sandbox, by absolute path. */
|
|
26
|
+
files(): ReadonlyMap<string, Uint8Array>;
|
|
27
|
+
/** Makes `link` an absolute path that stands for `target` in the latest sandbox, as a symlink does. */
|
|
28
|
+
symlink(link: string, target: string): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The commands the fake runs, in the form `[name, ...arguments]`: `echo` prints its arguments, `env` prints the
|
|
32
|
+
* environment it was given as `NAME=value` lines, `cat <path>` prints a file, `write <path> <text>` writes one,
|
|
33
|
+
* `true` and `false` exit with 0 and 1, `sleep <seconds>` waits and honours the timeout and the signal, and
|
|
34
|
+
* `net-probe <host>` reaches a host only if the policy allows it. `find <dir>` lists the files under a folder, one per
|
|
35
|
+
* line or ending in NUL with `-print0`. When the command has `-prune`, it leaves out every folder named by a `-name`,
|
|
36
|
+
* the starting folder included. A `! -path <start>` exempts the starting folder. It exits with 0 and prints nothing for a folder
|
|
37
|
+
* with no files, and with 1 for a path that does not exist. `grep [-i] -e <pattern> -- <file>...` prints each
|
|
38
|
+
* matching line as `file:line:text`, reading the pattern as a JavaScript regular expression and skipping a file that
|
|
39
|
+
* holds a NUL byte. It exits with 1 when nothing matches, and with 2 after a missing file or a pattern it can't read,
|
|
40
|
+
* as grep does. A command that runs past its timeout exits with 124 and `timedOut: true`, and each stream keeps at
|
|
41
|
+
* most `maxOutputBytes`, with `truncated: true` when more was dropped.
|
|
42
|
+
* `bash -c <script>` and `sh -c <script>` split the script on whitespace and run its words as one of these commands,
|
|
43
|
+
* with no shell syntax. Any other command exits with 127.
|
|
44
|
+
*/
|
|
45
|
+
export declare const FAKE_COMMANDS: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* Builds a fake backend with the tier `os` and the stops `mistakes` and `exfiltration`, because it enforces the
|
|
48
|
+
* policy's file roots and network allowlist in memory. That says nothing about a real process: it runs none. It reads
|
|
49
|
+
* its policy back as a real backend does, so `provision()` throws `SandboxPolicyMismatchError` when `applied` changes
|
|
50
|
+
* the policy.
|
|
51
|
+
*/
|
|
52
|
+
export declare function fakeSandbox(options?: FakeSandboxOptions): FakeSandboxClient;
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fakeSandbox()`: a sandbox in memory, for tests of the code that runs on one. It enforces the policy it is given, so
|
|
3
|
+
* a test can see a denial, and it records every `exec`, but it confines no process and runs no program: it understands
|
|
4
|
+
* a few commands, listed at `FAKE_COMMANDS`. It is portable, so a test can use it on every target.
|
|
5
|
+
*/
|
|
6
|
+
import { HarnessError } from "../errors.js";
|
|
7
|
+
import { SandboxDeniedError, SandboxUnavailableError } from "../sandbox/errors.js";
|
|
8
|
+
import { confirmPolicy } from "../sandbox/policy.js";
|
|
9
|
+
/**
|
|
10
|
+
* The commands the fake runs, in the form `[name, ...arguments]`: `echo` prints its arguments, `env` prints the
|
|
11
|
+
* environment it was given as `NAME=value` lines, `cat <path>` prints a file, `write <path> <text>` writes one,
|
|
12
|
+
* `true` and `false` exit with 0 and 1, `sleep <seconds>` waits and honours the timeout and the signal, and
|
|
13
|
+
* `net-probe <host>` reaches a host only if the policy allows it. `find <dir>` lists the files under a folder, one per
|
|
14
|
+
* line or ending in NUL with `-print0`. When the command has `-prune`, it leaves out every folder named by a `-name`,
|
|
15
|
+
* the starting folder included. A `! -path <start>` exempts the starting folder. It exits with 0 and prints nothing for a folder
|
|
16
|
+
* with no files, and with 1 for a path that does not exist. `grep [-i] -e <pattern> -- <file>...` prints each
|
|
17
|
+
* matching line as `file:line:text`, reading the pattern as a JavaScript regular expression and skipping a file that
|
|
18
|
+
* holds a NUL byte. It exits with 1 when nothing matches, and with 2 after a missing file or a pattern it can't read,
|
|
19
|
+
* as grep does. A command that runs past its timeout exits with 124 and `timedOut: true`, and each stream keeps at
|
|
20
|
+
* most `maxOutputBytes`, with `truncated: true` when more was dropped.
|
|
21
|
+
* `bash -c <script>` and `sh -c <script>` split the script on whitespace and run its words as one of these commands,
|
|
22
|
+
* with no shell syntax. Any other command exits with 127.
|
|
23
|
+
*/
|
|
24
|
+
export const FAKE_COMMANDS = [
|
|
25
|
+
"echo",
|
|
26
|
+
"env",
|
|
27
|
+
"cat",
|
|
28
|
+
"write",
|
|
29
|
+
"true",
|
|
30
|
+
"false",
|
|
31
|
+
"sleep",
|
|
32
|
+
"net-probe",
|
|
33
|
+
"find",
|
|
34
|
+
"grep",
|
|
35
|
+
"bash",
|
|
36
|
+
"sh",
|
|
37
|
+
];
|
|
38
|
+
const ENCODER = new TextEncoder();
|
|
39
|
+
const DECODER = new TextDecoder();
|
|
40
|
+
// What a real backend keeps of each stream when the caller names no cap.
|
|
41
|
+
const DEFAULT_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;
|
|
42
|
+
function normalize(path) {
|
|
43
|
+
const parts = [];
|
|
44
|
+
for (const part of path.split("/")) {
|
|
45
|
+
if (part === "" || part === ".")
|
|
46
|
+
continue;
|
|
47
|
+
if (part === "..")
|
|
48
|
+
parts.pop();
|
|
49
|
+
else
|
|
50
|
+
parts.push(part);
|
|
51
|
+
}
|
|
52
|
+
return `/${parts.join("/")}`;
|
|
53
|
+
}
|
|
54
|
+
/** The lines of `text` that match, as `grep -n -H` prints them. */
|
|
55
|
+
function matchingLines(file, text, pattern) {
|
|
56
|
+
const lines = text.endsWith("\n") ? text.slice(0, -1).split("\n") : text.split("\n");
|
|
57
|
+
return lines.map((line, index) => (pattern.test(line) ? `${file}:${index + 1}:${line}\n` : "")).join("");
|
|
58
|
+
}
|
|
59
|
+
/** A `find -path` pattern with its backslash escapes removed, as the literal path it names. */
|
|
60
|
+
const literalOf = (pattern) => pattern?.replace(/\\(.)/g, "$1");
|
|
61
|
+
/** `text` cut to its first `bytes` UTF-8 bytes, never splitting a character, and whether anything was cut. */
|
|
62
|
+
function capped(text, bytes) {
|
|
63
|
+
const encoded = ENCODER.encode(text);
|
|
64
|
+
if (encoded.length <= bytes)
|
|
65
|
+
return { text, cut: false };
|
|
66
|
+
let end = bytes;
|
|
67
|
+
while (end > 0 && (encoded[end] & 0b1100_0000) === 0b1000_0000)
|
|
68
|
+
end -= 1;
|
|
69
|
+
return { text: DECODER.decode(encoded.subarray(0, end)), cut: true };
|
|
70
|
+
}
|
|
71
|
+
/** The pattern of a `grep` command's flags, or the result grep gives for a pattern it can't read. */
|
|
72
|
+
function patternOf(flags) {
|
|
73
|
+
const at = flags.indexOf("-e");
|
|
74
|
+
try {
|
|
75
|
+
return new RegExp(at < 0 ? "" : (flags[at + 1] ?? ""), flags.includes("-i") ? "i" : "");
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// grep reports a pattern it can't read on standard error and exits with 2, before it reads any file.
|
|
79
|
+
return { exitCode: 2, stdout: "", stderr: `grep: ${error.message}\n` };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const within = (path, root) => {
|
|
83
|
+
const base = normalize(root);
|
|
84
|
+
return base === "/" || path === base || path.startsWith(`${base}/`);
|
|
85
|
+
};
|
|
86
|
+
class FakeSandbox {
|
|
87
|
+
disposed = false;
|
|
88
|
+
stops = [];
|
|
89
|
+
// What ends each command still running, so `dispose()` can reject them as a real backend does.
|
|
90
|
+
running = new Set();
|
|
91
|
+
store = new Map();
|
|
92
|
+
links = new Map();
|
|
93
|
+
root;
|
|
94
|
+
policy;
|
|
95
|
+
log;
|
|
96
|
+
constructor(root, policy, log) {
|
|
97
|
+
this.root = normalize(root);
|
|
98
|
+
this.policy = policy;
|
|
99
|
+
this.log = log;
|
|
100
|
+
}
|
|
101
|
+
live() {
|
|
102
|
+
if (this.disposed)
|
|
103
|
+
throw new HarnessError("sandbox_disposed", "the sandbox was disposed");
|
|
104
|
+
}
|
|
105
|
+
/** The policy the fake enforces, as a copy. */
|
|
106
|
+
async readBack() {
|
|
107
|
+
this.live();
|
|
108
|
+
const { readRoots, writeRoots, network } = this.policy;
|
|
109
|
+
return {
|
|
110
|
+
readRoots: [...readRoots],
|
|
111
|
+
writeRoots: [...writeRoots],
|
|
112
|
+
network: { allow: [...network.allow], deny: [...network.deny] },
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** The absolute path a name stands for: joined to the root, tidied of `.` and `..`, then followed through links. */
|
|
116
|
+
resolve(path, base = this.root) {
|
|
117
|
+
const tidy = normalize(path.startsWith("/") ? path : `${base}/${path}`);
|
|
118
|
+
for (const [link, target] of this.links) {
|
|
119
|
+
if (tidy === link || tidy.startsWith(`${link}/`))
|
|
120
|
+
return normalize(`${target}${tidy.slice(link.length)}`);
|
|
121
|
+
}
|
|
122
|
+
return tidy;
|
|
123
|
+
}
|
|
124
|
+
readDenial(path) {
|
|
125
|
+
const roots = [...this.policy.readRoots, ...this.policy.writeRoots];
|
|
126
|
+
if (roots.some((root) => within(path, root)))
|
|
127
|
+
return undefined;
|
|
128
|
+
return { kind: "filesystem_read", target: path, reason: "the path is outside the read roots" };
|
|
129
|
+
}
|
|
130
|
+
writeDenial(path) {
|
|
131
|
+
if (this.policy.writeRoots.some((root) => within(path, root)))
|
|
132
|
+
return undefined;
|
|
133
|
+
return { kind: "filesystem_write", target: path, reason: "the path is outside the write roots" };
|
|
134
|
+
}
|
|
135
|
+
networkDenial(host) {
|
|
136
|
+
const { allow, deny } = this.policy.network;
|
|
137
|
+
if (allow.includes(host) && !deny.includes(host))
|
|
138
|
+
return undefined;
|
|
139
|
+
return { kind: "network", target: host, reason: "the host is not on the network allowlist" };
|
|
140
|
+
}
|
|
141
|
+
async readFile(path) {
|
|
142
|
+
this.live();
|
|
143
|
+
const target = this.resolve(path);
|
|
144
|
+
const denial = this.readDenial(target);
|
|
145
|
+
if (denial)
|
|
146
|
+
throw new SandboxDeniedError(denial);
|
|
147
|
+
const data = this.store.get(target);
|
|
148
|
+
if (data === undefined)
|
|
149
|
+
throw new HarnessError("sandbox_not_found", `no such file: ${target}`);
|
|
150
|
+
return data.slice();
|
|
151
|
+
}
|
|
152
|
+
async writeFile(path, data) {
|
|
153
|
+
this.live();
|
|
154
|
+
const target = this.resolve(path);
|
|
155
|
+
const denial = this.writeDenial(target);
|
|
156
|
+
if (denial)
|
|
157
|
+
throw new SandboxDeniedError(denial);
|
|
158
|
+
this.store.set(target, data.slice());
|
|
159
|
+
}
|
|
160
|
+
/** Writes a file without a policy check, for the manifest's own files. */
|
|
161
|
+
seed(path, data) {
|
|
162
|
+
this.store.set(this.resolve(path), data.slice());
|
|
163
|
+
}
|
|
164
|
+
async exec(command, options) {
|
|
165
|
+
this.live();
|
|
166
|
+
if (!Array.isArray(command) || command.length === 0) {
|
|
167
|
+
throw new HarnessError("invalid_sandbox_options", "a sandbox command is a non-empty list of strings");
|
|
168
|
+
}
|
|
169
|
+
options.signal.throwIfAborted();
|
|
170
|
+
const cwd = this.resolve(options.cwd ?? ".");
|
|
171
|
+
const denial = this.readDenial(cwd);
|
|
172
|
+
if (denial)
|
|
173
|
+
return { denied: denial };
|
|
174
|
+
this.log.push({ command: [...command], cwd: options.cwd, env: { ...options.env }, timeoutMs: options.timeoutMs });
|
|
175
|
+
const [name = "", ...args] = command;
|
|
176
|
+
const result = await this.run(name, args, options);
|
|
177
|
+
if ("denied" in result)
|
|
178
|
+
return result;
|
|
179
|
+
// Each stream keeps at most `maxOutputBytes`, as a real backend's does.
|
|
180
|
+
const limit = options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;
|
|
181
|
+
const stdout = capped(result.stdout, limit);
|
|
182
|
+
const stderr = capped(result.stderr, limit);
|
|
183
|
+
if (!stdout.cut && !stderr.cut)
|
|
184
|
+
return result;
|
|
185
|
+
return { ...result, stdout: stdout.text, stderr: stderr.text, truncated: true };
|
|
186
|
+
}
|
|
187
|
+
async run(name, args, options) {
|
|
188
|
+
const ok = (stdout = "") => ({ exitCode: 0, stdout, stderr: "" });
|
|
189
|
+
switch (name) {
|
|
190
|
+
case "echo":
|
|
191
|
+
return ok(`${args.join(" ")}\n`);
|
|
192
|
+
case "env":
|
|
193
|
+
return ok(Object.entries(options.env)
|
|
194
|
+
.map(([key, value]) => `${key}=${value}\n`)
|
|
195
|
+
.join(""));
|
|
196
|
+
case "true":
|
|
197
|
+
return ok();
|
|
198
|
+
case "false":
|
|
199
|
+
return { exitCode: 1, stdout: "", stderr: "" };
|
|
200
|
+
case "cat":
|
|
201
|
+
return this.cat(args[0] ?? "");
|
|
202
|
+
case "write":
|
|
203
|
+
return this.writeCommand(args[0] ?? "", args.slice(1).join(" "));
|
|
204
|
+
case "net-probe": {
|
|
205
|
+
const host = args[0] ?? "";
|
|
206
|
+
const denial = this.networkDenial(host);
|
|
207
|
+
return denial ? { denied: denial } : ok(`reached ${host}\n`);
|
|
208
|
+
}
|
|
209
|
+
case "sleep":
|
|
210
|
+
return this.sleep(Number(args[0] ?? 0) * 1000, options);
|
|
211
|
+
case "find":
|
|
212
|
+
return this.find(args);
|
|
213
|
+
case "grep":
|
|
214
|
+
return this.grep(args);
|
|
215
|
+
case "bash":
|
|
216
|
+
case "sh":
|
|
217
|
+
return this.shell(args, options);
|
|
218
|
+
default:
|
|
219
|
+
return { exitCode: 127, stdout: "", stderr: `command not found: ${name}\n` };
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
cat(path) {
|
|
223
|
+
const target = this.resolve(path);
|
|
224
|
+
const denial = this.readDenial(target);
|
|
225
|
+
if (denial)
|
|
226
|
+
return { denied: denial };
|
|
227
|
+
const data = this.store.get(target);
|
|
228
|
+
return data === undefined
|
|
229
|
+
? { exitCode: 1, stdout: "", stderr: `no such file: ${target}\n` }
|
|
230
|
+
: { exitCode: 0, stdout: DECODER.decode(data), stderr: "" };
|
|
231
|
+
}
|
|
232
|
+
/** The script's words as one command, so a test can drive a shell tool without a shell. */
|
|
233
|
+
shell(args, options) {
|
|
234
|
+
if (args[0] !== "-c")
|
|
235
|
+
return Promise.resolve({ exitCode: 2, stdout: "", stderr: "the fake shell runs only -c\n" });
|
|
236
|
+
const [name = "", ...rest] = (args[1] ?? "").trim().split(/\s+/);
|
|
237
|
+
return this.run(name, rest, options);
|
|
238
|
+
}
|
|
239
|
+
/** Whether `path` is a folder: the root, a folder above it, or a folder that holds a file. */
|
|
240
|
+
isFolder(path) {
|
|
241
|
+
if (within(this.root, path))
|
|
242
|
+
return true;
|
|
243
|
+
const prefix = path === "/" ? "/" : `${path}/`;
|
|
244
|
+
return [...this.store.keys()].some((file) => file.startsWith(prefix));
|
|
245
|
+
}
|
|
246
|
+
find(args) {
|
|
247
|
+
const start = this.resolve(args[0] ?? ".");
|
|
248
|
+
const denial = this.readDenial(start);
|
|
249
|
+
if (denial)
|
|
250
|
+
return { denied: denial };
|
|
251
|
+
if (!this.store.has(start) && !this.isFolder(start)) {
|
|
252
|
+
return { exitCode: 1, stdout: "", stderr: `find: '${args[0] ?? "."}': No such file or directory\n` };
|
|
253
|
+
}
|
|
254
|
+
const named = args.flatMap((arg, index) => (arg === "-name" ? [args[index + 1] ?? ""] : []));
|
|
255
|
+
const pruned = new Set(args.includes("-prune") ? named : []);
|
|
256
|
+
// `! -path <start>` exempts the starting point from the prune, as it does for find; without it the prune tests
|
|
257
|
+
// the starting point's own name too, so a search that starts in a pruned folder finds nothing.
|
|
258
|
+
const exempt = args.some((arg, index) => arg === "!" && args[index + 1] === "-path" && literalOf(args[index + 2]) === start);
|
|
259
|
+
const ownName = start.split("/").at(-1) ?? "";
|
|
260
|
+
if (!exempt && ownName !== "" && pruned.has(ownName))
|
|
261
|
+
return { exitCode: 0, stdout: "", stderr: "" };
|
|
262
|
+
const files = [...this.store.keys()]
|
|
263
|
+
.filter((path) => path === start || path.startsWith(`${start === "/" ? "" : start}/`))
|
|
264
|
+
.filter((path) => !path
|
|
265
|
+
.slice(start.length)
|
|
266
|
+
.split("/")
|
|
267
|
+
.some((part) => pruned.has(part)))
|
|
268
|
+
.sort();
|
|
269
|
+
const end = args.includes("-print0") ? "\0" : "\n";
|
|
270
|
+
return { exitCode: 0, stdout: files.map((path) => `${path}${end}`).join(""), stderr: "" };
|
|
271
|
+
}
|
|
272
|
+
grep(args) {
|
|
273
|
+
const split = args.indexOf("--");
|
|
274
|
+
const flags = split < 0 ? args : args.slice(0, split);
|
|
275
|
+
const files = split < 0 ? [] : args.slice(split + 1);
|
|
276
|
+
const pattern = patternOf(flags);
|
|
277
|
+
if (!(pattern instanceof RegExp))
|
|
278
|
+
return pattern;
|
|
279
|
+
let stdout = "";
|
|
280
|
+
let stderr = "";
|
|
281
|
+
for (const file of files) {
|
|
282
|
+
const target = this.resolve(file);
|
|
283
|
+
const denial = this.readDenial(target);
|
|
284
|
+
if (denial)
|
|
285
|
+
return { denied: denial };
|
|
286
|
+
const data = this.store.get(target);
|
|
287
|
+
if (data === undefined)
|
|
288
|
+
stderr += `grep: ${file}: No such file or directory\n`;
|
|
289
|
+
else if (!data.includes(0))
|
|
290
|
+
stdout += matchingLines(file, DECODER.decode(data), pattern);
|
|
291
|
+
}
|
|
292
|
+
// grep exits with 2 after any error, even when other files matched.
|
|
293
|
+
return { exitCode: stderr !== "" ? 2 : stdout === "" ? 1 : 0, stdout, stderr };
|
|
294
|
+
}
|
|
295
|
+
writeCommand(path, text) {
|
|
296
|
+
const target = this.resolve(path);
|
|
297
|
+
const denial = this.writeDenial(target);
|
|
298
|
+
if (denial)
|
|
299
|
+
return { denied: denial };
|
|
300
|
+
this.store.set(target, ENCODER.encode(text));
|
|
301
|
+
return { exitCode: 0, stdout: "", stderr: "" };
|
|
302
|
+
}
|
|
303
|
+
sleep(ms, options) {
|
|
304
|
+
return new Promise((resolve, reject) => {
|
|
305
|
+
const done = (result) => {
|
|
306
|
+
clearTimeout(timer);
|
|
307
|
+
options.signal.removeEventListener("abort", aborted);
|
|
308
|
+
this.running.delete(disposed);
|
|
309
|
+
resolve(result);
|
|
310
|
+
};
|
|
311
|
+
const aborted = () => {
|
|
312
|
+
clearTimeout(timer);
|
|
313
|
+
this.running.delete(disposed);
|
|
314
|
+
reject(options.signal.reason);
|
|
315
|
+
};
|
|
316
|
+
const disposed = () => {
|
|
317
|
+
clearTimeout(timer);
|
|
318
|
+
options.signal.removeEventListener("abort", aborted);
|
|
319
|
+
reject(new HarnessError("sandbox_disposed", "the sandbox was disposed"));
|
|
320
|
+
};
|
|
321
|
+
this.running.add(disposed);
|
|
322
|
+
const stopAt = options.timeoutMs !== undefined && options.timeoutMs < ms ? options.timeoutMs : ms;
|
|
323
|
+
const timer = setTimeout(() => {
|
|
324
|
+
const timedOut = stopAt < ms;
|
|
325
|
+
done(timedOut
|
|
326
|
+
? { exitCode: 124, stdout: "", stderr: `timed out after ${stopAt} ms\n`, timedOut: true }
|
|
327
|
+
: { exitCode: 0, stdout: "", stderr: "" });
|
|
328
|
+
}, stopAt);
|
|
329
|
+
options.signal.addEventListener("abort", aborted, { once: true });
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
async dispose() {
|
|
333
|
+
this.disposed = true;
|
|
334
|
+
for (const stop of [...this.running])
|
|
335
|
+
stop();
|
|
336
|
+
this.running.clear();
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Builds a fake backend with the tier `os` and the stops `mistakes` and `exfiltration`, because it enforces the
|
|
341
|
+
* policy's file roots and network allowlist in memory. That says nothing about a real process: it runs none. It reads
|
|
342
|
+
* its policy back as a real backend does, so `provision()` throws `SandboxPolicyMismatchError` when `applied` changes
|
|
343
|
+
* the policy.
|
|
344
|
+
*/
|
|
345
|
+
export function fakeSandbox(options = {}) {
|
|
346
|
+
const execs = [];
|
|
347
|
+
let latest;
|
|
348
|
+
const client = {
|
|
349
|
+
tier: "os",
|
|
350
|
+
stops: options.stops ?? ["mistakes", "exfiltration"],
|
|
351
|
+
execs,
|
|
352
|
+
files: () => latest?.store ?? new Map(),
|
|
353
|
+
symlink(link, target) {
|
|
354
|
+
latest?.links.set(normalize(link), normalize(target));
|
|
355
|
+
},
|
|
356
|
+
async provision(manifest, policy) {
|
|
357
|
+
if (options.unavailable !== undefined)
|
|
358
|
+
throw new SandboxUnavailableError("fake", options.unavailable);
|
|
359
|
+
const sandbox = new FakeSandbox(manifest.root, options.applied?.(policy) ?? policy, execs);
|
|
360
|
+
sandbox.stops = await confirmPolicy(client, sandbox, policy);
|
|
361
|
+
for (const [path, data] of Object.entries(manifest.files ?? {})) {
|
|
362
|
+
sandbox.seed(path, typeof data === "string" ? ENCODER.encode(data) : data);
|
|
363
|
+
}
|
|
364
|
+
latest = sandbox;
|
|
365
|
+
return sandbox;
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
return client;
|
|
369
|
+
}
|
|
370
|
+
//# sourceMappingURL=fake-sandbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fake-sandbox.js","sourceRoot":"","sources":["../../src/testing/fake-sandbox.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AA2CrD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,aAAa,GAAsB;IAC9C,MAAM;IACN,KAAK;IACL,KAAK;IACL,OAAO;IACP,MAAM;IACN,OAAO;IACP,OAAO;IACP,WAAW;IACX,MAAM;IACN,MAAM;IACN,MAAM;IACN,IAAI;CACL,CAAC;AAEF,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAClC,yEAAyE;AACzE,MAAM,wBA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AO,CAAC,KAAK,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC;QACpD,KAAK;QACL,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,KAAK,IAAI,IAAI,GAAG,EAAE;QACvC,OAAO,CAAC,IAAY,EAAE,MAAc;YAClC,MAAM,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QACxD,CAAC;QACD,KAAK,CAAC,SAAS,CAAC,QAA2B,EAAE,MAAqB;YAChE,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS;gBAAE,MAAM,IAAI,uBAAuB,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;YACtG,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,IAAI,MAAM,EAAE,KAAK,CAAC,CAAC;YAC3F,OAAO,CAAC,KAAK,GAAG,MAAM,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;YAC7D,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;gBAChE,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC7E,CAAC;YACD,MAAM,GAAG,OAAO,CAAC;YACjB,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * `fakeSandbox()`: a sandbox in memory, for tests of the code that runs on one. It enforces the policy it is given, so\n * a test can see a denial, and it records every `exec`, but it confines no process and runs no program: it understands\n * a few commands, listed at `FAKE_COMMANDS`. It is portable, so a test can use it on every target.\n */\nimport { HarnessError } from \"../errors.js\";\nimport { SandboxDeniedError, SandboxUnavailableError } from \"../sandbox/errors.js\";\nimport { confirmPolicy } from \"../sandbox/policy.js\";\nimport type {\n ExecOptions,\n ExecResult,\n Sandbox,\n SandboxClient,\n SandboxDenial,\n SandboxPolicy,\n SandboxStop,\n WorkspaceManifest,\n} from \"../sandbox/types.js\";\n\n/** The options of `fakeSandbox()`. */\nexport interface FakeSandboxOptions {\n /** Makes `provision()` throw `SandboxUnavailableError` with this reason, as a backend that can't start does. */\n readonly unavailable?: string;\n /**\n * The policy the fake applies and reads back instead of the requested one, as a hosted provider's account-wide\n * override would. `provision()` then throws `SandboxPolicyMismatchError` when the two differ.\n */\n readonly applied?: (requested: SandboxPolicy) => SandboxPolicy;\n /** The stops the fake claims. Defaults to `mistakes` and `exfiltration`, which its in-memory checks deliver. */\n readonly stops?: readonly SandboxStop[];\n}\n\n/** One command the fake received, with what the caller passed. */\nexport interface RecordedExec {\n readonly command: readonly string[];\n readonly cwd: string | undefined;\n readonly env: Readonly<Record<string, string>>;\n readonly timeoutMs: number | undefined;\n}\n\n/** A fake backend, and what it has seen. */\nexport interface FakeSandboxClient extends SandboxClient {\n /** Every command run through any sandbox this client provisioned, in order. */\n readonly execs: readonly RecordedExec[];\n /** The files of the latest sandbox, by absolute path. */\n files(): ReadonlyMap<string, Uint8Array>;\n /** Makes `link` an absolute path that stands for `target` in the latest sandbox, as a symlink does. */\n symlink(link: string, target: string): void;\n}\n\n/**\n * The commands the fake runs, in the form `[name, ...arguments]`: `echo` prints its arguments, `env` prints the\n * environment it was given as `NAME=value` lines, `cat <path>` prints a file, `write <path> <text>` writes one,\n * `true` and `false` exit with 0 and 1, `sleep <seconds>` waits and honours the timeout and the signal, and\n * `net-probe <host>` reaches a host only if the policy allows it. `find <dir>` lists the files under a folder, one per\n * line or ending in NUL with `-print0`. When the command has `-prune`, it leaves out every folder named by a `-name`,\n * the starting folder included. A `! -path <start>` exempts the starting folder. It exits with 0 and prints nothing for a folder\n * with no files, and with 1 for a path that does not exist. `grep [-i] -e <pattern> -- <file>...` prints each\n * matching line as `file:line:text`, reading the pattern as a JavaScript regular expression and skipping a file that\n * holds a NUL byte. It exits with 1 when nothing matches, and with 2 after a missing file or a pattern it can't read,\n * as grep does. A command that runs past its timeout exits with 124 and `timedOut: true`, and each stream keeps at\n * most `maxOutputBytes`, with `truncated: true` when more was dropped.\n * `bash -c <script>` and `sh -c <script>` split the script on whitespace and run its words as one of these commands,\n * with no shell syntax. Any other command exits with 127.\n */\nexport const FAKE_COMMANDS: readonly string[] = [\n \"echo\",\n \"env\",\n \"cat\",\n \"write\",\n \"true\",\n \"false\",\n \"sleep\",\n \"net-probe\",\n \"find\",\n \"grep\",\n \"bash\",\n \"sh\",\n];\n\nconst ENCODER = new TextEncoder();\nconst DECODER = new TextDecoder();\n// What a real backend keeps of each stream when the caller names no cap.\nconst DEFAULT_MAX_OUTPUT_BYTES = 8 * 1024 * 1024;\n\nfunction normalize(path: string): string {\n const parts: string[] = [];\n for (const part of path.split(\"/\")) {\n if (part === \"\" || part === \".\") continue;\n if (part === \"..\") parts.pop();\n else parts.push(part);\n }\n return `/${parts.join(\"/\")}`;\n}\n\n/** The lines of `text` that match, as `grep -n -H` prints them. */\nfunction matchingLines(file: string, text: string, pattern: RegExp): string {\n const lines = text.endsWith(\"\\n\") ? text.slice(0, -1).split(\"\\n\") : text.split(\"\\n\");\n return lines.map((line, index) => (pattern.test(line) ? `${file}:${index + 1}:${line}\\n` : \"\")).join(\"\");\n}\n\n/** A `find -path` pattern with its backslash escapes removed, as the literal path it names. */\nconst literalOf = (pattern: string | undefined): string | undefined => pattern?.replace(/\\\\(.)/g, \"$1\");\n\n/** `text` cut to its first `bytes` UTF-8 bytes, never splitting a character, and whether anything was cut. */\nfunction capped(text: string, bytes: number): { text: string; cut: boolean } {\n const encoded = ENCODER.encode(text);\n if (encoded.length <= bytes) return { text, cut: false };\n let end = bytes;\n while (end > 0 && ((encoded[end] as number) & 0b1100_0000) === 0b1000_0000) end -= 1;\n return { text: DECODER.decode(encoded.subarray(0, end)), cut: true };\n}\n\n/** The pattern of a `grep` command's flags, or the result grep gives for a pattern it can't read. */\nfunction patternOf(flags: readonly string[]): RegExp | ExecResult {\n const at = flags.indexOf(\"-e\");\n try {\n return new RegExp(at < 0 ? \"\" : (flags[at + 1] ?? \"\"), flags.includes(\"-i\") ? \"i\" : \"\");\n } catch (error) {\n // grep reports a pattern it can't read on standard error and exits with 2, before it reads any file.\n return { exitCode: 2, stdout: \"\", stderr: `grep: ${(error as Error).message}\\n` };\n }\n}\n\nconst within = (path: string, root: string): boolean => {\n const base = normalize(root);\n return base === \"/\" || path === base || path.startsWith(`${base}/`);\n};\n\nclass FakeSandbox implements Sandbox {\n private disposed = false;\n stops: readonly SandboxStop[] = [];\n // What ends each command still running, so `dispose()` can reject them as a real backend does.\n private readonly running = new Set<() => void>();\n readonly store = new Map<string, Uint8Array>();\n readonly links = new Map<string, string>();\n private readonly root: string;\n private readonly policy: SandboxPolicy;\n private readonly log: RecordedExec[];\n\n constructor(root: string, policy: SandboxPolicy, log: RecordedExec[]) {\n this.root = normalize(root);\n this.policy = policy;\n this.log = log;\n }\n\n private live(): void {\n if (this.disposed) throw new HarnessError(\"sandbox_disposed\", \"the sandbox was disposed\");\n }\n\n /** The policy the fake enforces, as a copy. */\n async readBack(): Promise<SandboxPolicy> {\n this.live();\n const { readRoots, writeRoots, network } = this.policy;\n return {\n readRoots: [...readRoots],\n writeRoots: [...writeRoots],\n network: { allow: [...network.allow], deny: [...network.deny] },\n };\n }\n\n /** The absolute path a name stands for: joined to the root, tidied of `.` and `..`, then followed through links. */\n resolve(path: string, base = this.root): string {\n const tidy = normalize(path.startsWith(\"/\") ? path : `${base}/${path}`);\n for (const [link, target] of this.links) {\n if (tidy === link || tidy.startsWith(`${link}/`)) return normalize(`${target}${tidy.slice(link.length)}`);\n }\n return tidy;\n }\n\n private readDenial(path: string): SandboxDenial | undefined {\n const roots = [...this.policy.readRoots, ...this.policy.writeRoots];\n if (roots.some((root) => within(path, root))) return undefined;\n return { kind: \"filesystem_read\", target: path, reason: \"the path is outside the read roots\" };\n }\n\n private writeDenial(path: string): SandboxDenial | undefined {\n if (this.policy.writeRoots.some((root) => within(path, root))) return undefined;\n return { kind: \"filesystem_write\", target: path, reason: \"the path is outside the write roots\" };\n }\n\n private networkDenial(host: string): SandboxDenial | undefined {\n const { allow, deny } = this.policy.network;\n if (allow.includes(host) && !deny.includes(host)) return undefined;\n return { kind: \"network\", target: host, reason: \"the host is not on the network allowlist\" };\n }\n\n async readFile(path: string): Promise<Uint8Array> {\n this.live();\n const target = this.resolve(path);\n const denial = this.readDenial(target);\n if (denial) throw new SandboxDeniedError(denial);\n const data = this.store.get(target);\n if (data === undefined) throw new HarnessError(\"sandbox_not_found\", `no such file: ${target}`);\n return data.slice();\n }\n\n async writeFile(path: string, data: Uint8Array): Promise<void> {\n this.live();\n const target = this.resolve(path);\n const denial = this.writeDenial(target);\n if (denial) throw new SandboxDeniedError(denial);\n this.store.set(target, data.slice());\n }\n\n /** Writes a file without a policy check, for the manifest's own files. */\n seed(path: string, data: Uint8Array): void {\n this.store.set(this.resolve(path), data.slice());\n }\n\n async exec(command: readonly string[], options: ExecOptions): Promise<ExecResult> {\n this.live();\n if (!Array.isArray(command) || command.length === 0) {\n throw new HarnessError(\"invalid_sandbox_options\", \"a sandbox command is a non-empty list of strings\");\n }\n options.signal.throwIfAborted();\n const cwd = this.resolve(options.cwd ?? \".\");\n const denial = this.readDenial(cwd);\n if (denial) return { denied: denial };\n this.log.push({ command: [...command], cwd: options.cwd, env: { ...options.env }, timeoutMs: options.timeoutMs });\n const [name = \"\", ...args] = command;\n const result = await this.run(name, args, options);\n if (\"denied\" in result) return result;\n // Each stream keeps at most `maxOutputBytes`, as a real backend's does.\n const limit = options.maxOutputBytes ?? DEFAULT_MAX_OUTPUT_BYTES;\n const stdout = capped(result.stdout, limit);\n const stderr = capped(result.stderr, limit);\n if (!stdout.cut && !stderr.cut) return result;\n return { ...result, stdout: stdout.text, stderr: stderr.text, truncated: true };\n }\n\n private async run(name: string, args: string[], options: ExecOptions): Promise<ExecResult> {\n const ok = (stdout = \"\"): ExecResult => ({ exitCode: 0, stdout, stderr: \"\" });\n switch (name) {\n case \"echo\":\n return ok(`${args.join(\" \")}\\n`);\n case \"env\":\n return ok(\n Object.entries(options.env)\n .map(([key, value]) => `${key}=${value}\\n`)\n .join(\"\"),\n );\n case \"true\":\n return ok();\n case \"false\":\n return { exitCode: 1, stdout: \"\", stderr: \"\" };\n case \"cat\":\n return this.cat(args[0] ?? \"\");\n case \"write\":\n return this.writeCommand(args[0] ?? \"\", args.slice(1).join(\" \"));\n case \"net-probe\": {\n const host = args[0] ?? \"\";\n const denial = this.networkDenial(host);\n return denial ? { denied: denial } : ok(`reached ${host}\\n`);\n }\n case \"sleep\":\n return this.sleep(Number(args[0] ?? 0) * 1000, options);\n case \"find\":\n return this.find(args);\n case \"grep\":\n return this.grep(args);\n case \"bash\":\n case \"sh\":\n return this.shell(args, options);\n default:\n return { exitCode: 127, stdout: \"\", stderr: `command not found: ${name}\\n` };\n }\n }\n\n private cat(path: string): ExecResult {\n const target = this.resolve(path);\n const denial = this.readDenial(target);\n if (denial) return { denied: denial };\n const data = this.store.get(target);\n return data === undefined\n ? { exitCode: 1, stdout: \"\", stderr: `no such file: ${target}\\n` }\n : { exitCode: 0, stdout: DECODER.decode(data), stderr: \"\" };\n }\n\n /** The script's words as one command, so a test can drive a shell tool without a shell. */\n private shell(args: string[], options: ExecOptions): Promise<ExecResult> {\n if (args[0] !== \"-c\") return Promise.resolve({ exitCode: 2, stdout: \"\", stderr: \"the fake shell runs only -c\\n\" });\n const [name = \"\", ...rest] = (args[1] ?? \"\").trim().split(/\\s+/);\n return this.run(name, rest, options);\n }\n\n /** Whether `path` is a folder: the root, a folder above it, or a folder that holds a file. */\n private isFolder(path: string): boolean {\n if (within(this.root, path)) return true;\n const prefix = path === \"/\" ? \"/\" : `${path}/`;\n return [...this.store.keys()].some((file) => file.startsWith(prefix));\n }\n\n private find(args: string[]): ExecResult {\n const start = this.resolve(args[0] ?? \".\");\n const denial = this.readDenial(start);\n if (denial) return { denied: denial };\n if (!this.store.has(start) && !this.isFolder(start)) {\n return { exitCode: 1, stdout: \"\", stderr: `find: '${args[0] ?? \".\"}': No such file or directory\\n` };\n }\n const named = args.flatMap((arg, index) => (arg === \"-name\" ? [args[index + 1] ?? \"\"] : []));\n const pruned = new Set(args.includes(\"-prune\") ? named : []);\n // `! -path <start>` exempts the starting point from the prune, as it does for find; without it the prune tests\n // the starting point's own name too, so a search that starts in a pruned folder finds nothing.\n const exempt = args.some(\n (arg, index) => arg === \"!\" && args[index + 1] === \"-path\" && literalOf(args[index + 2]) === start,\n );\n const ownName = start.split(\"/\").at(-1) ?? \"\";\n if (!exempt && ownName !== \"\" && pruned.has(ownName)) return { exitCode: 0, stdout: \"\", stderr: \"\" };\n const files = [...this.store.keys()]\n .filter((path) => path === start || path.startsWith(`${start === \"/\" ? \"\" : start}/`))\n .filter(\n (path) =>\n !path\n .slice(start.length)\n .split(\"/\")\n .some((part) => pruned.has(part)),\n )\n .sort();\n const end = args.includes(\"-print0\") ? \"\\0\" : \"\\n\";\n return { exitCode: 0, stdout: files.map((path) => `${path}${end}`).join(\"\"), stderr: \"\" };\n }\n\n private grep(args: string[]): ExecResult {\n const split = args.indexOf(\"--\");\n const flags = split < 0 ? args : args.slice(0, split);\n const files = split < 0 ? [] : args.slice(split + 1);\n const pattern = patternOf(flags);\n if (!(pattern instanceof RegExp)) return pattern;\n let stdout = \"\";\n let stderr = \"\";\n for (const file of files) {\n const target = this.resolve(file);\n const denial = this.readDenial(target);\n if (denial) return { denied: denial };\n const data = this.store.get(target);\n if (data === undefined) stderr += `grep: ${file}: No such file or directory\\n`;\n else if (!data.includes(0)) stdout += matchingLines(file, DECODER.decode(data), pattern);\n }\n // grep exits with 2 after any error, even when other files matched.\n return { exitCode: stderr !== \"\" ? 2 : stdout === \"\" ? 1 : 0, stdout, stderr };\n }\n\n private writeCommand(path: string, text: string): ExecResult {\n const target = this.resolve(path);\n const denial = this.writeDenial(target);\n if (denial) return { denied: denial };\n this.store.set(target, ENCODER.encode(text));\n return { exitCode: 0, stdout: \"\", stderr: \"\" };\n }\n\n private sleep(ms: number, options: ExecOptions): Promise<ExecResult> {\n return new Promise((resolve, reject) => {\n const done = (result: ExecResult) => {\n clearTimeout(timer);\n options.signal.removeEventListener(\"abort\", aborted);\n this.running.delete(disposed);\n resolve(result);\n };\n const aborted = () => {\n clearTimeout(timer);\n this.running.delete(disposed);\n reject(options.signal.reason);\n };\n const disposed = () => {\n clearTimeout(timer);\n options.signal.removeEventListener(\"abort\", aborted);\n reject(new HarnessError(\"sandbox_disposed\", \"the sandbox was disposed\"));\n };\n this.running.add(disposed);\n const stopAt = options.timeoutMs !== undefined && options.timeoutMs < ms ? options.timeoutMs : ms;\n const timer = setTimeout(() => {\n const timedOut = stopAt < ms;\n done(\n timedOut\n ? { exitCode: 124, stdout: \"\", stderr: `timed out after ${stopAt} ms\\n`, timedOut: true }\n : { exitCode: 0, stdout: \"\", stderr: \"\" },\n );\n }, stopAt);\n options.signal.addEventListener(\"abort\", aborted, { once: true });\n });\n }\n\n async dispose(): Promise<void> {\n this.disposed = true;\n for (const stop of [...this.running]) stop();\n this.running.clear();\n }\n}\n\n/**\n * Builds a fake backend with the tier `os` and the stops `mistakes` and `exfiltration`, because it enforces the\n * policy's file roots and network allowlist in memory. That says nothing about a real process: it runs none. It reads\n * its policy back as a real backend does, so `provision()` throws `SandboxPolicyMismatchError` when `applied` changes\n * the policy.\n */\nexport function fakeSandbox(options: FakeSandboxOptions = {}): FakeSandboxClient {\n const execs: RecordedExec[] = [];\n let latest: FakeSandbox | undefined;\n const client: FakeSandboxClient = {\n tier: \"os\",\n stops: options.stops ?? [\"mistakes\", \"exfiltration\"],\n execs,\n files: () => latest?.store ?? new Map(),\n symlink(link: string, target: string) {\n latest?.links.set(normalize(link), normalize(target));\n },\n async provision(manifest: WorkspaceManifest, policy: SandboxPolicy) {\n if (options.unavailable !== undefined) throw new SandboxUnavailableError(\"fake\", options.unavailable);\n const sandbox = new FakeSandbox(manifest.root, options.applied?.(policy) ?? policy, execs);\n sandbox.stops = await confirmPolicy(client, sandbox, policy);\n for (const [path, data] of Object.entries(manifest.files ?? {})) {\n sandbox.seed(path, typeof data === \"string\" ? ENCODER.encode(data) : data);\n }\n latest = sandbox;\n return sandbox;\n },\n };\n return client;\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@buildanagent/harness/testing`: test doubles and conformance suites for the harness's components. The in-memory
|
|
3
|
+
* sandbox, and the conformance suites of the sandbox, the session store, the scheduler and the key store, are here so
|
|
4
|
+
* far.
|
|
5
|
+
*/
|
|
6
|
+
export { FAKE_COMMANDS, type FakeSandboxClient, type FakeSandboxOptions, fakeSandbox, type RecordedExec, } from "./fake-sandbox.js";
|
|
7
|
+
export { type KeyStoreCase, type KeyStoreConformanceReport, type KeyStoreFactory, type KeyStoreUnderTest, keyStoreConformanceCases, runKeyStoreConformance, } from "./key-store-conformance.js";
|
|
8
|
+
export { runSandboxConformance, type SandboxCase, type SandboxConformanceOptions, type SandboxConformanceReport, type SandboxFactory, type SandboxUnderTest, sandboxConformanceCases, } from "./sandbox-conformance.js";
|
|
9
|
+
export { type DeliveredWake, runSchedulerConformance, type SchedulerCase, type SchedulerConformanceReport, type SchedulerFactory, type SchedulerUnderTest, schedulerConformanceCases, } from "./scheduler-conformance.js";
|
|
10
|
+
export { runStoreConformance, type StoreCase, type StoreConformanceReport, type StoreFactory, type StoreUnderTest, storeConformanceCases, } from "./store-conformance.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@buildanagent/harness/testing`: test doubles and conformance suites for the harness's components. The in-memory
|
|
3
|
+
* sandbox, and the conformance suites of the sandbox, the session store, the scheduler and the key store, are here so
|
|
4
|
+
* far.
|
|
5
|
+
*/
|
|
6
|
+
export { FAKE_COMMANDS, fakeSandbox, } from "./fake-sandbox.js";
|
|
7
|
+
export { keyStoreConformanceCases, runKeyStoreConformance, } from "./key-store-conformance.js";
|
|
8
|
+
export { runSandboxConformance, sandboxConformanceCases, } from "./sandbox-conformance.js";
|
|
9
|
+
export { runSchedulerConformance, schedulerConformanceCases, } from "./scheduler-conformance.js";
|
|
10
|
+
export { runStoreConformance, storeConformanceCases, } from "./store-conformance.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EACL,aAAa,EAGb,WAAW,GAEZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAKL,wBAAwB,EACxB,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,qBAAqB,EAMrB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAEL,uBAAuB,EAKvB,yBAAyB,GAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,mBAAmB,EAKnB,qBAAqB,GACtB,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * `@buildanagent/harness/testing`: test doubles and conformance suites for the harness's components. The in-memory\n * sandbox, and the conformance suites of the sandbox, the session store, the scheduler and the key store, are here so\n * far.\n */\nexport {\n FAKE_COMMANDS,\n type FakeSandboxClient,\n type FakeSandboxOptions,\n fakeSandbox,\n type RecordedExec,\n} from \"./fake-sandbox.js\";\nexport {\n type KeyStoreCase,\n type KeyStoreConformanceReport,\n type KeyStoreFactory,\n type KeyStoreUnderTest,\n keyStoreConformanceCases,\n runKeyStoreConformance,\n} from \"./key-store-conformance.js\";\nexport {\n runSandboxConformance,\n type SandboxCase,\n type SandboxConformanceOptions,\n type SandboxConformanceReport,\n type SandboxFactory,\n type SandboxUnderTest,\n sandboxConformanceCases,\n} from \"./sandbox-conformance.js\";\nexport {\n type DeliveredWake,\n runSchedulerConformance,\n type SchedulerCase,\n type SchedulerConformanceReport,\n type SchedulerFactory,\n type SchedulerUnderTest,\n schedulerConformanceCases,\n} from \"./scheduler-conformance.js\";\nexport {\n runStoreConformance,\n type StoreCase,\n type StoreConformanceReport,\n type StoreFactory,\n type StoreUnderTest,\n storeConformanceCases,\n} from \"./store-conformance.js\";\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { type KeyStore } from "@buildanagent/agent-safety";
|
|
8
|
+
import { type CaseReport, type RunnableCase } from "./run-cases.js";
|
|
9
|
+
/** What a factory returns: the store under test. */
|
|
10
|
+
export interface KeyStoreUnderTest {
|
|
11
|
+
readonly store: KeyStore;
|
|
12
|
+
}
|
|
13
|
+
/** Makes a fresh store for each case. */
|
|
14
|
+
export type KeyStoreFactory = () => KeyStoreUnderTest | Promise<KeyStoreUnderTest>;
|
|
15
|
+
/** One key store case. */
|
|
16
|
+
export type KeyStoreCase = RunnableCase;
|
|
17
|
+
/** What `runKeyStoreConformance()` reports. */
|
|
18
|
+
export type KeyStoreConformanceReport = CaseReport;
|
|
19
|
+
/** The cases, each run against a store from `factory`. */
|
|
20
|
+
export declare function keyStoreConformanceCases(factory: KeyStoreFactory): readonly KeyStoreCase[];
|
|
21
|
+
/** Runs every case and reports which passed, which skipped and which failed. */
|
|
22
|
+
export declare function runKeyStoreConformance(factory: KeyStoreFactory): Promise<KeyStoreConformanceReport>;
|