From 9eed387cb587e2405b848e3906da427584796f58 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Thu, 1 Oct 2026 08:22:53 +0200 Subject: [PATCH] test(node): Wait for TypeSafe channel subscription in ESM scenario On Node < 24.13 the ESM build is transformed on the Module.register loader thread, which reports the injection over a MessagePort. The integration can subscribe after the scenario's first call, leaving it uninstrumented. Co-Authored-By: Claude Opus 5.5 --- .../suites/tracing/typesafe/scenario.mjs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/dev-packages/node-integration-tests/suites/tracing/typesafe/scenario.mjs b/dev-packages/node-integration-tests/suites/tracing/typesafe/scenario.mjs index 694a9fd97d59..50c4df8606c2 100644 --- a/dev-packages/node-integration-tests/suites/tracing/typesafe/scenario.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/typesafe/scenario.mjs @@ -1,6 +1,7 @@ import * as Sentry from '@sentry/node'; import { choice, noul, score, TypeSafeClient } from '@typesafe-ai/sdk'; import express from 'express'; +import { tracingChannel } from 'node:diagnostics_channel'; function startMockServer() { const app = express(); @@ -41,7 +42,17 @@ function startMockServer() { }); } +// On Node < 24.13 the ESM build is transformed on the `Module.register` loader thread, which reports the +// injection back over a `MessagePort`, so the integration may subscribe only after this module starts running. +async function waitForSubscription() { + const channel = tracingChannel('orchestrion:@typesafe-ai/sdk:system-one'); + while (!channel.start.hasSubscribers) { + await new Promise(resolve => setTimeout(resolve, 10)); + } +} + async function run() { + await waitForSubscription(); const server = await startMockServer(); const client = new TypeSafeClient({ apiKey: 'mock-api-key',