feat(filters): lua/luajit and luacheck filters, with an opt-in repeated-line collapse - #3480
Open
Hydr0gen19 wants to merge 2 commits into
Open
feat(filters): lua/luajit and luacheck filters, with an opt-in repeated-line collapse#3480Hydr0gen19 wants to merge 2 commits into
Hydr0gen19 wants to merge 2 commits into
Conversation
Lua test runners print the same line hundreds of times: 1866 lines of output where only 62 are unique. No stage of the TOML pipeline could collapse repeats, so there was no way to filter that without dropping content. Adds an opt-in collapse to the pipeline — global, at first occurrence, with the count rendered back in — and turns it on for lua, luajit, luac -p and luacheck. Off by default, so the other 63 filters are unchanged.
The issue reporter asked for it after running this branch against his own suite: he does not use luac -p, and a syntax check that prints nothing on success has nothing to collapse. luac stays on the passthrough path now, in every form. Also spells out in the filter docs what the tail exemption looks like when a trailing line repeats an earlier one: both are visible, only the first carries the count. He hit that on the real output and had to stop and check the count was not wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(filters): lua/luajit and luacheck filters, with an opt-in repeated-line collapse
Fixes #3467
Before anything else: this is a proposal, not a settled design
No maintainer has weighed in on #3467 yet, and #3054 already asks for a general lossless dedup filter (there, as a
rtk pipefilter forpython/conda run). This PR is one concrete shape for the primitive #3054 asks about, deliberately scoped to the Lua commands from #3467 so that nothing else in the project changes behaviour. If you would rather have it as artk pipe -ffilter, or as a Rust module, or with different semantics, I'm happy to rework it — the interesting part is the ~30 lines of primitive, not where it's wired in.What #3467 asks for
rtk discover --allranksluajit(1556 calls) andluacheck(598) as the reporter's top two unhandled commands. A passing Lua test run emits 1866 lines / 265 KB, of which 62 lines are distinct — the rest isprint()chatter from the code under test, repeated up to 802 times. There is nothing Lua-specific to parse here; the whole win is collapsing exact repeats.The issue author answered two design questions in the thread, and this PR follows those answers.
1. Shared primitive, but opt-in.
So
collapse_repeatsis a new optional field on the TOML filter DSL. It is disabled unless a filter sets it. None of the existing built-in filters set it, so none of them change behaviour — that is the main reason this is safe to land, and it's why the diff totoml_filter.rsis additive only.2. Global at first occurrence, not consecutive runs. Remeasured by the reporter:
Consecutive collapse buys 3.6% (the longest run in the whole file is 3 lines). Global collapse takes it to 62 lines / 14,096 bytes with the counts rendered back in. Note this differs from #3054, which asks for the consecutive variant — worth deciding which one the project wants before this lands.
Checked against the reporter's real output
The numbers above are his, measured with
awkbefore this PR existed. He has since run this branch against the same suite: 1866 lines → 65, with the two big repeaters at the top carrying their counts and theassertions, 0 failuressummary still the last thing on screen. 65 rather than 62 becausekeep_tail = 5re-emits the final lines verbatim.Two things came out of that run, both folded in here:
src/filters/README.mdnow spells it out.What changed
src/core/toml_filter.rs— new pipeline stage 6,collapse_repeats:Keeps the first occurrence of every distinct line, in order, and appends
(×N)to the ones that repeat:keep_taillines are exempt: emitted verbatim, and excluded from the counts. That is the issue's "keep the tail intact (test runners put the summary last)" — it matters when a runner's final line duplicates an earlier one (e.g. a per-testOKand a finalOK).(×24)on an invisible line is noise.strip_lines_matching/max_lines/ head-tail caps, so no non-duplicate line is ever dropped, pass or fail. The existingrun_fallbacktee hint on non-zero exit is untouched.src/filters/lua.toml— the filter that opts in.match_commandrequires an argument, so a bareluaREPL keeps the raw inherited-stdio passthrough path.An earlier revision of this PR also shipped a
luac -pfilter, because the issue's answer named that command. The reporter has since asked for it to be dropped — he does not actually run it, and a syntax check that prints nothing on success has nothing to collapse. It is gone, andluacin every form now stays on the passthrough path.src/filters/luacheck.toml— no collapse needed here:Checking <file> OKlines are all distinct. Plainstrip_lines_matchingdrops them and keeps every diagnostic plus theTotal: N warnings / M errors in K filesfooter, which already carries the file count the issue wanted summarised. A clean 89-file project goes from 75 lines to that one footer line. Nomax_linescap, so findings can't be truncated away.src/discover/rules.rs— rewrite patterns so the hook routes these commands (per the checklist insrc/cmds/README.md).Docs —
src/filters/README.md(field table, a section on when not to enable the collapse, and the tail note above),src/core/README.mdanddocs/contributing/TECHNICAL.md(8 → 9 stages).Testing
src/core/toml_filter.rs: off-unless-configured, global vs per-run counting, tail exemption, blank-line handling,Lossiness::None, a ≥60% savings assertion on repetitive output, and a routing test assertingluajit …→luaandluacheck .→luacheck, while bareluaand bothluacforms match nothing.test_builtin_filter_countupdated 63 → 65.Every one of those tests fails on
developand passes here.Ran in a
rust:1container: 2585 unit tests pass. One pre-existing integration test,copilot_selfheal_test::unwritable_hooks_dir_never_breaks_the_hook, fails there both before and after this change — it makes a directory unwritable, which is a no-op as root in a container. Unrelated to this PR.What I verified myself, as opposed to what the reporter measured on his suite: the ≥60% assertion in
collapse_repeats_saves_tokens_on_repetitive_outputruns the real pipeline over 900 lines of repetitive chatter and checks the trailing summary is still last.Open questions for maintainers
Lossiness::Nonefor the collapse, so no tee hint is written. Every distinct line survives, so nothing is hidden — but strictly speaking the interleaving order of repeats is not recoverable. If you'd rather be conservative, flipping it toLossiness::Wholeis a one-line change; the cost is a tee file written on every run.(×N)marker. The Design Philosophy says not to invent output formats. The pipeline already emits... (N lines omitted), and the issue asked for this exact spelling, so I kept it. ASCII(xN)(as Capture savings on python/conda output: hook routing for wrapper commands + a lossless dedup filter #3054 spells it) is a one-line change if you prefer it.rtk pipededup filter is the shape you want, this primitive should probably move there and the Lua filters become callers.