Skip to content

♻️ refactor(sink): extract shared secret-value-from-keys helper (dup audit) - #38

Merged
konih merged 4 commits into
mainfrom
refactor/sink-secret-value-dedup
Jul 3, 2026
Merged

konih merged 4 commits into
mainfrom
refactor/sink-secret-value-dedup

Conversation

@konih

@konih konih commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • BACKLOG §3 "dup audit" item: internal/sink/postgres/config.go's dsnFromSecret and internal/sink/mongodb/config.go's uriFromSecret independently looped over a set of candidate secret keys looking for the first non-empty value — near-identical bodies, different key lists/error text.
  • Extracts the scan into a new leaf package internal/sink/secretkv (FirstValue(data, keys...)). No import-cycle risk: internal/sink (registry) already imports internal/sink/postgres/internal/sink/mongodb, so those two could never import internal/sink back; secretkv sits as a sibling leaf package instead, same pattern as internal/sink/git/internal/sink/layout.
  • Pure refactor — both callers keep their own candidate key lists and error messages, so observable behavior (including error text) is unchanged.
  • Drive-by: corrected a stale BACKLOG.md entry for "Multi-operator sink dedupe guidance" (P2) discovered already shipped in docs/deployment/topology-matrix.md's "Multi-operator sink dedupe runbook" section (19107a20e) while picking this lane — local-only coordination doc, not part of this diff.

Test plan

  • TDD: TestFirstValue_* in internal/sink/secretkv/secretkv_test.go written first, confirmed red (undefined: FirstValue), then made green.
  • Existing postgres/mongodb config tests pass unmodified (no behavior change).
  • task test — full unit + envtest suite green
  • task lint / task arch-lint — 0 issues
  • task verify — no codegen drift
  • task coverage — internal/ 80.6% (floor 72%); new package 100%
  • task scrub — clean
  • task changelog:verify — synced

🤖 Generated with Claude Code

konih added 2 commits July 1, 2026 00:53
…audit)

postgres's dsnFromSecret and mongodb's uriFromSecret independently looped
over a set of candidate secret keys (dsn/url/connectionString/... vs
uri/url/connectionString/...) looking for the first non-empty value, with
near-identical bodies. Extracts the scan into internal/sink/secretkv.FirstValue
(a new leaf package under the sink component, no import-cycle risk since
postgres/mongodb are imported BY internal/sink, not the other way around).

Pure refactor: both callers keep their own candidate key lists and error
messages, so observable behavior (including error text) is unchanged. Backed
by the existing postgres/mongodb regression suite (unmodified, still green)
plus new direct unit tests for the extracted helper.
@konih

konih commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

REVIEW — sink-secret-value-dedup @ bb0f85f — NO SELF-VERDICT — 2026-07-01

No verdict posted (auto-mode classifier blocks self-authored APPROVE on own commits this
session even with chat confirmation, per AGENTS.md standing rule). Raw gate results + findings
below for the maintainer to judge directly.

Reviewer: next-sprint session (self-review attempt blocked by auto-mode classifier)
Branch: refactor/sink-secret-value-dedup -> main · Base: origin/main @ f147642d8 · PR: #38

Gate matrix

Gate Result Notes
go build ./... PASS
task verify PASS no codegen drift
task lint PASS golangci-lint 0 issues
task arch-lint PASS OK - No warnings found (confirms internal/sink/secretkv as a leaf under the existing sink arch-lint component introduces no new violations and no import cycle)
task test PASS full suite incl. envtest green
task coverage PASS internal/ 80.6% (floor 72%); new internal/sink/secretkv 100%
task scrub PASS clean
task changelog:verify PASS synced in bb0f85f4f
task helm-test n/a no chart changes
task vulncheck n/a no go.mod/go.sum changes

Findings

ID Sev Area Finding Evidence Block?
MR-01 P3 Scope internal/sink/bigquery/config.go has its own ConfigFromSpec shape (project/dataset/table validation) but does not resolve a connection string from a secret the same way (BigQuery auth is service-account/workload-identity based, not DSN/URI) — confirmed not a missed instance of this duplication, just a structurally different sink. No action needed. internal/sink/bigquery/config.go No
MR-02 P3 Scope internal/sink/gitlab/config.go's ConfigFromSpec was checked too (BACKLOG wording said "postgres/mongodb/gitlab triplication") — its shape is endpoint/TLS validation, not a secret-key scan, so there was no third instance of the dsnFromSecret/uriFromSecret pattern to fold in; only postgres and mongodb actually had it. Noting this so the BACKLOG wording isn't misread as "three call sites still exist" — there were only ever two for this specific duplication. internal/sink/gitlab/config.go:24-68 No

No P0/P1 findings.

Functional correctness

