@systemfsoftware/effect-spec-runtime 0.3.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,15 @@
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
+
3
13
  ## 0.3.0
4
14
 
5
15
  ### Minor Changes
package/dist/index.mjs CHANGED
@@ -1,10 +1,23 @@
1
1
  import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
2
2
  import { Kernel } from "@systemfsoftware/effect-sim-kernel";
3
- import { Cause, Config, Context, Effect, Exit, Layer, Match, Option } from "effect";
3
+ import { createSpanRecorder, providedWorkspaceRoot, testIdentityOf, throwFailureRecord } from "@systemfsoftware/vitest/failure";
4
+ import { Cause, Config, Context, Effect, Exit, Layer, Match, Option, Schema } from "effect";
4
5
  import { dual } from "effect/Function";
5
6
  import { VitestTestContext, vitestTestContextKey } from "@systemfsoftware/vitest";
6
7
  import { captureRunBinding } from "@systemfsoftware/vitest/integration";
7
8
  import { describe } from "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
8
21
  //#region src/TaskRef.service.ts
9
22
  var TaskRef_service_exports = /* @__PURE__ */ __exportAll({
10
23
  RawVitestTaskRef: () => RawVitestTaskRef,
@@ -82,36 +95,41 @@ const announcedCase = (body, env, reason) => Effect.gen(function* () {
82
95
  * provides the case scope.
83
96
  */
84
97
  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
98
  const describeSuspended = (fiber) => {
93
99
  const first = fiber.frames[0];
94
100
  if (first === void 0) return `fiber ${fiber.id}`;
95
101
  return `fiber ${fiber.id} at ${first}`;
96
102
  };
97
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);
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;
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
+ };
103
111
  };
104
- const throwKernelFailure = (failure, schedule) => {
105
- throw new Error(scheduleReport(schedule, describeKernelFailure(failure)));
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
106
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);
107
128
  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);
129
+ const throwIfExitFailed = (observed, schedule, recorder) => {
130
+ if (Exit.isFailure(observed.exit)) throwExitFailure(observed.exit, schedule, recorder);
114
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)));
115
133
  const surveyOf = (baseline) => ({
116
134
  fibers: new Set(baseline.steps.map((step) => step.fiberId)).size,
117
135
  steps: baseline.steps.length
@@ -143,19 +161,23 @@ const replayOf = (value) => {
143
161
  return replay;
144
162
  };
145
163
  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
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);
153
174
  });
154
- });
175
+ };
155
176
  const runSeeds = (program, seeds, at, steps) => {
156
177
  const seed = seeds[at];
157
178
  if (seed === void 0) return Promise.resolve();
158
- return Kernel.run(program, {
179
+ const run = recorded(program);
180
+ return Kernel.run(run.program, {
159
181
  explore: "body",
160
182
  choose: Kernel.pick({
161
183
  seed,
@@ -165,20 +187,23 @@ const runSeeds = (program, seeds, at, steps) => {
165
187
  throwIfFailed(observed, {
166
188
  seed,
167
189
  decisions: observed.decisions
168
- });
190
+ }, run.recorder);
169
191
  return runSeeds(program, seeds, at + 1, steps);
170
192
  });
171
193
  };
172
194
  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
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));
177
203
  });
178
- return seededRuns(program, seed, surveyOf(baseline));
179
- });
204
+ };
180
205
  const replayOrSeeded = (program, replay) => {
181
- if (replay.path !== void 0) return replayRun(program, replay.path);
206
+ if (replay.path !== void 0) return replayRun(program, replay, replay.path);
182
207
  return baselineThen(program, replay.seed);
183
208
  };
184
209
  /**
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.3.0",
4
+ "version": "0.3.1",
5
5
  "author": "Ryan Lee <drdgvhbh@gmail.com>",
6
6
  "repository": {
7
7
  "type": "git",
@@ -32,15 +32,15 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@systemfsoftware/effect-sim-kernel": "^0.1.1"
35
+ "@systemfsoftware/effect-sim-kernel": "^0.2.0"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@microsoft/api-extractor": "^7.59.1",
39
39
  "@systemfsoftware/arethetypeswrong-cli": "^4.2.0",
40
- "@systemfsoftware/oxlint-config-recommended": "^3.1.0",
40
+ "@systemfsoftware/oxlint-config-recommended": "^3.2.0",
41
41
  "@systemfsoftware/tsconfig": "^2.0.1",
42
42
  "@systemfsoftware/tsdown-config": "^0.1.0",
43
- "@systemfsoftware/vitest": "^0.1.0",
43
+ "@systemfsoftware/vitest": "^0.2.0",
44
44
  "@systemfsoftware/vitest-config": "^0.1.0",
45
45
  "@types/node": "^26",
46
46
  "effect": "4.0.0-rc.117",
@@ -52,11 +52,12 @@
52
52
  "vitest": "^5"
53
53
  },
54
54
  "peerDependencies": {
55
- "@systemfsoftware/vitest": "^0.1.0",
55
+ "@systemfsoftware/vitest": "^0.2.0",
56
56
  "effect": "4.0.0-rc.117",
57
57
  "vitest": "^5"
58
58
  },
59
59
  "publishConfig": {
60
+ "access": "public",
60
61
  "provenance": true
61
62
  },
62
63
  "scripts": {