@teamscala/service-boot 0.23.291 → 0.23.293
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/package.json +10 -2
- package/src/asset-proxy.test.ts +32 -0
- package/src/asset-proxy.ts +1 -1
- package/src/attach-transfers-upload.d.ts +1 -1
- package/src/attach-transfers-upload.test.ts +25 -0
- package/src/attach-transfers-upload.ts +2 -2
- package/src/fn-routers/cache-admin-router.d.ts +2 -2
- package/src/fn-routers/proposal-send-router.d.ts +2 -2
- package/src/fn-routers/public-agreement-router.d.ts +40 -32
- package/src/fn-routers/public-gpt-session-router.d.ts +20 -2
- package/src/fn-routers/public-gpt-session-router.ts +1 -1
- package/src/fn-routers/sign-in-flow-router.d.ts +41 -9
- package/src/fn-routers/task-sync-projection.d.ts +120 -0
- package/src/fn-routers/task-sync-projection.test.ts +123 -0
- package/src/fn-routers/task-sync-projection.ts +201 -0
- package/src/fn-routers/task-sync-router.d.ts +1 -70
- package/src/fn-routers/task-sync-router.test.ts +41 -3
- package/src/fn-routers/task-sync-router.ts +46 -139
- package/src/pg-boss-handler-registry.d.ts +1 -1
- package/src/register-registry-page-route/graph-cache.d.ts +2 -2
- package/src/resource-not-found.test.ts +47 -0
- package/src/resource-not-found.ts +1 -1
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @system service-boot
|
|
3
|
+
* @status handwritten
|
|
4
|
+
* @edit edit directly
|
|
5
|
+
*
|
|
6
|
+
* Co-located tests for the task-sync PROJECTION pure helpers. The module was
|
|
7
|
+
* split out of task-sync-router.ts precisely so this half — the WHAT-changes
|
|
8
|
+
* decisions — is unit-testable with no database (the router only EXECUTES the
|
|
9
|
+
* plan). Covers status mapping, the blocked-row preservation rule, key
|
|
10
|
+
* resolution, update-target resolution + full reconciliation planning.
|
|
11
|
+
*/
|
|
12
|
+
import { describe, expect, it } from "bun:test";
|
|
13
|
+
import {
|
|
14
|
+
STATUS_TO_WORK_ITEM,
|
|
15
|
+
normalizeStatus,
|
|
16
|
+
planReconcile,
|
|
17
|
+
resolveProjectedStatus,
|
|
18
|
+
resolveTaskUpdateTarget,
|
|
19
|
+
subtaskKey,
|
|
20
|
+
type ReconcilePlan,
|
|
21
|
+
} from "./task-sync-projection.ts";
|
|
22
|
+
import type { TaskListItem } from "./task-sync-router.ts";
|
|
23
|
+
|
|
24
|
+
describe("STATUS_TO_WORK_ITEM", () => {
|
|
25
|
+
it("maps the three CLI statuses to work_items status enum values", () => {
|
|
26
|
+
expect(STATUS_TO_WORK_ITEM.pending).toBe("todo");
|
|
27
|
+
expect(STATUS_TO_WORK_ITEM.in_progress).toBe("in-progress");
|
|
28
|
+
expect(STATUS_TO_WORK_ITEM.completed).toBe("done");
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe("normalizeStatus", () => {
|
|
33
|
+
it("maps work_items statuses back to the normalized CLI form", () => {
|
|
34
|
+
expect(normalizeStatus("todo")).toBe("pending");
|
|
35
|
+
expect(normalizeStatus("in-progress")).toBe("in_progress");
|
|
36
|
+
expect(normalizeStatus("done")).toBe("completed");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("collapses unknown / null / internal statuses to pending", () => {
|
|
40
|
+
expect(normalizeStatus(null)).toBe("pending");
|
|
41
|
+
expect(normalizeStatus("blocked")).toBe("pending");
|
|
42
|
+
expect(normalizeStatus("some-internal-state")).toBe("pending");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe("resolveProjectedStatus", () => {
|
|
47
|
+
it("preserves a blocked row when the CLI list can only express it as todo", () => {
|
|
48
|
+
expect(resolveProjectedStatus("blocked", "todo")).toBe("blocked");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("lets real CLI transitions (in-progress, done) win normally", () => {
|
|
52
|
+
expect(resolveProjectedStatus("blocked", "in-progress")).toBe("in-progress");
|
|
53
|
+
expect(resolveProjectedStatus("todo", "done")).toBe("done");
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("subtaskKey", () => {
|
|
58
|
+
it("prefers mark, then content, then title", () => {
|
|
59
|
+
expect(subtaskKey({ mark: "1", content: "c", title: "t" })).toBe("1");
|
|
60
|
+
expect(subtaskKey({ content: "c", title: "t" })).toBe("c");
|
|
61
|
+
expect(subtaskKey({ content: "", title: "t" })).toBe("t");
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("resolveTaskUpdateTarget", () => {
|
|
66
|
+
const existing = [
|
|
67
|
+
{ id: "a", title: "Alpha", kind_data: { task_sync: { mark: "1" } } },
|
|
68
|
+
{ id: "b", title: "Beta", kind_data: null },
|
|
69
|
+
];
|
|
70
|
+
it("updates by stamped mark", () => {
|
|
71
|
+
expect(resolveTaskUpdateTarget(existing, { taskId: "1", subject: "anything" })).toEqual({
|
|
72
|
+
op: "update",
|
|
73
|
+
id: "a",
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
it("updates by exact title when no mark matches", () => {
|
|
77
|
+
expect(resolveTaskUpdateTarget(existing, { taskId: "9", subject: "Beta" })).toEqual({
|
|
78
|
+
op: "update",
|
|
79
|
+
id: "b",
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it("heals when nothing matches but a subject can rebuild the row", () => {
|
|
83
|
+
expect(resolveTaskUpdateTarget(existing, { taskId: "9", subject: "Gamma" })).toEqual({
|
|
84
|
+
op: "heal",
|
|
85
|
+
title: "Gamma",
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
it("discards when nothing matches and there is no subject", () => {
|
|
89
|
+
expect(resolveTaskUpdateTarget(existing, { taskId: "9" })).toEqual({ op: "discard" });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
describe("planReconcile", () => {
|
|
94
|
+
it("creates new items, updates changed ones, deletes unseen ones", () => {
|
|
95
|
+
const existing = [
|
|
96
|
+
{ id: "1", kind: "subtask", parent_id: null, organisation_id: "org", title: "Keep", status: "todo", completed: false, position: "0", kind_data: {} },
|
|
97
|
+
{ id: "2", kind: "subtask", parent_id: null, organisation_id: "org", title: "Gone", status: "todo", completed: false, position: "1", kind_data: {} },
|
|
98
|
+
];
|
|
99
|
+
const incoming: TaskListItem[] = [
|
|
100
|
+
{ content: "Keep", status: "completed", mark: undefined },
|
|
101
|
+
{ content: "New", status: "pending", mark: undefined },
|
|
102
|
+
];
|
|
103
|
+
const plan: ReconcilePlan = planReconcile(existing, incoming);
|
|
104
|
+
// "Keep" changed (todo→done) → update; "Gone" absent → delete; "New" → create.
|
|
105
|
+
expect(plan.toUpdate.map((u) => u.id)).toEqual(["1"]);
|
|
106
|
+
expect(plan.toUpdate[0]?.status).toBe("done");
|
|
107
|
+
expect(plan.toCreate.map((c) => c.content)).toEqual(["New"]);
|
|
108
|
+
expect(plan.toDelete).toEqual(["2"]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("preserves a blocked existing row against an incoming todo", () => {
|
|
112
|
+
const existing = [
|
|
113
|
+
{ id: "1", kind: "subtask", parent_id: null, organisation_id: "org", title: "X", status: "blocked", completed: false, position: "5", kind_data: {} },
|
|
114
|
+
];
|
|
115
|
+
// Incoming pending (-> "todo") at a DIFFERENT position so an update fires;
|
|
116
|
+
// without the preservation rule the row would be rewritten to "todo",
|
|
117
|
+
// silently destroying the block.
|
|
118
|
+
const incoming: TaskListItem[] = [{ content: "X", status: "pending", mark: undefined }];
|
|
119
|
+
const plan = planReconcile(existing, incoming, "src");
|
|
120
|
+
expect(plan.toUpdate.length).toBe(1);
|
|
121
|
+
expect(plan.toUpdate[0]?.status).toBe("blocked");
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @system service-boot
|
|
3
|
+
* @status handwritten
|
|
4
|
+
* @edit edit directly
|
|
5
|
+
*
|
|
6
|
+
* The task-sync PROJECTION: how a CLI's task list maps onto `work_items` rows,
|
|
7
|
+
* and what reconciling one against the other should do.
|
|
8
|
+
*
|
|
9
|
+
* Split out of `task-sync-router.ts`, which had grown past the 1000-line budget
|
|
10
|
+
* and so could not be committed by anyone touching it. The seam is real rather
|
|
11
|
+
* than arbitrary: everything here is PURE and decides WHAT should change, while
|
|
12
|
+
* the router owns the ORPC surface and performs the writes. That is exactly why
|
|
13
|
+
* this half is directly testable with no database.
|
|
14
|
+
*
|
|
15
|
+
* CAPABILITY HARVEST (capability-harvest-on-split): APP-LOCAL, not a capability
|
|
16
|
+
* candidate. Checked against the 14 platform singletons and the package catalog
|
|
17
|
+
* — nothing generic to fold into, and the doctrine test fails: no unrelated app
|
|
18
|
+
* could install this unmodified, because every export is bound to the
|
|
19
|
+
* `work_items` schema and task-sync's own contract (STATUS_TO_WORK_ITEM encodes
|
|
20
|
+
* the work_items status enum, subtaskKey is this projection's key convention,
|
|
21
|
+
* planReconcile diffs against work_items subtask rows).
|
|
22
|
+
*
|
|
23
|
+
* The near-miss is worth naming so the next reader does not re-derive it: the
|
|
24
|
+
* SHAPE — diff a desired list against existing rows into create/update/delete —
|
|
25
|
+
* is generic, and `document-signing` is precedent for lifting a pure domain half
|
|
26
|
+
* out of service-boot into a package. It stays here because it has exactly one
|
|
27
|
+
* consumer; extracting it now would be speculative packaging, which
|
|
28
|
+
* platform-capabilities treats as drift. Revisit if a SECOND surface needs
|
|
29
|
+
* list-against-rows reconciliation — then the generic diff core (not the
|
|
30
|
+
* work_items-specific mapping) is what earns a package.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
import type { TaskListItem, WorkItem } from "./task-sync-router.ts";
|
|
34
|
+
|
|
35
|
+
// TodoWrite-style status (the normalized form) → work_items.status (DB enum).
|
|
36
|
+
// The DB enum uses a hyphen for the active state ("in-progress"); see
|
|
37
|
+
// COLUMN_ENUMS["work_items.status"] in db-validation.
|
|
38
|
+
export const STATUS_TO_WORK_ITEM: Record<TaskListItem["status"], string> = {
|
|
39
|
+
pending: "todo",
|
|
40
|
+
in_progress: "in-progress",
|
|
41
|
+
completed: "done",
|
|
42
|
+
};
|
|
43
|
+
// work_items.status → normalized. Unknown/internal statuses collapse to pending.
|
|
44
|
+
const WORK_ITEM_TO_STATUS: Record<string, TaskListItem["status"]> = {
|
|
45
|
+
todo: "pending",
|
|
46
|
+
"in-progress": "in_progress",
|
|
47
|
+
active: "in_progress",
|
|
48
|
+
done: "completed",
|
|
49
|
+
completed: "completed",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export function normalizeStatus(s: string | null): TaskListItem["status"] {
|
|
53
|
+
return (s && WORK_ITEM_TO_STATUS[s]) || "pending";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Decide the status to WRITE for an existing row, given what the CLI list says.
|
|
58
|
+
*
|
|
59
|
+
* The CLI task list has no `blocked` state, so a blocked row round-trips as
|
|
60
|
+
* `pending` (via `normalizeStatus`, which collapses unknown/internal statuses)
|
|
61
|
+
* and then maps back to `todo` — silently destroying the block. That is not a
|
|
62
|
+
* cosmetic drift: the stop gate reads these rows, so un-blocking one re-blocks
|
|
63
|
+
* the LANE from stopping, and the lane's only apparent fix is to touch the list
|
|
64
|
+
* again, which destroys it again.
|
|
65
|
+
*
|
|
66
|
+
* A `todo` arriving from the CLI therefore carries NO information: it is what
|
|
67
|
+
* the projection emits for every status it cannot represent, not an assertion
|
|
68
|
+
* that the work became un-blocked. `in-progress` and `done` are different —
|
|
69
|
+
* those are real transitions the CLI CAN express, so they win normally.
|
|
70
|
+
*
|
|
71
|
+
* Measured 2026-07-30: a lane set a row to `blocked` with a named blocker, the
|
|
72
|
+
* next TaskUpdate reset it to `todo`, and the stop gate reported the lane
|
|
73
|
+
* unfinished again — three turns of ping-pong before the cause was found.
|
|
74
|
+
*/
|
|
75
|
+
export function resolveProjectedStatus(
|
|
76
|
+
currentStatus: string | null | undefined,
|
|
77
|
+
incomingStatus: string,
|
|
78
|
+
): string {
|
|
79
|
+
if (currentStatus === "blocked" && incomingStatus === "todo") return "blocked";
|
|
80
|
+
return incomingStatus;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function subtaskKey(item: { mark?: string; content: string; title: string }): string {
|
|
84
|
+
return item.mark || item.content || item.title;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Pure decision for a TaskUpdate/TaskDelete: which existing subtask does this
|
|
89
|
+
* event address, and what should happen when none does. Extracted for the same
|
|
90
|
+
* reason planReconcile was — the handler should only EXECUTE, so the matching
|
|
91
|
+
* rule is unit-testable.
|
|
92
|
+
*
|
|
93
|
+
* Three resolutions:
|
|
94
|
+
* - `update` — matched by mark, or (mark absent/unstamped) by exact title.
|
|
95
|
+
* - `heal` — nothing matched but the event carries a subject, so the row can
|
|
96
|
+
* be reconstructed. Covers a TaskCreate that silently produced no
|
|
97
|
+
* subtask, which previously orphaned the task forever.
|
|
98
|
+
* - `discard` — nothing matched and there is no subject to rebuild a title from.
|
|
99
|
+
*
|
|
100
|
+
* Measured 2026-07-28: marks "1" and "3" were stamped for one lane while mark
|
|
101
|
+
* "2" was never written at all, and every later update for it was dropped as
|
|
102
|
+
* `no-matching-subtask` — 26 of 30 tasksync discards in six hours, across seven
|
|
103
|
+
* distinct lane sessions, were that one reason.
|
|
104
|
+
*/
|
|
105
|
+
export function resolveTaskUpdateTarget(
|
|
106
|
+
existing: Array<{ id: string; title: string; kind_data?: Record<string, unknown> | null }>,
|
|
107
|
+
evt: { taskId: string; subject?: string },
|
|
108
|
+
): { op: "update"; id: string } | { op: "heal"; title: string } | { op: "discard" } {
|
|
109
|
+
const byMark = existing.find(
|
|
110
|
+
(s) =>
|
|
111
|
+
evt.taskId &&
|
|
112
|
+
(s.kind_data as { task_sync?: { mark?: string } } | null)?.task_sync?.mark === evt.taskId,
|
|
113
|
+
);
|
|
114
|
+
if (byMark) return { op: "update", id: byMark.id };
|
|
115
|
+
const subject = (evt.subject ?? "").trim();
|
|
116
|
+
if (subject) {
|
|
117
|
+
const byTitle = existing.find((s) => s.title === subject);
|
|
118
|
+
if (byTitle) return { op: "update", id: byTitle.id };
|
|
119
|
+
return { op: "heal", title: subject };
|
|
120
|
+
}
|
|
121
|
+
return { op: "discard" };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Pure reconciliation plan: given the lane's EXISTING subtasks and its INCOMING
|
|
126
|
+
* (current) task list, compute the create/update/delete ops that make the
|
|
127
|
+
* subtask set match the list — WITHOUT touching prisma. Extracted so the
|
|
128
|
+
* matching/status/positioning logic is unit-testable (the handler only executes
|
|
129
|
+
* the plan). Matching is by stable mark when the CLI provides one, else by
|
|
130
|
+
* content. Position follows incoming index, so a reorder is an update.
|
|
131
|
+
*/
|
|
132
|
+
export interface ReconcilePlan {
|
|
133
|
+
toCreate: Array<{
|
|
134
|
+
content: string;
|
|
135
|
+
status: string;
|
|
136
|
+
completed: boolean;
|
|
137
|
+
position: string;
|
|
138
|
+
kind_data: Record<string, unknown>;
|
|
139
|
+
}>;
|
|
140
|
+
toUpdate: Array<{
|
|
141
|
+
id: string;
|
|
142
|
+
content: string;
|
|
143
|
+
status: string;
|
|
144
|
+
completed: boolean;
|
|
145
|
+
position: string;
|
|
146
|
+
kind_data: Record<string, unknown>;
|
|
147
|
+
}>;
|
|
148
|
+
toDelete: string[];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export function planReconcile(
|
|
152
|
+
existing: WorkItem[],
|
|
153
|
+
incoming: TaskListItem[],
|
|
154
|
+
source?: string,
|
|
155
|
+
): ReconcilePlan {
|
|
156
|
+
const byKey = new Map<string, WorkItem>();
|
|
157
|
+
for (const s of existing) {
|
|
158
|
+
const mark = (s.kind_data?.task_sync as { mark?: string } | undefined)?.mark;
|
|
159
|
+
byKey.set(subtaskKey({ mark, content: "", title: s.title }), s);
|
|
160
|
+
}
|
|
161
|
+
const toCreate: ReconcilePlan["toCreate"] = [];
|
|
162
|
+
const toUpdate: ReconcilePlan["toUpdate"] = [];
|
|
163
|
+
const seen = new Set<string>();
|
|
164
|
+
for (let i = 0; i < incoming.length; i++) {
|
|
165
|
+
const item = incoming[i];
|
|
166
|
+
const content = (item.content ?? "").trim();
|
|
167
|
+
if (!content) continue;
|
|
168
|
+
const key = subtaskKey({ mark: item.mark, content, title: content });
|
|
169
|
+
const incomingStatus = STATUS_TO_WORK_ITEM[item.status] ?? "todo";
|
|
170
|
+
const completed = item.status === "completed";
|
|
171
|
+
const position = String(i);
|
|
172
|
+
const taskSync = { task_sync: { mark: item.mark, source } };
|
|
173
|
+
const match = byKey.get(key);
|
|
174
|
+
if (match) {
|
|
175
|
+
seen.add(match.id);
|
|
176
|
+
// A blocked row must survive a list the CLI cannot express it in.
|
|
177
|
+
const status = resolveProjectedStatus(match.status, incomingStatus);
|
|
178
|
+
const changed =
|
|
179
|
+
match.title !== content ||
|
|
180
|
+
match.status !== status ||
|
|
181
|
+
(match.completed ?? false) !== completed ||
|
|
182
|
+
match.position !== position;
|
|
183
|
+
if (changed) {
|
|
184
|
+
toUpdate.push({
|
|
185
|
+
id: match.id,
|
|
186
|
+
content,
|
|
187
|
+
status,
|
|
188
|
+
completed,
|
|
189
|
+
position,
|
|
190
|
+
kind_data: { ...match.kind_data, ...taskSync },
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
} else {
|
|
194
|
+
// A row being created has no prior status to preserve, so the incoming
|
|
195
|
+
// one stands unmodified.
|
|
196
|
+
toCreate.push({ content, status: incomingStatus, completed, position, kind_data: taskSync });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const toDelete = existing.filter((s) => !seen.has(s.id)).map((s) => s.id);
|
|
200
|
+
return { toCreate, toUpdate, toDelete };
|
|
201
|
+
}
|
|
@@ -81,7 +81,7 @@ export interface LaneIdentity {
|
|
|
81
81
|
*/
|
|
82
82
|
organisation_id?: string;
|
|
83
83
|
}
|
|
84
|
-
interface WorkItem {
|
|
84
|
+
export interface WorkItem {
|
|
85
85
|
id: string;
|
|
86
86
|
kind: string;
|
|
87
87
|
parent_id: string | null;
|
|
@@ -104,8 +104,6 @@ export declare function untrackedRunForPane(pane: string): {
|
|
|
104
104
|
};
|
|
105
105
|
tracked_task_id: null;
|
|
106
106
|
};
|
|
107
|
-
export declare const STATUS_TO_WORK_ITEM: Record<TaskListItem["status"], string>;
|
|
108
|
-
export declare function normalizeStatus(s: string | null): TaskListItem["status"];
|
|
109
107
|
/**
|
|
110
108
|
* Resolve the org a lane's task is created under. Explicit when the lane knows
|
|
111
109
|
* its org (a dispatched fleet lane carries one); defaults to the platform org
|
|
@@ -154,72 +152,6 @@ export declare function classifyTaskHookEvent(evt: {
|
|
|
154
152
|
hook_event_name?: unknown;
|
|
155
153
|
task_subject?: unknown;
|
|
156
154
|
}): "completed" | "created" | "tool";
|
|
157
|
-
export declare function subtaskKey(item: {
|
|
158
|
-
mark?: string;
|
|
159
|
-
content: string;
|
|
160
|
-
title: string;
|
|
161
|
-
}): string;
|
|
162
|
-
/**
|
|
163
|
-
* Pure decision for a TaskUpdate/TaskDelete: which existing subtask does this
|
|
164
|
-
* event address, and what should happen when none does. Extracted for the same
|
|
165
|
-
* reason planReconcile was — the handler should only EXECUTE, so the matching
|
|
166
|
-
* rule is unit-testable.
|
|
167
|
-
*
|
|
168
|
-
* Three resolutions:
|
|
169
|
-
* - `update` — matched by mark, or (mark absent/unstamped) by exact title.
|
|
170
|
-
* - `heal` — nothing matched but the event carries a subject, so the row can
|
|
171
|
-
* be reconstructed. Covers a TaskCreate that silently produced no
|
|
172
|
-
* subtask, which previously orphaned the task forever.
|
|
173
|
-
* - `discard` — nothing matched and there is no subject to rebuild a title from.
|
|
174
|
-
*
|
|
175
|
-
* Measured 2026-07-28: marks "1" and "3" were stamped for one lane while mark
|
|
176
|
-
* "2" was never written at all, and every later update for it was dropped as
|
|
177
|
-
* `no-matching-subtask` — 26 of 30 tasksync discards in six hours, across seven
|
|
178
|
-
* distinct lane sessions, were that one reason.
|
|
179
|
-
*/
|
|
180
|
-
export declare function resolveTaskUpdateTarget(existing: Array<{
|
|
181
|
-
id: string;
|
|
182
|
-
title: string;
|
|
183
|
-
kind_data?: Record<string, unknown> | null;
|
|
184
|
-
}>, evt: {
|
|
185
|
-
taskId: string;
|
|
186
|
-
subject?: string;
|
|
187
|
-
}): {
|
|
188
|
-
op: "update";
|
|
189
|
-
id: string;
|
|
190
|
-
} | {
|
|
191
|
-
op: "heal";
|
|
192
|
-
title: string;
|
|
193
|
-
} | {
|
|
194
|
-
op: "discard";
|
|
195
|
-
};
|
|
196
|
-
/**
|
|
197
|
-
* Pure reconciliation plan: given the lane's EXISTING subtasks and its INCOMING
|
|
198
|
-
* (current) task list, compute the create/update/delete ops that make the
|
|
199
|
-
* subtask set match the list — WITHOUT touching prisma. Extracted so the
|
|
200
|
-
* matching/status/positioning logic is unit-testable (the handler only executes
|
|
201
|
-
* the plan). Matching is by stable mark when the CLI provides one, else by
|
|
202
|
-
* content. Position follows incoming index, so a reorder is an update.
|
|
203
|
-
*/
|
|
204
|
-
export interface ReconcilePlan {
|
|
205
|
-
toCreate: Array<{
|
|
206
|
-
content: string;
|
|
207
|
-
status: string;
|
|
208
|
-
completed: boolean;
|
|
209
|
-
position: string;
|
|
210
|
-
kind_data: Record<string, unknown>;
|
|
211
|
-
}>;
|
|
212
|
-
toUpdate: Array<{
|
|
213
|
-
id: string;
|
|
214
|
-
content: string;
|
|
215
|
-
status: string;
|
|
216
|
-
completed: boolean;
|
|
217
|
-
position: string;
|
|
218
|
-
kind_data: Record<string, unknown>;
|
|
219
|
-
}>;
|
|
220
|
-
toDelete: string[];
|
|
221
|
-
}
|
|
222
|
-
export declare function planReconcile(existing: WorkItem[], incoming: TaskListItem[], source?: string): ReconcilePlan;
|
|
223
155
|
export declare const taskSyncRouter: {
|
|
224
156
|
/**
|
|
225
157
|
* Bind (create-or-confirm) the task a lane owns. Called from a SessionStart
|
|
@@ -373,4 +305,3 @@ export declare const taskSyncRouter: {
|
|
|
373
305
|
notified: boolean;
|
|
374
306
|
}>, Record<never, never>, Record<never, never>>;
|
|
375
307
|
};
|
|
376
|
-
export {};
|
|
@@ -13,11 +13,11 @@ import {
|
|
|
13
13
|
resolveTaskUpdateTarget,
|
|
14
14
|
planReconcile,
|
|
15
15
|
normalizeStatus,
|
|
16
|
+
resolveProjectedStatus,
|
|
16
17
|
subtaskKey,
|
|
17
18
|
STATUS_TO_WORK_ITEM,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} from "./task-sync-router.ts";
|
|
19
|
+
} from "./task-sync-projection.ts";
|
|
20
|
+
import { type TaskListItem, upsertFromTaskListInput } from "./task-sync-router.ts";
|
|
21
21
|
import * as v from "valibot";
|
|
22
22
|
|
|
23
23
|
interface WorkItemLike {
|
|
@@ -309,3 +309,41 @@ describe("task-sync upsertFromTaskListInput schema", () => {
|
|
|
309
309
|
expect(() => v.parse(upsertFromTaskListInput, { task_list: [] })).toThrow();
|
|
310
310
|
});
|
|
311
311
|
});
|
|
312
|
+
|
|
313
|
+
describe("a blocked row survives a CLI list that cannot express it", () => {
|
|
314
|
+
it("an incoming todo does NOT overwrite a blocked row", () => {
|
|
315
|
+
// The CLI emits todo/pending for every status it cannot represent, so a
|
|
316
|
+
// todo arriving for a blocked row asserts nothing about the work.
|
|
317
|
+
expect(resolveProjectedStatus("blocked", "todo")).toBe("blocked");
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("real transitions the CLI CAN express still win", () => {
|
|
321
|
+
// in-progress and done are genuine user signals, not projection artifacts.
|
|
322
|
+
expect(resolveProjectedStatus("blocked", "in-progress")).toBe("in-progress");
|
|
323
|
+
expect(resolveProjectedStatus("blocked", "done")).toBe("done");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("a non-blocked row is unaffected", () => {
|
|
327
|
+
expect(resolveProjectedStatus("todo", "in-progress")).toBe("in-progress");
|
|
328
|
+
expect(resolveProjectedStatus("in-progress", "done")).toBe("done");
|
|
329
|
+
expect(resolveProjectedStatus("done", "todo")).toBe("todo");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("a missing current status never resurrects a block", () => {
|
|
333
|
+
expect(resolveProjectedStatus(null, "todo")).toBe("todo");
|
|
334
|
+
expect(resolveProjectedStatus(undefined, "todo")).toBe("todo");
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("planReconcile leaves a blocked subtask blocked when the list says pending", () => {
|
|
338
|
+
// The end-to-end shape: this is what re-blocked the lane three times.
|
|
339
|
+
const plan = planReconcile(
|
|
340
|
+
[{ mark: "1", content: "Deploy the fix", status: "pending" }],
|
|
341
|
+
[{ id: "row-1", title: "Deploy the fix", status: "blocked", completed: false, position: "0", kind_data: { task_sync: { mark: "1" } } }] as never,
|
|
342
|
+
"claude-code",
|
|
343
|
+
);
|
|
344
|
+
const update = plan.toUpdate.find((u) => u.id === "row-1");
|
|
345
|
+
|
|
346
|
+
// Either untouched, or updated while KEEPING blocked — never downgraded.
|
|
347
|
+
expect(update?.status ?? "blocked").toBe("blocked");
|
|
348
|
+
});
|
|
349
|
+
});
|