fix(02): write fixtures exclusively and only on successful flush (WR-01)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -305,6 +305,40 @@ func TestProxyDuplicateSessionName(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyFailedSessionLeavesNoFixture(t *testing.T) {
|
||||
upstream := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.URL.Path == "/ok" {
|
||||
_, _ = w.Write([]byte(`{"ok":true}`))
|
||||
return
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"token":"` + testJWT + `"}`))
|
||||
}))
|
||||
t.Cleanup(upstream.Close)
|
||||
fixtures := t.TempDir()
|
||||
proxy := newTestProxy(t, upstream.URL, fixtures, testRulesYAML())
|
||||
srv := httptest.NewServer(proxy.Handler())
|
||||
t.Cleanup(srv.Close)
|
||||
|
||||
doProxy(t, srv.URL, "partial", "/ok", "")
|
||||
req, err := http.NewRequest(http.MethodGet, srv.URL+"/leak", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
req.Header.Set(SessionHeader, "partial")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
if err := proxy.Flush(); err == nil {
|
||||
t.Fatal("failed session flush must surface the capture error")
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(fixtures, "nuxt", "partial.yaml")); !os.IsNotExist(err) {
|
||||
t.Fatalf("partial session fixture committed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func newTestProxy(t *testing.T, upstream, fixtures, rulesYAML string) *Proxy {
|
||||
t.Helper()
|
||||
p, err := NewProxy(ProxyConfig{
|
||||
|
||||
Reference in New Issue
Block a user