Skip to content

test: improve test coverage across formatters and core #813

Closed

Description

@planetf1

Improve unit/integration test coverage so that test/ stands on its own — without leaning on docs/examples/ as accidental test infrastructure.

Background in Discussion #811.

Why bother

HPC coverage from test/ alone (all backends, 1034 tests): 63.9% line, 51.8% branch. Several areas have near-zero test/ coverage and are only exercised by print-only examples or e2e suites behind GPU gates. Much of that code is deterministic parsing, validation, and serialisation — straightforward to unit test, no model required.

Once properly covered in test/, examples become what they should be: runnable docs, not load-bearing test infrastructure.

Coverage baseline (LSF/HPC run, 2026-04-10, most tests running)

Reasonably covered (>75%):

Area Stmts Miss Cov%
formatters/ (non-granite) 159 8 95.0
core/ 636 61 90.4
backends/adapters/ 95 13 86.3
plugins/ 651 92 85.9
telemetry/ 389 58 85.1
stdlib/sampling/ 567 90 84.1
stdlib/components/ 911 181 80.1
backends/ (core 5) 1415 286 79.8

Under-covered — pure logic, no backend needed:

Area Stmts Miss Cov% Notes
formatters/granite/ 2347 1128 51.9 Biggest gap by far. Deterministic string transforms, fully testable with fixtures.
stdlib/requirements/ 361 208 42.4 Pydantic models, validation logic
stdlib/components/unit_test_eval 71 71 0.0 Pure Pydantic + JSON, used by eval CLI
stdlib/frameworks/react.py 39 39 0.0 Partially testable with mock backend

Under-covered — backend-dependent (not worth pursuing):

Area Stmts Miss Cov% Notes
backends/vllm.py — — — Removed from codebase
backends/watsonx.py 241 203 15.8 Deprecated (use LiteLLM or OpenAI instead)
backends/bedrock.py 42 32 23.8 Gated behind credentials not available in CI

No point investing test effort in removed or deprecated code. Bedrock is small (42 stmts) but has testable pure logic (URI construction, ModelIdentifier matching, env var validation) — included in #816.

Excluded from coverage work: stdlib/requirements/safety/guardian.py (157 stmts, 0%) — deprecated in favour of Guardian Intrinsics. Not worth the investment.

Children

Area Issue Tests Status
Granite formatters (3.2, 3.3, intrinsics) #812 ~199 ✅ Closed
stdlib/requirements (tool_reqs, requirement, md) #814 ~28 ✅ Closed
helpers (openai_compatible_helpers, async_helpers) #815 ~24 ✅ Closed
Backend pure logic (cache, catalog, bedrock) #816 ~18 ✅ Closed
stdlib components (react, unit_test_eval) #817 ~21 ✅ Closed
Coverage wrap-up — remaining pure-logic gaps #860 ~300 ✅ Closed (PR #862 merged 2026-04-15)
CLI pure-logic helpers (decompose, eval) #861 37 ✅ Closed (PR #863 merged 2026-04-15)

Principles

  • Prioritise deterministic parsing, serialisation, and validation — high regression value, no model needed
  • Use canned data from existing testdata/ where available
  • All tests auto-receive unit marker, run in the default pytest invocation
  • Don't duplicate e2e/qualitative coverage — mocking risk is real, test behaviour not implementation details

Part of #726. Complements #729 (splitting existing e2e tests into lighter variants) — this issue covers gaps where no test existed at all. Progress tracking depends on #737 (coverage reporting) to give us ongoing visibility of where we stand.

