@systemfsoftware/effect-spec-runtime 0.2.0 → 0.3.1

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,26 @@
1
1
  # @systemfsoftware/effect-spec-runtime
2
2
 
3
+ ## 0.3.1
4
+
5
+ ### Patch Changes
6
+
7
+ - A failing kernel-explored case now throws the rendered failure record. A failure on the baseline schedule no longer prints a schedule or replay value; a seeded failure still names its seed and replay path.
8
+
9
+ - Updated dependencies:
10
+ - @systemfsoftware/effect-sim-kernel@0.2.0
11
+ - @systemfsoftware/vitest@0.2.0
12
+
13
+ ## 0.3.0
14
+
15
+ ### Minor Changes
16
+
17
+ - 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.
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies:
22
+ - @systemfsoftware/vitest@0.1.0
23
+
3
24
  ## 0.2.0
4
25
 
5
26
  ### 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,221 @@
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 { createSpanRecorder, providedWorkspaceRoot, testIdentityOf, throwFailureRecord } from "@systemfsoftware/vitest/failure";
4
+ import { Cause, Config, Context, Effect, Exit, Layer, Match, Option, Schema } from "effect";
3
5
  import { dual } from "effect/Function";
6
+ import { VitestTestContext, vitestTestContextKey } from "@systemfsoftware/vitest";
7
+ import { captureRunBinding } from "@systemfsoftware/vitest/integration";
4
8
  import { describe } from "vitest";
