Skip to content

Commit 8514d56

Browse files
committed
test(llmobs): resolve the agents openai client from the loaded package
The LLMObs spec anchored `openai` at `versions/node_modules/@openai/agents-openai`, a hoisted path bun's isolated linker never creates, so the suite failed at its `before` hook with `Cannot find module 'openai'`. Resolving from the loaded `@openai/agents-openai` build pins the copy that build itself uses, the same way the APM plugin setup now does.
1 parent c78b854 commit 8514d56

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

packages/dd-trace/test/llmobs/plugins/openai-agents/index.spec.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const assert = require('node:assert/strict')
4-
const path = require('node:path')
4+
const { createRequire } = require('node:module')
55

66
const { withVersions } = require('../../../setup/mocha')
77

@@ -80,13 +80,12 @@ describe('integrations', () => {
8080
before(() => {
8181
agentsCore = require(`../../../../../../versions/@openai/agents@${version}`).get()
8282

83-
const { OpenAIChatCompletionsModel, OpenAIResponsesModel } =
84-
require(`../../../../../../versions/@openai/agents-openai@${version}`).get()
83+
const agentsOpenai = require(`../../../../../../versions/@openai/agents-openai@${version}`)
84+
const { OpenAIChatCompletionsModel, OpenAIResponsesModel } = agentsOpenai.get()
8585

86-
const agentsOpenaiDir = path.join(
87-
__dirname, '..', '..', '..', '..', '..', '..', 'versions', 'node_modules', '@openai', 'agents-openai'
88-
)
89-
const openaiPath = require.resolve('openai', { paths: [agentsOpenaiDir] })
86+
// Resolve from the loaded package so the client class comes from the `openai` copy this
87+
// `@openai/agents-openai` build uses, rather than whichever copy the layout happens to hoist.
88+
const openaiPath = createRequire(agentsOpenai.getPath()).resolve('openai')
9089
const { OpenAI } = require(openaiPath)
9190

9291
const mockClient = new OpenAI({

0 commit comments

Comments
 (0)