@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
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
|
|
3
|
+
import { limitArbitrary, pendingCompletionArbitrary } from "../../test-support/generators.ts";
|
|
4
|
+
import { readiness } from "../core/deps.ts";
|
|
2
5
|
import { selectCandidates, type CompactionCandidate } from "./candidate.ts";
|
|
3
6
|
import type { PendingCompletion } from "./completion.ts";
|
|
4
7
|
import { TodoItem, TodoList } from "../core/domain.ts";
|
|
@@ -14,17 +17,16 @@ const completion = (
|
|
|
14
17
|
items: readonly ItemSpec[],
|
|
15
18
|
completedItemIds: readonly number[],
|
|
16
19
|
): PendingCompletion => {
|
|
17
|
-
const list =
|
|
20
|
+
const list = TodoList.make({
|
|
18
21
|
id: 1,
|
|
19
22
|
name: "Work",
|
|
20
|
-
items: items.map(
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}),
|
|
23
|
+
items: items.map((item) =>
|
|
24
|
+
TodoItem.make({
|
|
25
|
+
id: item.id,
|
|
26
|
+
title: item.title ?? `item ${item.id}`,
|
|
27
|
+
done: item.done,
|
|
28
|
+
deps: [...(item.deps ?? [])],
|
|
29
|
+
}),
|
|
28
30
|
),
|
|
29
31
|
nextItemId: items.reduce((max, item) => Math.max(max, item.id), 0) + 1,
|
|
30
32
|
});
|
|
@@ -38,37 +40,6 @@ const first = (pending: PendingCompletion, limit = 8): CompactionCandidate => {
|
|
|
38
40
|
return candidates[0]!;
|
|
39
41
|
};
|
|
40
42
|
|
|
41
|
-
it("selectCandidates prefers the first ready dependent successor", () => {
|
|
42
|
-
const candidate = first(
|
|
43
|
-
completion(
|
|
44
|
-
[
|
|
45
|
-
{ id: 1, done: true },
|
|
46
|
-
{ id: 2, done: false, deps: ["Work:1"] },
|
|
47
|
-
{ id: 3, done: false },
|
|
48
|
-
],
|
|
49
|
-
[1],
|
|
50
|
-
),
|
|
51
|
-
);
|
|
52
|
-
assert.strictEqual(candidate.id, 2);
|
|
53
|
-
assert.strictEqual(candidate.class, "dependent-successor");
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("selectCandidates skips a dependent successor that is still blocked", () => {
|
|
57
|
-
const candidate = first(
|
|
58
|
-
completion(
|
|
59
|
-
[
|
|
60
|
-
{ id: 1, done: true },
|
|
61
|
-
{ id: 2, done: false, deps: ["Work:1", "Work:4"] },
|
|
62
|
-
{ id: 3, done: false },
|
|
63
|
-
{ id: 4, done: false },
|
|
64
|
-
],
|
|
65
|
-
[1],
|
|
66
|
-
),
|
|
67
|
-
);
|
|
68
|
-
assert.strictEqual(candidate.id, 3);
|
|
69
|
-
assert.strictEqual(candidate.class, "ready-queue");
|
|
70
|
-
});
|
|
71
|
-
|
|
72
43
|
it("selectCandidates considers every item in the completed batch", () => {
|
|
73
44
|
const candidate = first(
|
|
74
45
|
completion(
|
|
@@ -85,51 +56,6 @@ it("selectCandidates considers every item in the completed batch", () => {
|
|
|
85
56
|
assert.strictEqual(candidate.class, "dependent-successor");
|
|
86
57
|
});
|
|
87
58
|
|
|
88
|
-
it("selectCandidates falls back to the first remaining ready item in list order", () => {
|
|
89
|
-
const candidate = first(
|
|
90
|
-
completion(
|
|
91
|
-
[
|
|
92
|
-
{ id: 1, done: true },
|
|
93
|
-
{ id: 3, done: false },
|
|
94
|
-
{ id: 4, done: false },
|
|
95
|
-
],
|
|
96
|
-
[1],
|
|
97
|
-
),
|
|
98
|
-
);
|
|
99
|
-
assert.strictEqual(candidate.id, 3);
|
|
100
|
-
assert.strictEqual(candidate.class, "ready-queue");
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it("selectCandidates excludes every completed item from the fallback", () => {
|
|
104
|
-
const candidate = first(
|
|
105
|
-
completion(
|
|
106
|
-
[
|
|
107
|
-
{ id: 1, done: false },
|
|
108
|
-
{ id: 2, done: false },
|
|
109
|
-
{ id: 3, done: false },
|
|
110
|
-
],
|
|
111
|
-
[1, 2],
|
|
112
|
-
),
|
|
113
|
-
);
|
|
114
|
-
assert.strictEqual(candidate.id, 3);
|
|
115
|
-
assert.notStrictEqual(candidate.id, 1);
|
|
116
|
-
assert.notStrictEqual(candidate.id, 2);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("selectCandidates returns an empty array when nothing is ready", () => {
|
|
120
|
-
const candidates = selectCandidates(
|
|
121
|
-
completion(
|
|
122
|
-
[
|
|
123
|
-
{ id: 1, done: true },
|
|
124
|
-
{ id: 2, done: false, deps: ["Work:9"] },
|
|
125
|
-
],
|
|
126
|
-
[1],
|
|
127
|
-
),
|
|
128
|
-
8,
|
|
129
|
-
);
|
|
130
|
-
assert.deepStrictEqual(candidates, []);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
59
|
it("selectCandidates carries the completed batch as prior work", () => {
|
|
134
60
|
const candidate = first(
|
|
135
61
|
completion(
|
|
@@ -148,44 +74,59 @@ it("selectCandidates carries the completed batch as prior work", () => {
|
|
|
148
74
|
assert.strictEqual(candidate.id, 4);
|
|
149
75
|
});
|
|
150
76
|
|
|
151
|
-
it(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
[2, 4, 3],
|
|
167
|
-
);
|
|
168
|
-
assert.deepStrictEqual(
|
|
169
|
-
candidates.map((candidate) => candidate.class),
|
|
170
|
-
["dependent-successor", "dependent-successor", "ready-queue"],
|
|
171
|
-
);
|
|
172
|
-
});
|
|
77
|
+
it.prop(
|
|
78
|
+
"every judged candidate is ready and not completed",
|
|
79
|
+
{ pending: pendingCompletionArbitrary, limit: limitArbitrary },
|
|
80
|
+
({ pending, limit }) => {
|
|
81
|
+
const view = readiness(pending.list);
|
|
82
|
+
const completed = new Set(pending.completedItemIds);
|
|
83
|
+
for (const candidate of selectCandidates(pending, limit)) {
|
|
84
|
+
const entry = view[pending.list.items.findIndex((item) => item.id === candidate.id)];
|
|
85
|
+
assert.notStrictEqual(entry, undefined);
|
|
86
|
+
assert.strictEqual(entry!.ready, true);
|
|
87
|
+
assert(!completed.has(candidate.id));
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
91
|
+
);
|
|
173
92
|
|
|
174
|
-
it(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
93
|
+
it.prop(
|
|
94
|
+
"judged candidates keep stored order with dependent successors before the ready queue",
|
|
95
|
+
{ pending: pendingCompletionArbitrary, limit: limitArbitrary },
|
|
96
|
+
({ pending, limit }) => {
|
|
97
|
+
const candidates = selectCandidates(pending, limit);
|
|
98
|
+
const classes = candidates.map((candidate) => candidate.class);
|
|
99
|
+
const firstQueue = classes.indexOf("ready-queue");
|
|
100
|
+
if (firstQueue !== -1) assert(classes.slice(firstQueue).every((cls) => cls === "ready-queue"));
|
|
101
|
+
const position = new Map(pending.list.items.map((item, index) => [item.id, index]));
|
|
102
|
+
for (const cls of ["dependent-successor", "ready-queue"] as const) {
|
|
103
|
+
const positions = classes.flatMap((candidateClass, at) =>
|
|
104
|
+
candidateClass === cls ? [position.get(candidates[at]!.id)!] : [],
|
|
105
|
+
);
|
|
106
|
+
assert.deepStrictEqual(
|
|
107
|
+
positions,
|
|
108
|
+
positions.toSorted((left, right) => left - right),
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
it.prop(
|
|
116
|
+
"the judged set never exceeds the limit",
|
|
117
|
+
{ pending: pendingCompletionArbitrary, limit: limitArbitrary },
|
|
118
|
+
({ pending, limit }) => {
|
|
119
|
+
assert(selectCandidates(pending, limit).length <= limit);
|
|
120
|
+
},
|
|
121
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
it.prop(
|
|
125
|
+
"nothing is judged exactly when no open unblocked item is left",
|
|
126
|
+
{ pending: pendingCompletionArbitrary, limit: limitArbitrary },
|
|
127
|
+
({ pending, limit }) => {
|
|
128
|
+
const readyLeft = readiness(pending.list).some((entry) => entry.ready);
|
|
129
|
+
assert.strictEqual(selectCandidates(pending, limit).length === 0, !readyLeft);
|
|
130
|
+
},
|
|
131
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
132
|
+
);
|
|
@@ -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, Fiber, Option } from "effect";
|
|
3
6
|
import { TestClock } from "effect/testing";
|
|
@@ -317,7 +320,7 @@ it.effect("gateway returns disabled when the classifier call exceeds the deadlin
|
|
|
317
320
|
withGateway(
|
|
318
321
|
Effect.gen(function* () {
|
|
319
322
|
const gateway = yield* ClassifierGateway;
|
|
320
|
-
const captured: { signal?: AbortSignal } = {};
|
|
323
|
+
const captured: { signal?: AbortSignal | undefined } = {};
|
|
321
324
|
const registry: ClassifierRegistry = {
|
|
322
325
|
getAvailableOfType: async () => [jev],
|
|
323
326
|
classify: (_model, _context, options) => {
|
|
@@ -352,6 +355,23 @@ it.effect(
|
|
|
352
355
|
),
|
|
353
356
|
);
|
|
354
357
|
|
|
358
|
+
it.effect("gateway keeps the verdict when the run signal is live and never aborted", () => {
|
|
359
|
+
// Constructed outside the Effect program so the run signal is a plain value.
|
|
360
|
+
const signal = new AbortController().signal;
|
|
361
|
+
return withGateway(
|
|
362
|
+
Effect.gen(function* () {
|
|
363
|
+
const gateway = yield* ClassifierGateway;
|
|
364
|
+
const registry: ClassifierRegistry = {
|
|
365
|
+
getAvailableOfType: async () => [clefFlash, jev],
|
|
366
|
+
classify: async () => choiceResult(0.1, 0.9),
|
|
367
|
+
};
|
|
368
|
+
// A live signal must not discard a verdict: only an aborted one does.
|
|
369
|
+
const result = yield* gateway.verdict(input(registry, { signal }));
|
|
370
|
+
assert.deepStrictEqual(result, { kind: "compact" });
|
|
371
|
+
}),
|
|
372
|
+
);
|
|
373
|
+
});
|
|
374
|
+
|
|
355
375
|
it.effect(
|
|
356
376
|
"gateway forwards the run signal to the classifier call and returns disabled on abort",
|
|
357
377
|
() => {
|
|
@@ -360,7 +380,7 @@ it.effect(
|
|
|
360
380
|
return withGateway(
|
|
361
381
|
Effect.gen(function* () {
|
|
362
382
|
const gateway = yield* ClassifierGateway;
|
|
363
|
-
const captured: { signal?: AbortSignal } = {};
|
|
383
|
+
const captured: { signal?: AbortSignal | undefined } = {};
|
|
364
384
|
const registry: ClassifierRegistry = {
|
|
365
385
|
getAvailableOfType: async () => [jev],
|
|
366
386
|
classify: (_model, _context, options) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Context, Effect, Layer, Option } from "effect";
|
|
1
|
+
import { Context, Effect, Layer, Option, Schema } from "effect";
|
|
2
2
|
import type {
|
|
3
3
|
ClassifierApi,
|
|
4
4
|
ClassifierModel,
|
|
@@ -7,6 +7,12 @@ import type {
|
|
|
7
7
|
JsonObject,
|
|
8
8
|
} from "@earendil-works/pi-ai";
|
|
9
9
|
|
|
10
|
+
/** A classifier call the registry rejected; the gateway turns it into "disabled". */
|
|
11
|
+
export class ClassifierCallFailed extends Schema.TaggedError<
|
|
12
|
+
ClassifierCallFailed,
|
|
13
|
+
{ readonly brand: unique symbol }
|
|
14
|
+
>()("ClassifierCallFailed", { cause: Schema.Defect() }) {}
|
|
15
|
+
|
|
10
16
|
/**
|
|
11
17
|
* One question the gateway asks a classifier about a candidate. Built by
|
|
12
18
|
* `digest.ts`; owned here because it is the gateway's input contract.
|
|
@@ -30,7 +36,10 @@ export interface ClassifierRegistry {
|
|
|
30
36
|
readonly state: JsonObject;
|
|
31
37
|
readonly questions: Record<string, ClassifierQuestion>;
|
|
32
38
|
},
|
|
33
|
-
|
|
39
|
+
// Narrow (no explicit `undefined`) because the pi `ModelRegistry.classify`
|
|
40
|
+
// this is assigned from declares its own option bag that way, and
|
|
41
|
+
// `exactOptionalPropertyTypes` rejects the widened form.
|
|
42
|
+
options?: { readonly signal?: AbortSignal },
|
|
34
43
|
) => Promise<ClassifierResult>;
|
|
35
44
|
}
|
|
36
45
|
|
|
@@ -147,7 +156,7 @@ export class ClassifierGateway extends Context.Service<
|
|
|
147
156
|
readonly signal?: AbortSignal | undefined;
|
|
148
157
|
}) => Effect.Effect<ClassificationVerdict>;
|
|
149
158
|
}
|
|
150
|
-
>()("tracker/ClassifierGateway") {
|
|
159
|
+
>()("@ftrdotdev/pi-tracker/compaction/classifier/ClassifierGateway") {
|
|
151
160
|
static readonly layer: Layer.Layer<ClassifierGateway> = Layer.sync(ClassifierGateway, () => {
|
|
152
161
|
const verdict = Effect.fn("ClassifierGateway.verdict")(function* (input: {
|
|
153
162
|
readonly registry: ClassifierRegistry;
|
|
@@ -159,31 +168,35 @@ export class ClassifierGateway extends Context.Service<
|
|
|
159
168
|
readonly questions: readonly CompactionQuestion[];
|
|
160
169
|
readonly signal?: AbortSignal | undefined;
|
|
161
170
|
}) {
|
|
162
|
-
if (!input.enabled || input.signal?.aborted
|
|
171
|
+
if (!input.enabled || (input.signal?.aborted ?? false))
|
|
172
|
+
return CLASSIFICATION_VERDICT.disabled;
|
|
163
173
|
|
|
164
|
-
const available = yield* Effect.tryPromise(
|
|
165
|
-
input.registry.getAvailableOfType("classifier"),
|
|
166
|
-
|
|
174
|
+
const available = yield* Effect.tryPromise({
|
|
175
|
+
try: () => input.registry.getAvailableOfType("classifier"),
|
|
176
|
+
catch: (cause) => ClassifierCallFailed.make({ cause }),
|
|
177
|
+
}).pipe(Effect.catchCause(() => Effect.succeed([])));
|
|
167
178
|
const model = resolveClassifier(available, input.chosen);
|
|
168
179
|
if (Option.isNone(model)) return CLASSIFICATION_VERDICT.disabled;
|
|
169
|
-
const result = yield* Effect.tryPromise(
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
const result = yield* Effect.tryPromise({
|
|
181
|
+
try: (signal) =>
|
|
182
|
+
input.registry.classify(
|
|
183
|
+
model.value,
|
|
184
|
+
{
|
|
185
|
+
state: input.digest,
|
|
186
|
+
questions: Object.fromEntries(
|
|
187
|
+
input.questions.map((question) => [question.key, question.question]),
|
|
188
|
+
),
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
signal: input.signal === undefined ? signal : AbortSignal.any([signal, input.signal]),
|
|
192
|
+
},
|
|
193
|
+
),
|
|
194
|
+
catch: (cause) => ClassifierCallFailed.make({ cause }),
|
|
195
|
+
}).pipe(
|
|
183
196
|
Effect.timeoutOption(CLASSIFY_TIMEOUT_MILLIS),
|
|
184
197
|
Effect.catchCause(() => Effect.succeedNone),
|
|
185
198
|
);
|
|
186
|
-
if (input.signal?.aborted) return CLASSIFICATION_VERDICT.disabled;
|
|
199
|
+
if (input.signal?.aborted ?? false) return CLASSIFICATION_VERDICT.disabled;
|
|
187
200
|
return Option.isNone(result)
|
|
188
201
|
? CLASSIFICATION_VERDICT.disabled
|
|
189
202
|
: classifyVerdict(
|
|
@@ -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, Option } from "effect";
|
|
3
6
|
import { CompletionObserver, completedInActiveList } from "./completion.ts";
|
|
@@ -10,17 +13,16 @@ interface ItemSpec {
|
|
|
10
13
|
}
|
|
11
14
|
|
|
12
15
|
const list = (id: number, name: string, items: readonly ItemSpec[]): TodoList =>
|
|
13
|
-
|
|
16
|
+
TodoList.make({
|
|
14
17
|
id,
|
|
15
18
|
name,
|
|
16
|
-
items: items.map(
|
|
17
|
-
(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}),
|
|
19
|
+
items: items.map((item) =>
|
|
20
|
+
TodoItem.make({
|
|
21
|
+
id: item.id,
|
|
22
|
+
title: `item ${item.id}`,
|
|
23
|
+
done: item.done,
|
|
24
|
+
deps: [...(item.deps ?? [])],
|
|
25
|
+
}),
|
|
24
26
|
),
|
|
25
27
|
nextItemId: items.reduce((max, item) => Math.max(max, item.id), 0) + 1,
|
|
26
28
|
});
|
|
@@ -29,7 +31,7 @@ const state = (
|
|
|
29
31
|
lists: readonly TodoList[],
|
|
30
32
|
activeListId: number | null,
|
|
31
33
|
nextListId = lists.length + 1,
|
|
32
|
-
): TrackerState =>
|
|
34
|
+
): TrackerState => TrackerState.make({ lists: [...lists], activeListId, nextListId });
|
|
33
35
|
|
|
34
36
|
// ---------------------------------------------------------------------------
|
|
35
37
|
// completedInActiveList
|
|
@@ -122,7 +124,8 @@ it.effect("CompletionObserver record folds successive mutations into one batch",
|
|
|
122
124
|
);
|
|
123
125
|
yield* observer.record(s0, s1);
|
|
124
126
|
yield* observer.record(s1, s2);
|
|
125
|
-
const
|
|
127
|
+
const pending = yield* observer.consume;
|
|
128
|
+
const batch = Option.getOrThrow(pending);
|
|
126
129
|
assert.deepStrictEqual(batch.completedItemIds, [1, 3]);
|
|
127
130
|
assert.deepStrictEqual(
|
|
128
131
|
batch.list.items.map((item) => item.done),
|
|
@@ -151,7 +154,8 @@ it.effect(
|
|
|
151
154
|
);
|
|
152
155
|
yield* observer.record(s0, s1);
|
|
153
156
|
yield* observer.record(s1, s2);
|
|
154
|
-
const
|
|
157
|
+
const pending = yield* observer.consume;
|
|
158
|
+
const batch = Option.getOrThrow(pending);
|
|
155
159
|
assert.deepStrictEqual(batch.completedItemIds, [1]);
|
|
156
160
|
assert.deepStrictEqual(
|
|
157
161
|
batch.list.items.map((item) => item.id),
|
|
@@ -170,7 +174,8 @@ it.effect("CompletionObserver record drops a completed item that was reopened be
|
|
|
170
174
|
const s2 = state([list(1, "Work", [{ id: 1, done: false }])], 1);
|
|
171
175
|
yield* observer.record(s0, s1);
|
|
172
176
|
yield* observer.record(s1, s2);
|
|
173
|
-
|
|
177
|
+
const pending = yield* observer.consume;
|
|
178
|
+
assert.strictEqual(Option.isNone(pending), true);
|
|
174
179
|
}),
|
|
175
180
|
),
|
|
176
181
|
);
|
|
@@ -184,7 +189,8 @@ it.effect("CompletionObserver record drops a completed item that was removed bef
|
|
|
184
189
|
const s2 = state([list(1, "Work", [])], 1);
|
|
185
190
|
yield* observer.record(s0, s1);
|
|
186
191
|
yield* observer.record(s1, s2);
|
|
187
|
-
|
|
192
|
+
const pending = yield* observer.consume;
|
|
193
|
+
assert.strictEqual(Option.isNone(pending), true);
|
|
188
194
|
}),
|
|
189
195
|
),
|
|
190
196
|
);
|
|
@@ -209,7 +215,8 @@ it.effect(
|
|
|
209
215
|
);
|
|
210
216
|
yield* observer.record(s0, s1);
|
|
211
217
|
yield* observer.record(s1, s2);
|
|
212
|
-
|
|
218
|
+
const pending = yield* observer.consume;
|
|
219
|
+
assert.strictEqual(Option.isNone(pending), true);
|
|
213
220
|
}),
|
|
214
221
|
),
|
|
215
222
|
);
|
|
@@ -234,7 +241,8 @@ it.effect(
|
|
|
234
241
|
);
|
|
235
242
|
yield* observer.record(s0, s1);
|
|
236
243
|
yield* observer.record(s1, s2);
|
|
237
|
-
const
|
|
244
|
+
const pending = yield* observer.consume;
|
|
245
|
+
const batch = Option.getOrThrow(pending);
|
|
238
246
|
assert.deepStrictEqual(batch.completedItemIds, [1]);
|
|
239
247
|
assert.strictEqual(batch.list.name, "Other");
|
|
240
248
|
}),
|
|
@@ -73,7 +73,7 @@ export class CompletionObserver extends Context.Service<
|
|
|
73
73
|
/** Read and clear in one step, so one completion set yields one decision. */
|
|
74
74
|
readonly consume: Effect.Effect<Option.Option<PendingCompletion>>;
|
|
75
75
|
}
|
|
76
|
-
>()("tracker/CompletionObserver") {
|
|
76
|
+
>()("@ftrdotdev/pi-tracker/compaction/completion/CompletionObserver") {
|
|
77
77
|
static readonly layer: Layer.Layer<CompletionObserver> = Layer.effect(
|
|
78
78
|
CompletionObserver,
|
|
79
79
|
Effect.gen(function* () {
|
|
@@ -86,6 +86,6 @@ it("a record caps references at eight and products at four", () => {
|
|
|
86
86
|
});
|
|
87
87
|
|
|
88
88
|
it("a malformed record fails to decode", () => {
|
|
89
|
-
const exit = Effect.
|
|
89
|
+
const exit = Effect.exit(decodeDecisionRecord({ rule: 42 })).pipe(Effect.runSync);
|
|
90
90
|
assert.strictEqual(exit._tag, "Failure");
|
|
91
91
|
});
|
|
@@ -50,7 +50,7 @@ export const decisionRecordSchema = Schema.Struct({
|
|
|
50
50
|
products: Schema.Array(recordProduct),
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
export type DecisionRecord =
|
|
53
|
+
export type DecisionRecord = typeof decisionRecordSchema.Type;
|
|
54
54
|
|
|
55
55
|
const referenceOf = (entry: ResolvedReference): DecisionRecord["references"][number] =>
|
|
56
56
|
entry.reference.kind === "decision"
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import { PROPERTY_RUNS } from "@ftrdotdev/pi-test-kit";
|
|
3
|
+
import { limitArbitrary, pendingCompletionArbitrary } from "../../test-support/generators.ts";
|
|
4
|
+
import { digestOf } from "../../test-support/doubles.ts";
|
|
5
|
+
import { selectCandidates } from "./candidate.ts";
|
|
2
6
|
import { NEEDS_CONTEXT_LABEL, NEEDS_NONE_LABEL } from "./classifier.ts";
|
|
3
7
|
import type { CompactionCandidate } from "./candidate.ts";
|
|
4
8
|
import {
|
|
@@ -12,22 +16,6 @@ import {
|
|
|
12
16
|
} from "./digest.ts";
|
|
13
17
|
import type { ResolvedProduct, ResolvedReference } from "./observations.ts";
|
|
14
18
|
|
|
15
|
-
interface DigestShape {
|
|
16
|
-
candidates: Array<{
|
|
17
|
-
ref: string;
|
|
18
|
-
text: string;
|
|
19
|
-
description?: string;
|
|
20
|
-
class: string;
|
|
21
|
-
relationship: string;
|
|
22
|
-
references: Array<Record<string, unknown>>;
|
|
23
|
-
products: Array<Record<string, unknown>>;
|
|
24
|
-
referenceCut?: string;
|
|
25
|
-
productCut?: string;
|
|
26
|
-
}>;
|
|
27
|
-
completed: Array<{ ref: string; text: string; description?: string }>;
|
|
28
|
-
survival: string;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
19
|
const dependent: CompactionCandidate = {
|
|
32
20
|
class: "dependent-successor",
|
|
33
21
|
listName: "Work",
|
|
@@ -52,7 +40,7 @@ it("buildDigests carries only the candidates, the completed batch, and the survi
|
|
|
52
40
|
});
|
|
53
41
|
|
|
54
42
|
it("buildDigests lists one entry per candidate with its class and relationship", () => {
|
|
55
|
-
const digest =
|
|
43
|
+
const digest = digestOf([dependent, readyQueue], noFacts);
|
|
56
44
|
assert.deepStrictEqual(digest.candidates, [
|
|
57
45
|
{
|
|
58
46
|
ref: "Work:2",
|
|
@@ -74,7 +62,7 @@ it("buildDigests lists one entry per candidate with its class and relationship",
|
|
|
74
62
|
});
|
|
75
63
|
|
|
76
64
|
it("buildDigests carries the completed batch once as prior work", () => {
|
|
77
|
-
const digest =
|
|
65
|
+
const digest = digestOf([dependent, readyQueue], noFacts);
|
|
78
66
|
assert.deepStrictEqual(digest.completed, [{ ref: "Work:1", text: "first" }]);
|
|
79
67
|
});
|
|
80
68
|
|
|
@@ -88,7 +76,7 @@ it("buildDigests carries a long description as its first paragraph with a named
|
|
|
88
76
|
...readyQueue,
|
|
89
77
|
description: `${first}\n\nsecond paragraph`,
|
|
90
78
|
};
|
|
91
|
-
const digest =
|
|
79
|
+
const digest = digestOf([candidate], noFacts);
|
|
92
80
|
const description = digest.candidates[0]!.description!;
|
|
93
81
|
assert.strictEqual(description, `${"a".repeat(DESCRIPTION_LIMIT)}… [50 more characters]`);
|
|
94
82
|
assert.notInclude(description, "second paragraph");
|
|
@@ -96,7 +84,7 @@ it("buildDigests carries a long description as its first paragraph with a named
|
|
|
96
84
|
|
|
97
85
|
it("buildDigests carries a description that is already one short paragraph unchanged", () => {
|
|
98
86
|
const candidate: CompactionCandidate = { ...readyQueue, description: "one line" };
|
|
99
|
-
const digest =
|
|
87
|
+
const digest = digestOf([candidate], noFacts);
|
|
100
88
|
assert.strictEqual(digest.candidates[0]!.description, "one line");
|
|
101
89
|
});
|
|
102
90
|
|
|
@@ -111,10 +99,7 @@ it("buildDigests caps references at eight and products at four with a marker", (
|
|
|
111
99
|
state: "readable",
|
|
112
100
|
}));
|
|
113
101
|
const products: ResolvedProduct[] = produces.map((product) => ({ product, state: "exists" }));
|
|
114
|
-
const digest =
|
|
115
|
-
[{ ...readyQueue, refs, produces }],
|
|
116
|
-
[{ references, products }],
|
|
117
|
-
) as unknown as DigestShape;
|
|
102
|
+
const digest = digestOf([{ ...readyQueue, refs, produces }], [{ references, products }]);
|
|
118
103
|
const candidate = digest.candidates[0]!;
|
|
119
104
|
assert.strictEqual(candidate.references.length, REFERENCE_CAP);
|
|
120
105
|
assert.strictEqual(candidate.products.length, PRODUCT_CAP);
|
|
@@ -124,10 +109,10 @@ it("buildDigests caps references at eight and products at four with a marker", (
|
|
|
124
109
|
|
|
125
110
|
it("buildDigests carries a declared decision as a fact and never asserts it is archived", () => {
|
|
126
111
|
const refs = [{ kind: "decision" as const, topic: "storage shape" }];
|
|
127
|
-
const digest =
|
|
112
|
+
const digest = digestOf(
|
|
128
113
|
[{ ...readyQueue, refs }],
|
|
129
114
|
[{ references: [{ reference: refs[0]!, state: "unresolved" }], products: [] }],
|
|
130
|
-
)
|
|
115
|
+
);
|
|
131
116
|
assert.deepStrictEqual(digest.candidates[0]!.references, [
|
|
132
117
|
{ kind: "decision", topic: "storage shape", state: "unresolved" },
|
|
133
118
|
]);
|
|
@@ -135,7 +120,7 @@ it("buildDigests carries a declared decision as a fact and never asserts it is a
|
|
|
135
120
|
});
|
|
136
121
|
|
|
137
122
|
it("buildDigests carries the survival instruction and no transcript text", () => {
|
|
138
|
-
const digest =
|
|
123
|
+
const digest = digestOf([dependent], noFacts);
|
|
139
124
|
assert.include(digest.survival, "transcript");
|
|
140
125
|
assert.include(digest.survival, "description");
|
|
141
126
|
assert.notInclude(JSON.stringify(digest), "assistant said");
|
|
@@ -151,13 +136,6 @@ it("compactQuestions keys each question by its candidate reference and index", (
|
|
|
151
136
|
assert.strictEqual(questions[0]!.key, `${QUESTION_KEY_PREFIX}.Work_2.0`);
|
|
152
137
|
});
|
|
153
138
|
|
|
154
|
-
it("compactQuestions produces ids that satisfy the provider pattern", () => {
|
|
155
|
-
const questions = compactQuestions([dependent, readyQueue]);
|
|
156
|
-
for (const { key } of questions) {
|
|
157
|
-
assert.match(key, /^[A-Za-z0-9_.-]{1,100}$/);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
139
|
it("compactQuestions asks one two-label choice question per candidate", () => {
|
|
162
140
|
const questions = compactQuestions([dependent, readyQueue]);
|
|
163
141
|
assert.strictEqual(questions.length, 2);
|
|
@@ -183,3 +161,25 @@ it("compactQuestions uses the class-specific wording", () => {
|
|
|
183
161
|
queueQuestion!.question.instructions,
|
|
184
162
|
);
|
|
185
163
|
});
|
|
164
|
+
|
|
165
|
+
it.prop(
|
|
166
|
+
"a question key is provider-safe for any reference",
|
|
167
|
+
{ pending: pendingCompletionArbitrary, limit: limitArbitrary },
|
|
168
|
+
({ pending, limit }) => {
|
|
169
|
+
const candidates = selectCandidates(pending, limit);
|
|
170
|
+
const questions = compactQuestions(candidates);
|
|
171
|
+
assert.strictEqual(questions.length, candidates.length);
|
|
172
|
+
for (const { key } of questions) assert.match(key, /^[A-Za-z0-9_.-]{1,100}$/);
|
|
173
|
+
},
|
|
174
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
it.prop(
|
|
178
|
+
"question keys are unique within one candidate list",
|
|
179
|
+
{ pending: pendingCompletionArbitrary, limit: limitArbitrary },
|
|
180
|
+
({ pending, limit }) => {
|
|
181
|
+
const keys = compactQuestions(selectCandidates(pending, limit)).map((entry) => entry.key);
|
|
182
|
+
assert.strictEqual(new Set(keys).size, keys.length);
|
|
183
|
+
},
|
|
184
|
+
{ arbitrary: { runs: PROPERTY_RUNS } },
|
|
185
|
+
);
|
|
@@ -265,9 +265,7 @@ export const makeFootprintRecorder = (probe: FileProbe): Effect.Effect<Footprint
|
|
|
265
265
|
|
|
266
266
|
const snapshot = drainAll.pipe(Effect.andThen(Ref.get(facts)), Effect.map(footprintOf));
|
|
267
267
|
|
|
268
|
-
const consume = snapshot.pipe(
|
|
269
|
-
Effect.flatMap((footprint) => Ref.set(facts, emptyFacts()).pipe(Effect.as(footprint))),
|
|
270
|
-
);
|
|
268
|
+
const consume = snapshot.pipe(Effect.tap(() => Ref.set(facts, emptyFacts())));
|
|
271
269
|
|
|
272
270
|
const worker = Effect.forever(
|
|
273
271
|
Effect.gen(function* () {
|
|
@@ -295,7 +293,7 @@ export class FootprintRecorder extends Context.Service<
|
|
|
295
293
|
readonly snapshot: Effect.Effect<BatchFootprint>;
|
|
296
294
|
readonly consume: Effect.Effect<BatchFootprint>;
|
|
297
295
|
}
|
|
298
|
-
>()("tracker/FootprintRecorder") {
|
|
296
|
+
>()("@ftrdotdev/pi-tracker/compaction/footprint/FootprintRecorder") {
|
|
299
297
|
static readonly layer = (probe: FileProbe): Layer.Layer<FootprintRecorder> =>
|
|
300
298
|
Layer.effect(
|
|
301
299
|
FootprintRecorder,
|
|
@@ -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, Option, PlatformError } from "effect";
|
|
3
6
|
import * as FileSystem from "effect/FileSystem";
|
|
@@ -272,7 +275,8 @@ it.effect("load resolves every value from the shared contract fixture", () =>
|
|
|
272
275
|
|
|
273
276
|
it.effect("load reads the enabled, classifier, and probability keys the contract names", () =>
|
|
274
277
|
Effect.gen(function* () {
|
|
275
|
-
const
|
|
278
|
+
const fixtureText = yield* readFixture;
|
|
279
|
+
const parsed = JSON.parse(fixtureText) as {
|
|
276
280
|
smartCompaction: Record<string, unknown>;
|
|
277
281
|
};
|
|
278
282
|
assert.strictEqual(SMART_COMPACTION_KEY in parsed, true);
|