From c4ed3da30b4fa6e420540ceee12d33a9fac548eb Mon Sep 17 00:00:00 2001 From: shankar0123 Date: Sat, 16 May 2026 06:24:09 +0000 Subject: [PATCH] =?UTF-8?q?fix(ci):=20Sprint=206=20CI=20follow-up=20?= =?UTF-8?q?=E2=80=94=20staticcheck=20ST1021=20+=20tenant-query=20baseline?= =?UTF-8?q?=20+=20skip=20inventory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sprint 6 push (commits 43836ac + 663b14b) tripped three CI guards. Fixing all three in this single follow-up — each is a small, mechanical correction that doesn't change behavior: 1. staticcheck ST1021: AuditChainSnapshot doc comment was on the wrong type. internal/service/audit_chain_metric.go:91 had: // Snapshot returns the current counter state for the Prometheus // exposer. Reads use atomic loads — no mutex. type AuditChainSnapshot struct { ... } The comment described Snapshot() (the method on AuditChainCounter) but sat directly above the AuditChainSnapshot struct. staticcheck ST1021 requires exported-type comments to start with the type's name + optional leading article. Rewrote to lead with "AuditChainSnapshot is the point-in-time view ...". 2. multi-tenant-query-coverage: baseline drifted 31 → 32 because Sprint 6 COMP-002-RETENTION added UserRepository.ListDeactivatedBefore at internal/repository/postgres/user.go:191 — legitimately tenant-spanning by design. The retention policy is control-plane-wide (one CERTCTL_USER_RETENTION_WINDOW for the whole deployment, not per-tenant). The scheduler's userRetentionLoop walks every tenant's deactivated users on the same tick. A per-tenant tenant_id filter would require the scheduler to iterate every tenant — more code for equivalent semantics. Per the guard's own documentation (option b), legitimately tenant-spanning queries get an inline rationale comment + a baseline lift. Both delivered: - Inline comment block on the SELECT in user.go::ListDeactivatedBefore. - BASELINE_COUNT 31 → 32 in scripts/ci-guards/multi-tenant-query-coverage.sh, with the Sprint 6 rebase entry added to the rebase-history comment. 3. skip-inventory-drift: docs/testing/skip-inventory.md was stale. COMP-001-HASH added three new t.Skip sites in internal/repository/postgres/audit_chain_test.go (the three testing.Short() gates on the testcontainers integration tests). Re-ran ./scripts/skip-inventory.sh to regenerate the doc — totals went from 144 → 147 sites + 78 → 82 short-mode guards. Verified locally: bash scripts/ci-guards/multi-tenant-query-coverage.sh (clean) bash scripts/ci-guards/skip-inventory-drift.sh (clean) go vet ./... (clean) staticcheck ./internal/service/... (clean) Closes the three Sprint 6 CI failures. The next CI run should green out. --- docs/testing/skip-inventory.md | 7 +++++-- internal/repository/postgres/user.go | 7 +++++++ internal/service/audit_chain_metric.go | 6 ++++-- scripts/ci-guards/multi-tenant-query-coverage.sh | 12 ++++++++++-- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/docs/testing/skip-inventory.md b/docs/testing/skip-inventory.md index 251f7f6..66a8138 100644 --- a/docs/testing/skip-inventory.md +++ b/docs/testing/skip-inventory.md @@ -8,8 +8,8 @@ ## Summary -- Total t.Skip sites: **144** -- testing.Short() guards: **78** (these gate behind `go test -short`) +- Total t.Skip sites: **147** +- testing.Short() guards: **82** (these gate behind `go test -short`) Re-run inventory with: `./scripts/skip-inventory.sh`. @@ -162,6 +162,9 @@ Re-run inventory with: `./scripts/skip-inventory.sh`. ### `internal/repository/postgres` +- `internal/repository/postgres/audit_chain_test.go:137` — t.Skip("skipping integration test in short mode") +- `internal/repository/postgres/audit_chain_test.go:36` — t.Skip("skipping integration test in short mode") +- `internal/repository/postgres/audit_chain_test.go:58` — t.Skip("skipping integration test in short mode") - `internal/repository/postgres/audit_worm_test.go:29` — t.Skip("skipping integration test in short mode") - `internal/repository/postgres/auth_revoke_scope_test.go:118` — t.Skip("integration test in short mode") - `internal/repository/postgres/auth_revoke_scope_test.go:149` — t.Skip("integration test in short mode") diff --git a/internal/repository/postgres/user.go b/internal/repository/postgres/user.go index e3e34a8..9038d86 100644 --- a/internal/repository/postgres/user.go +++ b/internal/repository/postgres/user.go @@ -185,6 +185,13 @@ func (r *UserRepository) ListAll(ctx context.Context, tenantID string) ([]*userd // this list per tick and calls UserRetentionService.DeleteUserPII on // each. Cross-tenant on purpose: a single retention policy spans the // whole control plane. +// +// multi-tenant-query-coverage carve-out: the SELECT below intentionally +// omits `tenant_id` because retention is a control-plane-wide policy +// (one CERTCTL_USER_RETENTION_WINDOW for the whole deployment, not +// per-tenant). Adding a `tenant_id = $N` filter would require the +// scheduler loop to iterate every tenant, which is more code for +// equivalent semantics. The guard's baseline counts this query. func (r *UserRepository) ListDeactivatedBefore(ctx context.Context, threshold time.Time) ([]*userdomain.User, error) { rows, err := r.db.QueryContext(ctx, `SELECT `+userColumns+` diff --git a/internal/service/audit_chain_metric.go b/internal/service/audit_chain_metric.go index e5c32bf..95589bc 100644 --- a/internal/service/audit_chain_metric.go +++ b/internal/service/audit_chain_metric.go @@ -88,8 +88,10 @@ func (c *AuditChainCounter) RecordBreak(brokenAtID string, brokenAtPos int) { } } -// Snapshot returns the current counter state for the Prometheus -// exposer. Reads use atomic loads — no mutex. +// AuditChainSnapshot is the point-in-time view of the counters the +// Prometheus exposer reads. Snapshot() returns one of these; the +// metrics handler renders each field into Prometheus exposition +// format. Reads use atomic loads — no mutex required. type AuditChainSnapshot struct { BreaksDetected uint64 WalksCompleted uint64 diff --git a/scripts/ci-guards/multi-tenant-query-coverage.sh b/scripts/ci-guards/multi-tenant-query-coverage.sh index c12f45d..c25faa1 100755 --- a/scripts/ci-guards/multi-tenant-query-coverage.sh +++ b/scripts/ci-guards/multi-tenant-query-coverage.sh @@ -67,8 +67,16 @@ TARGET_DIR="${REPO_ROOT}/internal/repository/postgres" # # To rebase: re-run the guard, set BASELINE_COUNT to the new value, # include the rebase commit's SHA in the "last rebase" comment. -BASELINE_COUNT=31 -# Last rebase: 2026-05-11 (Audit 2026-05-11 fix bundle dropped tenant_id-less +BASELINE_COUNT=32 +# Last rebase: 2026-05-16 (Sprint 6 COMP-002-RETENTION added +# UserRepository.ListDeactivatedBefore at internal/repository/postgres/user.go:191 +# — legitimately tenant-spanning by design. The scheduler's +# userRetentionLoop walks every tenant's deactivated users on the +# same tick; the retention policy is control-plane-wide, not +# per-tenant. Documented inline in the SQL comment. +# +# Prior rebases: +# 2026-05-11 (Audit 2026-05-11 fix bundle dropped tenant_id-less # queries by 1; v2.1.0 release-gate Phase 5 ratcheted baseline 32 -> 31). if [ ! -d "$TARGET_DIR" ]; then