Repository navigation
Expand file tree
/
Copy pathnative_floor_test.go
More file actions
104 lines (99 loc) · 3.24 KB
/
Copy pathnative_floor_test.go
File metadata and controls
104 lines (99 loc) · 3.24 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package acpruntime
import (
"context"
"encoding/json"
"io"
"strings"
"testing"
)
// compareVersions anchors the semver-ish ordering used for version floors.
func TestCompareVersions(t *testing.T) {
cases := []struct {
a, b string
want int
}{
{"0.153.4", "0.153.4", 0},
{"0.153.4", "0.153.5", -1},
{"0.154.0", "0.153.9", 1},
{"1.0", "0.99.99", 1},
{"0.153", "0.153.1", -1}, // shorter prefix sorts lower
}
for _, tc := range cases {
if got := compareVersions(tc.a, tc.b); got != tc.want {
t.Fatalf("compareVersions(%q, %q) = %d, want %d", tc.a, tc.b, got, tc.want)
}
}
}
// The bridge ships probe results in initialize _meta; below-floor engines
// must surface a visible warning through Session.Diagnostics().
func TestNativeBelowFloorWarningSurfacesInDiagnostics(t *testing.T) {
providerReader, runtimeWriter := io.Pipe()
runtimeReader, providerWriter := io.Pipe()
runtimePeer := NewPeer(runtimeReader, runtimeWriter, PeerOptions{})
providerPeer := NewPeer(providerReader, providerWriter, PeerOptions{})
providerPeer.RegisterRequest("session/prompt", func(context.Context, json.RawMessage) (any, error) {
return PromptResponse{StopReason: "end_turn"}, nil
})
ctx, cancel := context.WithCancel(context.Background())
go func() { _ = runtimePeer.Start(ctx) }()
go func() { _ = providerPeer.Start(ctx) }()
t.Cleanup(func() {
cancel()
runtimePeer.Close()
providerPeer.Close()
_ = providerReader.Close()
_ = runtimeWriter.Close()
_ = runtimeReader.Close()
_ = providerWriter.Close()
})
bootstrap := sessionBootstrap{
Agent: Agent{Type: CodexNativeRegistryID},
CWD: ".",
Connection: NewConnection(runtimePeer, Client{}),
Dispose: func(context.Context) error { return nil },
InitializeResponse: InitializeResponse{
Meta: map[string]any{
"x-acp-runtime-native": map[string]any{
"engine": "codex",
"version": "0.140.0",
"verifiedFloor": "0.153.4",
"belowVerifiedFloor": true,
},
},
},
SessionResponse: NewSessionResponse{SessionID: "session-1"},
Profile: defaultAgentProfile(),
QueuePolicy: resolveQueuePolicy(QueuePolicyInput{}),
}
driver := newACPSessionDriver(bootstrap)
diag := driver.Diagnostics()
found := false
for _, warning := range diag.Warnings {
if strings.Contains(warning, "below the verified floor") {
found = true
}
}
if !found {
t.Fatalf("warnings = %v, want below-floor warning", diag.Warnings)
}
info, ok := diag.Raw["nativeEngine"].(map[string]any)
if !ok || info["engine"] != "codex" {
t.Fatalf("diagnostics raw missing nativeEngine info: %+v", diag.Raw)
}
}
// TestProbeNativeEngineVersion verifies token extraction + caching semantics
// against a command that is guaranteed present and supports --version (git).
func TestProbeNativeEngineVersion(t *testing.T) {
version, err := ProbeNativeEngineVersion(context.Background(), "git")
if err != nil {
t.Skipf("git not usable in this environment: %v", err)
}
if version == "" {
t.Fatal("empty version")
}
// Cached second call must succeed without re-running the command.
again, err := ProbeNativeEngineVersion(context.Background(), "git")
if err != nil || again != version {
t.Fatalf("cached probe = %q, %v; want %q, nil", again, err, version)
}
}