Skip to content

fix(tests): wait on install.sh's own events in install-star's tests, not on set times - #1895

Merged
devswha merged 1 commit into
mainfrom
fix/install-star-epipe
Oct 24, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/install-star-epipe

Conversation

@devswha

@devswha devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner

What it does

scripts/install-star.test.ts failed on a loaded PC in three ways (seen in bun run check fast at a load average of about 97 on 32 cores). This makes each test wait on what install.sh itself did, bounded, instead of on set times:

  • EPIPE between tests. atTerminal's type() wrote to script(1)'s stdin with no guard. As script exits it closes its end of the pipe, and until Bun reaps it a write there throws EPIPE synchronously (reproduced: a child that closed its stdin but is not reaped yet makes FileSink.write/flush throw {code: "EPIPE", errno: -32, syscall: "write"}). Typed from the Ctrl-C test's interval, that was an unhandled error outside any test. type() now drops the keys on EPIPE only; any other error still throws.
  • Timeouts. Each helper now waits for the installer's own end (its output closed and its exit), bounded by RUN_ENDS_WITHIN_MS (45 s); a run still going then is ended and the test fails with what it printed. setDefaultTimeout() stays above that only as a backstop. The per-test 30 s/60 s timeouts are gone.
  • Elapsed-time checks and fs.watch. < 8 s, < 15 s and < 20 s checks failed under load, and fs.watch failed with EMFILE once the PC was out of inotify instances. They are replaced by evidence of what the installer did:
    • a bash stand-in passes through to the real bash and records how the question's read -r -t 20 ended, so a test tells an answer read (0) or the end of input (1) apart from its 20 seconds running out (over 128). Without this, a lost answer and a timed-out question both end with no star, so a longer timeout alone would let a broken installer pass;
    • the stand-in gh leaves its pid: a gh that never answers, or ignores TERM, is gone once the installer ended (it sleeps 60 s otherwise); a lingering child of gh is still running when the installer has already ended;
    • the browser opener's record is polled within the deadline instead of watched.
  • The Ctrl-C test now also asserts the read was ended by Ctrl-C, not by its 20 seconds running out.
  • The one test whose behaviour is time itself ("goes on by itself when nobody is at the terminal", the question's 20 s) keeps its time bounds, and now also asserts the read ran out.

No production code changes.

Why it can no longer flake under load

No assertion depends on how fast the PC is any more, except the 20 s question test, where time is the behaviour under test and its bounds are wide. Every wait is for an event of the installer's (its output, its exit, the question on the terminal, a file the stand-ins write), bounded so a hung run fails with its output instead of hanging, and a write into an installer that already ended is not an error.

How it was verified

  • Under load, 8 runs at a time: the previous revision (EPIPE guard plus longer timeouts) failed 2 to 4 tests in every one of 16 runs at a load average of 68 to 131 (the gh wall-clock checks and EMFILE). This approach: 24 of 24 runs passed 39/39 at a load average of 86 to 154, and the final revision (with the Ctrl-C assertion) 16 of 16 runs passed 40/40 at a load average of 50 to 119.
  • With install.sh changed so the question's read never gets the typed answer, all 7 answered tests fail (read status 142, or no star / no "gh could not star it"), while the Ctrl-C, CI, no-question and nobody-at-the-terminal tests pass, as they should.
  • bun run typecheck and scripts/conventions.test.ts pass.
  • Review: omo-native-code-reviewer. On the first revision (EPIPE guard plus 30 s timeouts) it found that a longer timeout lets a lost answer pass; on the second, the same gap in the Ctrl-C test. Both are fixed: every answered test asserts how the question's read ended, and the Ctrl-C test fails (read status 142) with an install.sh that ignores Ctrl-C. Its LOW notes (a gh deadline of 30 s instead of 10 would still pass, which follows dropping wall-clock checks; the stand-in matching the read's text, now guarded by a test that install.sh still asks with it) are addressed or accepted.
  • bun run check fast (through dori heavy) on this commit: typecheck, build and unit tests ok (6397 pass, 0 fail, 13 skip).

Fixes #1866

…not on set times

On a loaded PC scripts/install-star.test.ts failed in three ways:

- atTerminal's type() wrote to script(1)'s stdin with no guard. As script
  exits it closes its end of the pipe, and until Bun reaps it a write there
  throws EPIPE synchronously; typed from the Ctrl-C test's interval, that was
  an unhandled error between tests. type() now drops the keys on EPIPE only.
- Whole runs of install.sh outlasted bun's 5 s default timeout. Each helper
  now waits for the installer's own end (output closed and exit), bounded by
  RUN_ENDS_WITHIN_MS (45 s), and a run still going then is ended and fails
  with what it printed. setDefaultTimeout() is only a backstop above it.
- Elapsed-time checks (< 8, 15 and 20 s) and fs.watch (EMFILE once the PC is
  out of inotify instances) failed under load. They are replaced by what the
  installer did:
  - a bash stand-in passes through to the real bash and records how the
    question's read ended, so a test tells an answer read (0) or the end of
    input (1) apart from its 20 seconds running out; a raised timeout alone
    let a lost answer pass, since both end with no star;
  - the stand-in gh leaves its pid, so the tests see a gh that never answers
    or ignores TERM was ended by the installer, and a lingering child of gh
    still running when the installer had already ended;
  - the browser opener's record is polled within a deadline, not watched.

