testing: effectTest harness — return an Effect, get pass/fail - #10
Merged
Merged
Conversation
Tests across the suite repeat `test(name, () => Effect.runPromise(Effect.scoped(Effect.gen(...))))`, and a failing Effect rejects with a FiberFailure that buries the real error/assertion behind the promise boundary. `effectTest(name, body, options?)` lets a test body return an Effect: - always wraps the body in `Effect.scoped`, giving every test a per-test Scope whose finalizers run on both the success and failure paths; - `options.layer` threads the test's requirements (R) without a global — the caller composes captureLogger / TestContext (TestClock) / the stub HttpClient layer and passes them as one layer. The base stays on the live clock, so TestClock is opt-in; - runs via `Effect.runPromiseExit` and, on failure, throws `Cause.squash(cause)` so the raw error surfaces — squash (not prettyErrors) preserves the original thrown object, keeping bun's assertion-diff renderer intact. `runTestEffect` is the engine behind the registrar, exported so the pass/fail mapping is itself testable. comms-30hq
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.
What
Adds
effectTestto@commy/testing— a bun:test harness that lets a test body return a success/failure Effect instead of hand-wrappingEffect.runPromise(Effect.scoped(Effect.gen(...)))at every call site.Foundation for the hexagonal test architecture (comms-e5vm); first consumer is the Tier-2 proof (comms-e5vm.2).
Why
Nearly every test in the suite repeats the
Effect.runPromise(Effect.scoped(...))wrapper, and a failing Effect rejects with aFiberFailurethat buries the real error/assertion behind the promise boundary — so a failedexpect()shows up wrapped, not as itself.How
effectTest(name, body, options?):Effect.scoped, giving every test a per-testScopewhose finalizers run on both the success and failure paths;options.layerthreads the test's requirements (R) without a global — the caller composescaptureLogger/TestContext(TestClock) / the stub HttpClient layer (comms-e5vm.1) and passes them as one layer. The base harness stays on the live clock, so TestClock is opt-in and live-clock tests are unaffected;Effect.runPromiseExitand, on failure, throwsCause.squash(cause)so the raw error surfaces.squash(notprettyErrors) deliberately returns the original thrown object untouched, keeping bun's assertion-diff renderer intact.runTestEffectis the engine behind the registrar, exported so the pass/fail mapping is itself testable (and usable inside a customtest.each).Design decisions (resolving the bead's open questions)
.scoped/.livevariants — the base is already always-scoped + live-clock; everything else is opt-in viaoptions.layer.Tests
11 tests covering: success resolves with value; typed failure and thrown defect both surface the raw object (not a FiberFailure); per-test Scope finalizers run on success and failure; layer provision via a
Context.Tagservice,captureLogger, andTestContext/TestClock; layer-build failure surfaces; plus theeffectTestregistrar wired end-to-end.