test: add independent P1.1 acceptance and manual tooling
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { access, readFile, rm } from "node:fs/promises";
|
||||
import { join, dirname, resolve } from "node:path";
|
||||
import test from "node:test";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { renderOwnedSnapshot } from "./p11-render-snapshot.mjs";
|
||||
import { cleanupManual, prepareManual, readManualOwnership, serveManual, stopManual } from "./p11-manual-acceptance.mjs";
|
||||
|
||||
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const fixedRoot = join(repoRoot, ".artifacts", "manual-acceptance", "p11");
|
||||
|
||||
async function safeCleanup() {
|
||||
try {
|
||||
const owned = await readManualOwnership({ repositoryRoot: repoRoot });
|
||||
if (owned.status === "RUNNING") await stopManual({ repositoryRoot: repoRoot }).catch(() => {});
|
||||
await cleanupManual({ repositoryRoot: repoRoot }).catch(() => {});
|
||||
} catch {
|
||||
await rm(fixedRoot, { recursive: true, force: true }).catch(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
test.beforeEach(async () => { await safeCleanup(); });
|
||||
test.afterEach(async () => { await safeCleanup(); });
|
||||
|
||||
test("renderer rejects unowned ownership and out-of-root snapshot paths", { concurrency: false }, async () => {
|
||||
await prepareManual({ repositoryRoot: repoRoot });
|
||||
const outside = join(repoRoot, "outside.yaml");
|
||||
await import("node:fs/promises").then(({ writeFile }) => writeFile(outside, "x"));
|
||||
await assert.rejects(renderOwnedSnapshot({
|
||||
repositoryRoot: repoRoot,
|
||||
ownershipPath: join(repoRoot, "ownership.json"),
|
||||
snapshotPath: outside,
|
||||
outputPath: join(fixedRoot, "rendered", "bad.yaml"),
|
||||
snapshotSha256: "a".repeat(64),
|
||||
}));
|
||||
await rm(outside, { force: true });
|
||||
});
|
||||
|
||||
test("renderer copies an owned runtime lease deterministically", { concurrency: false }, async () => {
|
||||
await prepareManual({ repositoryRoot: repoRoot });
|
||||
await serveManual({ repositoryRoot: repoRoot });
|
||||
const validateRequest = JSON.parse(await readFile(join(fixedRoot, "requests", "validate-p11-filesystem.json"), "utf8"));
|
||||
const status = await fetch("http://127.0.0.1:8791/workspace-registry/status");
|
||||
const statusBody = await status.json();
|
||||
const publish = await fetch("http://127.0.0.1:8791/workspaces/publish", {
|
||||
method: "POST",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: JSON.stringify({ action: "create", workspace: validateRequest.workspace, baseCommit: statusBody.head }),
|
||||
});
|
||||
assert.equal(publish.status, 200);
|
||||
const readResponse = await fetch("http://127.0.0.1:8791/workspaces/p11-filesystem");
|
||||
const readBody = await readResponse.json();
|
||||
const snapshotPath = readBody.revision.snapshotPath;
|
||||
const manifest = JSON.parse(await readFile(join(dirname(snapshotPath), "snapshot.json"), "utf8"));
|
||||
const digest = manifest.files["p11-filesystem.yaml"];
|
||||
const one = join(fixedRoot, "rendered", "one.yaml");
|
||||
const two = join(fixedRoot, "rendered", "two.yaml");
|
||||
await renderOwnedSnapshot({ repositoryRoot: repoRoot, ownershipPath: join(fixedRoot, "ownership.json"), snapshotPath, outputPath: one, snapshotSha256: digest });
|
||||
await renderOwnedSnapshot({ repositoryRoot: repoRoot, ownershipPath: join(fixedRoot, "ownership.json"), snapshotPath, outputPath: two, snapshotSha256: digest });
|
||||
assert.equal(await readFile(one, "utf8"), await readFile(two, "utf8"));
|
||||
await access(one);
|
||||
await access(two);
|
||||
});
|
||||
Reference in New Issue
Block a user