Skip to content

Unify async test assertions on a shared helper#641

Open
polRk wants to merge 1 commit into
mainfrom
claude/amazing-golick-3d5608
Open

Unify async test assertions on a shared helper#641
polRk wants to merge 1 commit into
mainfrom
claude/amazing-golick-3d5608

Conversation

@polRk

@polRk polRk commented Jul 15, 2026

Copy link
Copy Markdown
Member

What

Standardize the test suite on a single async-assertion style — vitest expect matchers plus one shared promise-settlement helper — replacing scattered hand-rolled .then() idioms. Test-only; no product behavior changes.

Why

The suite mixed several ad-hoc async-assertion idioms: bare .then() flag probes for "still pending", Promise.race([p, setTimeout(...)]) timeouts for liveness, and a per-file re-invented trackCommit. This was inconsistent and tripped two oxlint warnings (promise(always-return), no-unmodified-loop-condition). AGENTS.md already declares vitest expect the standard, but it wasn't enforced for the async cases.

Changes

  • Add a shared, dependency-free track(promise) → { settled, rejected, reason? } helper next to each package's settle() in *.fixtures.ts (core, coordination, topic writer + reader), plus a new packages/fsm/src/promise.fixtures.ts.
  • Replace hand-rolled pending-probe flags (let f = false; p.then(() => (f = true))) with track() across endpoints, writer, session-runtime, session-registry, and fsm queue.
  • Replace Promise.race([p.then(...), setTimeout(...)]) liveness checks with await expect(p).resolves.*, bounded by the test timeout (coordination client, topic reader).
  • Swap reader-rebalance's local trackCommit for the shared track().
  • Document the one canonical vitest-expect assertion style (rejects / resolves / pending-probe) in AGENTS.md Testing Rules.
  • Net effect: clears both oxlint warnings (48 → 46 total); no behavior change.

Not a breaking change. Intentionally left as-is (documented in review, not the target anti-pattern): session-pool dual-outcome captures, the election/mutex integration probes with their justified heuristic sleeps, and the fsm sleep().then('label') race harness.

Testing

  • npm run build — passes (fixtures are compiled, so track/Settlement are type-checked).
  • npm run test:uni — 1023 passed, 1 skipped.
  • reader-rebalance integration test — run live against local YDB, passes.
  • npm run lint — exit 0, 46 warnings (down from 48; promise(always-return) and no-unmodified-loop-condition cleared, none added).
  • Edited test files type-checked clean.

Checklist

  • Changeset added — N/A: test-only change, no published/consumable API surface affected.
  • README updated — N/A: no public API change.

Separate from the core-package refactor (#638).

- Add a shared track() promise-settlement helper next to each
  settle() in *.fixtures.ts (core, coordination, topic) and a new
  fsm promise.fixtures.ts
- Replace hand-rolled `.then()` probes with track(), and liveness
  Promise.race timeouts with `await expect().resolves`
- Swap reader-rebalance's local trackCommit for the shared helper
- Document the one canonical vitest-expect assertion style in AGENTS.md
- Clears the promise(always-return) and no-unmodified-loop-condition
  lint warnings (48 -> 46)
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.

1 participant