chore: import upstream snapshot with attribution
SDK Tests / changes (push) Successful in 2m29s
Real E2E Tests / changes (push) Successful in 2m29s
Deploy Docs Pages / build (push) Has been cancelled
Deploy Docs Pages / deploy (push) Has been cancelled
Real E2E Tests / JavaScript E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Python E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Java E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / C# E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Go E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Real E2E CI (push) Has been cancelled
SDK Tests / SDK CI (push) Has been cancelled
SDK Tests / CLI Tests (push) Has been cancelled
SDK Tests / Python SDK Quality (code-interpreter) (push) Has been cancelled
SDK Tests / Python SDK Quality (sandbox) (push) Has been cancelled
SDK Tests / Python SDK Tests (code-interpreter) (push) Has been cancelled
SDK Tests / JavaScript SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / JavaScript SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Python SDK Tests (sandbox) (push) Has been cancelled
SDK Tests / CLI Quality (push) Has been cancelled
SDK Tests / Kotlin SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Kotlin SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / C# SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / C# SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Go SDK Quality And Tests (push) Has been cancelled
SDK Tests / changes (push) Successful in 2m29s
Real E2E Tests / changes (push) Successful in 2m29s
Deploy Docs Pages / build (push) Has been cancelled
Deploy Docs Pages / deploy (push) Has been cancelled
Real E2E Tests / JavaScript E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Python E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Java E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / C# E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Go E2E (docker bridge) (push) Has been cancelled
Real E2E Tests / Real E2E CI (push) Has been cancelled
SDK Tests / SDK CI (push) Has been cancelled
SDK Tests / CLI Tests (push) Has been cancelled
SDK Tests / Python SDK Quality (code-interpreter) (push) Has been cancelled
SDK Tests / Python SDK Quality (sandbox) (push) Has been cancelled
SDK Tests / Python SDK Tests (code-interpreter) (push) Has been cancelled
SDK Tests / JavaScript SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / JavaScript SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Python SDK Tests (sandbox) (push) Has been cancelled
SDK Tests / CLI Quality (push) Has been cancelled
SDK Tests / Kotlin SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Kotlin SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / C# SDK Quality And Tests (code-interpreter) (push) Has been cancelled
SDK Tests / C# SDK Quality And Tests (sandbox) (push) Has been cancelled
SDK Tests / Go SDK Quality And Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { DefaultAdapterFactory } from "../dist/index.js";
|
||||
|
||||
test("DefaultAdapterFactory merges sandbox and endpoint headers for code requests", async () => {
|
||||
const recorded = [];
|
||||
const fetchImpl = async (input, init = {}) => {
|
||||
const request = input instanceof Request ? input : new Request(input, init);
|
||||
const url = new URL(request.url);
|
||||
const headers = Object.fromEntries(request.headers.entries());
|
||||
recorded.push({
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
headers,
|
||||
});
|
||||
|
||||
if (url.pathname === "/code/context") {
|
||||
return new Response(JSON.stringify({ id: "ctx-1", language: "python" }), {
|
||||
status: 200,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
return new Response(
|
||||
[
|
||||
JSON.stringify({ type: "stdout", text: "hello", timestamp: 1 }),
|
||||
JSON.stringify({ type: "execution_complete", execution_time: 2, timestamp: 2 }),
|
||||
].join("\n"),
|
||||
{
|
||||
status: 200,
|
||||
headers: { "content-type": "text/event-stream" },
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const sandbox = {
|
||||
connectionConfig: {
|
||||
headers: { "x-global": "global" },
|
||||
fetch: fetchImpl,
|
||||
sseFetch: fetchImpl,
|
||||
},
|
||||
};
|
||||
|
||||
const factory = new DefaultAdapterFactory();
|
||||
const codes = factory.createCodes({
|
||||
sandbox,
|
||||
execdBaseUrl: "http://sandbox.internal:3456",
|
||||
endpointHeaders: { "x-endpoint": "endpoint" },
|
||||
});
|
||||
|
||||
const context = await codes.createContext("python");
|
||||
assert.equal(context.id, "ctx-1");
|
||||
|
||||
const execution = await codes.run("print('hello')");
|
||||
assert.equal(execution.logs.stdout[0]?.text, "hello");
|
||||
|
||||
assert.equal(recorded.length, 2);
|
||||
assert.equal(recorded[0].url, "http://sandbox.internal:3456/code/context");
|
||||
assert.equal(recorded[0].headers["x-global"], "global");
|
||||
assert.equal(recorded[0].headers["x-endpoint"], "endpoint");
|
||||
assert.equal(recorded[1].url, "http://sandbox.internal:3456/code");
|
||||
assert.equal(recorded[1].headers["x-global"], "global");
|
||||
assert.equal(recorded[1].headers["x-endpoint"], "endpoint");
|
||||
assert.equal(recorded[1].headers.accept, "text/event-stream");
|
||||
});
|
||||
Reference in New Issue
Block a user