Skip to content

Support intra-segment wildcards in mock path matching#21

Merged
andrespaez90 merged 1 commit into
mainfrom
feat/intra-segment-path-wildcards
May 21, 2026
Merged

Support intra-segment wildcards in mock path matching#21
andrespaez90 merged 1 commit into
mainfrom
feat/intra-segment-path-wildcards

Conversation

@andrespaez90

Copy link
Copy Markdown

Summary

  • Extended matchPath to use path.Match per segment, enabling patterns like /tickets-bff/tkt_* to match paths where the wildcard appears within a segment (not just as a whole-segment *).
  • Added pathSpecificity as a tiebreaker in findBestLocked: when multiple mocks score equally, the one with fewer wildcard characters wins — so an exact-path mock always takes priority over a wildcard-path mock.
  • Updated the path placeholder in the mock editor UI to /tickets-bff/tkt_* to surface this new capability to users.

Test plan

  • TestMatchPathSupportsWildcardWithinSegment — covers exact match, whole-segment *, prefix wildcard (tkt_*), non-matching prefix, and mismatched segment count.
  • TestFindPrefersExactPathOverWildcardPath — verifies that when both /tickets-bff/tkt_* and /tickets-bff/tkt_8WNAsd8wsRnf0xC0m are registered, the exact mock wins for a matching request.
  • Run go test ./... to confirm all tests pass.
  • Open the mock editor and verify the path placeholder shows /tickets-bff/tkt_*.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 14, 2026 19:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds intra-segment wildcard support to mock path matching (using path.Match per segment), introduces a path-specificity tiebreaker so exact paths beat wildcard paths when match scores tie, and—beyond what the description states—adds a new "proxy" on_end mode for sequence mocks that lets requests fall through to the real backend after the sequence is exhausted, with matching frontend type, sequence-display, sidebar, and editor changes.

Changes:

  • Per-segment wildcard matching via path.Match, plus a pathSpecificity tiebreaker in findBestLocked.
  • New "proxy" sequence end-mode wired through backend resolution and frontend display/editor.
  • Updated mock-editor placeholder and added Go tests for path matching, exact-vs-wildcard preference, and proxy fall-through.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
mock.go Adds pathpkg.Match-based segment matching, pathSpecificity tiebreaker, and "proxy" OnEnd handling that returns nil after exhaustion.
mock_test.go New tests for intra-segment wildcards, exact-over-wildcard preference, and proxy sequence fall-through.
frontend/src/types.ts Extends Sequence.on_end union with 'proxy'.
frontend/src/sequence.ts Treats 'proxy' like 'reset' for cursor advance and adds proxyNext label/tooltip.
frontend/src/components/Sidebar.tsx Adds tooltip variant and updates comment for 'proxy' sequence mode.
frontend/src/components/MockEditorModal.tsx Adds "Proxy after end" button, exhausted-state messaging, and updates path placeholder to /tickets-bff/tkt_*.

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

Comment thread mock.go
@andrespaez90 andrespaez90 requested a review from a team May 14, 2026 20:45
Previously, path matching only supported whole-segment wildcards (`*`),
so a pattern like `/tickets-bff/tkt_*` would not match
`/tickets-bff/tkt_8WNAsd8wsRnf0xC0m`.

Switch each segment comparison to use `path.Match` so that patterns like
`tkt_*` are resolved as glob expressions within a single segment.

When multiple mocks match the same request with equal specificity, prefer
the one whose path has fewer wildcard characters (via `pathSpecificity`),
ensuring an exact-path mock always wins over a wildcard-path mock.

Update the path placeholder in the mock editor to reflect the new syntax.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@andrespaez90 andrespaez90 force-pushed the feat/intra-segment-path-wildcards branch from ebc717e to a580396 Compare May 14, 2026 20:56
@andrespaez90 andrespaez90 merged commit b1af3d0 into main May 21, 2026
4 checks passed
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.

3 participants