Skip to content

Commit add8b48

Browse files
norandomclaude
andcommitted
fix(cli): make commands that passed without doing the work fail loudly
Python analyze and Python mutate write nothing, say they are not implemented and exit 2. mutate exits 1 when no operator matched. The pre-push hook no longer announces refactoring branches and checks budgets only; the dead refactor-branch code is removed. New CLI and hook tests cover each behaviour. README, the deconvolute skill, the adopter check and R55 describe the change. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 53aba71 commit add8b48

8 files changed

Lines changed: 235 additions & 81 deletions

File tree

‎.agents/skills/deconvolute/SKILL.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ Evaluate structural reduction using `lesscode-core`:
7474
The native `lesscode-core` binary exposes first-class deconvolution commands across all supported runtimes:
7575

7676
### Known limits of the porcelain (R55, 2026-11-10)
77-
Measured with the 1.0.1 binary; see `docs/research/2026-11-10/01-released-binary-adopter-dogfood.md`.
78-
- `analyze --lang python` performs no analysis and still reports `"passed": true`. Do not use it as evidence.
79-
- `mutate` uses operators bound to the experiment specimens. On other code it usually writes no mutants and still exits 0; read `mutants_generated`. There is no Python generator.
77+
Measured with the 1.0.1 binary; see `docs/research/2026-11-10/01-released-binary-adopter-dogfood.md`. Where the release after 1.0.1 behaves differently, the item says so.
78+
- `analyze --lang python` performs no analysis. From the release after 1.0.1 it writes no receipt, prints a note to stderr and exits 2. Version 1.0.1 still reports `"passed": true`. Do not use either as evidence.
79+
- `mutate` uses operators bound to the experiment specimens. On other code it usually writes no mutants. From the release after 1.0.1 it then exits 1 (the receipt shows `"mutants_generated": 0`); version 1.0.1 exits 0, so read `mutants_generated`. There is no Python generator: from the release after 1.0.1 `mutate --lang python` writes nothing and exits 2.
8080
- `density --lang python` reports the line count in both the line and statement fields.
81-
- The pre-push hook enforces complexity budgets only. It does not analyze `refactor/*` or `deconvolute/*` branches.
81+
- The pre-push hook enforces complexity budgets only. From the release after 1.0.1 it treats `refactor/*` and `deconvolute/*` branches like any other branch; version 1.0.1 announces them but checks nothing more.
8282

8383
### Binary Discovery
8484
Prefer an installed release binary on `PATH` (`lesscode-core --version`; install with `scripts/install.sh` or `scripts/install.ps1`). Otherwise locate the compiled binary in standard build locations:
@@ -114,7 +114,7 @@ lesscode-core deconvolute density --lang <rust|java|typescript|python> --baselin
114114
- **Decision:** Emits `pass` if thresholds ($\ge 20\%$ and $\ge 50$ lines, $\ge 10\%$ and $\ge 10$ statements) are met, or `marginal`/`fail` otherwise.
115115

116116
### Intelligent Git Pre-Push Hook (`pre-push` & `install-hook`)
117-
Interprets push refs, verifies complexity ceilings before remote push, and gates candidate refactoring branches:
117+
Interprets push refs and verifies complexity ceilings before a remote push:
118118
```powershell
119119
# Install the pre-push hook into .git/hooks:
120120
lesscode-core deconvolute install-hook [--git-dir .git] [--force]
@@ -124,7 +124,7 @@ lesscode-core deconvolute pre-push [--local-ref <ref>] [--local-sha <sha>]
124124
```
125125
- **Automatic Bypasses:** Deletions of remote branches and `LESSCODE_SKIP_HOOK=1` exit 0 immediately.
126126
- **Complexity Budgets:** Intercepts regressions in `complexity-budgets.json` before code reaches the remote.
127-
- **Refactoring Branches (`refactor/*`, `deconvolute/*`):** Recognized and announced; the hook prints a note when tracked files are uncommitted. No state-boundary or mutation check runs in the hook, so run `analyze` and the test oracle yourself.
127+
- **Refactoring Branches (`refactor/*`, `deconvolute/*`):** From the release after 1.0.1, treated like any other branch: budget check only (version 1.0.1 announces them and prints a note when tracked files are uncommitted). No state-boundary or mutation check runs in the hook, so run `analyze` and the test oracle yourself.
128128

