feat: prepare installation workspaces through existing readiness services
This commit is contained in:
@@ -15,10 +15,34 @@ import {
|
||||
import { WorkspaceSecretStore } from "../src/workspaces/secret-store.js";
|
||||
import type { WorkspaceRegistry, WorkspaceRevision } from "../src/workspaces/registry.js";
|
||||
import type { WorkspaceDescriptor } from "../src/workspaces/schema.js";
|
||||
// @ts-expect-error The native operator embeds this plain ESM client.
|
||||
import { prepareWorkspace } from "../../tools/tht/internal/installapply/import-bindings.mjs";
|
||||
|
||||
const roots: string[] = [];
|
||||
afterEach(() => { for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true }); });
|
||||
|
||||
test("installation retry preserves the durable destructive review and source comments", async () => {
|
||||
const { app, repository, database, setObserved } = await setup();
|
||||
try {
|
||||
await seedCatalog(repository, database);
|
||||
const tablesBefore = await repository.listTables(database.id);
|
||||
setObserved({ schemaVersion: 1, capabilities: { tables: "available", columns: "available", relationships: "available" }, tables: [], columns: [], relationships: [] });
|
||||
const started = await app.inject({ method: "POST", url: `/catalog/databases/${database.id}/sync-runs`, payload: { version: database.version, scope: "all", tableIds: [] } });
|
||||
const run = await waitFor(repository, started.json().id, "awaiting_confirmation");
|
||||
const request = async (path: string, body?: unknown) => {
|
||||
expect(body).toBeUndefined();
|
||||
const response = await app.inject({ method: "GET", url: path });
|
||||
return new Response(response.body, { status: response.statusCode, headers: { "content-type": "application/json" } });
|
||||
};
|
||||
for (let attempt = 0; attempt < 2; attempt++) {
|
||||
await expect(prepareWorkspace(request, "psd-clinical", revision.commit)).rejects.toMatchObject({ code: "schema_review_required", runId: run.id });
|
||||
}
|
||||
expect(await repository.listTables(database.id)).toEqual(tablesBefore);
|
||||
expect(await repository.listSyncRuns(database.id)).toHaveLength(1);
|
||||
expect((await repository.getSyncRun(run.id))?.state).toBe("awaiting_confirmation");
|
||||
} finally { await app.close(); }
|
||||
});
|
||||
|
||||
const workspace: WorkspaceDescriptor = {
|
||||
workspace: { schema_version: 4, id: "psd-clinical", name: "Policlinico San Donato", language: "it" },
|
||||
dwh: { engine: "postgres", database: "warehouse", schema: "datawarehouse", port: 5432, supported_transports: ["postgres_direct"] },
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import { expect, test } from "vitest";
|
||||
// The shipped operator client is plain ESM, shared by the embedded command and these API-boundary tests.
|
||||
// @ts-expect-error JavaScript operator module has no separate declaration file.
|
||||
import { prepareWorkspace } from "../../tools/tht/internal/installapply/import-bindings.mjs";
|
||||
|
||||
const revision = "a".repeat(40);
|
||||
|
||||
test.each(["blocked", "failed"])("configured Evidence/index failure (%s) remains a real stop", async state => {
|
||||
const request = async (path: string, body?: unknown): Promise<Response> => {
|
||||
if (path === "/catalog/databases") return Response.json([{ id: "database-id", workspaceId: "chinook", version: 2, schemaSyncedVersion: 2,
|
||||
binding: { transport: "postgres_direct" }, workspaceRevision: { commit: revision } }]);
|
||||
if (path.endsWith("/sync-runs")) return Response.json([]);
|
||||
if (path.endsWith("/preprocessing")) return Response.json({ state }, { status: body === undefined ? 200 : 422 });
|
||||
throw Error("unexpected destructive operation");
|
||||
};
|
||||
await expect(prepareWorkspace(request, "chinook", revision, async () => {})).rejects.toMatchObject({ code: `preprocessing_${state}` });
|
||||
});
|
||||
|
||||
test("SSH metadata connectivity cannot be mistaken for session transport support", async () => {
|
||||
const calls: string[] = [];
|
||||
const request = async (path: string) => {
|
||||
calls.push(path);
|
||||
return Response.json([{ id: "database-id", workspaceId: "chinook", version: 2,
|
||||
binding: { transport: "ssh_tunnel" }, workspaceRevision: { commit: revision } }]);
|
||||
};
|
||||
await expect(prepareWorkspace(request, "chinook", revision)).rejects.toMatchObject({ code: "session_transport_unsupported" });
|
||||
expect(calls).toEqual(["/catalog/databases"]);
|
||||
});
|
||||
test("a destructive synchronization stops at the existing domain gate without confirmation", async () => {
|
||||
const calls: string[] = [];
|
||||
const request = async (path: string) => {
|
||||
calls.push(path);
|
||||
if (path === "/catalog/databases") return Response.json([{ id: "database-id", workspaceId: "chinook", version: 2,
|
||||
binding: { transport: "postgres_direct" }, workspaceRevision: { commit: revision } }]);
|
||||
if (path.endsWith("/sync-runs")) return Response.json([{ id: "run-id", state: "awaiting_confirmation", scope: "all" }]);
|
||||
throw Error("unexpected operation");
|
||||
};
|
||||
await expect(prepareWorkspace(request, "chinook", revision)).rejects.toMatchObject({ code: "schema_review_required", runId: "run-id" });
|
||||
expect(calls).toEqual(["/catalog/databases", "/catalog/databases/database-id/sync-runs"]);
|
||||
});
|
||||
|
||||
test("fresh additive sync and preprocessing use existing APIs once, then repeat as a no-op", async () => {
|
||||
const writes: string[] = [];
|
||||
let synchronized = false, preprocessed = false;
|
||||
const request = async (path: string, body?: unknown) => {
|
||||
if (body !== undefined) writes.push(path);
|
||||
if (path === "/catalog/databases") return Response.json([{ id: "database-id", workspaceId: "chinook", version: 2,
|
||||
schemaSyncedVersion: synchronized ? 2 : undefined,
|
||||
binding: { transport: "postgres_direct" }, workspaceRevision: { commit: revision } }]);
|
||||
if (path === "/catalog/databases/database-id") return Response.json({ version: 2, schemaSyncedVersion: 2 });
|
||||
if (path.endsWith("/sync-runs")) {
|
||||
if (body) { expect(body).toEqual({ version: 2, scope: "all", tableIds: [] }); return Response.json({ id: "run-id", state: "queued", scope: "all" }); }
|
||||
return Response.json(synchronized ? [{ id: "run-id", state: "succeeded", scope: "all" }] : []);
|
||||
}
|
||||
if (path === "/catalog/sync-runs/run-id") { synchronized = true; return Response.json({ id: "run-id", state: "succeeded", scope: "all" }); }
|
||||
if (path === "/workspaces/chinook/preprocessing") {
|
||||
if (body) preprocessed = true;
|
||||
return Response.json({ state: preprocessed ? "ready" : "required" });
|
||||
}
|
||||
throw Error("unexpected operation");
|
||||
};
|
||||
expect(await prepareWorkspace(request, "chinook", revision, async () => {})).toEqual({ workspaceId: "chinook", state: "ready" });
|
||||
expect(await prepareWorkspace(request, "chinook", revision, async () => {})).toEqual({ workspaceId: "chinook", state: "ready" });
|
||||
expect(writes).toEqual(["/catalog/databases/database-id/sync-runs", "/workspaces/chinook/preprocessing"]);
|
||||
});
|
||||
Reference in New Issue
Block a user