5
- import { vitestTestContextKey } from "@effect/vitest";
9
+ //#region src/KernelFailure.schema.ts
10
+ /**
11
+ * The kernel's own failure — a deadlock, an escape, a wait it cannot observe, or a runaway run — as a failure
12
+ * value carrying the message the record's headline shows (R1, R2). It is a value, not a formatted string, so the
13
+ * renderer reads its first location from the innermost unfinished cell span's decide site.
14
+ */
15
+ var KernelFailure = class extends Schema.TaggedError()("KernelFailure", { detail: Schema.String }) {
16
+ get message() {
17
+ return this.detail;
18
+ }
19
+ };
20
+ //#endregion
21
+ //#region src/TaskRef.service.ts
22
+ var TaskRef_service_exports = /* @__PURE__ */ __exportAll({
23
+ RawVitestTaskRef: () => RawVitestTaskRef,
24
+ VitestTaskRef: () => VitestTaskRef,
25
+ provideTaskRef: () => provideTaskRef
26
+ });
27
+ const VitestTaskRef = Context.Reference("@systemfsoftware/effect-spec-runtime/VitestTask", { defaultValue: () => null });
28
+ /**
29
+ * The task context as the fork's run provides it: built on the fork's own key, so a case lane that goes
30
+ * through `provideTaskRef` and a property lane the fork runs itself read the same context.
31
+ */
32
+ const RawVitestTaskRef = Context.Reference(vitestTestContextKey, { defaultValue: () => null });
33
+ const isPlainTaskContext = (ctx) => typeof ctx === "object" && ctx !== null;
34
+ const isTaskContext = (ctx) => typeof ctx === "object" ? ctx !== null : typeof ctx === "function";
35
+ const readTaskContext = (ctx) => Option.getOrNull(Option.liftPredicate(ctx, isPlainTaskContext));
36
+ const readRawTaskContext = (ctx) => Option.getOrNull(Option.liftPredicate(ctx, isTaskContext));
37
+ const provideTaskRefImpl = (effect, ctx) => effect.pipe(Effect.provideService(VitestTaskRef, readTaskContext(ctx)), Effect.provideService(RawVitestTaskRef, readRawTaskContext(ctx)));
38
+ const provideTaskRef = dual(2, provideTaskRefImpl);
39
+ //#endregion
40
+ //#region src/KernelCase.ts
41
+ var KernelCase_exports = /* @__PURE__ */ __exportAll({
42
+ announceLive: () => announceLive,
43
+ caseProgram: () => caseProgram,
44
+ explore: () => explore,
45
+ liveCase: () => liveCase
46
+ });
47
+ /**
48
+ * One run's program: the case's layers build under the zero-preemption
49
+ * schedule, exploration is marked, and the scenario body runs under the
50
+ * kernel's test clock inside a scope the run owns.
51
+ */
52
+ const exploredCase = (body, env) => Effect.gen(function* () {
53
+ const built = yield* Layer.build(env);
54
+ yield* Kernel.beginExploration;
55
+ return yield* Effect.provideContext(body, built);
56
+ });
57
+ /**
58
+ * Closes the case's scope when the program settles: every resource the case
59
+ * acquired — its layers and its body — is released whether the body succeeds,
60
+ * fails, or is interrupted.
61
+ */
62
+ const caseScope = Effect.scoped;
63
+ /**
64
+ * Marks where the harness's own setup ends and the explored body begins:
65
+ * the case's layers build before it (fresh in every run, under the
66
+ * zero-preemption schedule), the scenario body runs after it.
67
+ */
68
+ const caseProgram = dual((args) => args.length === 2 && Effect.isEffect(args[0]), (body, env) => caseScope(Effect.provide(exploredCase(body, env), Kernel.TestClock.layer)));
69
+ /** Announces a live case with its reason, which is how the run report lists it. */
70
+ const announceLive = (reason) => Effect.gen(function* () {
71
+ const task = yield* RawVitestTaskRef;
72
+ return yield* announce(task, reason);
73
+ });
74
+ const dispatchAnnotate = (annotate, message) => Option.match(Option.fromNullishOr(annotate), {
75
+ onNone: () => Effect.void,
76
+ onSome: (record) => Effect.promise(() => Promise.resolve(record(message)))
77
+ });
78
+ const announce = (task, reason) => Option.match(Option.fromNullishOr(task), {
79
+ onNone: () => Effect.void,
80
+ onSome: (context) => dispatchAnnotate(context.annotate, `live case: ${reason}`)
81
+ });
82
+ /**
83
+ * One live case's program: the case's layers build fresh around the case and
84
+ * the scenario body runs under them; the live-clock runner provides the
85
+ * scope.
86
+ */
87
+ const announcedCase = (body, env, reason) => Effect.gen(function* () {
88
+ const built = yield* Layer.build(env);
89
+ yield* announceLive(reason);
90
+ return yield* Effect.provideContext(body, built);
91
+ });
92
+ /**
93
+ * Runs a live-declared case: the case's layers are rebuilt fresh around the
94
+ * case, the reason is announced before the body, and the live-clock runner
95
+ * provides the case scope.
96
+ */
97
+ const liveCase = dual((args) => args.length === 3 && Effect.isEffect(args[0]), (body, env, reason) => announcedCase(body, env, reason));
98
+ const describeSuspended = (fiber) => {
99
+ const first = fiber.frames[0];
100
+ if (first === void 0) return `fiber ${fiber.id}`;
101
+ return `fiber ${fiber.id} at ${first}`;
102
+ };
103
+ 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);
104
+ /** One run with its own recorder: the record is rendered from exactly the spans this run opened (KTD2). */
105
+ const recorded = (program) => {
106
+ const recorder = createSpanRecorder();
107
+ return {
108
+ program: Effect.withTracer(program, recorder.tracer),
109
+ recorder
110
+ };
111
+ };
112
+ /** The replay value a schedule is worth: only a generator's choice, never a baseline run's own order (R6). */
113
+ const replayValueOf = (schedule) => schedule.seed === void 0 ? void 0 : {
114
+ seed: schedule.seed,
115
+ path: schedule.decisions
116
+ };
117
+ const scheduleNoteOf = (schedule) => schedule.seed === void 0 ? void 0 : { seed: schedule.seed };
118
+ const throwRecord = (failure, schedule, recorder) => throwFailureRecord({
119
+ failure,
120
+ spans: recorder.spans,
121
+ identity: testIdentityOf(),
122
+ replay: replayValueOf(schedule),
123
+ schedule: scheduleNoteOf(schedule),
124
+ root: providedWorkspaceRoot()
125
+ });
126
+ const throwKernelFailure = (failure, schedule, recorder) => throwRecord(new KernelFailure({ detail: describeKernelFailure(failure) }), schedule, recorder);
127
+ const throwExitFailure = (exit, schedule, recorder) => throwRecord(Cause.squash(exit.cause), schedule, recorder);
128
+ const isKernelFailure = (observed) => "failure" in observed;
129
+ const throwIfExitFailed = (observed, schedule, recorder) => {
130
+ if (Exit.isFailure(observed.exit)) throwExitFailure(observed.exit, schedule, recorder);
131
+ };
132
+ const throwIfFailed = (observed, schedule, recorder) => Match.value(observed).pipe(Match.when(isKernelFailure, (failed) => throwKernelFailure(failed.failure, schedule, recorder)), Match.orElse((completed) => throwIfExitFailed(completed, schedule, recorder)));
133
+ const surveyOf = (baseline) => ({
134
+ fibers: new Set(baseline.steps.map((step) => step.fiberId)).size,
135
+ steps: baseline.steps.length
136
+ });
137
+ const budgetOf = (survey) => Effect.runPromise(Kernel.currentSeedsFor({
138
+ fibers: survey.fibers,
139
+ steps: survey.steps
140
+ }));
141
+ const seedList = (count) => Array.from({ length: count }, (_entry, seed) => seed);
142
+ const seedsToRun = (seed, budget) => {
143
+ if (seed === void 0) return seedList(budget);
144
+ return [seed];
145
+ };
146
+ const SEED_PATTERN = /seed=(\d+)/u;
147
+ const PATH_PATTERN = /path=((?:\d+)(?:,\d+)*)/u;
148
+ const seedOf = (value) => {
149
+ const match = SEED_PATTERN.exec(value);
150
+ if (match === null) return void 0;
151
+ return Number(match[1]);
152
+ };
153
+ 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))));
154
+ const isEmptyReplay = (replay) => replay.seed === void 0 && replay.path === void 0;
155
+ const replayOf = (value) => {
156
+ const replay = {
157
+ seed: seedOf(value),
158
+ path: pathOf(value)
159
+ };
160
+ if (isEmptyReplay(replay)) throw new Error(`CONFORMANCE_REPLAY names neither a seed nor a decision path: ${value}`);
161
+ return replay;
162
+ };
163
+ const readReplayValue = () => Effect.runPromise(Effect.map(Config.option(Config.String("CONFORMANCE_REPLAY")), Option.getOrUndefined));
164
+ const replayRun = (program, replay, path) => {
165
+ const run = recorded(program);
166
+ return Kernel.run(run.program, {
167
+ explore: "body",
168
+ path
169
+ }).then((observed) => {
170
+ throwIfFailed(observed, {
171
+ seed: replay.seed,
172
+ decisions: path
173
+ }, run.recorder);
174
+ });
175
+ };
176
+ const runSeeds = (program, seeds, at, steps) => {
177
+ const seed = seeds[at];
178
+ if (seed === void 0) return Promise.resolve();
179
+ const run = recorded(program);
180
+ return Kernel.run(run.program, {
181
+ explore: "body",
182
+ choose: Kernel.pick({
183
+ seed,
184
+ steps
185
+ })
186
+ }).then((observed) => {
187
+ throwIfFailed(observed, {
188
+ seed,
189
+ decisions: observed.decisions
190
+ }, run.recorder);
191
+ return runSeeds(program, seeds, at + 1, steps);
192
+ });
193
+ };
194
+ const seededRuns = (program, seed, survey) => budgetOf(survey).then((budget) => runSeeds(program, seedsToRun(seed, budget), 0, survey.steps));
195
+ const baselineThen = (program, seed) => {
196
+ const run = recorded(program);
197
+ return Kernel.run(run.program, { explore: "body" }).then((baseline) => {
198
+ throwIfFailed(baseline, {
199
+ seed: void 0,
200
+ decisions: baseline.decisions
201
+ }, run.recorder);
202
+ return seededRuns(program, seed, surveyOf(baseline));
203
+ });
204
+ };
205
+ const replayOrSeeded = (program, replay) => {
206
+ if (replay.path !== void 0) return replayRun(program, replay, replay.path);
207
+ return baselineThen(program, replay.seed);
208
+ };
209
+ /**
210
+ * Runs one case's program under the kernel: the direct order first, then the
211
+ * profile's seeded PCT schedules at the profile depth. A failure reports its
212
+ * seed and decision path, which `CONFORMANCE_REPLAY` reproduces.
213
+ */
214
+ const explore = (program) => readReplayValue().then((value) => {
215
+ if (value === void 0) return baselineThen(program, void 0);
216
+ return replayOrSeeded(program, replayOf(value));
217
+ });
218
+ //#endregion
6
219
  //#region src/Register.ts
