Files
truthmark/tests/routing/area-resolver.test.ts
Merlin's CatGitHubCopilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>MerlinHCopilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
9fa9ac25a4 feat: add workflow eval framework (#32)
* feat: add workflow eval framework

Add workflow evaluation scenarios, rubrics, schemas, and runner scripts for installed Truthmark workflows.

Move research notes under docs/research and migrate tests from Vitest to node:test.

* Potential fix for pull request finding 'CodeQL / Replacement of a substring with itself'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>

---------

Co-authored-by: MerlinH <merlinh221@gmail.com>
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
2026-06-30 20:57:55 +10:00

346 lines
7.3 KiB
TypeScript

import { describe, it } from "node:test";
import { expect } from "expect";
import { resolveAreaRouting } from "../../src/routing/area-resolver.js";
import { createTempRepo } from "../helpers/temp-repo.js";
const config = {
rootIndex: "docs/truthmark/routes/areas.md",
areaFilesRoot: "docs/truthmark/routes/areas",
};
describe("resolveAreaRouting", () => {
it("loads leaf areas from delegated child route files", async () => {
const repo = await createTempRepo();
try {
await repo.writeFile(
"docs/truthmark/routes/areas.md",
`# Truthmark Areas
## Payments
Area files:
- docs/truthmark/routes/areas/payments.md
Code surface:
- services/payments/**
Update truth when:
- payment behavior changes
`,
);
await repo.writeFile(
"docs/truthmark/routes/areas/payments.md",
`# Payments Areas
## Checkout
Truth documents:
- docs/truthmark/engineering/behaviors/payments-checkout.md
Code surface:
- services/payments/checkout/**
Update truth when:
- checkout behavior changes
`,
);
const result = await resolveAreaRouting(repo.rootDir, config);
expect(result.diagnostics).toEqual([]);
expect(result.routeFiles).toEqual([
"docs/truthmark/routes/areas.md",
"docs/truthmark/routes/areas/payments.md",
]);
expect(result.areas).toEqual([
expect.objectContaining({
name: "Checkout",
truthDocuments: [
"docs/truthmark/engineering/behaviors/payments-checkout.md",
],
sourcePath: "docs/truthmark/routes/areas/payments.md",
parentName: "Payments",
}),
]);
} finally {
await repo.cleanup();
}
});
it("rejects child route files outside the configured area files root", async () => {
const repo = await createTempRepo();
try {
await repo.writeFile(
"docs/truthmark/routes/areas.md",
`# Truthmark Areas
## Payments
Area files:
- docs/payments.md
Code surface:
- services/payments/**
Update truth when:
- payment behavior changes
`,
);
const result = await resolveAreaRouting(repo.rootDir, config);
expect(result.areas).toEqual([]);
expect(result.diagnostics).toEqual(
expect.arrayContaining([
expect.objectContaining({
category: "area-index",
severity: "error",
file: "docs/payments.md",
message: expect.stringContaining(
"must live under docs/truthmark/routes/areas",
),
}),
]),
);
} finally {
await repo.cleanup();
}
});
it("rejects nested delegation inside child route files", async () => {
const repo = await createTempRepo();
try {
await repo.writeFile(
"docs/truthmark/routes/areas.md",
`# Truthmark Areas
## Payments
Area files:
- docs/truthmark/routes/areas/payments.md
Code surface:
- services/payments/**
Update truth when:
- payment behavior changes
`,
);
await repo.writeFile(
"docs/truthmark/routes/areas/payments.md",
`# Payments Areas
## Checkout
Area files:
- docs/truthmark/routes/areas/payments/checkout.md
Code surface:
- services/payments/checkout/**
Update truth when:
- checkout behavior changes
`,
);
const result = await resolveAreaRouting(repo.rootDir, config);
expect(result.areas).toEqual([]);
expect(result.diagnostics).toEqual(
expect.arrayContaining([
expect.objectContaining({
category: "area-index",
severity: "error",
file: "docs/truthmark/routes/areas/payments.md",
message: expect.stringContaining(
"Child area files must contain leaf areas only",
),
}),
]),
);
} finally {
await repo.cleanup();
}
});
it("reports duplicate leaf area keys across route files", async () => {
const repo = await createTempRepo();
try {
await repo.writeFile(
"docs/truthmark/routes/areas.md",
`# Truthmark Areas
## Payments
Area files:
- docs/truthmark/routes/areas/payments.md
Code surface:
- services/payments/**
Update truth when:
- payment behavior changes
`,
);
await repo.writeFile(
"docs/truthmark/routes/areas/payments.md",
`# Payments Areas
## Checkout
Truth documents:
- docs/truthmark/truth/payments.md
Code surface:
- services/payments/checkout/**
Update truth when:
- checkout behavior changes
## Checkout
Truth documents:
- docs/truthmark/truth/payments-legacy.md
Code surface:
- services/payments/legacy-checkout/**
Update truth when:
- legacy checkout behavior changes
`,
);
const result = await resolveAreaRouting(repo.rootDir, config);
expect(result.diagnostics).toEqual(
expect.arrayContaining([
expect.objectContaining({
category: "area-index",
severity: "error",
message: expect.stringContaining("Duplicate area key checkout"),
}),
]),
);
} finally {
await repo.cleanup();
}
});
it("reports child code surfaces that are outside the delegated parent surface", async () => {
const repo = await createTempRepo();
try {
await repo.writeFile(
"docs/truthmark/routes/areas.md",
`# Truthmark Areas
## Payments
Area files:
- docs/truthmark/routes/areas/payments.md
Code surface:
- services/payments/**
Update truth when:
- payment behavior changes
`,
);
await repo.writeFile(
"docs/truthmark/routes/areas/payments.md",
`# Payments Areas
## Checkout
Truth documents:
- docs/truthmark/truth/payments.md
Code surface:
- services/orders/**
Update truth when:
- checkout behavior changes
`,
);
const result = await resolveAreaRouting(repo.rootDir, config);
expect(result.diagnostics).toEqual(
expect.arrayContaining([
expect.objectContaining({
category: "area-index",
severity: "review",
file: "docs/truthmark/routes/areas/payments.md",
message: expect.stringContaining(
"outside parent area Payments code surface",
),
}),
]),
);
} finally {
await repo.cleanup();
}
});
it("does not treat wildcard parent prefixes as implicit child containment", async () => {
const repo = await createTempRepo();
try {
await repo.writeFile(
"docs/truthmark/routes/areas.md",
`# Truthmark Areas
## Apps
Area files:
- docs/truthmark/routes/areas/apps.md
Code surface:
- apps/*/src/**
Update truth when:
- app behavior changes
`,
);
await repo.writeFile(
"docs/truthmark/routes/areas/apps.md",
`# Apps Areas
## Admin Docs
Truth documents:
- docs/truthmark/truth/apps/admin-docs.md
Code surface:
- apps/admin/docs/**
Update truth when:
- admin docs behavior changes
`,
);
const result = await resolveAreaRouting(repo.rootDir, config);
expect(result.diagnostics).toEqual(
expect.arrayContaining([
expect.objectContaining({
category: "area-index",
severity: "review",
file: "docs/truthmark/routes/areas/apps.md",
message: expect.stringContaining(
"outside parent area Apps code surface",
),
}),
]),
);
} finally {
await repo.cleanup();
}
});
});