refactor(cf): Queue-based CFEvents + property tests#135
Merged
Conversation
12 fast-check property tests using Schema.toArbitrary for CloudflareInfo, CloudflareResult, and CloudflareSnapshot. Validates round-trip encode/decode, type constraints (finite, integer), required fields, and JSON serialization.
…ipeline Replace the createCFEvents frozen closure in cloudflare-event-emitter.ts with a Queue.unbounded<CFEvent>() pipeline. The old closure mixed three concerns (tracker mutation, CDP event emission, replay marker injection) and used a _setRealEmit closure hack for late-binding. New architecture: - CFEvent TaggedEnum (6 variants) in cf-event-types.ts - makeCFEventPipeline() in cf-event-queue.ts with Stream consumer - Queue.offerUnsafe for synchronous publishing from any context - Match.exhaustive consumer with compile-time variant coverage Call site changes: 34 sites across 3 files (detector: 20, state-tracker: 11, solver crash handler: 1, solver layer: 5). SolverEvents consumers (45 call sites across 4 files) required ZERO changes — interface unchanged. Deleted: createCFEvents function, CFEvents type, _setRealEmit hack.
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
createCFEvents()frozen closure withQueue.unbounded<CFEvent>()pipelineMatch.exhaustivefor compile-time variant coverageQueue.offerUnsafefor synchronous publishing from Resolution callbacks, scope finalizers, and crash handlerscreateCFEvents,CFEventstype, and_setRealEmitclosure hackChanges
src/session/cf/cf-event-types.tssrc/session/cf/cf-event-queue.tssrc/shared/cloudflare-schema.property.test.tssrc/session/cf/cloudflare-event-emitter.tscreateCFEvents+CFEvents(-100 lines)src/session/cloudflare-solver.tssrc/session/cf/cloudflare-detector.tsevents.*→cfPublish(CFEvent.*)(20 sites)src/session/cf/cloudflare-state-tracker.tsevents.*→cfPublish(CFEvent.*)(11 sites)src/session/cf/cf-session-state.tsevents→cfPublishin constructorZERO changes: solver.effect.ts, cf-phase-checkbox.ts, cf-phase-oopif.ts, solve-strategies.ts (45 consumer call sites unchanged)
Test plan
npx tsc --noEmit— zero type errorsnpx vitest run— 293/293 tests pass (16 files)grep -r 'createCFEvents\|CFEvents' src/— zero code references (comments only)grep -r '\.events\.(emit|marker)' src/session/— zero references