fix: retain snapshots for removed workspaces
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -522,6 +522,33 @@ test("retains a historical snapshot while a resumable manifest still references
|
||||
expect(existsSync(registry.snapshotPath(currentCommit, "psd-clinical"))).toBe(true);
|
||||
});
|
||||
|
||||
test("lists operational descriptors retained after their workspace was removed from the active revision", async () => {
|
||||
const remote = await fixture();
|
||||
const root = join(remote.root, "registry");
|
||||
const registry = new WorkspaceRegistry(config(root, remote.remote));
|
||||
await registry.bootstrap();
|
||||
|
||||
writeFileSync(join(remote.source, "workspaces", "archive-only.yaml"), validYaml.replace(
|
||||
"id: psd-clinical", "id: archive-only",
|
||||
));
|
||||
await git(remote.source, ["add", "workspaces/archive-only.yaml"]);
|
||||
await git(remote.source, ["commit", "-m", "Add retained workspace"]);
|
||||
await git(remote.source, ["push", "origin", "main"]);
|
||||
await registry.pull();
|
||||
|
||||
rmSync(join(remote.source, "workspaces", "psd-clinical.yaml"));
|
||||
await git(remote.source, ["add", "-u"]);
|
||||
await git(remote.source, ["commit", "-m", "Remove original workspace"]);
|
||||
await git(remote.source, ["push", "origin", "main"]);
|
||||
await registry.pull();
|
||||
|
||||
const retained = await registry.listRetainedSnapshots();
|
||||
expect(retained).toEqual(expect.arrayContaining([
|
||||
expect.objectContaining({ id: "psd-clinical", commit: remote.initialCommit, state: "operational" }),
|
||||
expect.objectContaining({ id: "archive-only", state: "operational" }),
|
||||
]));
|
||||
});
|
||||
|
||||
test("does not bypass an existing live advisory repository lock", async () => {
|
||||
const remote = await fixture();
|
||||
const root = join(remote.root, "registry");
|
||||
|
||||
Reference in New Issue
Block a user