Skip to content

Conversation

@cpinn
Copy link
Contributor

@cpinn cpinn commented Jan 15, 2026

Problem
Cloudflare Workers are encountering compatibility issues with certain dependencies in the Braintrust SDK. These issues surface particularly in restrictive runtime environments and how some dependencies behave in Vite-based builds.

Changes

  • Add additional test coverage for cloudflare workers:
    • braintrust, braintrust/browser and nodejs_compat flag
    • vite cloudflare test
  • introduce browser specific configuration to drop nunjucks template support in browser

Maintain this existing build structure:
braintrust (CJS) -> node
braintrust (ESM) -> node
braintrust/browser -> no cli, no filesystem, no git, no nunjucks

@cpinn cpinn force-pushed the caitlin/externalize branch from b716030 to 8d2e5e2 Compare January 16, 2026 05:15
@cpinn cpinn changed the base branch from main to add-vite-cloudflare-test January 16, 2026 05:16
@cpinn cpinn changed the base branch from add-vite-cloudflare-test to main January 16, 2026 05:16
@cpinn cpinn changed the title add multiple cloudflare tests and change bundling for the browser build improvde cloudflare support Jan 16, 2026
@cpinn cpinn changed the title improvde cloudflare support improved cloudflare worker support Jan 16, 2026
@cpinn cpinn requested a review from ibolmo January 16, 2026 18:50
@ibolmo ibolmo mentioned this pull request Jan 17, 2026
environment === "cloudflare-worker-browser-no-compat" ||
environment === "cloudflare-worker-browser-node-compat" ||
environment === "nextjs-edge-runtime" ||
environment === "vite-react-hono") &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not excited for this. i think instead of having the shared tests we should make the nunjucks/rendering be specific per smoke test. this way we avoid this complexity and makes maintenance easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't changed this because I am actually still a bit annoyed about removing the support from all these places. I get we need to do something for vite but I am still not necessarily on board with dropping everything so I didn't really want to put effort into doing something there until we 100% decided that was the stance we wanted to take.

Same with some of the other cleanup.

import * as braintrust from "braintrust/browser";
import { createWorker } from "./worker";

export default createWorker(braintrust, "cloudflare-worker-browser-no-compat");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is not at the moment with the way the files are setup.

import * as braintrust from "braintrust";
import { createWorker } from "./worker";

export default createWorker(braintrust, "cloudflare-worker-node-node-compat");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate?

runImportVerificationTests,
runPromptTemplatingTests,
type TestResult,
} from "../../../shared/dist/index.mjs";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just realized we're importing from shared/dist. shouldn't we let each environment decide if it will import from cjs or mjs?

const adapters = await setupTestEnvironment({
initLogger,
testingExports: _exportsForTestingOnly,
canUseFileSystem: false,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"description": "Smoke test for Braintrust Node build in Deno runtime",
"private": true,
"scripts": {
"test": "deno test --no-config --import-map=./deno.json --lock=deno.lock --allow-env --allow-read=.,../build --allow-net shared_suite_test.ts span_test.ts"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto is this needed?

} from "../../../../shared/dist/index.mjs";

import * as braintrust from "braintrust";
import * as braintrust from "braintrust/browser";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might need two versions. one that is browser and one that is node.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we will not learn something new, though 🤔 but i know this test the particular interesting one is the dev mode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The node one will always fail. Nunjucks and vite do not work together. if you use vite you need to use browser.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"name": "braintrust-vite-react-hono-smoke-test",
"main": "./src/worker/index.ts",
"compatibility_date": "2025-01-15",
"compatibility_flags": ["nodejs_compat"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here did we want to try without compat? maybe the same results

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting as well the min. 2025-01-15

Copy link
Contributor Author

@cpinn cpinn Jan 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can. I did that in the other tests.

I do wonder how useful it is without the compat in general since then you lose all the hierarchy. I think that would be a pretty annoying span experience.

return process.env[name];
};

iso.renderNunjucksString = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we still need nunjucks-env.browser.ts and nunjucks-utils.browser.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no they were from some issue I thought I was running into with the deno build and I had been waiting to see if this build finally passed.

import { _internalSetInitialState } from "./logger";
import { promisify } from "util";
import * as zlib from "zlib";
import { renderNunjucksString as nunjucksRender } from "./template/nunjucks-env";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something to consider for the future (or perhaps the ai is quick to do this).

i previously added a lint rule to disallow import from cli in the sdk/js.

what if we had a sdk/js/node and sdk/js/browser ... we then move files in two each of those. we could say that nothing is allowed to depend on sdk/js/node/** unless the it stems from node.ts, and same with browser.ts

entry: ["src/browser.ts"],
format: ["cjs", "esm"],
outDir: "dist",
removeNodeProtocol: false,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibolmo should this be false? it was false when I cherry picked the change but I was confused why we would want it false for the browser build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants