Repository navigation
✅ test(sink/git,sink/gitlab): local-repo coverage for temp-key/known-hosts/SSH-guard/push (COV-90-S02) - #187
Conversation
There was a problem hiding this comment.
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
pushCommittednon-fast-forward behaviors andstageChangesadd-error wrapping; add tests forpinGoGitSSHResolutionrewrite/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.
| // 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%).
87fc1dc to
06768c7
Compare
There was a problem hiding this comment.
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 thusfeatureBranch) fromobjectPathviapathvalidate.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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|



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 --barerepos (no network, no Docker), plus the REL-GIT-MULTIPART (#183) GitLab parity + prune-error paths.Coverage delta (uncovered statements)
internal/sink/git(isolated)internal/sink/gitlab(isolated)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:-coverpkg=./internal/...frame (whattask coverageuses) git is at 162 uncovered after this lane.ExportFilesWithBranch(137-149) requires a network-reachable remote (file:// always routes through the CLI engine); the deepexportRemote/mirror/exec_giterror branches (mkdir/write/status/commit failures,resolveGitExecutablePATH 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)
writeTempPrivateKey43.8% → 50.0% — RED: asserts 0600 perms + verbatim content in at.TempDir(); also create-temp failure. (write/chmod/close error branches need an FD seam — not covered.)pinGoGitSSHResolution16.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.writeTempKnownHosts50.0% → 58.3% — create-temp failure (viasshAuthMethod) + malformed known_hosts parse error + happy-path content lock.pushCommitted50.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 asgit push.stageChanges72.2% → 77.8% — non-prunewt.Adderror branch.exportRemote70.8% → higher — insecure-SSH propagation + feature-branch checkout, mirror-preparation failure.ExportFilesWithBranch— no-files guard + CLI-pathClassifyExportError.Export64.3% → 71.4%,ExportFiles73.7% → 78.9%,NewBackend→ 100% — merge_request-mode branch-spec + prune-opts (PruneKeepPaths/SuppressPrune) wiring and invalid-spec error.RED evidence
writeTempPrivateKeyperms assertion isperm != 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.pinGoGitSSHResolutioninput URL omits the port, so the:22in the rewritten output is an observable change (not identity).isNonFastForwardError.Honest notes (residual / not reachable without a production seam or network)
PushPolicyCommit: the+refs/heads/mainforce-fetch insyncRemoteBeforePushreconciles 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.pushCommittedresidual reds (SetReference-error at 365, post-merge-SetReference at 400, retry-error at 405) are error-injection branches needing a seam.EnsureMergeRequesttails (backend.go 76-81 / 116-121) require a live git-smart-HTTP server → not coverable without Docker.writeTempPrivateKey/writeTempKnownHostswrite/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.