Skip to content

feat(tools): extend error-log-review to go.mod version review#4560

Open
wuhuizuo wants to merge 1 commit into
mainfrom
agent/coder/588e1db4
Open

feat(tools): extend error-log-review to go.mod version review#4560
wuhuizuo wants to merge 1 commit into
mainfrom
agent/coder/588e1db4

Conversation

@wuhuizuo
Copy link
Copy Markdown
Contributor

Summary

  • add optional file-scoped matcher support so rules can target go.mod files without renaming the error-log-review job
  • extend the shared error-log-review config to review go/toolchain directive changes for the six covered repositories
  • add tests for file-scoped matching and loading the live shared config, and update tool messaging/docs to cover protected changes beyond error logs

Testing

  • docker run --rm -v /Users/pingcap/multica_workspaces/653ba637-3f90-422e-b29d-e6d5d36993db/588e1db4/workdir/ci:/work -w /work/tools/error-log-review golang:1.26 go test ./...

@wuhuizuo
Copy link
Copy Markdown
Contributor Author

/hold

Copy link
Copy Markdown

@ti-chi-bot ti-chi-bot Bot left a comment

Choose a reason for hiding this comment

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

I have already done a preliminary review for you, and I hope to help you do a better job.

Summary

This PR enhances the error-log-review tool to include support for reviewing go.mod file changes, specifically targeting go and toolchain directive modifications. It introduces file-scoped matching and extends configuration patterns for several repositories. The approach is well-structured, with updates to the YAML configuration, tool logic, and tests. Overall, the implementation is clear but could benefit from improved error handling and minor optimizations.


Critical Issues

  • Error handling in matchesFileScope function
    • File: tools/error-log-review/config.go, lines 21-31
    • Issue: The function ignores errors returned by filepath.Match, which could cause unexpected behavior or silent failures when given invalid patterns.
    • Recommendation: Log or handle the error explicitly to ensure problematic patterns do not disrupt the matching logic.
      matched, err := filepath.Match(pattern, base)
      if err != nil {
          log.Printf("Invalid file matching pattern: %s, error: %v", pattern, err)
          continue
      }

Code Improvements

  • Regex Compilation Efficiency

    • File: tools/error-log-review/config.go, lines 12-15
    • Issue: Patterns are compiled repeatedly when loading the configuration, which is both redundant and inefficient.
    • Recommendation: Compile patterns once during configuration loading and reuse them.
      for i := range config.Repositories {
          for j := range config.Repositories[i].Patterns {
              compiled, err := regexp.Compile(config.Repositories[i].Patterns[j].Regex)
              if err != nil {
                  return nil, fmt.Errorf("failed to compile regex for pattern %s: %v", config.Repositories[i].Patterns[j].Name, err)
              }
              config.Repositories[i].Patterns[j].compiled = compiled
          }
      }
  • Testing Coverage Specificity

    • File: tools/error-log-review/matcher_test.go, TestCheckPRDiffWithFileScopedPatterns
    • Issue: While the test validates matches, it does not check if the output matches the exact lines in the diff. This could lead to undetected false positives/negatives.
    • Recommendation: Extend the test to verify match line content against expected values.
      expectedMatches := map[string]string{
          "go.mod": "go 1.24.1",
          "components/worker/go.mod": "go 1.23.7",
          "main.go": `log.Error("production error")`,
      }
      for _, match := range matches {
          if match.Line != expectedMatches[match.File] {
              t.Errorf("unexpected match for %s: got %s, expected %s", match.File, match.Line, expectedMatches[match.File])
          }
      }

Best Practices

  • Documentation Consistency

    • File: tools/error-log-review/README.md, lines 1-80
    • Issue: The README updates are helpful but could better highlight the exact configuration changes required for adding new file-scoped patterns.
    • Recommendation: Add detailed examples showing how to configure file-scoped rules, including edge cases like nested modules.
  • Unclear Error Messaging

    • File: tools/error-log-review/main.go, lines 75-138
    • Issue: The error messages for missing approvals are generic and do not mention which file or pattern caused the failure.
    • Recommendation: Include specific file and pattern names in error messages to improve debugging clarity.
      fmt.Printf("Protected change in file %s (pattern: %s) requires approval - failing CI\n", match.File, match.Pattern)
  • Naming Conventions

    • File: tools/error-log-review/matcher.go, lines 57-60
    • Issue: The function name matchesFileScope is misleading since it implies matching scopes rather than verifying file inclusion.
    • Recommendation: Rename to isFileInScope for improved clarity.

Conclusion

The PR is well-constructed and introduces valuable functionality to the error-log-review tool. Addressing the issues listed above will improve robustness, performance, and usability, especially for debugging and extending file-scoped pattern matching.

@wuhuizuo
Copy link
Copy Markdown
Contributor Author

/approve

@ti-chi-bot
Copy link
Copy Markdown

ti-chi-bot Bot commented Apr 28, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: wuhuizuo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the approved label Apr 28, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request expands the error log review tool to support broader 'protected changes,' specifically adding a pattern to monitor go and toolchain version updates in go.mod files. It introduces a files field to the pattern configuration, allowing rules to be scoped to specific filenames. Feedback suggests that the new test case enforcing the go_mod_version pattern across all repositories is overly restrictive and may cause CI failures for non-Go projects added in the future.

Comment on lines +208 to +227
for _, repo := range config.Repositories {
found := false
for _, pattern := range repo.Patterns {
if pattern.Name != "go_mod_version" {
continue
}

found = true
if !matchesFileScope("go.mod", pattern.Files) {
t.Errorf("repository %s go_mod_version pattern should match root go.mod", repo.Name)
}
if !matchesFileScope("nested/module/go.mod", pattern.Files) {
t.Errorf("repository %s go_mod_version pattern should match nested go.mod", repo.Name)
}
}

if !found {
t.Errorf("repository %s is missing go_mod_version pattern", repo.Name)
}
}
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.

medium

The test TestLoadSharedConfigIncludesGoModReview enforces that every repository defined in the shared config.yaml must contain the go_mod_version pattern. This makes the test suite fragile; if a new repository is added to the configuration for a different purpose (e.g., a non-Go project that only needs error log review), this test will fail and block CI.

Consider making this test more specific by checking only a predefined list of Go-based repositories, or simply verifying that the pattern exists in at least one repository to ensure the configuration loading logic works.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant