feat(FN-4809): merge fusion/fn-4809

This commit is contained in:
gsxdsm
2026-05-17 00:53:02 -07:00
parent 87bd369673
commit 404e202d7e
2 changed files with 60 additions and 42 deletions

View File

@@ -120,7 +120,6 @@ export type {
SandboxProvisioningPolicyInput,
SandboxProvisioningPolicyDecision,
} from "./sandbox-provisioning-policy.js";
export type { SecretAccessPolicy } from "./types.js";
export type {
ResolveSecretAccessPolicyInput,
ResolveSecretAccessPolicyDecision,

View File

@@ -1,48 +1,67 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
import type { RunAuditEventInput } from "@fusion/core";
import {
createMockStore,
mockedCreateFnAgent,
mockedExistsSync,
setupHappyPathExecSync,
} from "./merger-test-helpers.js";
import * as mergerModule from "../merger.js";
import { describe, expect, it, vi } from "vitest";
import type { RunAuditEventInput, TaskStore } from "@fusion/core";
import { createRunAuditor } from "../run-audit.js";
import { emitMergeAttemptAuditEvent } from "../merger.js";
function createStore(recordImpl?: (input: RunAuditEventInput) => Promise<void>) {
const recordRunAuditEvent = vi.fn(recordImpl ?? (async () => {}));
const store = { recordRunAuditEvent } as unknown as TaskStore;
return { store, recordRunAuditEvent };
}
describe("FN-4809 merge-attempt run_audit emission", () => {
beforeEach(() => {
vi.clearAllMocks();
mockedExistsSync.mockReturnValue(true);
setupHappyPathExecSync();
mockedCreateFnAgent.mockResolvedValue({
session: {
prompt: vi.fn().mockResolvedValue(undefined),
dispose: vi.fn(),
subscribe: vi.fn(),
on: vi.fn(),
state: {},
sessionManager: { getLeafId: vi.fn().mockReturnValue("leaf-1") },
},
} as any);
it.each([1, 2, 3] as const)("emits git merge:start with merge-attempt-%d phase (FN-4809)", async (attemptNum) => {
const { store, recordRunAuditEvent } = createStore();
const audit = createRunAuditor(store, {
runId: "run-1",
agentId: "agent-1",
taskId: "FN-4809",
phase: "merge",
});
await emitMergeAttemptAuditEvent({
audit,
branch: "fusion/FN-4809",
attemptNum,
mergeConflictStrategy: "smart-prefer-main",
attemptLabel: `Attempt ${attemptNum}: test`,
taskId: "FN-4809",
});
expect(recordRunAuditEvent).toHaveBeenCalledTimes(1);
const event = recordRunAuditEvent.mock.calls[0][0] as RunAuditEventInput;
expect(event.domain).toBe("git");
expect(event.mutationType).toBe("merge:start");
expect(event.taskId).toBe("FN-4809");
expect(event.metadata).toMatchObject({
phase: `merge-attempt-${attemptNum}`,
attemptNum,
mergeConflictStrategy: "smart-prefer-main",
attemptLabel: `Attempt ${attemptNum}: test`,
});
expect(/^merge-attempt-/.test(String(event.metadata?.phase))).toBe(true);
});
it("emits git merge:start with merge-attempt-1 phase (FN-4809)", async () => {
const store = createMockStore({ branch: "fusion/FN-050" }) as any;
const recordRunAuditEvent = vi.fn(async (_input: RunAuditEventInput) => {});
store.recordRunAuditEvent = recordRunAuditEvent;
it("swallows run-audit record failures (FN-4809)", async () => {
const { store } = createStore(async () => {
throw new Error("db unavailable");
});
const audit = createRunAuditor(store, {
runId: "run-1",
agentId: "agent-1",
taskId: "FN-4809",
phase: "merge",
});
await mergerModule.aiMergeTask(store, "/tmp/root", "FN-050");
const mergeStartEvent = recordRunAuditEvent.mock.calls
.map((call) => call[0] as RunAuditEventInput)
.find((event) =>
event.domain === "git"
&& event.mutationType === "merge:start"
&& event.taskId === "FN-050"
&& typeof event.metadata?.phase === "string"
&& /^merge-attempt-/.test(event.metadata.phase),
);
expect(mergeStartEvent).toBeDefined();
expect(mergeStartEvent?.metadata).toMatchObject({ phase: "merge-attempt-1" });
await expect(
emitMergeAttemptAuditEvent({
audit,
branch: "fusion/FN-4809",
attemptNum: 1,
mergeConflictStrategy: "smart-prefer-main",
attemptLabel: "Attempt 1: test",
taskId: "FN-4809",
}),
).resolves.toBeUndefined();
});
});