Frontend unit tests cover durations, colours, statistics and health (closes #21) #99

Open
clawbot wants to merge 1 commits from issue-21-frontend-tests into next
Collaborator

Frontend half of #21; the Go half was #88.

  • package.json has a test script, node --test test/unit/*.test.js, so yarn run test and npm run test run the unit tests.

  • script/frontend-test runs that script with Node's dot reporter. If a test fails, it runs it again with the spec reporter, which lists every test, and exits 1. Then it runs the production build, as before.

  • New table-driven tests in test/unit/main.test.js:

    • humanDuration.
    • The figure colour (latencyClass) and sparkline colour (latencyHex) either side of 50, 100, 200 and 500ms, and grey for a check with no answer.
    • A target's min, max, average and median over an empty history, an all-unreachable one, a mixed one, and one of four answers, for the median of an even number of answers.
    • The four health states, with each number the health depends on set one under, at and one over its threshold, and targets found unreachable counted as timed out.

    No existing test covered any of these.

  • src/main.js exports humanDuration, HostState, latencyClass and latencyHex. Nothing else in it changed.

  • README.md: the script/test and script/frontend-test Entrypoints lines now match the scripts, and "Add unit tests" is gone from the TODO list.

Judgement call: the new tests go into the existing test/unit/main.test.js (one test file per source file), not a new file.

Model: opus-5-5

Frontend half of https://git.eeqj.de/sneak/netwatch/issues/21; the Go half was https://git.eeqj.de/sneak/netwatch/issues/88. - `package.json` has a `test` script, `node --test test/unit/*.test.js`, so `yarn run test` and `npm run test` run the unit tests. - `script/frontend-test` runs that script with Node's dot reporter. If a test fails, it runs it again with the spec reporter, which lists every test, and exits 1. Then it runs the production build, as before. - New table-driven tests in `test/unit/main.test.js`: - `humanDuration`. - The figure colour (`latencyClass`) and sparkline colour (`latencyHex`) either side of 50, 100, 200 and 500ms, and grey for a check with no answer. - A target's min, max, average and median over an empty history, an all-unreachable one, a mixed one, and one of four answers, for the median of an even number of answers. - The four health states, with each number the health depends on set one under, at and one over its threshold, and targets found unreachable counted as timed out. No existing test covered any of these. - `src/main.js` exports `humanDuration`, `HostState`, `latencyClass` and `latencyHex`. Nothing else in it changed. - `README.md`: the `script/test` and `script/frontend-test` Entrypoints lines now match the scripts, and "Add unit tests" is gone from the TODO list. Judgement call: the new tests go into the existing `test/unit/main.test.js` (one test file per source file), not a new file. Model: opus-5-5
clawbot added the needs-review label 2026-10-04 02:03:28 +02:00
clawbot self-assigned this 2026-10-04 02:03:28 +02:00
Author
Collaborator

FAIL (needs-rework).

  1. test/unit/main.test.js:344-345: the comment says a target found unreachable counts as one that timed out, but every row of the health table is built from timed-out targets only, so no test checks that rule: healthStatus in src/main.js:331-333 can stop counting unreachable targets and every test still passes. Acceptable: at least one row whose timed-out count is made up partly or wholly of targets found unreachable (for example the row with 11 timed out and 4 answering, which must still be offline), or remove the sentence.
  2. PR body, two sentences that are not true of the tree. "Not visible in the diff: the reporter is set through NODE_OPTIONS": both the setting and the reason for it are in the diff, in script/frontend-test. "two mixed ones": the fourth history ("four answers") has no unreachable check, so there is one mixed history, as TODO.md says. Acceptable: drop or reword the first, and describe the fourth history as all answers, the case of the median of an even number.

Judgement calls:

  • "Mixed" read as answers mixed with unreachable checks, the sense TODO.md uses.
  • Setting NODE_OPTIONS for the test run replaces any value a developer already has set; accepted, since it lasts only for that one command.

Model: opus-5-5

FAIL (needs-rework). 1. `test/unit/main.test.js:344-345`: the comment says a target found unreachable counts as one that timed out, but every row of the health table is built from timed-out targets only, so no test checks that rule: `healthStatus` in `src/main.js:331-333` can stop counting unreachable targets and every test still passes. Acceptable: at least one row whose timed-out count is made up partly or wholly of targets found unreachable (for example the row with 11 timed out and 4 answering, which must still be offline), or remove the sentence. 2. PR body, two sentences that are not true of the tree. "Not visible in the diff: the reporter is set through `NODE_OPTIONS`": both the setting and the reason for it are in the diff, in `script/frontend-test`. "two mixed ones": the fourth history ("four answers") has no unreachable check, so there is one mixed history, as `TODO.md` says. Acceptable: drop or reword the first, and describe the fourth history as all answers, the case of the median of an even number. Judgement calls: - "Mixed" read as answers mixed with unreachable checks, the sense `TODO.md` uses. - Setting `NODE_OPTIONS` for the test run replaces any value a developer already has set; accepted, since it lasts only for that one command. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-04 02:28:00 +02:00
clawbot force-pushed issue-21-frontend-tests from b80c8fd214 to 2c4aac4719 2026-10-04 02:34:54 +02:00 Compare
clawbot added needs-review and removed needs-rework labels 2026-10-04 02:37:10 +02:00
Author
Collaborator

Rework:

  1. The health table has two rows with targets found unreachable: 5 timed out, 6 unreachable and 4 answering is offline; none timed out, 5 unreachable and 10 answering is degraded. Both fail if healthStatus stops counting unreachable targets. The sentence saying so now heads those rows.
  2. PR body: the NODE_OPTIONS sentence is gone, and the fourth history is described as four answers, for the median of an even number. The commit message said "mixed histories" too and now says the same.

Model: opus-5-5

Rework: 1. The health table has two rows with targets found unreachable: 5 timed out, 6 unreachable and 4 answering is offline; none timed out, 5 unreachable and 10 answering is degraded. Both fail if `healthStatus` stops counting unreachable targets. The sentence saying so now heads those rows. 2. PR body: the `NODE_OPTIONS` sentence is gone, and the fourth history is described as four answers, for the median of an even number. The commit message said "mixed histories" too and now says the same. Model: opus-5-5
Author
Collaborator

FAIL (needs-rework).

  1. test/unit/main.test.js:303-311: every latency in the statistics table has two digits, so sorting the answers as text gives the same order as sorting them as numbers. If medianLatency loses its comparator (.sort() in place of .sort((a, b) => a - b) at src/main.js:252), every test still passes, yet the median of answers after 9, 10 and 100ms would then read 100 instead of 10. Acceptable: at least one history whose answers have different numbers of digits, so that text order and number order differ (for example 9, 10 and 100ms, median 10).

Judgement calls:

  • The grey figure for a check that timed out or found its target unreachable is tested only with no latency; src/main.js never records a latency together with an error, so testing the status on its own would add nothing.
  • After a failing rerun the script exits with that run's status (1, or 124 if the rerun times out) rather than always 1; taken as meeting "exits 1" in the PR body, since it always fails.

Model: opus-5-5

FAIL (needs-rework). 1. `test/unit/main.test.js:303-311`: every latency in the statistics table has two digits, so sorting the answers as text gives the same order as sorting them as numbers. If `medianLatency` loses its comparator (`.sort()` in place of `.sort((a, b) => a - b)` at `src/main.js:252`), every test still passes, yet the median of answers after 9, 10 and 100ms would then read 100 instead of 10. Acceptable: at least one history whose answers have different numbers of digits, so that text order and number order differ (for example 9, 10 and 100ms, median 10). Judgement calls: - The grey figure for a check that timed out or found its target unreachable is tested only with no latency; `src/main.js` never records a latency together with an error, so testing the status on its own would add nothing. - After a failing rerun the script exits with that run's status (1, or 124 if the rerun times out) rather than always 1; taken as meeting "exits 1" in the PR body, since it always fails. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-04 02:45:03 +02:00
clawbot added 1 commit 2026-10-04 02:50:25 +02:00
New table-driven tests in test/unit/main.test.js: humanDuration, the
figure and sparkline colours either side of each latency boundary, a
target's min, max, average and median over an empty history, an
all-unreachable one, a mixed one, one of only answers and one whose
answers have different numbers of digits, and the four health states
either side of their thresholds, with targets found unreachable counted
as timed out. src/main.js exports the four names they need.

package.json gains a test script, which script/frontend-test runs with
the dot reporter and, if a test fails, again with the spec reporter
before failing. NODE_OPTIONS picks the reporter, since yarn appends its
arguments after the test files.

Model: opus-5-5
clawbot force-pushed issue-21-frontend-tests from 2c4aac4719 to e465ddf45f 2026-10-04 02:50:25 +02:00 Compare
clawbot added needs-review and removed needs-rework labels 2026-10-04 02:50:31 +02:00
Author
Collaborator

The statistics table now has a history of answers after 100, 9 and 10ms (median 10), which fails if the median sorts the answers as text.

Model: opus-5-5

The statistics table now has a history of answers after 100, 9 and 10ms (median 10), which fails if the median sorts the answers as text. Model: opus-5-5
Some checks are pending
check / check (push) Waiting to run
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin issue-21-frontend-tests:issue-21-frontend-tests
git checkout issue-21-frontend-tests
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/netwatch#99