test(server): prove execution span overlap with explicit barriers (#16712)

Prove overlapping execution spans with per-run promise barriers, live recording checks, and exported span identity matching. Preserve the existing run ownership, parent, ingress-link, count, and test-budget assertions.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
DottaandPaperclip authored and GitHub committed 2026-10-18 03:00:21 -05:00
1 parent bfadb66556
commit 8de28c12e4
1 file changed
+25 -5
@@ -32,11 +32,29 @@ afterEach(async () => {
it("parents overlapping preparation and response work to their own execution attempts independently of ingress sampling", async () => {
const trigger = { traceId: "1".repeat(32), spanId: "2".repeat(16), traceFlags: TraceFlags.NONE, isRemote: true };
const overlappingSpanIds = new Map<string, { source: string | undefined; readers: string | undefined }>();
await context.with(trace.setSpanContext(context.active(), trigger), () => Promise.all(["one", "two"].map(runId =>
withRunExecutionTiming(runId, async () => {
let sourceSpan: ReturnType<typeof trace.getActiveSpan>, readersSpan: ReturnType<typeof trace.getActiveSpan>;
let started!: () => void, checked!: () => void;
const bothStarted = new Promise<void>(resolve => { started = resolve; });
const bothChecked = new Promise<void>(resolve => { checked = resolve; });
let arrivals = 0, observations = 0;
const assertOverlap = async () => {
if (++arrivals === 2) started();
await bothStarted;
try {
expect(sourceSpan?.isRecording()).toBe(true);
expect(readersSpan?.isRecording()).toBe(true);
} finally {
if (++observations === 2) checked();
}
await bothChecked;
};
await createRunPreparationTiming(runId)("workspace", () => Promise.all([
measureRunPhase("workspace.sources", async () => {
await Promise.resolve();
sourceSpan = trace.getActiveSpan();
await assertOverlap();
await measureRunPhase("workspace.sources.alias_scan", () => {
const parent = getActiveStepContext()?.parentContext;
expect(parent).toBeDefined();
@@ -44,8 +62,12 @@ it("parents overlapping preparation and response work to their own execution att
expect(getRunExecutionTraceContext(runId === "one" ? "two" : "one")).toBeUndefined();
});
}),
measureRunPhase("workspace.readers", async () => { await Promise.resolve(); }),
measureRunPhase("workspace.readers", async () => {
readersSpan = trace.getActiveSpan();
await assertOverlap();
}),
]));
overlappingSpanIds.set(runId, { source: sourceSpan?.spanContext().spanId, readers: readersSpan?.spanContext().spanId });
await measureRunPhase("response.add_comment", () => undefined);
}),
)));
@@ -68,9 +90,7 @@ it("parents overlapping preparation and response work to their own execution att
expect(readers.parentSpanContext?.spanId).toBe(phase.spanContext().spanId);
expect(aliases.parentSpanContext?.spanId).toBe(source.spanContext().spanId);
expect(reply.parentSpanContext?.spanId).toBe(attempt.spanContext().spanId);
const ns = (time: readonly [number, number]) => time[0] * 1e9 + time[1];
expect(ns(readers.startTime)).toBeLessThanOrEqual(ns(source.endTime));
expect(ns(source.startTime)).toBeLessThanOrEqual(ns(readers.endTime));
expect(overlappingSpanIds.get(runId)).toEqual({ source: source.spanContext().spanId, readers: readers.spanContext().spanId });
expect(owned).toHaveLength(6);
}
expect(getRunExecutionTraceContext("one")).toBeUndefined();