Skip to content

refactor: split the longest functions, and test reusing scores under --skip - #217

Merged
tamada merged 11 commits into
mainfrom
refactor/stats-to-markdown
Oct 22, 2026
Merged

tamada merged 11 commits into
mainfrom
refactor/stats-to-markdown

Conversation

@tamada

@tamada tamada commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Splits the longest functions in the CLI so that each is about 50 lines or fewer, removes the duplicated code the splitting turned up, and adds tests for a path no test reached. Behaviour does not change.

This is based on #215 and targets its branch, because both touch perform_run. Once #215 is merged, GitHub retargets this to main.

Functions split

function before after
to_markdown (cli/stats.rs) 143 17
Roots::resolve (cli/mcp/paths.rs) 109 7
oinkie_review (cli/mcp/server.rs) 95 31
perform_lift (cli/main.rs) 83 39
load_comparison (cli/review.rs) 82 50
perform_run (cli/main.rs) 78 46
read_result_file (cli/main.rs) 77 24
run (cli/mcp/analysis.rs) 54 33
extract_birthmark_op (src/extract.rs) 54 48
  • to_markdown has one function per section of the report.
  • Roots::resolve reads as its steps: refuse .., make the path absolute, find the deepest part that exists, append the rest, check it against the roots.
  • The other functions have their steps moved out the same way.

Duplication removed

  • Comparing a pair and storing its CSV, and reusing the CSV an earlier run left, were written out in both perform_run and compare_impl. Both now call compare_and_store and reuse_result.
  • oinkie_review built its scores with a copy of analysis::scores. It now calls analysis::scores.
  • Removing inputs given more than once was written out in both extract_all and the MCP run. Both now call unique_inputs.
  • CompareResult::new takes impl Into<PathBuf>, so callers pass a birthmark's path as it is.

Fixes and tests

  • oinkie_review's tool description read "a directory of pair CSVs similarity CSVs". It now says what those CSVs hold and which tools wrote them.
  • No test reached --skip reusing a pair's score, from either run or compare. Two CLI tests plant a score no comparison gives in a pair's CSV and require the second run with --skip to report it. Both fail when the reuse is disabled.

Checked

  • to_markdown: the report from oinkie stats -f markdown, with and without --per-file --top 3, over a directory that produces every section, is identical byte for byte before and after.
  • resolve: its answers to six paths, the refusal messages included, are identical before and after.
  • cargo test --features mcp (413 tests) and clippy with -D warnings pass locally, and every commit builds on its own.

🤖 Generated with Claude Code

tamada and others added 11 commits October 22, 2026 15:47
to_markdown was 143 lines. Each section -- the introduction, functions per
file, elements per function, the top elements of a group, the per-file table
and the skipped files -- is now its own function, and to_markdown puts them
in order. The output is unchanged byte for byte.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
resolve was 109 lines. It now refuses `..`, makes the path absolute, finds
the deepest part that exists, appends the rest and checks the result against
the roots, each in a function of its own. The refusals that name the roots
are made in one place. Every answer, refusals included, is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
oinkie_review was 95 lines. Parsing the aggregator and min_elements, the
review itself and the confinement of the birthmarks the score CSVs name are
now functions of their own, and the scores are made by analysis::scores,
which the other tools already used, rather than by a copy of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each was around 80 lines. run's extraction, reading a pair's CSV and parsing
its result line, and building the lifter, lifting one file and running the
lifts in jobs are now functions of their own. Comparing a pair and storing
its CSV, and reusing the CSV an earlier run left, were written out in both
perform_run and compare_impl; both now call compare_and_store and
reuse_result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
load_comparison was 82 lines. Reading a matrix line's column names and a
row's values, and checking that the values fill the matrix, are now
functions of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It read "a directory of pair CSVs similarity CSVs". It now says what those
CSVs are and which tools wrote them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…icate inputs

run was 54 lines. Extracting each input once, into the destination or into
memory, is now extract_inputs. Removing the inputs given more than once was
written out in both extract_all and run; both now call unique_inputs. The
pair's birthmark paths go to CompareResult::new as they are, since it takes
anything that converts into a PathBuf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A score no comparison gives is planted in a pair's CSV, and the second run
with --skip must report it. Neither path was reached by any test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ark_op

Importing the variants inside the function lets each match arm and condition
fit on one line.
Base automatically changed from feat/extractor-new-into to main October 22, 2026 08:29
@tamada tamada self-assigned this Oct 22, 2026
@tamada tamada added this to the v0.9.0 milestone Oct 22, 2026
@sonarqubecloud

Copy link
Copy Markdown

@tamada
tamada merged commit dcabe47 into main Oct 22, 2026
8 checks passed
@tamada
tamada deleted the refactor/stats-to-markdown branch October 22, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant