MCPcopy Index your code
hub / github.com/coder/coder / TestGuessSessionID

Function TestGuessSessionID

aibridge/session_test.go:15–230  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestGuessSessionID(t *testing.T) {
16 t.Parallel()
17
18 cases := []struct {
19 name string
20 client aibridge.Client
21 body string
22 headers map[string]string
23 sessionID *string
24 }{
25 // Claude Code.
26 {
27 name: "claude_code_header_takes_precedence",
28 client: aibridge.ClientClaudeCode,
29 headers: map[string]string{"X-Claude-Code-Session-Id": "header-session-id"},
30 body: `{"metadata":{"user_id":"user_abc123_account_456_session_body-session-id"}}`,
31 sessionID: utils.PtrTo("header-session-id"),
32 },
33 {
34 name: "claude_code_header_only",
35 client: aibridge.ClientClaudeCode,
36 headers: map[string]string{"X-Claude-Code-Session-Id": "aabb-ccdd"},
37 body: `{"model":"claude-3"}`,
38 sessionID: utils.PtrTo("aabb-ccdd"),
39 },
40 {
41 name: "claude_code_empty_header_falls_back_to_body",
42 client: aibridge.ClientClaudeCode,
43 headers: map[string]string{"X-Claude-Code-Session-Id": ""},
44 body: `{"metadata":{"user_id":"user_abc123_account_456_session_f47ac10b-58cc-4372-a567-0e02b2c3d479"}}`,
45 sessionID: utils.PtrTo("f47ac10b-58cc-4372-a567-0e02b2c3d479"),
46 },
47 {
48 name: "claude_code_whitespace_header_falls_back_to_body",
49 client: aibridge.ClientClaudeCode,
50 headers: map[string]string{"X-Claude-Code-Session-Id": " "},
51 body: `{"metadata":{"user_id":"user_abc123_account_456_session_f47ac10b-58cc-4372-a567-0e02b2c3d479"}}`,
52 sessionID: utils.PtrTo("f47ac10b-58cc-4372-a567-0e02b2c3d479"),
53 },
54 {
55 name: "claude_code_with_valid_session",
56 client: aibridge.ClientClaudeCode,
57 body: `{"metadata":{"user_id":"user_abc123_account_456_session_f47ac10b-58cc-4372-a567-0e02b2c3d479"}}`,
58 sessionID: utils.PtrTo("f47ac10b-58cc-4372-a567-0e02b2c3d479"),
59 },
60 {
61 name: "claude_code_with_valid_session_new_format",
62 client: aibridge.ClientClaudeCode,
63 body: `{"metadata":{"user_id":"{\"device_id\":\"45aa15c8c244ea2582f8144dde91a50ec3815851f6f648abef4ee15b173cc927\",\"account_uuid\":\"\",\"session_id\":\"54c1eb09-bc4c-4d2f-98eb-6d2ab2d5e2fe\"}"}}`,
64 sessionID: utils.PtrTo("54c1eb09-bc4c-4d2f-98eb-6d2ab2d5e2fe"),
65 },
66 {
67 name: "claude_code_new_format_empty_session_id",
68 client: aibridge.ClientClaudeCode,
69 body: `{"metadata":{"user_id":"{\"device_id\":\"abc\",\"account_uuid\":\"\",\"session_id\":\"\"}"}}`,
70 },
71 {
72 name: "claude_code_new_format_no_session_id_field",

Callers

nothing calls this directly

Calls 7

PtrToFunction · 0.92
GuessSessionIDFunction · 0.92
RunMethod · 0.65
ContextMethod · 0.65
SetMethod · 0.65
EqualMethod · 0.45
ReadAllMethod · 0.45

Tested by

no test coverage detected