Secure, Fast, and Extensible Sandbox runtime for AI agents.
fix(sdk-js): preserve explicit API key in create metrics
Claire-ovo3d3f5f0d661c
diff --git a/sdks/sandbox/javascript/src/internal/lifecycleMetrics.ts b/sdks/sandbox/javascript/src/internal/lifecycleMetrics.tsindex 9a43f4148..3d0422fcd 100644--- a/sdks/sandbox/javascript/src/internal/lifecycleMetrics.ts+++ b/sdks/sandbox/javascript/src/internal/lifecycleMetrics.ts@@ -85,7 +85,7 @@ export function reportSandboxCreateMetric(};if (connectionConfig.apiKey &&- !headers["OPEN-SANDBOX-API-KEY"]+ !Object.keys(headers).some((name) => name.toLowerCase() === "open-sandbox-api-key")) {headers["OPEN-SANDBOX-API-KEY"] = connectionConfig.apiKey;}diff --git a/sdks/sandbox/javascript/tests/sandbox.create.test.mjs b/sdks/sandbox/javascript/tests/sandbox.create.test.mjsindex 635b0fd06..e427947ad 100644--- a/sdks/sandbox/javascript/tests/sandbox.create.test.mjs+++ b/sdks/sandbox/javascript/tests/sandbox.create.test.mjs@@ -535,6 +535,35 @@ test("Sandbox.create reports create metrics after ready", async () => {assert.match(ua, /^OpenSandbox-JS-SDK\//);});+for (const headerName of ["open-sandbox-api-key", "Open-Sandbox-Api-Key"]) {+ test(`Sandbox.create metrics preserves explicit ${headerName}`, async (t) => {+ const { adapterFactory } = createAdapterFactory();+ const config = new ConnectionConfig({+ domain: "http://127.0.0.1:8080",+ apiKey: "fallback-key",+ headers: { [headerName]: "explicit-key" },+ }).withTransportIfMissing();+ t.after(() => config.closeTransport());+ const requests = [];+ Object.defineProperty(config, "fetch", {+ get: () => async (url, init) => {+ requests.push(new Request(url, init));+ return new Response(null);+ },+ });+ const sandbox = await Sandbox.create({+ adapterFactory,+ connectionConfig: config,+ image: "python:3.12",+ skipHealthCheck: true,+ });+ t.after(() => sandbox.close());+ assert.equal(requests.length, 1);+ assert.match(requests[0].url, /\/metrics\/events$/);+ assert.equal(requests[0].headers.get("open-sandbox-api-key"), "explicit-key");+ });+}+test("Sandbox.create metrics failure does not change create error", async () => {const { adapterFactory } = createAdapterFactory();adapterFactory.createExecdStack = () => ({