Skip to content

[Task]: remove duplicated helpers, stop shipping the conformance harness, slim the test suite (over-engineering audit) #779

Open

Description

@sumithr

Priority / sequencing

P2 / priority: later

Suggested labels

  • documentation
  • ux
  • compatibility
  • distribution

Roadmap fields

Status: Backlog; Priority: P2; Size: XL; Order: (unset); Depends on: (none)

Problem

A repo-wide over-engineering audit (grep-verified) found about 1,000 lines of removable excess in src/ and scripts/, plus test-suite excess in tests/:

  1. Copy-pasted helpers. The same logic is hand-written 2 to 5 times across modules, so a fix in one copy silently misses the others.
  2. A test harness shipping in the wheel. src/sumo_qa/conformance.py (~761 lines) is a test and eval harness. Only tests/ imports it.
  3. An over-grown test suite. tests/ has 4,746 collected tests, but line coverage of src/ needs only 641 of them. Per-item parametrize fan-outs, copy-pasted helpers and per-test subprocess/git setup inflate both the count and the maintenance cost (Scope D).

Expected outcome

  • Every duplicated helper listed in Scope exists once and every former copy calls it.
  • conformance.py lives under tests/ and is absent from the built wheel.
  • Public MCP tool names, docstrings, schemas and CLI behaviour are unchanged.
  • The test suite keeps every check it has today with far fewer collected tests and lines, and shared test helpers live once in tests/conftest.py.

Scope

0. Refresh the audit first (before any edit)

  • Re-run the ponytail over-engineering audit (/ponytail-audit) on current main, covering src/, scripts/, tests/evals/ and tests/. This issue may sit in the backlog for a while, so the list below is a snapshot of main at ec7db3b. Grep-verify each item in Scopes B, C and D against current main: tick and annotate an item that is already gone, and drop one that no longer applies. Add every new finding to Scope B, C or D. Post the refreshed list as a comment on this issue before implementing. Ad-hoc ponytail reviews are not run while this issue is open, so this audit is where anything that landed since ec7db3b gets caught.

A. Decisions (recorded)

B. Collapse duplicates (largest first)

  • JSON-RPC initialize / tools/list handshake written 4 times: installer.py:1301, doctor.py:227, scripts/uvx_smoke_handshake.py:54, scripts/regen_tools_list_snapshot.py:48. One helper in src/sumo_qa/. Callers classify the result.
  • Load-envelope boilerplate (error class, _classify if-chain, schema_version pre-check, loc join) in ledger_validation.py, export_validation.py, context_bundle_validation.py, scorecard_validation.py, gate_evidence_validation.py, coverage_models.py. One load_envelope(data, model, version, err_cls) plus a dict lookup for the error kind. Keep each public *ValidationError name and its kind values.
  • Per-host setup/uninstall pairs in installer.py:855-1020 share one shape. Drive them from a (name, path_fn, container_key) table.
  • Markdown cell escaper copied 4 times and table builder 3 times across ledger_format.py, export_format.py, scorecard_format.py, context_bundle_format.py. One md_cell() and one md_table().
  • JetBrains IDE-dir detection (jb_root OS branch) at installer.py:972, installer.py:1138, doctor.py:1002. One _jetbrains_ide_dirs(home, system).
  • Claude Code config_dir resolution duplicated in installer._setup_claude_code, installer._uninstall_claude_code, doctor._claude_code_config_path.
  • Heading scanner, fence/heading regexes, _dedupe, slugify duplicated between skill_manifest.py:67-134 and knowledge_loaders.py:175-235. Also _approx_tokens and _FRONTMATTER_RE duplicated in skill_prompts.py / skill_manifest.py.
  • Four pass-through knowledge-loader tools in server.py:914-995. Register from a table (names and docstrings unchanged).
  • "Read config, warn unreadable, parse, warn malformed" repeated in repo_map_resolvers/{rust,php,typescript,csharp}.py. One ScanContext.read_parsed() in base.py.
  • Dot-segment join loop copied in cpp.py:154, typescript.py:354, ruby.py:188. Use posixpath.normpath(posixpath.join(...)) plus a .. check, as csharp/php already do. Replace the 8 rsplit("/", 1)[0] if "/" in x else "" sites with posixpath.dirname.
  • Path-resolution ladder hand-rolled in knowledge_loaders._standards_dir / _rules_path. One _first_existing(candidates).
  • git rev-parse --show-toplevel block x3 (repo_map_scanner.py:298, :619, repo_map_impact.py:188) and _git_env x2. One helper each.

C. Small deletions

  • LanguageConfig.extensions is never read. Drop the field and every extensions=(...). Drop explicit barrels=() that repeats the default.
  • PreparableResolver Protocol (repo_map_resolvers/base.py:198) exists for one isinstance check. Use getattr(resolver, "prepare", None).
  • TestDataValidator Protocol (tdm_validation.py:17) has one implementation. Annotate with MockValidator.
  • Dead _NON_SLUG_RE at knowledge_loaders.py:175.
  • Single-use wrappers: typescript._is_out_of_repo_target, skill_manifest._public_section / _public_module (identical).
  • tests/evals/promptfoo/recall.py (from the PR test(evals): add a review-recall corpus of real past misses and a recall reporter #770 ponytail review, about -6 lines; outside the src/ + scripts/ line count): _case returns (identity, caught) instead of a 5-tuple that repeats the identity fields; the controls counter uses _bucket() like every other bucket; the per-run identities / source bookkeeping moves to a list beside file_runs, so summarise no longer deletes keys before returning. tests/test_eval_recall_report.py stays green unchanged, and recall.py output on a real recall report is identical before and after.

D. Test suite (tests/, excluding tests/evals/): from the 2026-10-01 audit of 7abc919

The suite has 4,746 collected tests from 2,791 test functions. Line coverage of src/ needs only 641 of them. The audit estimate is about -1,140 tests and -3,800 lines. Every change keeps the same checks: a merged fan-out must still fail on every offender and name each one.

  • Merge per-item fan-outs into one test that collects offenders and asserts the list is empty (about -950 tests):
    • test_mutmut_subprocess_exclusions.py:158: 150 copies, one per test file. Also hoist its two tomllib parses.
    • test_eval_runner_defaults.py:96-122: candidate / judge / no-openai checks, 65 copies each. Parse each config once.
    • test_review_skill_modules.py: the load-bearing rule check (95 copies, :856) plus the per-module and per-pinned-marker families (:814, :868, :877, :955, :1096, :1126, :1194). Cache _all_skill_text(), which is re-read on every call.
    • test_skill_conformance.py: the structure checks (:24-90, 126 items), the host-phrase denylists (:98-125, 126 items) and the contract-doc check (:128-157).
    • test_repo_map_resolver_scanner_contract.py:96-133: 62 items.
    • Also the smaller fan-outs: test_eval_recall_corpus.py:99-160, test_check_no_em_dashes.py:174-186 (also drop its git ls-files at collection time), test_skill_md_token_budget.py:111-123, test_skill_md_description_vs_body.py:172-181, test_skill_modules.py:131-140 and :242-265, test_skill_triggering.py:36-186 (also reuse one server instead of rebuilding it per row).
  • Widen fixture scope for expensive setup (the part that saves time):
    • test_session_start_hook.py: one module-scoped hook run per env variant, and fold the tests that read the same payload. About -20s.
    • Real git repos per test in test_report_builder.py (18 callers), test_repo_map_scanner.py (10), test_check_mutation_gate.py:673 (8): copy a session-scoped template repo.
    • Node assert harness spawned per row in the four test_eval_*_assert.py files: batch each table through one _grade call.
    • MCP server subprocess per test in test_e2e_mcp_initialize.py:111-166 and test_tools_list_contract.py: once per module.
    • test_repo_map_resolvers_java.py:46-94: replace the interpreter spawn with an in-process sys.modules check.
  • Fold near-duplicate tests into tables:
    • test_doctor.py: per-host config checks, run_mcp_probe error shapes, registry variants, colour and exit-code renderer tests.
    • test_claude_hooks.py: slug-prior resolution (:1166-1700) and path validation (:455-655).
    • Pure-resolve cases in test_repo_map_resolvers_{rust,ruby,go,typescript,php,python,java,cpp}.py, and the 8 *_resolver_is_registered tests (covered by the scanner contract).
    • test_cli.py human/--json/missing-repo clusters; test_installer_idempotency.py; test_claude_cli_provider.py:74-312 tables; test_server_schemas.py per-model rejects_unknown_field; per-tool metadata trio in test_server_*_tool.py; test_report_html.py:82-120; test_knowledge_loaders_entries.py:161-186, :286-307, :357-430; test_eval_mirror_gate_assert.py:104-380; test_toolchain_pin_lockstep.py:380-660 with test_treesitter_pins.py.
  • One shared tests/conftest.py (none exists today) replacing the copies: _repo_root() (8), git-repo setup (about 6), _FakeStream/_FakeProc/_ok Popen fakes (4 files), _needs_ts skip marker (13), _write file helper (6), the node assert harness (4), a shared server fixture.
  • Delete tautology and dead tests:
    • test_installer_uses_plugin_metadata.py:19-49 (greps installer source).
    • test_bin_wrapper.py (prose greps).
    • test_doctor.py hasattr/dataclass/version meta-tests (:116-150, :1046-1049) and test_doctor_module_form_help_is_path_independent.
    • test_token_weight_regression.py:112-130 (permanent xfail) and the subsumed loop at :189-265.
    • test_error_envelope.py:48-86: drop the duplicate hint test and tighten the always-true or assert.
    • Five weak loader tests in test_knowledge_loaders.py:273-352 subsumed by test_knowledge_loaders_strengthening.py.
    • test_report_builder.py:522 (duplicates the HTML tracker-leak guard).
    • TestNpmScripts in test_eval_runner_defaults.py:129-150, and the per-config wiring greps in the three test_eval_*_assert.py files.
  • Mutation-gated modules need care. Tests that kill mutants in tdm_validation, report_builder and knowledge_loaders may only move or merge if the mutation gate stays at no new survivors. Do not delete test_tdm_validation_strengthening.py wholesale. Replace the encoding/indent spy tests in test_report_builder.py:1179, :1198, :1245 with # pragma: no mutate only if the mutation-survivor triage classes those mutants as equivalent.

Acceptance criteria

  • A refreshed audit of current main is posted on this issue before implementation, and Scopes B, C and D match it (stale items removed, new findings added).
  • conformance.py is under tests/, all its importers are updated, and it is absent from the built wheel.
  • analysis/ and gate_evidence_* keep their public API. They change only to adopt shared helpers from Scope B.
  • Each Scope B item: git grep shows one definition and no remaining copy.
  • Each Scope C item is removed, or the PR states why it was kept.
  • No public MCP tool name, schema or docstring changes. The tools/list snapshot test passes unchanged.
  • Mutation gate holds on every touched file (no new survivors).
  • Net line count in src/ + scripts/ goes down. The PR states the before/after wc -l.
  • Each Scope D item is done, or the PR states why it was kept. The PR states before/after collected-test count, tests/ line count and local full-suite time.
  • The 100% coverage gate still passes, and a merged fan-out still fails on a seeded offender and names it.

Test plan

  • uv run pytest (full suite) green.
  • uv run mutmut run on the touched modules, with the mutation gate passing.
  • Install smoke: python -m sumo_qa.installer --skip-mcp-install in a scratch workspace plus sumo-qa doctor, to confirm the shared handshake and host-table refactors behave the same.
  • Build the wheel and confirm conformance.py is absent from it.
  • For each merged fan-out, seed one offender locally and confirm the merged test fails and names it.
  • uv run pytest --collect-only -q | tail -1 and the full-suite time, before and after.

Context

Activity

  1. added
    enhancement
    priority: later
    on Oct 1, 2026
  2. changed the title [-][Task]: remove duplicated helpers and decide the fate of unwired subsystems (over-engineering audit)[/-] [+][Task]: remove duplicated helpers and stop shipping the conformance harness (over-engineering audit)[/+] on Oct 1, 2026
  3. changed the title [-][Task]: remove duplicated helpers and stop shipping the conformance harness (over-engineering audit)[/-] [+][Task]: remove duplicated helpers, stop shipping the conformance harness, slim the test suite (over-engineering audit)[/+] on Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-taskenhancementpriority: latertooling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions