test(perf): add performance instrumentation tests

This commit is contained in:
oyi77
2026-07-15 03:15:12 +07:00
parent c35e8a9b44
commit 7912f34f96

View File

@@ -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`);
});