Update files

This commit is contained in:
Mohamed Boudra
2026-02-04 14:12:48 +07:00
parent 835e8e45d1
commit a616b847bb
2 changed files with 33 additions and 0 deletions

View File

@@ -162,6 +162,32 @@ describe("AgentStorage", () => {
expect(updatedRecord?.lastStatus).toBe("running");
});
test("applySnapshot preserves archivedAt (soft-delete) status", async () => {
const agentId = "agent-archived";
await storage.applySnapshot(
createManagedAgent({
id: agentId,
lifecycle: "idle",
})
);
const archivedAt = "2025-01-03T00:00:00.000Z";
const recordBeforeArchive = await storage.get(agentId);
expect(recordBeforeArchive).not.toBeNull();
await storage.upsert({ ...recordBeforeArchive!, archivedAt });
await storage.applySnapshot(
createManagedAgent({
id: agentId,
lifecycle: "running",
updatedAt: new Date("2025-01-04T00:00:00.000Z"),
})
);
const recordAfterSnapshot = await storage.get(agentId);
expect(recordAfterSnapshot?.archivedAt).toBe(archivedAt);
});
test("stores titles independently of snapshots", async () => {
await storage.applySnapshot(
createManagedAgent({

View File

@@ -230,6 +230,13 @@ export class AgentStorage {
? options?.internal
: (agent.internal ?? existing?.internal),
});
// Preserve soft-delete/archive status across snapshot flushes.
// `archivedAt` is not part of the ManagedAgent snapshot, so a naive projection
// would wipe it during normal persistence (including on daemon restart).
if (existing && existing.archivedAt !== undefined) {
record.archivedAt = existing.archivedAt;
}
await this.upsert(record);
}