Skip to content

refactor: schema-driven pred create (11K → 2.3K lines)#1008

Merged
GiggleLiu merged 13 commits intomainfrom
schema-driven-create
Apr 5, 2026
Merged

refactor: schema-driven pred create (11K → 2.3K lines)#1008
GiggleLiu merged 13 commits intomainfrom
schema-driven-create

Conversation

@GiggleLiu
Copy link
Copy Markdown
Contributor

Summary

  • Replace the 11,049-line create.rs with schema-driven generic dispatch using existing registry factory functions
  • New create.rs is 2,295 lines (79% reduction), split into 4 files totaling 8,820 lines
  • CLI creation now auto-maps ProblemSchemaEntry fields to CLI flags via snake_case → kebab-case convention
  • New models need only matching CLI flags + type parser support — no match arm in create.rs
  • All existing CLI flags preserved via #[arg(alias)] for backward compatibility
  • Updated add-model skill, review-structural skill, and CLAUDE.md to reflect new conventions

Architecture

ProblemSchemaEntry fields → flag_map() → parse_field_value() → JSON → factory() → DynProblem

File structure after refactor

File Lines Purpose
create.rs 2,295 Main dispatch, help, random, example paths
create/schema_support.rs 2,519 Type parsers, flag mapping, generic resolution
create/schema_semantics.rs 1,308 Per-problem validators, derived values
create/tests.rs 2,698 Schema-driven path tests

What's preserved

  • All pred create commands work identically
  • --random and --example paths unchanged
  • Old flag names work via aliases
  • Constructor/try_from validation still catches invalid input

Known trade-offs

  • Error messages are more generic (schema-driven vs hand-crafted usage strings)
  • Cross-field validation now happens at factory level (still fails, just later)

Test plan

  • cargo test -p problemreductions-cli passes
  • cargo clippy --workspace --all-targets -- -D warnings clean
  • make check passes
  • make cli-demo (exercises all commands end-to-end)
  • Manual smoke test: pred create MIS --graph 0-1,1-2, pred create SAT --num-vars 3 --clauses "1,2;-1,3", pred create BinPacking --sizes 3,3,2 --capacity 5

🤖 Generated with Claude Code

GiggleLiu and others added 12 commits April 5, 2026 11:19
Design for replacing the 11K-line create.rs with a schema-driven
generic dispatch using existing registry factory functions. Targets
~73% line reduction by eliminating the 5,400-line match statement.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix problem count (177 → 189)
- Expand type parser table from 16 to 52 types in 3 categories
- Add serde edge cases section (try_from, from, skip, custom BigUint)
- Add Appendix A with complete flag→field mismatch list
- Add generic resolution notes for W, W::Sum, Vec<Vec<W>>

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- add-model Step 4.5: replace "add match arm" with schema-driven instructions
- review-structural check 13: replace grep for problem name with schema field→flag verification
- CLAUDE.md Extension Points: document schema-driven create convention

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.17%. Comparing base (c57a131) to head (0701d41).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1008      +/-   ##
==========================================
+ Coverage   98.15%   98.17%   +0.01%     
==========================================
  Files         896      896              
  Lines       91150    91715     +565     
==========================================
+ Hits        89472    90039     +567     
+ Misses       1678     1676       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…force schema naming

- Remove 16 duplicate field checks in all_data_flags_empty()
- Remove backward-compat aliases ("sets", "query") from flag_map();
  schema-derived names ("subsets", "query-attribute") are canonical
- Map schema field "sets" → "subsets" in help_flag_name for consistency
- Add CLAUDE.md rule: CLI flag names must match schema field names

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@GiggleLiu GiggleLiu merged commit 22c4b05 into main Apr 5, 2026
5 checks passed
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