Repository navigation
Done
Labels
Description
Current State
- Test file:
pkg/cli/gitattributes_test.go(181 LOC, 2 test functions, 1 table-driven with 6 cases) - Source pair: no
gitattributes.go; the code under test lives inpkg/cli/git.go:ensureGitAttributes,readGitAttributesFile,ensureRequiredGitAttributesEntry,stageGitAttributesIfChanged - Testify usage: none. The file uses
t.Fatalf/t.Errorfandos.MkdirTemp+os.Chdir.
Strengths
- Table-driven main test with legacy-migration and idempotency (second call) checks.
- Covers the not-in-git-repo error path.
Prioritized Improvements
1. Missing / high-value tests
ensureRequiredGitAttributesEntryis a pure function but has no direct tests. Add a table test withnilinput, an empty slice, a trailing-empty-line input, legacy-entry replacement (assert the returned slice andmodified), and a whitespace-padded existing entry.readGitAttributesFileis untested: a missing file returns an empty slice, and an existing file is split by\n.ensureGitAttributeswrite failure (e.g..gitattributesis a directory) is not tested. Assert the error containsfailed to write .gitattributes.stageGitAttributesIfChangedis untested.- Per-case isolation: the current table reuses one repo and removes
.gitattributesmanually. Prefer a freshgit initper subtest.
2. Testify assertion upgrades
Before / after
// before
tmpDir, err := os.MkdirTemp("", "gh-aw-gitattributes-test")
if err != nil { t.Fatalf(...) }
defer os.RemoveAll(tmpDir)
...
if updated != tt.expectUpdated {
t.Errorf("updated=%v, want %v", updated, tt.expectUpdated)
}
// after
tmpDir := t.TempDir()
t.Chdir(tmpDir)
updated, err := ensureGitAttributes()
require.NoError(t, err, "ensureGitAttributes should succeed")
assert.Equal(t, tt.expectUpdated, updated, "updated flag mismatch")
assert.Equal(t, strings.TrimSpace(tt.expectedContent), strings.TrimSpace(string(content)))
assert.Contains(t, string(content), constants.WorkflowsLockYmlGitAttributesEntry)
assert.NotContains(t, string(content), ".github/workflows/*.campaign.g.md")Other upgrades:
os.Stat+os.IsNotExistbecomesassert.NoFileExists/require.FileExists.t.Skipon agit initfailure becomesrequire.NoErrorafter anexec.LookPath("git")skip.- Use
t.Chdir(Go 1.24+) in place of the manualos.Getwd/Chdirdefer. - Use
constants.WorkflowsLockYmlGitAttributesEntryinstead of the hard-coded string.
3. Table-driven refactors
- Split the
existingContent/expectedContenttable: move the pure-logic cases into anensureRequiredGitAttributesEntrytest and keep a few file-based cases forensureGitAttributes. - Add a
wantErrcolumn to cover the error paths in one table.
4. Organization / readability
- Extract a helper
setupGitRepo(t)(TempDir + Chdir +git init) shared by both tests. - Rename
TestEnsureGitAttributesNotInGitRepotoTestEnsureGitAttributes_NotInGitRepo, matching nearby tests. - Move the repeated "campaign.g.md not present" check into its own case rather than asserting it in every iteration.
Acceptance Checklist
- Replace
t.Fatalf/t.Errorfwithrequire/assert - Add direct tests for
ensureRequiredGitAttributesEntryandreadGitAttributesFile - Add a write-failure test
- Use
t.TempDir()/t.Chdir()and a shared setup helper -
make test-unitpasses
Generated by 🧪 Daily Testify Uber Super Expert · copilot · auto (Claude Sonnet 5.5) · ~16 AIC · ⌖ ~2 AIC · ⊞ 9.5K · ◷
- expires on Nov 11, 2026, 10:05 AM UTC-08:00
Reacted by Copilot
Activity
github-actions commentedon Nov 9, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, Copilot will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