test(FN-4689): complete Step 3 — update sandbox wiring audit expectations

Fusion-Task-Id: FN-4689
Fusion-Task-Lineage: 3b856c6f-27b2-4a1c-bd6e-41e716bffd4d
This commit is contained in:
Fusion (runfusion.ai)
2026-05-15 16:32:54 -07:00
committed by gsxdsm
parent 423041a14a
commit b2fb268bf8

View File

@@ -1,8 +1,11 @@
import { describe, expect, it } from "vitest"; import { describe, expect, it, vi } from "vitest";
import type { RunAuditEventInput, TaskStore } from "@fusion/core"; import type { RunAuditEventInput, Routine, RoutineStore, TaskStore } from "@fusion/core";
import { __runConfiguredCommandForTests } from "../executor.js"; import { __runConfiguredCommandForTests } from "../executor.js";
import { __executePostMergeScriptStepForTests } from "../merger.js"; import { __executePostMergeScriptStepForTests } from "../merger.js";
import { createRunAuditor } from "../run-audit.js"; import { createRunAuditor } from "../run-audit.js";
import { RoutineRunner } from "../routine-runner.js";
import { __resetSandboxBackendForTests, __setSandboxBackendForTests } from "../sandbox/index.js";
import type { HeartbeatMonitor } from "../agent-heartbeat.js";
class AuditStoreStub { class AuditStoreStub {
events: RunAuditEventInput[] = []; events: RunAuditEventInput[] = [];
@@ -62,4 +65,67 @@ describe("sandbox wiring audit emissions", () => {
expect(response.success).toBe(true); expect(response.success).toBe(true);
expect(store.events.some((event) => event.domain === "sandbox" && event.mutationType === "sandbox:run")).toBe(true); expect(store.events.some((event) => event.domain === "sandbox" && event.mutationType === "sandbox:run")).toBe(true);
}); });
it("emits sandbox:prepare and sandbox:run for routine-runner command execution", async () => {
__setSandboxBackendForTests({
capabilities: () => ({ id: "native", supportsNetworkPolicy: false, supportsFilesystemPolicy: false, supportsStreaming: true, platform: "any" }),
prepare: vi.fn().mockResolvedValue(undefined),
run: vi.fn().mockResolvedValue({ stdout: "ok", stderr: "", exitCode: 0, signal: null, timedOut: false, bufferExceeded: false }),
runStreaming: vi.fn(),
dispose: vi.fn().mockResolvedValue(undefined),
});
const store = new AuditStoreStub();
const routine: Routine = {
id: "routine-audit",
agentId: "routine-agent",
name: "Routine Audit",
enabled: true,
executionPolicy: "parallel",
catchUpPolicy: "skip",
runCount: 0,
runHistory: [],
trigger: { type: "cron", cronExpression: "* * * * *" },
cronExpression: "* * * * *",
command: "echo ok",
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
};
const routineStore: RoutineStore = {
getRoutine: vi.fn().mockResolvedValue(routine),
startRoutineExecution: vi.fn().mockResolvedValue(undefined),
completeRoutineExecution: vi.fn().mockResolvedValue(undefined),
getDueRoutines: vi.fn().mockResolvedValue([]),
listRoutines: vi.fn().mockResolvedValue([routine]),
updateRoutine: vi.fn(),
recordRun: vi.fn(),
cancelRoutineExecution: vi.fn(),
init: vi.fn(),
on: vi.fn(),
off: vi.fn(),
} as unknown as RoutineStore;
const heartbeatMonitor = {
executeHeartbeat: vi.fn(),
start: vi.fn(),
stop: vi.fn(),
trackAgent: vi.fn(),
on: vi.fn(),
off: vi.fn(),
} as unknown as HeartbeatMonitor;
const runner = new RoutineRunner({
routineStore,
heartbeatMonitor,
rootDir: process.cwd(),
taskStore: store as unknown as TaskStore,
});
const result = await runner.executeRoutine(routine.id, "cron");
expect(result.success).toBe(true);
expect(store.events.some((event) => event.domain === "sandbox" && event.mutationType === "sandbox:prepare")).toBe(true);
expect(store.events.some((event) => event.domain === "sandbox" && event.mutationType === "sandbox:run")).toBe(true);
__resetSandboxBackendForTests();
});
}); });