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 }); }
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user