|
1 | 1 | import path from "node:path"; |
2 | 2 | import { DatabaseSync } from "node:sqlite"; |
3 | | -import { afterEach, describe, expect, it } from "vitest"; |
| 3 | +import { afterEach, describe, expect, it, vi } from "vitest"; |
4 | 4 | import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js"; |
5 | 5 | import { closeOpenClawStateDatabaseForTest } from "../state/openclaw-state-db.js"; |
6 | 6 | import { createAuditEventWriter } from "./audit-event-writer.js"; |
@@ -59,6 +59,46 @@ afterEach(() => { |
59 | 59 | const tempDirs = useAutoCleanupTempDirTracker(afterEach); |
60 | 60 |
|
61 | 61 | describe("private execution decision work", () => { |
| 62 | + it.each(["raw ref", "complete envelope"] as const)( |
| 63 | + "rejects an oversized %s before the FIFO clone boundary", |
| 64 | + async (oversizedPart) => { |
| 65 | + const stateDir = tempDirs.make("openclaw-audit-private-decision-bounds-"); |
| 66 | + const errors: string[] = []; |
| 67 | + const writer = createAuditEventWriter({ stateDir, onError: (error) => errors.push(error) }); |
| 68 | + const token = createExecutionIdentityAdmissionToken("bounded-private-decision-run", { |
| 69 | + contextId: "bounded-private-decision-context", |
| 70 | + executionId: "bounded-private-decision-execution", |
| 71 | + now: 1_000, |
| 72 | + }); |
| 73 | + const work = decisionWork({ |
| 74 | + token, |
| 75 | + receiptId: "bounded-private-decision", |
| 76 | + rawResource: oversizedPart === "raw ref" ? "r".repeat(4_097) : "resource", |
| 77 | + rawTarget: "target", |
| 78 | + }); |
| 79 | + if (oversizedPart === "complete envelope") { |
| 80 | + const refs = Array.from({ length: 16 }, (_, index) => `${index}:`.padEnd(256, "p")); |
| 81 | + work.receipt.enforcement.policyRefs = refs; |
| 82 | + work.receipt.enforcement.grantRefs = refs; |
| 83 | + work.receipt.enforcement.contextFieldsUsed = refs; |
| 84 | + work.receipt.missingEvidence = refs; |
| 85 | + work.receipt.remediation = Array.from({ length: 8 }, (_, index) => ({ |
| 86 | + code: `repair-${index}`, |
| 87 | + text: "r".repeat(512), |
| 88 | + })); |
| 89 | + } |
| 90 | + |
| 91 | + await writer.ready; |
| 92 | + const clone = vi.spyOn(globalThis, "structuredClone"); |
| 93 | + expect(writer.recordExecutionDecisionWork(work)).toBe(false); |
| 94 | + expect(clone).not.toHaveBeenCalled(); |
| 95 | + clone.mockRestore(); |
| 96 | + await writer.stop(); |
| 97 | + |
| 98 | + expect(errors).toEqual(["audit execution decision receipt could not be queued"]); |
| 99 | + }, |
| 100 | + ); |
| 101 | + |
62 | 102 | it("projects private refs inside the admission FIFO without retaining raw owners", async () => { |
63 | 103 | const stateDir = tempDirs.make("openclaw-audit-private-decision-"); |
64 | 104 | const database = { env: { OPENCLAW_STATE_DIR: stateDir } }; |
|
0 commit comments