docs(coding-agent): synced omp docs coverage
Added root omp docs for memory_edit, learn, manage_skill, generate_image, and tts, plus package-level coverage for user-facing README-only CLIs. Added a docs-index freshness check to package check and made gen:bundle generate and reset the docs embed itself. Fixes #3934
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { gzipSync } from "node:zlib";
|
||||
import { decodeDocsIndex } from "@oh-my-pi/pi-coding-agent/internal-urls/docs-index";
|
||||
import { assertDocsIndexFresh } from "../../scripts/generate-docs-index";
|
||||
|
||||
function embed(files: readonly string[], bodies: readonly string[]): string {
|
||||
return `${JSON.stringify(files)}\n${Buffer.from(gzipSync(Buffer.from(JSON.stringify(bodies)))).toString("base64")}`;
|
||||
}
|
||||
|
||||
const files = ["agent.md", "tools/read.md"];
|
||||
const bodies = ["agent body", "read body"];
|
||||
const embedPayload = embed(files, bodies);
|
||||
|
||||
// The embed path only runs in compiled binaries / the npm bundle; dev tests
|
||||
// otherwise exercise the disk fallback (empty placeholder), so a regression in
|
||||
// the two-line `<filenames>\n<gzip bodies>` parsing would ship broken `omp://`
|
||||
// docs undetected. These cover the populated-embed decode directly.
|
||||
describe("decodeDocsIndex (embedded docs path)", () => {
|
||||
const files = ["agent.md", "tools/read.md"];
|
||||
const bodies = ["agent body", "read body"];
|
||||
const embed = `${JSON.stringify(files)}\n${Buffer.from(gzipSync(Buffer.from(JSON.stringify(bodies)))).toString("base64")}`;
|
||||
|
||||
it("lists filenames from the first line without inflating the blob", () => {
|
||||
// A deliberately corrupt blob: filenames must resolve anyway, proving the
|
||||
// listing path never decodes the gzip body.
|
||||
@@ -19,7 +24,7 @@ describe("decodeDocsIndex (embedded docs path)", () => {
|
||||
});
|
||||
|
||||
it("resolves bodies by index-aligned path, lazily, on first read", async () => {
|
||||
const index = decodeDocsIndex(embed);
|
||||
const index = decodeDocsIndex(embedPayload);
|
||||
expect(index).not.toBeNull();
|
||||
expect(await index?.getBody("agent.md")).toBe("agent body");
|
||||
expect(await index?.getBody("tools/read.md")).toBe("read body");
|
||||
@@ -30,3 +35,17 @@ describe("decodeDocsIndex (embedded docs path)", () => {
|
||||
expect(decodeDocsIndex("")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("docs index freshness guard", () => {
|
||||
it("rejects stale filename lists before bundling", () => {
|
||||
expect(() => assertDocsIndexFresh(embed(["agent.md"], ["agent body"]), { files, bodies })).toThrow(
|
||||
"Embedded docs index has 1 docs; source corpus has 2.",
|
||||
);
|
||||
});
|
||||
|
||||
it("rejects stale bodies with matching filenames", () => {
|
||||
expect(() => assertDocsIndexFresh(embed(files, ["old agent body", "read body"]), { files, bodies })).toThrow(
|
||||
"Embedded docs index body mismatch for agent.md. Run `bun run gen:docs`.",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user