Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .claude/skills/ci-gates/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -1744,3 +1744,43 @@ instrument that works because everything it has ever seen was arranged one way.
auditor at it, especially then — and when a prediction cannot be tested, say
which precondition failed rather than letting the attempt read as a confirmation.

## 44. Feeding the degenerate inputs to my own new flag

§42 said the boundary operator's yield is the empty case, the equal case, and
the one off the edge — the inputs nobody plants. §43 said a tool you wrote from
the lessons is still a tool. This is what happened when the two were applied to
`--dir`, one iteration after shipping it.

Four degenerate inputs. **Two of them exited 0.**

| input | before | after |
|---|---|---|
| a directory that does not exist | refused, names the flag | unchanged |
| a **file** instead of a directory | died with `git status failed` | refused as *not a directory* |
| an **empty** directory | header, no rows, **exit 0** | refused: nothing measured is not nothing wrong |
| a directory **outside any git work tree** | ran, **exit 0** | refused |

**The empty directory is the vacuous pass, in the command whose subject is
vacuous passes.** A table with a header and no rows reads exactly like a clean
suite. I had widened the file filter the day before *because* a wrong filter
produced this table — and never made the empty result say so, so the hazard
survived the fix that was aimed at it.

**The one outside a work tree has teeth.** This command rewrites each gate file
in place and restores it afterwards, and that restore is only a promise because
`git checkout` can undo an interrupted run. Outside a repository there is no
undo — and the dirty-tree guard that exists for exactly this passed silently,
because `git status` *fails* there and its empty stdout reads as clean. **A guard
whose failure mode is indistinguishable from its success.**

**And then I wrote the bug into its own fix.** The first version of the
empty-directory refusal printed `FAIL: no gate scripts under …` and returned
`Ok(())` — announcing that nothing had been measured, and exiting 0. Measured,
not noticed by reading: `exit 0` before, `exit 1` after. A message is not a
verdict, and this is the third time this campaign that the two got confused.

**The rule.** After adding an option, spend one iteration giving it the inputs
you had no reason to try: nothing, empty, wrong type, wrong place. The author of
an option builds the case that motivated it — which is, by construction, not any
of those.

148 changes: 123 additions & 25 deletions cli/tri/src/gates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,54 @@ fn equivalence_claims(src: &str) -> std::collections::HashMap<usize, String> {
out
}

/// Where to audit, and a refusal for every way the answer can be nothing.
///
/// T111: each branch below is a degenerate input this flag accepted on the day
/// it shipped, found by feeding it the inputs its own author had no reason to
/// try -- which is the lesson the command exists to teach, arriving in the
/// command.
fn resolve_target(dir: Option<&str>) -> Result<(std::path::PathBuf, std::path::PathBuf)> {
let Some(d) = dir else {
let r = repo_root()?;
let t = r.join("tools");
return Ok((r, t));
};
let tools = std::fs::canonicalize(d).with_context(|| format!("--dir {d}"))?;
if !tools.is_dir() {
// Previously this reached the dirty-tree check and died with
// "git status failed", which names the instrument rather than the
// mistake.
anyhow::bail!("--dir {d} is not a directory");
}
// The gate runs with cwd at ITS repository root, not at the directory
// holding it: a gate that resolves paths relative to the working directory
// would otherwise be run somewhere it has never been run, and the
// difference would look like a finding.
//
// And a directory outside any repository is REFUSED, not defaulted. This
// command rewrites gate files in place and restores them afterwards; the
// restore is only a promise because `git checkout` can undo an interrupted
// run. Outside a work tree there is no undo, and the dirty-tree guard that
// is supposed to protect against exactly that passed silently there --
// `git status` fails, stdout is empty, and empty reads as clean.
let out = Command::new("git")
.args(["rev-parse", "--show-toplevel"])
.current_dir(&tools)
.output();
match out {
Ok(o) if o.status.success() => Ok((
std::path::PathBuf::from(String::from_utf8_lossy(&o.stdout).trim().to_string()),
tools,
)),
_ => anyhow::bail!(
"--dir {d} is not inside a git work tree.\n\
This command rewrites each gate in place and restores it. That restore \
is only recoverable because `git checkout` exists; with no repository \
an interrupted run leaves a mutated file and no way back."
),
}
}

