{"record":{"id":"443308c721f5956b","repo":"rtk-ai/rtk","slug":"listing-shorter-than-file2","errorCode":null,"errorMessage":"listing shorter than file2","messagePattern":"listing shorter than file2","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmds/git/diff_cmd.rs","lineNumber":7326,"sourceCode":"                            assert_eq!(a[l1 - 1], old, \"~ names file1 at {l1}\");\n                            rewritten[l1 - 1] = Some(new.to_string());\n                        }\n                    }\n                }\n                other => panic!(\"unexpected marker {other:?} in {line:?}\"),\n            }\n        }\n\n        let mut stream = a\n            .iter()\n            .enumerate()\n            .filter(|(i, _)| !removed[*i])\n            .map(|(i, l)| rewritten[i].clone().unwrap_or_else(|| (*l).to_string()));\n        let out: Vec<String> = fixed\n            .into_iter()\n            .map(|slot| {\n                slot.or_else(|| stream.next())\n                    .expect(\"listing shorter than file2\")\n            })\n            .collect();\n        assert!(stream.next().is_none(), \"listing longer than file2\");\n        out\n    }\n\n    #[test]\n    fn test_condensed_listing_reconstructs_the_second_file() {\n        // The pairing is by similarity and may cross; the render has to carry\n        // enough numbers that a reader rebuilding file2 gets file2. A\n        // small alphabet of similar lines makes crossings frequent, which a\n        // realistic corpus does not.\n        let mut seed = 0xc0ff_ee00_u64;\n        let mut crossed = 0usize;\n        for _ in 0..3_000 {\n            let n = (lcg(&mut seed) % 12) as usize;\n            let m = (lcg(&mut seed) % 12) as usize;\n            let mut make_lines = |k: usize| -> Vec<String> {","sourceCodeStart":7308,"sourceCodeEnd":7344,"githubUrl":"https://github.com/rtk-ai/rtk/blob/0924356b4caba4989607227b7c8824d3d8098719/src/cmds/git/diff_cmd.rs#L7308-L7344","documentation":"Test-helper panic in a rewrite-fixing harness: for each line of file2 not removed, the code takes a fixed slot or pulls the next line from the original listing; `.expect(\"listing shorter than file2\")` panics when the listing (e.g. cargo fix/npm audit fix suggestions) has fewer entries than the surviving lines of file2, and the following assert panics when it has more. It enforces a 1:1 correspondence between the rewritten file and the fix listing.","triggerScenarios":"Calling this helper with a `stream` (fix suggestion listing) whose line count differs from the count of non-removed lines in file2 — typically when the fixer outputs fewer or extra suggestions, or when removed-line filtering is miscounted.","commonSituations":"Tool output format changes (a fixer skips suggestions for some lines or emits combined suggestions), fixtures regenerated with a different tool version, or an off-by-one in the `removed` mask.","solutions":["Regenerate the test fixtures so the fix listing length matches the non-removed line count of file2.","Check the `removed` mask computation — an over- or under-count of removed lines desynchronizes the pairing.","If the real tool legitimately skips lines, change the helper to pad with `None` instead of panicking."],"exampleFix":"// before\nslot.or_else(|| stream.next())\n    .expect(\"listing shorter than file2\")\n// after\nslot.or_else(|| stream.next()).unwrap_or_else(|| {\n    panic!(\"listing shorter than file2: needed a line for slot {i}\")\n})","handlingStrategy":"validation","validationCode":"// before pairing, assert counts agree\nlet kept: Vec<_> = file2_lines.iter().enumerate().filter(|(i, _)| !removed[*i]).collect();\nassert_eq!(kept.len(), stream.len(), \"listing/file2 length mismatch\");","typeGuard":null,"tryCatchPattern":"slot.or_else(|| stream.next())\n    .unwrap_or_else(|| panic!(\"listing shorter than file2 at slot {i}\"));","preventionTips":["Assert listing length equals surviving-line count before zipping","Regenerate fixtures whenever the upstream fixer output format changes","Unit-test the removed-line mask computation independently"],"tags":["rust","test-helper","invariant"],"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"}