@ftrdotdev/pi-tracker 0.8.0 → 0.9.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 +369 -0
- package/README.md +5 -0
- package/package.json +20 -16
- package/src/compaction/candidate.test.ts +66 -125
- package/src/compaction/classifier.test.ts +22 -2
- package/src/compaction/classifier.ts +35 -22
- package/src/compaction/completion.test.ts +24 -16
- package/src/compaction/completion.ts +1 -1
- package/src/compaction/decision-record.test.ts +1 -1
- package/src/compaction/decision-record.ts +1 -1
- package/src/compaction/digest.test.ts +34 -34
- package/src/compaction/footprint.ts +2 -4
- package/src/compaction/settings.test.ts +5 -1
- package/src/compaction/settings.ts +1 -1
- package/src/compaction/settle.test.ts +50 -10
- package/src/compaction/settle.ts +1 -1
- package/src/core/deps.test.ts +128 -109
- package/src/core/deps.ts +3 -2
- package/src/core/domain.test.ts +99 -68
- package/src/core/domain.ts +16 -10
- package/src/core/persistence.test.ts +18 -19
- package/src/core/persistence.ts +4 -3
- package/src/core/store.test.ts +129 -167
- package/src/core/store.ts +77 -57
- package/src/harness-collection.test.ts +75 -0
- package/src/index.test.ts +35 -30
- package/src/index.ts +45 -66
- package/src/layers.test.ts +101 -0
- package/src/layers.ts +46 -0
- package/src/presentation/tool-metadata.test.ts +36 -38
- package/src/presentation/tool-metadata.ts +127 -130
- package/src/presentation/ui.test.ts +67 -67
- package/src/presentation/ui.ts +22 -19
- package/src/presentation/vim-settings.test.ts +3 -0
- package/src/presentation/vim-settings.ts +1 -1
|
@@ -106,7 +106,7 @@ export class SmartCompactionSettingsService extends Context.Service<
|
|
|
106
106
|
/** Never fails: every read, parse, or shape problem yields the defaults. */
|
|
107
107
|
readonly load: Effect.Effect<SmartCompactionSettings>;
|
|
108
108
|
}
|
|
109
|
-
>()("tracker/
|
|
109
|
+
>()("@ftrdotdev/pi-tracker/compaction/settings/SmartCompactionSettingsService") {
|
|
110
110
|
static make(
|
|
111
111
|
path: string,
|
|
112
112
|
): Layer.Layer<SmartCompactionSettingsService, never, FileSystem.FileSystem> {
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Each test is its own entry point: it builds a fresh layer for one scenario and
|
|
2
|
+
// runs its effects inside it, so providing there is the pattern the rule allows.
|
|
3
|
+
/* oxlint-disable effecttsgo/strict-effect-provide */
|
|
1
4
|
import { assert, it } from "@effect/vitest";
|
|
2
5
|
import { Effect, Layer } from "effect";
|
|
3
6
|
import type { ClassifierApi, ClassifierModel, ClassifierResult } from "@earendil-works/pi-ai";
|
|
@@ -5,7 +8,7 @@ import { NEEDS_CONTEXT_LABEL, NEEDS_NONE_LABEL } from "./classifier.ts";
|
|
|
5
8
|
import { ClassifierGateway, type ClassifierRegistry } from "./classifier.ts";
|
|
6
9
|
import type { CompactionCandidate } from "./candidate.ts";
|
|
7
10
|
import { CompletionObserver } from "./completion.ts";
|
|
8
|
-
import { FootprintRecorder } from "./footprint.ts";
|
|
11
|
+
import { FootprintRecorder, type ToolEvent } from "./footprint.ts";
|
|
9
12
|
import {
|
|
10
13
|
containsSymbol,
|
|
11
14
|
emptyFootprint,
|
|
@@ -90,7 +93,10 @@ const footprintLayer = (footprint: BatchFootprint): Layer.Layer<FootprintRecorde
|
|
|
90
93
|
Layer.succeed(
|
|
91
94
|
FootprintRecorder,
|
|
92
95
|
FootprintRecorder.of({
|
|
93
|
-
|
|
96
|
+
// Untraced: a test stub needs no span.
|
|
97
|
+
capture: Effect.fnUntraced(function* (_event: ToolEvent): Effect.fn.Return<void> {
|
|
98
|
+
yield* Effect.void;
|
|
99
|
+
}),
|
|
94
100
|
snapshot: Effect.succeed(footprint),
|
|
95
101
|
consume: Effect.succeed(footprint),
|
|
96
102
|
}),
|
|
@@ -104,7 +110,7 @@ const item = (spec: {
|
|
|
104
110
|
readonly refs?: TodoItem["refs"];
|
|
105
111
|
readonly produces?: TodoItem["produces"];
|
|
106
112
|
}): TodoItem =>
|
|
107
|
-
|
|
113
|
+
TodoItem.make({
|
|
108
114
|
id: spec.id,
|
|
109
115
|
title: spec.title,
|
|
110
116
|
description: spec.description ?? "",
|
|
@@ -114,16 +120,26 @@ const item = (spec: {
|
|
|
114
120
|
produces: [...(spec.produces ?? [])],
|
|
115
121
|
});
|
|
116
122
|
|
|
123
|
+
/** A copy of `item` with only `done` changed. Fields stay explicit so the class
|
|
124
|
+
* prototype survives; spreading the instance would drop it. */
|
|
125
|
+
const withDone = (item: TodoItem, done: boolean): TodoItem =>
|
|
126
|
+
TodoItem.make({
|
|
127
|
+
id: item.id,
|
|
128
|
+
title: item.title,
|
|
129
|
+
description: item.description,
|
|
130
|
+
refs: item.refs,
|
|
131
|
+
produces: item.produces,
|
|
132
|
+
deps: item.deps,
|
|
133
|
+
done,
|
|
134
|
+
});
|
|
135
|
+
|
|
117
136
|
const stateOf = (first: TodoItem, candidate: TodoItem, firstDone: boolean): TrackerState =>
|
|
118
|
-
|
|
137
|
+
TrackerState.make({
|
|
119
138
|
lists: [
|
|
120
|
-
|
|
139
|
+
TodoList.make({
|
|
121
140
|
id: 1,
|
|
122
141
|
name: "Work",
|
|
123
|
-
items: [
|
|
124
|
-
new TodoItem({ ...first, done: firstDone }),
|
|
125
|
-
new TodoItem({ ...candidate, done: false }),
|
|
126
|
-
],
|
|
142
|
+
items: [withDone(first, firstDone), withDone(candidate, false)],
|
|
127
143
|
nextItemId: 3,
|
|
128
144
|
}),
|
|
129
145
|
],
|
|
@@ -140,6 +156,7 @@ const decide = (input: {
|
|
|
140
156
|
readonly probe: FileProbe;
|
|
141
157
|
readonly spy: RegistrySpy;
|
|
142
158
|
readonly candidate: TodoItem;
|
|
159
|
+
readonly signal?: AbortSignal | undefined;
|
|
143
160
|
}): Effect.Effect<SettleDecision> => {
|
|
144
161
|
const first = item({
|
|
145
162
|
id: 1,
|
|
@@ -153,7 +170,11 @@ const decide = (input: {
|
|
|
153
170
|
const observer = yield* CompletionObserver;
|
|
154
171
|
yield* observer.record(before, after);
|
|
155
172
|
const decider = yield* SettleDecider;
|
|
156
|
-
return yield* decider.decide({
|
|
173
|
+
return yield* decider.decide({
|
|
174
|
+
registry: input.spy.registry,
|
|
175
|
+
outcome: "completed",
|
|
176
|
+
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
177
|
+
});
|
|
157
178
|
}).pipe(
|
|
158
179
|
Effect.provide(
|
|
159
180
|
SettleDecider.layer(input.probe).pipe(
|
|
@@ -218,6 +239,25 @@ it.effect("a candidate that names a batch output compacts", () =>
|
|
|
218
239
|
}),
|
|
219
240
|
);
|
|
220
241
|
|
|
242
|
+
it.effect("the classifier decides a lost reference while the run signal is live", () => {
|
|
243
|
+
// Constructed outside the Effect program so the run signal is a plain value.
|
|
244
|
+
const signal = new AbortController().signal;
|
|
245
|
+
return Effect.gen(function* () {
|
|
246
|
+
const spy = registrySpy(0.1);
|
|
247
|
+
const decision = yield* decide({
|
|
248
|
+
footprint: { ...emptyFootprint(), deleted: [{ path: "src/a.ts" }] },
|
|
249
|
+
probe: probeOf({}),
|
|
250
|
+
spy,
|
|
251
|
+
signal,
|
|
252
|
+
candidate: candidate({ refs: [{ kind: "path", path: "src/a.ts" }] }),
|
|
253
|
+
});
|
|
254
|
+
// A live signal is not an abort: the gateway must still answer, and the
|
|
255
|
+
// answer must reach the decider. Before the fix this path always kept.
|
|
256
|
+
assert.strictEqual(spy.calls(), 1);
|
|
257
|
+
assertCompacts(decision);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
221
261
|
// ---------------------------------------------------------------------------
|
|
222
262
|
// Observe-only rows keep the classifier in the loop
|
|
223
263
|
// ---------------------------------------------------------------------------
|
package/src/compaction/settle.ts
CHANGED
|
@@ -50,7 +50,7 @@ export class SettleDecider extends Context.Service<
|
|
|
50
50
|
readonly signal?: AbortSignal | undefined;
|
|
51
51
|
}) => Effect.Effect<SettleDecision>;
|
|
52
52
|
}
|
|
53
|
-
>()("tracker/SettleDecider") {
|
|
53
|
+
>()("@ftrdotdev/pi-tracker/compaction/settle/SettleDecider") {
|
|
54
54
|
static readonly layer = (
|
|
55
55
|
probe: FileProbe,
|
|
56
56
|
): Layer.Layer<
|
package/src/core/deps.test.ts
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
|
|
3
|
+
import {
|
|
4
|
+
acyclicListArbitrary,
|
|
5
|
+
cyclicListArbitrary,
|
|
6
|
+
graphListArbitrary,
|
|
7
|
+
refusedReferenceArbitrary,
|
|
8
|
+
referenceArbitrary,
|
|
9
|
+
unlinkedListArbitrary,
|
|
10
|
+
} from "../../test-support/generators.ts";
|
|
2
11
|
import { TodoItem, TodoList } from "./domain.ts";
|
|
3
12
|
import {
|
|
4
13
|
blockersOf,
|
|
5
14
|
cyclePath,
|
|
6
15
|
dependentsOf,
|
|
7
16
|
firstReadyIndex,
|
|
17
|
+
formatItemRef,
|
|
8
18
|
orderedItems,
|
|
9
19
|
parseItemRef,
|
|
10
20
|
readiness,
|
|
11
|
-
|
|
21
|
+
resolveRef,
|
|
12
22
|
} from "./deps.ts";
|
|
13
23
|
|
|
14
24
|
/**
|
|
@@ -21,18 +31,17 @@ const listWith = (
|
|
|
21
31
|
done: readonly number[] = [],
|
|
22
32
|
name = "Work",
|
|
23
33
|
): TodoList =>
|
|
24
|
-
|
|
34
|
+
TodoList.make({
|
|
25
35
|
id: 1,
|
|
26
36
|
name,
|
|
27
37
|
nextItemId: deps.length + 1,
|
|
28
|
-
items: deps.map(
|
|
29
|
-
(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}),
|
|
38
|
+
items: deps.map((itemDeps, index) =>
|
|
39
|
+
TodoItem.make({
|
|
40
|
+
id: index + 1,
|
|
41
|
+
title: `item ${index + 1}`,
|
|
42
|
+
done: done.includes(index),
|
|
43
|
+
deps: itemDeps,
|
|
44
|
+
}),
|
|
36
45
|
),
|
|
37
46
|
});
|
|
38
47
|
|
|
@@ -46,9 +55,26 @@ it("parseItemRef returns null for a malformed reference", () => {
|
|
|
46
55
|
}
|
|
47
56
|
});
|
|
48
57
|
|
|
49
|
-
it(
|
|
50
|
-
|
|
51
|
-
}
|
|
58
|
+
it.prop(
|
|
59
|
+
"an item reference round-trips through format and parse, whatever the list name",
|
|
60
|
+
{ reference: referenceArbitrary },
|
|
61
|
+
({ reference }) => {
|
|
62
|
+
assert.deepStrictEqual(parseItemRef(formatItemRef(reference.name, reference.id)), {
|
|
63
|
+
name: reference.name,
|
|
64
|
+
id: reference.id,
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
it.prop(
|
|
71
|
+
"parseItemRef refuses a reference whose id is not a positive integer",
|
|
72
|
+
{ reference: refusedReferenceArbitrary },
|
|
73
|
+
({ reference }) => {
|
|
74
|
+
assert.strictEqual(parseItemRef(`${reference.name}:${reference.idText}`), null);
|
|
75
|
+
},
|
|
76
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
77
|
+
);
|
|
52
78
|
|
|
53
79
|
it("cyclePath returns null for a candidate that keeps the graph acyclic", () => {
|
|
54
80
|
// Item 2 depends on item 1, so adding "item 3 depends on item 2" is fine.
|
|
@@ -107,26 +133,58 @@ it("cyclePath ignores a dependency naming another list", () => {
|
|
|
107
133
|
// Readiness (derived on read, never stored)
|
|
108
134
|
// --------------------------------------------------------------------------
|
|
109
135
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
117
|
-
assert.deepStrictEqual(
|
|
118
|
-
entries.map((entry) => entry.blockers),
|
|
119
|
-
[[], []],
|
|
120
|
-
);
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
it("a dependency blocks its dependent until it is done", () => {
|
|
124
|
-
const entries = readiness(listWith([[], ["Work:1"]]));
|
|
136
|
+
/** The dependency refs of one item whose target is absent or not done. */
|
|
137
|
+
const openDeps = (list: TodoList, index: number): readonly string[] =>
|
|
138
|
+
(list.items[index]?.deps ?? []).filter((ref) => {
|
|
139
|
+
const target = resolveRef(list, ref);
|
|
140
|
+
return target === undefined || !(list.items[target]?.done ?? false);
|
|
141
|
+
});
|
|
125
142
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
})
|
|
143
|
+
it.prop(
|
|
144
|
+
"readiness marks an item ready exactly when it is open and every dependency is done",
|
|
145
|
+
{ list: graphListArbitrary },
|
|
146
|
+
({ list }) => {
|
|
147
|
+
const entries = readiness(list);
|
|
148
|
+
for (const [index, item] of list.items.entries()) {
|
|
149
|
+
assert.strictEqual(entries[index]!.ready, !item.done && openDeps(list, index).length === 0);
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
153
|
+
);
|
|
154
|
+
|
|
155
|
+
it.prop(
|
|
156
|
+
"readiness reports exactly the open dependencies as blockers",
|
|
157
|
+
{ list: graphListArbitrary },
|
|
158
|
+
({ list }) => {
|
|
159
|
+
const entries = readiness(list);
|
|
160
|
+
for (const index of list.items.keys()) {
|
|
161
|
+
assert.deepStrictEqual(entries[index]!.blockers, openDeps(list, index));
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
it.prop(
|
|
168
|
+
"blockersOf reports nothing for a done item",
|
|
169
|
+
{ list: graphListArbitrary },
|
|
170
|
+
({ list }) => {
|
|
171
|
+
for (const [index, item] of list.items.entries()) {
|
|
172
|
+
if (item.done) assert.deepStrictEqual(blockersOf(list, index), []);
|
|
173
|
+
}
|
|
174
|
+
},
|
|
175
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
it.prop(
|
|
179
|
+
"firstReadyIndex is the first ready index, or undefined when nothing is ready",
|
|
180
|
+
{ list: graphListArbitrary },
|
|
181
|
+
({ list }) => {
|
|
182
|
+
const entries = readiness(list);
|
|
183
|
+
const expected = list.items.findIndex((_, index) => entries[index]!.ready);
|
|
184
|
+
assert.strictEqual(firstReadyIndex(list), expected === -1 ? undefined : expected);
|
|
185
|
+
},
|
|
186
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
187
|
+
);
|
|
130
188
|
|
|
131
189
|
it("a done item reports the dependencies that are still open", () => {
|
|
132
190
|
// The state a reopen creates: item 2 is done while its prerequisite is open.
|
|
@@ -143,56 +201,6 @@ it("a done item reports the dependencies that are still open", () => {
|
|
|
143
201
|
assert.deepStrictEqual(satisfied[1]?.blockers, []);
|
|
144
202
|
});
|
|
145
203
|
|
|
146
|
-
it("blockersOf reports nothing for a done item, so completion is not gated on it", () => {
|
|
147
|
-
// The completion gate reads `blockersOf`. A done item must not be refused a
|
|
148
|
-
// repeat done mark, so the gate view stays empty while the reading view
|
|
149
|
-
// (`unsatisfiedDeps`, which `readiness` uses) keeps the fact.
|
|
150
|
-
const list = listWith([[], ["Work:1"]], [1]);
|
|
151
|
-
|
|
152
|
-
assert.deepStrictEqual(blockersOf(list, 1), []);
|
|
153
|
-
assert.deepStrictEqual(unsatisfiedDeps(list, 1), ["Work:1"]);
|
|
154
|
-
assert.deepStrictEqual(unsatisfiedDeps(listWith([[], ["Work:1"]], []), 1), ["Work:1"]);
|
|
155
|
-
assert.deepStrictEqual(unsatisfiedDeps(listWith([[], ["Work:1"]], [0, 1]), 1), []);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("readiness follows a chain", () => {
|
|
159
|
-
// Item 3 depends on item 2, which depends on item 1.
|
|
160
|
-
const chain = listWith([[], ["Work:1"], ["Work:2"]]);
|
|
161
|
-
assert.deepStrictEqual(
|
|
162
|
-
readiness(chain).map((entry) => entry.ready),
|
|
163
|
-
[true, false, false],
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
// Only the middle link is unblocked by completing item 1.
|
|
167
|
-
const progressed = listWith([[], [], ["Work:2"]], [0]);
|
|
168
|
-
assert.deepStrictEqual(
|
|
169
|
-
readiness(progressed).map((entry) => entry.blockers),
|
|
170
|
-
[[], [], ["Work:2"]],
|
|
171
|
-
);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("a diamond dependency unblocks only when both branches are done", () => {
|
|
175
|
-
const branches = [[], [], ["Work:1", "Work:2"]];
|
|
176
|
-
|
|
177
|
-
assert.deepStrictEqual(readiness(listWith(branches))[2]?.blockers, ["Work:1", "Work:2"]);
|
|
178
|
-
assert.deepStrictEqual(readiness(listWith(branches, [0]))[2]?.blockers, ["Work:2"]);
|
|
179
|
-
|
|
180
|
-
const joined = readiness(listWith(branches, [0, 1]))[2];
|
|
181
|
-
assert.deepStrictEqual(joined?.blockers, []);
|
|
182
|
-
assert.strictEqual(joined?.ready, true);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it("firstReadyIndex returns the earliest ready item in list order", () => {
|
|
186
|
-
// Item 1 is done, item 2 is blocked by item 3, item 3 is ready.
|
|
187
|
-
assert.strictEqual(firstReadyIndex(listWith([[], ["Work:3"], []], [0])), 2);
|
|
188
|
-
// Item 1 is blocked by item 2, which is ready.
|
|
189
|
-
assert.strictEqual(firstReadyIndex(listWith([["Work:2"], []])), 1);
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("firstReadyIndex is undefined when nothing is ready", () => {
|
|
193
|
-
assert.strictEqual(firstReadyIndex(listWith([[], []], [0, 1])), undefined);
|
|
194
|
-
});
|
|
195
|
-
|
|
196
204
|
it("a dangling reference leaves its dependent blocked", () => {
|
|
197
205
|
const entry = readiness(listWith([[], ["Work:9"]]))[1];
|
|
198
206
|
|
|
@@ -217,25 +225,44 @@ it("dependentsOf lists the items that depend on a given item", () => {
|
|
|
217
225
|
const idsOf = (items: readonly { readonly id?: number }[]): number[] =>
|
|
218
226
|
items.map((item) => item.id ?? 0);
|
|
219
227
|
|
|
220
|
-
it(
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
228
|
+
it.prop(
|
|
229
|
+
"orderedItems is a permutation of the stored items that places every dependency first",
|
|
230
|
+
{ list: acyclicListArbitrary },
|
|
231
|
+
({ list }) => {
|
|
232
|
+
const ordered = orderedItems(list);
|
|
233
|
+
const compare = (a: number, b: number): number => a - b;
|
|
234
|
+
assert.deepStrictEqual(idsOf(ordered).toSorted(compare), idsOf(list.items).toSorted(compare));
|
|
235
|
+
const position = new Map(ordered.map((item, index) => [item.id, index]));
|
|
236
|
+
for (const item of ordered) {
|
|
237
|
+
for (const ref of item.deps ?? []) {
|
|
238
|
+
const dependency = parseItemRef(ref);
|
|
239
|
+
assert.notStrictEqual(dependency, null);
|
|
240
|
+
assert(position.get(dependency!.id)! < position.get(item.id)!);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
245
|
+
);
|
|
246
|
+
|
|
247
|
+
it.prop(
|
|
248
|
+
"orderedItems returns the stored order when no item declares a dependency",
|
|
249
|
+
{ list: unlinkedListArbitrary },
|
|
250
|
+
({ list }) => {
|
|
251
|
+
assert.deepStrictEqual(idsOf(orderedItems(list)), idsOf(list.items));
|
|
252
|
+
},
|
|
253
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
it.prop(
|
|
257
|
+
"orderedItems keeps every item when the graph has a cycle",
|
|
258
|
+
{ list: cyclicListArbitrary },
|
|
259
|
+
({ list }) => {
|
|
260
|
+
const ordered = orderedItems(list);
|
|
261
|
+
assert.strictEqual(ordered.length, list.items.length);
|
|
262
|
+
assert.deepStrictEqual(idsOf(ordered), idsOf(list.items));
|
|
263
|
+
},
|
|
264
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
265
|
+
);
|
|
239
266
|
|
|
240
267
|
it("orderedItems keeps the stored order among items that are ready together", () => {
|
|
241
268
|
// Item 2 waits for item 1. Item 3 is ready from the start, so it keeps its
|
|
@@ -244,11 +271,3 @@ it("orderedItems keeps the stored order among items that are ready together", ()
|
|
|
244
271
|
|
|
245
272
|
assert.deepStrictEqual(idsOf(orderedItems(list)), [1, 3, 2]);
|
|
246
273
|
});
|
|
247
|
-
|
|
248
|
-
it("orderedItems keeps every item when the graph has a cycle", () => {
|
|
249
|
-
// Only a hand-edited snapshot can produce a cycle; rendering must not throw
|
|
250
|
-
// or drop items, so the stored order stands in.
|
|
251
|
-
const list = listWith([["Work:2"], ["Work:1"]]);
|
|
252
|
-
|
|
253
|
-
assert.deepStrictEqual(idsOf(orderedItems(list)), [1, 2]);
|
|
254
|
-
});
|
package/src/core/deps.ts
CHANGED
|
@@ -178,7 +178,7 @@ export const unsatisfiedDeps = (list: DependencyList, index: number): readonly s
|
|
|
178
178
|
* fact for a done row.
|
|
179
179
|
*/
|
|
180
180
|
export const blockersOf = (list: DependencyList, index: number): readonly string[] =>
|
|
181
|
-
list.items[index]?.done
|
|
181
|
+
(list.items[index]?.done ?? false) ? [] : unsatisfiedDeps(list, index);
|
|
182
182
|
|
|
183
183
|
/** Derived readiness of one item. `ready` means "open and unblocked". */
|
|
184
184
|
export interface ItemReadiness {
|
|
@@ -246,5 +246,6 @@ export const orderedItems = <T extends DependencyItem>(
|
|
|
246
246
|
});
|
|
247
247
|
});
|
|
248
248
|
if (!Graph.isAcyclic(graph)) return list.items;
|
|
249
|
-
|
|
249
|
+
const order = Graph.topo(graph);
|
|
250
|
+
return [...Graph.indices(order)].map((index) => list.items[index]!);
|
|
250
251
|
};
|
package/src/core/domain.test.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
|
|
2
3
|
import { Effect, Option, Result } from "effect";
|
|
4
|
+
import { migrationStateArbitrary, trackerStateArbitrary } from "../../test-support/generators.ts";
|
|
3
5
|
import {
|
|
4
6
|
decodeStateEffect,
|
|
5
7
|
emptyState,
|
|
@@ -23,22 +25,22 @@ const decodeOrThrow = (snapshot: unknown): TrackerState =>
|
|
|
23
25
|
|
|
24
26
|
/** A realistic two-list state used by several tests. */
|
|
25
27
|
const sampleState = (): TrackerState =>
|
|
26
|
-
|
|
28
|
+
TrackerState.make({
|
|
27
29
|
lists: [
|
|
28
|
-
|
|
30
|
+
TodoList.make({
|
|
29
31
|
id: 1,
|
|
30
32
|
name: "Work",
|
|
31
33
|
nextItemId: 3,
|
|
32
34
|
items: [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
TodoItem.make({ id: 1, title: "write plan", done: true }),
|
|
36
|
+
TodoItem.make({ id: 2, title: "implement tracker", done: false }),
|
|
35
37
|
],
|
|
36
38
|
}),
|
|
37
|
-
|
|
39
|
+
TodoList.make({
|
|
38
40
|
id: 2,
|
|
39
41
|
name: "Home",
|
|
40
42
|
nextItemId: 2,
|
|
41
|
-
items: [
|
|
43
|
+
items: [TodoItem.make({ id: 1, title: "water plants", done: false })],
|
|
42
44
|
}),
|
|
43
45
|
],
|
|
44
46
|
activeListId: 1,
|
|
@@ -53,48 +55,26 @@ it("emptyState produces the canonical empty snapshot", () => {
|
|
|
53
55
|
});
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
it(
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
assert.strictEqual(decoded.nextListId, 3);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("item ids and deps round-trip", () => {
|
|
70
|
-
const state = new TrackerState({
|
|
71
|
-
lists: [
|
|
72
|
-
new TodoList({
|
|
73
|
-
id: 1,
|
|
74
|
-
name: "Work",
|
|
75
|
-
nextItemId: 4,
|
|
76
|
-
items: [
|
|
77
|
-
new TodoItem({ id: 1, title: "a", done: true }),
|
|
78
|
-
new TodoItem({ id: 3, title: "b", done: false, deps: ["Work:1"] }),
|
|
79
|
-
],
|
|
80
|
-
}),
|
|
81
|
-
],
|
|
82
|
-
activeListId: 1,
|
|
83
|
-
nextListId: 2,
|
|
84
|
-
});
|
|
58
|
+
it.prop(
|
|
59
|
+
"any tracker state round-trips through encode and decode",
|
|
60
|
+
{ state: trackerStateArbitrary },
|
|
61
|
+
({ state }) => {
|
|
62
|
+
// Compare encoded forms: decoding applies the schema's defaults, so the
|
|
63
|
+
// decoded value diffs from the fixture on those fields.
|
|
64
|
+
assert.deepStrictEqual(encodeState(decodeOrThrow(encodeState(state))), encodeState(state));
|
|
65
|
+
},
|
|
66
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
67
|
+
);
|
|
85
68
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
);
|
|
96
|
-
assert.strictEqual(decoded.lists[0]?.nextItemId, 4);
|
|
97
|
-
});
|
|
69
|
+
it.prop(
|
|
70
|
+
"an encoded tracker snapshot is plain JSON",
|
|
71
|
+
{ state: trackerStateArbitrary },
|
|
72
|
+
({ state }) => {
|
|
73
|
+
const encoded = encodeState(state);
|
|
74
|
+
assert.deepStrictEqual(JSON.parse(JSON.stringify(encoded)), encoded);
|
|
75
|
+
},
|
|
76
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
77
|
+
);
|
|
98
78
|
|
|
99
79
|
it("encoded snapshots carry item ids, deps, and the list counter", () => {
|
|
100
80
|
const encoded = encodeState(sampleState());
|
|
@@ -119,15 +99,9 @@ it("decoded values are real class instances", () => {
|
|
|
119
99
|
it("constructors validate their input", () => {
|
|
120
100
|
// Invalid types / missing fields throw at construction time. (The invalid
|
|
121
101
|
// inputs are cast because the constructor signature is already typed.)
|
|
122
|
-
assert.throws(() =>
|
|
123
|
-
assert.throws(() =>
|
|
124
|
-
assert.throws(() =>
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("encoded snapshots are JSON-serializable", () => {
|
|
128
|
-
const state = sampleState();
|
|
129
|
-
const encoded = encodeState(state);
|
|
130
|
-
assert.deepStrictEqual(JSON.parse(JSON.stringify(encoded)), encoded);
|
|
102
|
+
assert.throws(() => TodoItem.make({ title: 42, done: false } as never));
|
|
103
|
+
assert.throws(() => TodoItem.make({ title: "x" } as never));
|
|
104
|
+
assert.throws(() => TrackerState.make({} as never));
|
|
131
105
|
});
|
|
132
106
|
|
|
133
107
|
it("activeListId: null round-trips as null (not undefined)", () => {
|
|
@@ -149,9 +123,9 @@ it("unknown extra keys are ignored (forward compatibility)", () => {
|
|
|
149
123
|
});
|
|
150
124
|
|
|
151
125
|
it("rejects a snapshot with the wrong field type", () => {
|
|
152
|
-
const result = Effect.
|
|
153
|
-
|
|
154
|
-
const failure =
|
|
126
|
+
const result = Effect.result(decodeStateEffect({ lists: 42 })).pipe(Effect.runSync);
|
|
127
|
+
if (!Result.isFailure(result)) assert.fail("expected a failure");
|
|
128
|
+
const failure = Result.getFailure(result).pipe(Option.getOrThrow);
|
|
155
129
|
assert.strictEqual(failure._tag, "SchemaError");
|
|
156
130
|
assert.match(failure.message, /lists/i);
|
|
157
131
|
});
|
|
@@ -162,8 +136,8 @@ it("rejects a snapshot with an invalid item field", () => {
|
|
|
162
136
|
activeListId: null,
|
|
163
137
|
nextListId: 2,
|
|
164
138
|
};
|
|
165
|
-
const result = Effect.
|
|
166
|
-
|
|
139
|
+
const result = Effect.result(decodeStateEffect(bad)).pipe(Effect.runSync);
|
|
140
|
+
if (!Result.isFailure(result)) assert.fail("expected a failure");
|
|
167
141
|
});
|
|
168
142
|
|
|
169
143
|
it("drops a legacy string item id so old sessions stay loadable", () => {
|
|
@@ -177,7 +151,7 @@ it("drops a legacy string item id so old sessions stay loadable", () => {
|
|
|
177
151
|
nextItemId: 9,
|
|
178
152
|
};
|
|
179
153
|
const decoded = decodeOrThrow(legacy);
|
|
180
|
-
assert.deepStrictEqual(decoded.lists[0]?.items, [
|
|
154
|
+
assert.deepStrictEqual(decoded.lists[0]?.items, [TodoItem.make({ title: "x", done: false })]);
|
|
181
155
|
});
|
|
182
156
|
|
|
183
157
|
it("splits a legacy text item into a title and a description", () => {
|
|
@@ -218,18 +192,75 @@ it("enforces Int list ids (fractional ids are rejected)", () => {
|
|
|
218
192
|
activeListId: null,
|
|
219
193
|
nextListId: 2,
|
|
220
194
|
};
|
|
221
|
-
const result = Effect.
|
|
222
|
-
|
|
195
|
+
const result = Effect.result(decodeStateEffect(bad)).pipe(Effect.runSync);
|
|
196
|
+
if (!Result.isFailure(result)) assert.fail("expected a failure");
|
|
223
197
|
});
|
|
224
198
|
|
|
225
199
|
it("rejects a snapshot missing required fields", () => {
|
|
226
|
-
const result = Effect.
|
|
227
|
-
|
|
200
|
+
const result = Effect.result(decodeStateEffect({ lists: [] })).pipe(Effect.runSync);
|
|
201
|
+
if (!Result.isFailure(result)) assert.fail("expected a failure");
|
|
228
202
|
});
|
|
229
203
|
|
|
230
204
|
it("rejects non-object input", () => {
|
|
231
205
|
for (const bad of ["not json", 42, null, undefined, [1, 2]]) {
|
|
232
|
-
const result = Effect.
|
|
233
|
-
|
|
206
|
+
const result = Effect.result(decodeStateEffect(bad)).pipe(Effect.runSync);
|
|
207
|
+
if (!Result.isFailure(result)) assert.fail(`expected ${JSON.stringify(bad)} to fail`);
|
|
234
208
|
}
|
|
235
209
|
});
|
|
210
|
+
|
|
211
|
+
it.prop(
|
|
212
|
+
"migration gives every item a positive id",
|
|
213
|
+
{ state: migrationStateArbitrary },
|
|
214
|
+
({ state }) => {
|
|
215
|
+
for (const list of migrateState(state).lists) {
|
|
216
|
+
assert(list.items.every((item) => item.id >= 1));
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
it.prop(
|
|
223
|
+
"migration leaves each list counter above the highest item id",
|
|
224
|
+
{ state: migrationStateArbitrary },
|
|
225
|
+
({ state }) => {
|
|
226
|
+
for (const list of migrateState(state).lists) {
|
|
227
|
+
assert(list.nextItemId > Math.max(0, ...list.items.map((item) => item.id)));
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
it.prop(
|
|
234
|
+
"migration is idempotent",
|
|
235
|
+
{ state: migrationStateArbitrary },
|
|
236
|
+
({ state }) => {
|
|
237
|
+
assert.deepStrictEqual(
|
|
238
|
+
encodeState(migrateState(migrateState(state))),
|
|
239
|
+
encodeState(migrateState(state)),
|
|
240
|
+
);
|
|
241
|
+
},
|
|
242
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
it.prop(
|
|
246
|
+
"migration preserves titles, completion flags, descriptions, references and dependencies",
|
|
247
|
+
{ state: migrationStateArbitrary },
|
|
248
|
+
({ state }) => {
|
|
249
|
+
const migrated = migrateState(state);
|
|
250
|
+
assert.strictEqual(migrated.lists.length, state.lists.length);
|
|
251
|
+
for (const [listIndex, list] of state.lists.entries()) {
|
|
252
|
+
const after = migrated.lists[listIndex]!;
|
|
253
|
+
assert.strictEqual(after.items.length, list.items.length);
|
|
254
|
+
for (const [position, item] of list.items.entries()) {
|
|
255
|
+
const kept = after.items[position]!;
|
|
256
|
+
assert.strictEqual(kept.title, item.title);
|
|
257
|
+
assert.strictEqual(kept.done, item.done);
|
|
258
|
+
assert.strictEqual(kept.description, item.description);
|
|
259
|
+
assert.deepStrictEqual(kept.refs, item.refs);
|
|
260
|
+
assert.deepStrictEqual(kept.produces, item.produces);
|
|
261
|
+
assert.deepStrictEqual(kept.deps, item.deps);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
266
|
+
);
|