Repository navigation
Expand .gitattributes test coverage - #76294
Conversation
Co-authored-by: gh-aw-bot <[email protected]>
.gitattributes test coverage
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review. Caution agentic threat detected DetailsPotential security threats were detected in the agent output. Detected threat types: prompt injection. Review the workflow run logs for details. PR Code Quality ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.
|
🏗️ Design Decision Gate — No ADR Draft GeneratedGate result: The volume trigger fired (146 added lines under 🔍 Evidence
📋 Next steps
|
|
Caution agentic threat detected DetailsPotential security threats were detected in the agent output. Detected threat types: prompt injection. Review the workflow run logs for details. Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Caution
agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.
Details
Potential security threats were detected in the agent output. Detected threat types: prompt injection.
Review the workflow run logs for details.
Found one test-coverage gap: the new suite does not verify behavior when an existing .gitattributes cannot be read, which can allow repository rules to be overwritten. Please add that regression case before merge. Static review only; tests were not run per review instructions.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~2 AIC · ⊞ 1.6K
Comment /review to run again
| tt.setup(t, path) | ||
| } | ||
|
|
||
| lines, err := readGitAttributesFile(path) |
There was a problem hiding this comment.
This only exercises the missing-file case; it does not cover an existing .gitattributes whose os.ReadFile fails (for example, permission denied). readGitAttributesFile currently treats every read error as an absent file, so ensureGitAttributes can overwrite repository rules instead of returning the error. Please add a regression case that asserts the read error is propagated and the file remains untouched.
There was a problem hiding this comment.
Non-NotExist read errors now propagate, and the regression test verifies ensureGitAttributes returns an error without modifying the existing file. Commit: 0e65c09.
There was a problem hiding this comment.
🟡 Changes recommended
A critical duplicate test function declaration in the cli package will prevent the test files from compiling until it is removed or renamed.
1 open issue
What changed in this PR
Expands .gitattributes test coverage in pkg/cli, including normalization, file handling, write failures, and staging behavior.
Changes:
- Adds table-driven tests for normalization, legacy-entry replacement, whitespace, missing files, and newline handling.
- Uses isolated temporary Git repositories and Testify assertions.
- Adds coverage for write failures, campaign-entry absence, and staging.
| File | Summary | Review findings |
|---|---|---|
pkg/cli/gitattributes_test.go |
Adds comprehensive isolated tests for .gitattributes creation, reading, normalization, error handling, and staging. |
Critical (1 vote): TestStageGitAttributesIfChanged duplicates an existing function in commands_compile_workflow_test.go, causing the package tests to fail compilation. Rename or remove the duplicate. |
Review effort: Lite (auto)
| if err := os.Chdir(tmpDir); err != nil { | ||
| t.Fatalf("Failed to change to temp directory: %v", err) | ||
| } | ||
| func TestStageGitAttributesIfChanged(t *testing.T) { |
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /tdd and /diagnosing-bugs. The test refactor is sound and passes (go test ./pkg/cli -run GitAttributes|RequiredGitAttributesEntry|StageGitAttributesIfChanged, gofmt and go vet clean). Three coverage gaps are flagged inline, and one is a real data-loss path in existing code.
📋 Key Themes & Highlights
Key Themes
- Unreadable file treated as absent:
readGitAttributesFile(pkg/cli/git.go) discards all read errors. I reproduced it: a.gitattributeswith mode0o200is overwritten with only the managed entry and no error is returned. The PR does not introduce this, but its new file-reading tests should cover it. - Write-failure case passes for the wrong reason: the directory case fails at
WriteFilebecause the read error was swallowed earlier. - Staging test covers one path only:
stageGitAttributesIfChangedalways runsgit add. It does not check for changes, so the name is misleading. The unchanged and missing-file cases are untested.
Positive Highlights
- ✅ Table-driven cases with fresh repos per case via
setupGitRepoandt.TempDir() - ✅
t.Chdirandrequire/assertreplace the manualChdir/Fatalfboilerplate - ✅ Separate test for campaign-entry absence, as the PR description intended
- ✅ Idempotence check on the second
ensureGitAttributes()call
No blocking issues. The unreadable-file bug is pre-existing and should be tracked separately if it is out of scope. @copilot please address the inline comments.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~2 AIC · ⊞ 6.3K
Comment /matt to run again
| expectUpdated: true, | ||
| }, | ||
| { | ||
| name: "fails to write when gitattributes is a directory", |
There was a problem hiding this comment.
[/tdd] This case passes for the wrong reason. The directory triggers the same swallowed read error, and the failure only shows up later at WriteFile. Once read errors propagate (see the comment on TestReadGitAttributesFile), this case should expect a read error rather than failed to write .gitattributes.
@copilot please address this.
There was a problem hiding this comment.
The directory case now expects the surfaced read error; a separate read-only-file case covers write failures. Commit: 0e65c09.
| if err := os.Chdir(tmpDir); err != nil { | ||
| t.Fatalf("Failed to change to temp directory: %v", err) | ||
| } | ||
| func TestStageGitAttributesIfChanged(t *testing.T) { |
There was a problem hiding this comment.
[/tdd] stageGitAttributesIfChanged does not check for changes. It always runs git add, and this test covers only the changed-file path. Add cases for an unchanged file (no-op, nil error) and a missing file (error returned, exit status 128 today). If the name is misleading, consider renaming it to stageGitAttributes.
@copilot please address this.
There was a problem hiding this comment.
Added coverage confirming a committed unchanged .gitattributes leaves no staged diff and a missing file returns an error. The added test has a unique name. Commit: 0e65c09.
| assert.True(t, os.IsNotExist(statErr), "no .gitattributes file should be created outside a git repository") | ||
| } | ||
|
|
||
| func TestReadGitAttributesFile(t *testing.T) { |
There was a problem hiding this comment.
[/diagnosing-bugs] Missing regression case: an unreadable .gitattributes is silently treated as absent. I reproduced it: a file with mode 0o200 is overwritten with only the managed entry and err is nil. readGitAttributesFile in pkg/cli/git.go discards every ReadFile error, not just fs.ErrNotExist, so existing user rules can be lost.
💡 Suggested change
Return the error when !errors.Is(err, fs.ErrNotExist). Then add a wantErr table case that makes the file unreadable, expects an error, and checks the file is unchanged. Skip that case when running as root, because root ignores permission bits.
@copilot please address this.
There was a problem hiding this comment.
readGitAttributesFile now returns non-NotExist errors. Added unreadable-file regression coverage for both direct reads and ensureGitAttributes, checking the existing content is preserved. Commit: 0e65c09.
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering. Structured data{
"completed_task": 0,
"head": "690c7da00e4bae658082ef466d122d2df89857a9",
"kind": "requested",
"schema_version": "1",
"state": "18fff3b75a15c4d42eaa067d28b07f0bdec9524629e3c7707027f78e7d167d10",
"work": [
"00471989231e69973b8f1443dfdb0fdb94a3e5165868fc95273b6edab40d541f",
"0c1302ba409bba29d70330d2f5281ab825eb7cce8f27cbde66f6ab13d9b03569",
"271550d2ca00f3e39f915a3d0b2a019afa6c9851735b4320d076de2ced193308",
"9fa5909e416255f6e749c25f4c68b8d385191b5e504ab7ff1d7d3c16f0ce967d"
],
"workflow": "pr-sous-chef"
}
|
…t-improve-test-quality Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
|
🎉 This pull request is included in a new release. Release: |

The existing tests lacked direct coverage for attribute-entry normalization, file reading, write failures, and staging.
t.Fatalf/t.Errorfwith Testifyrequireandassert; coverstageGitAttributesIfChanged.