All files / scripts/agentic/gate-checks comparative-international.ts

100% Statements 20/20
100% Branches 14/14
100% Functions 2/2
100% Lines 16/16

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                                            7x 7x 7x   6x   6x 6x     7x 36x 16x 12x 8x     7x   7x 1x             5x               6x    
/**
 * @module scripts/agentic/gate-checks/comparative-international
 * @description Check 7f — Validate comparative-international.md has a
 *              comparator set or ≥2 comparator rows.
 *
 * @see .github/prompts/05-analysis-gate.md §Check 7 (comparative-international)
 * @author Hack23 AB
 * @license Apache-2.0
 */
 
import { readFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { join } from 'node:path';
 
import type { GateCheckResult } from '../gate-shared/types.js';
 
/**
 * Check comparative-international.md for comparator set or ≥2 rows.
 */
export async function checkComparativeInternational(
  analysisDir: string,
): Promise<GateCheckResult[]> {
  const results: GateCheckResult[] = [];
  const filePath = join(analysisDir, 'comparative-international.md');
  if (!existsSync(filePath)) return results;
 
  const content = await readFile(filePath, 'utf-8');
 
  const COMPARATOR_SET_RE = /^\s*\*{0,2}Comparator set\*{0,2}\s*:/m;
  const hasComparatorSet = COMPARATOR_SET_RE.test(content) &&
    !/^\s*\*{0,2}Comparator set\*{0,2}\s*:\s*[-–—]*\s*$/m.test(content);
 
  const tableRows = content.split('\n').filter((line) => {
    if (!/^\|/.test(line)) return false;
    if (/^\|[\s:-]+(\|[\s:-]+)+\|?\s*$/.test(line)) return false;
    if (/^\|\s*(Jurisdiction|Comparator|Country)\s*\|/.test(line)) return false;
    return true;
  });
 
  const hasEnoughRows = tableRows.length >= 2;
 
  if (!hasComparatorSet && !hasEnoughRows) {
    results.push({
      checkId: 'family-c-structure',
      passed: false,
      message: 'comparative-international.md: missing comparator set or fewer than 2 comparator rows',
      artifact: 'comparative-international.md',
    });
  } else {
    results.push({
      checkId: 'family-c-structure',
      passed: true,
      message: 'comparative-international.md: comparator data present',
      artifact: 'comparative-international.md',
    });
  }
 
  return results;
}