feat: read and validate curated FK annotations at the pinned commit (P5)
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { promisify } from "node:util";
|
||||
import { afterEach, expect, test } from "vitest";
|
||||
import { WorkspaceRegistry } from "../src/workspaces/registry.js";
|
||||
import type { WorkspaceRegistryConfig } from "../src/workspaces/types.js";
|
||||
|
||||
const runFile = promisify(execFile);
|
||||
const temporaryRoots: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
temporaryRoots.splice(0).forEach((root) => rmSync(root, { recursive: true, force: true }));
|
||||
});
|
||||
|
||||
const validYaml = `workspace:
|
||||
schema_version: 3
|
||||
id: psd-clinical
|
||||
name: Policlinico San Donato
|
||||
language: it
|
||||
dwh:
|
||||
engine: postgres
|
||||
database: postgres
|
||||
schema: datawarehouse
|
||||
supported_transports: [postgres_direct]
|
||||
semantic_index:
|
||||
vector_store:
|
||||
engine: qdrant
|
||||
collection: psd-clinical
|
||||
dimensions: 1024
|
||||
distance: cosine
|
||||
embedding:
|
||||
provider: ollama_internal
|
||||
model: qwen3-embedding:0.6b
|
||||
dimensions: 1024
|
||||
llm_policy:
|
||||
allowed: [zai/glm-5.2]
|
||||
`;
|
||||
|
||||
async function git(cwd: string, args: string[]): Promise<string> {
|
||||
const { stdout } = await runFile("git", args, { cwd });
|
||||
return stdout.trim();
|
||||
}
|
||||
|
||||
function config(root: string, remoteUrl: string): WorkspaceRegistryConfig {
|
||||
return {
|
||||
root,
|
||||
remoteUrl,
|
||||
branch: "main",
|
||||
gitAuthorName: "Registry Annotations Test",
|
||||
gitAuthorEmail: "registry-annotations@example.invalid",
|
||||
installationId: "test",
|
||||
secretRoots: [],
|
||||
maxImportBytes: 1024,
|
||||
maxImportEntries: 1,
|
||||
};
|
||||
}
|
||||
|
||||
type AnnotationsLayout = "absent" | "valid" | "malformed" | "dir";
|
||||
|
||||
async function fixture(layout: AnnotationsLayout): Promise<{ root: string; remote: string }> {
|
||||
const root = mkdtempSync(join(tmpdir(), "thoth-registry-annotations-"));
|
||||
temporaryRoots.push(root);
|
||||
const remote = join(root, "remote.git");
|
||||
const source = join(root, "source");
|
||||
await git(root, ["init", "--bare", "--initial-branch=main", remote]);
|
||||
mkdirSync(source);
|
||||
await git(source, ["init", "--initial-branch=main"]);
|
||||
await git(source, ["config", "user.name", "Registry Annotations Test"]);
|
||||
await git(source, ["config", "user.email", "registry-annotations@example.invalid"]);
|
||||
writeFileSync(join(source, "thoth-workspaces.yaml"),
|
||||
"schema_version: 1\nworkspaces:\n - id: psd-clinical\n name: Policlinico San Donato\n");
|
||||
mkdirSync(join(source, "psd-clinical", "schema"), { recursive: true });
|
||||
writeFileSync(join(source, "psd-clinical", "workspace.yaml"), validYaml);
|
||||
const annotationsPath = join(source, "psd-clinical", "schema", "annotations.yaml");
|
||||
if (layout === "valid") writeFileSync(annotationsPath, "tables: {}\n");
|
||||
if (layout === "malformed") writeFileSync(annotationsPath, "tables: [not, a, mapping]\n");
|
||||
if (layout === "dir") {
|
||||
mkdirSync(annotationsPath, { recursive: true });
|
||||
writeFileSync(join(annotationsPath, "child.txt"), "nested\n");
|
||||
}
|
||||
await git(source, ["add", "-A"]);
|
||||
await git(source, ["commit", "-m", "initial"]);
|
||||
await git(source, ["remote", "add", "origin", remote]);
|
||||
await git(source, ["push", "origin", "main"]);
|
||||
return { root, remote };
|
||||
}
|
||||
|
||||
test("activation accepts a valid curated annotation blob", async () => {
|
||||
const fixtureValue = await fixture("valid");
|
||||
const registry = new WorkspaceRegistry(config(join(fixtureValue.root, "registry"), fixtureValue.remote));
|
||||
|
||||
await expect(registry.bootstrap()).resolves.toMatchObject({ degraded: false });
|
||||
});
|
||||
|
||||
test("activation accepts an absent annotation blob", async () => {
|
||||
const fixtureValue = await fixture("absent");
|
||||
const registry = new WorkspaceRegistry(config(join(fixtureValue.root, "registry"), fixtureValue.remote));
|
||||
|
||||
await expect(registry.bootstrap()).resolves.toMatchObject({ degraded: false });
|
||||
});
|
||||
|
||||
test("activation rejects malformed annotations", async () => {
|
||||
const fixtureValue = await fixture("malformed");
|
||||
const registry = new WorkspaceRegistry(config(join(fixtureValue.root, "registry"), fixtureValue.remote));
|
||||
|
||||
await expect(registry.bootstrap()).rejects.toMatchObject({ code: "workspace_invalid" });
|
||||
});
|
||||
|
||||
test("activation rejects a tree at the annotations path", async () => {
|
||||
const fixtureValue = await fixture("dir");
|
||||
const registry = new WorkspaceRegistry(config(join(fixtureValue.root, "registry"), fixtureValue.remote));
|
||||
|
||||
await expect(registry.bootstrap()).rejects.toMatchObject({ code: "workspace_invalid" });
|
||||
});
|
||||
Reference in New Issue
Block a user