fix: retain snapshots for removed workspaces

This commit is contained in:
2026-08-04 08:52:11 +02:00
parent 8b046f9fb2
commit 3b23cf3714
4 changed files with 116 additions and 3 deletions
+35
View File
@@ -135,6 +135,41 @@ test("an administrator session listing retains revisions referenced by resumable
expect(retained).toHaveBeenCalledWith([retainedRevision]);
});
test("retention scans a removed workspace's retained snapshot", async () => {
const retained = vi.fn(async () => {});
const removedRevision = "e".repeat(40);
const activeSnapshot = "/registry/snapshots/a/other.yaml";
const removedSnapshot = "/registry/snapshots/e/removed.yaml";
const listRetainedSnapshots = vi.fn(async () => [
{ id: "other", commit: "a".repeat(40), state: "operational", snapshotPath: activeSnapshot },
{ id: "removed", commit: removedRevision, state: "operational", snapshotPath: removedSnapshot },
]);
const app = buildApp(loadConfig({ AUTH_MODE: "upstream", THT_HARNESS_DIR: "../harness" }), {
thtRunner: {
withPrincipal: () => ({
sessionList: async (snapshotPath: string) => snapshotPath === removedSnapshot
? [{ id: "resumable", status: "closed", archived: false, workspace_revision: removedRevision }]
: [],
}),
} as any,
workspaceRegistry: {
list: async () => [{ id: "other", commit: "a".repeat(40), state: "operational", snapshotPath: activeSnapshot }],
listRetainedSnapshots,
reconcileSnapshotRetention: retained,
} as any,
});
const response = await app.inject({
method: "GET", url: "/sessions?scope=all",
headers: { ...aliceHeaders, "x-thoth-is-admin": "1" },
});
expect(response.statusCode).toBe(200);
expect(listRetainedSnapshots).toHaveBeenCalledOnce();
expect(retained).toHaveBeenCalledWith([removedRevision]);
expect(response.json()).toEqual([expect.objectContaining({ id: "resumable" })]);
});
test("the single local installation listing reconciles its resumable workspace pins", async () => {
const retained = vi.fn(async () => {});
const retainedRevision = "d".repeat(40);