#!/usr/bin/env bash # Row 73 (#1567): rerun the role-file revert and the mutants against a tree # with the candidate. Usage: mutants.sh . Each mutant edits one line, # runs the row's tests, 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 its file, or the unmutated run fails. # The tasks test is in the list but kills nothing here: the verb refuses a # coder's task.reassign with or without the grant. set -euo pipefail TREE="$(cd "${1:?usage: mutants.sh }" && pwd)" cd "$TREE" ROLE=roles/coder.json BROKER=packages/bus/src/broker.mjs RESOLVE=packages/business/src/resolve.mjs TOOLS=packages/harness/src/tools.mjs TESTS=( packages/bus/tests/broker.test.mjs packages/business/tests/role.test.mjs packages/business/tests/resolve.test.mjs packages/harness/tests/tools.test.mjs packages/tasks/tests/verbs.test.mjs ) run_tests() { node --test "${TESTS[@]}" >"$1" 2>&1; } # name | file | sed expression MUTANTS=( 'role-keeps-reassign|'"$ROLE"'|s/"crossRole": \["task.scope.change"\]/"crossRole": ["task.reassign", "task.scope.change"]/' 'broker-unlisted-cross|'"$BROKER"'|/^ ? .cross-role.$/{n;s/^ : .gated.;$/ : '"'"'cross-role'"'"';/}' 'resolve-cross-unnarrowed|'"$RESOLVE"'|s/^ crossRole = crossRole.filter((a) => vars\["limits.authority"\].includes(a));$/ crossRole = [...crossRole];/' 'classify-unlisted-cross|'"$RESOLVE"'|/^ if (resolved.limits.authority.crossRole.includes(action)) return "cross";$/{n;s/return "gated";/return "cross";/}' 'tools-all-task-verbs|'"$TOOLS"'|s/^ if (held.has(action)) add(name, action, action, description, obj(properties, required));$/ add(name, action, action, description, obj(properties, required));/' ) 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 file expr <<<"$m" cp -p "$file" "$OUT/orig" sed -i -e "$expr" "$file" if cmp -s "$OUT/orig" "$file"; then echo "$name: NOT APPLIED (sed matched nothing)"; status=1; continue fi diff -u "$OUT/orig" "$file" >"$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" "$file" cmp -s "$OUT/orig" "$file" || { echo "restore failed: $file" >&2; exit 1; } rm -f "$OUT/orig" done exit "$status"