{"record":{"id":"ea21a1ebaaab88f4","repo":"rtk-ai/rtk","slug":"f-txt-entry","errorCode":null,"errorMessage":"f.txt entry","messagePattern":"f\\.txt entry","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cmds/git/diff_cmd.rs","lineNumber":6760,"sourceCode":"        let with_fact = format!(\"{fixture}Seulement dans b: h.txt\\n\");\n        assert!(condense_unified_diff_strict(&with_fact).is_none());\n    }\n\n    #[test]\n    fn no_newline_marker_stays_attached_to_the_line_it_describes() {\n        // Real `git diff` of two files: `f.txt` changes its first line while\n        // its unchanged last line lacks a newline (marker after a context\n        // line), and `g.txt` gains a trailing newline (marker after `-y`).\n        // The first marker used to land under `+A` and claim the ADDED line\n        // had no newline; it must be dropped. The second is the witness of\n        // a newline-only change and must stay right under `-y`.\n        let fixture = include_str!(\"../../../tests/fixtures/diff/git_diff_no_newline_raw.txt\");\n        let out = condense_unified_diff_strict(fixture).expect(\"must parse\");\n        let lines: Vec<&str> = out.lines().collect();\n        let f = lines\n            .iter()\n            .position(|l| *l == \"[file] f.txt (+1 -1)\")\n            .expect(\"f.txt entry\");\n        assert_eq!(&lines[f..f + 3], &[\"[file] f.txt (+1 -1)\", \"-a\", \"+A\"]);\n        assert!(\n            lines[f + 3].starts_with(\"[file] g.txt\"),\n            \"marker after a context line leaked under +A:\\n{out}\"\n        );\n        let g = f + 3;\n        assert_eq!(\n            &lines[g..g + 4],\n            &[\n                \"[file] g.txt (+1 -1)\",\n                \"-y\",\n                \"\\\\ No newline at end of file\",\n                \"+y\"\n            ]\n        );\n    }\n\n    #[test]","sourceCodeStart":6742,"sourceCodeEnd":6778,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/git/diff_cmd.rs#L6742-L6778","documentation":"This is a Rust test panic: `.expect(\"f.txt entry\")` on `Iterator::position` aborts because the condensed diff output did not contain the line `[file] f.txt (+1 -1)`. The test asserts that a context line followed by `-a`/`+A` is grouped under the f.txt file header; when the filter's grouping changes (header format, ordering, or marker handling), the probe line is missing and `expect` panics. It is thrown by the library's own test suite, not at runtime by end users.","triggerScenarios":"Running `cargo test` for the strict unified-diff tests on fixture tests/fixtures/diff/git_diff_no_newline_raw.txt when `condense_unified_diff_strict` emits a different file header string, omits the f.txt entry, or reorders output so no line equals the exact probe string.","commonSituations":"A developer refactors the diff file-header formatting (e.g. changes `[file] name (+N -N)` wording), alters how no-newline-at-EOF markers are attached, or changes line grouping so context lines attach to a different file block — snapshot expectations silently break.","solutions":["Run `rtk git diff` or the filter on the fixture manually and compare the emitted headers against the expected `[file] f.txt (+1 -1)` string.","Update the test probe to the new header format if the format change was intentional, and refresh related snapshot files with `INSTA_UPDATE=always cargo test`.","If the header should be unchanged, fix the regression in `condense_unified_diff_strict` (check marker/context-line grouping logic) and re-run the test."],"exampleFix":"// before\n.expect(\"f.txt entry\");\n// after\nlet f = lines.iter().position(|l| *l == \"[file] f.txt (+1 -1)\")\n    .unwrap_or_else(|| panic!(\"f.txt header missing from output:\\n{out}\"));","handlingStrategy":"validation","validationCode":"// assert the header format before snapshot-sensitive tests\nlet sample = condense_unified_diff_strict(FIXTURE).unwrap();\nassert!(sample.contains(\"[file] \"), \"header format changed: {sample}\");","typeGuard":"fn find_line<'a>(lines: &[&'a str], probe: &str) -> Option<usize> {\n    lines.iter().position(|l| *l == probe)\n}","tryCatchPattern":"// Rust tests panic, not catch: use Results and unwrap_or_else with context\nlet f = find_line(&lines, \"[file] f.txt (+1 -1)\")\n    .unwrap_or_else(|| panic!(\"header missing:\\n{out}\"));","preventionTips":["Use insta snapshot tests for diff header formats so format changes are explicit diffs, not string probes","Keep the header format string in one shared constant used by both filter and tests","Include the actual output in every panic message"],"tags":["rust","test-assertion","git-diff"],"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"}