3dbb3cb7b2
- discover.ts: Fix ignore package path handling for root '.' directories, add .pi-map.md to default ignore list - llm-extract.ts: Fix export regex to only match line-start exports and handle 'export async function', fix root package role to 'Project root' - init.ts: Minor cleanup - .gitignore: Add .pi-map.md - tests: 6 integration tests covering init, patch (small/large packages), validate (missing, orphaned, stale-signature detection) All 14 tests pass. TypeScript compiles clean.
104 lines
2.8 KiB
TypeScript
104 lines
2.8 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import {
|
|
renderPackageMap,
|
|
parsePackageMap,
|
|
type PackageMapData,
|
|
} from "../src/format.js";
|
|
|
|
const sampleData: PackageMapData = {
|
|
path: "pkg/auth",
|
|
role: "Auth layer: JWT issuance, validation, refresh. Stateless. Dep: pkg/crypto, pkg/db.",
|
|
files: [
|
|
{
|
|
name: "tokens.ts",
|
|
purpose: "JWT gen/val",
|
|
exports: ["issueToken", "verifyToken", "refreshToken"],
|
|
deps: ["crypto/hmac", "db/sessions"],
|
|
},
|
|
{
|
|
name: "middleware.ts",
|
|
purpose: "HTTP auth guard",
|
|
exports: ["requireAuth", "requireRole"],
|
|
deps: ["tokens/verifyToken"],
|
|
},
|
|
{
|
|
name: "types.ts",
|
|
purpose: "shared auth types",
|
|
exports: ["AuthToken", "UserClaims", "Role"],
|
|
deps: [],
|
|
},
|
|
],
|
|
arch: "Guard pattern on routes. Tokens short-lived (15m), refresh long-lived (7d). Rotation on every use.",
|
|
dirty: "-",
|
|
};
|
|
|
|
describe("format", () => {
|
|
it("renders package map correctly", () => {
|
|
const output = renderPackageMap(sampleData);
|
|
expect(output).toContain("# pkg/auth");
|
|
expect(output).toContain("## role");
|
|
expect(output).toContain("## files");
|
|
expect(output).toContain(
|
|
"- tokens.ts | JWT gen/val | exp: issueToken, verifyToken, refreshToken | dep: crypto/hmac, db/sessions",
|
|
);
|
|
expect(output).toContain("## arch");
|
|
expect(output).toContain("## dirty");
|
|
expect(output).toContain("-");
|
|
});
|
|
|
|
it("round-trips parse and render", () => {
|
|
const rendered = renderPackageMap(sampleData);
|
|
const parsed = parsePackageMap(rendered);
|
|
|
|
expect(parsed.path).toBe(sampleData.path);
|
|
expect(parsed.role).toBe(sampleData.role);
|
|
expect(parsed.arch).toBe(sampleData.arch);
|
|
expect(parsed.dirty).toBeUndefined(); // "-" is normalized to undefined
|
|
expect(parsed.files).toHaveLength(3);
|
|
|
|
const tokens = parsed.files.find((f) => f.name === "tokens.ts");
|
|
expect(tokens).toBeDefined();
|
|
expect(tokens!.purpose).toBe("JWT gen/val");
|
|
expect(tokens!.exports).toEqual([
|
|
"issueToken",
|
|
"verifyToken",
|
|
"refreshToken",
|
|
]);
|
|
expect(tokens!.deps).toEqual(["crypto/hmac", "db/sessions"]);
|
|
});
|
|
|
|
it("handles files without exports or deps", () => {
|
|
const data: PackageMapData = {
|
|
path: "pkg/utils",
|
|
role: "Utilities",
|
|
files: [
|
|
{ name: "helpers.ts", purpose: "Helpers", exports: [], deps: [] },
|
|
],
|
|
arch: "Shared helpers",
|
|
dirty: "2024-01-01: patched",
|
|
};
|
|
const rendered = renderPackageMap(data);
|
|
const parsed = parsePackageMap(rendered);
|
|
expect(parsed.files[0].exports).toEqual([]);
|
|
expect(parsed.files[0].deps).toEqual([]);
|
|
expect(parsed.dirty).toBe("2024-01-01: patched");
|
|
});
|
|
|
|
it("parses multiline arch", () => {
|
|
const markdown = `# pkg/test
|
|
## role
|
|
Test package
|
|
## files
|
|
- test.ts | Test file
|
|
## arch
|
|
Line one.
|
|
Line two.
|
|
Line three.
|
|
## dirty
|
|
-
|
|
`;
|
|
const parsed = parsePackageMap(markdown);
|
|
expect(parsed.arch).toBe("Line one.\nLine two.\nLine three.");
|
|
});
|
|
});
|