diff --git a/README.md b/README.md index 652d3e0..fcef079 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,9 @@ Claude Code discovers the skill from the `name` and `description` in `SKILL.md`. - `SKILL.md`: the pipeline — the faculties, the loop, Self's discipline, and the git and tooling rules, each of which exists because something broke. -- `tools/eureka-mutations.ps1`: the mutation harness, parameterised by repo so - one copy serves every campaign. +- `tools/stopgap/ygg-verify.sh`: runs a verification job for an exact revision + on Yggdrasil in a capped container. It is a stopgap until Idunn's verify + transaction lands. - `references/briefs.md`: brief templates for each faculty. - `references/cut-map.md`: the shape of the target document and the cut map. - `references/postmortem-template.md` and `references/postmortem-cultcache.md`: diff --git a/SKILL.md b/SKILL.md index 24dd962..d9a0855 100644 --- a/SKILL.md +++ b/SKILL.md @@ -213,14 +213,17 @@ briefly, and the verification. The brief says: not a gate; the triaged survivor list is the record, and Self commits it in the map. Soul reruns the tool on the range rather than trusting Hands' triage. -- **Hand-written mutation entries are the fallback, for code no tool - reaches:** editor probes, shaders, a runtime without a tool. - `tools/eureka-mutations.ps1` serves those, under its contract: a no-op - control, byte-exact restore verified by hash, anchors matching exactly - once, an honest exit status. Anchors couple the suite to the code's - spelling, strand on every refactor, and can keep matching while silently - re-targeting onto code the tests no longer run, so a campaign that falls - back says why the tool cannot reach and treats each entry as debt. +- **No committed hand-written mutation suites, and no fallback harness.** + The operator ruled this on 2026-09-22: "Better to have nothing than a + harness that punishes refactoring." Anchors couple a suite to the code's + spelling. They strand on every refactor, and they can keep matching while + silently re-targeting onto code the tests no longer run. Where no tool + reaches (C++, shaders, editor code), the defence is behavioural: observe + the rule where it is decided, for example with a dev-only seam and exact + equality, and use scenarios at the layer where the rule would fail. Soul + may still mutate code by hand as a one-off probe during a pass. Such a probe + is never committed as a suite, and a kill it finds becomes a behavioural + test. - **"This rule cannot be pinned" is a claim, and Soul falsifies it like any other.** Recording an honest gap is right and beats inventing a kill, but the gap itself is a hypothesis about reachability, and it was wrong both times it @@ -416,20 +419,20 @@ and reconciles the target doc with the Body. the checkout with older sources ran the other checkout's last mutant binary. A surviving mutant can make an unmutated tree look green this way. A second checkout, such as Soul's clone or a parallel Hands worktree, gets its own - target subdirectory. The mutation harness is immune because it bumps the time - on every file it writes. A plain test run is not. + target subdirectory. The stopgap's containers each build in their own + scratch clone, so they are immune. - **Heavy verification runs on Yggdrasil, not on the operator's workstation.** - Heavy verification means builds, test suites and mutation harnesses. The - owner is Idunn's verify transaction (a campaign in progress, ruled - 2026-09-22). Until it lands, use the stopgap `tools/stopgap/ygg-verify.sh`. - It pushes an exact revision to a mirror on Yggdrasil and runs one command in - a container capped at 6 CPUs and 16 GiB, niced, with at most 2 jobs at a - time. Every Hands and Soul brief says so. Starfire runs only what has to run - on Windows, such as the QUIC win32 harness: one job at a time, never burners. + Heavy verification means builds, test suites and mutation tools. The owner + is Idunn's verify transaction (a campaign in progress, ruled 2026-09-22). + Until it lands, use the stopgap `tools/stopgap/ygg-verify.sh`. It pushes an + exact revision to a mirror on Yggdrasil and runs one command in a container + capped at 4 CPUs and 12 GiB, niced, with at most 2 jobs at a time. Every + Hands and Soul brief says so. Starfire runs only what has to run on Windows, + such as the QUIC win32 scenarios: one job at a time, never burners. - **The operator's workstation has a load budget, and Self owns it.** Running stress under load there, with CPU burners, is forbidden: use a dedicated host, or a container capped with `--cpus`. Run at most one heavy - verification job at a time, meaning a mutation harness, a repeated test + verification job at a time, meaning a mutation run, a repeated test loop, or a workspace build. Parallel agents are sized to that limit, not to the pipeline's appetite. On 2026-09-22 the operator had to force a shutdown. At the time, 16 `node` burners at twice the CPU count were running diff --git a/references/briefs.md b/references/briefs.md index 3abe82b..0834d32 100644 --- a/references/briefs.md +++ b/references/briefs.md @@ -104,8 +104,8 @@ suite with , scoped to this cut's diff code. Triage every survivor in the report by name and line: killed by a new test, killed by fixing a degenerate fixture, or equivalent with a one-line reason. A survivor that weakens a rule and cannot be killed is reported, not -hidden. Code no tool reaches falls back to `tools/eureka-mutations.ps1`; say -why the tool cannot reach it. +hidden. Code no tool reaches gets behavioural tests at the layer where the +rule is decided, never a committed mutation suite (operator, 2026-09-22). A hand mutation hits the rule at the layer it protects: the production call site, observed where the consequence lands (disk, the kernel, the request sent). Mutating a helper or an in-memory mirror proves the helper, not the @@ -158,9 +158,9 @@ it: "I'll wait for the suite and then report" ends the turn exactly as a to-do list does. Aetheria's shield Cut 3 burned two round trips this way, the second one after being told. If a run is going, block on it in this turn or read its finished output; do not yield to say what you are about to do. -Mutation tools run on schemata or copies and never edit the tree; a fallback -entry through `eureka-mutations.ps1` restores by hash, and `git checkout` is -never the restore, because it also reverts uncommitted fix code. +Mutation tools run on schemata or copies and never edit the tree. A Soul +probe that mutates by hand works on a scratch copy: the stopgap's container +or a throwaway clone, never the working tree. Warnings: measure from a forced rebuild and compare distinct messages; cargo replays warnings only when it actually rebuilds. Semantic properties ("exactly one call site", "this step actually runs"): diff --git a/tools/eureka-mutations.ps1 b/tools/eureka-mutations.ps1 deleted file mode 100644 index 71ff833..0000000 --- a/tools/eureka-mutations.ps1 +++ /dev/null @@ -1,546 +0,0 @@ -# Eureka mutation harness: one script for every cut's mutation suite. -# -# A suite is a data file of entries; each entry is one rule a test claims to -# pin, together with the exact source change that removes the rule and the -# test that must fail while the change is applied. The harness applies one -# entry at a time, runs that test alone, restores the file from the original -# bytes, and reports a verdict per entry. Nothing here knows which cut it is -# serving. -# -# powershell -File tools/eureka-mutations.ps1 ` -# -Entries tools/eureka-cut6b-mutations.psd1 ` -# -Target epiphany-pipeline/src/lib.rs ` -# -Test 'cargo test -p epiphany-pipeline --lib' -# -# -Entries a `.psd1` whose root is `@{ Mutations = @(...) }`, or a `.ps1` that -# returns the array. Paths are relative to the repo root. -# -Target the file (or files) the suite mutates, relative to the repo root. -# With one target every edit is against it; with more than one, each -# edit names its `File`, which must be one of the targets. -# -Test the cargo command that runs the suite's tests, as one string; the -# harness appends `-- --exact ` per entry. An entry may -# carry its own `Command` when its test lives in another package. -# The string is split on whitespace with no quoting, so a command -# or argument carrying a space (a path with a space in it) cannot be -# expressed here. -# -TimeoutSeconds the most one command may run, 1800 by default. A command -# still running at the limit is killed with its process tree by the -# harness itself, inside the entry's own restore, so a hung cargo is -# ended by the harness rather than by whatever tool is running the -# harness; the entry gets no verdict. -# -Repo the repo root that `-Entries` and `-Target` are relative to and -# that commands run from. Defaults to this script's parent, so a -# suite in another repo names this harness and passes its own root. -# -# Entry shape: `Id`, `Rule`, `Test`, and either `Old`/`New` (with an optional -# `File`) or `Edits = @(@{ File; Old; New }, ...)`. `New = ''` deletes the -# anchor. `MustNotCompile = $true` marks an entry whose proof is a compile -# error: it is killed when the mutated tree does not build and survives when -# it does; for every other entry a tree that does not build is no verdict. -# -# Harness rules: -# - Every target is read as bytes and decoded as UTF-8; every write encodes -# text back to bytes through one path, UTF-8 with no BOM. Windows PowerShell -# 5.1 is the interpreter on this host and its default round-trip corrupts a -# non-ASCII literal, which fails a test on its own and fakes a kill. -# - Anchors are written with plain newlines and converted to the target's own -# line endings before matching. -# - Every anchor must match exactly once, counting overlapping occurrences: -# `}\n}\n` in `}\n}\n}\n` is two sites, and a splice at the first would -# change a region the entry does not describe. Zero is a stale entry. Both -# throw, naming the entry. -# - Restore is the original bytes written back, never a checkout, and the -# restored file must hash to those bytes. Every write to a target, M0's -# included, sits inside a `try` whose `finally` restores every target the -# step touched, so a write that throws on the second target still restores -# the first. A target that cannot be restored is printed with the words -# RESTORE FAILED and its original SHA-256 so a human can recover it, and the -# run throws. -# - A hard kill runs no `finally`. So before any target is written, its -# original bytes are copied to a sidecar beside it, -# `.eureka-mutation-original`, which is deleted only after a -# hash-verified restore. At startup, every sidecar under the repo root -# (`target/`, `node_modules/` and `.git/` excluded), not only those of this -# run's targets, is repaired: the file is restored from it, hash-verified, -# and the sidecar removed, and the run prints that a previous run died -# mid-mutation and was repaired. A file that already equals its sidecar is -# left alone and the run says so. A file that is missing is recreated from -# its sidecar and the run says so. A file that differs is never overwritten -# silently: its current bytes go to `.eureka-mutation-overwritten` -# before the restore is written, and the run prints that path and its -# SHA-256 once the restore has landed; a restore that fails without opening -# the file removes that copy again, so it exists only when something was -# overwritten. An existing `.eureka-mutation-overwritten` is never itself -# clobbered: every copy is written to the first unused name in that family -# (`.eureka-mutation-overwritten`, then `.eureka-mutation-overwritten.1`, -# `.2`, ...), so a human's own copy and every repair's copy all survive. A -# file that cannot be written keeps its sidecar and the run stops, naming -# the file. A sidecar of a sidecar is not something a run leaves behind and -# cannot be ordered against its sibling, so the run stops before any -# repair, naming both. A sidecar `Assert-TargetUnedited` kept on purpose, -# because an edit outside the harness was caught and could not be silently -# discarded, carries its own marker, `.eureka-h1-stopped`; startup -# repair refuses to run at all while any such marker exists, prints what to -# reconcile, and touches nothing, rather than mistaking a deliberate stop -# for a crash and reverting a hand-cleaned file out from under an operator. -# - Every hash comparison in this script (sidecar, mutant and restore -# verification) is a case-sensitive ordinal compare (`-ceq`/`-cne`), and so -# is the no-op guard that rejects a mutation whose old and new text come -# out identical: PowerShell's plain `-eq`/`-ne` are case-insensitive, which -# let a mutant differing only in case (`"query"` to `"Query"`) be rejected -# as a no-op. Anchor matching (`Measure-Sites`, and the splice site lookup -# that follows it) already used ordinal `IndexOf` and needed no change. -# - M0 is built in and cannot be omitted: before any entry, every target's -# bytes are decoded and re-encoded through the harness I/O path and compared -# to the original bytes before anything is written. If a byte differs, the -# harness is broken: the target and the first differing offset are named, -# nothing is written and no entry runs. Only then is the target rewritten -# through the write path and hashed; a write that lands other bytes is the -# same verdict, with the original bytes written back first. Then every -# command the suite uses is run bare, and a failure is the same verdict. - -param( - [Parameter(Mandatory = $true)] [string] $Entries, - [Parameter(Mandatory = $true)] [string[]] $Target, - [Parameter(Mandatory = $true)] [string] $Test, - [int] $TimeoutSeconds = 1800, - [string] $Repo -) - -$ErrorActionPreference = 'Stop' - -if ($PSVersionTable.PSVersion.Major -lt 5 -or $env:OS -ne 'Windows_NT') { - throw "This script runs under Windows PowerShell 5.1 on Windows. Found PowerShell $($PSVersionTable.PSVersion) on $(if ($env:OS) { $env:OS } else { 'a non-Windows host' })." -} -if (-not $env:CARGO_TARGET_DIR) { - throw 'CARGO_TARGET_DIR is not set; set it the way the cut ran it rather than building into the repo-local target/.' -} -if ($TimeoutSeconds -lt 1) { throw "TimeoutSeconds must be at least 1, got $TimeoutSeconds." } - -$repo = if ($Repo) { (Resolve-Path -LiteralPath $Repo).Path } else { Split-Path -Parent $PSScriptRoot } -$utf8 = [System.Text.UTF8Encoding]::new($false) -# `powershell -File` hands a comma-separated argument over as one string, so -# split it here rather than asking the caller to know that. -$Target = @($Target | ForEach-Object { $_ -split ',' } | ForEach-Object { $_.Trim() } | Where-Object { $_ }) - -# The one decode and the one encode. M0 proves them inverse on every target's -# actual bytes before any write; every write goes through `Write-Text`. -function Decode-Bytes([byte[]] $bytes) { $utf8.GetString($bytes) } -function Encode-Text([string] $text) { [byte[]] ($utf8.GetPreamble() + $utf8.GetBytes($text)) } -function Write-Text([string] $path, [string] $text) { [System.IO.File]::WriteAllBytes($path, (Encode-Text $text)) } -function Get-Hash([string] $path) { (Get-FileHash -Algorithm SHA256 -LiteralPath $path).Hash } -function Get-BytesHash([byte[]] $bytes) { - ([System.Security.Cryptography.SHA256]::Create().ComputeHash($bytes) | ForEach-Object { $_.ToString('X2') }) -join '' -} -function Get-SidecarPath([string] $path) { "$path.eureka-mutation-original" } -$sidecarSuffix = '.eureka-mutation-original' -# H1's kept sidecar is marked so startup repair can tell it apart from a -# crash's: this file exists only when `Assert-TargetUnedited` chose to keep -# the sidecar on purpose (F1). Its own suffix, never matched by -# `Find-Sidecars`, so it is never itself mistaken for a sidecar. -function Get-H1MarkerPath([string] $path) { "$path.eureka-h1-stopped" } -# `.eureka-mutation-overwritten` holds a human's or a prior run's bytes and -# must never be clobbered (F2): every write picks the first name in this -# family that does not already exist, so an existing copy always survives -# beside the new one. -function Get-UniqueOverwrittenPath([string] $path) { - $base = "$path.eureka-mutation-overwritten" - if (-not (Test-Path -LiteralPath $base)) { return $base } - $counter = 1 - while (Test-Path -LiteralPath "$base.$counter") { $counter++ } - "$base.$counter" -} -# Every sidecar under `$root`, pruning the directories no target lives in. -function Find-Sidecars([string] $root) { - $pending = [System.Collections.Generic.Stack[string]]::new() - $pending.Push($root) - while ($pending.Count) { - $directory = $pending.Pop() - foreach ($child in [System.IO.Directory]::EnumerateDirectories($directory)) { - if ([System.IO.Path]::GetFileName($child) -in @('target', 'node_modules', '.git')) { continue } - $pending.Push($child) - } - [System.IO.Directory]::EnumerateFiles($directory, "*$sidecarSuffix") - } -} -# The first offset at which two byte arrays differ, or -1 when they are equal. -function Find-FirstDifference([byte[]] $left, [byte[]] $right) { - if ($null -eq $left -or $null -eq $right) { throw 'harness broken: Find-FirstDifference was handed a null byte array; a missing file is its own case and is decided before any comparison.' } - if ([System.Linq.Enumerable]::SequenceEqual($left, $right)) { return -1 } - $shared = [Math]::Min($left.Length, $right.Length) - for ($offset = 0; $offset -lt $shared; $offset++) { - if ($left[$offset] -ne $right[$offset]) { return $offset } - } - $shared -} -# Occurrences of `$anchor` in `$text`, overlapping ones included: the search -# resumes one character after each hit, not after its end. -function Measure-Sites([string] $text, [string] $anchor) { - $count = 0 - $at = $text.IndexOf($anchor, [System.StringComparison]::Ordinal) - while ($at -ge 0) { - $count++ - $at = $text.IndexOf($anchor, $at + 1, [System.StringComparison]::Ordinal) - } - $count -} - -# H1: a target's bytes are never restored, and never overwritten with the -# next mutant, without first being proven to still be one of two things: the -# M0 original, or (when supplied) the exact mutant this entry itself wrote. -# Anything else means a build step, a stray edit, or another tool changed the -# target while a run was in flight or between entries -- the case Soul found -# the harness silently discarding (H1: `eureka-mutations.ps1:163-175, 393, -# 415`). Such an edit is saved beside the target, a loud warning names it, and -# the run stops: continuing would either bury the edit under a restore or, for -# the next entry's write, bury it under a different mutant, either way losing -# it exactly as before. -# -# When this fires from inside `Restore-Targets`, this entry's own sidecar is -# already on disk (written before the mutant, below) and is kept rather than -# removed, on purpose, so the M0 original survives beside the edit that was -# lost. That kept sidecar is not a crash: it is deliberate, and startup -# repair must never treat it as one (F1), so an H1 marker goes down beside it -# naming the file and the moment. Startup repair refuses to run while that -# marker exists; an operator clears it by hand once the file is reconciled. -function Assert-TargetUnedited([string] $file, [string] $mutantHash) { - $path = $targets[$file] - if (-not (Test-Path -LiteralPath $path)) { return } - $current = Get-Hash $path - if ($current -ceq $hashes[$file]) { return } - if ($mutantHash -and $current -ceq $mutantHash) { return } - $overwritten = Get-UniqueOverwrittenPath $path - [System.IO.File]::WriteAllBytes($overwritten, [System.IO.File]::ReadAllBytes($path)) - $message = "EDIT LOST: $path (SHA-256 $current) is neither the M0 original ($($hashes[$file])) nor this entry's own mutant. Something edited it outside the harness while a run was in flight or between entries. Its bytes are kept in $overwritten. Stopping the run rather than silently discarding them." - $sidecar = Get-SidecarPath $path - if (Test-Path -LiteralPath $sidecar) { - $marker = Get-H1MarkerPath $path - [System.IO.File]::WriteAllText($marker, "H1 stopped a run over $path at $(Get-Date -Format o). $message`nThe sidecar $sidecar holds the M0 original on purpose; startup repair will refuse to run while this marker exists. Reconcile $path by hand against $overwritten and $sidecar, then delete $marker (and the sidecar, once you are done with it) to let the harness run again.") - $message = "$message A marker is kept at $marker; startup repair on this repo will refuse to run until it is removed by hand." - } - Write-Host $message - throw $message -} - -# Writes the original bytes back to each named target and proves it by hash, -# then removes the target's sidecar. A target already hashing to its original -# is not rewritten, so a write that never opened the file (a locked target) -# is not reported as a failed restore. Every target is attempted even when an -# earlier one fails; a target that cannot be restored is printed with RESTORE -# FAILED and its original SHA-256, its sidecar is kept, and the first failure -# is rethrown once the rest have been attempted. `$mutantHashes[$file]`, when -# supplied, is the SHA-256 of the mutant this call's caller itself wrote to -# `$file`, the one departure from the M0 original `Assert-TargetUnedited` lets -# through before restoring over it. -function Restore-Targets([string[]] $files, [hashtable] $mutantHashes = @{}) { - $failure = $null - foreach ($file in $files) { - $path = $targets[$file] - try { - Assert-TargetUnedited $file $mutantHashes[$file] - if ((Get-Hash $path) -cne $hashes[$file]) { - [System.IO.File]::WriteAllBytes($path, $bytes[$file]) - } - if ((Get-Hash $path) -cne $hashes[$file]) { - throw "writing the original bytes back did not restore $file; it does not hash to the original." - } - Remove-Item -LiteralPath (Get-SidecarPath $path) -Force -ErrorAction SilentlyContinue - } - catch { - Write-Host "RESTORE FAILED: $path was not restored; its original SHA-256 is $($hashes[$file]) and its original bytes are kept beside it in $(Get-SidecarPath $path). $_" - if (-not $failure) { $failure = $_ } - } - } - if ($failure) { throw $failure } -} - -# Runs one command from the repo root with its output captured; returns the -# test lines it printed, its exit code, whether the tree compiled and whether -# it ran out of time. A command still running at `$TimeoutSeconds` is killed -# with its whole process tree inside this function's own `finally`. -function Invoke-Cargo([string] $command, [string[]] $filter) { - $words = @($command -split '\s+' | Where-Object { $_ }) - if ($words.Count -lt 1) { throw "Empty test command." } - $arguments = @($words | Select-Object -Skip 1) + $filter - $start = [System.Diagnostics.ProcessStartInfo]::new() - $start.FileName = $words[0] - $start.Arguments = @($arguments | ForEach-Object { '"' + $_ + '"' }) -join ' ' - $start.WorkingDirectory = $repo - $start.UseShellExecute = $false - $start.RedirectStandardOutput = $true - $start.RedirectStandardError = $true - $start.CreateNoWindow = $true - $process = [System.Diagnostics.Process]::Start($start) - $stdout = $process.StandardOutput.ReadToEndAsync() - $stderr = $process.StandardError.ReadToEndAsync() - $timedOut = $false - try { - $timedOut = -not $process.WaitForExit($TimeoutSeconds * 1000) - } - finally { - if (-not $process.HasExited) { - # taskkill reports on stderr when a child is already gone; under - # `Stop` that line would be a terminating error of its own. - $ErrorActionPreference = 'Continue' - & taskkill /PID $process.Id /T /F 2>&1 | Out-Null - $ErrorActionPreference = 'Stop' - $process.WaitForExit() - } - } - $output = @(($stdout.Result + $stderr.Result) -split "`r?`n" | Where-Object { $_ -ne '' }) - $output | Out-Host - if ($timedOut) { Write-Host "TIMED OUT: '$command $($filter -join ' ')' ran past $TimeoutSeconds seconds and was killed with its process tree." } - $passed = @($output | ForEach-Object { if ($_ -match '^test (\S+) \.\.\. ok$') { $Matches[1] } }) - $failed = @($output | ForEach-Object { if ($_ -match '^test (\S+) \.\.\. FAILED$') { $Matches[1] } }) - # A test failure also prints an `error:` line, so only a compiler error - # code or cargo's own "could not compile" counts as a build failure. - $compiled = -not ($output | Where-Object { $_ -match '^error\[E\d+\]' -or $_ -match 'could not compile' }) - [pscustomobject]@{ Passed = $passed; Failed = $failed; ExitCode = $process.ExitCode; Compiled = $compiled; TimedOut = $timedOut } -} - -# --- Load the suite --------------------------------------------------------- - -$entriesPath = Join-Path $repo $Entries -$mutations = switch ([System.IO.Path]::GetExtension($entriesPath)) { - '.psd1' { (Import-PowerShellDataFile -LiteralPath $entriesPath).Mutations } - '.ps1' { & $entriesPath } - default { throw "$Entries`: an entries file is a .psd1 or a .ps1." } -} -if (-not $mutations -or @($mutations).Count -lt 1) { throw "$Entries`: no mutations." } - -$targets = @{} -foreach ($file in $Target) { - $path = Join-Path $repo $file - if (-not (Test-Path -LiteralPath $path)) { throw "Target $file does not exist." } - $targets[$file] = $path -} - -# Normalise every entry to a list of edits against a named target. -$suite = foreach ($mutation in $mutations) { - if (-not $mutation.Id) { throw 'An entry has no Id.' } - if (-not $mutation.Test) { throw "$($mutation.Id): no Test." } - $edits = if ($mutation.ContainsKey('Edits')) { @($mutation.Edits) } else { @(@{ File = $mutation.File; Old = $mutation.Old; New = $mutation.New }) } - if ($edits.Count -lt 1) { throw "$($mutation.Id): no edits." } - $resolved = foreach ($edit in $edits) { - $file = $edit.File - if (-not $file) { - if ($Target.Count -ne 1) { throw "$($mutation.Id): an edit names no File and the suite has $($Target.Count) targets." } - $file = $Target[0] - } - if (-not $targets.ContainsKey($file)) { throw "$($mutation.Id): edits $file, which is not a target of this run." } - if ([string]::IsNullOrEmpty($edit.Old)) { throw "$($mutation.Id): an edit against $file has an empty Old." } - [pscustomobject]@{ File = $file; Old = [string] $edit.Old; New = [string] $edit.New } - } - [pscustomobject]@{ - Id = [string] $mutation.Id - Rule = [string] $mutation.Rule - Test = [string] $mutation.Test - Command = if ($mutation.Command) { [string] $mutation.Command } else { $Test } - MustNotCompile = [bool] $mutation.MustNotCompile - Edits = @($resolved) - } -} - -# --- Repair a previous run that died mid-mutation -------------------------------- - -# The whole repo is searched, not only this run's targets: a sidecar left -# beside a file another suite mutates is the same dead run and the same -# corrupted tree. -$sidecars = @(Find-Sidecars $repo) -# The harness never mutates a sidecar, so a sidecar whose file is itself a -# sidecar was not left by a run and the two cannot be ordered: whichever is -# restored first decides which bytes are "original". Nothing is touched; a -# human resolves it. -foreach ($sidecar in $sidecars) { - $path = $sidecar.Substring(0, $sidecar.Length - $sidecarSuffix.Length) - if ($path.EndsWith($sidecarSuffix)) { - throw "$sidecar is a sidecar of a sidecar ($path), which no run leaves behind; which file holds the original bytes cannot be decided here. Nothing was written and no sidecar was repaired; resolve both by hand." - } -} -# F1: a sidecar H1 kept on purpose is marked, and startup repair must never -# treat it as a crash. Check every sidecar for its marker before touching -# any of them, so one H1-stopped file stops the whole repair pass rather -# than being silently repaired alongside unrelated crash sidecars. -$h1Stopped = @(foreach ($sidecar in $sidecars) { - $path = $sidecar.Substring(0, $sidecar.Length - $sidecarSuffix.Length) - $marker = Get-H1MarkerPath $path - if (Test-Path -LiteralPath $marker) { [pscustomobject]@{ Path = $path; Marker = $marker } } -}) -if ($h1Stopped.Count) { - $message = "Startup repair refuses to run: $($h1Stopped.Count) file(s) were stopped by H1 in a previous run, not crashed, and their sidecars are kept on purpose. Nothing was restored. Reconcile each file by hand, then delete its marker to resume: $(($h1Stopped | ForEach-Object { "$($_.Path) (marker $($_.Marker))" }) -join '; ')." - Write-Host $message - throw $message -} -foreach ($sidecar in $sidecars) { - $path = $sidecar.Substring(0, $sidecar.Length - $sidecarSuffix.Length) - try { - $original = [System.IO.File]::ReadAllBytes($sidecar) - $hash = Get-BytesHash $original - # A missing file is its own case: the sidecar holds the only copy of - # its bytes, so there is nothing to compare and nothing to keep. - if (-not (Test-Path -LiteralPath $path)) { - [System.IO.File]::WriteAllBytes($path, $original) - if ((Get-Hash $path) -cne $hash) { - throw "recreating it from $sidecar did not land the original bytes (SHA-256 $hash)." - } - Remove-Item -LiteralPath $sidecar -Force - Write-Host "A previous run left $sidecar and $path was missing; the file was recreated from the sidecar (SHA-256 $hash) and the sidecar removed." - continue - } - $current = [System.IO.File]::ReadAllBytes($path) - if ((Find-FirstDifference $current $original) -lt 0) { - Remove-Item -LiteralPath $sidecar -Force - Write-Host "A previous run left $sidecar; sidecar matched; nothing to restore. The sidecar was removed." - continue - } - # The bytes about to be overwritten may be a hand edit made after the - # crash. They are copied beside the file before the restore is written, - # because once the restore lands the copy is their only home; if the - # restore then fails without touching the file, the copy is removed - # below so it never claims an overwrite that did not happen. F2: an - # existing `.eureka-mutation-overwritten` -- a human's own copy, or one - # a prior repair left -- is never clobbered; this repair always writes - # to a fresh name beside it. - $overwritten = Get-UniqueOverwrittenPath $path - [System.IO.File]::WriteAllBytes($overwritten, $current) - try { - [System.IO.File]::WriteAllBytes($path, $original) - } - catch { - if ((Find-FirstDifference ([System.IO.File]::ReadAllBytes($path)) $current) -lt 0) { - Remove-Item -LiteralPath $overwritten -Force -ErrorAction SilentlyContinue - throw "the restore did not open the file and nothing was overwritten, so $overwritten was removed. $_" - } - throw "the restore changed the file before failing; its pre-repair bytes (SHA-256 $(Get-BytesHash $current)) are kept in $overwritten. $_" - } - if ((Get-Hash $path) -cne $hash) { - throw "restoring it from $sidecar did not land the original bytes (SHA-256 $hash); its pre-repair bytes (SHA-256 $(Get-BytesHash $current)) are kept in $overwritten." - } - Write-Host "The bytes $path held before the repair (SHA-256 $(Get-BytesHash $current)) are kept in $overwritten." - Remove-Item -LiteralPath $sidecar -Force - Write-Host "A previous run died mid-mutation of $path; it was repaired from $sidecar (SHA-256 $hash) and the sidecar removed." - } - catch { - $message = "$path could not repair, sidecar kept ($sidecar). Nothing ran. $($_.Exception.Message)" - Write-Host $message - throw $message - } -} - -# --- M0: the no-op control ---------------------------------------------------- - -$originals = @{} # decoded text per target; every edit is spliced into this -$bytes = @{} # the original bytes per target; the restore source -$hashes = @{} -$eols = @{} -Write-Host '--- M0: no-op control' -foreach ($file in $Target) { - $path = $targets[$file] - $original = [System.IO.File]::ReadAllBytes($path) - $text = Decode-Bytes $original - $encoded = Encode-Text $text - $differs = Find-FirstDifference $original $encoded - if ($differs -ge 0) { - throw "harness broken: $file does not survive the harness I/O path; the re-encoded bytes first differ from the original at offset $differs (original $($original.Length) bytes, re-encoded $($encoded.Length)). Nothing was written and no entry ran." - } - $hash = Get-BytesHash $original - $bytes[$file] = $original - $hashes[$file] = $hash - # The encode is proven; now the write path is, against the same bytes. - # The sidecar goes down before the write, and whatever the write does - # after its first byte, the `finally` writes the original back and - # proves it by hash. - [System.IO.File]::WriteAllBytes((Get-SidecarPath $path), $original) - try { - Write-Text $path $text - if ((Get-Hash $path) -cne $hash) { - throw "harness broken: writing $file through the harness I/O path did not land the re-encoded bytes; the original bytes were written back. No entry ran." - } - } - finally { - Restore-Targets @($file) - } - $originals[$file] = $text - $eols[$file] = if ($text.Contains("`r`n")) { "`r`n" } else { "`n" } - Write-Host "M0: $file decoded, re-encoded and rewritten, bytes unchanged ($(if ($eols[$file] -eq "`r`n") { 'CRLF' } else { 'LF' }), SHA-256 $hash)" -} -foreach ($command in @($suite | ForEach-Object { $_.Command } | Select-Object -Unique)) { - $control = Invoke-Cargo $command @() - if ($control.TimedOut -or $control.ExitCode -ne 0 -or $control.Failed.Count -ne 0 -or $control.Passed.Count -lt 1) { - throw "harness broken: '$command' is not green unmutated ($(if ($control.TimedOut) { 'timed out' } else { "exit $($control.ExitCode)" }), $($control.Passed.Count) passed, failed: $($control.Failed -join ', ')). No entry ran." - } - Write-Host "M0: '$command' green, $($control.Passed.Count) passed" -} -$results = @([pscustomobject]@{ Id = 'M0'; Test = '(suite)'; Verdict = 'green'; Rule = 'No-op control: targets round-tripped through the I/O path byte for byte, every command green.' }) - -# --- Entries -------------------------------------------------------------------- - -foreach ($mutation in $suite) { - Write-Host "--- $($mutation.Id): $($mutation.Rule)" - # Prepare every edit against the original text before touching a file, so - # a stale anchor throws with the tree untouched. - $texts = @{} - foreach ($file in @($mutation.Edits | ForEach-Object { $_.File } | Select-Object -Unique)) { $texts[$file] = $originals[$file] } - foreach ($edit in $mutation.Edits) { - $eol = $eols[$edit.File] - $old = ($edit.Old -replace "`r`n", "`n") -replace "`n", $eol - $new = ($edit.New -replace "`r`n", "`n") -replace "`n", $eol - $sites = Measure-Sites $texts[$edit.File] $old - if ($sites -ne 1) { - throw "$($mutation.Id): anchor matches $sites times in $($edit.File), expected exactly 1." - } - if ($old -ceq $new) { throw "$($mutation.Id): replacement changes nothing in $($edit.File)." } - # Spliced by position at the one site, so the replacement need not be - # unique (`Ok(())` is not) or non-empty. - $at = $texts[$edit.File].IndexOf($old, [System.StringComparison]::Ordinal) - $texts[$edit.File] = $texts[$edit.File].Substring(0, $at) + $new + $texts[$edit.File].Substring($at + $old.Length) - } - $files = @($texts.Keys) - $run = $null - # H1: before this entry writes its mutant, every target it touches must - # still be the M0 original -- never a prior entry's leftover mutant, and - # never an edit that landed between entries. Anything else stops the run - # rather than burying an unexplained edit under the next mutant. - foreach ($file in $files) { Assert-TargetUnedited $file $null } - # Every sidecar goes down before any target is written, and the writes sit - # inside the `try`, so a write that throws on the second target still - # restores the first. - foreach ($file in $files) { [System.IO.File]::WriteAllBytes((Get-SidecarPath $targets[$file]), $bytes[$file]) } - try { - foreach ($file in $files) { Write-Text $targets[$file] $texts[$file] } - $run = Invoke-Cargo $mutation.Command @('--', '--exact', $mutation.Test) - } - finally { - # Restore is the original bytes, whatever the entry or the build left - # behind, verified by hash -- but only once each target is proven to - # still be either the M0 original or exactly the mutant just written, - # so an edit made by the test command itself (H1) is caught here - # rather than silently overwritten by the restore. - $mutantHashes = @{} - foreach ($file in $files) { $mutantHashes[$file] = Get-BytesHash (Encode-Text $texts[$file]) } - Restore-Targets $files $mutantHashes - } - $named = $mutation.Test.Split(':')[-1] - $verdict = if ($run.TimedOut) { - 'TIMED OUT (no verdict)' - } elseif ($mutation.MustNotCompile) { - if (-not $run.Compiled) { 'killed (did not compile)' } else { 'SURVIVED (compiled)' } - } elseif (-not $run.Compiled) { - 'DID NOT BUILD (no verdict)' - } elseif ($run.Failed -contains $mutation.Test) { - 'killed' - } elseif ($run.Passed -contains $mutation.Test) { - 'SURVIVED' - } else { - 'TEST NOT RUN (stale test name?)' - } - $results += [pscustomobject]@{ Id = $mutation.Id; Test = $named; Verdict = $verdict; Rule = $mutation.Rule } - Write-Host "$($mutation.Id): $verdict" -} - -$results | Format-Table -AutoSize -Wrap -$notKilled = @($results | Where-Object { $_.Id -ne 'M0' -and $_.Verdict -notlike 'killed*' }) -if ($notKilled.Count) { - throw "Not every mutation was killed: $(($notKilled | ForEach-Object { "$($_.Id) $($_.Verdict)" }) -join '; ')." -} -Write-Host 'M0 green; every mutation was killed by its own test.' diff --git a/tools/stopgap/rust.Dockerfile b/tools/stopgap/rust.Dockerfile index 157108a..00a6819 100644 --- a/tools/stopgap/rust.Dockerfile +++ b/tools/stopgap/rust.Dockerfile @@ -1,9 +1,6 @@ -# STOPGAP image for ygg-verify.sh: Rust plus PowerShell, so the Eureka mutation -# harness can run cargo suites. It dies with ygg-verify.sh (see that file's -# deletion line). +# STOPGAP image for ygg-verify.sh: Rust plus cargo-mutants, the ecosystem +# mutation tool Soul runs on a cut's diff. It dies with ygg-verify.sh (see that +# file's deletion line). ygg-verify.sh tags the image by this file's hash, so an +# edit here rebuilds it. FROM rust:1.95-bookworm -ARG PWSH_VERSION=7.5.3 -RUN curl -fsSL -o /tmp/pwsh.tar.gz \ - "https://github.com/PowerShell/PowerShell/releases/download/v${PWSH_VERSION}/powershell-${PWSH_VERSION}-linux-x64.tar.gz" \ - && mkdir -p /opt/pwsh && tar -xzf /tmp/pwsh.tar.gz -C /opt/pwsh && rm /tmp/pwsh.tar.gz \ - && chmod +x /opt/pwsh/pwsh && ln -s /opt/pwsh/pwsh /usr/local/bin/pwsh +RUN cargo install --locked cargo-mutants && rm -rf /usr/local/cargo/registry diff --git a/tools/stopgap/ygg-verify.sh b/tools/stopgap/ygg-verify.sh index 748878f..94da402 100644 --- a/tools/stopgap/ygg-verify.sh +++ b/tools/stopgap/ygg-verify.sh @@ -16,67 +16,73 @@ # What it does: # 1. Pushes from a local repo to a bare mirror at # ~/eureka-verify/repos/.git on Yggdrasil. Unpushed commits work too. -# 2. Clones it into a scratch work directory on Yggdrasil and checks the -# commit out detached. It uses a real clone, not a worktree, because a +# 2. Clones the mirror into a scratch work directory on Yggdrasil and checks +# the commit out detached. It is a real clone, not a worktree, because a # worktree's .git file points at a host path the container cannot see. -# 3. Runs in with a CPU and memory cap, niced, with one -# shared registry cache per toolchain. The build output directory stays -# inside the work directory, never shared between checkouts. +# 3. Runs in under a CPU and memory cap, niced. Each +# toolchain gets one shared registry cache. The build output directory +# stays inside the work directory and is never shared between checkouts. # 4. Removes the work directory unless KEEP=1, and exits with the job's status. # # At most $SLOTS jobs run at once on Yggdrasil, because it serves live -# traffic. The default cap for each job is 4 of its 16 CPUs and 12 GiB, the policy the operator ruled for Idunn verify (Q-V6). +# traffic. The default cap for each job is 4 of its 16 CPUs and 12 GiB, the +# policy the operator ruled for Idunn verify (Q-V6). # -# EDITING: bash reads a running script from disk as it goes, so an in-place -# edit breaks every job still running it. One died with "unexpected EOF" on -# 2026-09-22. Write the new version to a temp file and rename it over this one. +# There is no hand-written mutation harness: the operator retired it on +# 2026-09-22. Mutation testing uses the ecosystem's tools on a cut's diff. +# +# EDITING: bash reads a running script from disk as it goes, so editing this +# file in place breaks every job still running it (one died with "unexpected +# EOF", 2026-09-22). Write the new version to a temp file and rename it over +# this one. # # Usage (Git Bash on Starfire): # ygg-verify.sh '' # Images: -# rust eureka-verify-rust (rust 1.95 plus pwsh; built from rust.Dockerfile) -# dotnet mcr.microsoft.com/dotnet/sdk:10.0 (ships pwsh) -# any other value is used as the image name as-is. -# The Eureka harness is copied to /harness/eureka-mutations.ps1 in the container. +# rust eureka-verify-rust: (rust 1.95 plus cargo-mutants) +# dotnet mcr.microsoft.com/dotnet/sdk:10.0 (install Stryker in the command: +# dotnet tool install -g dotnet-stryker) +# any other value is used as an image name as-is. # Example: # ygg-verify.sh /f/Projects/Huginn HEAD rust \ -# 'cargo test --workspace && pwsh /harness/eureka-mutations.ps1 -Repo /src -Entries tools/eureka-cut10-mutations.psd1' +# 'cargo test --workspace && git diff BASE HEAD > /tmp/d && cargo mutants --in-diff /tmp/d' set -euo pipefail repo=${1:?local repo}; rev=${2:?revision}; image=${3:?image}; cmd=${4:?command} host=${YGG_HOST:-ygg}; cpus=${CPUS:-4}; mem=${MEM:-12g}; slots=${SLOTS:-2} here=$(cd "$(dirname "$0")" && pwd) -harness="$here/../eureka-mutations.ps1" sshopts=(-o BatchMode=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=4) sha=$(git -C "$repo" rev-parse --verify "$rev^{commit}") name=$(basename "$(git -C "$repo" rev-parse --show-toplevel)") case "$image" in - rust) image=eureka-verify-rust ;; + rust) image=eureka-verify-rust:$(sha256sum "$here/rust.Dockerfile" | cut -c1-12) ;; dotnet) image=mcr.microsoft.com/dotnet/sdk:10.0 ;; esac -ssh "${sshopts[@]}" "$host" "mkdir -p ~/eureka-verify/repos ~/eureka-verify/work ~/eureka-verify/harness && \ +ssh "${sshopts[@]}" "$host" "mkdir -p ~/eureka-verify/repos ~/eureka-verify/work ~/eureka-verify/images && \ { test -d ~/eureka-verify/repos/$name.git || git init -q --bare ~/eureka-verify/repos/$name.git; }" git -C "$repo" push -q "$host:eureka-verify/repos/$name.git" "$sha:refs/verify/$sha" --force -scp -q "$harness" "$host:eureka-verify/harness/eureka-mutations.ps1" -if [ "$image" = eureka-verify-rust ]; then - scp -q "$here/rust.Dockerfile" "$host:eureka-verify/harness/rust.Dockerfile" -fi +case "$image" in + eureka-verify-rust:*) scp -q "$here/rust.Dockerfile" "$host:eureka-verify/images/rust.Dockerfile" ;; +esac -# ssh joins its arguments into one string that the remote shell re-splits, so -# every argument is quoted here. Without it, `a && b` in the command runs b -# on the host. +# ssh joins its arguments into one string that the remote shell splits again, +# so every argument is quoted here. Without that, `a && b` in the command runs +# b on the host. remote_args=$(printf '%q ' "$name" "$sha" "$image" "$cpus" "$mem" "$slots" "${KEEP:-0}" "$cmd") ssh "${sshopts[@]}" "$host" "bash -s -- $remote_args" <<'REMOTE' set -euo pipefail name=$1 sha=$2 image=$3 cpus=$4 mem=$5 slots=$6 keep=$7 cmd=$8 root=~/eureka-verify -if [ "$image" = eureka-verify-rust ] && ! sudo docker image inspect eureka-verify-rust >/dev/null 2>&1; then - sudo nice -n 10 docker build -q -t eureka-verify-rust -f $root/harness/rust.Dockerfile $root/harness >/dev/null -fi -# Take whichever slot frees first. Waiting on one fixed slot while another -# freed stranded a job for over an hour on 2026-09-22. +case "$image" in + eureka-verify-rust:*) + if ! sudo docker image inspect "$image" >/dev/null 2>&1; then + sudo nice -n 10 docker build -q -t "$image" -f "$root/images/rust.Dockerfile" "$root/images" >/dev/null + fi ;; +esac +# Take whichever slot frees first. On 2026-09-22 a job waited on one fixed slot +# while another freed, and stayed stranded for over an hour. slot=""; waited=0 while [ -z "$slot" ]; do for i in $(seq 1 "$slots"); do @@ -96,7 +102,7 @@ git -C "$work" checkout -q --detach "$sha" echo "ygg-verify: $name@${sha:0:10} slot $slot, image $image, cpus $cpus, mem $mem, work $work" >&2 set +e sudo nice -n 10 docker run --rm --cpus="$cpus" --memory="$mem" \ - -v "$work:/src" -v "$root/harness:/harness:ro" -v /etc/machine-id:/etc/machine-id:ro \ + -v "$work:/src" -v /etc/machine-id:/etc/machine-id:ro \ -v eureka-cargo-registry:/usr/local/cargo/registry -v eureka-nuget:/root/.nuget/packages \ -e CARGO_TARGET_DIR=/src/target \ -e GIT_CONFIG_COUNT=1 -e GIT_CONFIG_KEY_0=safe.directory -e GIT_CONFIG_VALUE_0='*' \