@ftrdotdev/pi-tracker 0.7.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 +88 -9
- package/package.json +27 -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 +5 -5
- 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 +59 -17
- package/src/index.ts +63 -64
- 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 +128 -67
- package/src/presentation/ui.ts +68 -20
- package/src/presentation/vim-settings.test.ts +101 -0
- package/src/presentation/vim-settings.ts +59 -0
|
@@ -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<
|
|
@@ -119,10 +119,10 @@ export class SettleDecider extends Context.Service<
|
|
|
119
119
|
if (routed.verdict === "compact") {
|
|
120
120
|
return withRecord(SETTLE_DECISION.compact(resumePointer(head)));
|
|
121
121
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
// An observe-only row is reported through the decision record, not
|
|
123
|
+
// the console: Effect's default logger writes to stdout, which pi's
|
|
124
|
+
// TUI redirects to stderr, and the differential renderer never
|
|
125
|
+
// repaints those rows, so a log line would stick in the editor area.
|
|
126
126
|
const verdict = yield* gateway.verdict({
|
|
127
127
|
registry: input.registry,
|
|
128
128
|
enabled: values.enabled,
|
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
|
};
|