feat(02-02): capture named sessions through a loopback proxy

Record Nuxt/MCP traffic as ordered flows via parity:proxy, pin
loopback upstream, and refuse oversized or credential-shaped fixtures.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Jakub Zych
2026-09-17 12:27:57 +02:00
parent 603270da08
commit bb6a5a91c9
9 changed files with 1209 additions and 6 deletions

60
tide/rules_test.go Normal file
View File

@@ -0,0 +1,60 @@
package tide
import (
"os"
"path/filepath"
"strings"
"testing"
)
func TestRulesLoadAndMatch(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "rules.yaml")
raw := "" +
"client: nuxt\n" +
"keep_request_headers:\n" +
" - Cookie\n" +
"keep_response_headers:\n" +
" - Location\n" +
"routes:\n" +
" - method: GET\n" +
" path: /sample\n" +
" capture:\n" +
" - from: response.json\n" +
" path: $.token\n" +
" as: jwt:alice\n" +
" category: jwt\n" +
" - method: POST\n" +
" path: /items/*\n"
if err := os.WriteFile(path, []byte(raw), 0o644); err != nil {
t.Fatal(err)
}
rules, err := LoadRules(path)
if err != nil {
t.Fatal(err)
}
if rules.Client != ClientNuxt {
t.Fatalf("client: %s", rules.Client)
}
if got := rules.Match("GET", "/sample"); got == nil || len(got.Capture) != 1 || got.Capture[0].As != "jwt:alice" {
t.Fatalf("GET /sample match: %+v", got)
}
if got := rules.Match("POST", "/items/9"); got == nil {
t.Fatal("POST /items/9 should match wildcard")
}
if got := rules.Match("GET", "/other"); got != nil {
t.Fatalf("unexpected match: %+v", got)
}
}
func TestRulesRejectUnknownAndInvalid(t *testing.T) {
if _, err := ParseRules([]byte("client: nuxt\nextra: true\n")); err == nil {
t.Fatal("unknown field must fail")
}
if _, err := ParseRules([]byte("client: browser\n")); err == nil || !strings.Contains(err.Error(), "client") {
t.Fatalf("invalid client: %v", err)
}
if _, err := ParseRules([]byte("client: mcp\nroutes:\n - method: GET\n path: /x\n capture:\n - path: $.a\n")); err == nil || !strings.Contains(err.Error(), "as") {
t.Fatalf("capture missing as: %v", err)
}
}