Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178#!/usr/bin/env node
/** Integration check: run the built CLI against the fixture package and assert the report matches its documented expectations. Needs podman and (on first run) an image build, so it lives behind the dedicated `test:integration` mise task instead of `test:unit`. @example ```bash mise run '//package/cli/mutation-test:test:integration' ``` */
import { readFile, } from 'node:fs/promises';import { tmpdir, } from 'node:os';import { join, } from 'node:path';import { cwd, } from 'node:process';
import spawn from 'nano-spawn';
import { tagged, } from '@monochromatic-dev/module-logger/ts';
import { isRecord, } from './is-record.ts';import type { RunReport, } from './host/report.ts';
/** Module logger for the integration check. */const l = tagged({ tag: 'mutation-test-integration', },);
/** Fixture package path relative to the repo root. */const FIXTURE_PACKAGE = 'package/cli/mutation-test.fixture';
/** Asserts one condition, throwing with context when it fails. @param options - Condition and failure message. @throws Error when the condition is false. @example ```ts check({ that: totals.killed > 0, message: 'expected kills' }); ``` */function check(options: { readonly that: boolean; readonly message: string;},): void { if (!options.that) throw new Error(`integration check failed: ${options.message}`,);}
/** Runs the CLI against the fixture and asserts report expectations. @example ```ts await runIntegrationCheck(); ``` */export async function runIntegrationCheck(): Promise<void> { /** Logger scoped to this check run. */ const rl = tagged({ tag: runIntegrationCheck.name, l, },); /** Report destination for this run. */ const reportFile = join( tmpdir(), `mutation-integration-${String(Date.now(),)}.json`, ); rl.info(`running CLI against ${FIXTURE_PACKAGE}`,); await spawn( 'node', [ join( cwd(), 'package/cli/mutation-test/dist/final/node/cli.mjs', ), '--package', FIXTURE_PACKAGE, '--report', reportFile, ], { stdout: 'inherit', stderr: 'inherit', }, );
/** Parsed report before shape validation. */ const parsed: unknown = JSON.parse(await readFile( reportFile, 'utf8', ),);
check({ that: isRecord(parsed,) && isRecord(parsed.totals,) && Array.isArray(parsed.mutants,), message: 'report JSON must carry totals and mutants', },);
/** Parsed run report from the fixture run; shape checked above, and the writer is this same package, so deeper validation adds no safety. */ // oxlint-disable-next-line no-unsafe-type-assertion -- shape checked at runtime above; writer is this package's own report builder const report = parsed as RunReport;
check({ that: report.totals .killed > 0, message: `clampedSum mutants must die, got killed=${String(report.totals .killed,)}`, },); check({ that: report.totals .survived > 0, message: `describeSign zero-branch and untested.ts mutants must survive, got survived=${ String(report.totals .survived,) }`, },); check({ that: report.totals .runtimeError === 0, message: `no infra errors expected, got runtimeError=${String(report.totals .runtimeError,)}`, },);
/** Survivors from the file no test selects. */ const untestedSurvivors = report.mutants .filter(function fromUntested(record,): boolean { return (record.file === 'src/untested.ts') && (record.status === 'survived'); },); check({ that: untestedSurvivors.length > 0, message: 'untested.ts must produce short-circuit survivors', },); check({ that: untestedSurvivors.every(function isConfirmed(record,): boolean { return record.confirmed; },), message: 'short-circuit survivors must be confirmed by construction', },); check({ that: report.mutants .filter(function actionable(record,): boolean { return (record.status === 'survived') || (record.status === 'timeout'); },) .every(function isConfirmed(record,): boolean { return record.confirmed; },), message: 'every survivor and timeout must be confirmed', },);
rl.info(`integration check passed; report at ${reportFile}`,);}
await runIntegrationCheck();