All files / scripts/agentic/gate-checks mermaid-diagrams.ts

100% Statements 15/15
100% Branches 9/9
100% Functions 1/1
100% Lines 14/14

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                                              7x   7x 112x 112x   36x   36x 36x 1x           1x       35x       112x 1x             34x                 7x    
/**
 * @module scripts/agentic/gate-checks/mermaid-diagrams
 * @description Check 5 — Verify Mermaid diagrams with colour-coded config
 *              exist in required files.
 *
 * @see .github/prompts/05-analysis-gate.md §Check 5
 * @author Hack23 AB
 * @license Apache-2.0
 */
 
import { readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
 
import { MERMAID_REQUIRED_ARTIFACTS } from '../artifact-inventory.js';
import type { GateCheckResult } from '../gate-shared/types.js';
 
/**
 * Verify Mermaid diagrams with colour-coded config exist in required files.
 */
export async function checkMermaidDiagrams(
  analysisDir: string,
): Promise<GateCheckResult[]> {
  const results: GateCheckResult[] = [];
 
  for (const filename of MERMAID_REQUIRED_ARTIFACTS) {
    const filePath = join(analysisDir, filename);
    if (!existsSync(filePath)) continue;
 
    const content = await readFile(filePath, 'utf-8');
 
    const hasMermaid = /^```mermaid/m.test(content);
    if (!hasMermaid) {
      results.push({
        checkId: 'mermaid-diagrams',
        passed: false,
        message: `${filename}: missing Mermaid block`,
        artifact: filename,
      });
      continue;
    }
 
    const hasColourConfig =
      /^\s*style\s+/m.test(content) ||
      /themeVariables/m.test(content) ||
      /%%\{\s*init/m.test(content);
 
    if (!hasColourConfig) {
      results.push({
        checkId: 'mermaid-diagrams',
        passed: false,
        message: `${filename}: missing Mermaid colour-coded config`,
        artifact: filename,
      });
    } else {
      results.push({
        checkId: 'mermaid-diagrams',
        passed: true,
        message: `${filename}: Mermaid with colour config present`,
        artifact: filename,
      });
    }
  }
 
  return results;
}