Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

Adds test coverage for task frontmatter parsing with selectors containing array values and custom fields that aren't part of the typed struct.

Changes

  • New test case in TestTaskFrontMatter_Unmarshal covering:

    • single_shot: true (typed field)
    • collect_and_push: false (custom field stored in Content map)
    • selectors: tool: [""] (selector with array value)
  • Enhanced validation to check custom Content fields and Selectors map beyond the existing typed field checks

Example test input:

---
single_shot: true
collect_and_push: false
selectors:
    tool: [""]
---

Say hello.

This ensures the YAML unmarshaler correctly populates both typed TaskFrontMatter fields and the underlying Content map for arbitrary frontmatter fields.

Original prompt

Add more task parsing tests. Include this example

---
single_shot: true
collect_and_push: false
selectors:
    tool: [""]
---

Say hello.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copilot AI changed the title [WIP] Add more task parsing tests with example Add task parsing test with selectors and custom fields Dec 24, 2025
Copilot AI requested a review from alexec December 24, 2025 01:41
@alexec alexec marked this pull request as ready for review December 24, 2025 01:48
Copilot AI review requested due to automatic review settings December 24, 2025 01:48
Copy link
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 adds test coverage for task frontmatter parsing, specifically focusing on handling selectors with array values and custom fields that aren't part of the typed TaskFrontMatter struct. The changes enhance the test suite to validate that both typed fields and arbitrary YAML fields in the Content map are correctly unmarshaled.

Key Changes:

  • Added a new test case "task with selectors and custom fields" demonstrating parsing of single_shot, collect_and_push, and selectors with array values
  • Enhanced test validation logic to check custom Content fields beyond typed struct fields
  • Added validation for the Selectors map to ensure selector values are properly unmarshaled

gotVal, exists := got.Selectors[key]
if !exists {
t.Errorf("Selectors[%q] missing, want %v", key, wantVal)
} else if fmt.Sprintf("%v", gotVal) != fmt.Sprintf("%v", wantVal) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The same fragile comparison logic using fmt.Sprintf("%v") is used here. For comparing map values (especially nested structures like arrays), this string-based comparison is unreliable and may lead to false positives or false negatives.

Consider using reflect.DeepEqual or a proper testing comparison library for accurate validation of complex selector values.

Copilot uses AI. Check for mistakes.
Comment on lines +153 to +161
yaml: `---
single_shot: true
collect_and_push: false
selectors:
tool: [""]
---
Say hello.
`,
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The test input includes YAML document delimiters (---) which are inconsistent with other test cases in this file. All other test cases provide raw YAML without delimiters. Since this test directly calls yaml.Unmarshal, it should follow the same pattern as other tests and exclude the delimiters.

While go-yaml may accept document delimiters, maintaining consistency with the existing test pattern improves readability and clearly shows that this is testing YAML unmarshaling, not markdown frontmatter extraction.

Suggested change
yaml: `---
single_shot: true
collect_and_push: false
selectors:
tool: [""]
---
Say hello.
`,
yaml: `single_shot: true
collect_and_push: false
selectors:
tool:
- ""`,

Copilot uses AI. Check for mistakes.
gotVal, exists := got.Content[key]
if !exists {
t.Errorf("Content[%q] missing, want %v", key, wantVal)
} else if fmt.Sprintf("%v", gotVal) != fmt.Sprintf("%v", wantVal) {
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The comparison logic using fmt.Sprintf("%v") is fragile and can produce false positives. For comparing slices and maps, this approach converts them to string representation which may not accurately reflect equality. For example, []any{""} and []string{""} will have different string representations even though they contain the same values.

Consider using a proper deep equality check such as reflect.DeepEqual or a testing library like github.com/google/go-cmp/cmp for more reliable comparisons of complex types.

Copilot uses AI. Check for mistakes.
@alexec alexec closed this Dec 24, 2025
@alexec alexec deleted the copilot/add-task-parsing-tests branch December 24, 2025 01:52
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.

2 participants