Skip to content

✅ test(sink/git,sink/gitlab): local-repo coverage for temp-key/known-hosts/SSH-guard/push (COV-90-S02) - #187

Merged
konih merged 1 commit into
mainfrom
test/cov-90-s02-git-sink
Aug 3, 2026
Merged

konih merged 1 commit into
mainfrom
test/cov-90-s02-git-sink

Conversation

@konih

@konih konih commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Lane: COV-90-S02 — sink/git local-repo path coverage (P1, Track A)

Test-only. Covers the git sink's temp-key / known-hosts / SSH-guard / push / export-flow branches using local tmp + bare git init --bare repos (no network, no Docker), plus the REL-GIT-MULTIPART (#183) GitLab parity + prune-error paths.

Coverage delta (uncovered statements)

package before after total %
internal/sink/git (isolated) 207 172 85.1% → 87.6%
internal/sink/gitlab (isolated) 42 39 83.9% → 85.1%

Repo floor gate: internal/ coverage 86.0% (floor 85%) ✓ (both frames measured with the same awk over the coverprofile).

Achieved vs. tasks.md target — honest reconciliation

tasks.md targets internal/sink/git uncovered 195 → ~90. That number is not reachable within S02's scope. Concretely:

  • The five named S02 functions hold only ~49 uncovered statements combined; covering them 100% could not get git below ~158.
  • In the merged -coverpkg=./internal/... frame (what task coverage uses) git is at 162 uncovered after this lane.
  • The remaining large pools are Track-B / seam-bound, not local-coverable: the entire go-git remote export branch in ExportFilesWithBranch (137-149) requires a network-reachable remote (file:// always routes through the CLI engine); the deep exportRemote / mirror / exec_git error branches (mkdir/write/status/commit failures, resolveGitExecutable PATH failure) need production seams or fault injection. Reaching ~90 would require the Track-B integration fold (design.md §Feasibility risk) or refactors out of scope for a test-additive lane. Flagging rather than forcing risky setups.

Targets covered (before → after, isolated frame)

  • writeTempPrivateKey 43.8% → 50.0% — RED: asserts 0600 perms + verbatim content in a t.TempDir(); also create-temp failure. (write/chmod/close error branches need an FD seam — not covered.)
  • pinGoGitSSHResolution 16.7% → 94.4% — resolve-and-rewrite (public IP literal, so netguard resolves with no DNS), non-ssh passthrough, unparseable URL, forbidden-host resolve failure, unsupported auth method.
  • writeTempKnownHosts 50.0% → 58.3% — create-temp failure (via sshAuthMethod) + malformed known_hosts parse error + happy-path content lock.
  • pushCommitted 50.0% → 84.6% — non-fast-forward → sync fast-forward → success (bare local repo advanced after clone); a non-reconciling policy surfaces a wrapped, non-ff-classified rejection (git push: non-fast-forward update), not swallowed; a transport push failure wraps as git push.
  • stageChanges 72.2% → 77.8% — non-prune wt.Add error branch.
  • exportRemote 70.8% → higher — insecure-SSH propagation + feature-branch checkout, mirror-preparation failure.
  • ExportFilesWithBranch — no-files guard + CLI-path ClassifyExportError.
  • gitlab Export 64.3% → 71.4%, ExportFiles 73.7% → 78.9%, NewBackend → 100% — merge_request-mode branch-spec + prune-opts (PruneKeepPaths/SuppressPrune) wiring and invalid-spec error.

RED evidence

  • writeTempPrivateKey perms assertion is perm != 0o600 (a regression to 0644 would fail it). Argued, not observed-as-failing — this is a test-additive lane; the assertion is non-tautological because a laxer mode or truncated write fails it.
  • pinGoGitSSHResolution input URL omits the port, so the :22 in the rewritten output is an observable change (not identity).
  • non-ff surfacing asserted via the package's own isNonFastForwardError.

Honest notes (residual / not reachable without a production seam or network)

  • Non-ff never surfaces under the default PushPolicyCommit: the +refs/heads/main force-fetch in syncRemoteBeforePush reconciles by superseding the local commit (returns nil). The wrapped non-ff-classified error is only reachable under a non-reconciling policy — the test asserts that contract explicitly.
  • pushCommitted residual reds (SetReference-error at 365, post-merge-SetReference at 400, retry-error at 405) are error-injection branches needing a seam.
  • gitlab post-export token/EnsureMergeRequest tails (backend.go 76-81 / 116-121) require a live git-smart-HTTP server → not coverable without Docker.
  • writeTempPrivateKey/writeTempKnownHosts write/chmod/close error branches need an FD-injection seam; only the create-temp branch is reachable.

Gate matrix (all green)

go build ./... · go vet ./... · task lint (0 issues) · task test · task verify · task coverage (86.0% ≥ 85%)

No production behavior changed (test-additive only). Do not merge — awaiting independent review.

Copilot AI review requested due to automatic review settings August 3, 2026 17:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds targeted, local-only unit/integration-style tests to increase branch coverage for the internal/sink/git and internal/sink/gitlab sinks—specifically around SSH temp-file handling, SSH URL guarding, and push/non-fast-forward behavior—without requiring network access or Docker.

Changes:

  • Add tests for SSH temp private key creation (content + 0600 perms) and create-temp failure wrapping.
  • Add tests for known_hosts temp-file failure propagation, malformed known_hosts parsing, and successful known_hosts temp-file writes.
  • Add local bare-repo tests for pushCommitted non-fast-forward behaviors and stageChanges add-error wrapping; add tests for pinGoGitSSHResolution rewrite/error branches.
  • Extend GitLab backend export tests to cover merge-request mode wiring and prune options plumbing, plus invalid spec error path.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
internal/sink/gitlab/backend_export_test.go Adds merge-request mode and prune-option wiring tests for GitLab backend exports.
internal/sink/git/temp_key_test.go Adds tests for temp SSH private key file permissions/content and create-temp failure wrapping.
internal/sink/git/ssh_auth_test.go Adds tests for known_hosts temp-file failure, malformed parsing, and happy-path write behavior.
internal/sink/git/push_committed_local_test.go Adds local bare-repo tests for push/non-fast-forward recovery and staging error wrapping.
internal/sink/git/gogit_ssh_guard_test.go Adds tests covering SSH URL resolution pinning/rewriting and guard error branches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +128 to +130
// TestBackend_Export_BranchMRModeBuildsFeatureBranch drives Export in merge_request mode with a
// commit context supplied via the context, exercising the branch-spec wiring (feature branch derived
// from the injected namespace/name) before the clone fails against a non-git server.
…sh + export-flow branches with local repos (COV-90-S02)

Local-repo (no network, no Docker) coverage for the git sink's SSH, push, and
export-flow paths plus the GitLab multipart parity wiring (REL-GIT-MULTIPART, #183):

- writeTempPrivateKey: assert 0600 perms + verbatim content; cover create-temp failure.
- writeTempKnownHosts / sshAuthMethod: cover create-temp failure and malformed
  known_hosts parse error; lock happy-path content.
- pinGoGitSSHResolution: rewrite-to-resolved (public IP literal, no DNS), non-ssh
  passthrough, unparseable URL, forbidden-host resolve failure, unsupported auth (16.7% -> 94.4%).
- pushCommitted against bare local repos: non-fast-forward -> sync fast-forward success;
  a non-reconciling policy surfaces a wrapped, non-ff-classified rejection (not swallowed);
  a transport push failure wraps as "git push" (50% -> 84.6%).
- exportRemote / ExportFilesWithBranch: insecure-SSH + feature-branch checkout, mirror-prep
  failure, no-files guard, CLI-path ClassifyExportError.
- stageChanges: cover the non-prune wt.Add error branch.
- gitlab Backend Export/ExportFiles: merge_request-mode branch-spec + prune-opts wiring
  and NewBackend invalid-spec error.

git pkg uncovered 207 -> 172 (85.1% -> 87.6%); gitlab uncovered 42 -> 39 (83.9% -> 85.1%).
Repo floor gate: internal/ coverage 86.0% (floor 85%).
Copilot AI review requested due to automatic review settings August 3, 2026 17:51
@konih
konih force-pushed the test/cov-90-s02-git-sink branch from 87fc1dc to 06768c7 Compare August 3, 2026 17:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Suppressed comments (1)

internal/sink/gitlab/backend_export_test.go:131

  • The test comment says the feature branch is derived from the injected commit context, but Backend.Export derives invNS/invName (and thus featureBranch) from objectPath via pathvalidate.InventoryFromObjectPath. This makes the comment (and the test name) misleading and can confuse future maintainers about what’s actually being exercised here.
// TestBackend_Export_BranchMRModeBuildsFeatureBranch drives Export in merge_request mode with a
// commit context supplied via the context, exercising the branch-spec wiring (feature branch derived
// from the injected namespace/name) before the clone fails against a non-git server.
func TestBackend_Export_BranchMRModeBuildsFeatureBranch(t *testing.T) {

@codecov

codecov Bot commented Aug 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@konih
konih merged commit 40b3256 into main Aug 3, 2026
30 of 31 checks passed
@konih
konih deleted the test/cov-90-s02-git-sink branch August 3, 2026 18:03
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