Repository navigation
test(e2e): validate #8304 failed-startup recovery #8874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b0040bb
d472658
9dd967a
2708023
3952ff5
6456527
1728562
2009c24
410e9c2
f0c7bf7
83f680b
e3dcddd
79b41c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,90 @@ | |
|
|
||
| import { afterEach, describe, expect, it, vi } from "vitest"; | ||
|
|
||
| import { relockAndReconfirm, resolveSettleMs } from "./relock-reconfirm"; | ||
| import { | ||
| confirmDeferredPermissivePolicyForStoppedSandbox, | ||
| relockAndReconfirm, | ||
| resolveSettleMs, | ||
| } from "./relock-reconfirm"; | ||
|
|
||
| const SUBMITTED_POLICY_HASH = "d71616b0333b"; | ||
|
|
||
| function timedOutPolicySet(overrides: { stdout?: string; stderr?: string } = {}) { | ||
| return { | ||
| status: 1, | ||
| stdout: overrides.stdout ?? `Policy version 11 submitted (hash: ${SUBMITTED_POLICY_HASH})\n`, | ||
| stderr: overrides.stderr ?? "Timeout waiting for policy version 11 to load\n", | ||
| }; | ||
| } | ||
|
|
||
| function policyReceipt(hash = SUBMITTED_POLICY_HASH, version = "11", status = "pending") { | ||
| return { | ||
| status: 0, | ||
| stdout: `Version: ${version}\nHash: ${hash}\nStatus: ${status}\n---\nversion: 1\nnetwork_policies: {}\n`, | ||
| stderr: "", | ||
| }; | ||
| } | ||
|
|
||
| describe("deferred permissive policy confirmation", () => { | ||
| it("accepts an exact committed receipt only after proving no sandbox container runs (#8304)", () => { | ||
| const proveNoRunningDirectSandbox = vi.fn(() => true); | ||
| const readPolicyReceipt = vi.fn(() => policyReceipt()); | ||
|
|
||
| expect( | ||
| confirmDeferredPermissivePolicyForStoppedSandbox(timedOutPolicySet(), { | ||
| proveNoRunningDirectSandbox, | ||
| readPolicyReceipt, | ||
| parsePolicy: () => "version: 1\nnetwork_policies: {}", | ||
| }), | ||
| ).toBe(true); | ||
| expect(proveNoRunningDirectSandbox).toHaveBeenCalledOnce(); | ||
| expect(readPolicyReceipt).toHaveBeenCalledOnce(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ["a live sandbox", false, policyReceipt(), timedOutPolicySet()], | ||
| ["a mismatched hash", true, policyReceipt("aaaaaaaaaaaa"), timedOutPolicySet()], | ||
| ["a mismatched version", true, policyReceipt(SUBMITTED_POLICY_HASH, "12"), timedOutPolicySet()], | ||
| [ | ||
| "a rejected receipt", | ||
| true, | ||
| policyReceipt(SUBMITTED_POLICY_HASH, "11", "rejected"), | ||
| timedOutPolicySet(), | ||
| ], | ||
| [ | ||
| "submission without a timeout", | ||
| true, | ||
| policyReceipt(), | ||
| timedOutPolicySet({ stderr: "policy rejected\n" }), | ||
| ], | ||
| [ | ||
| "duplicate submission evidence", | ||
| true, | ||
| policyReceipt(), | ||
| timedOutPolicySet({ | ||
| stdout: `Policy version 11 submitted (hash: ${SUBMITTED_POLICY_HASH})\nPolicy version 11 submitted (hash: ${SUBMITTED_POLICY_HASH})\n`, | ||
| }), | ||
| ], | ||
| ])("rejects %s (#8304)", (_name, stopped, receipt, policySetResult) => { | ||
| expect( | ||
| confirmDeferredPermissivePolicyForStoppedSandbox(policySetResult, { | ||
| proveNoRunningDirectSandbox: () => stopped, | ||
| readPolicyReceipt: () => receipt, | ||
| parsePolicy: () => "version: 1\nnetwork_policies: {}", | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Cover both permitted receipt states and duplicate receipt fields. The success case covers As per path instructions, tests must give behavioral confidence. 🤖 Prompt for AI AgentsSource: Path instructions |
||
|
|
||
| it("rejects a receipt whose policy body is invalid (#8304)", () => { | ||
| expect( | ||
| confirmDeferredPermissivePolicyForStoppedSandbox(timedOutPolicySet(), { | ||
| proveNoRunningDirectSandbox: () => true, | ||
| readPolicyReceipt: () => policyReceipt(), | ||
| parsePolicy: () => "", | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| const sealedHashes = { | ||
| "/sandbox/.openclaw/openclaw.json": | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.