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
  • introduce build verification and improved auto selection via node exports for different environments

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
@cpinn cpinn requested a review from knjiang as a code owner January 16, 2026 23:34
@ibolmo ibolmo mentioned this pull request Jan 17, 2026
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

@cpinn
Copy link
Contributor Author

cpinn commented Jan 20, 2026

okay I removed a couple of the dead files and removed the noExternal change I had made after we made the deno test changes.

once smoke-v2 is merged in we can update the compatibility dates for the cloudflare tests. Update: discussed and we plan to keep the older compatibility dates for wrangler and the specific newer date that is required for vite+cloudflare plugin

ibolmo and others added 2 commits January 20, 2026 15:43
## Braintrust JS SDK Smoke Tests v2

### Design Principles

1. **Well-Known Tarball Paths**: Uses version-agnostic paths like
`braintrust-latest.tgz` so package.json never changes
2. **Build Before Install**: Ensures artifacts exist before npm tries to
install them
3. **Track Lock Files**: Commits lock files to catch transitive
dependency issues
4. **Makefile as Source of Truth**: Single clear interface (`make test`)
for every scenario
5. **Expected Failures Support**: Uses `xfail` status to document known
platform limitations without failing tests

### Quick Start

```bash
# Run all scenarios
make test

# Run specific scenario
make test otel-v1

# List available scenarios
make list
```

### What's Improved from v1

- ✅ No version-specific tarballs (eliminates package.json churn)
- ✅ Peer dependencies fully specified (no `--legacy-peer-deps`
workaround)
- ✅ Auto-discovery (no manual registration)
- ✅ Shared test package for DRY test logic
- ✅ Lock files tracked (surfaces packaging issues early)

This infrastructure ensures the Braintrust SDK "just works" across the
JavaScript ecosystem's diverse runtime landscape.
"@std/assert": "jsr:@std/assert@^1.0.14",
"@braintrust/smoke-test-shared": "jsr:@braintrust/smoke-test-shared",
"braintrust": "npm:braintrust@^2.0.2"
"braintrust": "npm:braintrust"
Copy link
Collaborator

Choose a reason for hiding this comment

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

avoid us having to update this

cd ../../.. && pnpm exec turbo build --filter=braintrust; \
fi; \
fi
if [ -n "$(BRAINTRUST_TAR)" ]; then \
Copy link
Collaborator

Choose a reason for hiding this comment

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

we shouldn't care to rebuild lcoally. the tar is important for ci

echo "==> Building SDK for workspace link"; \
cd ../../.. && pnpm exec turbo build --filter=braintrust; \
fi; \
deno install
Copy link
Collaborator

Choose a reason for hiding this comment

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

deno install seems to ignore the links directive and tries to grab from npm.

ibolmo and others added 5 commits January 20, 2026 16:52
This PR updates default entrypoint selection so each runtime resolves
the correct build. Node environments select the Node entrypoint, while
browser and worker environments default to the browser build.

Worker runtimes no longer implicitly resolve the Node build. Importing
braintrust/node must be done explicitly and is expected to fail in
workers (e.g. cloudflare-vite-hono-vite-dev-node-esm), rather than
failing due to accidental default resolution.

PR changes:

The change uses Node’s conditional exports to ensure the correct build
is selected based on runtime capabilities, instead of relying on
ambiguous defaults.

Each scenario now checks that the appropriate isomorphic build type
(Node vs browser) is selected and that module resolution lands on the
correct output files for that environment.
Simpler testing/expecting and ensure all scenarios are running all the
things.

Currently CI shows failing because of ALS not working in /browser.
Expected for now.
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