Skip to content

Fix waitForConnections vacuous-truth + add loop() test coverage - #36

Merged
rapguit merged 2 commits into
codespar:mainfrom
AndreLFSMartins:fix/core-waitforconnections-and-loop-tests
Jun 26, 2026
Merged

rapguit merged 2 commits into
codespar:mainfrom
AndreLFSMartins:fix/core-waitforconnections-and-loop-tests

Conversation

@AndreLFSMartins

Copy link
Copy Markdown
Contributor

fix(sdk): waitForConnections treats empty/failed connections as connected

In packages/core, createSession's manageConnections.waitForConnections gate breaks as soon as connections().every(c => c.connected) is true. But connections() returns [] on a failed or empty backend response, and [].every(...) is vacuously true — so the gate resolves on the first poll with zero servers connected, the opposite of what waitForConnections promises. Guarded with conns.length > 0.

The Python SDK already guards this (_async_session.py: if conns and all(...)), so this also restores TS/Python parity.

test(sdk): loop() had no tests

loop() (the "Complete Loop" orchestration) had zero coverage. Adds tests for: happy path, dynamic params(prevResults), when() skips, abortOnError true/false, thrown-error retry, linear vs exponential backoff, and the zero-step / all-skipped edge cases.


No wire-contract change. npm test + tsc --noEmit green for packages/core.

AndreLFSMartins and others added 2 commits May 18, 2026 15:52
…nnections

connections() returns [] on a failed or empty backend response.
[].every() is vacuously true, so the waitForConnections gate broke on
the first poll and createSession resolved while zero servers were
connected — the opposite of the manageConnections.waitForConnections
contract. Guard with conns.length > 0.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
loop() had no tests. Covers happy path, dynamic params(prevResults),
when() skips, abortOnError true/false, thrown-error retry, linear and
exponential backoff, and the zero-step / all-skipped edge cases.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@rapguit

rapguit commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Thanks again, Andre — quality PR, easy to review.

Verified locally:

  • Bug is real: [].every(...) is vacuously true, and connections() returning [] on a failed/empty response would resolve the gate with zero servers connected. One-line guard (conns.length > 0 &&) is the right fix.
  • Python parity: confirmed against packages/python/src/codespar/_async_session.py:1193if conns and all(c.connected for c in conns). Same shape, now mirrored in TS.
  • Tests: full @codespar/sdk suite passes (95/95) with the change merged onto current main. tsc --noEmit clean.
  • loop() coverage: the previously-untested orchestration entrypoint now has 13 tests covering happy path, dynamic params, when() gating, abortOnError, retry policies (linear + exponential), and the vacuous-truth edge cases at the boundaries. Characterization-style tests for those edge cases (success:true on zero/all-skipped steps) are a sensible call — locks current behavior without quietly changing it.

One tiny note for future PRs: a couple of test comments reference docs/fix-core.md (R4 / C2) which doesn't ship in the repo. Harmless — the comments stand on their own — just a heads-up so future readers don't go chasing a missing doc.

Merging.

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.

2 participants