@@ -35,7 +35,7 @@ func TestNormalizeURL(t *testing.T) {
3535// ---------- New ----------
3636
3737func TestNew_CreatesClient (t * testing.T ) {
38- c := New ("test-key" , "http://localhost:1234" )
38+ c := New ("test-key" , "http://localhost:1234" , "" )
3939 if c == nil {
4040 t .Fatal ("expected non-nil client" )
4141 }
@@ -54,14 +54,14 @@ func TestNew_CreatesClient(t *testing.T) {
5454}
5555
5656func TestNew_TrimsTrailingSlash (t * testing.T ) {
57- c := New ("key" , "http://example.com/" )
57+ c := New ("key" , "http://example.com/" , "" )
5858 if c .apiURL != "http://example.com" {
5959 t .Errorf ("expected trailing slash trimmed, got %q" , c .apiURL )
6060 }
6161}
6262
6363func TestNew_EmptyURL (t * testing.T ) {
64- c := New ("key" , "" )
64+ c := New ("key" , "" , "" )
6565 if c .apiURL != "" {
6666 t .Errorf ("expected empty apiURL, got %q" , c .apiURL )
6767 }
@@ -87,7 +87,7 @@ func TestRawGet_Success(t *testing.T) {
8787 }))
8888 defer ts .Close ()
8989
90- c := New ("my-key" , ts .URL )
90+ c := New ("my-key" , ts .URL , "" )
9191 var result map [string ]string
9292 err := c .RawGet (context .Background (), "/test/path" , & result )
9393 if err != nil {
@@ -104,7 +104,7 @@ func TestRawGet_HTTPError(t *testing.T) {
104104 }))
105105 defer ts .Close ()
106106
107- c := New ("key" , ts .URL )
107+ c := New ("key" , ts .URL , "" )
108108 var result map [string ]any
109109 err := c .RawGet (context .Background (), "/fail" , & result )
110110 if err == nil {
@@ -122,7 +122,7 @@ func TestRawGet_NilResult(t *testing.T) {
122122 }))
123123 defer ts .Close ()
124124
125- c := New ("key" , ts .URL )
125+ c := New ("key" , ts .URL , "" )
126126 err := c .RawGet (context .Background (), "/path" , nil )
127127 if err != nil {
128128 t .Fatalf ("unexpected error: %v" , err )
@@ -147,7 +147,7 @@ func TestRawPost_Success(t *testing.T) {
147147 }))
148148 defer ts .Close ()
149149
150- c := New ("key" , ts .URL )
150+ c := New ("key" , ts .URL , "" )
151151 var result map [string ]string
152152 err := c .RawPost (context .Background (), "/create" , map [string ]any {"name" : "test" }, & result )
153153 if err != nil {
@@ -165,7 +165,7 @@ func TestRawPost_NilBody(t *testing.T) {
165165 }))
166166 defer ts .Close ()
167167
168- c := New ("key" , ts .URL )
168+ c := New ("key" , ts .URL , "" )
169169 err := c .RawPost (context .Background (), "/path" , nil , nil )
170170 if err != nil {
171171 t .Fatalf ("unexpected error: %v" , err )
@@ -187,7 +187,7 @@ func TestRawDelete_Success(t *testing.T) {
187187 }))
188188 defer ts .Close ()
189189
190- c := New ("key" , ts .URL )
190+ c := New ("key" , ts .URL , "" )
191191 err := c .RawDelete (context .Background (), "/items/abc" , nil )
192192 if err != nil {
193193 t .Fatalf ("unexpected error: %v" , err )
@@ -200,7 +200,7 @@ func TestRawDelete_HTTPError(t *testing.T) {
200200 }))
201201 defer ts .Close ()
202202
203- c := New ("key" , ts .URL )
203+ c := New ("key" , ts .URL , "" )
204204 err := c .RawDelete (context .Background (), "/missing" , nil )
205205 if err == nil {
206206 t .Fatal ("expected error for 404" )
@@ -219,13 +219,11 @@ func TestRawRequest_SetsAPIKeyHeader(t *testing.T) {
219219 }))
220220 defer ts .Close ()
221221
222- c := New ("secret-key" , ts .URL )
222+ c := New ("secret-key" , ts .URL , "" )
223223 _ = c .RawGet (context .Background (), "/test" , nil )
224224}
225225
226226func TestRawRequest_SetsWorkspaceHeader (t * testing.T ) {
227- t .Setenv ("LANGSMITH_WORKSPACE_ID" , "ws-123" )
228-
229227 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
230228 if got := r .Header .Get ("x-tenant-id" ); got != "ws-123" {
231229 t .Errorf ("expected x-tenant-id=ws-123, got %q" , got )
@@ -235,13 +233,11 @@ func TestRawRequest_SetsWorkspaceHeader(t *testing.T) {
235233 }))
236234 defer ts .Close ()
237235
238- c := New ("key" , ts .URL )
236+ c := New ("key" , ts .URL , "ws-123" )
239237 _ = c .RawGet (context .Background (), "/test" , nil )
240238}
241239
242240func TestRawRequest_NoWorkspaceHeaderWhenUnset (t * testing.T ) {
243- t .Setenv ("LANGSMITH_WORKSPACE_ID" , "" )
244-
245241 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
246242 if got := r .Header .Get ("x-tenant-id" ); got != "" {
247243 t .Errorf ("expected empty x-tenant-id, got %q" , got )
@@ -251,14 +247,14 @@ func TestRawRequest_NoWorkspaceHeaderWhenUnset(t *testing.T) {
251247 }))
252248 defer ts .Close ()
253249
254- c := New ("key" , ts .URL )
250+ c := New ("key" , ts .URL , "" )
255251 _ = c .RawGet (context .Background (), "/test" , nil )
256252}
257253
258254// ---------- Error cases ----------
259255
260256func TestRawGet_InvalidURL (t * testing.T ) {
261- c := New ("key" , "http://127.0.0.1:1" ) // unlikely to be listening
257+ c := New ("key" , "http://127.0.0.1:1" , "" ) // unlikely to be listening
262258 err := c .RawGet (context .Background (), "/test" , nil )
263259 if err == nil {
264260 t .Fatal ("expected error for unreachable server" )
@@ -272,7 +268,7 @@ func TestRawGet_InvalidJSON(t *testing.T) {
272268 }))
273269 defer ts .Close ()
274270
275- c := New ("key" , ts .URL )
271+ c := New ("key" , ts .URL , "" )
276272 var result map [string ]any
277273 err := c .RawGet (context .Background (), "/test" , & result )
278274 if err == nil {
@@ -291,7 +287,7 @@ func TestRawRequest_400Error(t *testing.T) {
291287 }))
292288 defer ts .Close ()
293289
294- c := New ("key" , ts .URL )
290+ c := New ("key" , ts .URL , "" )
295291 err := c .RawGet (context .Background (), "/test" , nil )
296292 if err == nil {
297293 t .Fatal ("expected error for 400" )
@@ -307,7 +303,7 @@ func TestRawRequest_500Error(t *testing.T) {
307303 }))
308304 defer ts .Close ()
309305
310- c := New ("key" , ts .URL )
306+ c := New ("key" , ts .URL , "" )
311307 err := c .RawPost (context .Background (), "/test" , map [string ]string {"a" : "b" }, nil )
312308 if err == nil {
313309 t .Fatal ("expected error for 500" )
@@ -336,7 +332,7 @@ func TestRawDo_ReturnsStatusAndBody(t *testing.T) {
336332 }))
337333 defer ts .Close ()
338334
339- c := New ("my-key" , ts .URL )
335+ c := New ("my-key" , ts .URL , "" )
340336 status , hdr , body , err := c .RawDo (context .Background (), "PATCH" , "/api/v1/sessions" , nil , nil )
341337 if err != nil {
342338 t .Fatalf ("unexpected error: %v" , err )
@@ -360,7 +356,7 @@ func TestRawDo_WithBodyReader(t *testing.T) {
360356 }))
361357 defer ts .Close ()
362358
363- c := New ("key" , ts .URL )
359+ c := New ("key" , ts .URL , "" )
364360 status , _ , body , err := c .RawDo (context .Background (), "POST" , "/create" , strings .NewReader (`{"name":"test"}` ), nil )
365361 if err != nil {
366362 t .Fatalf ("unexpected error: %v" , err )
@@ -386,7 +382,7 @@ func TestRawDo_ExtraHeaders(t *testing.T) {
386382 }))
387383 defer ts .Close ()
388384
389- c := New ("key" , ts .URL )
385+ c := New ("key" , ts .URL , "" )
390386 extra := http.Header {"X-Custom" : []string {"hello" }}
391387 _ , _ , _ , err := c .RawDo (context .Background (), "GET" , "/test" , nil , extra )
392388 if err != nil {
@@ -401,7 +397,7 @@ func TestRawDo_Returns4xxWithoutError(t *testing.T) {
401397 }))
402398 defer ts .Close ()
403399
404- c := New ("key" , ts .URL )
400+ c := New ("key" , ts .URL , "" )
405401 status , _ , body , err := c .RawDo (context .Background (), "GET" , "/test" , nil , nil )
406402 if err != nil {
407403 t .Fatalf ("unexpected error: %v" , err )
@@ -417,14 +413,14 @@ func TestRawDo_Returns4xxWithoutError(t *testing.T) {
417413// ---------- Accessors ----------
418414
419415func TestAPIKey (t * testing.T ) {
420- c := New ("secret" , "http://localhost" )
416+ c := New ("secret" , "http://localhost" , "" )
421417 if c .APIKey () != "secret" {
422418 t .Errorf ("expected secret, got %q" , c .APIKey ())
423419 }
424420}
425421
426422func TestAPIURL (t * testing.T ) {
427- c := New ("key" , "http://localhost:1234" )
423+ c := New ("key" , "http://localhost:1234" , "" )
428424 if c .APIURL () != "http://localhost:1234" {
429425 t .Errorf ("expected http://localhost:1234, got %q" , c .APIURL ())
430426 }
0 commit comments