test: assert the specific error code instead of any failure (#1781 B4) - #1790
Open
thymikee wants to merge 1 commit into
Open
test: assert the specific error code instead of any failure (#1781 B4)#1790thymikee wants to merge 1 commit into
thymikee wants to merge 1 commit into
Conversation
Converts the 20 test assertions across the repo that accepted ANY
failure (bare `expect(...).toThrow()`, bare `assert.throws(fn)`, bare
`assert.rejects(p)`) into assertions on the specific AppError `code`
each test is actually about, or — where the propagated error is
genuinely opaque (a mocked upstream failure whose identity, not its
shape, is the point) — identity assertions with a comment explaining
why.
Added a synchronous `assertThrowsAppError(fn, {code, message?})`
sibling to the existing `assertRejectsAppError` helper in
src/__tests__/test-utils/app-error.ts, exported via the test-utils
index, for the two src/ sites that needed it.
packages/provider-limrun and packages/provider-webdriver have no
test-utils dir and cannot import from src/, so those sites use
vitest's `expect(...).toThrow(expect.objectContaining({ code }))` or
an inline `assert.rejects(p, matcherFn)` instead.
Sites converted:
- packages/provider-limrun/src/app-log-runtime.test.ts:153-155
(bare `.toThrow()` x3 -> `UNSUPPORTED_OPERATION`)
- src/daemon/__tests__/app-log.test.ts:39 (bare `.toThrow()` ->
message match; plain Error, not AppError, from verified-file's
identity check)
- src/daemon/__tests__/resumable-upload-range.test.ts:13 (bare
`assert.throws(fn)` -> `INVALID_ARGS`); also fixed line 19's
`assert.throws(fn, value)`, a documented Node.js gotcha where a
string second argument is the failure message, not a matcher, so
it was equally bare in effect
- packages/provider-webdriver/src/webdriver-client.test.ts:229 (bare
`assert.rejects(p)` -> asserts the raw AbortSignal.timeout()
rejection's `name`, since the transport re-throws it unwrapped)
- src/daemon/handlers/__tests__/session-device-claims.test.ts:129,
151, 174 (bare `assert.rejects(p)` x3 -> identity assertions; each
test's point is device-claim rollback/retention around an opaque
mocked upstream failure)
- src/platforms/android/__tests__/settings.test.ts:109 (bare
`assert.rejects(p)` -> `UNSUPPORTED_OPERATION`)
- src/platforms/android/__tests__/snapshot.test.ts:1071, 1342 (bare
`assert.rejects(p)` x2 -> `COMMAND_FAILED` + message)
- src/platforms/android/__tests__/touch-helper-session.test.ts:526
(bare `assert.rejects(p)` -> `COMMAND_FAILED`, wrong-protocol
message)
- src/platforms/apple/core/__tests__/runner-command-retry.test.ts:472,
527, 550, 762, 881, 1016 (bare `assert.rejects(p)` x6 ->
`COMMAND_FAILED` with the recovery-path-specific details/message)
- src/platforms/apple/core/__tests__/runner-transport.test.ts:61
(bare `assert.rejects(p)` -> identity assertion; fetchWithTimeout
does not wrap fetch() failures into an AppError)
No repo-wide scanner/lint rule added (explicitly out of scope per
#1781); no test loosened.
Size Report
Startup median (7 runs, lower is better):
Top changed chunks:
|
thymikee
marked this pull request as ready for review
August 17, 2026 17:39
Member
Author
|
Request changes before merge:
The changed assertions themselves appear honest on review. CI is green for the relevant test gates; the only failure is CodeQL Java/Kotlin failing while GitHub returned 503 during SARIF upload, which is infrastructure-unrelated to this TypeScript-only test change. |
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Umbrella #1781, item B4 "assert the right reason". The repo's typed-error rule: failures are
AppErrorwith acodefrom the closedKNOWN_APP_ERROR_CODESset (packages/kernel/src/errors.ts). This PR converts the 20 test assertions across the repo that instead accepted ANY failure — bareexpect(...).toThrow(), bareassert.throws(fn), bareassert.rejects(p)— into assertions on the specific code (or, where the propagated error is genuinely opaque, an identity assertion with a comment explaining why).Re-derived the site list with real paren matching (multi-line matchers excluded,
.not.toThrow()excluded) rather than trusting the hand-picked examples in the issue; the exact count came out to 20, not 21 (one of the originally-cited examples turned out to already assert a specific matcher).Added a synchronous
assertThrowsAppError(fn, {code, message?})sibling to the existingassertRejectsAppErrorhelper insrc/__tests__/test-utils/app-error.ts, exported via the test-utils index.packages/provider-limrunandpackages/provider-webdriverhave no test-utils dir and cannot import fromsrc/, so those sites use vitest'sexpect(...).toThrow(expect.objectContaining({ code }))or an inlineassert.rejects(p, matcherFn)instead — no cross-package imports, no new re-export surface.Sites converted
packages/provider-limrun/src/app-log-runtime.test.ts:153-155— bare.toThrow()x3 →UNSUPPORTED_OPERATIONsrc/daemon/__tests__/app-log.test.ts:39— bare.toThrow()→ message match (plainError, notAppError, from verified-file's identity check; message differs by operation)src/daemon/__tests__/resumable-upload-range.test.ts:13— bareassert.throws(fn)→INVALID_ARGS. Also fixed line 19'sassert.throws(fn, value): a documented Node.js gotcha where a string second argument is the assertion failure message, not a matcher, so it was equally bare in effect.packages/provider-webdriver/src/webdriver-client.test.ts:229— bareassert.rejects(p)→ asserts the rawAbortSignal.timeout()rejection'sname, since the transport re-throws it unwrapped (not anAppError)src/daemon/handlers/__tests__/session-device-claims.test.ts:129,151,174— bareassert.rejects(p)x3 → identity assertions; each test's point is device-claim rollback/retention behavior around an opaque mocked upstream failure, not any particular error shapesrc/platforms/android/__tests__/settings.test.ts:109— bareassert.rejects(p)→UNSUPPORTED_OPERATIONsrc/platforms/android/__tests__/snapshot.test.ts:1071,1342— bareassert.rejects(p)x2 →COMMAND_FAILED+ messagesrc/platforms/android/__tests__/touch-helper-session.test.ts:526— bareassert.rejects(p)→COMMAND_FAILED, wrong-protocol messagesrc/platforms/apple/core/__tests__/runner-command-retry.test.ts:472,527,550,762,881,1016— bareassert.rejects(p)x6 →COMMAND_FAILEDwith the recovery-path-specific details/messagesrc/platforms/apple/core/__tests__/runner-transport.test.ts:61— bareassert.rejects(p)→ identity assertion;fetchWithTimeoutdoes not wrapfetch()failures into anAppErrorNo repo-wide scanner/lint rule added (explicitly out of scope per #1781); no test loosened.
Follow-up surfaced
src/utils/app-log-files.ts:43andsrc/utils/verified-file.ts:35,110throw plainErrorinstead ofAppError, which is whyapp-log.test.ts:39had to become a message match instead of a code assertion. This is a typed-error-rule gap in product code, out of scope for this PR. Filing as its own issue, referencing #1781 B4.Test plan
npx vitest runon all 10 touched test files — 153 tests passedpnpm run typecheck— cleannpx oxlint --deny-warningson touched files — clean