test(kv): cover the KV credential seam — kv_config + credentials (→100%) - #77
test(kv): cover the KV credential seam — kv_config + credentials (→100%)#77seonghobae wants to merge 7 commits into
Conversation
`kv_config.py` is the KV seam the cost/routing hub and `credentials.py` read config and provider secrets through (never `os.getenv` at runtime), but its own surface was only exercised incidentally by other suites — line coverage sat at 49%, leaving the secret sub-surface and the pg_llm_batch adapter untested. Add a focused `tests/test_kv_config.py` (13 tests, dependency-free — small fakes stand in for the pg_llm_batch config/secret stores) pinning the full contract: - InMemoryConfigStore: seed loading, get/set roundtrip + default, get_category returns a non-aliasing copy, show_config sorted ordering, and the set_secret/get_secret/require_secret surface (incl. secrets staying out of show_config and require_secret raising KeyError when absent). - PostgresConfigStoreAdapter: get/set delegation, and get_secret/require_secret behavior with and without a backing secret store (default vs. KeyError, and swallowing a backing-store error to the default). - get_config_store: the no-DSN in-memory selection path, seeded and unseeded. kv_config.py line coverage 49% -> 100% (the pg_llm_batch-present branch remains `# pragma: no cover`, as before). Full suite: 313 passed (was 300). Test-only; no production behavior changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T47gHdkeM8H2Mpu4VwZT3c
|
Warning Review limit reached
Next review available in: 10 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
Comment |
…-> 100%) Completes the KV credential-seam coverage started in the kv_config test: the non-DB surface of credentials.py was uncovered — PostgresCredentialBackend argument validation, from_env bootstrap-transport reads, and the _select_backend postgres branch (the live pgcrypto/psycopg methods stay # pragma: no cover). Add tests/test_credentials_backend.py (8 tests, no Postgres needed) pinning the "KV, not env" bootstrap boundary: - PostgresCredentialBackend raises NotConfigured on an empty DSN or passphrase, and stores both (lazy schema) when valid. - from_env builds from exactly the two bootstrap env vars, and fails loudly when the DSN is unset (no silent empty backend). - _select_backend: memory default (case-insensitive), the postgres branch routes through from_env, and an unknown selector raises. credentials.py 83% -> 100%; combined with kv_config.py the KV seam is now 100%. Full suite 321 passed (was 313). Test-only; no production behavior changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T47gHdkeM8H2Mpu4VwZT3c
…% -> 100%) The cost hub's token-accounting seam was 74% covered. Add tests/test_token_counting.py (5 tests, dependency-free — a fake stands in for pg_llm_batch.TokenCounter): the heuristic counter's empty/whitespace-only zero path and word/punctuation monotonicity; PgTiktokenAdapter count_text/count_messages delegation (incl. the non-dict message -> "" branch); and build_token_counter's no-DSN heuristic selection (the pg_llm_batch import path stays # pragma: no cover). token_counting.py 74% -> 100%. Full suite 326 passed (was 300). Test-only. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T47gHdkeM8H2Mpu4VwZT3c
…> 100%) batch_routing is the cost hub's sync-vs-batch routing/execution surface; its embeddings path was undercovered. Add tests/test_batch_routing_embeddings.py (9 tests, no network / no pg-llm-batch install — a fake async client + fake assembler stand in): - LocalEmbeddingBatchBackend submit/poll/retrieve incl. the dependency-free token-count fallback (no token_counter) - PgLlmBatchEmbeddingBackend submit/poll/retrieve against a fake BatchAPIClient (both assembler and memory:// payload paths), result ordering + usage mapping, and empty-on-download-failure - helpers: heuristic_embedding (dimension + positive-guard), _extract_embedding (parse/defaults), _extract_answer (empty choices), cheapest_upstream (empty candidates -> None), EmbeddingBatchRequest.to_jsonl_line + build_embeddings_jsonl_body batch_routing.py 81% -> 100%. Test-only; no production change. Verified: 9 passed; full suite green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T47gHdkeM8H2Mpu4VwZT3c
Add targeted tests for previously-uncovered defensive/edge paths in the cost-hub router, all reachable and behavior-pinning: - _provider_from_base_url: mock scheme, real host extraction, empty input, and a malformed URL that must fall through the guarded parse to "" (never raise). - _positive_int: valid parse, ValueError/TypeError fallbacks, non-positive -> default. - _weighted_average_embedding: empty parts, all-empty-vector parts, and the weighted mean. - poll_batch / retrieve_batch / embeddings_batch_document: KeyError on an unknown job id. - _split_embedding_input / _force_token_safe_chunks: empty input, over-max_chars fixed-width split, and the token-dense single-unit midpoint-recursion fallback. - _count_embedding_tokens: tolerates a failing token counter (word-count fallback) and coerces a non-positive count on non-empty text to 1. cost_router.py coverage 89% -> 96% (full suite 341 passed). Tests only; no production behavior changes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T47gHdkeM8H2Mpu4VwZT3c
There was a problem hiding this comment.
Pull request overview
OpenCode cannot approve yet because required coverage evidence did not pass.
Review outcome
1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence
-
Problem: The required coverage-evidence job result was
failure, so OpenCode cannot establish approval sufficiency for this head. -
Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.
-
Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports
successwith required evidence or explicit no-source not-applicable evidence. -
Regression test: Keep the approval branch checking
needs.coverage-evidence.result == successbefore posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present. -
Result: REQUEST_CHANGES
-
Reason: coverage-evidence result was
failure, so required test/docstring evidence was not proven for current headf4847f9139c79494160a07e74f29abff857372e7. -
Head SHA:
f4847f9139c79494160a07e74f29abff857372e7 -
Workflow run: 30523412654
-
Workflow attempt: 1
Coverage evidence
Coverage evidence job did not run or did not publish coverage evidence.
Changed-File Evidence Map
flowchart LR
PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
Evidence --> S1["Test (5 files)"]
S1 --> I1["regression suite"]
I1 --> R1["Review risk: Test (5 files)"]
R1 --> V1["targeted test run"]
OpenCode Review Overview
Pull request overviewOpenCode cannot approve yet because required coverage evidence did not pass. Review outcome1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence
Coverage evidenceCoverage evidence job did not run or did not publish coverage evidence. Changed-File Evidence Mapflowchart LR
PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
Evidence --> S1["Changed file: cost_router.py"]
S1 --> I1["repository behavior"]
I1 --> R1["Review risk: Changed file: cost_router.py"]
R1 --> V1["required checks"]
Evidence --> S2["Test (6 files)"]
S2 --> I2["regression suite"]
I2 --> R2["Review risk: Test (6 files)"]
R2 --> V2["targeted test run"]
|
Close the remaining cost_router.py branches to meet the org's 100% coverage standard: - _served_provider_model: the fallback path when the trace names an agent the orchestrator cannot resolve (lookup raises -> "unknown", fallback_model). - embeddings_batch_document: the pending return while the backend poll is not yet complete; the count_text token fallback when an item reports non-positive prompt_tokens and its request carries a zero token_count; and the empty-source branch when an input receives no returned embedding item. - _weighted_average_embedding: mark the total_weight<=0 guard `# pragma: no cover` — it is unreachable (each summand is max(1, ...) over a guaranteed-non-empty parts list), documented inline. Tests added drive a fake embeddings backend (pending / complete-with-gaps) via the public submit/document surface. Full suite: 344 passed; cost_router.py 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T47gHdkeM8H2Mpu4VwZT3c
Add 13 focused tests closing the remaining cost_ledger.py branches to meet the org's 100% coverage standard, all with real tests (no pragmas): - InMemoryUsageTelemetrySink event-list trim past max_events. - _emit_usage_event best-effort swallow when the sink raises. - NonBlockingLedgerStore: zero-queue-size guard, queue.Full drop path (+dropped telemetry), query delegation, flush timeout, worker success-path mark/emit. - InMemoryLedgerStore.__len__. - SQL ledger store time-window WHERE-clause builder (start/end params). - CostLedger: non-blocking store wrapping via flag; attribution passed as an AttributionDimensions instance; inline append failure marks health + emits an export_error event; flush no-op when the store has no flush(). Deterministic threading via Event-synchronized backends (no sleeps). Full suite: 357 passed; cost_ledger.py 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T47gHdkeM8H2Mpu4VwZT3c
There was a problem hiding this comment.
Pull request overview
OpenCode cannot approve yet because required coverage evidence did not pass.
Review outcome
1. HIGH .github/workflows/opencode-review.yml:1 - Coverage evidence did not prove required test/docstring evidence
-
Problem: The required coverage-evidence job result was
failure, so OpenCode cannot establish approval sufficiency for this head. -
Root cause: Automated approval is only valid when the same-head coverage-evidence job proves supported repository test suites passed and configured docstring gates passed or were advisory, or reports not applicable because no supported source files or package manifests exist. Missing, failed, skipped, unavailable, or unsupported-tooling test evidence is a blocker.
-
Fix: Install or configure the repository test/docstring evidence tooling when source files or package manifests exist, rerun the current-head coverage-evidence job, and approve only after it reports
successwith required evidence or explicit no-source not-applicable evidence. -
Regression test: Keep the approval branch checking
needs.coverage-evidence.result == successbefore posting APPROVE, and publish REQUEST_CHANGES when coverage-evidence blocker states such as cancelled, skipped, failed, unsupported-tooling, or below-100 evidence are present. -
Result: REQUEST_CHANGES
-
Reason: coverage-evidence result was
failure, so required test/docstring evidence was not proven for current head2f9a4e4add83916ab0ed9fbbae873c5bbc3a0ffb. -
Head SHA:
2f9a4e4add83916ab0ed9fbbae873c5bbc3a0ffb -
Workflow run: 30532943059
-
Workflow attempt: 1
Coverage evidence
Coverage evidence job did not run or did not publish coverage evidence.
Changed-File Evidence Map
flowchart LR
PR["PR changed files"] --> Evidence["OpenCode bounded evidence"]
Evidence --> S1["Changed file: cost_router.py"]
S1 --> I1["repository behavior"]
I1 --> R1["Review risk: Changed file: cost_router.py"]
R1 --> V1["required checks"]
Evidence --> S2["Test (6 files)"]
S2 --> I2["regression suite"]
I2 --> R2["Review risk: Test (6 files)"]
R2 --> V2["targeted test run"]
|
Status at head The only remaining red is That base finding set is remediated by the open PRs #74 / #75 / #78 / #79 (none merged yet). This PR is not the right place to also fix it — a duplicate Generated by Claude Code |
|
Closing as superseded by the combined coverage path in #75 and #79. #75 carries focused KV/config/token/batch coverage plus the two production bug fixes surfaced by that work; #79 carries the repository-wide 100% line/docstring gates and the remaining credential, router, ledger, and orchestrator branch tests. Merging this older overlapping test branch separately would duplicate test cases, reintroduce conflicts in the same files, and delay the canonical bug-fix-first sequence. |
Summary
The KV seam through which the cost/routing hub reads config and provider secrets (the AGENTS.md "KV, not env" rule — never
os.getenvat runtime) was only exercised incidentally by other suites, leaving its own surface undertested. This PR brings both halves of the seam to 100% with two focused, dependency-free test files (small fakes /monkeypatch— no Postgres orpg_llm_batchinstall needed).kv_config.py— 49% → 100% (tests/test_kv_config.py, 13 tests)get/setroundtrip + default,get_categoryreturns a non-aliasing copy,show_configsorted ordering, and theset_secret/get_secret/require_secretsurface (secrets stay out ofshow_config;require_secretraisesKeyErrorwhen absent).get/setdelegation;get_secret/require_secretwith and without a backing secret store (default vs.KeyError, swallowing a backing-store error to the default).credentials.py— 83% → 100% (tests/test_credentials_backend.py, 8 tests)NotConfiguredon an empty bootstrap DSN or passphrase; stores both (lazy schema) when valid.postgresbranch routes throughfrom_env, and an unknown selector raises.The live pgcrypto/psycopg methods (
_connect/get/set) require a real Postgres and remain# pragma: no cover, unchanged.Verification
coverage run --source=contextual_orchestrator.kv_config,contextual_orchestrator.credentials→ both files 100% (was 49% / 83%).pytest tests -q→ 321 passed (was 300).Scope
Test-only. No production code, dependency, or workflow changes — this locks the security-relevant KV/credential bootstrap boundary under test. Every added test function/class carries a docstring, so the
interrogatedocstring gate (≥80) is unaffected.