Files
leleka/engine/strata/apps/host/tests/chat-speed.test.mjs
T
Pavlo RatushnyiandClaude Sonnet 5.5 87e2633afe engine/strata: bring the Strata subtree to upstream 41cf05a0 (engine 0.1.50) with the local patches re-applied
Documented tree replacement (the history has no git-subtree metadata): 3-way merge of the old subtree
(570201a:engine/strata) against upstream 41cf05a06a25dd29103b7b27a2279a3f60c21876 (2026-10-25), merge base =
the old pin d9ab8435 (tree-identical to upstream 5b734e42; d9ab8435 is not an ancestor of upstream main).

Local patches re-applied by hand where they conflicted (15 files): STRATA_CUDA_STATIC profile, experimental KAR
experts and KAR PLE arms, keyless V-only arm (now beside upstream's K8V4 hybrid KV and fused norm+rope). Details,
conflict table and left-out files are in docs/upstream.md.

Left out (weights, captures, logs, media): new bench/results (2022 files), binary media and app assets (61),
docs/work/evidence (24), *.bin / *.gguf data files, and the 7 files the first import already left out.

scripts/build-cpu.sh: build the 11 CPU tests upstream registered since the old pin (they ran as "Not Run").
Checked: build-cpu.sh 16/16 ctest in WSL; sm_86 CUDA objects of the patched files compile, also with the KAR
macros on. No GPU run, no quality gate.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-25 12:49:15 +01:00

44 lines
2.6 KiB
JavaScript

/** The chat footer's "tok/s · last reply" is the answer-writing speed: the engine's output tokens over the time spent decoding them. */
import test, { mock } from 'node:test';
import assert from 'node:assert/strict';
import { TurnProjector } from '../server/agent/events.mjs';
const chunk = (attemptId, c) => ({ type: 'assistant-stream', frame: { type: 'chunk', attemptId, chunk: c } });
/** One model request: `pieces` chunks `gap` ms apart of the given kind, then the engine's usage; tool runs and the wait for the prompt take their own time. */
test('writing a big tool call counts as decoding time: 600 tokens over 10 s is 60 tok/s, not hundreds', () => {
mock.timers.enable({ apis: ['Date'], now: 1_000_000 });
try {
const p = new TurnProjector({ startedAt: Date.now() });
// the model reads a 30 s prompt first: no chunk yet
mock.timers.tick(30_000);
// it writes a file as a tool call: 100 chunks, 100 ms apart, 600 output tokens in the engine's count
for (let i = 0; i < 100; i++) {
p.consume(chunk('a1', { type: 'tool-call-delta', id: 'call-1', name: 'write', argumentsDelta: 'x'.repeat(24) }));
mock.timers.tick(100);
}
p.consume(chunk('a1', { type: 'usage', usage: { inputTokens: 5000, outputTokens: 600 } }));
// a short closing sentence
p.consume(chunk('a2', { type: 'text-delta', text: 'Done.' }));
p.consume({ type: 'event', event: { seq: 9, time: 9, type: 'turn/end', data: { reason: { kind: 'completed' } } } });
p.ended = { kind: 'completed' };
const done = p.finish({ model: 'm', contextMax: 32768 }).find(f => f.type === 'done');
assert.ok(done.tps >= 55 && done.tps <= 65, `${done.tps} tok/s`);
assert.equal(done.tokensOut, 600, "the engine's own count");
} finally { mock.timers.reset(); }
});
test('text and reasoning keep their speed, and tool-run time is not decoding time', () => {
mock.timers.enable({ apis: ['Date'], now: 2_000_000 });
try {
const p = new TurnProjector({ startedAt: Date.now() });
for (let i = 0; i < 50; i++) { p.consume(chunk('a1', { type: 'reasoning-delta', text: 'think ' })); mock.timers.tick(20); }
for (let i = 0; i < 50; i++) { p.consume(chunk('a1', { type: 'text-delta', text: 'word ' })); mock.timers.tick(20); }
p.consume(chunk('a1', { type: 'usage', usage: { inputTokens: 100, outputTokens: 100 } }));
mock.timers.tick(60_000); // a slow command runs: not decoding
p.ended = { kind: 'completed' };
const done = p.finish({}).find(f => f.type === 'done');
assert.ok(done.tps >= 45 && done.tps <= 55, `${done.tps} tok/s`);
} finally { mock.timers.reset(); }
});