refactor workspace registry addressed API
This commit is contained in:
@@ -11,7 +11,8 @@ import { parse } from "yaml";
|
||||
import { buildApp } from "../src/app.js";
|
||||
import { loadConfig } from "../src/config.js";
|
||||
import { ThtRunner } from "../src/tht/tht-runner.js";
|
||||
import { WorkspaceRegistry } from "../src/workspaces/registry.js";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { createWorkspaceRegistry, workspaceRegistryRecoveryIdentity, workspaceRegistrySnapshotPath, type WorkspaceRegistry } from "../src/workspaces/registry.js";
|
||||
import type { WorkspaceRegistryConfig } from "../src/workspaces/types.js";
|
||||
|
||||
const runFile = promisify(execFile);
|
||||
@@ -19,6 +20,23 @@ const harnessDir = resolve("../harness");
|
||||
const thtBin = join(harnessDir, ".venv", "bin", "tht");
|
||||
const roots: string[] = [];
|
||||
|
||||
async function bootstrap(registry: WorkspaceRegistry) {
|
||||
const ensured = await registry.ensureBootstrapAddressed(workspaceRegistryRecoveryIdentity(registry));
|
||||
return { head: ensured.snapshot.commit, revisions: ensured.snapshot.workspaces };
|
||||
}
|
||||
|
||||
async function pull(registry: WorkspaceRegistry) {
|
||||
const base = await bootstrap(registry);
|
||||
const identity = workspaceRegistryRecoveryIdentity(registry);
|
||||
return registry.publishAddressed({ mode: "create", operation: "registry_pull", runId: randomUUID().replaceAll("-", "").slice(0, 32) as never, requestSha256: createHash("sha256").update(`${identity.requestSha256}:${base.head}`).digest("hex") as never, installationIdentitySha256: identity.installationIdentitySha256, repositoryIdentitySha256: identity.repositoryIdentitySha256, remoteRefIdentitySha256: identity.remoteRefIdentitySha256, expectedBaseCommit: base.head as never });
|
||||
}
|
||||
|
||||
async function list(registry: WorkspaceRegistry) {
|
||||
const ensured = await registry.ensureBootstrapAddressed(workspaceRegistryRecoveryIdentity(registry));
|
||||
return ensured.snapshot.workspaces.map((item) => ({ id: item.workspaceId, commit: item.revision, blob: item.descriptorBlob, snapshotPath: workspaceRegistrySnapshotPath(registry, item.revision, item.workspaceId) }));
|
||||
}
|
||||
|
||||
|
||||
const canonicalWorkspace = `workspace:
|
||||
schema_version: 3
|
||||
id: psd-clinical
|
||||
@@ -114,9 +132,9 @@ async function fixture(workspaceSource = filesystemWorkspace) {
|
||||
maxImportBytes: 1024 * 1024,
|
||||
maxImportEntries: 16,
|
||||
};
|
||||
const registry = new WorkspaceRegistry(registryConfig);
|
||||
await registry.bootstrap();
|
||||
const revision = (await registry.list())[0];
|
||||
const registry = createWorkspaceRegistry(registryConfig);
|
||||
await bootstrap(registry);
|
||||
const revision = (await list(registry))[0];
|
||||
const environment = {
|
||||
THT_WS_PSD_CLINICAL_DWH_TRANSPORT: "postgres_direct",
|
||||
THT_WS_PSD_CLINICAL_DWH_HOST: "dwh.invalid",
|
||||
@@ -235,8 +253,8 @@ test("real Evidence-content-only commit changes runtime identity and root with i
|
||||
await git(f.source, ["add", "workspace-content/psd-clinical/evidence/guide.md"]);
|
||||
await git(f.source, ["commit", "-m", "Update Evidence content only"]);
|
||||
await git(f.source, ["push", "origin", "main"]);
|
||||
await f.registry.pull();
|
||||
const current = (await f.registry.list())[0];
|
||||
await pull(f.registry);
|
||||
const current = (await list(f.registry))[0];
|
||||
const second = await runner.acquireWorkspaceRuntime(current.snapshotPath);
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user