Skip to content

Commit 32a3d36

Browse files
joshwilhelmiclaude
andcommitted
[gobby-cli-#121] fix(gsqz): Suppress outer compression header for */no-op strategy
Follow-up to #111. The inner [gsqz:low-savings] marker is suppressed when adding it would grow output, but the outer "[Output compressed by gsqz -- STRATEGY, X% reduction]" header was still being prepended for the resulting */no-op strategy. That's noise -- no compression actually happened, so the header is just spurious. Adds CompressionResult::is_passthrough() classifying passthrough, excluded, and */no-op together. main.rs now uses it for both the outer-header decision and the daemon savings report so the two stay in sync. Adds a unit test for the classification and asserts the existing low-savings-suppressed test result also reports as passthrough. Rolls into the unreleased 0.4.1 -- no version bump. Tests: 149 in gsqz (+1 new), 268 across the workspace, all passing. Verified end-to-end: the compound-git command that previously emitted "git-mutation/low-savings, -1% reduction" now emits clean original output (strategy=git-mutation/no-op, savings=0.0%, no header). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 96e80c1 commit 32a3d36

4 files changed

Lines changed: 41 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3434
#### gsqz
3535

3636
- **Low-savings marker** — Suppress `[gsqz:low-savings]` marker when prepending it would grow the output beyond the original. The marker now only annotates when the annotation itself doesn't make things worse. (#111)
37+
- **Outer compression header for `/no-op` strategy** — When the low-savings marker is suppressed (above), the resulting `{pipeline}/no-op` strategy now also skips the outer `[Output compressed by gsqz — …, 0% reduction]` header and the daemon savings report. The user sees the original output verbatim. `CompressionResult::is_passthrough()` classifies `passthrough`, `excluded`, and `*/no-op` together so both call sites stay in sync. (#121)
3738

3839
## [0.1.0] — gobby-hooks
3940

crates/gsqz/src/compressor.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ impl CompressionResult {
1818
}
1919
(1.0 - self.compressed_chars as f64 / self.original_chars as f64) * 100.0
2020
}
21+
22+
/// True when no useful compression occurred — original output should be
23+
/// surfaced verbatim, with no `[Output compressed by gsqz — …]` header
24+
/// and no daemon savings report. Covers:
25+
/// - `passthrough` — output too short or fallback couldn't help.
26+
/// - `excluded` — command matched an exclusion regex.
27+
/// - `*/no-op` — a pipeline matched but adding the low-savings marker
28+
/// would itself have grown the output, so we kept the original.
29+
pub fn is_passthrough(&self) -> bool {
30+
self.strategy_name == "passthrough"
31+
|| self.strategy_name == "excluded"
32+
|| self.strategy_name.ends_with("/no-op")
33+
}
2134
}
2235

2336
struct CompiledPipeline {
@@ -479,6 +492,28 @@ mod tests {
479492
assert!(!result.compressed.contains("[gsqz:low-savings]"));
480493
assert_eq!(result.compressed, output);
481494
assert_eq!(result.compressed_chars, result.original_chars);
495+
// /no-op is a passthrough — main.rs uses this to skip the outer header.
496+
assert!(result.is_passthrough());
497+
}
498+
499+
#[test]
500+
fn test_is_passthrough_classification() {
501+
let mk = |name: &str| CompressionResult {
502+
compressed: String::new(),
503+
original_chars: 0,
504+
compressed_chars: 0,
505+
strategy_name: name.into(),
506+
};
507+
// Pure passthrough cases — main.rs surfaces output verbatim.
508+
assert!(mk("passthrough").is_passthrough());
509+
assert!(mk("excluded").is_passthrough());
510+
assert!(mk("git-mutation/no-op").is_passthrough());
511+
assert!(mk("cargo-test/no-op").is_passthrough());
512+
// Real compression — main.rs prepends the header and reports to daemon.
513+
assert!(!mk("git-status").is_passthrough());
514+
assert!(!mk("cargo-test/low-savings").is_passthrough());
515+
assert!(!mk("pytest/on_empty").is_passthrough());
516+
assert!(!mk("fallback").is_passthrough());
482517
}
483518

484519
#[test]

crates/gsqz/src/main.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ fn run_output_mode(cmd: &str, config: &Config, stats: bool) {
238238
}
239239

240240
// Report savings to daemon (best-effort)
241-
if result.strategy_name != "passthrough"
242-
&& result.strategy_name != "excluded"
241+
if !result.is_passthrough()
243242
&& let Some(ref url) = daemon_url
244243
{
245244
daemon::report_savings(
@@ -250,16 +249,15 @@ fn run_output_mode(cmd: &str, config: &Config, stats: bool) {
250249
);
251250
}
252251

253-
let output_str = if result.strategy_name != "passthrough" && result.strategy_name != "excluded"
254-
{
252+
let output_str = if result.is_passthrough() {
253+
result.compressed
254+
} else {
255255
format!(
256256
"[Output compressed by gsqz — {}, {:.0}% reduction]\n{}",
257257
result.strategy_name,
258258
result.savings_pct(),
259259
result.compressed
260260
)
261-
} else {
262-
result.compressed
263261
};
264262

265263
print!("{}", output_str);

docs/guides/gsqz-user-guide.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ The `--stats` flag prints to stderr:
288288
Strategy names to look for:
289289
- A pipeline name (e.g. `git-status`, `pytest`, `cargo-test`) — matched and compressed
290290
- `{name}/low-savings` — pipeline matched but compression was marginal (<5%)
291+
- `{name}/no-op` — pipeline matched but adding the low-savings marker would have grown the output, so the original is surfaced verbatim (no header, no daemon report)
291292
- `{name}/on_empty` — pipeline produced empty output, on_empty fallback used
292293
- `fallback` — no pipeline matched, generic truncation applied (with `[gsqz:passthrough]` marker)
293294
- `passthrough` — output was too short or compression didn't help

0 commit comments

Comments
 (0)