AI, fully local on your computer.
TypeScript aiai-toolskiwixllama-cpplocal-ailocal-llmofflineoffline-aioffline-firstprivacy-firstragwikipediazim
// @vitest-environment jsdom
import { describe, it, expect, vi, afterEach } from 'vitest'
import { StrictMode } from 'react'
import { render, screen, cleanup, waitFor, act, within, getDefaultNormalizer } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { PerformanceScreen } from '../../src/renderer/screens/PerformanceScreen'
import { ToastProvider } from '../../src/renderer/components'
import {
DEFAULT_SETTINGS,
type BenchmarkProgressStep,
type BenchmarkResult,
type ModelFileVerdict,
type ModelInfo,
type PerformanceSnapshot,
type ResidentModelRow,
type RuntimeStatus
} from '../../src/shared/types'
import { t, tCount, UI_LANGUAGE_CODES, type UiLanguage } from '../../src/shared/i18n'
import { fmt1 } from '../../src/shared/format'
import { effectiveReadSample } from '../helpers/benchmark-records'
import { catalogOf } from '../helpers/i18n-catalogs'
import { deferred } from '../helpers/deferred'
import { assertNoUnexpectedApiCalls } from '../helpers/renderer'
import {
checkedSnapshot as snapshot,
copiedReport,
installPerformance as install,
laptopResult as result,
MODELS,
OBSERVED_FULL,
office,
oldLaptop,
otherRow,
placement,
pushChanged,
renderPerformanceScreen,
RUNNING_STATUS,
startOwnRun,
STOPPED_STATUS,
tile
} from '../helpers/performance-screen'
// The Performance screen (design-guidelines §2, benchmark.md "Performance screen"): the
// check's answer as a verdict + four tiles (speed, memory, graphics memory, drive — the
// graphics tile folds into one unified tile on Apple Silicon), the observed rows, the other
// computers, and the two actions that lead somewhere (AI Model for the pick / context size,
// Diagnostics for the raw table). Copy is plain and encouraging: no "benchmark", no hardware
// shaming.
afterEach(() => {
try {
assertNoUnexpectedApiCalls()
} finally {
cleanup()
window.localStorage.clear()
}
})
/** A snapshot with an answer in the observed rows (the M3 background observation). */
const observedAnswer = {
lastAnswer: { tokensPerSecond: 40, ttftMs: 800, tokens: 100, modelId: 'qwen3.5-9b-ud-q4kxl', at: '2026-09-05T15:00:00Z' },
lastModelLoad: null,
lastChecksum: null
}
const noObservations = { lastAnswer: null, lastModelLoad: null, lastChecksum: null }
/** The always-mounted live region of #437. */
const stepList = (): HTMLElement | null => document.querySelector('ul.perf-steps')
describe('PerformanceScreen: the check as an answer', () => {
it('renders the verdict, the four tiles with ratings, and the context the pick assumes', async () => {
install(snapshot())
renderPerformanceScreen()
expect(await screen.findByText(/Runs Qwen3\.5 9B \(UD-Q4_K_XL\) at about 12 tokens per second\./)).toBeInTheDocument()
expect(screen.getByText(/Model starts from this drive are fast\./)).toBeInTheDocument()
// Tiles: value + rating word (never color alone).
expect(within(tile('Speed')).getByText('Good')).toBeInTheDocument()
expect(within(tile('Speed')).getByText('12')).toBeInTheDocument()
expect(screen.getByText('Memory')).toBeInTheDocument()
expect(screen.getByText('Lite')).toBeInTheDocument()
expect(within(tile('Drive')).getByText('Fast')).toBeInTheDocument()
expect(within(tile('Drive')).getByText('430')).toBeInTheDocument()
// The fit question is answered in its own row, never under RAM or VRAM.
expect(screen.getByText('Your model')).toBeInTheDocument()
expect(screen.getByText(/Qwen3\.5 9B \(UD-Q4_K_XL\) · 5\.8 GB on disk · 8,192-token context/)).toBeInTheDocument()
expect(screen.getByText(/Needs at least 5\.8 GB for the weights.*Should fit in graphics memory \(24\.2 GB\)/)).toBeInTheDocument()
expect(screen.getByText('On GPU')).toBeInTheDocument()
expect(screen.queryByText(/Fits Qwen/)).not.toBeInTheDocument()
// No graphics card on this laptop: the Graphics tile says so in words, never a bare dash.
expect(screen.getByText('Graphics memory')).toBeInTheDocument()
expect(screen.getByText(/No usable graphics card/)).toBeInTheDocument()
expect(screen.getByText('None')).toBeInTheDocument()
// The saved pick and the live one agree: no "at the time of the check" line.
expect(screen.queryByText(/Recommended at the time of the check/)).not.toBeInTheDocument()
// No jargon on the primary surface.
expect(screen.queryByText(/benchmark/i)).not.toBeInTheDocument()
})
it('lists the observed rows and the other computers with their own ratings', async () => {
install(snapshot())
renderPerformanceScreen()
expect(await screen.findByText(/Last answer: 11\.8 tokens \/ s, first token after 0\.9 s/)).toBeInTheDocument()
expect(screen.getByText(/Model start: 13\.5 s/)).toBeInTheDocument()
expect(screen.getByText(/41 tokens \/ s with Qwen3\.8 27B UD-Q4_K_M/)).toBeInTheDocument()
// Graphics memory rides along in the other-computer rows once the result carries it.
expect(screen.getByText(/Intel Core i9-13900K, 64\.0 GB RAM, 24\.0 GB VRAM/)).toBeInTheDocument()
expect(screen.getByText(/2 tokens \/ s with Qwen3\.5 4B/)).toBeInTheDocument()
// The 70 MB/s laptop is flagged by its drive, in words.
expect(screen.getByText('Slow drive')).toBeInTheDocument()
})
it('shows the honest empty states before any check and before any observation', async () => {
install(snapshot({ current: null, otherMachines: [], observed: { lastAnswer: null, lastModelLoad: null, lastChecksum: null } }))
renderPerformanceScreen()
expect(await screen.findByRole('button', { name: 'Check this computer' })).toBeInTheDocument()
// The card header and the Memory tile both say it: not checked yet.
expect(screen.getAllByText('Not checked yet').length).toBeGreaterThanOrEqual(1)
expect(screen.getAllByText('Pending')).toHaveLength(3)
expect(screen.getByText(/Nothing observed yet this session/)).toBeInTheDocument()
expect(screen.getByText(/None yet\. Plug the drive into another computer/)).toBeInTheDocument()
})
it('shows the graphics memory from the result, or from this machine’s eligible probe when the result predates the field', async () => {
install(snapshot({ current: result({ gpu: 'NVIDIA GeForce RTX 3090', gpuVramMb: 24576 }) }))
renderPerformanceScreen()
expect(await screen.findByText('24.0')).toBeInTheDocument()
expect(screen.getByText('Usable')).toBeInTheDocument()
cleanup()
// An old result (no gpuVramMb) on the current machine: the eligible probe's device fills
// the tile — a small DISCRETE card is "Small", with its size as the reason.
const legacy = result()
delete (legacy as Partial<BenchmarkResult>).gpuVramMb
// Main names a sub-gate card as the display device, never as the budget one (registerBenchmarkIpc.ts:1280-1281).
const smallCard = { name: 'NVIDIA GeForce GTX 1650', totalMb: 4096, useful: false }
install(snapshot({ current: legacy, currentGpu: null, graphicsDevice: smallCard }))
renderPerformanceScreen()
expect(await screen.findByText('4.0')).toBeInTheDocument()
expect(screen.getByText('Small')).toBeInTheDocument()
expect(screen.getByText(/NVIDIA GeForce GTX 1650 · Under 5 GB: models run on the processor/)).toBeInTheDocument()
cleanup()
// …but never for a result from ANOTHER computer: that check never recorded the field, so
// the tile claims nothing either way (N1) — not "no usable graphics card".
install(snapshot({ current: legacy, currentMachine: false, currentGpu: null, graphicsDevice: smallCard }))
renderPerformanceScreen()
expect(await screen.findByText('That check did not record the graphics card.')).toBeInTheDocument()
expect(screen.getByText('Not recorded')).toBeInTheDocument()
expect(screen.queryByText(/No usable graphics card/)).not.toBeInTheDocument()
expect(screen.queryByText('4.0')).not.toBeInTheDocument()
cleanup()
// A foreign result that RECORDED nothing (an explicit null) is a real "none".
install(snapshot({ current: result({ gpuVramMb: null }), currentMachine: false }))
renderPerformanceScreen()
expect(await screen.findByText(/No usable graphics card/)).toBeInTheDocument()
expect(screen.getByText('None')).toBeInTheDocument()
})
it('never reads the raw settings probe: without a device in the snapshot the tile stays empty, whatever settings hold (M8.3)', async () => {
// `snapshot.currentGpu` is the BUDGET device for the next start (PR #308 audit decision 9);
// when main reports none, the tile says so — it never falls back to the stored probe's first
// device, which on a hybrid laptop is the iGPU's shared-RAM figure (the P2 carry-over).
const legacy = result()
delete (legacy as Partial<BenchmarkResult>).gpuVramMb
install(snapshot({ current: legacy, currentGpu: null }), {
getSettings: vi.fn(async () => ({
...DEFAULT_SETTINGS,
gpuProbe: { devices: [{ id: 'Vulkan0', name: 'Intel(R) Graphics (ARL)', totalMb: 11577, freeMb: 8251 }], probedAt: '2026-09-05T00:00:00Z' }
}))
})
renderPerformanceScreen()
expect(await screen.findByText(/No usable graphics card/)).toBeInTheDocument()
expect(screen.queryByText('11.3')).not.toBeInTheDocument()
expect(screen.queryByText(/Intel\(R\) Graphics/)).not.toBeInTheDocument()
expect(screen.getByText('None')).toBeInTheDocument()
expect(screen.queryByText('24.2')).not.toBeInTheDocument()
expect(screen.queryByText('Usable')).not.toBeInTheDocument()
expect(screen.queryByText('NVIDIA GeForce RTX 3090')).not.toBeInTheDocument()
// The screen does read `getSettings` — for the two GPU flags behind the "acceleration is
// off" sub-line (next test), never for the probe: the ARL device above stays unseen.
})
it('names a discrete card under the usable gate — the real card and its memory, rated "Small" (owner decision 2026-09-07)', async () => {
// A 4 GB card, which is what "under the gate" means since #321 lowered it to 5,120 (the 6 GB
// laptop cards that used to sit here are now usable — see the next test). No budget device, so
// the next start is a RAM start (`currentGpu` null, class cpu) — and the tile still names THE
// card with its own memory, never the iGPU listed first and never "no usable graphics card".
// Whether the card is used is the rating's job, not the tile's silence.
install(
snapshot({
current: result({ gpu: null, gpuVramMb: null }),
currentGpu: null,
graphicsDevice: { name: 'NVIDIA GeForce GTX 1650', totalMb: 4096, useful: false },
placement: placement({ memoryClass: 'cpu', vramMb: null })
})
)
renderPerformanceScreen()
expect(await screen.findByText('4.0')).toBeInTheDocument()
expect(screen.getByText('Small')).toBeInTheDocument()
expect(screen.getByText(/NVIDIA GeForce GTX 1650 · Under 5 GB: models run on the processor/)).toBeInTheDocument()
expect(screen.queryByText(/No usable graphics card/)).not.toBeInTheDocument()
expect(screen.queryByText('Usable')).not.toBeInTheDocument()
})
it('a 6 GB laptop card (5,994 MiB) a result recorded reads "Usable": the shared rule rates it, not a flag (#321)', async () => {
// The visible half of lowering the gate to 5,120. No live device here, so the tile's own
// `isUsefulDevice` call decides: at the old 6,144 this read "Small". That the next start USES
// the card is performance-gpu.test.ts's (`snap.currentGpu`, useful, at 5,994).
install(
snapshot({
current: result({ gpu: 'NVIDIA GeForce RTX 3060 Laptop GPU', gpuVramMb: 5994 }),
currentGpu: null,
graphicsDevice: null,
placement: placement({ memoryClass: 'cpu', vramMb: null })
})
)
renderPerformanceScreen()
expect(await screen.findByText('5.9')).toBeInTheDocument()
expect(screen.getByText('Usable')).toBeInTheDocument()
expect(screen.queryByText('Small')).not.toBeInTheDocument()
expect(screen.queryByText(/Under 5 GB/)).not.toBeInTheDocument()
expect(screen.queryByText(/No usable graphics card/)).not.toBeInTheDocument()
})
// What main sends for an integrated-only machine: a display device, no budget device
// (registerBenchmarkIpc.ts:1280-1281, gpu-rules.ts:194).
const IRIS = { name: 'Intel(R) Iris(R) Xe Graphics', totalMb: 16_384, useful: false }
const integratedOnly = (): PerformanceSnapshot =>
snapshot({
current: result({ gpu: IRIS.name, gpuVramMb: IRIS.totalMb }),
currentGpu: null,
graphicsDevice: IRIS,
placement: placement({
memoryClass: 'cpu',
vramMb: null,
ramMb: 16_077,
verdict: { kind: 'cpu', needMb: 5939, estimated: true, budgetMb: 16_077, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
})
})
it('T12: an integrated device reporting 16 GB of shared memory is "Integrated", never "Usable", beside "On processor" (M8.1)', async () => {
// The old tile rated `mb >= USABLE_VRAM_MB` alone and printed "16.0 GB VRAM · Usable" while the row
// below said the model runs on the processor.
install(integratedOnly())
renderPerformanceScreen()
expect(await screen.findByText('On processor')).toBeInTheDocument()
expect(screen.getByText('16.0')).toBeInTheDocument()
expect(screen.getByText('GB shared')).toBeInTheDocument()
expect(screen.getByText('Integrated')).toBeInTheDocument()
expect(screen.getByText('Intel(R) Iris(R) Xe Graphics · Integrated, shared memory: models run on the processor.')).toBeInTheDocument()
expect(screen.queryByText('Usable')).not.toBeInTheDocument()
expect(screen.queryByText('GB VRAM')).not.toBeInTheDocument()
// Not blamed on size: the memory is not the card's own.
expect(screen.queryByText(/Under 5 GB/)).not.toBeInTheDocument()
expect(screen.queryByText('Small')).not.toBeInTheDocument()
})
it('rates a recorded device by the shared rule when the snapshot carries no flag for it', async () => {
// A foreign result (no live device applies) naming an integrated device: the same rule,
// from the recorded name + memory.
install(snapshot({ current: result({ gpu: 'AMD Radeon(TM) Graphics', gpuVramMb: 16_000 }), currentMachine: false, currentGpu: null }))
renderPerformanceScreen()
expect(await screen.findByText('Integrated')).toBeInTheDocument()
expect(screen.queryByText('Usable')).not.toBeInTheDocument()
})
it('an other-computer row lists VRAM only for a usable card, never an integrated device’s shared figure', async () => {
const igpuLaptop = result({
cpuModel: 'Intel Core i5-1235U',
cpuCores: 12,
ramGb: 16,
gpu: 'Intel(R) Iris(R) Xe Graphics',
gpuVramMb: 16_384,
tokensPerSecond: 6,
ranAt: '2026-08-30T10:00:00Z'
})
install(snapshot({ otherMachines: [office, igpuLaptop] }))
renderPerformanceScreen()
expect(await screen.findByText(/Intel Core i9-13900K, 64\.0 GB RAM, 24\.0 GB VRAM/)).toBeInTheDocument()
expect(screen.getByText(/Intel Core i5-1235U, 16\.0 GB RAM · /)).toBeInTheDocument()
expect(screen.queryByText(/16\.0 GB VRAM/)).not.toBeInTheDocument()
})
it('the integrated tile in German (asserted from the catalog, D-L8)', async () => {
install(integratedOnly())
renderPerformanceScreen({ lang: 'de' })
expect(await screen.findByText(t('de', 'perf.rating.integrated'))).toBeInTheDocument()
expect(screen.getByText(`Intel(R) Iris(R) Xe Graphics · ${t('de', 'perf.tile.graphics.integrated')}`)).toBeInTheDocument()
expect(screen.getByText(t('de', 'perf.tile.graphics.unitShared'))).toBeInTheDocument()
expect(screen.queryByText(t('de', 'perf.rating.usable'))).not.toBeInTheDocument()
})
it('says so when the last result belongs to a different computer', async () => {
install(snapshot({ currentMachine: false }))
renderPerformanceScreen()
expect(await screen.findByText(/measured on a different computer/)).toBeInTheDocument()
})
it.each([
[4.9, 'Slow'],
[5, 'Good']
])('a speed of %s tokens / s rates "%s" on the tile: slow is strictly under 5', async (tps, rating) => {
install(snapshot({ current: result({ tokensPerSecond: tps }) }))
renderPerformanceScreen()
await screen.findByText('Speed')
expect(within(tile('Speed')).getByText(String(tps))).toBeInTheDocument()
expect(within(tile('Speed')).getByText(rating)).toBeInTheDocument()
})
it.each([
[99, 'Slow', 'Model starts from this drive are slow.'],
[100, 'Fast', 'Model starts from this drive are fast.']
])('a read of %s MB/s rates "%s" on the Drive tile, and the verdict says so: slow is strictly under 100', async (mbps, rating, sentence) => {
install(snapshot({ current: result({ effectiveRead: effectiveReadSample({ mbps }) }) }))
renderPerformanceScreen()
expect(await screen.findByText(new RegExp(sentence.replace('.', '\\.')))).toBeInTheDocument()
expect(within(tile('Drive')).getByText(String(mbps))).toBeInTheDocument()
expect(within(tile('Drive')).getByText(rating)).toBeInTheDocument()
})
it('a Drive figure from a checksum sample says it came from a file check, not a model load', async () => {
const at = '2026-09-03T12:00:00'
install(snapshot({ current: result({ effectiveRead: effectiveReadSample({ source: 'checksum', bytes: 5_800_000_000, at }) }) }))
renderPerformanceScreen()
await screen.findByText('Speed')
expect(within(tile('Drive')).getByText(`From a file check on ${new Date(at).toLocaleDateString('en')}, 5.8 GB read`)).toBeInTheDocument()
})
it('a full file check fills its own observed row, named a check and marked once per model', async () => {
const at = '2026-09-03T12:00:00'
const lastChecksum = effectiveReadSample({ source: 'checksum', ms: 40_000, bytes: 5_800_000_000, modelId: 'qwen3.5-9b-ud-q4kxl', at })
install(snapshot({ observed: { ...noObservations, lastChecksum } }))
renderPerformanceScreen()
expect(await screen.findByText('File check: 40.0 s')).toBeInTheDocument()
expect(await screen.findByText(`Full file check of Qwen3.5 9B (UD-Q4_K_XL) on ${new Date(at).toLocaleDateString('en')}, 5.8 GB read`)).toBeInTheDocument()
expect(screen.getByText('Once per model')).toBeInTheDocument()
expect(screen.queryByText(/Nothing observed yet this session/)).not.toBeInTheDocument()
})
})
describe('PerformanceScreen: the Your-model row', () => {
it('reads an observed full offload off the log: layers, size with context, On GPU', async () => {
install(snapshot({ placement: placement({
observed: OBSERVED_FULL,
verdict: { kind: 'gpu', needMb: 6540, estimated: false, budgetMb: 24_822, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: 41, totalLayers: 41 }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/Takes 6\.4 GB with this context\. Fits in graphics memory \(24\.2 GB\): all 41 layers on the GPU\./)).toBeInTheDocument()
expect(screen.getByText('On GPU')).toBeInTheDocument()
})
it('an observed start whose log said nothing reads as Not measured, never "all layers on the GPU"', async () => {
// A start was recorded but every figure is null (a build below verbosity 4). The row must
// not dress that up as a measured full offload with an empty layer count.
// Owner gate (c): the sentence names the runtime's SILENCE, never "measured on its first
// start" — that start already happened, so a restart would change nothing.
install(snapshot({ placement: placement({
observed: { ...OBSERVED_FULL, gpuLayers: null, totalLayers: null, gpuModelMb: null, cpuModelMb: null, gpuKvMb: null },
verdict: { kind: 'unknown', needMb: null, estimated: false, budgetMb: 24_822, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
}) }))
renderPerformanceScreen()
expect(await screen.findByText('The runtime did not report where the model landed.')).toBeInTheDocument()
expect(screen.queryByText(/measured the first time it starts/)).not.toBeInTheDocument()
// Nothing here is an estimate, so the per-drive hint stays off.
expect(screen.queryByText(/one record per model/)).not.toBeInTheDocument()
expect(screen.getByText('Not measured')).toBeInTheDocument()
expect(screen.queryByText('On GPU')).not.toBeInTheDocument()
// The gap the L7 bug left behind ("all {layers} layers" with no count). The default
// matcher collapses whitespace, so ask for the raw text.
expect(screen.queryByText(/all\s{2,}layers/, { normalizer: (s) => s })).not.toBeInTheDocument()
expect(screen.queryByText(/layers on the GPU/)).not.toBeInTheDocument()
expect(screen.queryByText(/Fits in graphics memory/)).not.toBeInTheDocument()
})
it('L8: the estimate says the measurement is taken on THIS computer, and that the drive keeps one record per model', async () => {
// Nothing observed yet for this configuration. The placement lives in the DRIVE's settings,
// one entry per model id, and is read back only on the machine that wrote it — so a start
// on another computer sends this row back to the estimate.
install(snapshot({ placement: placement({
observed: null,
verdict: { kind: 'unknown', needMb: null, estimated: true, budgetMb: 24_822, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
}) }))
renderPerformanceScreen()
expect(
await screen.findByText('Where the model lands is measured the first time it starts on this computer.')
).toBeInTheDocument()
expect(
screen.getByText('The drive keeps one record per model, so a start on another computer replaces the one measured here.')
).toBeInTheDocument()
})
it('L8: the per-drive hint gives way to the more specific "measured earlier" note, never both', async () => {
install(snapshot({ placement: placement({
observed: null,
observedMismatch: { contextTokens: 32_768, backend: 'gpu', at: '2026-09-01T00:00:00Z' }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/Measured earlier with a 32,768-token context on/)).toBeInTheDocument()
expect(screen.queryByText(/one record per model/)).not.toBeInTheDocument()
// The verdict beside it is still the estimate for the CURRENT settings.
expect(screen.getByText(/Needs at least 5\.8 GB for the weights/)).toBeInTheDocument()
})
it('a "gpu" verdict with no layer count uses the wording that needs none, never "all layers"', async () => {
// Defence in depth: `placementVerdict` only reports 'gpu' when it read both counts, so a
// non-estimated 'gpu' with a null total can only come from a malformed record — it must
// still never render the empty `{layers}` interpolation (L7 / gate (c)).
install(snapshot({ placement: placement({
observed: OBSERVED_FULL,
verdict: { kind: 'gpu', needMb: 6540, estimated: false, budgetMb: 24_822, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/Should fit in graphics memory \(24\.2 GB\)\./)).toBeInTheDocument()
expect(screen.queryByText(/all\s{2,}layers/, { normalizer: (s) => s })).not.toBeInTheDocument()
expect(screen.queryByText(/layers on the GPU/)).not.toBeInTheDocument()
expect(screen.getByText('On GPU')).toBeInTheDocument()
})
it('names a partial offload with the layer split and the RAM spill, in words', async () => {
install(snapshot({ placement: placement({
vramMb: 16_384,
observed: { ...OBSERVED_FULL, gpuLayers: 30, gpuModelMb: 4000, cpuModelMb: 1900 },
verdict: { kind: 'partial', needMb: 6540, estimated: false, budgetMb: 16_384, freeAtStartMb: null, workingMb: null, spillMb: 1900, gpuLayers: 30, totalLayers: 41 }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/Graphics memory holds 16\.0 GB: 30 of 41 layers on the GPU, about 1\.9 GB runs from RAM\. Answers slower\./)).toBeInTheDocument()
expect(screen.getByText('Partly on GPU')).toBeInTheDocument()
})
it('an estimated spill states the budget and the spill, and claims no layer split', async () => {
install(snapshot({ placement: placement({
verdict: { kind: 'partial', needMb: 10_254, estimated: true, budgetMb: 8192, freeAtStartMb: null, workingMb: null, spillMb: 1843, gpuLayers: null, totalLayers: null }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/Graphics memory holds 8\.0 GB: about 1\.8 GB will run from RAM\. Answers slower\./)).toBeInTheDocument()
expect(screen.queryByText(/layers on the GPU/)).not.toBeInTheDocument()
})
it('a start observed on the processor says it runs there, not that it will', async () => {
install(snapshot({ placement: placement({
memoryClass: 'cpu',
vramMb: null,
verdict: { kind: 'cpu', needMb: null, estimated: false, budgetMb: 16_077, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/Runs on the processor from RAM \(15\.7 GB\)\./)).toBeInTheDocument()
expect(screen.queryByText(/Will run on the processor/)).not.toBeInTheDocument()
expect(screen.getByText('On processor')).toBeInTheDocument()
})
// CARD_FREE_SLACK_MB is 1,536: on this 24,822 MiB card the copy changes hands at 23,286 MiB free.
it.each([
['exactly the slack in use: the card counts as free', 23_286, /The card was free \(22\.7 of 24\.2 GB\)/],
['one MiB more in use: what else held the card is the reason', 23_285, /only 22\.7 GB of the card’s 24\.2 GB was free/]
])('the partial copy at the free-at-start boundary, %s', async (_why, freeAtStartMb, copy) => {
install(snapshot({ placement: placement({
observed: { ...OBSERVED_FULL, gpuLayers: 62, totalLayers: 66 },
verdict: { kind: 'partial', needMb: 19_389, estimated: false, budgetMb: 24_822, freeAtStartMb, workingMb: 2860, spillMb: 1743, gpuLayers: 62, totalLayers: 66 }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(copy)).toBeInTheDocument()
})
it('explains a spill on a card that would hold the model: what was free at start, plus the margin', async () => {
install(snapshot({ placement: placement({
model: { id: 'qwen3.8-27b-ud-q4km', sizeOnDiskGb: 18.4, onDrive: true, contextTokens: 8192 },
observed: { ...OBSERVED_FULL, modelId: 'qwen3.8-27b-ud-q4km', gpuLayers: 62, totalLayers: 66, gpuModelMb: 17_600, cpuModelMb: 1750, gpuKvMb: 512, gpuFreeAtStartMb: 20_300 },
verdict: { kind: 'partial', needMb: 19_862, estimated: false, budgetMb: 24_822, freeAtStartMb: 20_300, workingMb: 2860, spillMb: 1750, gpuLayers: 62, totalLayers: 66 }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/62 of 66 layers on the GPU, about 1\.7 GB runs from RAM: only 19\.8 GB of the card’s 24\.2 GB was free when the model started, and the runtime keeps a 1 GB safety margin\. Answers slower\. Restart the model once the card is free\./)).toBeInTheDocument()
})
it('explains a spill on a card that WAS free: the working buffers and the fixed margin', async () => {
install(snapshot({ placement: placement({
model: { id: 'qwen3.8-27b-ud-q4km', sizeOnDiskGb: 18.4, onDrive: true, contextTokens: 8192 },
observed: { ...OBSERVED_FULL, modelId: 'qwen3.8-27b-ud-q4km', gpuLayers: 62, totalLayers: 66, gpuModelMb: 17_134, cpuModelMb: 1711, gpuKvMb: 512, gpuFreeAtStartMb: 23_615, gpuComputeMb: 2860 },
verdict: { kind: 'partial', needMb: 19_389, estimated: false, budgetMb: 24_822, freeAtStartMb: 23_615, workingMb: 2860, spillMb: 1743, gpuLayers: 62, totalLayers: 66 }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/The card was free \(23\.1 of 24\.2 GB\), but the runtime also sets aside 2\.8 GB of working buffers and a 1 GB safety margin, and moves whole layers off the card when the sum gets close\. Answers slower\./)).toBeInTheDocument()
expect(screen.queryByText(/only 23\.1 GB/)).not.toBeInTheDocument()
})
it('DR4: all three partial copies state the runtime margin from the shared constant, never a literal', async () => {
// Rows above pin the rendered "1 GB" on the free and margin copies; this is the third branch.
install(snapshot({ placement: placement({
model: { id: 'qwen3.8-27b-ud-q4km', sizeOnDiskGb: 18.4, onDrive: true, contextTokens: 8192 },
observed: { ...OBSERVED_FULL, modelId: 'qwen3.8-27b-ud-q4km', gpuLayers: 62, totalLayers: 66 },
verdict: { kind: 'partial', needMb: 19_389, estimated: false, budgetMb: 24_822, freeAtStartMb: 23_615, workingMb: null, spillMb: 1743, gpuLayers: 62, totalLayers: 66 }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/sets aside working buffers and a 1 GB safety margin/)).toBeInTheDocument()
// At the shipped 1,024 a catalog literal "1 GB" reads the same as the interpolation; only a sentinel tells them apart.
const sentinel = '①'
for (const lang of ['en', 'de'] as const) {
for (const key of ['perf.model.partialFree', 'perf.model.partialMargin', 'perf.model.partialMarginNoWorking'] as const) {
expect(t(lang, key, { margin: sentinel })).toContain(`${sentinel} GB`)
}
}
})
it('on Apple Silicon shows one Unified memory tile, no graphics tile, and the unified budget', async () => {
install(snapshot({ placement: placement({
memoryClass: 'unified',
vramMb: null,
ramMb: 49_152,
verdict: { kind: 'gpu', needMb: 5939, estimated: true, budgetMb: 36_864, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
}) }))
renderPerformanceScreen()
expect(await screen.findByText('Unified memory')).toBeInTheDocument()
expect(screen.queryByText('Graphics memory')).not.toBeInTheDocument()
expect(screen.getByText(/Should fit in unified memory \(48\.0 GB, up to 36\.0 GB available to the model\)/)).toBeInTheDocument()
// The tile's line names the shared memory, then the processor, joined by " · ": exactly the text
// it read before #805 S3 split the core count into its own span.
const line = `${t('en', 'perf.tile.memory.unifiedSub')} · Intel Core i7-1260P${tCount('en', 'diag.bench.cores', 12)}`
expect(within(tile('Unified memory')).getByText((_, el) => el?.textContent === line)).toBeInTheDocument()
})
it('a model that cannot fit gets "Too large" and a way to a smaller model', async () => {
install(snapshot({ placement: placement({
memoryClass: 'cpu',
vramMb: null,
ramMb: 8192,
model: { id: 'qwen3.8-27b-ud-q4km', sizeOnDiskGb: 16.5, onDrive: true, contextTokens: 8192 },
verdict: { kind: 'too_large', needMb: 16_896, estimated: true, budgetMb: 8192, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
}) }))
const { onNavigate } = renderPerformanceScreen()
expect(await screen.findByText(/Too large for this computer \(8\.0 GB available\)\. Pick a smaller model\./)).toBeInTheDocument()
expect(screen.getByText('Too large')).toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: 'Choose a smaller model' }))
expect(onNavigate).toHaveBeenLastCalledWith('models')
})
it('with no model selected says so and points at AI Model', async () => {
install(snapshot({ placement: placement({ model: null, verdict: { kind: 'unknown', needMb: null, estimated: true, budgetMb: 24_822, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null } }) }))
renderPerformanceScreen()
expect(await screen.findByText(/No model selected yet/)).toBeInTheDocument()
expect(screen.getByText('Not measured')).toBeInTheDocument()
})
})
describe('PerformanceScreen: models on this computer', () => {
it('lists every role with where it runs by design, its lifetime and whether it is loaded now', async () => {
install(snapshot())
renderPerformanceScreen()
expect(await screen.findByText('Models on this computer')).toBeInTheDocument()
expect(screen.getByText('Translation')).toBeInTheDocument()
expect(screen.getByText(/Document search \(ranking\)/)).toBeInTheDocument()
expect(screen.getByText(/Document search \(index\)/)).toBeInTheDocument()
expect(screen.getByText('Voice')).toBeInTheDocument()
// Pinned roles say so, in words; the CLI says it runs only while working. Wave 8 ruling (e)
// amendment: the reranker's `cpu` fixture row (`device: 'cpu'`, in `placement`) used to be
// the fourth "by design" row before this step — Wave 8 ruling (d) makes a `cpu` reranker
// read plain "processor" instead (its posture is headroom-gated, not a fixed design choice),
// so three roles now say "by design": vision, the index embedder and voice.
expect(screen.getAllByText(/processor, by design/).length).toBe(3)
expect(screen.getByText(/runs only while working/)).toBeInTheDocument()
expect(screen.getAllByText(/unloads when idle/).length).toBe(2)
expect(screen.getAllByText('loaded now').length).toBe(3)
expect(screen.getAllByText('not loaded').length).toBe(3)
})
it('sums the card budget and the everything-at-once RAM need, flagging too much', async () => {
install(snapshot({ placement: placement({ ramMb: 16_077, totals: { ramAllMb: Math.round(17.0 * 1024), bothOnCard: false, chatAndTranslationOnCard: false } }) }))
renderPerformanceScreen()
expect(await screen.findByText(/Graphics card: chat 5\.4 GB \+ translation 6\.8 GB, of 24\.2 GB\./)).toBeInTheDocument()
// #914 code review: with both models here the chat-only line does not show as well.
expect(screen.queryByText(/Graphics card: chat 5\.4 GB, of/)).not.toBeInTheDocument()
expect(screen.getByText(/Everything loaded at once needs about 17\.0 GB of 15\.7 GB RAM\./)).toBeInTheDocument()
expect(screen.getByText('Too much at once')).toBeInTheDocument()
})
// A lite drive on a card machine: only the chat row is on the drive and it runs on the card, so main reports 0 (or a
// few MiB of spill). "about 0.0 GB of 31.3 GB RAM" with a Fits pill says nothing, so the line and its pill go.
describe('the everything-at-once line on a drive whose only model runs on the card', () => {
const cardOnly = (ramAllMb: number | null, over: Partial<ReturnType<typeof placement>> = {}) => {
const base = placement()
const models = base.models.map((r) => (r.role === 'chat' ? r : { ...r, onDrive: false, loaded: false }))
install(snapshot({ placement: { ...base, ramMb: 32_000, models, ...over, totals: { ramAllMb, bothOnCard: false, chatAndTranslationOnCard: false } } }))
renderPerformanceScreen()
}
const ramLine = (sum: string) => t('en', 'perf.models.ram', { sum, ram: fmt1(32_000 / 1024, 'en') })
// The key text before the figure, from the catalogue; the matcher gets whitespace-normalized text.
const lineKey = ramLine('0.1').split(' 0.1')[0].replace(/\s+/g, ' ').trim()
it.each([null, 0, 30, 51])('shows no line and no pill at %s MiB', async (mb) => {
cardOnly(mb)
expect(await screen.findByText(/Graphics card: chat/)).toBeInTheDocument()
expect(screen.queryByText((text) => text.startsWith(lineKey))).not.toBeInTheDocument()
expect(screen.queryByText(t('en', 'perf.models.ramOk'))).not.toBeInTheDocument()
expect(screen.queryByText(t('en', 'perf.models.ramTooMuch'))).not.toBeInTheDocument()
})
it.each([[52, '0.1'], [512, '0.5']])('shows the line and the Fits pill at %i MiB, reading %s GB', async (mb, gb) => {
cardOnly(mb)
expect(await screen.findByText(ramLine(gb))).toBeInTheDocument()
expect(screen.getByText(t('en', 'perf.models.ramOk'))).toBeInTheDocument()
})
it('shows the unified-memory variant of the line at 512 MiB', async () => {
cardOnly(512, { memoryClass: 'unified' })
expect(await screen.findByText(t('en', 'perf.models.memory', { sum: '0.5', budget: fmt1(24_822 / 1024, 'en') }))).toBeInTheDocument()
})
})
it('warns when chat and translation are both on the card, with the start-order advice', async () => {
install(
snapshot({
placement: placement({
ramMb: 131_072,
totals: { ramAllMb: Math.round(17.0 * 1024), bothOnCard: true, chatAndTranslationOnCard: true }
})
})
)
renderPerformanceScreen()
expect(await screen.findByText(/Both are on the card right now\. Whichever started second got what was left and runs slower/)).toBeInTheDocument()
expect(screen.getByText('Fits')).toBeInTheDocument()
})
// #476: the summary carried no line at all for a GPU-resident reranker — neither its own size
// nor the shared contention warning. #495 follow-up: this fixture (chat+reranker actually on
// the card, translation GPU-postured but NOT resident) is the exact scenario named —
// `bothOnCard` is true (3-way contention) but `chatAndTranslationOnCard` is
// false, so the badge appears on both lines while the chat/translation PAIR sentence (which
// names translation specifically) must not.
it('#476/#495 follow-up: shows a separate graphics-card line for a GPU-resident reranker, the contention badge on both lines, but the chat/translation pair copy only when translation is itself on the card', async () => {
const rows = placement().models.map((r) => (r.role === 'reranker' ? { ...r, device: 'gpu' as const } : r))
install(
snapshot({
placement: placement({
models: rows,
totals: { ramAllMb: Math.round(17.0 * 1024), bothOnCard: true, chatAndTranslationOnCard: false }
})
})
)
renderPerformanceScreen()
expect(await screen.findByText(/Graphics card: ranking 1\.1 GB, of 24\.2 GB\./)).toBeInTheDocument()
// The chat/translation line is unaffected — both lines coexist.
expect(screen.getByText(/Graphics card: chat 5\.4 GB \+ translation 6\.8 GB, of 24\.2 GB\./)).toBeInTheDocument()
// #495 follow-up: translation is not actually on the card here — the pair-naming sentence must be absent.
expect(screen.queryByText(/Both are on the card right now/)).not.toBeInTheDocument()
// bothOnCard now covers three residents sharing the card — the badge appears on BOTH lines.
expect(screen.getAllByText('Partly on GPU')).toHaveLength(2)
})
it('#476: a reranker on the processor shows no reranker card line (byte-unchanged default)', async () => {
install(snapshot())
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.queryByText(/Graphics card: ranking/)).not.toBeInTheDocument()
})
// #495 follow-up: the reranker starts lazily on the session's first rerank(), so the ORDINARY
// state of a fresh GPU session is device 'gpu' with nothing loaded yet — the line must key off
// residency, not posture, or it would assert the ranking model is on the card while the row
// right above it is badged "not loaded".
it('#495 follow-up: a GPU-postured but not-yet-loaded reranker shows no reranker card line', async () => {
const rows = placement().models.map((r) => (r.role === 'reranker' ? { ...r, device: 'gpu' as const, loaded: false } : r))
install(snapshot({ placement: placement({ models: rows }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.queryByText(/Graphics card: ranking/)).not.toBeInTheDocument()
})
it('on a machine without a usable card there is no card line, only the RAM line', async () => {
install(snapshot({ placement: placement({ memoryClass: 'cpu', vramMb: null, ramMb: 131_072 }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.queryByText(/Graphics card: chat/)).not.toBeInTheDocument()
expect(screen.getByText(/Everything loaded at once needs about/)).toBeInTheDocument()
})
it('chat and translation on the processor by configuration say "processor", not "by design", and the card line is gone (DR1)', async () => {
// The GPU switched off on a card machine: main puts both rows on the processor.
const rows = placement().models.map((r) => (r.role === 'chat' || r.role === 'translation' ? { ...r, device: 'cpu' as const } : r))
install(
snapshot({
placement: placement({
models: rows,
verdict: { kind: 'cpu', needMb: 5939, estimated: true, budgetMb: 16_077, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
})
})
)
renderPerformanceScreen()
await screen.findByText('Models on this computer')
// Wave 8 ruling (e) amendment: the fixture's reranker row is ALSO `device: 'cpu'`, so its
// row-sub line now starts with plain "processor · " too (ruling (d)) — three rows, not two —
// and only three roles (not four) say "by design".
expect(screen.getAllByText(/^processor · /)).toHaveLength(3)
expect(screen.getAllByText(/processor, by design/)).toHaveLength(3)
expect(screen.queryByText(/Graphics card: chat/)).not.toBeInTheDocument()
expect(screen.getByText(/Will run on the processor from RAM \(15\.7 GB\)/)).toBeInTheDocument()
})
// #495 follow-up: the reverted `anyOnCard` predicate (chat/translation only, never the
// reranker) needs its own pin: the case above has its reranker on the processor too, so it
// cannot tell the predicate from the wider one it replaced. The #495 row above leaves chat on
// the card, so it cannot see the pair line either.
it('chat and translation on the processor, reranker resident on the card but not yet loaded: neither card line renders', async () => {
const rows = placement().models.map((r) => {
if (r.role === 'chat' || r.role === 'translation') return { ...r, device: 'cpu' as const }
if (r.role === 'reranker') return { ...r, device: 'gpu' as const, loaded: false }
return r
})
install(snapshot({ placement: placement({ models: rows }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.queryByText(/Graphics card: chat/)).not.toBeInTheDocument()
expect(screen.queryByText(/Graphics card: ranking/)).not.toBeInTheDocument()
})
it('chat and translation on the processor, reranker resident and loaded on the card: only the reranker card line renders', async () => {
const rows = placement().models.map((r) => {
if (r.role === 'chat' || r.role === 'translation') return { ...r, device: 'cpu' as const }
if (r.role === 'reranker') return { ...r, device: 'gpu' as const, loaded: true }
return r
})
install(snapshot({ placement: placement({ models: rows }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.queryByText(/Graphics card: chat/)).not.toBeInTheDocument()
expect(await screen.findByText(/Graphics card: ranking/)).toBeInTheDocument()
})
it('on Apple Silicon the processor line speaks of unified memory and the pill compares against the budget (DR5)', async () => {
// 40 GB of models: under the 48 GB of RAM, over the 36 GB Metal lets models take.
install(
snapshot({
placement: placement({
memoryClass: 'unified',
vramMb: null,
ramMb: 49_152,
verdict: { kind: 'gpu', needMb: 5939, estimated: true, budgetMb: 36_864, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null },
totals: { ramAllMb: Math.round(40.0 * 1024), bothOnCard: false, chatAndTranslationOnCard: false }
})
})
)
renderPerformanceScreen()
expect(await screen.findByText(/Everything loaded at once needs about 40\.0 GB of the 36\.0 GB of unified memory available to models\./)).toBeInTheDocument()
expect(screen.getByText('Too much at once')).toBeInTheDocument()
expect(screen.queryByText(/GB RAM\./)).not.toBeInTheDocument()
})
it('#746: a probed Metal device prints no graphics-card line: the pool is counted once, by the memory line (#332)', async () => {
// `vramMb` carries the Metal pool's device. With a chat row on 'gpu' and a reranker resident
// there, both card gates would open on anything but `discrete`.
const rows = placement().models.map((r) => (r.role === 'reranker' ? { ...r, device: 'gpu' as const, loaded: true } : r))
install(snapshot({ placement: placement({
memoryClass: 'unified',
vramMb: 21_845,
ramMb: 32_768,
models: rows,
verdict: { kind: 'gpu', needMb: 5939, estimated: true, budgetMb: 24_576, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: null, totalLayers: null }
}) }))
renderPerformanceScreen()
expect(await screen.findByText(/Everything loaded at once needs about 17\.0 GB of the 24\.0 GB of unified memory available to models\./)).toBeInTheDocument()
expect(screen.queryByText(/Graphics card:/)).not.toBeInTheDocument()
})
it('a role with no model says so without a loaded pill, one with no size names the model alone, a live split is stated', async () => {
const rows = placement().models.map((r) => {
if (r.role === 'vision') return { ...r, modelId: null, sizeOnDiskGb: null, onDrive: false }
if (r.role === 'reranker') return { ...r, sizeOnDiskGb: null }
if (r.role === 'translation') return { ...r, loaded: true, gpuLayers: 20, totalLayers: 49 }
return r
})
install(snapshot({ placement: placement({ models: rows }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
const images = otherRow(/^Images$/)
expect(within(images).getByText(/No model installed for this\./)).toBeInTheDocument()
expect(within(images).queryByText(/loaded/)).not.toBeInTheDocument()
// #914 review N-2: main sends a row with no model as not on the drive (no manifest); it gets no badge at all.
expect(within(images).queryByText('not on this drive')).not.toBeInTheDocument()
const ranking = otherRow(/^Document search \(ranking\)$/)
expect(within(ranking).getByText(/bge-reranker-v2-m3-f16/)).toBeInTheDocument()
expect(within(ranking).queryByText(/ GB/)).not.toBeInTheDocument()
expect(within(otherRow(/^Translation$/)).getByText(/20 of 49 layers on the card/)).toBeInTheDocument()
})
/** The default rows with one role's row changed. */
const withRow = (role: ResidentModelRow['role'], over: Partial<ResidentModelRow>): ResidentModelRow[] =>
placement().models.map((r) => (r.role === role ? { ...r, ...over } : r))
// #914 (owner decision G-5 (c)): a model whose files are not on this drive keeps its row, named and sized from the
// catalog (the planning view), and says "not on this drive" where the other rows say loaded / not loaded.
it('#914: a model that is not on this drive says so in place of its loaded pill', async () => {
install(snapshot({ placement: placement({ models: withRow('vision', { onDrive: false }) }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
const images = otherRow(/^Images$/)
expect(within(images).getByText(/qwen2\.5-vl-3b-instruct-q4 · 3\.0 GB/)).toBeInTheDocument()
expect(within(images).getByText('not on this drive')).toBeInTheDocument()
expect(within(images).queryByText(/loaded/)).not.toBeInTheDocument()
expect(screen.getAllByText('not on this drive')).toHaveLength(1)
})
// #914: a chat model outside the catalog has no size (null from main; it was 0). The row names it alone and
// "Your model" leaves the size out, where both used to print "0.0 GB".
it('#914: a chat model with no known size prints no "0.0 GB", on its row or on Your model', async () => {
const rows = withRow('chat', { modelId: 'my-own-gguf', sizeOnDiskGb: null, onDrive: false })
install(snapshot({ placement: placement({ model: { id: 'my-own-gguf', sizeOnDiskGb: null, onDrive: false, contextTokens: 8192 }, models: rows }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.getByText('my-own-gguf · 8,192-token context')).toBeInTheDocument()
expect(within(otherRow(/^Chat$/)).queryByText(/ GB/)).not.toBeInTheDocument()
expect(screen.queryByText(/0\.0 GB/)).not.toBeInTheDocument()
})
/** The active 9B with its files gone: `placement.model.onDrive` (main, #914 code review) and its row agree. */
const chatNotHere = (): Partial<PerformanceSnapshot['placement']> => ({
model: { id: 'qwen3.5-9b-ud-q4kxl', sizeOnDiskGb: 5.8, onDrive: false, contextTokens: 8192 },
models: withRow('chat', { onDrive: false, loaded: false })
})
// #914 review SF-1: an active catalog model whose files are gone keeps its size on its row, beside "not on this
// drive". "Your model" leaves the size out: it said "5.8 GB on disk" two cards above that badge.
it('#914: "Your model" claims no size on disk when the chat row is not on this drive', async () => {
install(snapshot({ placement: placement(chatNotHere()) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.getByText('Qwen3.5 9B (UD-Q4_K_XL) · 8,192-token context')).toBeInTheDocument()
expect(screen.queryByText(/GB on disk/)).not.toBeInTheDocument()
const chat = otherRow(/^Chat$/)
expect(within(chat).getByText(/Qwen3\.5 9B \(UD-Q4_K_XL\) · 5\.4 GB/)).toBeInTheDocument()
expect(within(chat).getByText('not on this drive')).toBeInTheDocument()
})
// #914 code review: with the active model not here, "Your model" states no fit at all. The default verdict is the
// card estimate ("Needs at least 5.8 GB… Should fit in graphics memory", pill "On GPU"): a claim about files the
// drive does not hold. The block keeps the model's name and context and says "not on this drive", like its row.
it('#914: "Your model" states no fit for a model that is not on this drive', async () => {
install(snapshot({ placement: placement(chatNotHere()) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
const block = screen.getByText('Your model').closest<HTMLElement>('.perf-model')
if (!block) throw new Error('the Your model block has no .perf-model container')
expect(within(block).getByText('not on this drive')).toBeInTheDocument()
expect(within(block).queryByText(/Should fit|Needs at least|Takes /)).not.toBeInTheDocument()
expect(within(block).queryByText(t('en', 'perf.place.gpu'))).not.toBeInTheDocument()
})
// #914 code review: loaded beats `onDrive`. A model the runtime holds is in memory, whatever the drive says now (a
// weight deleted while held open): its row says "loaded now", never "not on this drive".
it('#914: a resident model says "loaded now" even when its files are not on this drive', async () => {
install(snapshot({ placement: placement({ models: withRow('reranker', { onDrive: false, loaded: true }) }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
const ranking = otherRow(/^Document search \(ranking\)$/)
expect(within(ranking).getByText('loaded now')).toBeInTheDocument()
expect(within(ranking).queryByText('not on this drive')).not.toBeInTheDocument()
})
// #914 (S-914-1): the chat/translation card line adds the two sizes against the card, so it needs both models here
// with a size. With no chat model selected it read "Graphics card: chat GB + translation 6.8 GB"; with
// TranslateGemma named from the catalog only, it counted a model that never reaches the card. `absent` is the line
// that must not show: with no chat model none at all; without TranslateGemma the pair line (the chat-only line
// stays, the next row).
it.each<[string, Partial<PerformanceSnapshot['placement']>, RegExp]>([
['no chat model is selected', { model: null, models: withRow('chat', { modelId: null, sizeOnDiskGb: null, onDrive: false, loaded: false }) }, /Graphics card: chat/],
['the translation model is not on this drive', { models: withRow('translation', { onDrive: false }) }, /\+ translation/],
[
'neither a chat model nor the translation model is here',
{
model: null,
models: withRow('chat', { modelId: null, sizeOnDiskGb: null, onDrive: false, loaded: false }).map((r) =>
r.role === 'translation' ? { ...r, onDrive: false } : r
)
},
/Graphics card: chat/
]
])('#914: no chat/translation card line when %s', async (_case, over, absent) => {
install(snapshot({ placement: placement(over) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
expect(screen.queryByText(absent)).not.toBeInTheDocument()
// The processor line stays.
expect(screen.getByText(/Everything loaded at once needs about/)).toBeInTheDocument()
})
// #914 code review (Fable N-5): a card machine whose drive holds the chat model but no translation model keeps the
// chat model's own card line, so the VRAM comparison does not vanish with TranslateGemma.
it('#914: the chat model on the card keeps its own card line when no translation model is on this drive', async () => {
install(snapshot({ placement: placement({ models: withRow('translation', { onDrive: false }) }) }))
renderPerformanceScreen()
expect(await screen.findByText('Graphics card: chat 5.4 GB, of 24.2 GB.')).toBeInTheDocument()
})
// #933: a model on this drive that every start refuses (its files failed their check, or it has no checksum on
// record; main reads `fileCheck` from the checksum cache) says why, where the other rows say loaded / not loaded.
it.each<[ModelFileVerdict, 'perf.models.damaged' | 'perf.models.noChecksum']>([
['damaged', 'perf.models.damaged'],
['unverified', 'perf.models.noChecksum']
])('#933: a row whose fileCheck is %s says why in place of "not loaded"', async (fileCheck, key) => {
install(snapshot({ placement: placement({ models: withRow('vision', { fileCheck }) }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
const images = otherRow(/^Images$/)
expect(within(images).getByText(t('en', key))).toBeInTheDocument()
expect(within(images).queryByText('not loaded')).not.toBeInTheDocument()
})
// #933: loaded beats it, as it beats `onDrive`: a resident model is in memory whatever the cache says.
it('#933: a resident model says "loaded now" even when the checksum cache says its files are damaged', async () => {
install(snapshot({ placement: placement({ models: withRow('reranker', { fileCheck: 'damaged', loaded: true }) }) }))
renderPerformanceScreen()
await screen.findByText('Models on this computer')
const ranking = otherRow(/^Document search \(ranking\)$/)
expect(within(ranking).getByText('loaded now')).toBeInTheDocument()
expect(within(ranking).queryByText(t('en', 'perf.models.damaged'))).not.toBeInTheDocument()
})
// #933: a damaged translation model never reaches the card, so the pair line does not add it; the chat model keeps
// its own card line (the #914 rule for a translation model that is not here).
it('#933: a damaged translation model is left out of the graphics-card line', async () => {
install(snapshot({ placement: placement({ models: withRow('translation', { fileCheck: 'damaged' }) }) }))
renderPerformanceScreen()
expect(await screen.findByText('Graphics card: chat 5.4 GB, of 24.2 GB.')).toBeInTheDocument()
expect(screen.queryByText(/\+ translation/)).not.toBeInTheDocument()
})
// #933: "Your model" claims no fit for an active model every start refuses, and its pill says what its row says. Its
// files are on disk, so the line keeps their size. Both verdicts (#933 review N4: `unverified` was not rendered).
it.each<[ModelFileVerdict, 'perf.models.damaged' | 'perf.models.noChecksum']>([
['damaged', 'perf.models.damaged'],
['unverified', 'perf.models.noChecksum']
])('#933: "Your model" states no fit for an active model that every start refuses (fileCheck %s)', async (fileCheck, key) => {
install(
snapshot({
placement: placement({
model: { id: 'qwen3.5-9b-ud-q4kxl', sizeOnDiskGb: 5.8, onDrive: true, fileCheck, contextTokens: 8192 },
models: withRow('chat', { fileCheck, loaded: false })
})
})
)
renderPerformanceScreen()
await screen.findByText('Models on this computer')
const block = screen.getByText('Your model').closest<HTMLElement>('.perf-model')
if (!block) throw new Error('the Your model block has no .perf-model container')
expect(within(block).getByText(t('en', key))).toBeInTheDocument()
expect(within(block).queryByText(/Should fit|Needs at least|Takes /)).not.toBeInTheDocument()
expect(within(block).queryByText(t('en', 'perf.place.gpu'))).not.toBeInTheDocument()
expect(within(block).getByText(/5\.8 GB on disk/)).toBeInTheDocument()
})
})
describe('PerformanceScreen: actions', () => {
it('"Check again" runs the benchmark, shows the steps as they land, then refreshes', async () => {
const { api, progress } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
expect(api.runBenchmark).toHaveBeenCalledTimes(1)
// Steps replace the tiles while the run is in flight.
expect(screen.getByText('Hardware detected')).toBeInTheDocument()
// Two nodes now carry the speed label: the visible one and the sr-only twin that appends
// the step state (#437). Anchor the match so only the visible line satisfies it.
expect(screen.getByText(/Generation speed with Qwen3\.5 9B \(UD-Q4_K_XL\)$/)).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Running…' })).toBeDisabled()
act(() => progress.forEach((cb) => cb('system')))
expect(screen.getByText('Hardware detected: done')).toBeInTheDocument()
await run.finish()
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(2))
expect(await screen.findByRole('button', { name: 'Check again' })).toBeInTheDocument()
})
it('offers "Start <model> and measure" when speed is unmeasured, the pick is installed and nothing runs', async () => {
const { api } = install(snapshot({ current: result({ tokensPerSecond: null, measuredModelId: null, speedBasis: null }) }), {
getRuntimeStatus: vi.fn(async () => STOPPED_STATUS)
})
renderPerformanceScreen()
const start = await screen.findByRole('button', { name: 'Start Qwen3.5 9B (UD-Q4_K_XL) and measure' })
await userEvent.click(start)
await waitFor(() => expect(api.useModel).toHaveBeenCalledWith('qwen3.5-9b-ud-q4kxl'))
await waitFor(() => expect(api.runBenchmark).toHaveBeenCalledTimes(1))
})
it('a model that will not start ends "Start … and measure" with the banner and measures nothing', async () => {
const { api } = install(snapshot({ current: result({ tokensPerSecond: null, measuredModelId: null, speedBasis: null }) }), {
getRuntimeStatus: vi.fn(async () => STOPPED_STATUS),
useModel: vi.fn(async () => {
throw new Error('Error: The model could not start')
})
})
renderPerformanceScreen()
await userEvent.click(await screen.findByRole('button', { name: 'Start Qwen3.5 9B (UD-Q4_K_XL) and measure' }))
expect(await screen.findByText(/Check failed: .*could not start/)).toBeInTheDocument()
expect(api.runBenchmark).not.toHaveBeenCalled()
expect(screen.getByRole('button', { name: 'Check again' })).toBeEnabled()
})
it('"Start … and measure" targets the LIVE recommendation, never the id saved with the check, and labels the saved one', async () => {
// A fresh probe moved the pick to the 4B (installed); the saved result still says 9B. The
// offer and the verdict follow the live pick; the saved one is history and is labelled so.
const fourBInstalled = MODELS.map((m) => (m.id === 'qwen3.5-4b-ud-q4kxl' ? { ...m, state: 'installed' } : m)) as ModelInfo[]
const { api } = install(
snapshot({
current: result({ tokensPerSecond: null, measuredModelId: null, speedBasis: null, recommendedModelId: 'qwen3.5-9b-ud-q4kxl' }),
recommendation: { modelId: 'qwen3.5-4b-ud-q4kxl', basis: 'discrete' }
}),
{
listModels: vi.fn(async () => fourBInstalled),
getRuntimeStatus: vi.fn(async () => STOPPED_STATUS)
}
)
renderPerformanceScreen()
expect(await screen.findByText(/Qwen3\.5 4B \(UD-Q4_K_XL\) is the best fit for this computer’s graphics memory\./)).toBeInTheDocument()
expect(screen.getByText('Recommended at the time of the check: Qwen3.5 9B (UD-Q4_K_XL)')).toBeInTheDocument()
expect(screen.queryByRole('button', { name: /Start Qwen3\.5 9B/ })).not.toBeInTheDocument()
await userEvent.click(screen.getByRole('button', { name: 'Start Qwen3.5 4B (UD-Q4_K_XL) and measure' }))
await waitFor(() => expect(api.useModel).toHaveBeenCalledWith('qwen3.5-4b-ud-q4kxl'))
expect(api.useModel).not.toHaveBeenCalledWith('qwen3.5-9b-ud-q4kxl')
await waitFor(() => expect(api.runBenchmark).toHaveBeenCalledTimes(1))
})
it('the verdict names the memory the live pick was judged against: graphics memory, unified memory, or RAM', async () => {
const cases: Array<[PerformanceSnapshot['recommendation'], RegExp]> = [
[{ modelId: 'qwen3.5-9b-ud-q4kxl', basis: 'unified' }, /best fit for this computer’s unified memory\./],
[{ modelId: 'qwen3.5-9b-ud-q4kxl', basis: 'cpu' }, /best fit for this computer’s RAM\./],
// Nothing in the catalog matches (or no catalog at all): the honest sentence, no CTA.
[{ modelId: null, basis: 'cpu' }, /No model in the catalog matches this computer yet\./],
[null, /No model in the catalog matches this computer yet\./]
]
for (const [recommendation, text] of cases) {
install(snapshot({ current: result({ tokensPerSecond: null, measuredModelId: null, speedBasis: null }), recommendation }), {
getRuntimeStatus: vi.fn(async () => STOPPED_STATUS)
})
renderPerformanceScreen()
expect(await screen.findByText(text)).toBeInTheDocument()
if (!recommendation?.modelId) expect(screen.queryByRole('button', { name: /and measure/ })).not.toBeInTheDocument()
cleanup()
}
})
it('"Change context size" goes to AI Model; the footer link opens Diagnostics; no "Why this model?" button', async () => {
install(snapshot())
const { onNavigate } = renderPerformanceScreen()
await userEvent.click(await screen.findByRole('button', { name: 'Change context size' }))
expect(screen.queryByRole('button', { name: /Why this model/ })).not.toBeInTheDocument()
expect(onNavigate).toHaveBeenLastCalledWith('models')
await userEvent.click(screen.getByRole('button', { name: 'Open Diagnostics' }))
expect(onNavigate).toHaveBeenLastCalledWith('settings:diagnostics')
})
it('"Copy report" hands the figures to the native clipboard', async () => {
install(snapshot())
renderPerformanceScreen()
const text = await copiedReport()
expect(text).toContain('This computer')
expect(text).toContain('Qwen3.5 9B (UD-Q4_K_XL)')
expect(text).toContain('8,192 tokens')
expect(text).toContain('Graphics memory: None')
// The report carries the result's own pick, labelled as what the check said at the time.
expect(text).toContain('Recommended at the time of the check: Qwen3.5 9B (UD-Q4_K_XL)')
})
// UI-languages owner call D-11 (a): the core count picks its plural form on this screen too, on
// the memory tile and in the copied report; until the UI languages wave one core read "(1 cores)".
// #805 S3 (open-issues wave owner round W5-4): on the tile the count sits in one `.nowrap` span
// after the space, so "(1 core)" never breaks inside (the line may still break before it); the
// text reads exactly as before, and the copied report stays plain text.
it('names a single core in the singular, on the memory tile (kept on one line) and in the copied report', async () => {
install(snapshot({ current: result({ cpuCores: 1 }) }))
renderPerformanceScreen()
const cores = t('en', 'diag.bench.cores.one', { count: 1 })
const cpu = `Intel Core i7-1260P${cores}`
const reads = (text: string) => (_: string, el: Element | null) => el?.textContent === text
await screen.findByText(reads(cpu))
const line = within(tile('Memory')).getByText(reads(cpu))
const kept = within(line).getByText(cores.trimStart())
expect(kept).toHaveClass('nowrap')
expect(kept.textContent).toBe(cores.trimStart()) // the space before it stays outside: a break may fall there
expect(await copiedReport()).toContain(`${t('en', 'diag.bench.cpu')}: ${cpu}`)
})
it.each<[string, (text: string) => Promise<boolean>, string]>([
['the clipboard took it', async () => true, 'Copied to clipboard'],
['the clipboard refused it', async () => false, 'Could not copy to the clipboard'],
[
'the call itself rejected',
async () => {
throw new Error('clipboard unavailable')
},
'Could not copy to the clipboard'
]
])('"Copy report" says how it went: %s', async (_why, copy, toast) => {
install(snapshot(), { copyToClipboard: vi.fn(copy) })
renderPerformanceScreen()
await copiedReport()
expect(await screen.findByText(toast)).toBeInTheDocument()
})
it('surfaces a failed run as a calm banner and returns to the tiles', async () => {
install(snapshot(), { runBenchmark: vi.fn(async () => { throw new Error('Error: Model is busy right now') }) })
renderPerformanceScreen()
await userEvent.click(await screen.findByRole('button', { name: 'Check again' }))
expect(await screen.findByText(/Check failed: .*busy/)).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Check again' })).toBeInTheDocument()
})
})
// Keyboard focus across the busy swap (HW3; design-guidelines §6). The busy branch renders a
// different subtree — the steps list and a disabled "Running…" button — so the action button a
// keyboard user just activated is UNMOUNTED and the active element falls back to <body>: the
// user is dropped out of the screen mid-task. The screen puts focus back on the primary action
// when the run IT started ends, and only then.
describe('PerformanceScreen: focus survives the run', () => {
it('returns focus to "Check again" after a run this window started', async () => {
const run = deferred<BenchmarkResult>()
const { api } = install(snapshot(), { runBenchmark: vi.fn(() => run.promise) })
renderPerformanceScreen()
const button = await screen.findByRole('button', { name: 'Check again' })
button.focus()
expect(document.activeElement).toBe(button)
await userEvent.keyboard('{Enter}')
await waitFor(() => expect(api.runBenchmark).toHaveBeenCalledTimes(1))
// The busy branch has replaced the actions row: the focused node is gone.
expect(screen.getByRole('button', { name: 'Running…' })).toBeDisabled()
expect(document.activeElement).toBe(document.body)
await act(async () => {
run.resolve(result())
})
const back = await screen.findByRole('button', { name: 'Check again' })
expect(document.activeElement).toBe(back)
})
it('returns focus after "Start … and measure" too — to the action the idle row keeps', async () => {
const run = deferred<BenchmarkResult>()
const { api } = install(snapshot({ current: result({ tokensPerSecond: null, measuredModelId: null, speedBasis: null }) }), {
getRuntimeStatus: vi.fn(async () => STOPPED_STATUS),
runBenchmark: vi.fn(() => run.promise)
})
renderPerformanceScreen()
const start = await screen.findByRole('button', { name: 'Start Qwen3.5 9B (UD-Q4_K_XL) and measure' })
start.focus()
await userEvent.keyboard('{Enter}')
await waitFor(() => expect(api.runBenchmark).toHaveBeenCalledTimes(1))
expect(document.activeElement).toBe(document.body)
await act(async () => {
run.resolve(result())
})
const back = await screen.findByRole('button', { name: 'Check again' })
expect(document.activeElement).toBe(back)
})
it('returns focus after a run that failed: the banner must not strand the keyboard on <body>', async () => {
const run = deferred<BenchmarkResult>()
const { api } = install(snapshot(), { runBenchmark: vi.fn(() => run.promise) })
renderPerformanceScreen()
const button = await screen.findByRole('button', { name: 'Check again' })
button.focus()
await userEvent.keyboard('{Enter}')
await waitFor(() => expect(api.runBenchmark).toHaveBeenCalledTimes(1))
expect(document.activeElement).toBe(document.body)
await act(async () => {
run.reject(new Error('Error: Model is busy right now'))
})
expect(await screen.findByText(/Check failed: .*busy/)).toBeInTheDocument()
expect(document.activeElement).toBe(screen.getByRole('button', { name: 'Check again' }))
})
it('a run this window did NOT start never steals focus', async () => {
// Another window (or the first-run path) takes the lane and releases it. Nothing here was
// activated, so the caret stays wherever the user left it — on the link they were reading.
const { api, pushes } = install(snapshot({ running: true }))
renderPerformanceScreen()
await screen.findByRole('button', { name: 'Running…' })
const elsewhere = screen.getByRole('button', { name: 'Open Diagnostics' })
elsewhere.focus()
expect(document.activeElement).toBe(elsewhere)
api.getPerformance.mockResolvedValue(snapshot({ running: false }))
await pushChanged(pushes)
await screen.findByRole('button', { name: 'Check again' })
expect(document.activeElement).toBe(elsewhere)
})
})
// The pushed refresh (PR #303 audit M1/M3; benchmark.md "Push, not poll"). `performance:changed`
// carries nothing: every push means "re-read `performance:get`". The screen's own action flag and
// the backend's occupancy span stay separate — one belongs to this window, the other to the
// machine — and no read is polled, dropped, doubled or applied out of order.
describe('PerformanceScreen: the pushed refresh', () => {
it('subscribes before the first read, and unsubscribes on unmount', async () => {
const { api, calls, pushes, unsubscribed } = install(snapshot())
const view = renderPerformanceScreen()
await screen.findByText(/Runs Qwen3\.5 9B/)
// A push that lands DURING the first read must find a listener already there.
expect(calls[0]).toBe('onPerformanceChanged')
expect(calls.indexOf('onPerformanceChanged')).toBeLessThan(calls.indexOf('getPerformance'))
expect(api.onPerformanceChanged).toHaveBeenCalledTimes(1)
const reads = api.getPerformance.mock.calls.length
view.unmount()
expect(unsubscribed()).toBe(1)
await pushChanged(pushes)
expect(api.getPerformance).toHaveBeenCalledTimes(reads)
})
it('registers one listener per mount and leaves none behind on a remount', async () => {
const { api, pushes, unsubscribed } = install(snapshot())
const first = renderPerformanceScreen()
await screen.findByText(/Runs Qwen3\.5 9B/)
first.unmount()
renderPerformanceScreen()
await screen.findByText(/Runs Qwen3\.5 9B/)
expect(api.onPerformanceChanged).toHaveBeenCalledTimes(2)
expect(unsubscribed()).toBe(1)
// Both callbacks still exist in the fake bridge; only the live screen reads.
expect(pushes).toHaveLength(2)
const reads = api.getPerformance.mock.calls.length
await pushChanged(pushes)
expect(api.getPerformance).toHaveBeenCalledTimes(reads + 1)
})
it('M1: a run this window did not start releases the screen the moment the backend is idle', async () => {
const { api, pushes } = install(snapshot({ running: true }))
renderPerformanceScreen()
expect(await screen.findByRole('button', { name: 'Running…' })).toBeDisabled()
api.getPerformance.mockResolvedValue(snapshot({ running: false }))
await pushChanged(pushes)
expect(await screen.findByRole('button', { name: 'Check again' })).toBeEnabled()
// The tiles are back, not just the button.
expect(screen.getByText('Speed')).toBeInTheDocument()
expect(screen.getByText(/Runs Qwen3\.5 9B/)).toBeInTheDocument()
})
it('M1 + #438: an external run shows as running with the background line, never the last run’s steps', async () => {
const { api, progress, pushes } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
act(() => progress.forEach((cb) => cb('system')))
expect(screen.getByText('Hardware detected: done')).toBeInTheDocument()
await run.finish()
await screen.findByRole('button', { name: 'Check again' })
// Someone else takes the lane. Main addresses progress to the window that invoked the run, so
// this window is never sent that run's steps and a step list could only sit frozen on step 1
// (#438, measured at 13.7 s on a real moved-drive check). The region carries one honest line
// instead — and nothing of our own finished run survives into it.
api.getPerformance.mockResolvedValue(snapshot({ running: true }))
await pushChanged(pushes)
expect(await screen.findByRole('button', { name: 'Running…' })).toBeDisabled()
expect(screen.getByText('Checking this computer in the background.')).toBeInTheDocument()
expect(screen.queryByText('Hardware detected')).not.toBeInTheDocument()
})
it('#438: the background line sits IN the step region, so an automatic check is still announced', async () => {
install(snapshot({ running: true }))
renderPerformanceScreen()
// The region is the always-mounted <ul> of #437: the line arrives as a text change inside a
// region that was already there, which is what makes it audible. An empty region would have
// left the automatic check silent — the cost this option would otherwise have carried.
const region = (await screen.findByText('Checking this computer in the background.')).closest('ul')
expect(region).toHaveClass('perf-steps')
expect(region).toHaveAttribute('aria-live', 'polite')
})
it('#438: at the tail of our own run the list stays ours, never blinking to the background line', async () => {
const { api, progress, pushes } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
act(() => progress.forEach((cb) => cb('system')))
// The backend still holds the span when the invoke resolves and `ownActionInFlight` drops —
// exactly the window in which that flag ALONE would have handed the region to the background
// line for a run the user is watching their own steps on.
api.getPerformance.mockResolvedValue(snapshot({ running: true }))
await pushChanged(pushes)
await run.finish()
expect(screen.queryByText('Checking this computer in the background.')).not.toBeInTheDocument()
expect(screen.getByText('Hardware detected: done')).toBeInTheDocument()
})
it('the push announcing our OWN run does not un-tick the steps it already reported', async () => {
const { api, progress, pushes } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
act(() => progress.forEach((cb) => cb('system')))
// Main pushes when the run takes its span — that snapshot is about OUR run.
api.getPerformance.mockResolvedValue(snapshot({ running: true }))
await pushChanged(pushes)
expect(screen.getByText('Hardware detected: done')).toBeInTheDocument()
await run.finish()
})
it('back-to-back checks each start with a clean step list', async () => {
const { progress } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
act(() => progress.forEach((cb) => cb('system')))
act(() => progress.forEach((cb) => cb('drive')))
expect(screen.getByText('Drive speed: done')).toBeInTheDocument()
await run.finish()
const second = await startOwnRun()
// The second run starts from nothing — never from what the first one reported.
expect(screen.getByText('Hardware detected: in progress')).toBeInTheDocument()
expect(screen.getByText('Drive speed: waiting')).toBeInTheDocument()
await second.finish()
})
it('M3: an observation from normal use fills the rows without leaving the screen', async () => {
const { api, pushes } = install(snapshot({ observed: noObservations }))
renderPerformanceScreen()
await screen.findByText(/Nothing observed yet this session/)
api.getPerformance.mockResolvedValue(snapshot({ observed: observedAnswer }))
await pushChanged(pushes)
expect(await screen.findByText(/Last answer: 40\.0 tokens \/ s/)).toBeInTheDocument()
expect(screen.queryByText(/Nothing observed yet this session/)).not.toBeInTheDocument()
})
it('a check this window starts disables its own button while the backend is still idle', async () => {
const { api } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
// Nothing pushed and the snapshot still says idle: the local flag alone drives this.
expect(screen.getByRole('button', { name: 'Running…' })).toBeDisabled()
expect(api.getPerformance).toHaveBeenCalledTimes(1)
await run.finish()
expect(await screen.findByRole('button', { name: 'Check again' })).toBeEnabled()
expect(api.getPerformance).toHaveBeenCalledTimes(2)
})
it('a push during a read is never dropped: one more read follows it', async () => {
const first = deferred<PerformanceSnapshot>()
let call = 0
const { api, pushes } = install(snapshot(), {
getPerformance: vi.fn(() => {
call += 1
return call === 1 ? first.promise : Promise.resolve(snapshot({ observed: observedAnswer }))
})
})
renderPerformanceScreen()
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(1))
await pushChanged(pushes)
// Serialised: the follow-up waits for the read already out.
expect(api.getPerformance).toHaveBeenCalledTimes(1)
await act(async () => {
first.resolve(snapshot({ observed: noObservations }))
})
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(2))
expect(await screen.findByText(/Last answer: 40\.0 tokens \/ s/)).toBeInTheDocument()
})
it('several pushes during one read coalesce into a single follow-up read', async () => {
const first = deferred<PerformanceSnapshot>()
let call = 0
const { api, pushes } = install(snapshot(), {
getPerformance: vi.fn(() => {
call += 1
return call === 1 ? first.promise : Promise.resolve(snapshot())
})
})
renderPerformanceScreen()
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(1))
await pushChanged(pushes)
await pushChanged(pushes)
await pushChanged(pushes)
expect(api.getPerformance).toHaveBeenCalledTimes(1)
await act(async () => {
first.resolve(snapshot())
})
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(2))
// …and no third: one pass answered all three pushes.
await act(async () => {})
expect(api.getPerformance).toHaveBeenCalledTimes(2)
})
it('a reply from a superseded read is discarded, never applied over a newer one', async () => {
// The runtime status is read alongside each snapshot. Hold the FIRST one open, let a push
// issue a second read whose status says nothing is running, then answer the first with the
// opposite: the stale answer must not take the "Start … and measure" offer away.
const slowStatus = deferred<RuntimeStatus>()
let statusCall = 0
const { api, pushes } = install(
snapshot({ current: result({ tokensPerSecond: null, measuredModelId: null, speedBasis: null }) }),
{
getRuntimeStatus: vi.fn(() => {
statusCall += 1
return statusCall === 1 ? slowStatus.promise : Promise.resolve(STOPPED_STATUS)
})
}
)
renderPerformanceScreen()
await waitFor(() => expect(api.getRuntimeStatus).toHaveBeenCalledTimes(1))
await pushChanged(pushes)
await waitFor(() => expect(api.getRuntimeStatus).toHaveBeenCalledTimes(2))
expect(await screen.findByRole('button', { name: 'Start Qwen3.5 9B (UD-Q4_K_XL) and measure' })).toBeInTheDocument()
await act(async () => {
slowStatus.resolve(RUNNING_STATUS)
})
expect(screen.getByRole('button', { name: 'Start Qwen3.5 9B (UD-Q4_K_XL) and measure' })).toBeInTheDocument()
})
it('a read that lands after unmount applies nothing', async () => {
const pending = deferred<PerformanceSnapshot>()
const { api } = install(snapshot(), { getPerformance: vi.fn(() => pending.promise) })
const view = renderPerformanceScreen()
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(1))
view.unmount()
await act(async () => {
pending.resolve(snapshot())
})
// React 18 dropped its warning for an update on an unmounted tree, so a state write is silent.
// What outlives the tree: an applied reply goes on to re-read the runtime and settings metadata.
expect(api.getRuntimeStatus).not.toHaveBeenCalled()
expect(api.getSettings).not.toHaveBeenCalled()
})
it('the done step re-reads instead of declaring the run over', async () => {
const { api, progress } = install(snapshot({ running: true }))
renderPerformanceScreen()
expect(await screen.findByRole('button', { name: 'Running…' })).toBeDisabled()
// 'done' means the PROBES finished — the persist and the release still follow, so the
// screen re-reads and keeps the run up until a snapshot says otherwise.
await act(async () => {
progress.forEach((cb) => cb('done'))
})
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(2))
expect(screen.getByRole('button', { name: 'Running…' })).toBeDisabled()
api.getPerformance.mockResolvedValue(snapshot({ running: false }))
await act(async () => {
progress.forEach((cb) => cb('done'))
})
await waitFor(() => expect(screen.getByRole('button', { name: 'Check again' })).toBeEnabled())
})
it('a failed read keeps the figures, says so, and the retry brings them back', async () => {
let call = 0
const { api, pushes } = install(snapshot(), {
getPerformance: vi.fn(async () => {
call += 1
if (call === 2) throw new Error("Error invoking remote method 'performance:get': Error: Workspace is locked")
return snapshot()
})
})
renderPerformanceScreen()
await screen.findByText(/Runs Qwen3\.5 9B/)
await pushChanged(pushes)
expect(await screen.findByText(/Could not read the latest figures: Workspace is locked/)).toBeInTheDocument()
// The last figures stay on screen and the actions stay live.
expect(screen.getByText(/Runs Qwen3\.5 9B/)).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Check again' })).toBeEnabled()
await userEvent.click(screen.getByRole('button', { name: 'Try again' }))
await waitFor(() => expect(screen.queryByText(/Could not read the latest figures/)).not.toBeInTheDocument())
expect(api.getPerformance).toHaveBeenCalledTimes(3)
})
it('a later successful read clears the read failure without hiding the failed check', async () => {
let call = 0
const { pushes } = install(snapshot(), {
runBenchmark: vi.fn(async () => {
throw new Error('Error: Model is busy right now')
}),
getPerformance: vi.fn(async () => {
call += 1
if (call === 3) throw new Error('Error: Workspace is locked')
return snapshot()
})
})
renderPerformanceScreen()
await userEvent.click(await screen.findByRole('button', { name: 'Check again' }))
expect(await screen.findByText(/Check failed: .*busy/)).toBeInTheDocument()
await pushChanged(pushes)
expect(
await screen.findByText(/Check failed: .*busy.*Could not read the latest figures: Workspace is locked/)
).toBeInTheDocument()
await pushChanged(pushes)
await waitFor(() => expect(screen.queryByText(/Could not read the latest figures/)).not.toBeInTheDocument())
expect(screen.getByText(/Check failed: .*busy/)).toBeInTheDocument()
})
it('a failed check clears only the local flag — a run that holds the lane still holds the screen', async () => {
const { api, pushes } = install(snapshot(), {
runBenchmark: vi.fn(async () => {
throw new Error('Error: Model is busy right now')
})
})
renderPerformanceScreen()
await screen.findByRole('button', { name: 'Check again' })
// Refused because another run already holds the lane — which the next read reports.
api.getPerformance.mockResolvedValue(snapshot({ running: true }))
await userEvent.click(screen.getByRole('button', { name: 'Check again' }))
expect(await screen.findByText(/Check failed: .*busy/)).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Running…' })).toBeDisabled()
// When that run ends, the push brings the screen back — with the failure still on it.
api.getPerformance.mockResolvedValue(snapshot({ running: false }))
await pushChanged(pushes)
expect(await screen.findByRole('button', { name: 'Check again' })).toBeEnabled()
expect(screen.getByText(/Check failed: .*busy/)).toBeInTheDocument()
})
it('survives a StrictMode double mount: the stale first reply is discarded and the re-read still loads', async () => {
// React.StrictMode (main.tsx) runs every effect twice in development: mount → cleanup →
// mount, on the SAME instance. The first read is still in flight when the cleanup bumps the
// generation and the second mount asks for a read of its own; that read must follow, or the
// screen sits on its empty state until the next push (the P3 launch smoke showed exactly
// that: a completed first-run benchmark and a screen saying "Not checked yet").
const first = deferred<PerformanceSnapshot>()
const second = deferred<PerformanceSnapshot>()
let reads = 0
const { api } = install(snapshot(), {
getPerformance: vi.fn(() => {
reads += 1
return reads === 1 ? first.promise : second.promise
})
})
render(
<StrictMode>
<ToastProvider>
<PerformanceScreen onNavigate={vi.fn()} />
</ToastProvider>
</StrictMode>
)
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(1))
await act(async () => {
first.resolve(snapshot())
})
await waitFor(() => expect(api.getPerformance).toHaveBeenCalledTimes(2))
// The models card renders only from an APPLIED snapshot: the first reply was discarded…
expect(screen.queryByText('Models on this computer')).not.toBeInTheDocument()
await act(async () => {
second.resolve(snapshot())
})
// …and the re-read lands.
expect(await screen.findByText('Models on this computer')).toBeInTheDocument()
expect(api.getPerformance).toHaveBeenCalledTimes(2)
})
})
// PR #303 audit P4 (H1 / L8 / M5 residual): the persisted benchmark records are validated on
// both sides of the settings store now, and the screen reads the launch context off the
// snapshot instead of recomputing it. These cover what the screen must do with what it is
// handed — including a record that never should have reached it.
describe('PerformanceScreen: malformed records and the resolved context', () => {
it('H1: a structurally invalid other-computer row costs its own figures, never the screen', async () => {
// The exact shape the old settings gate accepted and the snapshot exposed. `fmt1(undefined)`
// threw here and took the whole page down; the app-level ErrorBoundary (App.tsx:513) would now
// catch that, at the cost of the screen.
install(snapshot({ otherMachines: [{} as BenchmarkResult, office] }))
renderPerformanceScreen()
// The screen is up, the healthy row beside the blob is complete…
expect(await screen.findByText('Other computers this drive has been used on')).toBeInTheDocument()
expect(screen.getByText(/Intel Core i9-13900K, 64\.0 GB RAM, 24\.0 GB VRAM/)).toBeInTheDocument()
// …and the blob reads as unknowns rather than crashing or inventing figures.
expect(screen.getByText(/Unknown CPU, – GB RAM/)).toBeInTheDocument()
expect(screen.getAllByText('Unknown').length).toBeGreaterThanOrEqual(1)
})
it('H1: a partially filled record renders the fields it has and dashes the ones it lacks', async () => {
const partial = { cpuModel: 'Half A Record', profile: 'LITE', ranAt: '2026-08-01T00:00:00Z' } as unknown as BenchmarkResult
install(snapshot({ otherMachines: [partial] }))
renderPerformanceScreen()
expect(await screen.findByText(/Half A Record, – GB RAM/)).toBeInTheDocument()
// Its own profile pill (the current result carries the same one).
expect(screen.getAllByText('Lite')).toHaveLength(2)
})
it('H1: a current result with no usable figures still renders the card', async () => {
const legacy = { profile: 'BALANCED', ranAt: '' } as unknown as BenchmarkResult
install(snapshot({ current: legacy, otherMachines: [] }))
renderPerformanceScreen()
// An unknown date says so instead of printing "Invalid Date" or an empty stamp.
expect(await screen.findByText('Checked –')).toBeInTheDocument()
expect(screen.getByText('Balanced')).toBeInTheDocument()
})
it('#746: the same record still copies: no warnings list is no reason to lose the report', async () => {
install(snapshot({ current: { profile: 'BALANCED', ranAt: '' } as unknown as BenchmarkResult, otherMachines: [] }))
renderPerformanceScreen()
expect(await copiedReport()).toContain('BALANCED')
})
it('M5 residual: the context in the report is the snapshot’s, not a recomputed catalog value', async () => {
// The catalog says 8,192 for this model; the snapshot says what the runtime would ACTUALLY
// launch with (a manifest stating no window falls back to the settings default). The screen
// must state the snapshot's figure — recomputing produced "0-token context" for that model.
install(snapshot({ placement: placement({ recommendedContextTokens: 4096 }) }))
renderPerformanceScreen()
const text = await copiedReport()
expect(text).toContain('4,096 tokens')
expect(text).not.toContain('8,192 tokens')
expect(text).not.toContain('0 tokens')
})
it('M5 residual: with nothing recommended the report states no context at all', async () => {
// The no-match shape: `contextFor(null)` is null (registerBenchmarkIpc.ts:1018-1019), and a live object still reaches the inner guard.
install(snapshot({ recommendation: { modelId: null, basis: 'cpu' }, placement: placement({ recommendedContextTokens: null }) }))
renderPerformanceScreen()
const text = await copiedReport()
expect(text).toContain(`Recommended for the next start: ${t('en', 'diag.bench.noMatch')}`)
expect(text).not.toContain('Context size')
})
it('the same line in German (D-L8: asserted from the catalog, never a retyped literal)', async () => {
install(
snapshot({
placement: placement({
observed: null,
observedMismatch: { contextTokens: 32_768, backend: 'gpu', at: '2026-09-01T00:00:00Z' }
})
})
)
renderPerformanceScreen({ lang: 'de' })
const expected = tCount('de', 'perf.model.measuredOther', 32_768, {
context: (32_768).toLocaleString('de'),
when: new Date('2026-09-01T00:00:00Z').toLocaleDateString('de')
})
expect(await screen.findByText(expected)).toBeInTheDocument()
})
})
// A pair whose text shows a locale-grouped figure gets the raw number as the count and the grouped
// string as the param (i18n record §5). English and German say "tokens"/"Token" in both forms, so
// only a language with more forms can tell whether the count really is the figure shown. Each row
// shows two figures in two Russian forms: 32,768 is `many` («токенов») and 8,192 is `few`
// («токена»), so no single constant selector passes both. The field each row could mix its figure
// up with holds the other one, so a selector reading the wrong field fails too. The figure itself
// is compared with `Intl` output, never a typed literal: Russian groups with a no-break space.
describe('PerformanceScreen: in Russian, each context figure picks its own plural form', () => {
const FIGURES = [
{ shown: 32_768, form: 'many', other: 8192 },
{ shown: 8192, form: 'few', other: 32_768 }
] as const
const ru = (key: string, params: Record<string, string>): string =>
Object.entries(params).reduce((text, [name, value]) => text.split(`{${name}}`).join(value), catalogOf('ru')[key])
const grouped = (n: number): string => new Intl.NumberFormat('ru').format(n)
// The default collapses every whitespace run to a plain space, the no-break space included.
const exact = { normalizer: getDefaultNormalizer({ collapseWhitespace: false }) }
it.each(FIGURES)('the Your-model line, by the model’s context size: $shown ($form)', async ({ shown, form, other }) => {
install(
snapshot({
placement: placement({
model: { id: MODELS[0].id, sizeOnDiskGb: 5.8, onDrive: true, contextTokens: shown },
recommendedContextTokens: other
})
})
)
renderPerformanceScreen({ lang: 'ru' })
const line = ru(`perf.model.line.${form}`, { model: MODELS[0].displayName, size: fmt1(5.8, 'ru'), context: grouped(shown) })
expect(await screen.findByText(line, exact)).toBeInTheDocument()
})
it.each(FIGURES)('the measured-earlier note, by the measured context size: $shown ($form)', async ({ shown, form, other }) => {
install(
snapshot({
placement: placement({
model: { id: MODELS[0].id, sizeOnDiskGb: 5.8, onDrive: true, contextTokens: other },
observed: null,
observedMismatch: { contextTokens: shown, backend: 'gpu', at: '2026-09-01T00:00:00Z' }
})
})
)
renderPerformanceScreen({ lang: 'ru' })
const note = ru(`perf.model.measuredOther.${form}`, {
context: grouped(shown),
when: new Date('2026-09-01T00:00:00Z').toLocaleDateString('ru')
})
expect(await screen.findByText(note, exact)).toBeInTheDocument()
})
it.each(FIGURES)('the copied report, by the recommended context size: $shown ($form)', async ({ shown, form, other }) => {
install(
snapshot({
placement: placement({
model: { id: MODELS[0].id, sizeOnDiskGb: 5.8, onDrive: true, contextTokens: other },
recommendedContextTokens: shown
})
})
)
renderPerformanceScreen({ lang: 'ru' })
const text = await copiedReport(t('ru', 'perf.copy'))
expect(text.split('\n')).toContain(
`${t('ru', 'models.context.title')}: ${ru(`models.tech.contextValue.${form}`, { count: grouped(shown) })}`
)
})
})
// PR #303 audit P6 (L6): a decode figure never travels without HOW it was measured. The Speed
// tile already said "Approximate" for a chunk-counted reading; the Copy report and the
// other-computer rows presented the same number as an ordinary tokens/s figure with a Good/Slow
// rating, and the report headed every machine's figures "This computer".
describe('PerformanceScreen: where a speed figure came from', () => {
it('L6: the report carries the window a runtime-timings figure covers, and calls it nothing else', async () => {
install(snapshot())
renderPerformanceScreen()
const text = await copiedReport()
expect(text).toContain('12 tokens / s (Measured with Qwen3.5 9B (UD-Q4_K_XL) on')
expect(text).toContain('over 64 tokens')
expect(text).not.toMatch(/approximate/i)
expect(text).not.toMatch(/chunks/i)
})
it('L6: the report preserves the approximation qualifier and the chunk window', async () => {
install(snapshot({ current: result({ speedBasis: { basis: 'chunks', tokens: 10 } }) }))
renderPerformanceScreen()
const text = await copiedReport()
expect(text).toContain('Approximate: counted chunks, not runtime timings; 10 chunks')
expect(text).not.toContain('over 10 tokens')
})
it('L6: a legacy result with NO basis is approximate with no invented window, on the tile and in the report', async () => {
// Every result persisted before #291 was chunk-based and recorded no window. The app says
// so and stops there — it never dresses the missing figure up as a token or chunk count.
const legacy = result()
delete (legacy as Partial<BenchmarkResult>).speedBasis
install(snapshot({ current: legacy }))
renderPerformanceScreen()
expect(await screen.findByText('Approximate')).toBeInTheDocument()
expect(screen.getByText(/Approximate: counted chunks, not runtime timings/)).toBeInTheDocument()
const text = await copiedReport()
expect(text).toContain('Approximate: counted chunks, not runtime timings')
expect(text).not.toMatch(/\d+ chunks/)
expect(text).not.toMatch(/over \d+ tokens/)
})
it('L6: a result from another computer is not headed "This computer" — the report names the machine it belongs to', async () => {
install(snapshot({ currentMachine: false }))
renderPerformanceScreen()
const text = await copiedReport()
expect(text.split('\n')[0]).toBe('Another computer: Intel Core i7-1260P, 15.7 GB RAM')
expect(text).not.toContain('This computer')
})
it('L6: an other-computer row measured from chunks reads "Approximate", never Good or Slow', async () => {
install(snapshot({
otherMachines: [result({ cpuModel: 'Old CPU', ramGb: 8, tokensPerSecond: 24, speedBasis: { basis: 'chunks', tokens: 10 } })]
}))
renderPerformanceScreen()
await screen.findByText(/Old CPU/)
const row = otherRow(/Old CPU/)
expect(within(row).getByText('Approximate')).toBeInTheDocument()
// The qualifier travels with the row, in the same words the tile uses.
expect(
within(row).getByText(/Old CPU, 8\.0 GB RAM · .* · Approximate: counted chunks, not runtime timings; 10 chunks/)
).toBeInTheDocument()
// 24 tokens/s is above the slow threshold — the row must not claim the machine is Good on
// the strength of a figure the app cannot stand behind. Scoped to the row: the CURRENT
// result is a timings figure and keeps its own Good rating on the Speed tile.
expect(within(row).queryByText('Good')).not.toBeInTheDocument()
expect(within(row).queryByText('Slow')).not.toBeInTheDocument()
})
it('an other-computer row with no speed names the model recommended there, and rates nothing it did not measure', async () => {
install(snapshot({
otherMachines: [result({ cpuModel: 'Quiet CPU', tokensPerSecond: null, measuredModelId: null, speedBasis: null, recommendedModelId: 'qwen3.5-4b-ud-q4kxl' })]
}))
renderPerformanceScreen()
expect(await screen.findByText('Qwen3.5 4B (UD-Q4_K_XL) recommended, speed not measured')).toBeInTheDocument()
const row = otherRow(/Quiet CPU/)
for (const rating of ['Good', 'Slow', 'Approximate']) expect(within(row).queryByText(rating)).not.toBeInTheDocument()
})
it('L6: an other-computer row with NO basis is approximate with no window', async () => {
const legacy = result({ cpuModel: 'Older CPU', ramGb: 8, tokensPerSecond: 24 })
delete (legacy as Partial<BenchmarkResult>).speedBasis
install(snapshot({ otherMachines: [legacy] }))
renderPerformanceScreen()
expect(await screen.findByText('Approximate')).toBeInTheDocument()
expect(screen.getByText(/Older CPU, 8\.0 GB RAM · .* · Approximate: counted chunks, not runtime timings$/)).toBeInTheDocument()
expect(screen.queryByText(/chunks;/)).not.toBeInTheDocument()
})
it('L6: an other-computer row measured from runtime timings keeps its Good/Slow rating and names its window', async () => {
install(snapshot({ otherMachines: [office, oldLaptop] }))
renderPerformanceScreen()
await screen.findByText(/41 tokens \/ s with Qwen3\.8 27B UD-Q4_K_M/)
expect(screen.queryByText('Approximate')).not.toBeInTheDocument()
// office (41 t/s) is Good, oldLaptop (2 t/s) is Slow. Scoped: the Speed tile and the observed
// answer row supply two more "Good"s elsewhere on the screen.
expect(within(otherRow(/Intel Core i9-13900K/)).getByText('Good')).toBeInTheDocument()
expect(within(otherRow(/Intel Core i5-8250U/)).getByText('Slow')).toBeInTheDocument()
expect(screen.getByText(/Intel Core i9-13900K, 64\.0 GB RAM, 24\.0 GB VRAM · .* · over 64 tokens/)).toBeInTheDocument()
})
// §5 item 22 (d), owner decision 2026-09-08: how long a model took to START was answerable
// only for the CURRENT machine ("Observed while you worked"), although every persisted result
// already carries the sample. No schema change — `BenchmarkResult.effectiveRead` is on the
// history rows too; this is a renderer change. The three branches below are the whole feature,
// and the middle one is the honesty of it.
describe('item 22 (d): the model-start duration on an other-computer row', () => {
it("a 'model_load' sample shows the duration as a model start", async () => {
install(snapshot({ otherMachines: [office] }))
renderPerformanceScreen()
await screen.findByText(/41 tokens \/ s with/)
// office's sample: 13,500 ms → 13.5 s, beside the machine's own facts.
expect(screen.getByText(/Intel Core i9-13900K, .* · model start 13\.5 s ·/)).toBeInTheDocument()
})
it("a 'checksum' sample is a FILE CHECK and is never labelled a model start", async () => {
const checked = result({
cpuModel: 'Checksum Box',
effectiveRead: { mbps: 70, bytes: 2_500_000_000, ms: 36_000, source: 'checksum', modelId: 'qwen3.5-4b-ud-q4kxl', at: '2026-08-28T10:00:00Z' }
})
install(snapshot({ otherMachines: [checked] }))
renderPerformanceScreen()
await screen.findByText(/Checksum Box/)
expect(screen.getByText(/Checksum Box, .* · file check 36\.0 s ·/)).toBeInTheDocument()
// The teeth: a full file check reads the same bytes but is NOT a model start.
expect(screen.queryByText(/model start/)).not.toBeInTheDocument()
})
const absent = result({ cpuModel: 'Legacy Box' })
delete (absent as Partial<BenchmarkResult>).effectiveRead
it.each([
['field absent', absent],
['explicit null', result({ cpuModel: 'Legacy Box', effectiveRead: null })]
])('a row persisted before the field existed shows NOTHING — no placeholder, no zero (%s)', async (_why, legacy) => {
install(snapshot({ otherMachines: [legacy] }))
renderPerformanceScreen()
await screen.findByText(/Legacy Box/)
expect(screen.queryByText(/model start/)).not.toBeInTheDocument()
expect(screen.queryByText(/file check/)).not.toBeInTheDocument()
// A "0.0 s" would read as "it started instantly" — the row must simply not claim.
expect(screen.queryByText(/0\.0 s/)).not.toBeInTheDocument()
// The rest of the sub line is unaffected.
expect(screen.getByText(/Legacy Box, 15\.7 GB RAM · .* · over 64 tokens$/)).toBeInTheDocument()
})
})
})
// PR #303 audit P6 (N4 / N5): two labels that contradicted the figure beside them.
describe('PerformanceScreen: labels that match what is measured', () => {
it('N4: the empty Drive tile credits a file check as well as a model start', async () => {
install(snapshot({ current: result({ effectiveRead: null }) }))
renderPerformanceScreen()
expect(await screen.findByText('Measured by the first model start or file check')).toBeInTheDocument()
})
it('N5: the drive step is "Drive speed", not "Drive write speed" beside a tile reading MB/s read', async () => {
install(snapshot())
renderPerformanceScreen()
// The step list belongs to a run THIS window started (#438), so press the button rather than
// borrowing a foreign `running: true` span — that now shows the one-line background state.
const run = await startOwnRun()
expect(screen.getByText('Drive speed')).toBeInTheDocument()
expect(screen.queryByText(/write speed/i)).not.toBeInTheDocument()
await run.finish()
})
})
// Issue #325 — three residuals the PR #308 review left on this screen: (1) with the GPU switched
// off (or auto-disabled) the tile must not fall back to a card the result RECORDED while the GPU
// was on; (2) the Copy report carries the live pick beside the saved one; (3) a model running on
// the graphics card right now says so on the "Your model" row (the runtime status plus the
// placement evidence — the `observedMismatch` rule itself, #303 P4, is untouched).
describe('PerformanceScreen: #325 residuals', () => {
const recordedCard = result({ gpu: 'NVIDIA GeForce RTX 3070', gpuVramMb: 8192 })
const noCard = result({ gpu: null, gpuVramMb: null })
it.each([
['a card the saved result recorded', recordedCard],
['a saved result with no card', noCard]
])('#325 (1): with the GPU switched off the off state wins over %s', async (_why, current) => {
for (const flags of [{ gpuMode: 'off' as const }, { gpuAutoDisabled: true }]) {
install(snapshot({ current, currentGpu: null, placement: placement({ memoryClass: 'cpu', vramMb: null }) }), {
// The probe still lists the card: the copy names the cause, not a missing card.
getSettings: vi.fn(async () => ({
...DEFAULT_SETTINGS,
...flags,
gpuProbe: { devices: [{ id: 'Vulkan0', name: 'NVIDIA GeForce RTX 3070', totalMb: 8192, freeMb: 8000 }], probedAt: '2026-09-05T00:00:00Z' }
}))
})
renderPerformanceScreen()
expect(await screen.findByText('Graphics acceleration is off. Models run on the processor.')).toBeInTheDocument()
expect(screen.queryByText('Usable')).not.toBeInTheDocument()
expect(screen.queryByText('NVIDIA GeForce RTX 3070')).not.toBeInTheDocument()
expect(screen.queryByText(/No usable graphics card/)).not.toBeInTheDocument()
expect(screen.getByText('None')).toBeInTheDocument()
// The report follows the tile: the off copy, never the recorded card.
const text = await copiedReport()
expect(text).toContain('Graphics memory: Graphics acceleration is off. Models run on the processor.')
expect(text).not.toContain('RTX 3070')
cleanup()
}
})
it('#381 review: acceleration off HERE never overwrites another computer’s recorded card — the tile and the report both name it', async () => {
for (const flags of [{ gpuMode: 'off' as const }, { gpuAutoDisabled: true }]) {
install(
snapshot({ current: recordedCard, currentMachine: false, currentGpu: null, graphicsDevice: null, placement: placement({ memoryClass: 'cpu', vramMb: null }) }),
{ getSettings: vi.fn(async () => ({ ...DEFAULT_SETTINGS, ...flags })) }
)
renderPerformanceScreen()
// One `graphicsFigure` feeds the tile AND the report, so the leak showed on both. The
// pill is the tile's own tell: the record's card rates "Usable", the off branch "None".
expect(await screen.findByText('Usable')).toBeInTheDocument()
expect(screen.getByText('NVIDIA GeForce RTX 3070')).toBeInTheDocument()
expect(screen.queryByText('Graphics acceleration is off. Models run on the processor.')).not.toBeInTheDocument()
const text = await copiedReport()
expect(text.split('\n')[0]).toBe('Another computer: Intel Core i7-1260P, 15.7 GB RAM')
expect(text).toContain('Graphics memory: 8.0 GB VRAM (NVIDIA GeForce RTX 3070)')
expect(text).not.toContain('Graphics acceleration is off')
cleanup()
}
})
it('#325 (1): with the GPU on, the same recorded card still fills the tile (the fallback is kept)', async () => {
install(snapshot({ current: recordedCard, currentGpu: null }))
renderPerformanceScreen()
expect(await screen.findByText('Usable')).toBeInTheDocument()
expect(screen.getByText('NVIDIA GeForce RTX 3070')).toBeInTheDocument()
})
it('#325 (2): the Copy report carries the live recommendation beside the one saved with the check', async () => {
install(
snapshot({
recommendation: { modelId: 'qwen3.5-4b-ud-q4kxl', basis: 'cpu' },
placement: placement({ recommendedContextTokens: 4096 })
})
)
renderPerformanceScreen()
const text = await copiedReport()
expect(text).toContain('Recommended for the next start: Qwen3.5 4B (UD-Q4_K_XL) (RAM)')
expect(text).toContain('Recommended at the time of the check: Qwen3.5 9B (UD-Q4_K_XL)')
expect(text.indexOf('Recommended for the next start')).toBeLessThan(text.indexOf('Recommended at the time of the check'))
// #381: the context figure is the LIVE pick's launch context, so it sits directly under the
// live line — never after the saved one, where it reads as the saved pick's window.
const lines = text.split('\n')
const liveAt = lines.findIndex((l) => l.startsWith('Recommended for the next start'))
const contextAt = lines.findIndex((l) => l.startsWith('Context size:'))
const savedAt = lines.findIndex((l) => l.startsWith('Recommended at the time of the check:'))
expect(lines[contextAt]).toBe('Context size: 4,096 tokens')
expect(contextAt).toBe(liveAt + 1)
expect(contextAt).toBeLessThan(savedAt)
})
it('#325 (2): with no catalog there is no live line, and the saved line stands alone', async () => {
// Both figures derive from `recommendation?.modelId` MAIN-side (`contextFor(null)` is null),
// so "no live pick" and "no context" are the only pair the snapshot can carry (#381 review).
install(snapshot({ recommendation: null, placement: placement({ recommendedContextTokens: null }) }))
renderPerformanceScreen()
const text = await copiedReport()
expect(text).not.toContain('Recommended for the next start')
expect(text).not.toContain('Context size')
expect(text).toContain('Recommended at the time of the check: Qwen3.5 9B (UD-Q4_K_XL)')
})
const onCard: RuntimeStatus = { ...RUNNING_STATUS, backend: 'gpu' }
const mismatchOnCard = placement({
memoryClass: 'cpu',
vramMb: null,
observed: null,
observedMismatch: { contextTokens: 8192, backend: 'gpu', at: '2026-09-01T00:00:00Z' }
})
it('#325 (3): a model genuinely running on the graphics card right now says so, beside the dated earlier measurement', async () => {
install(snapshot({ currentGpu: null, placement: mismatchOnCard }), { getRuntimeStatus: vi.fn(async () => onCard) })
renderPerformanceScreen()
expect(await screen.findByText('Running on the graphics card right now.')).toBeInTheDocument()
// The #303 P4 rule is untouched: the mismatch note still dates the measurement.
expect(screen.getByText(/Measured earlier with a 8,192-token context on/)).toBeInTheDocument()
})
it('#325 (3): the line also stands over a matching observation', async () => {
install(snapshot({ placement: placement({ observed: OBSERVED_FULL, verdict: { kind: 'gpu', needMb: 6140, estimated: false, budgetMb: 24_822, freeAtStartMb: null, workingMb: null, spillMb: null, gpuLayers: 41, totalLayers: 41 } }) }), {
getRuntimeStatus: vi.fn(async () => onCard)
})
renderPerformanceScreen()
expect(await screen.findByText('Running on the graphics card right now.')).toBeInTheDocument()
})
const noLineRows: Array<[string, RuntimeStatus, PerformanceSnapshot['placement']]> = [
['the runtime is on the processor', { ...RUNNING_STATUS, backend: 'cpu' }, mismatchOnCard],
['nothing runs', STOPPED_STATUS, mismatchOnCard],
['another model runs on the card', { ...onCard, modelId: 'qwen3.5-4b-ud-q4kxl' }, mismatchOnCard],
['the runtime reports no backend', RUNNING_STATUS, mismatchOnCard],
[
'the placement evidence says the processor',
onCard,
placement({ memoryClass: 'cpu', vramMb: null, observed: null, observedMismatch: { contextTokens: 32_768, backend: 'cpu', at: '2026-09-01T00:00:00Z' } })
],
['there is no placement evidence at all', onCard, placement({ observed: null, observedMismatch: null })]
]
it.each(noLineRows)('#325 (3): no line when %s', async (_why, status, p) => {
const reply = deferred<RuntimeStatus>()
install(snapshot({ currentGpu: null, placement: p }), { getRuntimeStatus: vi.fn(() => reply.promise) })
renderPerformanceScreen()
expect(await screen.findByText('Your model')).toBeInTheDocument()
// The status is what the line reads: apply it, then look.
await act(async () => {
reply.resolve(status)
})
expect(screen.queryByText('Running on the graphics card right now.')).not.toBeInTheDocument()
})
it('#325 (3): the same line in German (asserted from the catalog)', async () => {
install(snapshot({ currentGpu: null, placement: mismatchOnCard }), { getRuntimeStatus: vi.fn(async () => onCard) })
renderPerformanceScreen({ lang: 'de' })
expect(await screen.findByText(t('de', 'perf.model.runningOnCard'))).toBeInTheDocument()
expect(t('de', 'perf.model.runningOnCard')).not.toBe(t('en', 'perf.model.runningOnCard'))
})
})
// Issue #381 (a side finding of the #330 round trip, F-B1.report.txt): under the "Another
// computer: …" heading the report still printed the live pick — this machine's — as a bare
// "Recommended for the next start", and the live pick's launch context after the SAVED line, so
// a reader going down the page attributed both to the other machine.
describe('PerformanceScreen: whose recommendation the report names (#381)', () => {
const otherMachineReport = () =>
install(
snapshot({
currentMachine: false,
recommendation: { modelId: 'qwen3.5-4b-ud-q4kxl', basis: 'cpu' },
placement: placement({ recommendedContextTokens: 4096 })
})
)
it('#381: under another computer’s heading the live pick is labelled as this computer’s, with its context beside it', async () => {
otherMachineReport()
renderPerformanceScreen()
const text = await copiedReport()
const lines = text.split('\n')
expect(lines[0]).toBe('Another computer: Intel Core i7-1260P, 15.7 GB RAM')
expect(text).toContain('Recommended for the next start on this computer: Qwen3.5 4B (UD-Q4_K_XL) (RAM)')
// The unqualified label would read as the other machine's pick.
expect(text).not.toMatch(/^Recommended for the next start:/m)
const liveAt = lines.findIndex((l) => l.startsWith('Recommended for the next start on this computer:'))
const contextAt = lines.findIndex((l) => l.startsWith('Context size:'))
const savedAt = lines.findIndex((l) => l.startsWith('Recommended at the time of the check:'))
expect(lines[contextAt]).toBe('Context size: 4,096 tokens')
expect(contextAt).toBe(liveAt + 1)
expect(contextAt).toBeLessThan(savedAt)
})
it('#381: the same report in German (asserted from the catalog, D-L8)', async () => {
otherMachineReport()
renderPerformanceScreen({ lang: 'de' })
const text = await copiedReport(t('de', 'perf.copy'))
const lines = text.split('\n')
expect(lines[0]).toBe(t('de', 'perf.report.otherComputer', { cpu: 'Intel Core i7-1260P', ram: fmt1(15.7, 'de') }))
const liveLabel = t('de', 'perf.recommendation.nextOnThisComputer')
expect(text).toContain(`${liveLabel}: Qwen3.5 4B (UD-Q4_K_XL) (${t('de', 'perf.basis.cpu')})`)
expect(liveLabel).not.toBe(t('en', 'perf.recommendation.nextOnThisComputer'))
// Not merely "different from English": the German line must say WHOSE computer it is.
expect(t('de', 'perf.recommendation.nextOnThisComputer')).toContain('diesem Computer')
expect(text).not.toContain(`${t('de', 'perf.recommendation.next')}:`)
const liveAt = lines.findIndex((l) => l.startsWith(`${liveLabel}:`))
const contextAt = lines.findIndex((l) => l.startsWith(`${t('de', 'models.context.title')}:`))
const savedAt = lines.findIndex((l) => l.startsWith(`${t('de', 'perf.recommendation.atCheckTime')}:`))
expect(lines[contextAt]).toBe(
`${t('de', 'models.context.title')}: ${tCount('de', 'models.tech.contextValue', 4096, { count: (4096).toLocaleString('de') })}`
)
expect(contextAt).toBe(liveAt + 1)
expect(contextAt).toBeLessThan(savedAt)
})
})
// #812 (open-issues wave owner call G-7): the maintainers read English and German. In any other
// interface language Copy report pastes the report, one divider line naming English, then the
// same report built in English. The English half is compared with what an English interface
// copies from the same snapshot, never with typed text.
describe('PerformanceScreen: an English copy of the report for support (#812)', () => {
const DIVIDER = '--- English ---'
const OTHER_LANGUAGES = UI_LANGUAGE_CODES.filter((code) => code !== 'en' && code !== 'de')
/** Lines the interface-language report must carry: the system values (CPU, model) stay as they are,
* and a size keeps a plain space before its unit in every language's copy (#804). */
const localLinesOf = (lang: UiLanguage): string[] => [
`${t(lang, 'perf.tile.memory')}: ${fmt1(15.7, lang)} ${t(lang, 'perf.tile.memory.unit')}`,
`${t(lang, 'diag.bench.cpu')}: Intel Core i7-1260P${tCount(lang, 'diag.bench.cores', 12)}`,
`${t(lang, 'models.context.title')}: ${tCount(lang, 'models.tech.contextValue', 8192, { count: (8192).toLocaleString(lang) })}`,
`${t(lang, 'perf.recommendation.atCheckTime')}: ${MODELS[0].displayName}`
]
/** Copy report with the interface in `lang`; unmounts after. */
async function copiedIn(lang: UiLanguage): Promise<string> {
install(snapshot())
renderPerformanceScreen({ lang })
const text = await copiedReport(t(lang, 'perf.copy'))
cleanup()
window.localStorage.clear()
return text
}
it.each(OTHER_LANGUAGES)('in %s: the report, a line naming English, then the English report', async (lang) => {
const english = await copiedIn('en')
const [local, englishHalf, ...rest] = (await copiedIn(lang)).split(`\n${DIVIDER}\n`)
expect(rest).toEqual([])
expect(englishHalf).toBe(english)
// The first half is the interface-language report: its own heading and wording, as many lines
// as the English one.
const lines = local.split('\n')
expect(lines[0]).toBe(t(lang, 'perf.card.title'))
expect(lines).toHaveLength(english.split('\n').length)
for (const line of localLinesOf(lang)) expect(lines).toContain(line)
})
it.each(['en', 'de'] as const)('in %s: the report alone, as before', async (lang) => {
const text = await copiedIn(lang)
expect(text).not.toMatch(/^--- .+ ---$/m)
expect(text.split('\n')[0]).toBe(t(lang, 'perf.card.title'))
for (const line of localLinesOf(lang)) expect(text.split('\n')).toContain(line)
})
})
// -------------------------------------------------------------------------------------------
// #437 — the progress steps are actually announceable.
//
// Verified by ear with Narrator on 2026-09-09 (issue #331, HW3 leg 1): across two real runs of
// 14.2 s and 14.4 s the screen said NOTHING. Two independent causes, both pinned here:
// 1. the aria-live list was created together with its <li>s, i.e. inserted already containing
// its content — the M-U1 anti-pattern. A region has to be present BEFORE the text arrives.
// 2. even mounted, its text never changed: progress lived only in the `perf-step-{state}`
// class and in StepIcon, which is aria-hidden. Nothing to announce.
// These tests are the DOM half of the acceptance; the by-ear half cannot be automated.
// -------------------------------------------------------------------------------------------
describe('PerformanceScreen: the step list is announceable (#437)', () => {
it('cause 1: the live region is mounted while idle, before any run', async () => {
install(snapshot())
renderPerformanceScreen()
await screen.findByRole('button', { name: 'Check again' })
const idle = stepList()
expect(idle).not.toBeNull()
expect(idle).toHaveAttribute('aria-live', 'polite')
// Empty, so `.perf-steps:empty` collapses it and the idle card is visually unchanged.
expect(idle).toBeEmptyDOMElement()
})
it('cause 1: the steps arrive INSIDE the same region node, not with a fresh one', async () => {
const { progress } = install(snapshot())
renderPerformanceScreen()
await screen.findByRole('button', { name: 'Check again' })
const idle = stepList()
expect(idle).not.toBeNull()
const run = await startOwnRun()
const during = stepList()
// The same element instance as the idle one: identity is what makes it announceable.
expect(during).toBe(idle)
expect(during?.querySelectorAll('li')).toHaveLength(3)
act(() => progress.forEach((cb) => cb('system')))
await run.finish()
await screen.findByRole('button', { name: 'Check again' })
// Back to idle: the region survives the run and empties, ready for the next one.
expect(stepList()).toBe(during)
expect(stepList()).toBeEmptyDOMElement()
})
it('cause 2: an advance changes the region text, not only a CSS class', async () => {
const { progress } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
const before = stepList()?.textContent ?? ''
expect(before).toContain('Hardware detected: in progress')
expect(before).toContain('Drive speed: waiting')
act(() => progress.forEach((cb) => cb('system')))
const after = stepList()?.textContent ?? ''
expect(after).not.toBe(before)
expect(after).toContain('Hardware detected: done')
expect(after).toContain('Drive speed: in progress')
await run.finish()
})
it('cause 2: the active step exposes aria-current, and only one step does', async () => {
const { progress } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
const current = (): HTMLElement[] => Array.from(document.querySelectorAll('.perf-steps [aria-current="step"]'))
expect(current()).toHaveLength(1)
expect(current()[0]?.textContent).toContain('Hardware detected')
act(() => progress.forEach((cb) => cb('system')))
expect(current()).toHaveLength(1)
expect(current()[0]?.textContent).toContain('Drive speed')
await run.finish()
})
it('the step line reads once: the visible label is hidden from AT, the sr-only twin carries it', async () => {
install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
const li = screen.getByText('Hardware detected').closest('li')
// Visible copy is unchanged and unduplicated on screen; only its accessible twin adds state.
expect(screen.getByText('Hardware detected')).toHaveAttribute('aria-hidden', 'true')
expect(li?.querySelector('.sr-only')?.textContent).toBe('Hardware detected: in progress')
await run.finish()
})
it('#436 applies here too: no live-region role nests inside the step region', async () => {
install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
expect(stepList()?.querySelectorAll('[role], [aria-live]')).toHaveLength(0)
await run.finish()
})
it('#436 holds for the #438 background line as well', async () => {
install(snapshot({ running: true }))
renderPerformanceScreen()
await screen.findByText('Checking this computer in the background.')
expect(stepList()?.querySelectorAll('[role], [aria-live]')).toHaveLength(0)
})
})
// #746: the finished steps stayed in state after the run, and the list rendered on that alone. So
// every check with no model up (main sends system, drive, done, L3) left "Generation speed …: in
// progress" with aria-current on the idle card, and a failed run left whatever step it stopped at.
describe('PerformanceScreen: the step list ends with the run (#746)', () => {
const finishRun = async (progress: Array<(step: BenchmarkProgressStep) => void>, steps: BenchmarkProgressStep[]): Promise<void> => {
const run = await startOwnRun()
act(() => {
for (const step of steps) progress.forEach((cb) => cb(step))
})
await act(async () => {
progress.forEach((cb) => cb('done'))
})
await run.finish()
await screen.findByRole('button', { name: 'Check again' })
}
it.each<[string, BenchmarkProgressStep[]]>([
['every step reported', ['system', 'drive', 'speed']],
['no speed leg ran', ['system', 'drive']],
['the drive probe failed as well', ['system']]
])('the idle card shows no step after a run that ended: %s', async (_why, steps) => {
const { progress } = install(snapshot())
renderPerformanceScreen()
await finishRun(progress, steps)
expect(stepList()).toBeEmptyDOMElement()
})
it('a run that failed after a step leaves no step "in progress" beside its banner', async () => {
const { progress } = install(snapshot())
renderPerformanceScreen()
const run = deferred<BenchmarkResult>()
vi.mocked(window.api.runBenchmark).mockImplementationOnce(() => run.promise)
await userEvent.click(await screen.findByRole('button', { name: 'Check again' }))
act(() => progress.forEach((cb) => cb('system')))
expect(screen.getByText('Drive speed: in progress')).toBeInTheDocument()
await act(async () => {
run.reject(new Error('Error: Model is busy right now'))
})
expect(await screen.findByText(/Check failed: .*busy/)).toBeInTheDocument()
expect(stepList()).toBeEmptyDOMElement()
})
it('the list goes with the idle read, not before: the tail of our own run still shows it (#438)', async () => {
const { api, progress, pushes } = install(snapshot())
renderPerformanceScreen()
const run = await startOwnRun()
act(() => progress.forEach((cb) => cb('system')))
api.getPerformance.mockResolvedValue(snapshot({ running: true }))
await pushChanged(pushes)
await run.finish()
expect(screen.getByText('Hardware detected: done')).toBeInTheDocument()
api.getPerformance.mockResolvedValue(snapshot({ running: false }))
await pushChanged(pushes)
await screen.findByRole('button', { name: 'Check again' })
expect(stepList()).toBeEmptyDOMElement()
})
})