Skip to content

Commit 74e2c2a

Browse files
committed
fix(test): scope sandbox dependencies for bun's isolated linker
Two failures the previous yarn flat-hoist masked: 1. vertex-ai: `version: '*'` resolves to `google-auth-library@10`, but every published `@google-cloud/vertexai` declares its transitive at `^9.0.0`. Bun's isolated linker keeps both physical copies — the test stubs `GoogleAuth.prototype.getAccessToken` on the @10 copy, the SDK loads the @9 copy at run-time, the stub never applies, and the real credential lookup throws `GoogleAuthError`. Pin the direct dep to `^9.0.0` so bun dedupes to a single `.bun/google-auth-library@9.x.y` entry and the prototype stub propagates to the SDK. 2. ai: `@ai-sdk/ui-utils` ranges `zod-to-json-schema` at `^3.0.0` and `ai@4.0.2` ranges `zod` at `^3.0.0`; bun picks `zod-to-json-schema@3.25.2` next to `zod@3.23.8`. `3.25.x` switched its zod imports to the `zod/v3` subpath, which only exists in `zod@>=3.25.32` and `zod@4`, so the sandbox crashes at load time with `ERR_PACKAGE_PATH_NOT_EXPORTED`. Bun does not honour nested overrides (oven-sh/bun#6608), so a flat `zod-to-json-schema: <3.25.0` override is the only shape that works; the only other consumer (`langchain` / `langgraph`) declares `>=3.0.0` and the constraint still holds.
1 parent c737eca commit 74e2c2a

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

packages/dd-trace/test/plugins/externals.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ module.exports = {
2323
versions: ['>=3.25.75'],
2424
// `ai@4.0.2` declares `zod` as an optional peer (`^3.0.0`) and
2525
// `@ai-sdk/openai@1.3.23+` declares it as a required peer. Yarn 1's flat
26-
// hoist served the standalone `zod` workspace's copy from the workspace
27-
// root to both sandboxes; bun's isolated linker honours each package's
28-
// own manifest and skips optional peers entirely, so the `versions/ai@`
29-
// sandbox lands without `zod` and `require('zod')` crashes at load time.
30-
// `dep: true` injects `zod` as a direct dep of the `versions/ai@`
31-
// sandbox so bun materialises it alongside `ai` in the isolated store.
26+
// hoist served the workspace root's `zod` to both consumers; bun's
27+
// isolated linker honours each package's own manifest and skips optional
28+
// peers entirely, so without `dep: true` the `versions/ai@` sandbox
29+
// lands without `zod` and `require('zod')` crashes at load time. The
30+
// matching `zod-to-json-schema` override in `install_plugin_modules.js`
31+
// keeps the transitive zod chain on a `zod@3`-compatible version.
3232
dep: true,
3333
},
3434
],
@@ -264,12 +264,15 @@ module.exports = {
264264
// `google-auth-library` is a regular transitive of `@google-cloud/vertexai`,
265265
// so under bun's isolated linker it lives in vertexai's private store and
266266
// isn't reachable from the workspace root. Inject it as a direct dep of
267-
// every vertexai sandbox so the test's `getExport` lookup resolves
268-
// (the same shape as the bedrock-runtime fix above).
267+
// every vertexai sandbox so the test's `getExport` lookup resolves.
268+
// Pin to vertexai's own `^9.0.0` range (every published version still
269+
// declares it) so bun dedupes the direct dep and the SDK's transitive to
270+
// a single physical `.bun/google-auth-library@9.x.y` entry — the prototype
271+
// stub only propagates to the SDK when both resolve to the same realpath.
269272
'@google-cloud/vertexai': [
270273
{
271274
name: 'google-auth-library',
272-
version: '*',
275+
version: '^9.0.0',
273276
dep: true,
274277
forced: true,
275278
},

scripts/install_plugin_modules.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,25 @@ async function assertWorkspaces () {
388388
// for the langchain-openai pair without affecting the
389389
// `@langchain/openai@1.x.x` peer constraint resolved elsewhere in
390390
// the workspace.
391+
// - `zod-to-json-schema@>=3.25.0` switched its zod imports to the
392+
// `zod/v3` subpath, which only exists in `zod@>=3.25.32` and
393+
// `zod@>=4`. `@ai-sdk/ui-utils` (the `ai@4.0.2` UI helper) declares
394+
// `zod-to-json-schema: ^3.0.0` and pulls in `zod@^3.0.0` itself, so
395+
// the isolated linker lands `zod-to-json-schema@3.25.2` next to a
396+
// `zod@3.23.x` that has no `/v3` subpath, crashing at load time
397+
// with `Package subpath './v3' is not defined`. The previous
398+
// package manager hid this because its flat hoist served the
399+
// workspace root's `zod@4` to every consumer. Pin the transitive
400+
// globally to the last 3.x release that still imports from `zod`
401+
// directly so the `ai@4.x` sandbox loads; the only other consumer
402+
// (`langchain`/`langgraph`) declares `zod-to-json-schema >=3.0.0`
403+
// and `<3.25.0` satisfies that range too. Bun does not support
404+
// nested override keys (oven-sh/bun#6608), so a flat key is
405+
// required here even though only the ai sandbox needs it.
391406
overrides: {
392407
collections: '^5.0.0',
393408
'@langchain/openai@0.0.34/@langchain/core': '^0.2.0',
409+
'zod-to-json-schema': '<3.25.0',
394410
},
395411
trustedDependencies: [...trustedDependencies].sort(),
396412
}, null, 2) + '\n'),

0 commit comments

Comments
 (0)