fix(build): make catalogs and packaged skills generated outputs (#1086)
* fix(build): generate catalogs and packaged skills without snapshot commits * fix(build): point skill drift recovery to uncached generation
This commit is contained in:
@@ -95,7 +95,7 @@ describe("canonical product catalog", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("matches every source-derived checked-in product fact", async () => {
|
||||
it("matches every source-derived build-generated product fact", async () => {
|
||||
const catalog = await createProductCatalog(root);
|
||||
expect(catalog.tools.total).toBe(TOOL_CONTRACTS.length);
|
||||
expect(
|
||||
@@ -204,10 +204,10 @@ describe("canonical product catalog", () => {
|
||||
providerCatalogDigest(catalog.providers),
|
||||
);
|
||||
expect(
|
||||
JSON.parse(await readFile("docs/product-catalog.json", "utf8")),
|
||||
JSON.parse(await readFile("docs/public/product-catalog.json", "utf8")),
|
||||
).toEqual(catalog);
|
||||
expect(await serializeProductCatalog(catalog)).toBe(
|
||||
await readFile("docs/product-catalog.json", "utf8"),
|
||||
await readFile("docs/public/product-catalog.json", "utf8"),
|
||||
);
|
||||
await expect(
|
||||
assertDocumentationFacts(root, catalog),
|
||||
|
||||
@@ -164,7 +164,7 @@ const createBuildCacheFixture = async (): Promise<string> => {
|
||||
"scripts/clean-build-output.mjs",
|
||||
"scripts/generate-package-metadata.mjs",
|
||||
"scripts/lib/generated-file.mjs",
|
||||
"skills/reverse-engineer-anything/SKILL.md",
|
||||
"skill-src/reverse-engineer-anything/SKILL.md",
|
||||
"src/generatedPackageMetadata.ts",
|
||||
];
|
||||
await Promise.all(
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import { execFile } from "node:child_process";
|
||||
import { copyFile, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const exec = promisify(execFile);
|
||||
const repositoryRoot = fileURLToPath(new URL("../../..", import.meta.url));
|
||||
const authored =
|
||||
'---\nname: reverse-engineer-anything\nmetadata:\n version: "33"\n---\n\n# Instructions\n\nInspect the caller-selected artifact.\n';
|
||||
|
||||
async function fixture(eol = "\n") {
|
||||
const root = await createTestTempDirectory("rea-generated-skill-");
|
||||
for (const path of [
|
||||
"scripts/generate-skill-metadata.mjs",
|
||||
"scripts/lib/generated-file.mjs",
|
||||
]) {
|
||||
await mkdir(dirname(join(root, path)), { recursive: true });
|
||||
await copyFile(join(repositoryRoot, path), join(root, path));
|
||||
}
|
||||
const sourceRoot = join(root, "skill-src/reverse-engineer-anything");
|
||||
const outputRoot = join(root, "skills/reverse-engineer-anything");
|
||||
await mkdir(join(sourceRoot, "references"), { recursive: true });
|
||||
await mkdir(join(root, "dist"));
|
||||
await writeFile(join(root, "package.json"), '{"type":"module"}\n');
|
||||
await writeFile(join(sourceRoot, "SKILL.md"), authored.replaceAll("\n", eol));
|
||||
await writeFile(
|
||||
join(sourceRoot, "references/guide.md"),
|
||||
`# Guide${eol}Preserve evidence.${eol}`,
|
||||
);
|
||||
const identity = async (count: number, digest: string) =>
|
||||
writeFile(
|
||||
join(root, "dist/catalogIdentity.js"),
|
||||
`export const CATALOG_IDENTITY = ${JSON.stringify({ counts: { mcp_tools: count }, digests: { combined_sha256: digest } })};\n`,
|
||||
);
|
||||
await identity(139, "a".repeat(64));
|
||||
const generate = (...args: string[]) =>
|
||||
exec(
|
||||
process.execPath,
|
||||
[join(root, "scripts/generate-skill-metadata.mjs"), ...args],
|
||||
{ cwd: root },
|
||||
);
|
||||
return { sourceRoot, outputRoot, identity, generate };
|
||||
}
|
||||
|
||||
it.each(["\n", "\r\n"])(
|
||||
"generates revision-specific metadata without rewriting authored instructions (%j)",
|
||||
async (eol) => {
|
||||
const f = await fixture(eol);
|
||||
await f.generate();
|
||||
const first = await readFile(join(f.outputRoot, "SKILL.md"), "utf8");
|
||||
expect(first).not.toContain("catalog_digest:");
|
||||
expect(first).toContain("tool_count: 139");
|
||||
expect(
|
||||
first.replace(/^ {2}(?:tool_count|catalog_digest):[^\n]*\n/gmu, ""),
|
||||
).toBe(authored);
|
||||
expect(
|
||||
await readFile(join(f.outputRoot, "references/guide.md"), "utf8"),
|
||||
).toBe("# Guide\nPreserve evidence.\n");
|
||||
await f.identity(139, "b".repeat(64));
|
||||
await f.generate();
|
||||
expect(await readFile(join(f.outputRoot, "SKILL.md"), "utf8")).toBe(first);
|
||||
await f.identity(140, "b".repeat(64));
|
||||
await expect(f.generate("--check")).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining("missing or stale"),
|
||||
});
|
||||
await f.generate();
|
||||
expect(await readFile(join(f.outputRoot, "SKILL.md"), "utf8")).toContain(
|
||||
"tool_count: 140",
|
||||
);
|
||||
expect(await readFile(join(f.sourceRoot, "SKILL.md"), "utf8")).toBe(
|
||||
authored.replaceAll("\n", eol),
|
||||
);
|
||||
expect(
|
||||
await readFile(join(f.sourceRoot, "references/guide.md"), "utf8"),
|
||||
).toBe(`# Guide${eol}Preserve evidence.${eol}`);
|
||||
await expect(f.generate("--check")).resolves.toMatchObject({ stderr: "" });
|
||||
},
|
||||
);
|
||||
|
||||
it("rejects missing, stale, and extra packaged references and removes deleted source files on rebuild", async () => {
|
||||
const f = await fixture();
|
||||
await f.generate();
|
||||
const guide = join(f.outputRoot, "references/guide.md");
|
||||
await rm(guide);
|
||||
await expect(f.generate("--check")).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining("guide.md is missing or stale"),
|
||||
});
|
||||
await f.generate();
|
||||
await writeFile(guide, "modified reference\n");
|
||||
await expect(f.generate("--check")).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining("guide.md is missing or stale"),
|
||||
});
|
||||
await f.generate();
|
||||
await writeFile(
|
||||
join(f.outputRoot, "references/removed.md"),
|
||||
"obsolete instructions\n",
|
||||
);
|
||||
await expect(f.generate("--check")).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining("file inventory drifted"),
|
||||
});
|
||||
await rm(join(f.sourceRoot, "references/guide.md"));
|
||||
await f.generate();
|
||||
await expect(readFile(guide)).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await expect(
|
||||
readFile(join(f.outputRoot, "references/removed.md")),
|
||||
).rejects.toMatchObject({ code: "ENOENT" });
|
||||
await f.generate("--check");
|
||||
});
|
||||
|
||||
it("rejects catalog-dependent metadata in the authored source", async () => {
|
||||
const f = await fixture();
|
||||
await writeFile(
|
||||
join(f.sourceRoot, "SKILL.md"),
|
||||
authored.replace(' version: "33"', ' version: "33"\n tool_count: 139'),
|
||||
);
|
||||
await expect(f.generate()).rejects.toMatchObject({
|
||||
stderr: expect.stringContaining(
|
||||
"Catalog metadata belongs in the generated skill",
|
||||
),
|
||||
});
|
||||
});
|
||||
@@ -50,7 +50,6 @@ async function metadata(directory: string, version: string, notes: string) {
|
||||
version,
|
||||
packages: [{ identifier: "rea-agents", version }],
|
||||
},
|
||||
"docs/product-catalog.json": { package: { version } },
|
||||
"release-please-config.json": {
|
||||
"changelog-sections": [
|
||||
{ type: "feat", hidden: false },
|
||||
@@ -371,7 +370,6 @@ it("validates candidate options before inspecting the working directory", async
|
||||
it.each([
|
||||
"package-lock.json",
|
||||
"server.json",
|
||||
"docs/product-catalog.json",
|
||||
"src/generatedPackageMetadata.ts",
|
||||
])("rejects inconsistent version metadata in %s", async (path) => {
|
||||
const f = await fixture();
|
||||
|
||||
@@ -103,11 +103,11 @@ it("requires explicit release preparation or publication instead of main pushes"
|
||||
"skip-github-release": "${{ inputs.phase == 'prepare' }}",
|
||||
"skip-github-pull-request": "${{ inputs.phase == 'publish' }}",
|
||||
});
|
||||
const catalogCommit = workflow.jobs["release-please"].steps.find(
|
||||
(step) => step.name === "Commit canonical release catalog",
|
||||
const catalogValidation = workflow.jobs["release-please"].steps.find(
|
||||
(step) => step.name === "Validate generated release documentation",
|
||||
);
|
||||
expect(catalogCommit?.env?.GH_TOKEN).toBe(
|
||||
"${{ secrets.RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}",
|
||||
expect(catalogValidation?.run).toBe(
|
||||
"npm run docs:check && git diff --exit-code",
|
||||
);
|
||||
});
|
||||
|
||||
@@ -203,7 +203,7 @@ it("binds npm and MCP publication to the same immutable release SHA", async () =
|
||||
"Set up Node.js for generated documentation",
|
||||
"Install dependencies",
|
||||
"Regenerate release documentation",
|
||||
"Commit canonical release catalog",
|
||||
"Validate generated release documentation",
|
||||
];
|
||||
for (const name of preparation) {
|
||||
expect(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
@@ -14,6 +15,7 @@ import {
|
||||
import { createDoctorHostFixture } from "../../../src/application/Doctor.fixture.js";
|
||||
import { TOOL_CONTRACTS } from "../../../src/contracts/toolContracts.js";
|
||||
import { PRODUCT_IDENTITY } from "../../../src/identity.js";
|
||||
import { z } from "zod";
|
||||
import { skillReferenceIssues } from "../../../scripts/lib/docs-facts.mjs";
|
||||
|
||||
describe("canonical skill transaction", () => {
|
||||
@@ -88,6 +90,7 @@ describe("canonical skill transaction", () => {
|
||||
expect(installedSkill).toContain(
|
||||
`tool_count: ${String(TOOL_CONTRACTS.length)}`,
|
||||
);
|
||||
expect(installedSkill).not.toContain("catalog_digest:");
|
||||
expect(await readFile(sibling, "utf8")).toBe("unrelated skill\n");
|
||||
expect(
|
||||
await readFile(
|
||||
@@ -102,6 +105,45 @@ describe("canonical skill transaction", () => {
|
||||
expect(await installCanonicalSkill(home)).toBe("unchanged");
|
||||
expect(await skillReferenceIssues(dirname(destination))).toEqual([]);
|
||||
});
|
||||
|
||||
it("binds portable conformance to the generated skill bytes that setup installs", async () => {
|
||||
const home = await createTestTempDirectory("rea-skill-commitment-");
|
||||
expect(await installCanonicalSkill(home)).toBe("installed");
|
||||
const paths = [
|
||||
"SKILL.md",
|
||||
"references/android-applications.md",
|
||||
"references/evidence-workflows.md",
|
||||
"references/javascript-applications.md",
|
||||
"references/native-and-artifacts.md",
|
||||
"references/runtime-observation.md",
|
||||
];
|
||||
const records = await Promise.all(
|
||||
paths.map(async (path) => {
|
||||
const bytes = await readFile(
|
||||
join(home, ".agents/skills/reverse-engineer-anything", path),
|
||||
);
|
||||
return `${path}\0${createHash("sha256").update(bytes).digest("hex")}\n`;
|
||||
}),
|
||||
);
|
||||
const manifest = z
|
||||
.object({
|
||||
skill_digests: z.array(
|
||||
z.object({ skill_id: z.string(), sha256: z.string() }),
|
||||
),
|
||||
})
|
||||
.parse(
|
||||
JSON.parse(
|
||||
await readFile(
|
||||
"docs/verification/managed-conformance-manifest.json",
|
||||
"utf8",
|
||||
),
|
||||
),
|
||||
);
|
||||
expect(manifest.skill_digests).toContainEqual({
|
||||
skill_id: "reverse-engineer-anything",
|
||||
sha256: createHash("sha256").update(records.join("")).digest("hex"),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("doctor verifies installed instructions and references even when metadata is current", async () => {
|
||||
|
||||
@@ -47,11 +47,6 @@ describe("release configuration", () => {
|
||||
path: "server.json",
|
||||
jsonpath: "$.packages[0].version",
|
||||
},
|
||||
{
|
||||
type: "json",
|
||||
path: "docs/product-catalog.json",
|
||||
jsonpath: "$.package.version",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user