@systemfsoftware/effect-spec-runtime 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @systemfsoftware/effect-spec-runtime
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Suite registrars take a scenario, `(expect) => Effect`, instead of a bare Effect, and each case registers as a generator test, so the check a case ends in comes from the test's own `expect`. Kernel-explored cases re-provide the test's check ledger through `captureRunBinding`, so every seeded replay is judged once.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies:
12
+ - @systemfsoftware/vitest@0.1.0
13
+
3
14
  ## 0.2.0
4
15
 
5
16
  ### Minor Changes
package/README.md CHANGED
@@ -1,30 +1,46 @@
1
1
  # @systemfsoftware/effect-spec-runtime
2
2
 
3
- The registrar core behind Effect spec harnesses: describe/it selection and the Vitest task reference, with error and body types as parameters. `@systemfsoftware/effect-gherkin-spec` is built on it.
3
+ The registrar and kernel-case core behind Effect spec harnesses: every case runs under the simulation kernel by default (the zero-preemption schedule, then the profile's seeded schedules), a case that must stay on the live clock declares itself with a required reason, and a failure reports the seed and decision path that `CONFORMANCE_REPLAY` reproduces. `@systemfsoftware/effect-gherkin-spec` is built on it.
4
4
 
5
- The package exports two namespace barrels:
5
+ The package exports three namespace barrels:
6
6
 
7
7
  ```ts
8
- import { Suite, TaskRef } from '@systemfsoftware/effect-spec-runtime'
8
+ import { KernelCase, Suite, TaskRef } from '@systemfsoftware/effect-spec-runtime'
9
+ import { Effect } from 'effect'
9
10
  ```
10
11
 
12
+ ## KernelCase
13
+
14
+ `KernelCase.caseProgram(body, env)` builds a case whose layers are rebuilt fresh around every run and whose body runs under the kernel's test clock; `KernelCase.liveCase(body, env, reason)` is the live-clock counterpart and announces the reason on the run report, so every live case is listed with why it stayed live.
15
+
11
16
  ## Suite
12
17
 
13
18
  `Suite.open` registers a suite with no layer, `Suite.openShared` adds a layer shared by the whole suite, `Suite.openCase` adds a layer acquired fresh around every case, and `Suite.openSharedCase` does both:
14
19
 
15
20
  ```ts
16
- import { layer } from '@effect/vitest'
17
-
18
- Suite.openShared(bindings, config, { layer: DatabaseFixture, excludeTestServices: false }, (register) => {
19
- register('reads through the shared database', effect, 'run')
21
+ Suite.openShared(bindings, config, { layer: DatabaseFixture }, (register) => {
22
+ register(
23
+ 'reads through the shared database',
24
+ (expect) =>
25
+ Effect.gen(function*() {
26
+ const row = yield* DatabaseFixture.read()
27
+ yield* expect(row).toEqual('the stored row')
28
+ }),
29
+ 'run',
30
+ )
20
31
  })
21
32
  ```
22
33
 
23
- - `bindings` (`Suite.Bindings`) are the `@effect/vitest` `it` methods and `layer` helper you run under.
24
- - `config` (`Suite.Config`) names the suite, picks the describe collector (`describe` | `skip` | `only`, `Suite.DescribeMode`), carries Vitest `options`, and sets `liveClock` to choose between the test-clock and live-clock case runners.
34
+ - `bindings` (`Suite.Bindings`) are the `@systemfsoftware/vitest` `it` methods you run under. Every case is registered as a generator body, so the test's own `expect` is the case's and each check is yielded: `it(name, function* ({ expect }) { … })`.
35
+ - A scenario is the expect-taking run — `Suite.Scenario<B, E, R>` is `(expect: Expect) => Effect<B, E, R | Scope | Asserted>` — and the registrar (`Suite.RegisterFn<B, E, R>`) calls it inside the case body, so a library that writes a flow reaches the test's check callback instead of importing an `expect`.
36
+ - `config` (`Suite.Config`) names the suite, picks the describe collector (`describe` | `skip` | `only`, `Suite.DescribeMode`), carries Vitest `options`, and optionally declares the whole suite live with `live: { reason }`.
37
+ - A live case carries a required reason instead of a boolean, so the run report can name every live case: `config` takes it as `live: { reason }` and a registration takes it as `register('waits on real I/O', (expect) => program, 'run', { reason: 'waits on a socket' })`; a case that waits on the kernel's test clock calls `TestClock.adjust` or `TestClock.setTime` inside its body.
38
+ - A case without a live declaration is registered on the kernel lane with `Register.UNTIMED`: every run is bounded in steps, so no wall-clock timeout applies.
25
39
  - Each entry point hands `use` a registrar (`Suite.RegisterFn<B, E, R>`); the registrar's body and error channels are yours to declare, and its requirement channel is the union of the layer services it hands you. A shared layer is acquired once for the whole suite; a per-case layer is acquired and finalized around every case.
26
40
  - `register` mode is `Suite.RegisterMode` (`'run' | 'skip' | 'only'`).
27
41
 
42
+ `Register.exploredProgram(program)` is the kernel run of one case's program: it re-provides the test's binding onto the program (so the checks the kernel runs count for this test), scopes the run, and reports a failure with its seed and decision path.
43
+
28
44
  ## TaskRef
29
45
 
30
46
  `TaskRef.provideTaskRef(effect, ctx)` makes the running Vitest task context available to a case body:
@@ -39,4 +55,4 @@ pnpm add @systemfsoftware/effect-spec-runtime@workspace:^
39
55
  ```
40
56
 
41
57
  > [!NOTE]
42
- > `effect`, `@effect/vitest`, and `vitest` are peer dependencies — you bring your own.
58
+ > `effect`, `@systemfsoftware/vitest`, and `vitest` are peer dependencies — you bring your own.
package/dist/index.d.ts CHANGED
@@ -1,10 +1,47 @@
1
1
  import { Context, Effect, Layer } from "effect";
2
+ import { Expect, Vitest } from "@systemfsoftware/vitest";
3
+ import { Asserted } from "@systemfsoftware/vitest/integration";
2
4
  import { TestOptions } from "vitest";
3
- import * as EffectVitest from "@effect/vitest";
4
- import { Vitest } from "@effect/vitest";
5
5
  import * as Scope from "effect/Scope";
6
+ declare namespace KernelCase_d_exports {
7
+ export { LiveCase, announceLive, caseProgram, explore, liveCase };
8
+ }
9
+ /**
10
+ * The live declaration a case carries instead of the `liveClock` boolean
11
+ * (KTD11): a required reason string, so the run report can name every live
12
+ * case with the reason it stayed on the live clock.
13
+ */
14
+ interface LiveCase {
15
+ readonly reason: string;
16
+ }
17
+ /**
18
+ * Marks where the harness's own setup ends and the explored body begins:
19
+ * the case's layers build before it (fresh in every run, under the
20
+ * zero-preemption schedule), the scenario body runs after it.
21
+ */
22
+ declare const caseProgram: {
23
+ <B, E, R, RIn extends Scope.Scope>(env: Layer.Layer<R, never, RIn>): (body: Effect.Effect<B, E, R | RIn | Scope.Scope>) => Effect.Effect<B, E>;
24
+ <B, E, R, RIn extends Scope.Scope>(body: Effect.Effect<B, E, R | RIn | Scope.Scope>, env: Layer.Layer<R, never, RIn>): Effect.Effect<B, E>;
25
+ };
26
+ /** Announces a live case with its reason, which is how the run report lists it. */
27
+ declare const announceLive: (reason: string) => Effect.Effect<void>;
28
+ /**
29
+ * Runs a live-declared case: the case's layers are rebuilt fresh around the
30
+ * case, the reason is announced before the body, and the live-clock runner
31
+ * provides the case scope.
32
+ */
33
+ declare const liveCase: {
34
+ <B, E, R, RIn extends Scope.Scope>(env: Layer.Layer<R, never, RIn>, reason: string): (body: Effect.Effect<B, E, R | RIn | Scope.Scope>) => Effect.Effect<B, E, Scope.Scope>;
35
+ <B, E, R, RIn extends Scope.Scope>(body: Effect.Effect<B, E, R | RIn | Scope.Scope>, env: Layer.Layer<R, never, RIn>, reason: string): Effect.Effect<B, E, Scope.Scope>;
36
+ };
37
+ /**
38
+ * Runs one case's program under the kernel: the direct order first, then the
39
+ * profile's seeded PCT schedules at the profile depth. A failure reports its
40
+ * seed and decision path, which `CONFORMANCE_REPLAY` reproduces.
41
+ */
42
+ declare const explore: <A, E>(program: Effect.Effect<A, E>) => Promise<void>;
6
43
  declare namespace Register_d_exports {
7
- export { DescribeMode, RegisterMode, invokeDescribe, selectCaseRunner, selectLayeredRunner };
44
+ export { DescribeMode, RegisterMode, UNTIMED, exploredProgram, invokeDescribe, selectCaseRunner };
8
45
  }
9
46
  type RegisterMode = 'run' | 'skip' | 'only';
10
47
  type DescribeMode = 'describe' | 'skip' | 'only';
@@ -16,52 +53,64 @@ declare const invokeDescribe: {
16
53
  (mode: DescribeMode, suiteName: string, suiteOpts: Options | undefined): (fn: () => void) => void;
17
54
  (mode: DescribeMode, suiteName: string, suiteOpts: Options | undefined, fn: () => void): void;
18
55
  };
19
- declare const selectCaseRunner: {
20
- (mode: RegisterMode, useLiveClock: boolean): (methodsIt: Vitest.Methods) => Vitest.Test<Scope.Scope>;
21
- (methodsIt: Vitest.Methods, mode: RegisterMode, useLiveClock: boolean): Vitest.Test<Scope.Scope>;
56
+ /**
57
+ * An explored case has no wall-clock limit: every run is bounded in steps, and
58
+ * the kernel reports a hang (deadlock, runaway, or a wait it cannot observe)
59
+ * deterministically. A timer would only measure how busy the machine is.
60
+ */
61
+ declare const UNTIMED: {
62
+ readonly timeout: 0;
22
63
  };
23
- declare const selectLayeredRunner: {
24
- <R>(mode: RegisterMode): (scopedIt: Pick<Vitest.MethodsNonLive<R>, 'effect'>) => Vitest.Test<R | Scope.Scope>;
25
- <R>(scopedIt: Pick<Vitest.MethodsNonLive<R>, 'effect'>, mode: RegisterMode): Vitest.Test<R | Scope.Scope>;
64
+ /**
65
+ * One case's program under the kernel: the test's binding is re-provided onto it (the kernel
66
+ * drives it in its own run, so the check ledger and the running Vitest task are handed over), the
67
+ * run is scoped, and a failure reports its seed and decision path.
68
+ */
69
+ declare const exploredProgram: <A, E>(program: Effect.Effect<A, E, Scope.Scope>) => Effect.Effect<void, E, Asserted>;
70
+ declare const selectCaseRunner: {
71
+ (mode: RegisterMode, live: LiveCase | undefined): (methodsIt: Vitest.Methods) => Vitest.Test<Scope.Scope>;
72
+ (methodsIt: Vitest.Methods, mode: RegisterMode, live: LiveCase | undefined): Vitest.Test<Scope.Scope>;
26
73
  };
27
74
  declare namespace Suite_d_exports {
28
- export { Bindings, Config, DescribeMode, LayerOptions, Options, RegisterFn, RegisterMode, Shared, open, openCase, openShared, openSharedCase };
75
+ export { Bindings, Config$1 as Config, DescribeMode, LiveCase, Options, RegisterFn, RegisterMode, Scenario, Shared, open, openCase, openShared, openSharedCase };
29
76
  }
30
77
  type Options = Pick<TestOptions, 'tags'> & Partial<TestOptions>;
31
- interface LayerOptions {
32
- readonly excludeTestServices?: boolean;
33
- }
34
- interface Bindings extends Pick<typeof EffectVitest, 'layer'> {
78
+ interface Bindings {
35
79
  readonly it: Vitest.Methods;
36
80
  }
37
- interface Config {
81
+ interface Config$1 {
38
82
  readonly name: string;
39
83
  readonly describe: DescribeMode;
40
84
  readonly options: Options | undefined;
41
- readonly liveClock: boolean;
85
+ readonly live?: LiveCase;
42
86
  }
43
87
  interface Shared<R> {
44
88
  readonly layer: Layer.Layer<R>;
45
- readonly excludeTestServices: boolean;
46
89
  }
90
+ /**
91
+ * A registered case: the runner's own `expect` arrives as the argument, so a case's assertion
92
+ * steps check through the test's callback rather than an import. `R` is what the case's layer
93
+ * provides; every marked step needs the runner's scope and check service beside it.
94
+ */
95
+ type Scenario<B, E, R> = (expect: Expect) => Effect.Effect<B, E, R | Scope.Scope | Asserted>;
47
96
  interface RegisterFn<B, E, R> {
48
- (name: string, body: Effect.Effect<B, E, R>, mode: RegisterMode): void;
97
+ (name: string, scenario: Scenario<B, E, R>, mode: RegisterMode, live?: LiveCase): void;
49
98
  }
50
99
  declare const open: {
51
- <B, E, C>(config: Config, use: (register: RegisterFn<B, E, never>, propIt: Vitest.MethodsNonLive<never>) => C): (bindings: Bindings) => void;
52
- <B, E, C>(bindings: Bindings, config: Config, use: (register: RegisterFn<B, E, never>, propIt: Vitest.MethodsNonLive<never>) => C): void;
100
+ <B, E, C>(config: Config$1, use: (register: RegisterFn<B, E, Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): (bindings: Bindings) => void;
101
+ <B, E, C>(bindings: Bindings, config: Config$1, use: (register: RegisterFn<B, E, Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): void;
53
102
  };
54
103
  declare const openShared: {
55
- <B, E, RShared, C>(config: Config, shared: Shared<RShared>, use: (register: RegisterFn<B, E, RShared>, propIt: Vitest.MethodsNonLive<RShared>) => C): (bindings: Bindings) => void;
56
- <B, E, RShared, C>(bindings: Bindings, config: Config, shared: Shared<RShared>, use: (register: RegisterFn<B, E, RShared>, propIt: Vitest.MethodsNonLive<RShared>) => C): void;
104
+ <B, E, RShared, C>(config: Config$1, shared: Shared<RShared>, use: (register: RegisterFn<B, E, RShared | Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): (bindings: Bindings) => void;
105
+ <B, E, RShared, C>(bindings: Bindings, config: Config$1, shared: Shared<RShared>, use: (register: RegisterFn<B, E, RShared | Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): void;
57
106
  };
58
107
  declare const openCase: {
59
- <B, E, RFresh, RFreshReq extends Scope.Scope, C>(config: Config, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RFresh | RFreshReq>, propIt: Vitest.MethodsNonLive<never>) => C): (bindings: Bindings) => void;
60
- <B, E, RFresh, RFreshReq extends Scope.Scope, C>(bindings: Bindings, config: Config, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RFresh | RFreshReq>, propIt: Vitest.MethodsNonLive<never>) => C): void;
108
+ <B, E, RFresh, RFreshReq extends Scope.Scope, C>(config: Config$1, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RFresh | RFreshReq | Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): (bindings: Bindings) => void;
109
+ <B, E, RFresh, RFreshReq extends Scope.Scope, C>(bindings: Bindings, config: Config$1, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RFresh | RFreshReq | Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): void;
61
110
  };
62
111
  declare const openSharedCase: {
63
- <B, E, RShared, RFresh, RFreshReq extends RShared | Scope.Scope, C>(config: Config, shared: Shared<RShared>, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RShared | RFresh | RFreshReq>, propIt: Vitest.MethodsNonLive<RShared>) => C): (bindings: Bindings) => void;
64
- <B, E, RShared, RFresh, RFreshReq extends RShared | Scope.Scope, C>(bindings: Bindings, config: Config, shared: Shared<RShared>, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RShared | RFresh | RFreshReq>, propIt: Vitest.MethodsNonLive<RShared>) => C): void;
112
+ <B, E, RShared, RFresh, RFreshReq extends RShared, C>(config: Config$1, shared: Shared<RShared>, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RShared | RFresh | Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): (bindings: Bindings) => void;
113
+ <B, E, RShared, RFresh, RFreshReq extends RShared, C>(bindings: Bindings, config: Config$1, shared: Shared<RShared>, caseLayer: Layer.Layer<RFresh, never, RFreshReq>, use: (register: RegisterFn<B, E, RShared | RFresh | Scope.Scope>, propIt: Vitest.MethodsNonLive<never>) => C): void;
65
114
  };
66
115
  declare namespace TaskRef_service_d_exports {
67
116
  export { RawVitestTaskRef, VitestTaskContext, VitestTaskRef, provideTaskRef };
@@ -83,4 +132,4 @@ declare const provideTaskRef: {
83
132
  <A, E, R, Ctx>(effect: Effect.Effect<A, E, R>, ctx: Ctx): Effect.Effect<A, E, R>;
84
133
  };
85
134
  //#endregion
86
- export { Suite_d_exports as Suite, TaskRef_service_d_exports as TaskRef };
135
+ export { KernelCase_d_exports as KernelCase, Suite_d_exports as Suite, TaskRef_service_d_exports as TaskRef };
package/dist/index.mjs CHANGED
@@ -1,8 +1,196 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
- import { Context, Effect, Layer, Match, Option } from "effect";
2
+ import { Kernel } from "@systemfsoftware/effect-sim-kernel";
3
+ import { Cause, Config, Context, Effect, Exit, Layer, Match, Option } from "effect";
3
4
  import { dual } from "effect/Function";
5
+ import { VitestTestContext, vitestTestContextKey } from "@systemfsoftware/vitest";
6
+ import { captureRunBinding } from "@systemfsoftware/vitest/integration";
4
7
  import { describe } from "vitest";
5
- import { vitestTestContextKey } from "@effect/vitest";
8
+ //#region src/TaskRef.service.ts
9
+ var TaskRef_service_exports = /* @__PURE__ */ __exportAll({
10
+ RawVitestTaskRef: () => RawVitestTaskRef,
11
+ VitestTaskRef: () => VitestTaskRef,
12
+ provideTaskRef: () => provideTaskRef
13
+ });
14
+ const VitestTaskRef = Context.Reference("@systemfsoftware/effect-spec-runtime/VitestTask", { defaultValue: () => null });
15
+ /**
16
+ * The task context as the fork's run provides it: built on the fork's own key, so a case lane that goes
17
+ * through `provideTaskRef` and a property lane the fork runs itself read the same context.
18
+ */
19
+ const RawVitestTaskRef = Context.Reference(vitestTestContextKey, { defaultValue: () => null });
20
+ const isPlainTaskContext = (ctx) => typeof ctx === "object" && ctx !== null;
21
+ const isTaskContext = (ctx) => typeof ctx === "object" ? ctx !== null : typeof ctx === "function";
22
+ const readTaskContext = (ctx) => Option.getOrNull(Option.liftPredicate(ctx, isPlainTaskContext));
23
+ const readRawTaskContext = (ctx) => Option.getOrNull(Option.liftPredicate(ctx, isTaskContext));
24
+ const provideTaskRefImpl = (effect, ctx) => effect.pipe(Effect.provideService(VitestTaskRef, readTaskContext(ctx)), Effect.provideService(RawVitestTaskRef, readRawTaskContext(ctx)));
25
+ const provideTaskRef = dual(2, provideTaskRefImpl);
26
+ //#endregion
27
+ //#region src/KernelCase.ts
28
+ var KernelCase_exports = /* @__PURE__ */ __exportAll({
29
+ announceLive: () => announceLive,
30
+ caseProgram: () => caseProgram,
31
+ explore: () => explore,
32
+ liveCase: () => liveCase
33
+ });
34
+ /**
35
+ * One run's program: the case's layers build under the zero-preemption
36
+ * schedule, exploration is marked, and the scenario body runs under the
37
+ * kernel's test clock inside a scope the run owns.
38
+ */
39
+ const exploredCase = (body, env) => Effect.gen(function* () {
40
+ const built = yield* Layer.build(env);
41
+ yield* Kernel.beginExploration;
42
+ return yield* Effect.provideContext(body, built);
43
+ });
44
+ /**
45
+ * Closes the case's scope when the program settles: every resource the case
46
+ * acquired — its layers and its body — is released whether the body succeeds,
47
+ * fails, or is interrupted.
48
+ */
49
+ const caseScope = Effect.scoped;
50
+ /**
51
+ * Marks where the harness's own setup ends and the explored body begins:
52
+ * the case's layers build before it (fresh in every run, under the
53
+ * zero-preemption schedule), the scenario body runs after it.
54
+ */
55
+ const caseProgram = dual((args) => args.length === 2 && Effect.isEffect(args[0]), (body, env) => caseScope(Effect.provide(exploredCase(body, env), Kernel.TestClock.layer)));
56
+ /** Announces a live case with its reason, which is how the run report lists it. */
57
+ const announceLive = (reason) => Effect.gen(function* () {
58
+ const task = yield* RawVitestTaskRef;
59
+ return yield* announce(task, reason);
60
+ });
61
+ const dispatchAnnotate = (annotate, message) => Option.match(Option.fromNullishOr(annotate), {
62
+ onNone: () => Effect.void,
63
+ onSome: (record) => Effect.promise(() => Promise.resolve(record(message)))
64
+ });
65
+ const announce = (task, reason) => Option.match(Option.fromNullishOr(task), {
66
+ onNone: () => Effect.void,
67
+ onSome: (context) => dispatchAnnotate(context.annotate, `live case: ${reason}`)
68
+ });
69
+ /**
70
+ * One live case's program: the case's layers build fresh around the case and
71
+ * the scenario body runs under them; the live-clock runner provides the
72
+ * scope.
73
+ */
74
+ const announcedCase = (body, env, reason) => Effect.gen(function* () {
75
+ const built = yield* Layer.build(env);
76
+ yield* announceLive(reason);
77
+ return yield* Effect.provideContext(body, built);
78
+ });
79
+ /**
80
+ * Runs a live-declared case: the case's layers are rebuilt fresh around the
81
+ * case, the reason is announced before the body, and the live-clock runner
82
+ * provides the case scope.
83
+ */
84
+ const liveCase = dual((args) => args.length === 3 && Effect.isEffect(args[0]), (body, env, reason) => announcedCase(body, env, reason));
85
+ const replayValueOf = (schedule) => {
86
+ const path = `path=${schedule.decisions.join(",")}`;
87
+ if (schedule.seed === void 0) return path;
88
+ return `seed=${schedule.seed};${path}`;
89
+ };
90
+ const describeSchedule = (schedule) => schedule.seed === void 0 ? "Effect's order" : `seed ${schedule.seed}`;
91
+ const scheduleReport = (schedule, detail) => `${detail}\nschedule: ${describeSchedule(schedule)}\nreplay with: CONFORMANCE_REPLAY="${replayValueOf(schedule)}"`;
92
+ const describeSuspended = (fiber) => {
93
+ const first = fiber.frames[0];
94
+ if (first === void 0) return `fiber ${fiber.id}`;
95
+ return `fiber ${fiber.id} at ${first}`;
96
+ };
97
+ const describeKernelFailure = (failure) => Match.value(failure).pipe(Match.when({ _tag: "Escape" }, (escape) => `escaped the controlled schedule through the ${escape.timer} timer at ${escape.site}`), Match.when({ _tag: "Blocked" }, (blocked) => `waited on a resource the kernel cannot observe: ${blocked.resources.join(", ")}`), Match.when({ _tag: "Deadlock" }, (deadlock) => `deadlocked with ${deadlock.suspended.length} suspended fibers: ${deadlock.suspended.map(describeSuspended).join("; ")}`), Match.when({ _tag: "Runaway" }, (runaway) => `ran past ${runaway.steps} steps with ${runaway.pending} fibers pending`), Match.exhaustive);
98
+ const throwExitFailure = (exit, schedule) => {
99
+ const first = Cause.prettyErrors(exit.cause)[0];
100
+ const reported = first === void 0 ? new Error(Cause.pretty(exit.cause)) : first;
101
+ reported.message = `${reported.message}\n\n${scheduleReport(schedule, "the scenario body failed")}`;
102
+ throw reported;
103
+ };
104
+ const throwKernelFailure = (failure, schedule) => {
105
+ throw new Error(scheduleReport(schedule, describeKernelFailure(failure)));
106
+ };
107
+ const isKernelFailure = (observed) => "failure" in observed;
108
+ const throwIfExitFailed = (observed, schedule) => {
109
+ if (Exit.isFailure(observed.exit)) throwExitFailure(observed.exit, schedule);
110
+ };
111
+ const throwIfFailed = (observed, schedule) => {
112
+ if (!isKernelFailure(observed)) throwIfExitFailed(observed, schedule);
113
+ else throwKernelFailure(observed.failure, schedule);
114
+ };
115
+ const surveyOf = (baseline) => ({
116
+ fibers: new Set(baseline.steps.map((step) => step.fiberId)).size,
117
+ steps: baseline.steps.length
118
+ });
119
+ const budgetOf = (survey) => Effect.runPromise(Kernel.currentSeedsFor({
120
+ fibers: survey.fibers,
121
+ steps: survey.steps
122
+ }));
123
+ const seedList = (count) => Array.from({ length: count }, (_entry, seed) => seed);
124
+ const seedsToRun = (seed, budget) => {
125
+ if (seed === void 0) return seedList(budget);
126
+ return [seed];
127
+ };
128
+ const SEED_PATTERN = /seed=(\d+)/u;
129
+ const PATH_PATTERN = /path=((?:\d+)(?:,\d+)*)/u;
130
+ const seedOf = (value) => {
131
+ const match = SEED_PATTERN.exec(value);
132
+ if (match === null) return void 0;
133
+ return Number(match[1]);
134
+ };
135
+ const pathOf = (value) => Option.getOrUndefined(Option.map(Option.flatMap(Option.fromNullishOr(PATH_PATTERN.exec(value)), (match) => Option.fromNullishOr(match[1])), (raw) => raw.split(",").map((entry) => Number(entry))));
136
+ const isEmptyReplay = (replay) => replay.seed === void 0 && replay.path === void 0;
137
+ const replayOf = (value) => {
138
+ const replay = {
139
+ seed: seedOf(value),
140
+ path: pathOf(value)
141
+ };
142
+ if (isEmptyReplay(replay)) throw new Error(`CONFORMANCE_REPLAY names neither a seed nor a decision path: ${value}`);
143
+ return replay;
144
+ };
145
+ const readReplayValue = () => Effect.runPromise(Effect.map(Config.option(Config.String("CONFORMANCE_REPLAY")), Option.getOrUndefined));
146
+ const replayRun = (program, path) => Kernel.run(program, {
147
+ explore: "body",
148
+ path
149
+ }).then((observed) => {
150
+ throwIfFailed(observed, {
151
+ seed: void 0,
152
+ decisions: path
153
+ });
154
+ });
155
+ const runSeeds = (program, seeds, at, steps) => {
156
+ const seed = seeds[at];
157
+ if (seed === void 0) return Promise.resolve();
158
+ return Kernel.run(program, {
159
+ explore: "body",
160
+ choose: Kernel.pick({
161
+ seed,
162
+ steps
163
+ })
164
+ }).then((observed) => {
165
+ throwIfFailed(observed, {
166
+ seed,
167
+ decisions: observed.decisions
168
+ });
169
+ return runSeeds(program, seeds, at + 1, steps);
170
+ });
171
+ };
172
+ const seededRuns = (program, seed, survey) => budgetOf(survey).then((budget) => runSeeds(program, seedsToRun(seed, budget), 0, survey.steps));
173
+ const baselineThen = (program, seed) => Kernel.run(program, { explore: "body" }).then((baseline) => {
174
+ throwIfFailed(baseline, {
175
+ seed: void 0,
176
+ decisions: baseline.decisions
177
+ });
178
+ return seededRuns(program, seed, surveyOf(baseline));
179
+ });
180
+ const replayOrSeeded = (program, replay) => {
181
+ if (replay.path !== void 0) return replayRun(program, replay.path);
182
+ return baselineThen(program, replay.seed);
183
+ };
184
+ /**
185
+ * Runs one case's program under the kernel: the direct order first, then the
186
+ * profile's seeded PCT schedules at the profile depth. A failure reports its
187
+ * seed and decision path, which `CONFORMANCE_REPLAY` reproduces.
188
+ */
189
+ const explore = (program) => readReplayValue().then((value) => {
190
+ if (value === void 0) return baselineThen(program, void 0);
191
+ return replayOrSeeded(program, replayOf(value));
192
+ });
193
+ //#endregion
6
194
  //#region src/Register.ts
7
195
  const selectDescribe = (mode) => ({
8
196
  skip: describe.skip,
@@ -22,39 +210,51 @@ const invokeDescribeImpl = (mode, suiteName, suiteOpts, fn) => Option.match(Opti
22
210
  * without options is registered through the two-argument collector call.
23
211
  */
24
212
  const invokeDescribe = dual(4, invokeDescribeImpl);
25
- const pickTester = (family, mode) => ({
26
- skip: family.skip,
27
- only: family.only,
28
- run: family
213
+ const pickLane = (lanes, mode) => ({
214
+ skip: lanes.skip,
215
+ only: lanes.only,
216
+ run: lanes.run
29
217
  })[mode];
218
+ /** The virtual-clock lane: the fork's own generator-body `it` and its two mode variants. */
219
+ const virtualLanes = (methodsIt) => ({
220
+ run: methodsIt,
221
+ skip: methodsIt.skip,
222
+ only: methodsIt.only
223
+ });
224
+ /** The live-clock lane: `it.live` and its two mode variants, which already carry `Scope`. */
225
+ const liveLanes = (methodsIt) => ({
226
+ run: methodsIt.live,
227
+ skip: methodsIt.live.skip,
228
+ only: methodsIt.live.only
229
+ });
30
230
  /**
31
- * The live-clock case runner observes wall-clock time; the test-clock runner
32
- * shares the suite's controlled clock.
231
+ * An explored case runs under the kernel's own clock, so it registers on the virtual lane; a
232
+ * live-declared case keeps the real clock and registers on `it.live`.
33
233
  */
34
- const caseClockFamily = (methodsIt, useLiveClock) => Match.value(useLiveClock).pipe(Match.when(true, () => methodsIt.live), Match.when(false, () => methodsIt.effect), Match.exhaustive);
35
- const selectCaseRunnerImpl = (methodsIt, mode, useLiveClock) => pickTester(caseClockFamily(methodsIt, useLiveClock), mode);
36
- const selectCaseRunner = dual(3, selectCaseRunnerImpl);
37
- const selectLayeredRunnerImpl = (scopedIt, mode) => pickTester(scopedIt.effect, mode);
38
- const selectLayeredRunner = dual(2, selectLayeredRunnerImpl);
39
- //#endregion
40
- //#region src/TaskRef.service.ts
41
- var TaskRef_service_exports = /* @__PURE__ */ __exportAll({
42
- RawVitestTaskRef: () => RawVitestTaskRef,
43
- VitestTaskRef: () => VitestTaskRef,
44
- provideTaskRef: () => provideTaskRef
234
+ const caseLanes = (methodsIt, live) => live === void 0 ? virtualLanes(methodsIt) : liveLanes(methodsIt);
235
+ const scopedBody = Effect.scoped;
236
+ /**
237
+ * An explored case has no wall-clock limit: every run is bounded in steps, and
238
+ * the kernel reports a hang (deadlock, runaway, or a wait it cannot observe)
239
+ * deterministically. A timer would only measure how busy the machine is.
240
+ */
241
+ const UNTIMED = { timeout: 0 };
242
+ /**
243
+ * One case's program under the kernel: the test's binding is re-provided onto it (the kernel
244
+ * drives it in its own run, so the check ledger and the running Vitest task are handed over), the
245
+ * run is scoped, and a failure reports its seed and decision path.
246
+ */
247
+ const exploredProgram = (program) => Effect.gen(function* () {
248
+ const bound = (yield* captureRunBinding).bind(program);
249
+ return yield* Effect.promise(() => bound.pipe(scopedBody, explore));
45
250
  });
46
- const VitestTaskRef = Context.Reference("@systemfsoftware/effect-spec-runtime/VitestTask", { defaultValue: () => null });
47
251
  /**
48
- * The task context as the fork's run provides it: built on the fork's own key, so a case lane that goes
49
- * through `provideTaskRef` and a property lane the fork runs itself read the same context.
252
+ * A live-declared case runs on the live clock as before; a case without a
253
+ * live declaration runs under the kernel, exploring the profile's schedules
254
+ * through the fork's Effect lane.
50
255
  */
51
- const RawVitestTaskRef = Context.Reference(vitestTestContextKey, { defaultValue: () => null });
52
- const isPlainTaskContext = (ctx) => typeof ctx === "object" && ctx !== null;
53
- const isTaskContext = (ctx) => typeof ctx === "object" ? ctx !== null : typeof ctx === "function";
54
- const readTaskContext = (ctx) => Option.getOrNull(Option.liftPredicate(ctx, isPlainTaskContext));
55
- const readRawTaskContext = (ctx) => Option.getOrNull(Option.liftPredicate(ctx, isTaskContext));
56
- const provideTaskRefImpl = (effect, ctx) => effect.pipe(Effect.provideService(VitestTaskRef, readTaskContext(ctx)), Effect.provideService(RawVitestTaskRef, readRawTaskContext(ctx)));
57
- const provideTaskRef = dual(2, provideTaskRefImpl);
256
+ const selectCaseRunnerImpl = (methodsIt, mode, live) => pickLane(caseLanes(methodsIt, live), mode);
257
+ const selectCaseRunner = dual(3, selectCaseRunnerImpl);
58
258
  //#endregion
59
259
  //#region src/Suite.ts
60
260
  var Suite_exports = /* @__PURE__ */ __exportAll({
@@ -63,43 +263,68 @@ var Suite_exports = /* @__PURE__ */ __exportAll({
63
263
  openShared: () => openShared,
64
264
  openSharedCase: () => openSharedCase
65
265
  });
66
- const layerSetupOptions = (excludeTestServices, useLiveClock) => ({
67
- excludeTestServices: excludeTestServices || useLiveClock,
68
- shared: true
69
- });
70
- const unlayeredRegister = (methodsIt, config, caseLayer) => (name, body, mode) => {
71
- selectCaseRunner(methodsIt, mode, config.liveClock)(name, (ctx) => provideTaskRef(body.pipe(Effect.provide(Layer.fresh(caseLayer))), ctx));
266
+ const caseEffectOf = (body, env, live) => {
267
+ if (live !== void 0) return liveCase(body, env, live.reason);
268
+ return caseProgram(body, env);
72
269
  };
73
- const layeredRegister = (scopedIt, caseLayer) => (name, body, mode) => {
74
- selectLayeredRunner(scopedIt, mode)(name, (ctx) => provideTaskRef(body.pipe(Effect.provide(Layer.fresh(caseLayer))), ctx));
270
+ /**
271
+ * One case's program: the callback's own `expect` builds the scenario Effect, and the case's
272
+ * layers build fresh around it — under the kernel's scheduled exploration, or on the live clock
273
+ * when the case declares a reason.
274
+ */
275
+ const caseProgramOf = (scenario, env, live, binding) => (expect) => {
276
+ const bound = binding.bind(scenario(expect));
277
+ return caseEffectOf(bound, env, live);
278
+ };
279
+ /**
280
+ * The fork's generator body for one case: it hands the callback's `expect` to the scenario, hands
281
+ * the running Vitest task to the step annotations, and runs the program the case declared — under
282
+ * the kernel's explored schedules, or on the live clock.
283
+ */
284
+ const caseBody = (scenario, env, live) => function* ({ expect }) {
285
+ const ctx = yield* VitestTestContext;
286
+ const binding = yield* captureRunBinding;
287
+ const program = provideTaskRef(caseProgramOf(scenario, env, live, binding)(expect), ctx);
288
+ if (live === void 0) {
289
+ yield* exploredProgram(program);
290
+ return;
291
+ }
292
+ yield* program;
293
+ };
294
+ const registerCase = (register, name, scenario, env, live) => {
295
+ if (live === void 0) {
296
+ register(name, caseBody(scenario, env, live), UNTIMED);
297
+ return;
298
+ }
299
+ register(name, caseBody(scenario, env, live));
300
+ };
301
+ const registrarFor = (methodsIt, config, env) => (name, scenario, mode, caseLive) => {
302
+ const live = caseLive ?? config.live;
303
+ registerCase(selectCaseRunner(methodsIt, mode, live), name, scenario, env, live);
75
304
  };
76
305
  const openImpl = (bindings, config, use) => {
77
306
  invokeDescribe(config.describe, config.name, config.options, () => {
78
- use(unlayeredRegister(bindings.it, config, Layer.empty), bindings.it);
307
+ use(registrarFor(bindings.it, config, Layer.empty), bindings.it);
79
308
  });
80
309
  };
81
310
  const open = dual(3, openImpl);
82
311
  const openSharedImpl = (bindings, config, shared, use) => {
83
312
  invokeDescribe(config.describe, config.name, config.options, () => {
84
- bindings.layer(shared.layer, layerSetupOptions(shared.excludeTestServices, config.liveClock))((scopedIt) => {
85
- use(layeredRegister(scopedIt, Layer.empty), scopedIt);
86
- });
313
+ use(registrarFor(bindings.it, config, Layer.fresh(shared.layer)), bindings.it);
87
314
  });
88
315
  };
89
316
  const openShared = dual(4, openSharedImpl);
90
317
  const openCaseImpl = (bindings, config, caseLayer, use) => {
91
318
  invokeDescribe(config.describe, config.name, config.options, () => {
92
- use(unlayeredRegister(bindings.it, config, caseLayer), bindings.it);
319
+ use(registrarFor(bindings.it, config, Layer.fresh(caseLayer)), bindings.it);
93
320
  });
94
321
  };
95
322
  const openCase = dual(4, openCaseImpl);
96
323
  const openSharedCaseImpl = (bindings, config, shared, caseLayer, use) => {
97
324
  invokeDescribe(config.describe, config.name, config.options, () => {
98
- bindings.layer(shared.layer, layerSetupOptions(shared.excludeTestServices, config.liveClock))((scopedIt) => {
99
- use(layeredRegister(scopedIt, caseLayer), scopedIt);
100
- });
325
+ use(registrarFor(bindings.it, config, Layer.fresh(caseLayer).pipe(Layer.provideMerge(shared.layer))), bindings.it);
101
326
  });
102
327
  };
103
328
  const openSharedCase = dual(5, openSharedCaseImpl);
104
329
  //#endregion
105
- export { Suite_exports as Suite, TaskRef_service_exports as TaskRef };
330
+ export { KernelCase_exports as KernelCase, Suite_exports as Suite, TaskRef_service_exports as TaskRef };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@systemfsoftware/effect-spec-runtime",
3
3
  "license": "Apache-2.0",
4
- "version": "0.2.0",
4
+ "version": "0.3.0",
5
5
  "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -31,12 +31,16 @@
31
31
  "files": [
32
32
  "dist"
33
33
  ],
34
+ "dependencies": {
35
+ "@systemfsoftware/effect-sim-kernel": "^0.1.1"
36
+ },
34
37
  "devDependencies": {
35
- "@effect/vitest": "npm:@systemfsoftware/vitest@0.0.0",
38
+ "@microsoft/api-extractor": "^7.59.1",
36
39
  "@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
37
- "@systemfsoftware/oxlint-config-recommended": "^3.0.0",
40
+ "@systemfsoftware/oxlint-config-recommended": "^3.1.0",
38
41
  "@systemfsoftware/tsconfig": "^2.0.1",
39
42
  "@systemfsoftware/tsdown-config": "^0.1.0",
43
+ "@systemfsoftware/vitest": "^0.1.0",
40
44
  "@systemfsoftware/vitest-config": "^0.1.0",
41
45
  "@types/node": "^26",
42
46
  "effect": "4.0.0-rc.117",
@@ -48,7 +52,7 @@
48
52
  "vitest": "^5"
49
53
  },
50
54
  "peerDependencies": {
51
- "@effect/vitest": "npm:@systemfsoftware/vitest@*",
55
+ "@systemfsoftware/vitest": "^0.1.0",
52
56
  "effect": "4.0.0-rc.117",
53
57
  "vitest": "^5"
54
58
  },
@@ -57,11 +61,13 @@
57
61
  },
58
62
  "scripts": {
59
63
  "clean": "rimraf dist",
60
- "build": "tsdown -l warn",
64
+ "build": "tsdown -l warn && pnpm api:check",
61
65
  "typecheck": "tsc -b",
62
66
  "test": "vitest run",
63
67
  "test:types": "TSTYCHE_TYPESCRIPT_MODULE=tstyche-typescript tstyche",
64
68
  "lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
65
- "attw": "attw --pack ."
69
+ "attw": "attw --pack .",
70
+ "api:check": "api-extractor-quiet run",
71
+ "api:update": "api-extractor run --local"
66
72
  }
67
73
  }