Add circular redirect detection to linter - #12
Merged
Conversation
Detect redirect loops at config-lint time using graph-based DFS cycle detection. The linter builds a directed graph from redirect rules and finds cycles with three-color marking. Exact and prefix rules produce error-severity findings; regex/glob rules use sample-based tracing and produce warnings (best-effort). Detection covers: direct cycles (A->B->A), transitive chains (A->B->C->A), prefix cross-cycles, cross-host cycles via absolute URLs, prefix self-loops with preserve_path, and regex/glob self-matching destinations. Also enrich the syncer webhook response: lint failures now return HTTP 422 with a structured JSON body containing all issues (severity, rule_id, message, suggestion) instead of a generic "Sync failed". This lets CI pipelines parse the response and provide specific feedback. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What's Changed
Lint: Circular Redirect Detection (
internal/lint/lint.go)New
checkCircularRedirects()builds a directed graph from redirect rules and runs DFS with three-color marking to find cycles:/a → /b,/b → /a/a → /b → /c → /a/foo/ → /bar/,/bar/ → /foo/example.com/p1 → example.com/p2 → …/p1preserve_path)/old/ → /old/new/expands infinitely^/api/v1/(.*) → /api/v1/v2/$1(sample-based)Supporting functions:
buildRedirectGraph,findCycles,extractDestinationPath,checkPrefixSelfLoops,checkRegexGlobCycles,generateRegexSamples/generateGlobSamples.Webhook: Structured Lint Error Response (
cmd/redirector-sync/main.go)LintErrortype carries the fulllint.ResultSyncOnce()returns*LintErroron lint failures (instead offmt.Errorf)errors.Asto detect lint failures and returns HTTP 422 with JSON:{ "status": "lint_failed", "source": "github-primary", "message": "lint errors found in config from source github-primary (1 errors)", "issues": [ { "severity": "error", "rule_id": "old-home", "message": "Circular redirect detected: old-home -> new-home -> old-home", "suggestion": "Remove one rule from the chain or change a destination to break the cycle" } ] }Documentation
docs/SYNCER.md— New "Circular Redirect Detection" section with graph diagram, detection table, 4 worked examples (direct cycle, prefix self-loop, regex warning, JSON for CI), webhook response format, and limitations tabledocs/FEATURES.md— Added circular redirect detection to lint checks listdocs/MANAGEMENT_API.md— Documented webhook response format (success/422/500)IMPLEMENTATION_PLAN.md— Phase 9 plan with Stage 9.1 marked completeTests (
internal/lint/lint_test.go)10 new tests covering all detection scenarios:
TestLinter_CheckCircularRedirects_DirectCycleTestLinter_CheckCircularRedirects_TransitiveCycleTestLinter_CheckCircularRedirects_NoCycleTestLinter_CheckCircularRedirects_ExternalDestinationTestLinter_CheckCircularRedirects_CrossHostCycleTestLinter_CheckCircularRedirects_PrefixSelfLoopTestLinter_CheckCircularRedirects_PrefixNoSelfLoopTestLinter_CheckCircularRedirects_NonRedirectSkippedTestLinter_CheckCircularRedirects_PrefixCrossCycleTestLinter_CheckCircularRedirects_RegexSelfCycleTest plan
go test ./...)golangci-lint run ./internal/lint/— 0 issuesgo build ./...— compiles cleanredirector-sync --lint --lint-config config.yaml🤖 Generated with Claude Code