87 lines
4.1 KiB
JavaScript
87 lines
4.1 KiB
JavaScript
import { mkdtemp, mkdir, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { failureCount, hasFailedResults, renderReport, runLegacyUrlInventory } from "./verify-host-aware-url-baseline.mjs";
|
|
|
|
describe("Host Aware URL baseline runner failure counting", () => {
|
|
it("counts TypeScript diagnostics from error TS markers", () => {
|
|
expect(failureCount("typecheck", "app/a.ts(1,1): error TS2322: nope\napp/b.ts(2,2): error TS7006: nope", "", 2)).toBe(2);
|
|
});
|
|
|
|
it("counts ESLint errors from the summary problem line", () => {
|
|
expect(failureCount("lint", "✖ 5 problems (3 errors, 2 warnings)", "", 1)).toBe(3);
|
|
});
|
|
|
|
it("counts Vitest failed tests from the test summary", () => {
|
|
expect(failureCount("vitest-host-aware-canonical-url", "Tests 4 failed | 8 passed", "", 1)).toBe(4);
|
|
});
|
|
|
|
it("returns zero for clean exits", () => {
|
|
expect(failureCount("typecheck", "", "", 0)).toBe(0);
|
|
});
|
|
|
|
it("treats legacy inventory integrity failures as failed gate results", () => {
|
|
expect(hasFailedResults([{ id: "legacy-url-inventory", exitCode: 1, failureCount: 1 }])).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("Host Aware URL legacy URL inventory", () => {
|
|
it("scans allowed roots and ignores documentation", async () => {
|
|
const root = await mkdtemp(join(tmpdir(), "hostAwareUrl-legacy-url-inventory-"));
|
|
await mkdir(join(root, "apps", "web", "app", "routes"), { recursive: true });
|
|
await mkdir(join(root, "apps", "web", "app", "components"), { recursive: true });
|
|
await mkdir(join(root, "docs"), { recursive: true });
|
|
|
|
await writeFile(
|
|
join(root, "apps", "web", "app", "routes", "sample.tsx"),
|
|
[
|
|
"import UrlUtils from '~/utils/app/UrlUtils';",
|
|
"const browserUrl = window.location.href;",
|
|
"const serverUrl = rootData.serverUrl;",
|
|
"const legacyRoute = '/app/:tenant/settings';",
|
|
].join("\n"),
|
|
"utf8"
|
|
);
|
|
await writeFile(join(root, "apps", "web", "app", "components", "sample.tsx"), "const path = CanonicalUrlUtils.appPath({ tenantSlug: 'acme', path: 'settings' });\n", "utf8");
|
|
await writeFile(join(root, "docs", "ignored.md"), "UrlUtils window.location rootData.serverUrl CanonicalUrlUtils '/app/:tenant'\n", "utf8");
|
|
|
|
const inventory = await runLegacyUrlInventory(root);
|
|
const allMatches = inventory.matches.join("\n");
|
|
|
|
expect(inventory.roots).toEqual(["apps/web/app/routes", "apps/web/app/components"]);
|
|
expect(inventory.missingRoots).toEqual(["apps/web/app/modules", "apps/web/app/utils", "apps/api/src"]);
|
|
expect(inventory.filesScanned).toBe(2);
|
|
expect(inventory.counts).toMatchObject({
|
|
"legacy-url-utils-import": 2,
|
|
"window-location-reference": 1,
|
|
"root-data-server-url": 1,
|
|
"canonical-url-utils-reference": 2,
|
|
"legacy-app-route-reference": 1,
|
|
});
|
|
expect(allMatches).toContain("apps/web/app/routes/sample.tsx");
|
|
expect(allMatches).toContain("apps/web/app/components/sample.tsx");
|
|
expect(allMatches).not.toContain("docs/ignored.md");
|
|
});
|
|
});
|
|
|
|
describe("Host Aware URL baseline report rendering", () => {
|
|
it("renders gate identifiers, exit codes, failure counts, and fingerprints", () => {
|
|
const report = renderReport([
|
|
{ id: "typecheck", command: "pnpm run typecheck", exitCode: 2, durationMs: 1500, failureCount: 7, fingerprint: { hash: "abc123def456", excerpt: "error TS2322" } },
|
|
{ id: "legacy-url-inventory", command: "read-only legacy URL inventory", exitCode: 0, durationMs: 42, failureCount: 0, fingerprint: { hash: "fed456abc123", excerpt: "legacy-url-utils-import: 1" } },
|
|
]);
|
|
|
|
expect(report).toContain("# Host Aware URL Baseline Health");
|
|
expect(report).toContain("## typecheck");
|
|
expect(report).toContain("## legacy-url-inventory");
|
|
expect(report).toContain("- Exitcode: 2");
|
|
expect(report).toContain("- Exitcode: 0");
|
|
expect(report).toContain("- Failure Count: 7");
|
|
expect(report).toContain("- Failure Count: 0");
|
|
expect(report).toContain("- Output Fingerprint: abc123def456");
|
|
expect(report).toContain("- Output Fingerprint: fed456abc123");
|
|
});
|
|
});
|