From 7912f34f9693ff3c60924aa56e8100c21245cff0 Mon Sep 17 00:00:00 2001 From: oyi77 Date: Wed, 15 Jul 2026 03:15:12 +0700 Subject: [PATCH] test(perf): add performance instrumentation tests --- .../unit/chatcore-streaming-pipeline.test.ts | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tests/unit/chatcore-streaming-pipeline.test.ts b/tests/unit/chatcore-streaming-pipeline.test.ts index c112ff6d21..bd3b305701 100644 --- a/tests/unit/chatcore-streaming-pipeline.test.ts +++ b/tests/unit/chatcore-streaming-pipeline.test.ts @@ -7,9 +7,8 @@ import { test } from "node:test"; import assert from "node:assert/strict"; -const { assembleStreamingPipeline } = await import( - "../../open-sse/handlers/chatCore/streamingPipeline.ts" -); +const { assembleStreamingPipeline } = + await import("../../open-sse/handlers/chatCore/streamingPipeline.ts"); // A fake stream: each pipeThrough appends the transform's tag and returns a new fake stream. function fakeStream(tag: string, log: string[]) { @@ -100,3 +99,37 @@ test("full chain order: pii → progress → heartbeat → echo", () => { assembleStreamingPipeline(baseArgs({ echoModel: "alias-x" }), deps); assert.deepEqual(log, ["pii-flag", "progress", "heartbeat", "echo"]); }); + +test("pipeline assembly creates performance mark and measure entries", () => { + performance.clearMarks(); + performance.clearMeasures(); + const { deps } = makeDeps(); + assembleStreamingPipeline(baseArgs(), deps); + assert.equal(performance.getEntriesByName("omni-pipeline-start").length, 1, "start mark"); + assert.equal(performance.getEntriesByName("omni-pipeline-end").length, 1, "end mark"); + assert.equal(performance.getEntriesByName("omni-pipeline").length, 1, "measure"); +}); + +test("re-entering pipeline clears previous timeline entries", () => { + performance.clearMarks(); + performance.clearMeasures(); + const { deps } = makeDeps(); + // First call creates entries + assembleStreamingPipeline(baseArgs(), deps); + // Second call — clearMarks/clearMeasures runs before new marks, so count stays 1 + assembleStreamingPipeline(baseArgs(), deps); + assert.equal(performance.getEntriesByName("omni-pipeline-start").length, 1, "start cleared"); + assert.equal(performance.getEntriesByName("omni-pipeline-end").length, 1, "end cleared"); + assert.equal(performance.getEntriesByName("omni-pipeline").length, 1, "measure cleared"); +}); + +test("performance measure has positive duration", () => { + performance.clearMarks(); + performance.clearMeasures(); + const { deps } = makeDeps(); + assembleStreamingPipeline(baseArgs(), deps); + const [entry] = performance.getEntriesByName("omni-pipeline"); + assert.ok(entry, "measure exists"); + assert.equal(entry.entryType, "measure"); + assert.ok(entry.duration >= 0, `duration ${entry.duration} >= 0`); +});