#!/usr/bin/env bash # Row 82 (#1551): rerun the listRuns mutants against a tree. Usage: # mutants.sh . The tree needs the candidate's listRuns; its tests can # be the candidate's or the base's. Each mutant drops one string check in # listRuns (scripts/mosaic-task.mjs), putting back that field's base line, # runs the runs suite, and restores the file from a saved copy, so the tree # need not be committed. Prints "killed" or "SURVIVED" per mutant; exit 1 if # any survives, a sed doesn't change the file, or the unmutated run fails. set -euo pipefail TREE="$(cd "${1:?usage: mutants.sh }" && pwd)" cd "$TREE" SRC=scripts/mosaic-task.mjs run_tests() { node --test 'packages/runs/tests/*.test.mjs' >"$1" 2>&1; } # name | sed expression MUTANTS=( 'status-unchecked|s/^ if (typeof result\.status === "string") status = result\.status;$/ status = result.status;/' 'taskid-unchecked|s/^ if (typeof result\.taskId === "string") taskId = result\.taskId;$/ taskId = result.taskId;/' 'workspace-unchecked|s/^ if (typeof result\.workspace === "string") workspace = result\.workspace;$/ workspace = String(result.workspace ?? "-");/' 'session-unchecked|s/^ if (typeof result\.session === "string") session = result\.session;$/ session = result.session ?? "-";/' ) OUT="${OUT:-$TREE/.mutants}" mkdir -p "$OUT" run_tests "$OUT/baseline.log" || { echo "baseline run failed: $OUT/baseline.log" >&2; exit 1; } echo "baseline: pass" status=0 for m in "${MUTANTS[@]}"; do IFS='|' read -r name expr <<<"$m" cp -p "$SRC" "$OUT/orig" sed -i -e "$expr" "$SRC" if cmp -s "$OUT/orig" "$SRC"; then echo "$name: NOT APPLIED (sed matched nothing)"; status=1; continue fi diff -u "$OUT/orig" "$SRC" >"$OUT/$name.diff" || true if run_tests "$OUT/$name.log"; then echo "$name: SURVIVED"; status=1 else echo "$name: killed ($(grep -E '^✖' "$OUT/$name.log" | grep -v 'failing tests' | sed 's/ ([0-9.]*ms)$//' | sort -u | tr '\n' ';'))" fi cp -p "$OUT/orig" "$SRC" cmp -s "$OUT/orig" "$SRC" || { echo "restore failed: $SRC" >&2; exit 1; } rm -f "$OUT/orig" done exit "$status"