feat: recover interrupted installation preparation safely
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
type WorkspacePreprocessingRouteDeps,
|
||||
} from "../src/routes/workspace-preprocessing.js";
|
||||
import type { WorkspaceRegistry } from "../src/workspaces/registry.js";
|
||||
import { PreprocessingStateError } from "../src/workspaces/preprocessing-state.js";
|
||||
|
||||
const admin: PrincipalContext = {
|
||||
issuer: "test",
|
||||
@@ -17,6 +18,22 @@ const admin: PrincipalContext = {
|
||||
isAdmin: true,
|
||||
};
|
||||
|
||||
test("explicit interrupted-run recovery is guarded and never steals an active owner", async () => {
|
||||
const run = vi.fn(async () => { throw new PreprocessingStateError("preprocessing_conflict", "private owner details"); });
|
||||
const deps = routeDeps(() => database({ preprocessingStatus: "running" }), { service: { run, clear: vi.fn() } });
|
||||
const app = Fastify();
|
||||
app.addHook("preHandler", async request => { request.principal = admin; });
|
||||
workspacePreprocessingRoutes(app, deps);
|
||||
try {
|
||||
const response = await app.inject({ method: "POST", url: "/workspaces/catalog-workspace/preprocessing", payload: { recoverInterrupted: true } });
|
||||
expect(response.statusCode).toBe(409);
|
||||
expect(response.json()).toMatchObject({ code: "preprocessing_conflict", state: "running" });
|
||||
expect(response.body).not.toContain("private owner");
|
||||
expect(run).toHaveBeenCalledOnce();
|
||||
expect(deps.service.clear).not.toHaveBeenCalled();
|
||||
} finally { await app.close(); }
|
||||
});
|
||||
|
||||
function database(overrides: Partial<WorkspaceDatabase> = {}): WorkspaceDatabase {
|
||||
return {
|
||||
id: "49b6491a-78bb-4cee-b27b-0efaf4419774",
|
||||
|
||||
Reference in New Issue
Block a user