Files
oh-my-pi/packages/coding-agent/test/internal-urls/docs-index.test.ts
T
can1357 831b664a4c perf(coding-agent): optimized documentation indexing via compressed blob
- Replaced raw TypeScript documentation map with a lazily-inflated gzip blob.
- Reduced bundled binary/npm package size by approximately 0.9MB.
- Encapsulated index logic into `docs-index.ts` to separate header metadata from content.
- Added `postpack` and robust `try/finally` patterns in build scripts to ensure clean artifacts.
- Implemented disk-based fallback during development to maintain existing developer experience.
2026-06-18 18:57:13 +02:00

33 lines
1.5 KiB
TypeScript

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";
// 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.
const index = decodeDocsIndex(`${JSON.stringify(files)}\n@@@not-a-valid-gzip-blob@@@`);
expect(index?.filenames).toEqual(files);
});
it("resolves bodies by index-aligned path, lazily, on first read", async () => {
const index = decodeDocsIndex(embed);
expect(index).not.toBeNull();
expect(await index?.getBody("agent.md")).toBe("agent body");
expect(await index?.getBody("tools/read.md")).toBe("read body");
expect(await index?.getBody("missing.md")).toBeUndefined();
});
it("returns null when there is no newline separator (empty placeholder)", () => {
expect(decodeDocsIndex("")).toBeNull();
});
});