docs: note that mock-endoify voids guard-refusal assertions - #1059
Draft
ci-belphegor wants to merge 1 commit into
Draft
docs: note that mock-endoify voids guard-refusal assertions#1059ci-belphegor wants to merge 1 commit into
ci-belphegor wants to merge 1 commit into
Conversation
`mock-endoify` stubs `assert` with no-ops, so `@endo/exo` rejects a guard violation with `undefined`, and vitest treats an `undefined` rejection as matching any `rejects.toThrow` matcher. Such an assertion therefore passes with the guard removed. Enforcement is unaffected — the guarded method still never runs — so this costs test validity, not safety. A lint rule cannot catch it: telling a guard rejection from one carrying a real `Error` is semantic, and banning `rejects.toThrow` outright would reject the 182 legitimate uses in shimmed packages. An audit of all 14 found no assertion currently relying on the vacuous path. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Explanation
mock-endoifystubsglobalThis.assertand its methods with no-opvi.fn()s.@endo/exorejects a guard violation throughassert.Fail, so under the shim such a rejection carriesundefined— and vitest treats anundefinedrejection as satisfying anyrejects.toThrowmatcher:undefined.rejects.toThrow(/zzz/u).rejects.toThrow(/zzz/u)new Error('real').rejects.toThrow(/zzz/u)'plain string'.rejects.toThrow(/zzz/u)So such an assertion also passes with the guard removed. This adds a testing convention to
AGENTS.mdand a warning at the shim itself.This costs test validity, not safety. Enforcement is unaffected — the guard still blocks the call and the guarded method never runs. Nothing here papers over a live bug.
Notes for reviewers
An audit of all 14
mock-endoifypackages found no assertion currently relying on the vacuous path. Method: patchassert.Failto throw a recognizable error, then run every suite — a vacuous assertion cannot survive that. 13 packages stayed green;sheavesproduced 4 failures, and those turned out to be a different mock artifact (hardenis a no-op, so errors are not frozen, so endo's passability check fires and the no-op swallows it — two lies cancelling). Those 4 assert real messages and are fine. Barerejects.toThrow()calls, which that method cannot detect, were grepped separately: the only hit is inside a JSDoc comment describing a helper already written to avoid this.A lint rule is not feasible, which is why this is a convention. Telling a guard rejection from one carrying a real
Erroris semantic; the only mechanical rule — banningrejects.toThrowin shimmed packages — would reject the 182 legitimate uses there.Making the stub honest is not the fix either, and the comment records why so nobody repeats the experiment:
@endo/patternscallsassert.failduring module initialization, so a throwing stub stops test files from loading entirely.Independent of the narrowing stack; based on
main. No changelog —@ocap/repo-toolsis private and neither change is consumer-facing.