7
220
  const selectDescribe = (mode) => ({
8
221
  skip: describe.skip,
@@ -22,39 +235,51 @@ const invokeDescribeImpl = (mode, suiteName, suiteOpts, fn) => Option.match(Opti
22
235
  * without options is registered through the two-argument collector call.
23
236
  */
24
237
  const invokeDescribe = dual(4, invokeDescribeImpl);
25
- const pickTester = (family, mode) => ({
26
- skip: family.skip,
27
- only: family.only,
28
- run: family
238
+ const pickLane = (lanes, mode) => ({
239
+ skip: lanes.skip,
240
+ only: lanes.only,
241
+ run: lanes.run
29
242
  })[mode];
243
+ /** The virtual-clock lane: the fork's own generator-body `it` and its two mode variants. */
244
+ const virtualLanes = (methodsIt) => ({
245
+ run: methodsIt,
246
+ skip: methodsIt.skip,
247
+ only: methodsIt.only
248
+ });
249
+ /** The live-clock lane: `it.live` and its two mode variants, which already carry `Scope`. */
250
+ const liveLanes = (methodsIt) => ({
251
+ run: methodsIt.live,
252
+ skip: methodsIt.live.skip,
253
+ only: methodsIt.live.only
254
+ });
30
255
  /**
31
- * The live-clock case runner observes wall-clock time; the test-clock runner
32
- * shares the suite's controlled clock.
256
+ * An explored case runs under the kernel's own clock, so it registers on the virtual lane; a
257
+ * live-declared case keeps the real clock and registers on `it.live`.
33
258
  */
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
259
+ const caseLanes = (methodsIt, live) => live === void 0 ? virtualLanes(methodsIt) : liveLanes(methodsIt);
260
+ const scopedBody = Effect.scoped;
261
+ /**
262
+ * An explored case has no wall-clock limit: every run is bounded in steps, and
263
+ * the kernel reports a hang (deadlock, runaway, or a wait it cannot observe)
264
+ * deterministically. A timer would only measure how busy the machine is.
265
+ */
266
+ const UNTIMED = { timeout: 0 };
267
+ /**
268
+ * One case's program under the kernel: the test's binding is re-provided onto it (the kernel
269
+ * drives it in its own run, so the check ledger and the running Vitest task are handed over), the
270
+ * run is scoped, and a failure reports its seed and decision path.
271
+ */
272
+ const exploredProgram = (program) => Effect.gen(function* () {
273
+ const bound = (yield* captureRunBinding).bind(program);
274
+ return yield* Effect.promise(() => bound.pipe(scopedBody, explore));
45
275
  });
46
- const VitestTaskRef = Context.Reference("@systemfsoftware/effect-spec-runtime/VitestTask", { defaultValue: () => null });
47
276
  /**
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.
277
+ * A live-declared case runs on the live clock as before; a case without a
278
+ * live declaration runs under the kernel, exploring the profile's schedules
279
+ * through the fork's Effect lane.
50
280
  */
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);
281
+ const selectCaseRunnerImpl = (methodsIt, mode, live) => pickLane(caseLanes(methodsIt, live), mode);
282
+ const selectCaseRunner = dual(3, selectCaseRunnerImpl);
58
283
  //#endregion
59
284
  //#region src/Suite.ts
60
285
  var Suite_exports = /* @__PURE__ */ __exportAll({
@@ -63,43 +288,68 @@ var Suite_exports = /* @__PURE__ */ __exportAll({
63
288
  openShared: () => openShared,
64
289
  openSharedCase: () => openSharedCase
65
290
  });
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));
291
+ const caseEffectOf = (body, env, live) => {
292
+ if (live !== void 0) return liveCase(body, env, live.reason);
293
+ return caseProgram(body, env);
294
+ };
295
+ /**
296
+ * One case's program: the callback's own `expect` builds the scenario Effect, and the case's
297
+ * layers build fresh around it — under the kernel's scheduled exploration, or on the live clock
298
+ * when the case declares a reason.
299
+ */
300
+ const caseProgramOf = (scenario, env, live, binding) => (expect) => {
301
+ const bound = binding.bind(scenario(expect));
302
+ return caseEffectOf(bound, env, live);
303
+ };
304
+ /**
305
+ * The fork's generator body for one case: it hands the callback's `expect` to the scenario, hands
306
+ * the running Vitest task to the step annotations, and runs the program the case declared — under
307
+ * the kernel's explored schedules, or on the live clock.
308
+ */
309
+ const caseBody = (scenario, env, live) => function* ({ expect }) {
310
+ const ctx = yield* VitestTestContext;
311
+ const binding = yield* captureRunBinding;
312
+ const program = provideTaskRef(caseProgramOf(scenario, env, live, binding)(expect), ctx);
313
+ if (live === void 0) {
314
+ yield* exploredProgram(program);
315
+ return;
316
+ }
317
+ yield* program;
318
+ };
319
+ const registerCase = (register, name, scenario, env, live) => {
320
+ if (live === void 0) {
321
+ register(name, caseBody(scenario, env, live), UNTIMED);
322
+ return;
323
+ }
324
+ register(name, caseBody(scenario, env, live));
72
325
  };
73
- const layeredRegister = (scopedIt, caseLayer) => (name, body, mode) => {
74
- selectLayeredRunner(scopedIt, mode)(name, (ctx) => provideTaskRef(body.pipe(Effect.provide(Layer.fresh(caseLayer))), ctx));
326
+ const registrarFor = (methodsIt, config, env) => (name, scenario, mode, caseLive) => {
327
+ const live = caseLive ?? config.live;
328
+ registerCase(selectCaseRunner(methodsIt, mode, live), name, scenario, env, live);
75
329
  };
76
330
  const openImpl = (bindings, config, use) => {
77
331
  invokeDescribe(config.describe, config.name, config.options, () => {
78
- use(unlayeredRegister(bindings.it, config, Layer.empty), bindings.it);
332
+ use(registrarFor(bindings.it, config, Layer.empty), bindings.it);
79
333
  });
80
334
  };
81
335
  const open = dual(3, openImpl);
82
336
  const openSharedImpl = (bindings, config, shared, use) => {
83
337
  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
- });
338
+ use(registrarFor(bindings.it, config, Layer.fresh(shared.layer)), bindings.it);
87
339
  });
88
340
  };
89
341
  const openShared = dual(4, openSharedImpl);
90
342
  const openCaseImpl = (bindings, config, caseLayer, use) => {
91
343
  invokeDescribe(config.describe, config.name, config.options, () => {
92
- use(unlayeredRegister(bindings.it, config, caseLayer), bindings.it);
344
+ use(registrarFor(bindings.it, config, Layer.fresh(caseLayer)), bindings.it);
93
345
  });
94
346
  };
95
347
  const openCase = dual(4, openCaseImpl);
96
348
  const openSharedCaseImpl = (bindings, config, shared, caseLayer, use) => {
97
349
  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
- });
350
+ use(registrarFor(bindings.it, config, Layer.fresh(caseLayer).pipe(Layer.provideMerge(shared.layer))), bindings.it);
101
351
  });
