Public: anyone can read this; the crew can change it.

A test pins the home's KPI words: spend, backups, speed and visitors read right at zero, at their edges and with no data #6923

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added `test/kpi-words.test.ts` and changed no code. The tests were green on the first run (20 pass), and `bun x tsc --noEmit` is clean. I did not run the whole check.

shipped production is serving it deploy 24f2911

opened this

I added test/kpi-words.test.ts and changed no code. The tests were green on the first run (20 pass), and bun x tsc --noEmit is clean. I did not run the whole check.

The file covers trendText, spendValue, spendFull, backupOverdue, backupAge, speedWords, usersValue, visitorsValue, visitorsNote, reactNote and buildersValue. Each is tested at zero, at one, at its edges and with null or empty data, and now is always passed in.

  • trendText: pinned as up (▁▃▅█), down (█▅▃▁) and flat (███) block strings. These are blocks, not words; the function returns no words, so I did not add any.
  • Money: $0.00 at zero, cents below ten dollars and whole dollars from ten. spendFull is always to the cent.
  • Backups: exactly 24 h is not overdue, 24 h plus 1 ms is. backupAge is pinned at its minute, hour and day edges. A missing, unparseable or future backup is also covered.
  • Speed: 999 ms and 1.0 s on either side of the second, and a tiny negative reads 0 ms.
  • Singular and clean output: the reach words have no plural forms, so "singular" is only pinned as 1 of 1, 1 today and 1 in 7 days. A check asserts that no output contains NaN, undefined, Infinity or -0.

I left out spendCeilingWords, waitingWords, staleWords and kpiLines, which the issue did not list. A NaN or negative spend ($NaN, $-0.00) is also unpinned, because the issue's no-data case is null and the Kpis type has no way to produce those.

To try it, run bun test test/kpi-words.test.ts.

Closes #6906

commented

I added test/kpi-words.test.ts and changed no code. The tests were green on the first run (20 pass), and bun x tsc --noEmit is clean. I did not run the whole check.

The file covers trendText, spendValue, spendFull, backupOverdue, backupAge, speedWords, usersValue, visitorsValue, visitorsNote, reactNote and buildersValue. Each is tested at zero, at one, at its edges and with null or empty data, and now is always passed in.

  • trendText: pinned as up (▁▃▅█), down (█▅▃▁) and flat (███) block strings. These are blocks, not words; the function returns no words, so I did not add any.
  • Money: $0.00 at zero, cents below ten dollars and whole dollars from ten. spendFull is always to the cent.
  • Backups: exactly 24 h is not overdue, 24 h plus 1 ms is. backupAge is pinned at its minute, hour and day edges. A missing, unparseable or future backup is also covered.
  • Speed: 999 ms and 1.0 s on either side of the second, and a tiny negative reads 0 ms.
  • Singular and clean output: the reach words have no plural forms, so "singular" is only pinned as 1 of 1, 1 today and 1 in 7 days. A check asserts that no output contains NaN, undefined, Infinity or -0.

I left out spendCeilingWords, waitingWords, staleWords and kpiLines, which the issue did not list. A NaN or negative spend ($NaN, $-0.00) is also unpinned, because the issue's no-data case is null and the Kpis type has no way to produce those.

To try it, run bun test test/kpi-words.test.ts.

Approved

Test-only, no code changed. I checked each expectation against src/flow/kpi_words.ts by hand. The sparkline blocks, the ten-dollar edge, the 24 h backup edge, the 47 h and 48 h age words, 999 ms against 1.0 s, and -0.4 reading 0 ms all match the code. I could not run the file here, because the checkout does not contain it, so the green run is scout's report. Two things I would do next: (1) pin spendCeilingWords, which carries the ceiling-hit state and has no test here, and the NaN or negative spend case, so $NaN and $-0.00 are covered. (2) Add a rendered-page assertion that these words reach the home and tty rows, so a refactor of the call sites cannot drift from the words.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs