{"record":{"id":"18bfc64ebd43c5db","repo":"rtk-ai/rtk","slug":"noise-not-raw","errorCode":null,"errorMessage":"noise, not raw","messagePattern":"noise, not raw","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/git/diff_cmd.rs","lineNumber":6646,"sourceCode":"        );\n        // A git binary section followed by another producer's header pair\n        // (two streams concatenated): the pair opens its own section\n        // rather than renaming the binary one and stealing its note.\n        let concat = \"diff --git a/x.bin b/x.bin\\nindex 1111111..2222222 100644\\nBinary files a/x.bin and b/x.bin differ\\n--- g1/m.txt\\t2026-01-01 00:00:00.000000000 +0000\\n+++ g2/m.txt\\t2026-01-01 00:00:00.000000000 +0000\\n@@ -1 +1 @@\\n-x\\n+y\\n\";\n        assert_eq!(\n            condense_unified_diff_strict(concat).as_deref(),\n            Some(\"[file] x.bin (binary)\\n[file] g2/m.txt (+1 -1)\\n-x\\n+y\")\n        );\n        assert_eq!(unquote_shell(\"$'caf\\\\351.txt'\"), \"$'caf\\\\351.txt'\");\n    }\n\n    #[test]\n    fn documented_bounds_hold() {\n        // The doc comment's \"noise, not loss\" bounds, executable.\n        // Rule 4: mbox prose quoting a whole well-formed header-plus-hunk\n        // block fabricates a phantom entry.\n        let phantom = \"From 0e7632a01b00c70cbc9dafcf1f23c71fa6b10de1 Mon Sep 17 00:00:00 2001\\nSubject: [PATCH] x\\n\\nThe old change was:\\n--- a/f\\n+++ b/f\\n@@ -1 +1 @@\\n-x\\n+y\\n---\\n g | 2 +-\\n 1 file changed, 1 insertion(+), 1 deletion(-)\\n\\ndiff --git a/g b/g\\n--- a/g\\n+++ b/g\\n@@ -1 +1 @@\\n-p\\n+q\\n-- \\n2.54.0\\n\";\n        let out = condense_unified_diff_strict(phantom).expect(\"noise, not raw\");\n        assert_eq!(out.matches(\"[file] \").count(), 2, \"got:\\n{out}\");\n        // Rule 7: a stale `--` in a malformed mbox stream is swallowed.\n        let stale = \"From 0e7632a01b00c70cbc9dafcf1f23c71fa6b10de1 Mon Sep 17 00:00:00 2001\\nSubject: [PATCH] x\\n\\n---\\n g | 2 +-\\n 1 file changed, 1 insertion(+), 1 deletion(-)\\n\\ndiff --git a/g b/g\\n--- a/g\\n+++ b/g\\n@@ -1 +1 @@\\n-p\\n+q\\n--\\n-- \\n2.54.0\\n\";\n        assert!(condense_unified_diff_strict(stale).is_some());\n        // Rule 8: prose imitating a diffstat line ends the exemption early,\n        // but format-patch's own `---` + diffstat right after is read as\n        // the stat separator, so the patch still condenses; a marked line\n        // between the two is lost content and falls back raw.\n        let fake_stat = \"From 0e7632a01b00c70cbc9dafcf1f23c71fa6b10de1 Mon Sep 17 00:00:00 2001\\nSubject: [PATCH] x\\n\\n rows | 3\\n---\\n g | 2 +-\\n 1 file changed, 1 insertion(+), 1 deletion(-)\\n\\ndiff --git a/g b/g\\n--- a/g\\n+++ b/g\\n@@ -1 +1 @@\\n-p\\n+q\\n-- \\n2.54.0\\n\";\n        let out = condense_unified_diff_strict(fake_stat).expect(\"noise, not raw\");\n        assert!(out.contains(\"[file] g (+1 -1)\"), \"got:\\n{out}\");\n        assert!(\n            condense_unified_diff_strict(&fake_stat.replace(\" rows | 3\\n\", \" rows | 3\\n-lost\\n\"))\n                .is_none()\n        );\n        // Rule 8: a bodyless `--no-stat` region whose prose wraps a short\n        // option to column 0 falls back raw.\n        let short = \"From aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa Mon Sep 17 00:00:00 2001\\nSubject: [PATCH 1/2] one\\n\\nPass\\n-p\\nto it.\\n-- \\n2.54.0\\n\\nFrom bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb Mon Sep 17 00:00:00 2001\\nSubject: [PATCH 2/2] two\\n\\ndiff --git a/y.txt b/y.txt\\n--- a/y.txt\\n+++ b/y.txt\\n@@ -1 +1 @@\\n-p\\n+q\\n-- \\n2.54.0\\n\";","sourceCodeStart":6628,"sourceCodeEnd":6664,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/git/diff_cmd.rs#L6628-L6664","documentation":"`.expect(\"noise, not raw\")` panic: `condense_unified_diff_strict()` returned None on a synthetic mbox-format-patch string used to test the documented \"noise, not loss\" bounds. Rule 4 under test: mbox prose that quotes a whole well-formed header-plus-hunk block (`--- a/f\\n+++ b/f\\n@@ ...`) inside the message fabricates one phantom `[file] f` entry, and the condenser must still parse (return Some) with exactly 2 `[file]` entries (f phantom + real g). None means the parser over-triggered its raw fallback on the quoted block.","triggerScenarios":"Calling `condense_unified_diff_strict()` on the inline `phantom` string (mbox `From ...` header, prose containing a fake `--- a/f / +++ b/f / @@ -1 +1 @@` block, then `---` diffstat and a real `diff --git a/g b/g` patch) returns None instead of Some with exactly 2 file entries.","commonSituations":"Pasting formatted patches (`git format-patch` mbox output) containing quoted example diffs into rtk; tightening raw-fallback heuristics until even documented-phantom cases stop parsing; changes to the mbox `From`/`--` boundary handling.","solutions":["Ensure the mbox `From ... Mon Sep 17` line always opens a message/prose region so in-prose header-shaped lines stay noise.","Verify the `---` + diffstat after the message is consumed as the stat separator, re-enabling patch mode for the real `diff --git` section.","Check the raw-fallback trigger only fires for unread column-0 lines after patch context begins, not inside the message region.","Update the fixture/string if the rule set changed and this scenario is no longer in-bounds."],"exampleFix":"// before\nif looks_like_header(line) && !in_patch { return None; } // prose header kills stream\n// after\nif looks_like_header(line) && !in_patch && !in_message_region { return None; }","handlingStrategy":"validation","validationCode":"let out = condense_unified_diff_strict(&mbox_with_quoted_diff);\nassert!(out.as_deref().map_or(false, |o| o.matches(\"[file] \").count() == 2), \"expected phantom + real entry\");","typeGuard":"fn condense_checked(diff: &str) -> Option<String> { crate::cmds::git::diff_cmd::condense_unified_diff_strict(diff) }","tryCatchPattern":"let out = condense_unified_diff_strict(input)\n    .unwrap_or_else(|| input.to_string()); // 'noise, not loss': raw fallback is always safe","preventionTips":["Constrain raw-fallback triggers to unread column-0 lines after patch context begins.","Open a message region on mbox `From` lines so quoted example diffs inside prose stay noise.","Keep the documented 'noise, not loss' bounds as executable tests (they are the spec).","When tightening heuristics, run documented_bounds_hold first — it encodes the intended trade-offs."],"tags":["rust","test-failure","diff-parsing","format-patch"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0924356b4caba4989607227b7c8824d3d8098719","analyzedAt":"2026-09-19T19:25:29.612Z","contentChangedAt":"2026-09-19T19:25:29.612Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}