edu icon indicating copy to clipboard operation
edu copied to clipboard

updates to chainlink tool

Open SharpRake opened this issue 6 months ago • 1 comments

Type of change

Enhancement

This PR adds new functionality to the chainlink tool for improved link checking and validation.

What should this PR do?

resolves https://github.com/chainguard-dev/internal/issues/5442

Why are we making this change?

The chainlink tool needed enhanced capabilities for link checking to better handle edge cases and improve reliability when validating links in documentation.

What are the acceptance criteria?

  • [ ] New link checking functionality is implemented in links.go
  • [ ] Comprehensive test coverage added in links_test.go
  • [ ] All existing tests continue to pass
  • [ ] Binary builds successfully

How should this PR be tested?

  1. Build the chainlink tool: cd tools/chainlink && go build
  2. Run the test suite: go test -v
  3. Test the tool against sample documentation with various link types
  4. Verify all tests pass and the tool handles edge cases correctly

SharpRake avatar Oct 08 '25 01:10 SharpRake

Deploy Preview for ornate-narwhal-088216 ready!

Name Link
Latest commit 766b1461854dcabe29484f5281202286a0f27a2f
Latest deploy log https://app.netlify.com/projects/ornate-narwhal-088216/deploys/695810c0f498680008494709
Deploy Preview https://deploy-preview-2662--ornate-narwhal-088216.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Oct 08 '25 01:10 netlify[bot]

My commit added:

  1. Remove insecure TLS verification fallback
  • Delete the TLS relaxed verification code block (lines ~199-217 in the PR)
  • Remove the isTLSError() helper function
  • Update shouldTryFallback() to exclude TLS-related conditions
  1. Extract common HTTP request creation logic into helper function
  • Create a new createRequest(method, url string) helper that sets User-Agent and Accept headers
  • Replace all 8+ instances of duplicated request creation code
  • This will reduce ~40 lines of repetitive code
  1. Replace goto statements with structured error handling
  • Refactor the fallback logic to use helper functions that return success/failure
  • Replace the processResponse: label and goto jumps with early returns or result structs
  • Make the control flow more readable and maintainable
  1. Replace string-based error checking with type assertions where possible
  • Update error detection to use errors.As() or type switches for proper error types
  • Keep string matching only where necessary (for wrapped errors without types)
  • More robust across Go version changes
  1. Implement logging levels (add -verbose flag, reduce default output)
  • Add a -verbose flag to control output verbosity
  • Keep important errors/warnings visible by default
  • Move debug messages (like "trying fallback strategy") behind verbose flag
  1. Add timeout/circuit breaker for fallback strategies
  • Add a maximum retry limit per link (e.g., max 2 fallback attempts)
  • Consider adding request timeouts for fallback attempts
  • Prevent excessive delays when checking broken links

Some other items than can be added in the future:

Add command-line flag for trailing slash fallback behavior

  • Add a new flag like -try-trailing-slash (default: false)
  • Only attempt trailing slash fallback when this flag is enabled
  • This prevents masking legitimate broken links by default

and

Expand test coverage for redirect loops, error conditions, and new flags

  • Add test for redirect loop fallback behavior
  • Add tests for the new -try-trailing-slash and -verbose flags
  • Add tests for error type detection improvements
  • Test timeout/circuit breaker behavior

ltagliaferri avatar Jan 02 '26 18:01 ltagliaferri