feat: atomic revision-qualified annotations sync with ownership manifest (P5)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
@@ -59,7 +59,7 @@ function config(root: string, remoteUrl: string): WorkspaceRegistryConfig {
|
||||
|
||||
type AnnotationsLayout = "absent" | "valid" | "malformed" | "dir";
|
||||
|
||||
async function fixture(layout: AnnotationsLayout): Promise<{ root: string; remote: string }> {
|
||||
async function fixture(layout: AnnotationsLayout): Promise<{ root: string; remote: string; commit: string }> {
|
||||
const root = mkdtempSync(join(tmpdir(), "thoth-registry-annotations-"));
|
||||
temporaryRoots.push(root);
|
||||
const remote = join(root, "remote.git");
|
||||
@@ -84,7 +84,8 @@ async function fixture(layout: AnnotationsLayout): Promise<{ root: string; remot
|
||||
await git(source, ["commit", "-m", "initial"]);
|
||||
await git(source, ["remote", "add", "origin", remote]);
|
||||
await git(source, ["push", "origin", "main"]);
|
||||
return { root, remote };
|
||||
const commit = await git(source, ["rev-parse", "HEAD"]);
|
||||
return { root, remote, commit };
|
||||
}
|
||||
|
||||
test("activation accepts a valid curated annotation blob", async () => {
|
||||
@@ -114,3 +115,21 @@ test("activation rejects a tree at the annotations path", async () => {
|
||||
|
||||
await expect(registry.bootstrap()).rejects.toMatchObject({ code: "workspace_invalid" });
|
||||
});
|
||||
|
||||
test("activation syncs the curated annotations to the revision root when a data root is set", async () => {
|
||||
const fixtureValue = await fixture("valid");
|
||||
const dataRoot = mkdtempSync(join(tmpdir(), "thoth-registry-annotations-data-"));
|
||||
temporaryRoots.push(dataRoot);
|
||||
const registry = new WorkspaceRegistry({
|
||||
...config(join(fixtureValue.root, "registry"), fixtureValue.remote),
|
||||
dataRoot,
|
||||
});
|
||||
|
||||
await registry.bootstrap();
|
||||
|
||||
const annotationsPath = join(dataRoot, "sessions", "psd-clinical", "revisions", fixtureValue.commit, "artifacts", "mschema", "annotations.yaml");
|
||||
const manifestPath = join(dataRoot, "sessions", "psd-clinical", "revisions", fixtureValue.commit, "artifacts", "mschema", "annotations.ownership.json");
|
||||
expect(readFileSync(annotationsPath, "utf8")).toBe("tables: {}\n");
|
||||
const manifest = JSON.parse(readFileSync(manifestPath, "utf8"));
|
||||
expect(manifest).toMatchObject({ workspace: "psd-clinical", commit: fixtureValue.commit });
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user