Skip to content

Improve test quality: pkg/parser/frontmatter_utils_test.go#23868

Merged
pelikhan merged 2 commits intomainfrom
copilot/improve-test-quality-frontmatter-utils
Apr 1, 2026
Merged

Improve test quality: pkg/parser/frontmatter_utils_test.go#23868
pelikhan merged 2 commits intomainfrom
copilot/improve-test-quality-frontmatter-utils

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 1, 2026

frontmatter_utils_test.go used raw t.Errorf/t.Fatalf throughout and lacked coverage for isRepositoryImport and had minimal coverage for ResolveIncludePath.

Changes

  • Testify assertions throughout — replaced all t.Errorf/t.Fatalf with assert.*/require.* with descriptive messages
  • TestIsRepositoryImport — new test with 14 cases: valid owner/repo variants (with ref, SHA, section, hyphens, underscores) and all rejection paths (3-part workflowspec, local/absolute/shared/ prefixed paths, file extensions)
  • TestResolveIncludePath — added absolute path case verifying the security check rejects paths like /etc/passwd that escape the base directory
  • TestIsWorkflowSpec — converted to testify assertions with descriptive messages
  • TestIsNotFoundError — not duplicated here; already covered with 6+ cases in import_remote_nested_test.go

- Replace t.Errorf/t.Fatalf with assert.*/require.* testify assertions
- Add TestIsRepositoryImport with 14 cases
- Add TestIsWorkflowSpec with testify-style assertions
- Expand TestResolveIncludePath with absolute path security case
- Add descriptive messages to all assertions
- Fix testifylint require-error lint warning"

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/4b6fcc6d-5f28-4ddf-82e1-5c03d96acacc

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve test quality for pkg/parser/frontmatter_utils_test.go Improve test quality: pkg/parser/frontmatter_utils_test.go Apr 1, 2026
Copilot AI requested a review from pelikhan April 1, 2026 12:10
@pelikhan pelikhan marked this pull request as ready for review April 1, 2026 12:15
Copilot AI review requested due to automatic review settings April 1, 2026 12:15
@github-actions github-actions bot mentioned this pull request Apr 1, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the quality and coverage of pkg/parser/frontmatter_utils_test.go by standardizing assertions with Testify and adding new/expanded test cases for import-path helpers and ResolveIncludePath security behavior.

Changes:

  • Replaced t.Errorf / t.Fatalf usage with assert.* / require.* for clearer, more consistent assertions.
  • Added TestIsRepositoryImport with a table of acceptance/rejection cases.
  • Expanded TestResolveIncludePath to include an “absolute path outside base dir” security-rejection case.

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

Comment on lines 118 to +127
func TestResolveIncludePath(t *testing.T) {
// Create temporary directory structure
tempDir, err := os.MkdirTemp("", "test_resolve")
if err != nil {
t.Fatalf("Failed to create temp dir: %v", err)
}
require.NoError(t, err, "should create temp dir")
defer os.RemoveAll(tempDir)

// Create regular test file in temp dir
regularFile := filepath.Join(tempDir, "regular.md")
if err := os.WriteFile(regularFile, []byte("test"), 0644); err != nil {
t.Fatalf("Failed to write regular file: %v", err)
}
err = os.WriteFile(regularFile, []byte("test"), 0644)
require.NoError(t, err, "should write regular file")
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

In this test, baseDir is set to tempDir (which doesn’t include a trailing ".github"). ResolveIncludePath’s security logic is written assuming baseDir is ".github" or a subdirectory (see comment in ResolveIncludePath), so it would be better to create a temp ".github" directory and use that as baseDir to match real usage (and avoid platform-specific path traversal behavior).

Copilot uses AI. Check for mistakes.
Comment on lines +148 to +153
{
name: "absolute path outside base dir is rejected for security",
filePath: "/etc/passwd",
baseDir: tempDir,
wantErr: true,
},
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

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

This case hard-codes "/etc/passwd" as the absolute path. To keep the test platform-agnostic (and avoid relying on Unix-specific paths), consider generating an absolute path that is guaranteed to be outside baseDir using filepath APIs (e.g., an abs path in filepath.Dir(baseDir)).

Copilot uses AI. Check for mistakes.
@pelikhan pelikhan merged commit 08ceefa into main Apr 1, 2026
67 checks passed
@pelikhan pelikhan deleted the copilot/improve-test-quality-frontmatter-utils branch April 1, 2026 12:42
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.

[testify-expert] Improve Test Quality: pkg/parser/frontmatter_utils_test.go

3 participants