@ftrdotdev/pi-tracker 0.3.0 → 0.5.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/README.md +110 -37
- package/package.json +2 -2
- package/src/deps.test.ts +254 -0
- package/src/deps.ts +250 -0
- package/src/domain.test.ts +51 -6
- package/src/domain.ts +159 -13
- package/src/index.test.ts +358 -0
- package/src/index.ts +225 -75
- package/src/persistence.test.ts +105 -6
- package/src/persistence.ts +5 -3
- package/src/store.test.ts +559 -22
- package/src/store.ts +326 -132
- package/src/tool-metadata.test.ts +167 -9
- package/src/tool-metadata.ts +161 -36
- package/src/ui.test.ts +263 -0
- package/src/ui.ts +172 -15
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ pi-tracker is an extension for Pi. It manages todolists in your session.
|
|
|
8
8
|
- Add, update, and remove items in a todolist.
|
|
9
9
|
- Mark an item as complete or incomplete.
|
|
10
10
|
- Change the task text of an item.
|
|
11
|
+
- Declare dependencies between items, so work happens in order.
|
|
11
12
|
- Persist todolists with the session.
|
|
12
13
|
- Show the active todolist in a widget above the editor.
|
|
13
14
|
|
|
@@ -25,33 +26,32 @@ The snapshot does not enter the LLM context.
|
|
|
25
26
|
Ask Pi to manage your todolists. Pi calls the `tracker` tool. The tool
|
|
26
27
|
supports these actions:
|
|
27
28
|
|
|
28
|
-
| Action | Purpose | Parameters
|
|
29
|
-
| ------------- | ----------------------------------------- |
|
|
30
|
-
| `list` | Show all lists and items | —
|
|
31
|
-
| `create_list` | Create a list (becomes active by default) | `name`, `initial_items?`, `activate?`
|
|
32
|
-
| `delete_list` | Delete a list | `list_id`
|
|
33
|
-
| `set_active` | Set or clear the active list | `list_id` (optional)
|
|
34
|
-
| `add_item` | Add one or more items | `list_id`, `text` (string or array
|
|
35
|
-
| `update_item` | Update one or more items | `item_id
|
|
36
|
-
| `remove_item` | Remove an item | `item_id`
|
|
37
|
-
|
|
38
|
-
`create_list` accepts `initial_items`
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
current active list.
|
|
29
|
+
| Action | Purpose | Parameters |
|
|
30
|
+
| ------------- | ----------------------------------------- | ----------------------------------------------------------- |
|
|
31
|
+
| `list` | Show all lists and items | — |
|
|
32
|
+
| `create_list` | Create a list (becomes active by default) | `name`, `initial_items?`, `activate?` |
|
|
33
|
+
| `delete_list` | Delete a list | `list_id` |
|
|
34
|
+
| `set_active` | Set or clear the active list | `list_id` (optional) |
|
|
35
|
+
| `add_item` | Add one or more items | `list_id`, `text` (string, item object, or array) |
|
|
36
|
+
| `update_item` | Update one or more items | `item_id` + `text?`/`done?`/`deps?`, or `list_id` + `items` |
|
|
37
|
+
| `remove_item` | Remove an item | `item_id` |
|
|
38
|
+
|
|
39
|
+
`create_list` accepts `initial_items` to create the list with its first
|
|
40
|
+
items in one call, so the list and its items are created atomically. Each
|
|
41
|
+
item is either a text string or an object `{text, deps?}`. `add_item`
|
|
42
|
+
accepts the same shapes, plus an array of them, to add several items in one
|
|
43
|
+
call.
|
|
44
|
+
|
|
45
|
+
Item ids are `listName:id`, as the `list` action shows them (e.g. `Work:2`).
|
|
46
|
+
An id is permanent: it is stored on the item, it is unique within its list,
|
|
47
|
+
and it is never reused. Removing an item leaves a gap in the numbering
|
|
48
|
+
instead of shifting the items after it, so a reference you already hold stays
|
|
49
|
+
valid. `update_item` accepts the scalar form (`item_id` with optional
|
|
50
|
+
`text`/`done`/`deps`) or a per-list batched form: `list_id` plus an `items`
|
|
51
|
+
array (`[{item_id, text?, done?, deps?}, ...]`), mirroring `add_item`'s
|
|
52
|
+
`list_id + text[]` shape, so one batch stays within a single list. Creating a
|
|
53
|
+
list makes it the active list (the widget switches to it); pass
|
|
54
|
+
`activate: false` to keep the current active list.
|
|
55
55
|
|
|
56
56
|
The tool validates every call and returns an error that names exactly what to
|
|
57
57
|
fix: each action accepts only its own parameters, required fields are
|
|
@@ -69,11 +69,55 @@ Example prompt:
|
|
|
69
69
|
Call `set_active` without `list_id` to deselect. The widget hides when no
|
|
70
70
|
list is active.
|
|
71
71
|
|
|
72
|
+
### Dependencies and readiness
|
|
73
|
+
|
|
74
|
+
An item can wait for other items. Pass `deps` on the item object when you
|
|
75
|
+
create it, or through `update_item`, as a list of `listName:id` references to
|
|
76
|
+
items in the same list. `deps` replaces the whole dependency set, so pass `[]`
|
|
77
|
+
to clear it. The result names the set before and after whenever the two
|
|
78
|
+
differ, so a dependency the call dropped does not disappear silently.
|
|
79
|
+
|
|
80
|
+
Dependencies must form a DAG. A dependency must exist, it must be in the same
|
|
81
|
+
list, and it must not close a cycle. A call that would close one is rejected,
|
|
82
|
+
and the error names the cycle path (e.g. `Work:1 → Work:2 → Work:1`).
|
|
83
|
+
|
|
84
|
+
Two rules gate mutations:
|
|
85
|
+
|
|
86
|
+
- You can only complete an item after every dependency is done. Completing a
|
|
87
|
+
blocked item fails, and the error names the blockers. Reopening is never
|
|
88
|
+
blocked, so you can always repair a mistake.
|
|
89
|
+
- You cannot remove an item that other items depend on. The error names the
|
|
90
|
+
dependents.
|
|
91
|
+
|
|
92
|
+
Reopening does not cascade. If you reopen a dependency whose dependents are
|
|
93
|
+
already done, those dependents stay done and the result adds a note that they
|
|
94
|
+
are now done but blocked. Giving a done item an open dependency produces the
|
|
95
|
+
same state and the same note, because a dependency edit would otherwise leave
|
|
96
|
+
the item silently unsatisfied. The `list` action marks such a row with
|
|
97
|
+
`(waiting on #Work:1)`: the item is finished, so it is not called blocked.
|
|
98
|
+
|
|
99
|
+
Readiness is derived on every read, never stored. The `list` action marks each
|
|
100
|
+
blocked item, and it ends every list that has dependencies with a `Ready now`
|
|
101
|
+
line. A list without a `blocked by` marker has nothing blocked, so an edge-free
|
|
102
|
+
list is not silent about readiness: it simply has nothing to report, and it
|
|
103
|
+
keeps the output it had before dependencies existed. A dependency reference
|
|
104
|
+
that does not resolve counts as a blocker, so a hand-edited snapshot cannot
|
|
105
|
+
silently unblock work.
|
|
106
|
+
|
|
107
|
+
An `update_item` batch applies its patches in order, so it behaves like the
|
|
108
|
+
same calls in sequence: one call can complete a chain, and a completion that
|
|
109
|
+
comes before its blocker in the array is refused.
|
|
110
|
+
|
|
111
|
+
Items render in a stable dependency order: a dependency comes before the items
|
|
112
|
+
that wait for it. A list with no dependencies keeps its stored order. The
|
|
113
|
+
stored order itself never changes; only the display order does. The `list`
|
|
114
|
+
action, the widget, and the `/tracker` items pane all use that order.
|
|
115
|
+
|
|
72
116
|
### Working through a list
|
|
73
117
|
|
|
74
118
|
The intended rhythm: break multi-step work into items up front (one item per
|
|
75
119
|
deliverable), work through them one at a time, and mark each done as it
|
|
76
|
-
completes. The list — shown in the widget —
|
|
120
|
+
completes. The list — shown in the widget — always shows current progress; the
|
|
77
121
|
agent should read it with `list` before starting and after finishing, and
|
|
78
122
|
update item text with `update_item` when scope changes.
|
|
79
123
|
|
|
@@ -110,10 +154,38 @@ active. It hides when no list is active.
|
|
|
110
154
|
|
|
111
155
|
The widget has a rounded border. The border uses the theme's `border` color.
|
|
112
156
|
|
|
157
|
+
When the list holds more items than the widget can show, the widget keeps the
|
|
158
|
+
first item, the current item (the first ready item), and the last item
|
|
159
|
+
visible, then fills the remaining rows around the current item. Items outside
|
|
160
|
+
that window collapse into a `⋮` row. The `⋮` row appears only when items are
|
|
161
|
+
hidden between the visible rows. The border label still shows the done and
|
|
162
|
+
total counts.
|
|
163
|
+
|
|
164
|
+
Each item line starts with one marker:
|
|
165
|
+
|
|
166
|
+
| Marker | Meaning |
|
|
167
|
+
| ------ | ------------------------------------------------------------ |
|
|
168
|
+
| `✓` | Done. |
|
|
169
|
+
| `●` | The current item: the first ready item, in the accent color. |
|
|
170
|
+
| `○` | Another open item that is ready. |
|
|
171
|
+
| `⊘` | An open item that waits for an unfinished dependency. |
|
|
172
|
+
|
|
173
|
+
The marker field is two columns wide for every marker, so the text stays
|
|
174
|
+
flush. The widget and the `list` action show the same derived order and the
|
|
175
|
+
same readiness, so the two surfaces never disagree. The marker is the widget's
|
|
176
|
+
whole report of an item's state, so a done item whose dependency was reopened
|
|
177
|
+
keeps the `✓` there; the `(waiting on ...)` annotation appears in the `list`
|
|
178
|
+
output and the `/tracker` items pane, which have room for it.
|
|
179
|
+
|
|
113
180
|
## Persistence
|
|
114
181
|
|
|
115
182
|
The state lives in the session file. Pi writes a snapshot after every change.
|
|
116
|
-
The state restores on resume, fork, and tree navigation.
|
|
183
|
+
The state restores on resume, fork, and tree navigation. Changes are applied
|
|
184
|
+
and written in order, and each result reports the state its own call produced
|
|
185
|
+
instead of a value another surface cached.
|
|
186
|
+
|
|
187
|
+
A snapshot saved before item ids existed loads with each item id equal to its
|
|
188
|
+
position, so references in that format still resolve.
|
|
117
189
|
|
|
118
190
|
## Installation
|
|
119
191
|
|
|
@@ -156,11 +228,12 @@ Registration lives in `package.json` under the `pi` field:
|
|
|
156
228
|
|
|
157
229
|
## Project structure
|
|
158
230
|
|
|
159
|
-
| File | Purpose
|
|
160
|
-
| -------------------- |
|
|
161
|
-
| `src/domain.ts` | Schema domain model (`TodoItem`, `TodoList`, `TrackerState`)
|
|
162
|
-
| `src/
|
|
163
|
-
| `src/
|
|
164
|
-
| `src/
|
|
165
|
-
| `src/
|
|
166
|
-
| `src
|
|
231
|
+
| File | Purpose |
|
|
232
|
+
| -------------------- | ---------------------------------------------------------------- |
|
|
233
|
+
| `src/domain.ts` | Schema domain model (`TodoItem`, `TodoList`, `TrackerState`) |
|
|
234
|
+
| `src/deps.ts` | Dependency references, cycle detection, readiness, derived order |
|
|
235
|
+
| `src/store.ts` | `TrackerStore` service with `Effect.Ref` state |
|
|
236
|
+
| `src/persistence.ts` | `TrackerPersistence` service (save and restore snapshots) |
|
|
237
|
+
| `src/ui.ts` | Widget pane and interactive `/tracker` component |
|
|
238
|
+
| `src/index.ts` | Pi bridge: tool, command, session hooks, widget refresh |
|
|
239
|
+
| `src/*.test.ts` | Test suites |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ftrdotdev/pi-tracker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Session-persistent todolist extension for Pi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"effect",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@effect/platform-node": "4.0.0-rc.108",
|
|
48
|
-
"@ftrdotdev/pi-tui": "^0.
|
|
48
|
+
"@ftrdotdev/pi-tui": "^0.5.0",
|
|
49
49
|
"effect": "4.0.0-rc.108"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
package/src/deps.test.ts
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { TodoItem, TodoList } from "./domain.ts";
|
|
3
|
+
import {
|
|
4
|
+
blockersOf,
|
|
5
|
+
cyclePath,
|
|
6
|
+
dependentsOf,
|
|
7
|
+
firstReadyIndex,
|
|
8
|
+
orderedItems,
|
|
9
|
+
parseItemRef,
|
|
10
|
+
readiness,
|
|
11
|
+
unsatisfiedDeps,
|
|
12
|
+
} from "./deps.ts";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A list whose items have ids 1..n in order, the given dependency sets, and
|
|
16
|
+
* the given item indexes marked done. `deps[i]` are the `listName:id`
|
|
17
|
+
* references of the item at index `i`.
|
|
18
|
+
*/
|
|
19
|
+
const listWith = (
|
|
20
|
+
deps: ReadonlyArray<readonly string[]>,
|
|
21
|
+
done: readonly number[] = [],
|
|
22
|
+
name = "Work",
|
|
23
|
+
): TodoList =>
|
|
24
|
+
new TodoList({
|
|
25
|
+
id: 1,
|
|
26
|
+
name,
|
|
27
|
+
nextItemId: deps.length + 1,
|
|
28
|
+
items: deps.map(
|
|
29
|
+
(itemDeps, index) =>
|
|
30
|
+
new TodoItem({
|
|
31
|
+
id: index + 1,
|
|
32
|
+
text: `item ${index + 1}`,
|
|
33
|
+
done: done.includes(index),
|
|
34
|
+
deps: itemDeps,
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/** Every item open. */
|
|
40
|
+
const listOf = (deps: ReadonlyArray<readonly string[]>, name = "Work"): TodoList =>
|
|
41
|
+
listWith(deps, [], name);
|
|
42
|
+
|
|
43
|
+
it("parseItemRef returns null for a malformed reference", () => {
|
|
44
|
+
for (const bad of ["Work", "", ":1", "Work:0", "Work:1x", "Work:-1", "Work:"]) {
|
|
45
|
+
assert.strictEqual(parseItemRef(bad), null, `expected ${JSON.stringify(bad)} to be rejected`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("parseItemRef splits on the last colon so list names may contain colons", () => {
|
|
50
|
+
assert.deepStrictEqual(parseItemRef("My:List:3"), { name: "My:List", id: 3 });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("cyclePath returns null for a candidate that keeps the graph acyclic", () => {
|
|
54
|
+
// Item 2 depends on item 1, so adding "item 3 depends on item 2" is fine.
|
|
55
|
+
const list = listOf([[], ["Work:1"], []]);
|
|
56
|
+
|
|
57
|
+
assert.strictEqual(cyclePath(list, 2, ["Work:2"]), null);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("cyclePath names a direct cycle", () => {
|
|
61
|
+
// Item 1 depends on item 2; making item 2 depend on item 1 closes the loop.
|
|
62
|
+
const list = listOf([["Work:2"], []]);
|
|
63
|
+
|
|
64
|
+
const path = cyclePath(list, 1, ["Work:1"]);
|
|
65
|
+
|
|
66
|
+
assert.notStrictEqual(path, null);
|
|
67
|
+
assert.include(path ?? [], "Work:1");
|
|
68
|
+
assert.include(path ?? [], "Work:2");
|
|
69
|
+
// The path starts and ends at the item being changed.
|
|
70
|
+
assert.strictEqual(path?.[0], "Work:2");
|
|
71
|
+
assert.strictEqual(path?.[path.length - 1], "Work:2");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("cyclePath names an indirect cycle", () => {
|
|
75
|
+
// 1 depends on 2 and 2 depends on 3; making 3 depend on 1 closes the loop.
|
|
76
|
+
const list = listOf([["Work:2"], ["Work:3"], []]);
|
|
77
|
+
|
|
78
|
+
const path = cyclePath(list, 2, ["Work:1"]);
|
|
79
|
+
|
|
80
|
+
assert.notStrictEqual(path, null);
|
|
81
|
+
for (const ref of ["Work:1", "Work:2", "Work:3"]) {
|
|
82
|
+
assert.include(path ?? [], ref);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("cyclePath catches a self dependency", () => {
|
|
87
|
+
const list = listOf([[]]);
|
|
88
|
+
|
|
89
|
+
assert.deepStrictEqual(cyclePath(list, 0, ["Work:1"]), ["Work:1", "Work:1"]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("cyclePath ignores a dependency that does not resolve", () => {
|
|
93
|
+
// An unresolvable reference cannot close a cycle; the store rejects it
|
|
94
|
+
// separately with a DependencyNotFound error.
|
|
95
|
+
const list = listOf([[]]);
|
|
96
|
+
|
|
97
|
+
assert.strictEqual(cyclePath(list, 0, ["Work:9"]), null);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("cyclePath ignores a dependency naming another list", () => {
|
|
101
|
+
const list = listOf([[]], "Work");
|
|
102
|
+
|
|
103
|
+
assert.strictEqual(cyclePath(list, 0, ["Home:1"]), null);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// --------------------------------------------------------------------------
|
|
107
|
+
// Readiness (derived on read, never stored)
|
|
108
|
+
// --------------------------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
it("an item with no dependencies is ready when open", () => {
|
|
111
|
+
const entries = readiness(listWith([[], []]));
|
|
112
|
+
|
|
113
|
+
assert.deepStrictEqual(
|
|
114
|
+
entries.map((entry) => entry.ready),
|
|
115
|
+
[true, true],
|
|
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"]]));
|
|
125
|
+
|
|
126
|
+
assert.strictEqual(entries[0]?.ready, true);
|
|
127
|
+
assert.strictEqual(entries[1]?.ready, false);
|
|
128
|
+
assert.deepStrictEqual(entries[1]?.blockers, ["Work:1"]);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it("a done item reports the dependencies that are still open", () => {
|
|
132
|
+
// The state a reopen creates: item 2 is done while its prerequisite is open.
|
|
133
|
+
// `ready` is false (the item is not actionable) and `blockers` names the open
|
|
134
|
+
// prerequisite, so the list can mark the row instead of showing a plain done
|
|
135
|
+
// row that hides the state.
|
|
136
|
+
const stale = readiness(listWith([[], ["Work:1"]], [1]));
|
|
137
|
+
assert.strictEqual(stale[1]?.ready, false);
|
|
138
|
+
assert.deepStrictEqual(stale[1]?.blockers, ["Work:1"]);
|
|
139
|
+
|
|
140
|
+
// A satisfied done item reports nothing.
|
|
141
|
+
const satisfied = readiness(listWith([[], ["Work:1"]], [0, 1]));
|
|
142
|
+
assert.strictEqual(satisfied[1]?.ready, false);
|
|
143
|
+
assert.deepStrictEqual(satisfied[1]?.blockers, []);
|
|
144
|
+
});
|
|
145
|
+
|
|
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
|
+
it("a dangling reference leaves its dependent blocked", () => {
|
|
197
|
+
const entry = readiness(listWith([[], ["Work:9"]]))[1];
|
|
198
|
+
|
|
199
|
+
assert.strictEqual(entry?.ready, false);
|
|
200
|
+
assert.deepStrictEqual(entry?.blockers, ["?"]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("dependentsOf lists the items that depend on a given item", () => {
|
|
204
|
+
const list = listWith([[], ["Work:1"], ["Work:1", "Work:2"], []]);
|
|
205
|
+
|
|
206
|
+
assert.deepStrictEqual(dependentsOf(list, 0), [1, 2]);
|
|
207
|
+
assert.deepStrictEqual(dependentsOf(list, 1), [2]);
|
|
208
|
+
assert.deepStrictEqual(dependentsOf(list, 2), []);
|
|
209
|
+
assert.deepStrictEqual(dependentsOf(list, 3), []);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// --------------------------------------------------------------------------
|
|
213
|
+
// Derived display order
|
|
214
|
+
// --------------------------------------------------------------------------
|
|
215
|
+
|
|
216
|
+
/** The ids of the given items, so an order is easy to assert. */
|
|
217
|
+
const idsOf = (items: readonly { readonly id?: number }[]): number[] =>
|
|
218
|
+
items.map((item) => item.id ?? 0);
|
|
219
|
+
|
|
220
|
+
it("orderedItems returns the stored order when nothing has dependencies", () => {
|
|
221
|
+
const list = listWith([[], [], []]);
|
|
222
|
+
|
|
223
|
+
assert.deepStrictEqual(idsOf(orderedItems(list)), [1, 2, 3]);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("orderedItems puts a dependency before its dependent", () => {
|
|
227
|
+
// Item 1 waits for item 2.
|
|
228
|
+
const list = listWith([["Work:2"], []]);
|
|
229
|
+
|
|
230
|
+
assert.deepStrictEqual(idsOf(orderedItems(list)), [2, 1]);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("orderedItems follows a chain", () => {
|
|
234
|
+
// Item 3 -> item 2 -> item 1.
|
|
235
|
+
const list = listWith([[], ["Work:1"], ["Work:2"]]);
|
|
236
|
+
|
|
237
|
+
assert.deepStrictEqual(idsOf(orderedItems(list)), [1, 2, 3]);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("orderedItems keeps the stored order among items that are ready together", () => {
|
|
241
|
+
// Item 2 waits for item 1. Item 3 is ready from the start, so it keeps its
|
|
242
|
+
// place ahead of item 2, which only becomes ready once item 1 is emitted.
|
|
243
|
+
const list = listWith([[], ["Work:1"], []]);
|
|
244
|
+
|
|
245
|
+
assert.deepStrictEqual(idsOf(orderedItems(list)), [1, 3, 2]);
|
|
246
|
+
});
|
|
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
|
+
});
|