All files / infrastructure/scripts/src/invariants/domain tables.ts

100% Statements 33/33
83.33% Branches 15/18
100% Functions 12/12
100% Lines 28/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75    2x 2x     2x 11x     2x 9x   101x       2x   8x   8x     2x 8x 8x   9x 10x   8x   8x 1x                 8x 2x                 8x     2x 6x 6x 6x 6x   6x   2x                    
import type { Finding } from "./findings.ts";
 
const BOUNDARIES_PATH = "packages/configs/src/eslint/lib/boundaries.ts";
const README_PATH = "README.md";
 
/** Every `sourceTag:` in the enforced copy of the tag table. */
export const tagsInBoundaries = (source: string): string[] =>
    [...source.matchAll(/sourceTag:\s*"([^"]+)"/g)].map((match) => match[1] ?? "");
 
/** Every tag named in the leftmost column of the README's tag table. */
export const tagsInReadmeTable = (readme: string): string[] =>
    readme
        .split("\n")
        .map((line) => /^\| `((?:type|scope):[^`]+)`/.exec(line)?.[1] ?? "")
        .filter(Boolean);
 
/** Project directories listed between the README's `docs:map:layout` markers. */
export const projectsInLayoutBlock = (readme: string): string[] => {
    const block =
        /<!-- docs:map:layout -->([\s\S]*?)<!-- \/docs:map:layout -->/.exec(readme)?.[1] ?? "";
 
    return [...block.matchAll(/^\s{4}([\w-]+)\//gm)].map((match) => match[1] ?? "");
};
 
export const compareTagTables = (boundaries: string, readme: string): Finding[] => {
    const enforced = tagsInBoundaries(boundaries);
    const documented = tagsInReadmeTable(readme);
 
    const undocumented = enforced.filter((tag) => !documented.includes(tag));
    const unenforced = documented.filter((tag) => !enforced.includes(tag));
 
    const findings: Finding[] = [];
 
    if (undocumented.length > 0) {
        findings.push({
            id: "tag-table-undocumented",
            title: "A tag is enforced but not documented",
            detail: `${undocumented.join(", ")} appears in boundaries.ts with no row in the README tag table.`,
            evidence: [BOUNDARIES_PATH, README_PATH],
            blocks: false,
        });
    }
 
    if (unenforced.length > 0) {
        findings.push({
            id: "tag-table-unenforced",
            title: "A tag is documented but not enforced",
            detail: `${unenforced.join(", ")} has a README row but no depConstraints entry.`,
            evidence: [README_PATH, BOUNDARIES_PATH],
            blocks: false,
        });
    }
 
    return findings;
};
 
export const compareLayoutBlock = (readme: string, projectRoots: string[]): Finding[] => {
    const listed = projectsInLayoutBlock(readme);
    const missing = projectRoots
        .map((root) => root.split("/").at(-1) ?? "")
        .filter((directory) => directory && !listed.includes(directory));
 
    if (missing.length === 0) return [];
 
    return [
        {
            id: "layout-block-incomplete",
            title: "A project is missing from the workspace layout",
            detail: `${missing.join(", ")} exists in the workspace but is not in the README layout block.`,
            evidence: [README_PATH],
            blocks: false,
        },
    ];
};