Delivers BACKLOG.md §3 "dup audit" item (postgres/mongodb/gitlab triplication note). On inspection,
the concrete, byte-for-byte-duplicated logic was specifically dsnFromSecret (postgres) and
uriFromSecret (mongodb) — both scan a map[string][]byte for the first non-empty, trimmed value
among a list of candidate key names, identical control flow, different key lists and error text.
gitlab's ConfigFromSpec does not touch a database secret at all (HTTPS git endpoint + TLS), so
it was never a third instance of this specific pattern (see MR-02). Extracted the scan into
internal/sink/secretkv.FirstValue(data, keys...), a new leaf package under the existing sink
arch-lint component (internal/sink/**). Placement was deliberate: internal/sink (the registry)
already imports internal/sink/postgres and internal/sink/mongodb to register them, so those two
packages importing the top-level internal/sink back would be an import cycle — secretkv sits as
a sibling leaf instead, same shape as the existing internal/sink/git shared-by-gitlab pattern.
Both callers keep their own candidate key lists and exact error message text, so this is a pure,
behavior-preserving refactor — confirmed by the full existing postgres/mongodb test suites
passing unmodified (zero test files touched in either package).

TDD followed: internal/sink/secretkv/secretkv_test.go (4 tests covering key-priority-order,
skipping blank values, trimming, and no-match) was written first against a non-existent FirstValue
function, confirmed red via "undefined: FirstValue" compile failure, then the production code was
added to turn it green.

Drive-by (not part of this diff): while picking up the original "Multi-operator sink dedupe
guidance" BACKLOG item for this lane, found it already shipped in
docs/deployment/topology-matrix.md's "Multi-operator sink dedupe runbook" section (19107a20e) —
corrected the stale BACKLOG.md entry (local-only coordination file, not in this PR) rather than
writing a duplicate doc.

Coverage delta

internal/ 80.6% (floor 72%) on this branch, rooted on origin/main @ f147642d8. New package
internal/sink/secretkv 100%. internal/sink/postgres 58.7% -> 58.4% and internal/sink/mongodb
35.7% -> 35.2% (small, expected dips: a few previously-counted lines moved into the new,
separately-100%-covered package, not a coverage loss in the underlying logic). No package fell
below its pre-existing floor; no package newly below 60% that wasn't already there (mongodb was
already 35.7% before this change, tracked separately under BACKLOG's MongoDB coverage item).

Summary / next steps

Maintainer review needed on GitHub — no self-verdict claimed per auto-mode classifier policy. All
gates green, no P0/P1 findings. Two P3 scope-clarification notes above, neither blocking.

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@konih

konih commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

REVIEW — sink-secret-value-dedup @ bb0f85f — APPROVE — 2026-07-03

Verdict: APPROVE
Reviewer: independent session (bulk PR-sweep, maintainer-directed)
Branch: refactor/sink-secret-value-dedup → main · Base: origin/main (up to date, no rebase needed) · PR: #38

Gate matrix

Gate Result Notes
go build ./... ✅
task verify ✅
task lint ✅ 0 issues
task arch-lint ✅
task test ✅ all packages pass; new internal/sink/secretkv 100% coverage
task coverage ✅ 80.6% (floor 72%)
task scrub ✅ no forbidden strings, gitleaks clean
task changelog:verify ✅

Findings

None.

Functional correctness

Extracts the identical "scan secret data for first non-empty value among candidate keys, trimmed" loop that both postgres/config.go's dsnFromSecret and mongodb/config.go's uriFromSecret had duplicated, into internal/sink/secretkv.FirstValue. Diffed the old inline loops against the new helper line-by-line — behavior is identical (same trim-then-check-empty semantics, same key-priority-order iteration, same nil-map handling implicit in map lookup). Both call sites updated consistently. No new CRD surface, no behavior change visible to users — pure internal dedup.

TDD compliance

New secretkv_test.go covers: first-match-wins in key order, skipping blank/whitespace-only values with fallback to next key, trimming, and both the "no key matches" and "nil map" no-match cases. These are real behavior tests (would fail if the extraction introduced a semantic difference), not padding. Existing postgres/mongodb config tests continue to pass unchanged, confirming the refactor didn't alter their observable behavior.

Coverage delta

internal/ overall 80.6% (floor 72%). New internal/sink/secretkv package at 100%. No regressions.

Summary / next steps

Clear to merge, no follow-up needed.

@konih

konih commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

Rebase-only update: head moved bb0f85f4f → a6e5ab187 (merge origin/main + changelog resync, no change to this PR's own diff — confirmed via gh pr diff 38 --name-only, still scoped to the 5 originally-reviewed files). Prior APPROVE stands. CI green on current head, mergeStateStatus: CLEAN. Proceeding to merge.

@konih
konih merged commit 2f166a5 into main Jul 3, 2026
25 checks passed
@konih
konih deleted the refactor/sink-secret-value-dedup branch July 3, 2026 20:02
konih added a commit that referenced this pull request Jul 10, 2026
…audit) (#38)

* ♻️ refactor(sink): extract shared secret-value-from-keys helper (dup audit)

postgres's dsnFromSecret and mongodb's uriFromSecret independently looped
over a set of candidate secret keys (dsn/url/connectionString/... vs
uri/url/connectionString/...) looking for the first non-empty value, with
near-identical bodies. Extracts the scan into internal/sink/secretkv.FirstValue
(a new leaf package under the sink component, no import-cycle risk since
postgres/mongodb are imported BY internal/sink, not the other way around).

Pure refactor: both callers keep their own candidate key lists and error
messages, so observable behavior (including error text) is unchanged. Backed
by the existing postgres/mongodb regression suite (unmodified, still green)
plus new direct unit tests for the extracted helper.

* 📄 docs: sync CHANGELOG

* 📄 docs: sync CHANGELOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants