fix: complete durable workspace runtime config handoff
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { test, expect } from "vitest";
|
||||
import { chmodSync, existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { join } from "node:path";
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { createHash } from "node:crypto";
|
||||
import { WorkspaceRuntimeConfigLeaseFactory } from "../src/workspaces/runtime-config-lease.js";
|
||||
|
||||
const commit = "a".repeat(40);
|
||||
const workspace = "abc";
|
||||
const descriptor = `workspace:
|
||||
schema_version: 3
|
||||
@@ -33,11 +34,27 @@ llm_policy:
|
||||
function fixture() {
|
||||
const root = mkdtempSync(join(tmpdir(), "runtime-config-lease-"));
|
||||
const snapshots = join(root, "snapshots");
|
||||
const snapshotPath = join(snapshots, commit, `${workspace}.yaml`);
|
||||
const repo = join(root, "repo");
|
||||
mkdirSync(join(repo, "workspaces"), { recursive: true });
|
||||
execFileSync("git", ["init", "--initial-branch=main"], { cwd: repo });
|
||||
execFileSync("git", ["config", "user.name", "Fixture"], { cwd: repo });
|
||||
execFileSync("git", ["config", "user.email", "fixture@example.invalid"], { cwd: repo });
|
||||
writeFileSync(join(repo, "workspaces", `${workspace}.yaml`), descriptor);
|
||||
execFileSync("git", ["add", "."], { cwd: repo });
|
||||
execFileSync("git", ["commit", "-m", "fixture"], { cwd: repo });
|
||||
const actualCommit = execFileSync("git", ["rev-parse", "HEAD"], { cwd: repo, encoding: "utf8" }).trim();
|
||||
const blob = execFileSync("git", ["rev-parse", `HEAD:workspaces/${workspace}.yaml`], { cwd: repo, encoding: "utf8" }).trim();
|
||||
const snapshotsDir = join(snapshots, actualCommit);
|
||||
const snapshotPath = join(snapshotsDir, `${workspace}.yaml`);
|
||||
const dataRoot = join(root, "data");
|
||||
const harness = join(root, "harness");
|
||||
mkdirSync(join(snapshots, commit), { recursive: true, mode: 0o700 });
|
||||
mkdirSync(snapshotsDir, { recursive: true, mode: 0o700 });
|
||||
chmodSync(snapshots, 0o700);
|
||||
writeFileSync(join(snapshotsDir, "snapshot.json"), JSON.stringify({
|
||||
head: actualCommit,
|
||||
revisions: [{ id: workspace, commit: actualCommit, blob, snapshotPath }],
|
||||
files: { [`${workspace}.yaml`]: createHash("sha256").update(descriptor).digest("hex") },
|
||||
}), { mode: 0o400 });
|
||||
mkdirSync(harness);
|
||||
writeFileSync(snapshotPath, descriptor, { mode: 0o400 });
|
||||
const secret = join(root, "password");
|
||||
@@ -66,9 +83,9 @@ test("session and maintenance share deterministic bytes and path", () => {
|
||||
expect(session.path).toBe(maintenance.path);
|
||||
expect(readFileSync(session.path, "utf8")).toBe(readFileSync(maintenance.path, "utf8"));
|
||||
expect(lstatSync(session.path).mode & 0o777).toBe(0o400);
|
||||
expect(existsSync(join(dirname(session.path), `${commit}.manifest.json`))).toBe(true);
|
||||
expect(existsSync(maintenance.manifestPath)).toBe(true);
|
||||
session.release(); maintenance.release();
|
||||
expect(existsSync(session.path)).toBe(false);
|
||||
expect(existsSync(session.path)).toBe(true);
|
||||
} finally { rmSync(f.root, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
|
||||
@@ -101,7 +101,8 @@ async function fixture(workspaceSource = filesystemWorkspace) {
|
||||
writeFileSync(path, contents, { mode: 0o600 });
|
||||
chmodSync(path, 0o600);
|
||||
}
|
||||
mkdirSync(dataRoot);
|
||||
mkdirSync(dataRoot, { mode: 0o700 });
|
||||
chmodSync(dataRoot, 0o700);
|
||||
const registryConfig: WorkspaceRegistryConfig = {
|
||||
root: registryRoot,
|
||||
remoteUrl: remote,
|
||||
@@ -138,7 +139,7 @@ function runnerFor(f: Awaited<ReturnType<typeof fixture>>): ThtRunner {
|
||||
harnessDir,
|
||||
configPath: "config/tht.yaml",
|
||||
dataRoot: f.dataRoot,
|
||||
runtimeSnapshotRoot: join(f.registryConfig.root, "snapshots", "runtime"),
|
||||
runtimeSnapshotRoot: join(f.registryConfig.root, "snapshots"),
|
||||
secretRoots: f.registryConfig.secretRoots,
|
||||
} as any);
|
||||
}
|
||||
@@ -162,7 +163,7 @@ test("real schema-v3 registry revision loads through ThtRunner and the harness c
|
||||
expect(existsSync(join(
|
||||
f.dataRoot, "sessions", "psd-clinical", "sessions", created.id, "session_manifest.yaml",
|
||||
))).toBe(true);
|
||||
expect(readdirSync(join(f.registryConfig.root, "snapshots", "runtime"))).toEqual([]);
|
||||
expect(readdirSync(join(f.registryConfig.root, "snapshots"))).toContain(f.revision.commit);
|
||||
});
|
||||
|
||||
test("separate runtime leases hand off byte-identical revision Evidence configs accepted by tht", async () => {
|
||||
@@ -215,7 +216,7 @@ test("separate runtime leases hand off byte-identical revision Evidence configs
|
||||
expect(existsSync(first.path)).toBe(true);
|
||||
expect(existsSync(second.path)).toBe(true);
|
||||
second.release();
|
||||
expect(existsSync(second.path)).toBe(false);
|
||||
expect(existsSync(second.path)).toBe(true);
|
||||
} finally {
|
||||
first.release();
|
||||
second.release();
|
||||
|
||||
Reference in New Issue
Block a user