Skip to content

Expand .gitattributes test coverage - #76294

Merged
pelikhan merged 6 commits into
mainfrom
copilot/testify-expert-improve-test-quality
Nov 9, 2026
Merged

pelikhan merged 6 commits into
mainfrom
copilot/testify-expert-improve-test-quality

Conversation

Copilot AI commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

The existing tests lacked direct coverage for attribute-entry normalization, file reading, write failures, and staging.

  • Coverage: Add table-driven cases for nil/empty input, trailing empty lines, legacy replacement, whitespace-padded entries, missing files, newline splitting, and write failures.
  • Isolation: Use a shared Git repository setup with fresh temporary repositories per case; test campaign-entry absence separately.
  • Assertions: Replace t.Fatalf/t.Errorf with Testify require and assert; cover stageGitAttributesIfChanged.

Copilot AI changed the title [WIP] Add tests for gitattributes_test.go to improve test quality Expand .gitattributes test coverage Nov 9, 2026
Copilot AI requested a review from gh-aw-bot November 9, 2026 18:59
@pelikhan
pelikhan marked this pull request as ready for review November 9, 2026 19:09
Copilot AI adaptive review requested due to automatic review settings November 9, 2026 19:09
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

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.

Generated from Ponytail Reviewer · routed: gpt61 medium · ~4 AIC · ⌖ ~1 AIC · ◇ ~1 AIC · ⊞ 181 · ◷

Generated by Ponytail Reviewer for #76294

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

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.

PR Code Quality Reviewer

Outcome: reported_action

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.

Generated from PR Code Quality Reviewer · gpt56 · ~3 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 1.6K · ◷

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

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.

Generated from PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~2 AIC · ◇ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #76294

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — No ADR Draft Generated

Gate result: The volume trigger fired (146 added lines under pkg/), but this PR makes no architectural decision. No ADR was drafted and nothing was pushed to the branch. No blocking action is required.

🔍 Evidence
  • Scope: one file, pkg/cli/gitattributes_test.go (+146 / −107). No production code changed.
  • Labels: no implementation label.
  • Existing ADR: none in the PR body or on the branch. Linked issue [testify-expert] Improve Test Quality: pkg/cli/gitattributes_test.go #76289 is a test-quality task with no ADR content.
  • Decision check: the changes are test conventions, not architecture. They include table-driven cases, t.TempDir() and t.Chdir(), a shared setupGitRepo helper, and Testify require and assert. Testify is already widespread: 1,412 _test.go files in the repo import testify/require.
  • Why the trigger fired: the default business-directory count includes pkg/ and does not exclude _test.go files.
📋 Next steps
  1. No ADR action is needed for this PR.
  2. If maintainers want test-code volume excluded from the gate, consider excluding _test.go files from the volume count in the gate configuration.
  3. If a reviewer sees an architectural decision that was missed, add an ADR under docs/adr/ and link it in the PR body.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 8.6K · ◷
Comment /review to run again

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

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.

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-09T19:16:00Z
review_event: COMMENT
top_themes:
  - Missing regression coverage for read errors in .gitattributes handling
files_reviewed:
  - pkg/cli/gitattributes_test.go
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~2 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Non-NotExist read errors now propagate, and the regression test verifies ensureGitAttributes returns an error without modifying the existing file. Commit: 0e65c09.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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)

Comment thread pkg/cli/gitattributes_test.go Outdated
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("Failed to change to temp directory: %v", err)
}
func TestStageGitAttributesIfChanged(t *testing.T) {

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 .gitattributes with mode 0o200 is 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 WriteFile because the read error was swallowed earlier.
  • Staging test covers one path only: stageGitAttributesIfChanged always runs git 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 setupGitRepo and t.TempDir()
  • ✅ t.Chdir and require/assert replace the manual Chdir/Fatalf boilerplate
  • ✅ 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

Comment thread pkg/cli/gitattributes_test.go Outdated
expectUpdated: true,
},
{
name: "fails to write when gitattributes is a directory",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The directory case now expects the surfaced read error; a separate read-only-file case covers write failures. Commit: 0e65c09.

Comment thread pkg/cli/gitattributes_test.go Outdated
if err := os.Chdir(tmpDir); err != nil {
t.Fatalf("Failed to change to temp directory: %v", err)
}
func TestStageGitAttributesIfChanged(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/cli/gitattributes_test.go:157): address unresolved feedback - Review comment
  3. Review (pkg/cli/gitattributes_test.go:74): address unresolved feedback - Review comment
  4. Review (pkg/cli/gitattributes_test.go:211): address unresolved feedback - Review comment
  5. Review (pkg/cli/gitattributes_test.go:131): address unresolved feedback - Review comment

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"
}

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~9 AIC · ⌖ ~26 AIC · ⊞ 1.3K · ◷
Comment /souschef to run again

@pelikhan
pelikhan merged commit 304244c into main Nov 9, 2026
47 checks passed
@pelikhan
pelikhan deleted the copilot/testify-expert-improve-test-quality branch November 9, 2026 22:06
@github-actions

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[testify-expert] Improve Test Quality: pkg/cli/gitattributes_test.go

4 participants