102
352
  };
103
353
  const openSharedCase = dual(5, openSharedCaseImpl);
104
354
  //#endregion
105
- export { Suite_exports as Suite, TaskRef_service_exports as TaskRef };
355
+ 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.1",
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.2.0"
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.2.0",
38
41
  "@systemfsoftware/tsconfig": "^2.0.1",
39
42
  "@systemfsoftware/tsdown-config": "^0.1.0",
43
+ "@systemfsoftware/vitest": "^0.2.0",
40
44
  "@systemfsoftware/vitest-config": "^0.1.0",
41
45
  "@types/node": "^26",
42
46
  "effect": "4.0.0-rc.117",
@@ -48,20 +52,23 @@
48
52
  "vitest": "^5"
49
53
  },
50
54
  "peerDependencies": {
51
- "@effect/vitest": "npm:@systemfsoftware/vitest@*",
55
+ "@systemfsoftware/vitest": "^0.2.0",
52
56
  "effect": "4.0.0-rc.117",
53
57
  "vitest": "^5"
54
58
  },
55
59
  "publishConfig": {
60
+ "access": "public",
56
61
  "provenance": true
57
62
  },
58
63
  "scripts": {
59
64
  "clean": "rimraf dist",
60
- "build": "tsdown -l warn",
65
+ "build": "tsdown -l warn && pnpm api:check",
61
66
  "typecheck": "tsc -b",
62
67
  "test": "vitest run",
63
68
  "test:types": "TSTYCHE_TYPESCRIPT_MODULE=tstyche-typescript tstyche",
64
69
  "lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
65
- "attw": "attw --pack ."
70
+ "attw": "attw --pack .",
71
+ "api:check": "api-extractor-quiet run",
72
+ "api:update": "api-extractor run --local"
66
73
  }
67
74
  }