fn label(d: Direction) -> &'static str {
match d {
Direction::Silent => "silent",
Expand All @@ -610,31 +658,7 @@ fn line_of(src: &str, byte: usize) -> usize {
}

fn mutate(only: Option<&str>, loud: bool, invert: bool, all: bool, dir: Option<&str>) -> Result<()> {
let (root, tools) = match dir {
None => {
let r = repo_root()?;
let t = r.join("tools");
(r, t)
}
Some(d) => {
let t = std::fs::canonicalize(d).with_context(|| format!("--dir {d}"))?;
// The gate runs with cwd at ITS repository root, not at the
// directory holding it: a gate that resolves paths relative to the
// working directory would otherwise be run somewhere it has never
// been run, and the difference would look like a finding.
let out = Command::new("git")
.args(["rev-parse", "--show-toplevel"])
.current_dir(&t)
.output();
let r = match out {
Ok(o) if o.status.success() => std::path::PathBuf::from(
String::from_utf8_lossy(&o.stdout).trim().to_string(),
),
_ => t.parent().map(|p| p.to_path_buf()).unwrap_or(t.clone()),
};
(r, t)
}
};
let (root, tools) = resolve_target(dir)?;
let dirty = Command::new("git")
.args(["status", "--porcelain", "--", "."])
.current_dir(&tools)
Expand Down Expand Up @@ -663,6 +687,24 @@ fn mutate(only: Option<&str>, loud: bool, invert: bool, all: bool, dir: Option<&
.collect();
files.sort();

// T111: nothing found is a FINDING, not a pass. Aimed at a directory with
// no gate scripts, this printed its header, printed no rows, and exited 0 --
// which reads exactly like a clean suite. The command whose whole subject is
// a check that cannot fail had one.
if files.is_empty() {
println!(
"FAIL: no gate scripts under {}\n\n \
Looked for *.py named check_* / check-* or containing \"gate\".\n \
Nothing was measured, which is not the same as nothing being wrong.",
tools.display()
);
// A message is not a verdict. The first version of this block printed
// FAIL and returned Ok, so the command announced that nothing had been
// measured and exited 0 -- the vacuous pass, written into the fix for
// the vacuous pass, in the command whose subject is vacuous passes.
anyhow::bail!("no gate scripts under {}", tools.display());
}

let directions: &[Direction] = if all {
&[
Direction::Silent,
Expand Down Expand Up @@ -1301,6 +1343,62 @@ def main():\n if problems:\n return 2\n return 0\n";
assert!(equivalence_claims("# mutant-equivalent: x\n").is_empty());
}

#[test]
fn every_degenerate_dir_is_refused_by_name() {
// T111: the four inputs `--dir` accepted on the day it shipped. Two of
// them exited 0 -- an empty directory printed a header and no rows,
// which reads exactly like a clean suite, and a directory outside any
// repository passed the dirty-tree guard because `git status` fails
// there and its empty stdout reads as clean.
//
// The second is the one with teeth: this command rewrites each gate in
// place and restores it, and that restore is only recoverable because
// `git checkout` exists. Outside a work tree an interrupted run leaves
// a mutated file and no way back.
let base = std::env::temp_dir().join(format!("tri_t111_{}", std::process::id()));
let _ = std::fs::remove_dir_all(&base);
std::fs::create_dir_all(base.join("plain")).unwrap();
std::fs::write(base.join("afile"), "x").unwrap();

let msg = |d: &std::path::Path| match resolve_target(Some(d.to_str().unwrap())) {
Ok(_) => "OK".to_string(),
Err(e) => format!("{e:#}"),
};

assert!(msg(&base.join("nope")).contains("--dir"), "a missing dir must name the flag");
assert!(
msg(&base.join("afile")).contains("not a directory"),
"a file must be refused as a file, not as a git failure"
);
assert!(
msg(&base.join("plain")).contains("git work tree"),
"a directory outside a repository must be refused: got {:?}",
msg(&base.join("plain"))
);

// And the accepting direction, or the three refusals above would pass
// for a function that refuses everything.
let repo = base.join("repo");
std::fs::create_dir_all(repo.join("tools")).unwrap();
let ran = Command::new("git")
.args(["init", "-q"])
.current_dir(&repo)
.status()
.map(|s| s.success())
.unwrap_or(false);
if ran {
let (root, tools) = resolve_target(Some(repo.join("tools").to_str().unwrap()))
.expect("a tools dir inside a repository is the normal case");
assert!(tools.ends_with("tools"));
assert_eq!(
std::fs::canonicalize(&root).unwrap(),
std::fs::canonicalize(&repo).unwrap(),
"root must be the work tree, not the parent of the directory"
);
}
let _ = std::fs::remove_dir_all(&base);
}

#[test]
fn the_boundary_operator_takes_comparisons_and_nothing_else() {
// T107. The operator is an off-by-one, so what it must NOT take matters
Expand Down
23 changes: 23 additions & 0 deletions docs/now/2026-08-23-degenerate-inputs-to-my-own-flag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# NOW — feeding the degenerate inputs to my own new flag (2026-08-23)

`--dir` shipped one iteration ago. Four degenerate inputs; **two of them exited 0**.

| input | before | after |
|---|---|---|
| a directory that does not exist | refused, names the flag | unchanged |
| a **file** instead of a directory | died with `git status failed` | refused as *not a directory* |
| an **empty** directory | header, no rows, **exit 0** | refused |
| a directory **outside any git work tree** | ran, **exit 0** | refused |

- The gate now refuses each of these by name, and the refusal says which mistake was made rather than which instrument noticed.
- The NOW entry this replaced had no bullet at all — a table instead — and `check-now-freshness` rejected it. Its four requirements are a heading, a bullet, a dated filename and a date in the UTC window; a table is none of them. Third time this campaign that a gate caught me rather than the other way round.

**The empty directory is the vacuous pass, in the command whose subject is vacuous passes.** A table with a header and no rows reads exactly like a clean suite. I had widened the file filter the day before *because* a wrong filter produced this table — and never made the empty result say so, so the hazard survived the fix aimed at it.

**The one outside a work tree has teeth.** This command rewrites each gate in place and restores it, and that restore is only a promise because `git checkout` can undo an interrupted run. Outside a repository there is no undo — and the dirty-tree guard that exists for exactly this passed silently, because `git status` *fails* there and its empty stdout reads as clean. A guard whose failure mode is indistinguishable from its success.

**And then I wrote the bug into its own fix.** The first version of the empty-directory refusal printed `FAIL: no gate scripts under …` and returned `Ok(())` — announcing that nothing had been measured, and exiting 0. Measured rather than noticed: exit 0 before, exit 1 after.

Test verified RED on the restored defect. Default behaviour unchanged, 14 unit tests green.

**The rule:** after adding an option, spend one iteration giving it the inputs you had no reason to try — nothing, empty, wrong type, wrong place. The author of an option builds the case that motivated it, which is by construction none of those.
Loading