129129
### General & Budget Commands
130130
```powershell

‎README.md‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,29 @@ Know these three things before you install it:
201201

202202
These limits were measured with the 1.0.1 binary on this repository and are
203203
recorded in [R55](docs/research/2026-11-10/01-released-binary-adopter-dogfood.md).
204+
Where the release after 1.0.1 behaves differently, the bullet says so.
204205

205206
- The commands do not run your tests and do not establish that a rewrite
206207
behaves the same. Behavioral evidence is yours to supply and review.
207-
- `deconvolute analyze --lang python` is not implemented. It returns an empty
208-
receipt with `"passed": true` for any Python file. Do not read that as a
209-
clean result.
208+
- `deconvolute analyze --lang python` is not implemented. From the release
209+
after 1.0.1 it writes no receipt, prints a note to stderr and exits with
210+
code 2. Version 1.0.1 instead returns an empty receipt with `"passed": true`
211+
for any Python file; do not read that as a clean result.
210212
- `deconvolute density --lang python` counts lines only; its statement fields
211213
repeat the line count.
212214
- `deconvolute mutate` applies operators written for the specimens used in
213215
this project's experiments. On other code it usually produces no mutants:
214216
it did so for 36 of the 38 Rust files in `native/src` and for all 40 Python
215-
files tried. The command still exits 0 in that case, so check
217+
files tried. From the release after 1.0.1 it exits with code 1 when no
218+
operator matches (the receipt still shows `"mutants_generated": 0`), and
219+
`--lang python` writes nothing and exits with code 2 because there is no
220+
Python generator. Version 1.0.1 exits 0 in both cases, so check
216221
`mutants_generated` in the receipt. It is not yet a general mutation tool.
217222
- The budget check reads the files in your working tree, not the commits being
218223
pushed, and it covers Rust only.
219-
- On `refactor/*` and `deconvolute/*` branches the hook prints a note about
220-
uncommitted changes. It performs no additional analysis on those branches.
224+
- The hook checks complexity budgets only, and from the release after 1.0.1
225+
it treats every branch the same. Version 1.0.1 prints a note on `refactor/*`
226+
and `deconvolute/*` branches but performs no additional analysis on them.
221227
- Receipts written with `--out` may be placed anywhere, including inside your
222228
source tree, and an existing file is overwritten.
223229

‎docs/research/2026-11-10/01-released-binary-adopter-dogfood.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ workstation's `PATH`.
167167
through the installer scripts, and run the analyzers on one external
168168
repository per language.
169169

170+
## Amendment, 2026-11-10: the three false passes now fail loudly
171+
172+
Owner decision of 2026-11-10 ("fail loudly now"), implemented for the release
173+
after 1.0.1: `deconvolute analyze --lang python` and `deconvolute mutate
174+
--lang python` write nothing, say on stderr that they are not implemented and
175+
exit 2; `mutate` exits 1 when no operator matched (the receipt is still
176+
written); the pre-push hook no longer announces refactoring branches and
177+
treats every branch the same, checking budgets only. Covered by new CLI and
178+
hook tests; 356 native tests pass. The findings above describe 1.0.1 and stay
179+
as measured. The operators themselves are unchanged and still specimen-bound;
180+
replacing them is the subject of the agnostic-annotation-driver gate.
181+
170182
## Amendment, 2026-11-10: owner direction on mutation
171183

172184
The owner directs that the specimen-bound mutation operators be addressed in

‎native/src/cli_deconvolute.rs‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub enum DeconvoluteCommand {
5252
#[arg(long)]
5353
out: Option<PathBuf>,
5454
},
55-
/// Intelligent Git pre-push hook for size governance and refactoring discipline.
55+
/// Git pre-push hook; enforces complexity budgets only.
5656
PrePush(cli_hook::PrePushArgs),
5757
/// Install standard Git pre-push hook script in .git/hooks.
5858
InstallHook(cli_hook::InstallHookArgs),
@@ -127,6 +127,12 @@ fn normalize_lang(lang: &str) -> Result<&'static str, String> {
127127
}
128128
}
129129

130+
/// Python has no analyzer or mutant generator: produce nothing and exit 2 (incomplete).
131+
fn python_not_implemented(what: &str) -> Result<u8, String> {
132+
eprintln!("Python {what} is not implemented in this release; no result was produced.");
133+
Ok(2)
134+
}
135+
130136
pub fn run(cmd: DeconvoluteCommand) -> Result<u8, String> {
131137
match cmd {
132138
DeconvoluteCommand::Analyze {
@@ -159,6 +165,9 @@ fn run_analyze(
159165
out: Option<&Path>,
160166
) -> Result<u8, String> {
161167
let lang = normalize_lang(lang)?;
168+
if lang == "python" {
169+
return python_not_implemented("analysis");
170+
}
162171
let source_text = read_text(source_path)?;
163172
let path_str = source_path.to_string_lossy().to_string();
164173

@@ -172,7 +181,6 @@ fn run_analyze(
172181
"typescript" => TypeScriptAdapter::new()
173182
.analyzer
174183
.scan_source(&path_str, &source_text),
175-
"python" => (Vec::new(), Vec::new()),
176184
_ => unreachable!(),
177185
};
178186

@@ -282,6 +290,9 @@ fn run_mutate(
282290
out: Option<&Path>,
283291
) -> Result<u8, String> {
284292
let lang = normalize_lang(lang)?;
293+
if lang == "python" {
294+
return python_not_implemented("mutation");
295+
}
285296
let source_text = read_text(source_path)?;
286297
fs::create_dir_all(out_dir)
287298
.map_err(|e| format!("Cannot create out-dir {}: {e}", out_dir.display()))?;
@@ -293,7 +304,6 @@ fn run_mutate(
293304
"rust" => "rs",
294305
"java" => "java",
295306
"typescript" => "ts",
296-
"python" => "py",
297307
_ => unreachable!(),
298308
};
299309
write_mutants(out_dir, ext, &mutants)?;
@@ -307,6 +317,13 @@ fn run_mutate(
307317
passed: !mutants.is_empty(),
308318
};
309319
emit_json(&receipt, out)?;
320+
if !receipt.passed {
321+
eprintln!(
322+
"No mutation operator matched {}; 0 mutants were generated.",
323+
receipt.source
324+
);
325+
return Ok(1);
326+
}
310327
Ok(0)
311328
}
312329

‎native/src/cli_hook.rs‎

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
//! Git pre-push hook and installer porcelain for size governance and refactoring discipline.
1+
//! Git pre-push hook and installer porcelain. The hook enforces complexity budgets only.
22
//!
3-
//! Intelligently intercepts candidate branches before pushing to remotes:
43
//! - Bypasses branch deletions (`(delete)` or zero-sha) and `LESSCODE_SKIP_HOOK=1`.
5-
//! - Runs fast complexity budget validation against `complexity-budgets.json`.
6-
//! - Treats `refactor/*` and `deconvolute/*` branches as major refactorings,
7-
//! validating AST state-boundary cleanliness on modified source files.
4+
//! - Otherwise runs the complexity budget check against `complexity-budgets.json`.
5+
//! - Treats every branch name the same; no other check runs.
86
97
use std::fs;
108
use std::io::Read;
@@ -19,7 +17,7 @@ pub struct PrePushArgs {
1917
pub remote: Option<String>,
2018
/// Remote URL (passed by git as $2).
2119
pub url: Option<String>,
22-
/// Local ref to validate (e.g. refs/heads/refactor/my-change).
20+
/// Local ref being pushed (e.g. refs/heads/my-branch).
2321
#[arg(long)]
2422
pub local_ref: Option<String>,
2523
/// Local commit sha.
@@ -77,13 +75,6 @@ pub fn parse_ref_lines(input: &str) -> Vec<PushRef> {
7775
.collect()
7876
}
7977

80-
pub fn is_refactor_branch(ref_name: &str) -> bool {
81-
let stripped = ref_name.strip_prefix("refs/heads/").unwrap_or(ref_name);
82-
stripped.starts_with("refactor/")
83-
|| stripped.starts_with("deconvolute/")
84-
|| stripped.starts_with("deconv/")
85-
}
86-
8778
pub fn is_branch_deletion(local_ref: &str, local_sha: &str) -> bool {
8879
local_ref == "(delete)"
8980
|| local_sha == "0000000000000000000000000000000000000000"
@@ -132,25 +123,6 @@ fn check_budgets_gate(config_path: &Path, root_path: &Path) -> Result<(), String
132123
Ok(())
133124
}
134125

135-
fn check_refactor_cleanliness() -> Result<(), String> {
136-
let output = std::process::Command::new("git")
137-
.args(["status", "--porcelain"])
138-
.output()
139-
.map_err(|e| format!("Failed to run git status: {e}"))?;
140-
if !output.status.success() {
141-
return Ok(());
142-
}
143-
let stdout = String::from_utf8_lossy(&output.stdout);
144-
let tracked_changes = stdout.lines().any(|l| {
145-
let prefix = &l[..l.len().min(2)];
146-
prefix.starts_with('M') || prefix.starts_with('A') || prefix.starts_with('D')
147-
});
148-
if tracked_changes {
149-
println!("[lesscode-hook] Note: Working tree contains uncommitted changes.");
150-
}
151-
Ok(())
152-
}
153-
154126
fn check_ref_target(r: &PushRef, args: &PrePushArgs) -> Result<(), String> {
155127
if is_branch_deletion(&r.local_ref, &r.local_sha) {
156128
println!(
@@ -160,14 +132,6 @@ fn check_ref_target(r: &PushRef, args: &PrePushArgs) -> Result<(), String> {
160132
return Ok(());
161133
}
162134

163-
if is_refactor_branch(&r.local_ref) {
164-
println!(
165-
"[lesscode-hook] Detected major refactoring branch: {}",
166-
r.local_ref
167-
);
168-
check_refactor_cleanliness()?;
169-
}
170-
171135
if !args.skip_budgets {
172136
if let Some((cfg, src)) = locate_budgets(args.config.as_deref(), args.root.as_deref()) {
173137
check_budgets_gate(&cfg, &src)?;

‎native/tests/cli_deconvolute.rs‎

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn check(status: i32, level2_ops: i32) -> bool {
133133

134134
let out_dir = dir.join("mutants");
135135
let out_receipt = dir.join("mutate-receipt.json");
136-
let (status, _, _) = run_cli(&[
136+
let (status, _, stderr) = run_cli(&[
137137
"deconvolute",
138138
"mutate",
139139
"--lang",
@@ -148,6 +148,7 @@ pub fn check(status: i32, level2_ops: i32) -> bool {
148148

149149
assert_eq!(status.code(), Some(0));
150150
assert!(out_dir.exists());
151+
assert!(!stderr.contains("No mutation operator matched"), "{stderr}");
151152
let receipt: serde_json::Value =
152153
serde_json::from_str(&fs::read_to_string(&out_receipt).unwrap()).unwrap();
153154
assert_eq!(receipt["receipt"], "deconvolution-mutation-v1");
@@ -157,6 +158,133 @@ pub fn check(status: i32, level2_ops: i32) -> bool {
157158
let _ = fs::remove_dir_all(&dir);
158159
}
159160

161+
#[test]
162+
fn mutate_without_matching_operator_exits_1_with_receipt() {
163+
let dir = temp_dir("mutate-nomatch");
164+
let src = dir.join("plain.rs");
165+
fs::write(&src, "pub fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n").unwrap();
166+
167+
let out_dir = dir.join("mutants");
168+
let out_receipt = dir.join("mutate-receipt.json");
169+
let (status, stdout, stderr) = run_cli(&[
170+
"deconvolute",
171+
"mutate",
172+
"--lang",
173+
"rust",
174+
"--source",
175+
src.to_str().unwrap(),
176+
"--out-dir",
177+
out_dir.to_str().unwrap(),
178+
"--out",
179+
out_receipt.to_str().unwrap(),
180+
]);
181+
182+
assert_eq!(status.code(), Some(1), "{stderr}");
183+
assert!(stdout.is_empty(), "{stdout}");
184+
assert_eq!(stderr.lines().count(), 1, "{stderr}");
185+
assert!(stderr.contains("No mutation operator matched"), "{stderr}");
186+
assert!(stderr.contains(src.to_str().unwrap()), "{stderr}");
187+
let receipt: serde_json::Value =
188+
serde_json::from_str(&fs::read_to_string(&out_receipt).unwrap()).unwrap();
189+
assert_eq!(receipt["receipt"], "deconvolution-mutation-v1");
190+
assert_eq!(receipt["mutants_generated"], 0);
191+
assert_eq!(receipt["passed"], false);
192+
let written = fs::read_dir(&out_dir).map(|d| d.count()).unwrap_or(0);
193+
assert_eq!(written, 0);
194+
195+
let _ = fs::remove_dir_all(&dir);
196+
}
197+
198+
#[test]
199+
fn analyze_python_is_not_implemented_and_writes_no_receipt() {
200+
let dir = temp_dir("analyze-python");
201+
let src = dir.join("module.py");
202+
fs::write(&src, "def add(a, b):\n return a + b\n").unwrap();
203+
let out = dir.join("analysis.json");
204+
205+
for lang in ["python", "py"] {
206+
let base = ["deconvolute", "analyze", "--lang", lang, "--source"];
207+
let mut to_stdout = base.to_vec();
208+
to_stdout.push(src.to_str().unwrap());
209+
let mut to_file = to_stdout.clone();
210+
to_file.extend(["--out", out.to_str().unwrap()]);
211+
212+
for args in [to_stdout, to_file] {
213+
let (status, stdout, stderr) = run_cli(&args);
214+
assert_eq!(status.code(), Some(2), "{lang}: {stderr}");
215+
assert!(stdout.is_empty(), "{lang}: {stdout}");
216+
assert_eq!(stderr.lines().count(), 1, "{lang}: {stderr}");
217+
assert!(stderr.contains("not implemented"), "{lang}: {stderr}");
218+
assert!(!out.exists(), "{lang}: receipt was written");
219+
}
220+
}
221+
222+
let _ = fs::remove_dir_all(&dir);
223+
}
224+
225+
#[test]
226+
fn mutate_python_is_not_implemented_and_writes_nothing() {
227+
let dir = temp_dir("mutate-python");
228+
let src = dir.join("module.py");
229+
fs::write(
230+
&src,
231+
"def check(status):\n if status != 0:\n return False\n return True\n",
232+
)
233+
.unwrap();
234+
let out_dir = dir.join("mutants");
235+
let out_receipt = dir.join("mutate-receipt.json");
236+
237+
for lang in ["python", "py"] {
238+
let mut args = vec!["deconvolute", "mutate", "--lang", lang, "--source"];
239+
args.extend([
240+
src.to_str().unwrap(),
241+
"--out-dir",
242+
out_dir.to_str().unwrap(),
243+
]);
244+
let mut with_out = args.clone();
245+
with_out.extend(["--out", out_receipt.to_str().unwrap()]);
246+
247+
for args in [args, with_out] {
248+
let (status, stdout, stderr) = run_cli(&args);
249+
assert_eq!(status.code(), Some(2), "{lang}: {stderr}");
250+
assert!(stdout.is_empty(), "{lang}: {stdout}");
251+
assert_eq!(stderr.lines().count(), 1, "{lang}: {stderr}");
252+
assert!(stderr.contains("not implemented"), "{lang}: {stderr}");
253+
let entries: Vec<_> = fs::read_dir(&dir)
254+
.unwrap()
255+
.map(|e| e.unwrap().file_name())
256+
.collect();
257+
assert_eq!(entries, vec!["module.py"], "{lang}: files were written");
258+
}
259+
}
260+
261+
let _ = fs::remove_dir_all(&dir);
262+
}
263+
264+
#[test]
265+
fn analyze_java_and_typescript_still_print_receipts() {
266+
let adapters = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("adapters");
267+
for (lang, file) in [
268+
("java", "java/ProbeMain.java"),
269+
("typescript", "typescript/candidate_degradation.ts"),
270+
] {
271+
let src = adapters.join(file);
272+
let (status, stdout, stderr) = run_cli(&[
273+
"deconvolute",
274+
"analyze",
275+
"--lang",
276+
lang,
277+
"--source",
278+
src.to_str().unwrap(),
279+
]);
280+
assert_eq!(status.code(), Some(0), "{lang}: {stderr}");
281+
let receipt: serde_json::Value = serde_json::from_str(&stdout).unwrap();
282+
assert_eq!(receipt["receipt"], "deconvolution-analysis-v1");
283+
assert_eq!(receipt["lang"], lang);
284+
assert_eq!(receipt["passed"], true);
285+
}
286+
}
287+
160288
#[test]
161289
fn density_subcommand_evaluates_structural_reduction() {
162290
let dir = temp_dir("density-rust");

0 commit comments

Comments
 (0)