Files
PaperClipAI/tests/runner-e2e/chat-catalog-domains/runtime-lost-sandbox.test.ts
T

14 lines
4.6 KiB
TypeScript

import { expect, it } from "vitest";
import type { EnvironmentLease } from "../../../packages/shared/src/types/environment.js";
import { destroyedLeaseBound, gradeLostSandbox, lostSandboxGuidance } from "./runtime-lost-sandbox.js";
function valid() { return { companyId: "company", leadId: "ceo", scenarioId: "workspaces.recover-lost-sandbox", origin: "http://127.0.0.1:42123", reply: "", links: [], agents: [], humanQueries: [], activity: [], tasks: [{ id: "website" }], runs: [{ id: "old", status: "failed" }, { id: "canonical", status: "succeeded" }, { id: "reconstruction", status: "succeeded" }, { id: "report", status: "succeeded" }], state: { task: { id: "website" }, exactProviderDestroyed: true, platformDestructionBound: true, survivingAttachmentVerified: true, noReconstructionBeforeHuman: true, guidanceReply: "The original sandbox was destroyed. A board member can use Continue from saved sources with the surviving attachments to reconstruct the page; missing unregistered files are not recovered.", actualReconstructionUi: true, actualReconstructionStatus: 202, humanDecisionBound: true, missingWorkAcknowledged: true, freshSessionBound: true, decisionSourcesBound: true, reconstructedArtifactVerified: true, newerWorkPreserved: true, originalFailureRetained: true, originalEventsRetained: true, confirmationBound: true, confirmationReply: "The website was reconstructed from the surviving attachment and the newer edits were preserved. The original run remains failed; missing unregistered state from the destroyed workspace is still unavailable." } }; }
it("accepts real authorized reconstruction while preserving the old failure", () => expect(gradeLostSandbox(valid()).passed).toBe(true));
it("accepts a natural saved-source guidance and factual result paraphrase", () => { const o = valid(); o.state.guidanceReply = "You need to choose the saved attachments and acknowledge the lost workspace state before rebuilding. An operator owns that decision."; o.state.confirmationReply = "Only the attached source was used to rebuild the page; your newer files were preserved separately. Unattached work cannot be restored from the destroyed allocation."; expect(gradeLostSandbox(o).passed).toBe(true); });
it("rejects SDK absence alone without independent platform evidence", () => { const o = valid(); o.state.platformDestructionBound = false; expect(gradeLostSandbox(o).passed).toBe(false); });
it("rejects an API-only substitute for the real routed human decision", () => { const o = valid(); o.state.actualReconstructionUi = false; expect(gradeLostSandbox(o).passed).toBe(false); });
it("rejects wrong decision source, stale session, missing newer edits and wrong reply phase", () => { for (const key of ["decisionSourcesBound", "freshSessionBound", "newerWorkPreserved", "confirmationBound", "humanDecisionBound"] as const) { const o = valid(); o.state[key] = false; expect(gradeLostSandbox(o).passed).toBe(false); } });
it("rejects erasing the failed source or claiming all lost files recovered", () => { const o = valid(); o.runs[0]!.status = "succeeded"; expect(gradeLostSandbox(o).passed).toBe(false); const p = valid(); p.state.confirmationReply += " All lost work was recovered."; expect(gradeLostSandbox(p).passed).toBe(false); expect(lostSandboxGuidance("I already reconstructed all lost files from that destroyed sandbox.")).toBe(false); });
it("requires the exact persisted destroyed termination receipt and no ongoing cleanup", () => { const binding = { companyId: "company", taskId: "website", runId: "old", leaseId: "lease", sandboxId: "sandbox", environmentId: "environment" }; const lease = { id: "lease", companyId: "company", issueId: "website", heartbeatRunId: "old", environmentId: "environment", provider: "daytona", providerLeaseId: "sandbox", metadata: { remoteExecutionTermination: { state: "destroyed" }, pendingCleanupInFlight: false } } as unknown as EnvironmentLease; expect(destroyedLeaseBound(lease, binding)).toBe(true); expect(destroyedLeaseBound({ ...lease, providerLeaseId: "another" }, binding)).toBe(false); expect(destroyedLeaseBound({ ...lease, metadata: { remoteExecutionTermination: { state: "stopped" } } }, binding)).toBe(false); expect(destroyedLeaseBound({ ...lease, metadata: { ...lease.metadata, pendingCleanupInFlight: true } }, binding)).toBe(false); });
it("rejects guidance that waives the actual human reconstruction decision", () => { expect(lostSandboxGuidance("The sandbox was destroyed; you can reconstruct from saved attachments without any board approval.")).toBe(false); expect(lostSandboxGuidance("You cannot rebuild the lost workspace without human approval of the saved attachments.")).toBe(true); });