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