Fixes #1866
@coderabbitai

coderabbitai Bot commented Oct 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4c8ce30 and ecd2209.

Files selected for processing: 1
  • scripts/install-star.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Fast checks failed on this run (40105758528) in two files this PR does not touch; both are known timing flakes, not the change:

bun run check fast passed on this commit locally (6397 pass, 0 fail). I'll re-run the failed job once the run completes.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Re-ran the failed Fast checks job (run 40105758528, attempt 2): it passed, and every other job passed in the first attempt. The PR is green.

@devswha

devswha commented Oct 24, 2026

Copy link
Copy Markdown
Owner Author

Merge pass review-work report. Overall: PASSED. This PR changes a test only, so under the maintainer's token rule it merges on the code review, the merge pass's own check and CI, without the gate reviewer.

Lane Verdict
Code review (omo-native-code-reviewer, programming + remove-ai-slops) PASS (WATCH)
Merge pass's own check scripts/install-star.test.ts 3 runs, 40/40 each; typecheck passes; git merge-tree clean

What was checked

  • Waits: every wait is bounded and fails loudly. Both helpers kill the installer after 45 s and throw with its output. A 60 s per-test timeout is the backstop. The browser-opener wait is a poll with a deadline.
  • Conventions: 10 pass, and the changed file has no fixed sleep.
  • EPIPE: only EPIPE is swallowed in type(); any other error is thrown again.
  • Assertions: the tests still check what install.sh does, and in places more strongly. The gh tests check that gh was ended, and the answer tests check how the read ended.

Follow-up (MEDIUM, accepted for a loaded PC): install.sh gives gh 10 s, but the tests now allow 45 s instead of the old 20 s. A regression that stretched that 10 s toward 30 s would go unnoticed.

All required checks are green and no review thread is open.

CodeRabbit did not review this PR (rate-limited or skipped). The reviews above stand in for it.

@devswha
devswha merged commit a30ba1c into main Oct 24, 2026
18 of 19 checks passed
@devswha
devswha deleted the fix/install-star-epipe branch October 24, 2026 20:20
devswha added a commit that referenced this pull request Oct 24, 2026
…1900)

## What it does

`server/collector.test.ts` waited on fixed sleeps (`await tick(20)`,
`tick(70)`, ... 61 of them by `scripts/fixed-sleeps.ts`'s count) for the
collector's debounce, snapshot retry, replay settle and reconnect timers
(5 ms in `fakeHerdr`). On a loaded PC a test could read the handler log
before those timers had run (1 failure in 200 runs seen in the
flaky-tests lane; it failed again on CI today, in #1895's Fast checks:
"tells what the snapshot that closes the subscription already shows"
read `[]` where it expected `w1:p1:unknown (was working)`). #1870 moved
the backoff test to fake timers and left the rest to this issue.

Now the whole `startStatusCollector recovery` describe runs on bun's
fake timers, so every timer fires at its own moment of the test's clock
however busy the PC is:

- `beforeEach`/`afterEach` turn fake timers on and off for the describe.
- `elapse(ms)` moves the clock a millisecond at a time and, after each
step, lets the promise chains that step started settle (`setImmediate`,
which bun does not fake). `elapse()` runs what is due now, as a 0 ms
timeout did. Each `tick()`/`tick(N)` became `elapse()`/`elapse(N)` with
the same amount, so every test reads the log at the same point of the
collector's timeline as before.
- The one recovery test that polled with `until()` (real sleeps and
`Date.now()`, which a frozen clock never moves) steps the clock and
asserts exact values.
- The first describe's only remaining wait is the marked `// fixed
wait:` that proves no refresh comes; `scripts/fixed-sleeps.json` drops
the collector entry (61 to 0).

No production code changes.

## Why it can no longer flake under load

What a test reads is decided by how far it moved the fake clock, not by
how long the PC took to run real timers: a debounce or replay settle
cannot be late, because it only runs when the test advances to it, and
the test waits for what it started to settle before it reads.

## How it was verified

- `bun test server/collector.test.ts`: 57 pass, 0 fail, in 3.5 s.
- 200 runs of the file, 8 at a time, at a load average of 150 to 162 on
32 cores (other lanes' checks running): 200 of 200 passed, 0 failures.
- The fake clock still catches timing regressions in
`server/collector.ts`: a reconnect delay 100 ms late fails 3 tests; a
replay settle 100 ms late fails 9.
- `scripts/conventions.test.ts` (fixed-sleep ratchet) passes.
- Review: `omo-native-code-reviewer` APPROVE. It ran the same collector
mutations against the old and the new test file and found each fails the
same tests with both (replay settle +100 ms: 9; reconnect +100 ms: 3;
snapshot retry +1000 ms: 1). Of its three LOW notes, the
reopened-subscription check now also asserts the subscription exists;
the marked fixed wait that proves no refresh comes and #1870's own (now
redundant) fake-timer calls are left as they are.
- `bun run check fast` (through `dori heavy`) on this commit: typecheck,
build and unit tests ok (6396 pass, 0 fail, 13 skip).

Fixes #1867

Co-authored-by: mp <mp@local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install-star.test.ts: EPIPE from typing into an exited installer under load

1 participant