Activity

  1. self-assigned this
    on Apr 10, 2026
  2. planetf1 commented on Apr 14, 2026

    @planetf1
    ContributorAuthor

    Coverage snapshot — 2026-04-14

    Reran unit/integration tests locally (same filter: not qualitative and not e2e and not ollama and not hf and not openai and not watsonx and not litellm and not slow) to measure progress since the baseline.

    Note: local runs exclude backend-gated tests so absolute figures are lower than the HPC baseline in the issue description (63.9%/51.8%). The delta is directly comparable since both runs use identical test selection.

    Overall

    Metric Baseline (315930f, 2026-04-10) Current (upstream/main, 2026-04-14) Delta
    Tests 858 1,202 +344
    Line coverage 47.8% 58.1% +10.3pp
    Branch coverage 34.0% 47.9% +13.8pp
    Lines covered 5,962 7,028 +1,066
    Lines missed 5,523 4,454 −1,069

    Gains by area

    Area 2026-04-10 2026-04-14 Delta Driver
    helpers/ 50.2% 94.9% +44.7pp #815
    formatters/granite/ 47.7% 76.4% +28.7pp #812 / #818
    stdlib/requirements/ 35.5% 54.7% +19.2pp #814
    stdlib/components/ 50.8% 62.0% +11.2pp #817
    backends/adapters/ 78.9% 81.1% +2.1pp #816
    core/ 77.4% 79.4% +2.0pp —
    plugins/ 85.9% 86.2% +0.3pp —
    backends/ (core 5) 30.1% 33.0% +2.9pp —

    Next steps — high-value pure-logic targets

    Files with meaningful statement counts, low coverage, and no backend dependency:

    File Stmts Miss Cov% Notes
    stdlib/functional.py 278 158 40.8% Biggest remaining pure-logic gap; function-calling orchestration — mockable backend, similar pattern to #817
    stdlib/components/genstub.py 237 147 31.7% Generative stub logic
    stdlib/session.py 196 121 33.7% Session management; portions testable with mock backend
    stdlib/sampling/majority_voting.py 86 58 25.9% Pure algorithm
    stdlib/sampling/budget_forcing.py + budget_forcing_alg.py 149 132 ~10% Pure sampling algorithm
    stdlib/components/simple.py 34 23 23.9% Small, deterministic
    stdlib/components/instruction.py 66 38 34.5% Deterministic
    stdlib/components/chat.py 76 41 39.4% Deterministic
    formatters/granite/base/util.py 140 114 14.9% String transforms — should be fully unit-testable
    telemetry/tracing.py 99 42 48.2% Partially mockable

    Probably skip

    Area Reason
    backends/ollama.py, huggingface.py, openai.py, litellm.py, watsonx.py Require live backend connections; CI-gated. Low ROI for unit tests.
    formatters/granite/retrievers/ (elasticsearch, embeddings, util — 190 stmts, 0%) Elasticsearch/embedding service dependencies; not pure logic
    stdlib/requirements/safety/guardian.py (157 stmts, 0%) Deprecated in favour of Guardian Intrinsics — already called out in issue
    backends/watsonx.py Deprecated (use LiteLLM or OpenAI compat) — already called out in issue
    stdlib/sampling/budget_forcing_alg.py 1.9% — likely exercised only via full inference loop; e2e-only
  3. planetf1 commented on Apr 15, 2026

    @planetf1
    ContributorAuthor

    Coverage snapshot — 2026-04-15

    Second wave of pure-logic tests on branch test/coverage-gaps-813 (#860). Same local filter as previous snapshot (not qualitative and not e2e and not ollama/hf/openai/watsonx/litellm/slow).

    Overall

    Metric Baseline (2026-04-10) First wave (2026-04-14) Current (2026-04-15) Delta from first wave
    Tests 858 1,202 1,448 +246
    Line coverage 47.8% 58.1% 61.8% +3.7pp
    Lines covered 5,962 7,028 7,407 +379
    Lines missed 5,523 4,454 4,075 −379

    Gains by area

    Area 2026-04-10 2026-04-14 2026-04-15 Delta Notes
    helpers/ 50.2% 94.9% 94.9% — Done
    formatters/granite/ 47.7% 76.4% 76.4% — Separate ongoing work
    stdlib/requirements/ 35.5% 54.7% 54.7% — Ceiling: guardian.py (157 stmts, deprecated) is the entire remaining gap
    stdlib/components/ 50.8% 62.0% 76.9% +14.9pp simple, instruction, chat, genstub, mobject
    stdlib/sampling/ — — 59.3% — majority_voting, sofai, repair; budget_forcing is Ollama-coupled
    backends/adapters/ 78.9% 81.1% 81.1% — Done
    backends/ (all) 30.1% 33.0% 38.3% +5.3pp openai/ollama pure helpers
    core/ 77.4% 79.4% 81.9% +2.5pp ImageBlock validation, ValidationResult, MOT._copy_from
    plugins/ 85.9% 86.2% 86.2% — Ceiling: cpex optional-dep registration
    telemetry/ — — 84.8% — _set_attribute_safe, set_span_error, end_backend_span

    Ceiling analysis

    Pure-logic coverage is now essentially maxed out. Remaining uncovered code in each area:

    • stdlib/requirements/ (54.7%): 157-stmt guardian.py (deprecated) is the entire gap. Without it: ~88%.
    • stdlib/components/ (76.9%): Remaining is SyncGenerativeStub.__call__() execution path (needs mock-backend) + model-gated intrinsics (guardian, rag).
    • stdlib/sampling/ (59.3%): budget_forcing (132 stmts) calls backend.generate_from_raw() directly. majority_voting.sample() is the async sampling loop.
    • plugins/ (86.2%): cpex optional-dependency registration — only runs when cpex installed.
    • telemetry/ (84.8%): OTel TracerProvider/BatchSpanProcessor bootstrap — only runs when OTEL configured.
    • backends/ (38.3%): Generate/stream/post-process paths all require live backend connections.

    Cumulative progress since 2026-04-10

    Metric Baseline Current Total delta
    Tests 858 1,448 +590
    Line coverage 47.8% 61.8% +14.0pp
    Lines covered 5,962 7,407 +1,445

    Remaining work

  4. planetf1 commented on Apr 15, 2026

    @planetf1
    ContributorAuthor

    Combined coverage snapshot — PRs #862, #863, #845

    Measured on a local branch combining all three open PRs (cherry-picked onto `upstream/main`). Filter: unit + integration tests, no live backends (same basis as the 47.8% baseline).

    Progression

    Point in time Tests Line coverage
    Baseline — before coverage work (2026-04-10) 858 47.8%
    After first wave (PR #862 base, 2026-04-14) 1,202 58.1%
    All three PRs combined 1,520 63.2%

    Total improvement: +15.4pp from the baseline.

    Previously under-covered areas

    Area Before After
    formatters/granite/ 51.9% 76.5%
    stdlib/requirements/ 42.4% 54.7%
    stdlib/components/unit_test_eval 0% 97.2%
    stdlib/frameworks/react.py 0% 100%
    cli/decompose/ unmeasured 64.3%
    cli/eval/ unmeasured 34.3%

    Caveat

    backends/ shows lower coverage locally (37%) than in the HPC baseline (79.8%) because live-backend tests are excluded from the local filter. The overall 63.2% figure is directly comparable to the 47.8% baseline — both use the same test scope. A full HPC run after merge will give the definitive combined figure.

  5. planetf1 commented on Apr 15, 2026

    @planetf1
    ContributorAuthor

    The 76.5% figure for `formatters/granite/` is likely to improve further in the next iteration. Issue #827 specifically tracks expanding the granite formatter tests with additional edge cases and alignment with the upstream granite-common test suite. That work is not included in the PRs above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions