Commit e9d618a
test(worker): real-DB integration harness + Tier-1 job coverage (toward 100% integration) (#87)
* test(worker): real-DB integration harness + Tier-1 job coverage (toward 100% integration)
Add internal/testhelpers — a real-Postgres integration harness mirroring
api's testhelpers.SetupTestDB. Before this, only 3 of ~59 worker job files
exercised a real DB; the rest were fake/mock-driven (INTEGRATION-COVERAGE-
PLAN-2026-06-04.md §5 #1 flagged worker as the platform's biggest
integration gap).
New REAL-DB round-trip integration tests (seed real rows → run Work()
against live Postgres → assert the DB state transition + side effects):
- deploy_status_reconcile + deploy_failure_autopsy (the 2026-05-30
silent-deploy-failure triad — highest value): build-Job-Failed →
row flips to 'failed' + autopsy row; healthy transition; stuck-building
reap; autopsy upsert + error_message stamp + deploy.failed audit emit
idempotency.
- entitlement_reconciler: drifted resource → applied_conn_limit persisted;
no-drift row left untouched.
Harness gates via t.Skip under -short / when no DB is reachable, so
`make gate` (deploy.yml) and ci.yml (no DB service) skip cleanly — matching
the existing propagation_runner_integration_test.go gating. Tests run
locally against postgres://postgres@localhost:5432/instant_dev_test.
ensureSchema also (re)creates the deployment_events failure_autopsy
partial-unique index defensively: a plain CREATE UNIQUE INDEX IF NOT EXISTS
silently no-ops when the canonical name is taken by an index on a different
table (observed on a dev box), so the harness probes the actual table and
creates a collision-proof index when absent.
Integration-only coverage (per-file, real-DB tests ONLY, the §1.4 mechanism):
deploy_status_reconcile.go : 0.0% -> 60.0% (90/150 stmts)
deploy_failure_autopsy.go : 0.0% -> 42.2% (94/223 stmts)
entitlement_reconciler.go : 0.0% -> 44.0% (74/168 stmts)
All three had ZERO integration coverage before (propagation_runner was the
only prior worker integration test and touches none of these files).
Jobs-package self-coverage (full suite): 97.2%.
make gate GREEN. golangci-lint clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(worker): give integration harness its own 100% coverage (fix patch-coverage gate)
PR #87's `coverage` CI check failed: diff-cover's 100%-patch gate flagged
253 uncovered lines in the new internal/testhelpers/testhelpers.go. Two
interacting causes:
1. SetupTestDB skipped under `testing.Short()`. coverage.yml's "Generate
coverage" step runs `go test ./... -short` against a real Postgres
service, so the -short guard skipped the integration tests that drive
the harness — leaving every line at 0%. Removed the -short guard;
gating is now purely on DB reachability (matches api's
testhelpers.SetupTestDB), so the no-DB workflows (deploy.yml -short,
ci.yml -race) still skip cleanly via the ping arm while coverage.yml's
Postgres service exercises the harness.
2. testhelpers.go is a non-_test.go file (it must be importable by the
internal/jobs integration tests), so it lands in coverage.out — but
Go credits coverage to the package whose tests ran (jobs), not
testhelpers. Added testhelpers_smoke_test.go, an in-package suite that
gives the harness its own coverage. Mirrors api's testapp_smoke_test.go.
The harness's fail/skip arms route through swappable tFatalf/tSkipf seams
(the platform "test seams, not waivers" rule) so the error paths are
covered with a closed DB; the create-index and bare-schema-fallback
branches are driven against the real DB; the seam defaults are covered via
isolated goroutines. Replaced the provably-unreachable sql.Open error arm
with pq.NewConnector (a reachable, tested DSN-parse skip).
Result: internal/testhelpers at 100% statements; diff-cover patch gate
100% / 0 missing; project floor 97.2% (>=95). `make gate` green.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(worker): cover the TEST_DATABASE_URL default-DSN fallback in SetupTestDB
The merged-HEAD coverage run flagged lines 105-106 (the `dsn == "" ->
DefaultTestDBURL` fallback) as the last 2 uncovered diff lines: CI always
exports TEST_DATABASE_URL, so the fallback only runs when the env var is
explicitly unset. Added TestIntegration_SetupTestDB_DefaultDSNFallback,
which clears the env var (t.Setenv "") and asserts SetupTestDB resolves to
the default localhost DSN. Brings internal/testhelpers back to 100% under
CI's environment; diff-cover patch gate now 100% / 0 missing.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 06e12b0 commit e9d618a
4 files changed
Lines changed: 1150 additions & 0 deletions
File tree
- internal
- jobs
- testhelpers
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
Lines changed: 113 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
0 commit comments