test(FN-4826): complete Step 4 — cover handoff telemetry paths
Fusion-Task-Id: FN-4826 Fusion-Task-Lineage: b08a58c8-66ab-43d4-bdf9-69d2b56b7bcc
This commit is contained in:
committed by
gsxdsm
parent
3453e77396
commit
1553f1dd0d
@@ -46,7 +46,7 @@ describe("MeshLeaseManager owning-node handoff integration", () => {
|
||||
localNodeId: "node-local",
|
||||
getHandoffPolicy: async () => policy,
|
||||
nodeHealthMonitor: {
|
||||
getNodeHealth: () => "offline",
|
||||
getNodeHealth: () => (ownerNodeId === "node-local" ? "online" : "offline"),
|
||||
} as unknown as NodeHealthMonitor,
|
||||
});
|
||||
return manager.recoverAbandonedLease(taskId, "test-owner-unavailable", { preserveProgress: true });
|
||||
@@ -54,28 +54,51 @@ describe("MeshLeaseManager owning-node handoff integration", () => {
|
||||
|
||||
it("applies handoff policy matrix for peer-owned leases", async () => {
|
||||
await seedLease("node-peer");
|
||||
let baselineEventIds = new Set(taskStore.getRunAuditEvents({ taskId, limit: 200 }).map((event) => event.id));
|
||||
expect(await runCase("block", "node-peer")).toBe(false);
|
||||
let task = await taskStore.getTask(taskId);
|
||||
expect(task?.checkedOutBy).toBe("agent-1");
|
||||
let newEvents = taskStore.getRunAuditEvents({ taskId, limit: 200 }).filter((event) => !baselineEventIds.has(event.id));
|
||||
expect(newEvents.some((event) => event.mutationType === "node:handoff:parked" && event.metadata?.source === "mesh-lease.recover" && event.metadata?.decisionReason === "handoff_blocked_by_policy")).toBe(true);
|
||||
expect(newEvents.some((event) => event.mutationType === "node:lease:recovered")).toBe(false);
|
||||
|
||||
await seedLease("node-peer");
|
||||
baselineEventIds = new Set(taskStore.getRunAuditEvents({ taskId, limit: 200 }).map((event) => event.id));
|
||||
expect(await runCase("reassign-to-local", "node-peer")).toBe(true);
|
||||
task = await taskStore.getTask(taskId);
|
||||
expect(task?.checkedOutBy ?? null).toBeNull();
|
||||
newEvents = taskStore.getRunAuditEvents({ taskId, limit: 200 }).filter((event) => !baselineEventIds.has(event.id));
|
||||
const localRecoveryEvent = newEvents.find((event) => event.mutationType === "node:lease:recovered");
|
||||
expect(localRecoveryEvent).toBeTruthy();
|
||||
expect(localRecoveryEvent?.metadata?.source).toBe("mesh-lease.recover");
|
||||
expect(typeof localRecoveryEvent?.metadata?.epoch).toBe("number");
|
||||
expect(String(localRecoveryEvent?.metadata?.recoveryReason ?? "")).toContain("test-owner-unavailable");
|
||||
|
||||
await seedLease("node-peer");
|
||||
baselineEventIds = new Set(taskStore.getRunAuditEvents({ taskId, limit: 200 }).map((event) => event.id));
|
||||
expect(await runCase("reassign-any-healthy", "node-peer")).toBe(true);
|
||||
task = await taskStore.getTask(taskId);
|
||||
expect(task?.checkedOutBy ?? null).toBeNull();
|
||||
newEvents = taskStore.getRunAuditEvents({ taskId, limit: 200 }).filter((event) => !baselineEventIds.has(event.id));
|
||||
const anyRecoveryEvent = newEvents.find((event) => event.mutationType === "node:lease:recovered");
|
||||
expect(anyRecoveryEvent).toBeTruthy();
|
||||
expect(anyRecoveryEvent?.metadata?.source).toBe("mesh-lease.recover");
|
||||
expect(typeof anyRecoveryEvent?.metadata?.epoch).toBe("number");
|
||||
expect(String(anyRecoveryEvent?.metadata?.recoveryReason ?? "")).toContain("test-owner-unavailable");
|
||||
});
|
||||
|
||||
it("recovers self-owned leases regardless of policy", async () => {
|
||||
for (const policy of ["block", "reassign-to-local", "reassign-any-healthy"] as const) {
|
||||
await seedLease("node-local");
|
||||
const baselineEventIds = new Set(taskStore.getRunAuditEvents({ taskId, limit: 200 }).map((event) => event.id));
|
||||
const recovered = await runCase(policy, "node-local");
|
||||
expect(recovered).toBe(true);
|
||||
const task = await taskStore.getTask(taskId);
|
||||
expect(task?.checkedOutBy ?? null).toBeNull();
|
||||
const newEvents = taskStore.getRunAuditEvents({ taskId, limit: 200 }).filter((event) => !baselineEventIds.has(event.id));
|
||||
const recoveryEvents = newEvents.filter((event) => event.mutationType === "node:lease:recovered");
|
||||
expect(recoveryEvents).toHaveLength(1);
|
||||
expect(recoveryEvents[0]?.metadata?.source).toBe("mesh-lease.recover");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user