test: expand BigQuery export coverage from 29.89% to 100% - #1223
Conversation
`tests/unit/test_bigquery_export.py` held a single test that covered 29.89% of `src/uvai/ml/bigquery_export.py`, leaving both transports, all four exporters, and every failure path unverified. Replace it with 42 tests covering `_get_bq_client`, `_insert_rows`, `_insert_via_rest`, and the four `export_*` entry points, including the REST fallback contract shared by all exporters. Statement coverage of the module goes from 29.89% to 100% (61 previously-missed statements). The pre-existing test was also order-dependent and already failing in a full-suite run: it poisoned `sys.modules["google.cloud.bigquery"]`, but `from google.cloud import bigquery` resolves via `getattr` on an already-imported parent package, so a mocked `google.cloud` left behind by another test bypassed the poison. Denying the import at `__import__` level makes it deterministic. Full `tests/unit` failures drop 134 -> 133 as a result. No production code is modified; all public signatures are unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🔍 PR Validation |
|
Important Review skippedAuto reviews are limited based on label configuration. 🏷️ Required labels (at least one) (1)
Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository YAML (base), Repository UI (inherited), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Snapshot WarningsEnsure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice. Scanned FilesNone |
Agent Completion Truth Gate: BLOCKEDReasons: Machine-readable verdict{
"details": {
"collection_errors": [
"incomplete_linked_issue_contract",
"missing_intent_snapshot",
"missing_agent_run_id",
"missing_agent_login"
],
"invalid_fields": [
"policy.agent_login",
"policy.run_id"
]
},
"reasons": [
"invalid_payload"
],
"verdict": "blocked"
} |
There was a problem hiding this comment.
Pull request overview
Expands deterministic, offline unit coverage for BigQuery exports, closing #909 without production changes.
Changes:
- Adds 42 tests covering both transports and four exporters.
- Covers serialization, fallback behavior, failures, and import-order isolation.
- Uses the approved test video ID and mocks external boundaries.
groupthinking
left a comment
There was a problem hiding this comment.
Review-requested triage — blocked on one non-code gate
Functional CI is fully green. test, build, lint-python, lint-frontend, trivy, bandit, CodeQL, both security scans, dependency-review, and Generate and Upload Coverage all pass. Copilot's review is a positive overview with no change requests; CodeRabbit auto-review was skipped by label config (not a failure).
The sole red is agent-completion/truth-gate, and it is a provenance gate rather than a code check. Its machine-readable verdict is:
{"verdict":"blocked","reasons":["invalid_payload"],
"details":{"invalid_fields":["policy.agent_login","policy.run_id"]}}i.e. the completion payload reached the gate with empty/invalid agent_login and run_id. This is unrelated to the diff — the change is test-only and src/uvai/ml/bigquery_export.py is untouched.
Why this isn't auto-resolved here. The missing fields are the originating run's agent identity and run id. A downstream reviewer cannot legitimately populate them — supplying fabricated provenance is exactly what this "truth gate" exists to prevent — so I will not push a payload to force it green. The gate's applicability/payload wiring is the subject of in-flight PRs #1123 (explicit noop terminal state) and #1154 (scope gate applicability to real dispatch evidence).
Unblock path (needs the maintainer / originating automation):
- Re-run the agent-completion workflow so it emits a payload with populated
policy.agent_loginandpolicy.run_id; or - Given all functional checks are green and the change is test-only, a maintainer merges past the provenance gate.
Terminal state: HALTED(truth_gate_invalid_payload). Not merging — main is protected and merge approval is a human decision.
Generated by Claude Code
|
Returned to draft during delivery control. The test-only change is linked to #909, but no current execution receipt or independent exact-head completion evidence has been reconciled. Preserve the branch and checks; do not advance until that evidence is bound. |
Note on the red
|
Canonical issue
Closes #909
src/uvai/ml/bigquery_export.pyhad a single test covering 29.89% of the module. Both transports (BigQuery client and REST fallback), all fourexport_*entry points, and every failure path were unverified.Outcome
Replaced the 1-test file with 42 tests. Statement coverage of
src/uvai/ml/bigquery_export.pygoes 29.89% -> 100% (61 previously-missed statements now covered, 0 missed).TestGetBqClientNone; construction raises ->None; success passesproject=PROJECT_IDTestInsertRowsFalse; success ->True; fully-qualifiedtable_ref; backend row errors ->False; exception ->False; empty-list behaviourTestInsertViaRestFalse; success ->True;insertErrors->False; network error ->False; metadata-server URL and header; bearer auth + insertAll URL; uniqueinsertIdper rowTestExportTranscriptOutcomeFalse; field serialization; absent metadata ->None; falsy0.0/FalsepreservedTestExportActionFeedbackTestExportModelCheckpointTestExportPipelineRun[]; failure details recordedTestExporterContractThe suite also fixes a pre-existing order-dependent failure. The old test poisoned
sys.modules["google.cloud.bigquery"], butfrom google.cloud import bigqueryresolves viagetattron an already-imported parent package, so a mockedgoogle.cloudleft behind by another test bypassed the poison entirely. It passed in isolation (vacuously -googleis not installed) and failed in a full-suite run. The replacement denies the import at__import__level, which is order-independent.No production code is modified. All public signatures are unchanged, as the issue requires.
Risk
src/uvai/ml/bigquery_export.pyis untouched (git statusclean for that path after every mutation run).Verification
Run on branch
groupthinking-bigquery-export-coverage, branched fromorigin/mainatb664e9227per the issue's "start from current main" criterion.Coverage baseline captured by stashing the new file and re-running:
Full
tests/unitrun, mine vs. baseline (same command, same machine):Passed count rises by exactly 42 (my tests) and failures drop by exactly 1 - the pre-existing
test_get_bq_client_import_error. All other counts are identical, confirming nothing else is affected. The remaining 133 failures and 41 errors are pre-existing and unrelated (collection errors reproduce identically at 36 with and without this change).Production evidence
1. The tests detect regressions. Passing tests are not the same as detecting tests, so each assertion was verified by mutating the source and confirming a failure. 10/10 mutations caught, source verified restored after each:
export_pipeline_runinsertIdinstead of per-row uniqueinsertErrorsin the REST responseexport_model_checkpointdefaultexported_attimestamp2. The order-dependence fix is demonstrated, not asserted. A temporary harness reproduced the exact pollution condition (a mocked
google.cloudinsys.modules), then was removed:And on unmodified
origin/main, the pre-existing test is confirmed already failing in a full-suite run:3. The replacement test is not vacuous. Because
googleis not installed in this environment, an import-denial test can pass without exercising anything. Mutating theImportErrorbranch to return a truthy sentinel fails the test, proving the branch is genuinely reached:A behaviour-preserving mutation (
except ImportError->except ZeroDivisionError) is correctly not flagged, since the genericexcept Exceptionhandler still returnsNone- the tests assert on contract, not on incidental structure.