@systemfsoftware/effect-spec-runtime 0.3.0 → 0.3.2
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 +17 -0
- package/dist/index.mjs +63 -58
- package/package.json +14 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @systemfsoftware/effect-spec-runtime
|
|
2
2
|
|
|
3
|
+
## 0.3.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- @systemfsoftware/vitest@0.3.0
|
|
9
|
+
|
|
10
|
+
## 0.3.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 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.
|
|
15
|
+
|
|
16
|
+
- Updated dependencies:
|
|
17
|
+
- @systemfsoftware/effect-sim-kernel@0.2.0
|
|
18
|
+
- @systemfsoftware/vitest@0.2.0
|
|
19
|
+
|
|
3
20
|
## 0.3.0
|
|
4
21
|
|
|
5
22
|
### 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 {
|
|
3
|
+
import { createSpanRecorder, providedWorkspaceRoot, replayOfText, 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
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
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
|
|
@@ -125,37 +143,24 @@ const seedsToRun = (seed, budget) => {
|
|
|
125
143
|
if (seed === void 0) return seedList(budget);
|
|
126
144
|
return [seed];
|
|
127
145
|
};
|
|
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
146
|
const readReplayValue = () => Effect.runPromise(Effect.map(Config.option(Config.String("CONFORMANCE_REPLAY")), Option.getOrUndefined));
|
|
146
|
-
const replayRun = (program, path) =>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
const replayRun = (program, replay, path) => {
|
|
148
|
+
const run = recorded(program);
|
|
149
|
+
return Kernel.run(run.program, {
|
|
150
|
+
explore: "body",
|
|
151
|
+
path
|
|
152
|
+
}).then((observed) => {
|
|
153
|
+
throwIfFailed(observed, {
|
|
154
|
+
seed: replay.seed,
|
|
155
|
+
decisions: path
|
|
156
|
+
}, run.recorder);
|
|
153
157
|
});
|
|
154
|
-
}
|
|
158
|
+
};
|
|
155
159
|
const runSeeds = (program, seeds, at, steps) => {
|
|
156
160
|
const seed = seeds[at];
|
|
157
161
|
if (seed === void 0) return Promise.resolve();
|
|
158
|
-
|
|
162
|
+
const run = recorded(program);
|
|
163
|
+
return Kernel.run(run.program, {
|
|
159
164
|
explore: "body",
|
|
160
165
|
choose: Kernel.pick({
|
|
161
166
|
seed,
|
|
@@ -165,22 +170,22 @@ const runSeeds = (program, seeds, at, steps) => {
|
|
|
165
170
|
throwIfFailed(observed, {
|
|
166
171
|
seed,
|
|
167
172
|
decisions: observed.decisions
|
|
168
|
-
});
|
|
173
|
+
}, run.recorder);
|
|
169
174
|
return runSeeds(program, seeds, at + 1, steps);
|
|
170
175
|
});
|
|
171
176
|
};
|
|
172
177
|
const seededRuns = (program, seed, survey) => budgetOf(survey).then((budget) => runSeeds(program, seedsToRun(seed, budget), 0, survey.steps));
|
|
173
|
-
const baselineThen = (program, seed) =>
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
178
|
+
const baselineThen = (program, seed) => {
|
|
179
|
+
const run = recorded(program);
|
|
180
|
+
return Kernel.run(run.program, { explore: "body" }).then((baseline) => {
|
|
181
|
+
throwIfFailed(baseline, {
|
|
182
|
+
seed: void 0,
|
|
183
|
+
decisions: baseline.decisions
|
|
184
|
+
}, run.recorder);
|
|
185
|
+
return seededRuns(program, seed, surveyOf(baseline));
|
|
177
186
|
});
|
|
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
187
|
};
|
|
188
|
+
const replayOrSeeded = (program, replay) => replay.path.length > 0 ? replayRun(program, replay, replay.path) : baselineThen(program, replay.seed);
|
|
184
189
|
/**
|
|
185
190
|
* Runs one case's program under the kernel: the direct order first, then the
|
|
186
191
|
* profile's seeded PCT schedules at the profile depth. A failure reports its
|
|
@@ -188,7 +193,7 @@ const replayOrSeeded = (program, replay) => {
|
|
|
188
193
|
*/
|
|
189
194
|
const explore = (program) => readReplayValue().then((value) => {
|
|
190
195
|
if (value === void 0) return baselineThen(program, void 0);
|
|
191
|
-
return replayOrSeeded(program,
|
|
196
|
+
return replayOrSeeded(program, replayOfText(value));
|
|
192
197
|
});
|
|
193
198
|
//#endregion
|
|
194
199
|
//#region src/Register.ts
|
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.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"author": "Ryan Lee <drdgvhbh@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,15 +32,22 @@
|
|
|
32
32
|
"dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@systemfsoftware/effect-sim-kernel": "^0.
|
|
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.
|
|
40
|
+
"@systemfsoftware/oxlint-config-recommended": "^3.3.0",
|
|
41
|
+
"@systemfsoftware/stryker-config": "^0.1.0",
|
|
42
|
+
"@systemfsoftware/stryker-ignorer-effect-schema-declarations": "latest",
|
|
43
|
+
"@systemfsoftware/stryker-ignorer-in-source-vitest-block": "latest",
|
|
44
|
+
"@systemfsoftware/stryker-js": "latest",
|
|
45
|
+
"@systemfsoftware/stryker-js-typescript-checker": "latest",
|
|
46
|
+
"@systemfsoftware/stryker-js-vitest-runner": "latest",
|
|
47
|
+
"@systemfsoftware/stryker-test-contribution": "latest",
|
|
41
48
|
"@systemfsoftware/tsconfig": "^2.0.1",
|
|
42
49
|
"@systemfsoftware/tsdown-config": "^0.1.0",
|
|
43
|
-
"@systemfsoftware/vitest": "^0.
|
|
50
|
+
"@systemfsoftware/vitest": "^0.3.0",
|
|
44
51
|
"@systemfsoftware/vitest-config": "^0.1.0",
|
|
45
52
|
"@types/node": "^26",
|
|
46
53
|
"effect": "4.0.0-rc.117",
|
|
@@ -52,11 +59,12 @@
|
|
|
52
59
|
"vitest": "^5"
|
|
53
60
|
},
|
|
54
61
|
"peerDependencies": {
|
|
55
|
-
"@systemfsoftware/vitest": "^0.
|
|
62
|
+
"@systemfsoftware/vitest": "^0.3.0",
|
|
56
63
|
"effect": "4.0.0-rc.117",
|
|
57
64
|
"vitest": "^5"
|
|
58
65
|
},
|
|
59
66
|
"publishConfig": {
|
|
67
|
+
"access": "public",
|
|
60
68
|
"provenance": true
|
|
61
69
|
},
|
|
62
70
|
"scripts": {
|
|
@@ -64,6 +72,7 @@
|
|
|
64
72
|
"build": "tsdown -l warn && pnpm api:check",
|
|
65
73
|
"typecheck": "tsc -b",
|
|
66
74
|
"test": "vitest run",
|
|
75
|
+
"mutation": "stryker run",
|
|
67
76
|
"test:types": "TSTYCHE_TYPESCRIPT_MODULE=tstyche-typescript tstyche",
|
|
68
77
|
"lint": "f=${OXLINT_FORMAT:-${AGENT:+agent}}; oxlint . --format=${f:-default}",
|
|
69
78
|
"attw": "attw --pack .",
|