-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroundtrip_test.go
More file actions
59 lines (55 loc) · 1.82 KB
/
Copy pathroundtrip_test.go
File metadata and controls
59 lines (55 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package agenthooks_test
// Round-trip property (DESIGN.md §5.4): for every fixture in the corpus,
// decode → encode(NoDecision) produces the provider-correct no-op, and
// Event.Raw is byte-identical to the input.
import (
"bytes"
"context"
"io"
"log/slog"
"testing"
"github.com/speakeasy-api/agenthooks"
"github.com/speakeasy-api/agenthooks/agenthookstest"
)
func TestRoundTripNoOpAndRawFidelity(t *testing.T) {
providers := []agenthooks.Provider{
agenthooks.ProviderClaudeCode,
agenthooks.ProviderCodex,
agenthooks.ProviderCursor,
agenthooks.ProviderGemini,
agenthooks.ProviderOpenCode,
agenthooks.ProviderKimi,
agenthooks.ProviderCopilot,
}
quiet := agenthooks.WithLogger(slog.New(slog.NewTextHandler(io.Discard, nil)))
for _, p := range providers {
for name, payload := range agenthookstest.Fixtures(t, agenthookstest.FixtureDir(p)) {
t.Run(string(p)+"/"+name, func(t *testing.T) {
var raws [][]byte
// Round-trip concerns one event's wire behavior: session-level
// synthesis (prompt backfill) would add a second OnAny delivery.
r := agenthooks.New(quiet, agenthooks.WithoutDedup(), agenthooks.WithoutBackfill())
r.OnAny(func(ctx context.Context, e *agenthooks.Event) error {
raw := make([]byte, len(e.Raw))
copy(raw, e.Raw)
raws = append(raws, raw)
if e.Provider != p {
t.Errorf("provider = %q, want %q", e.Provider, p)
}
if e.NativeName == "" {
t.Error("native name must always be set")
}
return nil
})
res := agenthookstest.Invoke(t, r, p, payload)
agenthookstest.AssertNoOp(t, p, res)
if len(raws) != 1 {
t.Fatalf("OnAny should fire exactly once, fired %d times", len(raws))
}
if !bytes.Equal(raws[0], payload) {
t.Errorf("Raw not byte-identical:\n raw: %s\nwant: %s", raws[0], payload)
}
})
}
}
}