Skip to content

Commit f4c69c6

Browse files
RulaKhaledclaude
andcommitted
test(server-utils): Make the trace continuation assertions provable
Both cases passed vacuously. `not.toBe(TRACE_ID)` on the malformed carrier also held when no agent span was opened at all, since `undefined` is not the carrier's id either; suppressing span creation entirely failed nine other tests and left that one green. And the active-trace case never checked the span landed on the surrounding request's trace, so continuing an unrelated new trace passed too. Now the first asserts a well-formed trace id, and the second asserts the agent span carries the `incoming request` span's own trace id. Dropping the `!getActiveSpan()` guard fails the second. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent a66a8ea commit f4c69c6

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎packages/server-utils/test/ai/lib/tracing/flue.test.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,23 @@ describe('createFlueInstrumentation', () => {
202202
async () => undefined,
203203
);
204204

205+
// Asserting a well-formed id, not just "not the carrier's": the span has to still be opened
206+
// on a fresh trace, and `not.toBe` alone would also pass if no span were opened at all.
207+
expect(agentTraceId()).toMatch(/^[0-9a-f]{32}$/);
205208
expect(agentTraceId()).not.toBe(TRACE_ID);
206209
});
207210

208211
// An in-process dispatch is genuinely part of the surrounding trace; continuing the persisted
209212
// one would detach it from the request it is actually running inside.
210213
it('keeps the active trace when one is already running', async () => {
211-
await startSpan({ name: 'incoming request' }, async () => {
214+
let requestTraceId: string | undefined;
215+
216+
await startSpan({ name: 'incoming request' }, async span => {
217+
requestTraceId = spanToStaticSpanJSON(span).trace_id;
212218
await instrumentation.interceptor(AGENT_OP, { ...AGENT_CTX, traceCarrier: CARRIER }, async () => undefined);
213219
});
214220

215-
expect(agentTraceId()).not.toBe(TRACE_ID);
221+
expect(agentTraceId()).toBe(requestTraceId);
216222
});
217223
});
218224

0 commit comments

Comments
 (0)