Files
open-multi-agent/scripts/observability-example-smoke.mjs
T
Jack Chen 7d6ea6c519 test: resolve tsx CLI through Node module resolution
The eval CLI tests and the two example smoke scripts located tsx with a
fixed number of `..` segments, assuming a hoisted install directly above
the workspace. A git worktree has no local node_modules and resolves
upwards to the main checkout, and a non-hoisted install keeps
node_modules inside the workspace, so the path pointed at nothing:
spawnSync failed to launch and 12 tests reported `status: null` instead
of a CLI exit code.

Resolve `tsx/cli` through Node's own module resolution behind a shared
tests/helpers/tsx-cli.ts, and spawn it with process.execPath rather than
executing the node_modules/.bin shim, which is a .cmd wrapper on Windows
that spawnSync cannot launch without a shell. `.bin/tsx` already links
to the same dist/cli.mjs, so the spawned command is unchanged.

Contributors can now run the full core suite directly from a worktree
without hand-linking tsx.
2026-07-26 20:19:54 +08:00

37 lines
1.2 KiB
JavaScript

import { spawn } from 'node:child_process'
import { createRequire } from 'node:module'
import { fileURLToPath } from 'node:url'
import { join } from 'node:path'
const root = fileURLToPath(new URL('..', import.meta.url))
// Resolved rather than joined onto `root`: a git worktree has no local
// `node_modules` and resolves upwards to the main checkout.
const tsx = createRequire(import.meta.url).resolve('tsx/cli')
const directory = join(root, 'packages', 'core', 'examples', 'integrations', 'observability-v2')
const examples = [
'batching-exporter.ts',
'in-memory-store.ts',
'file-trace-store.ts',
'otel-provider.ts',
'cli-lifecycle.ts',
'server-lifecycle.ts',
'serverless-lifecycle.ts',
]
for (const example of examples) {
await new Promise((resolve, reject) => {
const child = spawn(process.execPath, [tsx, join(directory, example)], {
cwd: root,
stdio: 'inherit',
env: { ...process.env, NO_COLOR: '1' },
})
child.once('error', reject)
child.once('exit', (code, signal) => {
if (code === 0) resolve()
else reject(new Error(`${example} failed with code ${code ?? 'null'} signal ${signal ?? 'none'}`))
})
})
}
console.log(`observability example smoke: ${examples.length} passed`)