@teamscala/service-boot 0.23.317 → 0.23.319
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 +526 -526
- package/src/agreement-gate.ts +12 -0
- package/src/auth-gate.test.ts +70 -0
- package/src/auth-gate.ts +68 -6
- package/src/build-client-assets.test.ts +1 -1
- package/src/build-client-assets.ts +1 -1
- package/src/discover-blocks.ts +1 -1
- package/src/fn-routers/index.ts +2 -0
- package/src/fn-routers/task-sync-assign.test.ts +123 -8
- package/src/fn-routers/task-sync-assign.ts +105 -18
- package/src/fn-routers/task-sync-bind.test.ts +18 -18
- package/src/fn-routers/task-sync-brief.test.ts +65 -22
- package/src/fn-routers/task-sync-brief.ts +77 -23
- package/src/fn-routers/task-sync-close.test.ts +44 -0
- package/src/fn-routers/task-sync-close.ts +82 -0
- package/src/fn-routers/task-sync-dispatch.test.ts +51 -33
- package/src/fn-routers/task-sync-hook-lifecycle.test.ts +204 -0
- package/src/fn-routers/task-sync-lane.test.ts +36 -0
- package/src/fn-routers/task-sync-projection.test.ts +26 -0
- package/src/fn-routers/task-sync-projection.ts +51 -0
- package/src/fn-routers/task-sync-rename.test.ts +53 -0
- package/src/fn-routers/task-sync-rename.ts +111 -0
- package/src/fn-routers/task-sync-router.test.ts +14 -2
- package/src/handlers/singleton-tools-currency-watch.ts +114 -11
- package/src/handlers/sweep-host-cache.test.ts +133 -0
- package/src/handlers/sweep-host-cache.ts +143 -26
- package/src/install-logging.ts +3 -0
- package/src/mount-orpc-router.ts +1 -1
- package/src/register-api-routes.ts +8 -2
- package/src/register-page-routes.ts +0 -3
- package/src/resolve-brand-favicon.ts +1 -1
- package/src/resource-not-found.ts +10 -0
- package/src/serve/stamp-transport-identity.test.ts +24 -0
- package/src/serve/stamp-transport-identity.ts +20 -7
- package/src/two-phase-boot.ts +85 -17
- package/src/two-phase-health-gate-client-only.test.ts +77 -0
- package/src/two-phase-health-gate.test.ts +13 -2
- package/src/agreement-gate.d.ts +0 -19
- package/src/asset-cache-key.d.ts +0 -11
- package/src/asset-optimize.d.ts +0 -17
- package/src/asset-proxy.d.ts +0 -11
- package/src/asset-social-card.d.ts +0 -17
- package/src/attach-agreement-magic.d.ts +0 -20
- package/src/attach-portal-members.d.ts +0 -23
- package/src/attach-proposal-accept.d.ts +0 -26
- package/src/attach-proposal-magic.d.ts +0 -18
- package/src/attach-transfers-upload.d.ts +0 -27
- package/src/auth-gate.d.ts +0 -28
- package/src/bind-page-handler.d.ts +0 -18
- package/src/build-client-assets/input-hashing.d.ts +0 -25
- package/src/build-client-assets/source-candidates.d.ts +0 -27
- package/src/build-client-assets.d.ts +0 -50
- package/src/compose-page-title.d.ts +0 -41
- package/src/content-gate/access.d.ts +0 -15
- package/src/content-gate/config-types.d.ts +0 -99
- package/src/content-gate/gate.d.ts +0 -13
- package/src/content-gate/parse-cookie.d.ts +0 -9
- package/src/content-gate/token.d.ts +0 -48
- package/src/content-page-floor.d.ts +0 -39
- package/src/discover-blocks.d.ts +0 -28
- package/src/expand-roster.d.ts +0 -34
- package/src/fn-routers/agreement-completion-email.d.ts +0 -14
- package/src/fn-routers/agreement-send-router.d.ts +0 -82
- package/src/fn-routers/ai-health-router.d.ts +0 -35
- package/src/fn-routers/auth-router.d.ts +0 -47
- package/src/fn-routers/cache-admin-router.d.ts +0 -57
- package/src/fn-routers/chat-session-router.d.ts +0 -219
- package/src/fn-routers/email-defaults.d.ts +0 -1
- package/src/fn-routers/email-link-ttl.d.ts +0 -1
- package/src/fn-routers/index.d.ts +0 -18
- package/src/fn-routers/panel-data-router.d.ts +0 -19
- package/src/fn-routers/persist-chat-messages.d.ts +0 -36
- package/src/fn-routers/plans-router.d.ts +0 -25
- package/src/fn-routers/proposal-send-router.d.ts +0 -58
- package/src/fn-routers/public-agreement-router.d.ts +0 -289
- package/src/fn-routers/public-assessment-router.d.ts +0 -68
- package/src/fn-routers/public-gpt-session-router.d.ts +0 -143
- package/src/fn-routers/sign-in-flow-router.d.ts +0 -107
- package/src/fn-routers/task-sync-assign.d.ts +0 -276
- package/src/fn-routers/task-sync-brief.d.ts +0 -69
- package/src/fn-routers/task-sync-dispatch.d.ts +0 -61
- package/src/fn-routers/task-sync-dispatch.ts +0 -124
- package/src/fn-routers/task-sync-lane.d.ts +0 -28
- package/src/fn-routers/task-sync-lane.ts +0 -91
- package/src/fn-routers/task-sync-projection.d.ts +0 -121
- package/src/fn-routers/task-sync-router.d.ts +0 -375
- package/src/fn-routers/task-sync-router.ts +0 -1011
- package/src/fn-routers/tasks-router.d.ts +0 -25
- package/src/fn-routers/user-preferences-router.d.ts +0 -77
- package/src/fn-routers/work-items-router.d.ts +0 -102
- package/src/gate-ttls.d.ts +0 -6
- package/src/gpt-gate.d.ts +0 -25
- package/src/handlers/bun-stable-watch.d.ts +0 -1
- package/src/handlers/pane-outbox-drain.d.ts +0 -1
- package/src/handlers/projects-digest.d.ts +0 -26
- package/src/handlers/prune-stale-data.d.ts +0 -30
- package/src/handlers/registry-stale-inactive-sweep.d.ts +0 -1
- package/src/handlers/scala-tools-currency-watch.d.ts +0 -1
- package/src/handlers/singleton-tools-currency-watch.d.ts +0 -1
- package/src/handlers/sweep-event-log.d.ts +0 -1
- package/src/handlers/sweep-host-cache.d.ts +0 -1
- package/src/handlers/upstream-issue-sync.d.ts +0 -1
- package/src/handlers/whatsapp-liveness-logic.d.ts +0 -34
- package/src/handlers/whatsapp-liveness.d.ts +0 -4
- package/src/hono-error-handler.d.ts +0 -25
- package/src/install-harness.d.ts +0 -45
- package/src/install-logging.d.ts +0 -34
- package/src/load-service-install-row.d.ts +0 -24
- package/src/load-service-prisma-client.d.ts +0 -18
- package/src/mount-orpc-router.d.ts +0 -15
- package/src/mount-server-packages.d.ts +0 -29
- package/src/mount.d.ts +0 -9
- package/src/mutable-app-ref.d.ts +0 -44
- package/src/page-route-shell-types.d.ts +0 -12
- package/src/page-server-orpc/audit-revert-router.d.ts +0 -37
- package/src/page-server-orpc/hub-mcp-client.d.ts +0 -12
- package/src/page-server-orpc/portal-diagnostics-router.d.ts +0 -49
- package/src/page-server-orpc/puck-pages-router.d.ts +0 -58
- package/src/page-server-orpc/server-client.d.ts +0 -16
- package/src/page-server-orpc/templates-router.d.ts +0 -34
- package/src/page-server-orpc/user-preferences-router.d.ts +0 -79
- package/src/pg-boss-handler-registry.d.ts +0 -27
- package/src/pg-boss-mount.d.ts +0 -42
- package/src/proposal-authorized-emails.d.ts +0 -28
- package/src/proposal-chat-inject.d.ts +0 -17
- package/src/proposal-gate.d.ts +0 -18
- package/src/read-html-template.d.ts +0 -38
- package/src/read-viewport-from-request.d.ts +0 -18
- package/src/readiness-gate.d.ts +0 -16
- package/src/register-api-routes.d.ts +0 -18
- package/src/register-crash-handlers.d.ts +0 -15
- package/src/register-page-routes.d.ts +0 -27
- package/src/register-page-server-client.d.ts +0 -11
- package/src/register-registry-page-route/ai-chat-prefetch.d.ts +0 -13
- package/src/register-registry-page-route/graph-cache.d.ts +0 -30
- package/src/register-registry-page-route/meta-title.d.ts +0 -2
- package/src/register-registry-page-route/proposal-approval-email-token.d.ts +0 -14
- package/src/register-registry-page-route/proposal-brand-stamping.d.ts +0 -28
- package/src/register-registry-page-route/resolve-page-data.d.ts +0 -1
- package/src/register-registry-page-route.d.ts +0 -27
- package/src/register-static-assets.d.ts +0 -13
- package/src/register-ws-routes.d.ts +0 -28
- package/src/resolve-app-base-url.d.ts +0 -13
- package/src/resolve-brand-favicon.d.ts +0 -28
- package/src/resolve-from-loader-config.d.ts +0 -32
- package/src/resolve-service-context.d.ts +0 -17
- package/src/resolve-service-port.d.ts +0 -75
- package/src/resolve-theme-mode.d.ts +0 -42
- package/src/resolvers/fetch-org-brand.d.ts +0 -2
- package/src/resolvers/portal-route-paths.d.ts +0 -39
- package/src/resolvers/website-by-host-map.d.ts +0 -12
- package/src/resource-chat-inject.d.ts +0 -46
- package/src/resource-not-found.d.ts +0 -60
- package/src/run-boot-hook-list.d.ts +0 -19
- package/src/run-boot-hooks.d.ts +0 -31
- package/src/scala-tools-currency-watchdog.d.ts +0 -10
- package/src/security-headers.d.ts +0 -12
- package/src/serve/serve.d.ts +0 -46
- package/src/serve/stamp-transport-identity.d.ts +0 -32
- package/src/server-error-page.d.ts +0 -29
- package/src/start-scheduled-jobs.d.ts +0 -18
- package/src/two-phase-boot.d.ts +0 -136
- package/src/types.d.ts +0 -46
- package/src/ui-service.d.ts +0 -46
- package/src/ws-boot-self-test.d.ts +0 -19
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @system service-boot
|
|
3
|
+
* @status handwritten
|
|
4
|
+
* @edit edit directly
|
|
5
|
+
*
|
|
6
|
+
* Lifecycle round-trip for the Claude Code per-item task projection:
|
|
7
|
+
* `upsertFromTaskHookHandler` (the extracted body of the upsertFromTaskHook
|
|
8
|
+
* ORPC handler) must carry a task through created -> in_progress -> completed ->
|
|
9
|
+
* deleted against an in-memory mock prisma, so `work_items` sees every state a
|
|
10
|
+
* task reaches (`task-projection-converges`). A projection that cannot express
|
|
11
|
+
* completion — or deletion — is an append-only log, and the operator cannot see
|
|
12
|
+
* what a lane is doing. The matcher covering TaskCreate|TaskUpdate|TaskDelete is
|
|
13
|
+
* what routes all three tool events here; these tests assert the body applies
|
|
14
|
+
* each one. Same mock-prisma shape as claim-orchestrator-session.test.ts.
|
|
15
|
+
*/
|
|
16
|
+
import { afterEach, beforeEach, describe, expect, it, mock } from "bun:test";
|
|
17
|
+
|
|
18
|
+
const recordEventMock = mock((_event: unknown) => {});
|
|
19
|
+
mock.module("@teamscala/event-log/record-event", () => ({ recordEvent: recordEventMock }));
|
|
20
|
+
mock.module("@teamscala/logger/app-loggers", () => ({
|
|
21
|
+
getAppLogger: () => ({
|
|
22
|
+
info: () => {},
|
|
23
|
+
warn: () => {},
|
|
24
|
+
error: () => {},
|
|
25
|
+
}),
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
const { upsertFromTaskHookHandler } = await import("./task-sync-router.ts");
|
|
29
|
+
|
|
30
|
+
/** A lane's parent task, returned by the mocked resolveLaneTask findFirst. */
|
|
31
|
+
const LANE_TASK = {
|
|
32
|
+
id: "task-1",
|
|
33
|
+
kind: "task",
|
|
34
|
+
parent_id: null,
|
|
35
|
+
organisation_id: "org-1",
|
|
36
|
+
title: "Test Lane",
|
|
37
|
+
status: "active",
|
|
38
|
+
completed: false,
|
|
39
|
+
position: null,
|
|
40
|
+
kind_data: { lane: { session: "ses-1", pane: "tmux:%1" } },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
function makePrisma() {
|
|
44
|
+
// In-memory subtask store, so the four states act on ONE evolving row.
|
|
45
|
+
const subtasks: Array<Record<string, unknown>> = [];
|
|
46
|
+
const findFirst = mock(async (args: { where: Record<string, unknown> }) => {
|
|
47
|
+
// resolveLaneTask asks for kind='task' + status active/archived; everything
|
|
48
|
+
// else (subtask lookups) returns null.
|
|
49
|
+
if (args.where?.kind === "task") return { ...LANE_TASK };
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
52
|
+
const findMany = mock(async (args: { where: Record<string, unknown> }) => {
|
|
53
|
+
const pid = args.where?.parent_id;
|
|
54
|
+
return subtasks.filter((s) => s.parent_id === pid);
|
|
55
|
+
});
|
|
56
|
+
const create = mock(async (args: { data: Record<string, unknown> }) => {
|
|
57
|
+
const row = { id: `s-${subtasks.length + 1}`, ...args.data };
|
|
58
|
+
subtasks.push(row);
|
|
59
|
+
return row;
|
|
60
|
+
});
|
|
61
|
+
const update = mock(async (args: { where: { id: string }; data: Record<string, unknown> }) => {
|
|
62
|
+
const row = subtasks.find((s) => s.id === args.where.id);
|
|
63
|
+
if (row) Object.assign(row, args.data);
|
|
64
|
+
return row ?? null;
|
|
65
|
+
});
|
|
66
|
+
const deleteMany = mock(async (args: { where: { id: { in: string[] } } }) => {
|
|
67
|
+
// Real Prisma form: where.id.in (a bare array on the scalar id is a
|
|
68
|
+
// validation error). Mirrors the canonical deleteMany in reconcileTaskList.
|
|
69
|
+
const ids = args.where?.id?.in ?? [];
|
|
70
|
+
let count = 0;
|
|
71
|
+
for (let i = subtasks.length - 1; i >= 0; i--) {
|
|
72
|
+
if (ids.includes(String(subtasks[i]?.id))) {
|
|
73
|
+
subtasks.splice(i, 1);
|
|
74
|
+
count++;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return { count };
|
|
78
|
+
});
|
|
79
|
+
return {
|
|
80
|
+
store: subtasks,
|
|
81
|
+
prisma: { work_items: { findFirst, findMany, create, update, deleteMany } },
|
|
82
|
+
mocks: { findFirst, findMany, create, update, deleteMany },
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** A lane context bound to a mock prisma, so each call site passes only the event. */
|
|
87
|
+
function bindCtx(prisma: unknown, session = "ses-1") {
|
|
88
|
+
const headers = new Headers();
|
|
89
|
+
headers.set("x-lane-session", session);
|
|
90
|
+
headers.set("x-lane-pane", "tmux:%1");
|
|
91
|
+
return { headers, prisma, user: undefined };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** makePrisma + a `hook(evt)` convenience bound to that prisma's session. */
|
|
95
|
+
function makeFixture() {
|
|
96
|
+
const fixture = makePrisma();
|
|
97
|
+
const hook = (evt: unknown) => upsertFromTaskHookHandler(evt, bindCtx(fixture.prisma));
|
|
98
|
+
return { ...fixture, hook };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
describe("upsertFromTaskHookHandler — full lifecycle round-trip", () => {
|
|
102
|
+
beforeEach(() => recordEventMock.mockClear());
|
|
103
|
+
|
|
104
|
+
it("created -> in_progress -> completed -> deleted all write through to one subtask", async () => {
|
|
105
|
+
const { hook, store, mocks } = makeFixture();
|
|
106
|
+
|
|
107
|
+
// 1. CREATED — PostToolUse:TaskCreate. The harness assigns the task id in
|
|
108
|
+
// tool_response.task.id; the projection must stamp it as the mark so every
|
|
109
|
+
// later state is mark-addressable.
|
|
110
|
+
const created = await hook({
|
|
111
|
+
tool_name: "TaskCreate",
|
|
112
|
+
hook_event_name: "PostToolUse",
|
|
113
|
+
tool_input: { subject: "Ship the fix" },
|
|
114
|
+
tool_response: { task: { id: "42" } },
|
|
115
|
+
});
|
|
116
|
+
expect(created).toEqual({ applied: true, op: "create", taskId: "42" });
|
|
117
|
+
expect(mocks.create).toHaveBeenCalledTimes(1);
|
|
118
|
+
const row = store[0];
|
|
119
|
+
expect(row.title).toBe("Ship the fix");
|
|
120
|
+
expect(row.status).toBe("todo");
|
|
121
|
+
expect((row.kind_data as { task_sync: { mark: string } }).task_sync.mark).toBe("42");
|
|
122
|
+
|
|
123
|
+
// 2. IN_PROGRESS — PostToolUse:TaskUpdate with status in_progress. Matched
|
|
124
|
+
// by the mark stamped at creation; the projection expresses it, it does
|
|
125
|
+
// not append a new row.
|
|
126
|
+
mocks.create.mockClear();
|
|
127
|
+
const inProgress = await hook({
|
|
128
|
+
tool_name: "TaskUpdate",
|
|
129
|
+
hook_event_name: "PostToolUse",
|
|
130
|
+
tool_input: { taskId: "42", status: "in_progress" },
|
|
131
|
+
});
|
|
132
|
+
expect(inProgress).toEqual({ applied: true, op: "update", taskId: "42" });
|
|
133
|
+
expect(mocks.create).not.toHaveBeenCalled();
|
|
134
|
+
expect(mocks.update).toHaveBeenCalledTimes(1);
|
|
135
|
+
expect(row.status).toBe("in-progress");
|
|
136
|
+
expect(row.completed).toBe(false);
|
|
137
|
+
expect(store).toHaveLength(1);
|
|
138
|
+
|
|
139
|
+
// 3. COMPLETED — PostToolUse:TaskUpdate with status completed. A projection
|
|
140
|
+
// that cannot express completion is an append-only log.
|
|
141
|
+
mocks.update.mockClear();
|
|
142
|
+
const done = await hook({
|
|
143
|
+
tool_name: "TaskUpdate",
|
|
144
|
+
hook_event_name: "PostToolUse",
|
|
145
|
+
tool_input: { taskId: "42", status: "completed" },
|
|
146
|
+
});
|
|
147
|
+
expect(done).toEqual({ applied: true, op: "update", taskId: "42" });
|
|
148
|
+
expect(mocks.update).toHaveBeenCalledTimes(1);
|
|
149
|
+
expect(row.status).toBe("done");
|
|
150
|
+
expect(row.completed).toBe(true);
|
|
151
|
+
expect(store).toHaveLength(1);
|
|
152
|
+
|
|
153
|
+
// 4. DELETED — PostToolUse:TaskDelete. The row leaves the projection; the
|
|
154
|
+
// list empties, which is the half a create-only projection can never do.
|
|
155
|
+
const deleted = await hook({
|
|
156
|
+
tool_name: "TaskDelete",
|
|
157
|
+
hook_event_name: "PostToolUse",
|
|
158
|
+
tool_input: { taskId: "42" },
|
|
159
|
+
});
|
|
160
|
+
expect(deleted).toEqual({ applied: true, op: "delete", taskId: "42" });
|
|
161
|
+
expect(mocks.deleteMany).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(store).toHaveLength(0);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("stamps the mark on a title-matched update so a later rename is mark-addressable", async () => {
|
|
166
|
+
// A row written with NO mark (pre-mark history, or a healed row) is only
|
|
167
|
+
// reachable by title. The first title-match must stamp the mark so the row
|
|
168
|
+
// never orphans on a later rename (the 2026-07-28 stranded-subtask class).
|
|
169
|
+
const { hook, store } = makeFixture();
|
|
170
|
+
store.push({
|
|
171
|
+
id: "legacy-1",
|
|
172
|
+
parent_id: "task-1",
|
|
173
|
+
title: "Old title",
|
|
174
|
+
status: "todo",
|
|
175
|
+
completed: false,
|
|
176
|
+
kind_data: {},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
await hook({
|
|
180
|
+
tool_name: "TaskUpdate",
|
|
181
|
+
hook_event_name: "PostToolUse",
|
|
182
|
+
tool_input: { taskId: "99", subject: "Old title", status: "in_progress" },
|
|
183
|
+
});
|
|
184
|
+
expect((store[0].kind_data as { task_sync: { mark: string } }).task_sync.mark).toBe("99");
|
|
185
|
+
expect(store[0].status).toBe("in-progress");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it("is idempotent on a retried TaskCreate (no duplicate subtask)", async () => {
|
|
189
|
+
// The hook curls with --retry, so one TaskCreate can arrive twice. A
|
|
190
|
+
// projection that duplicates on retry is not a projection.
|
|
191
|
+
const { hook, store } = makeFixture();
|
|
192
|
+
const evt = {
|
|
193
|
+
tool_name: "TaskCreate",
|
|
194
|
+
hook_event_name: "PostToolUse",
|
|
195
|
+
tool_input: { subject: "Once only" },
|
|
196
|
+
tool_response: { task: { id: "7" } },
|
|
197
|
+
};
|
|
198
|
+
await hook(evt);
|
|
199
|
+
const second = await hook(evt);
|
|
200
|
+
// The retried create matches the stored mark and is discarded, not doubled.
|
|
201
|
+
expect(second.applied).toBe(false);
|
|
202
|
+
expect(store.filter((s) => s.title === "Once only")).toHaveLength(1);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @system service-boot
|
|
3
|
+
* @status handwritten
|
|
4
|
+
* @edit edit directly
|
|
5
|
+
*
|
|
6
|
+
* Behavioral tests for canonical CLI-session lane resolution.
|
|
7
|
+
*/
|
|
8
|
+
import { describe, expect, it } from "bun:test";
|
|
9
|
+
import { resolveLaneWorkName } from "./task-sync-lane.ts";
|
|
10
|
+
|
|
11
|
+
describe("resolveLaneWorkName", () => {
|
|
12
|
+
it("reads the visible label from the active cli_sessions route", async () => {
|
|
13
|
+
let query: unknown;
|
|
14
|
+
const name = await resolveLaneWorkName(
|
|
15
|
+
{
|
|
16
|
+
cli_sessions: {
|
|
17
|
+
findFirst: async (args: unknown) => {
|
|
18
|
+
query = args;
|
|
19
|
+
return { id: "session-1", label: "ZeroStack" };
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
} as never,
|
|
23
|
+
"tmux:%7",
|
|
24
|
+
);
|
|
25
|
+
expect(name).toBe("ZeroStack");
|
|
26
|
+
expect(query).toMatchObject({ where: { host_route: { path: ["pane_id"], equals: "tmux:%7" } } });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("returns no unverified title when no active session owns the pane", async () => {
|
|
30
|
+
const name = await resolveLaneWorkName(
|
|
31
|
+
{ cli_sessions: { findFirst: async () => null } } as never,
|
|
32
|
+
"tmux:%8",
|
|
33
|
+
);
|
|
34
|
+
expect(name).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
import { describe, expect, it } from "bun:test";
|
|
13
13
|
import {
|
|
14
14
|
STATUS_TO_WORK_ITEM,
|
|
15
|
+
deriveEvidenceProgress,
|
|
15
16
|
normalizeStatus,
|
|
16
17
|
planReconcile,
|
|
17
18
|
resolveProjectedStatus,
|
|
@@ -29,6 +30,31 @@ describe("STATUS_TO_WORK_ITEM", () => {
|
|
|
29
30
|
});
|
|
30
31
|
});
|
|
31
32
|
|
|
33
|
+
describe("evidence-derived task progress", () => {
|
|
34
|
+
it("counts only required subtasks with independent Orchestrator acceptance", () => {
|
|
35
|
+
const out = deriveEvidenceProgress(
|
|
36
|
+
[
|
|
37
|
+
{ id: "a", status: "done" },
|
|
38
|
+
{ id: "b", status: "done" },
|
|
39
|
+
{ id: "c", status: "todo", kind_data: { pm_progress: { required: false } } },
|
|
40
|
+
],
|
|
41
|
+
[
|
|
42
|
+
{ work_item_id: "a", sender_role: "orchestrator", system_key: "acceptance:a" },
|
|
43
|
+
{ work_item_id: "b", sender_role: "worker", system_key: "acceptance:b" },
|
|
44
|
+
],
|
|
45
|
+
);
|
|
46
|
+
expect(out).toEqual({ total: 2, accepted: 1, percentage: 50 });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("does not treat prose, context, or done alone as evidence", () => {
|
|
50
|
+
expect(
|
|
51
|
+
deriveEvidenceProgress([{ id: "a", status: "done" }], [
|
|
52
|
+
{ work_item_id: "a", sender_role: "orchestrator", system_key: "progress:100" },
|
|
53
|
+
]),
|
|
54
|
+
).toEqual({ total: 1, accepted: 0, percentage: 0 });
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
32
58
|
describe("status translation is a single non-drifting source", () => {
|
|
33
59
|
// The forward map (CLI → work_items) is canonical; the reverse is DERIVED from
|
|
34
60
|
// it (+ a closed synonym set). This locks the structural fix: the two
|
|
@@ -74,6 +74,57 @@ export function normalizeStatus(s: string | null): TaskListItem["status"] {
|
|
|
74
74
|
return (s && WORK_ITEM_TO_STATUS[s]) || "pending";
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
export interface ProgressSubtask {
|
|
78
|
+
id: string;
|
|
79
|
+
status: string | null;
|
|
80
|
+
kind_data?: Record<string, unknown> | null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface ProgressAcceptanceEvidence {
|
|
84
|
+
work_item_id: string | null;
|
|
85
|
+
sender_role: string | null;
|
|
86
|
+
system_key: string | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface EvidenceProgress {
|
|
90
|
+
total: number;
|
|
91
|
+
accepted: number;
|
|
92
|
+
percentage: number;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Derive progress from the canonical checklist and independent acceptance
|
|
97
|
+
* comments. A done status without an Orchestrator acceptance comment is not
|
|
98
|
+
* evidence of completion; prose percentages and context gauges never enter
|
|
99
|
+
* this calculation. Subtasks are required by default, with an explicit
|
|
100
|
+
* `kind_data.pm_progress.required: false` opt-out for non-gating notes.
|
|
101
|
+
*/
|
|
102
|
+
export function deriveEvidenceProgress(
|
|
103
|
+
subtasks: ProgressSubtask[],
|
|
104
|
+
evidence: ProgressAcceptanceEvidence[],
|
|
105
|
+
): EvidenceProgress {
|
|
106
|
+
const required = subtasks.filter(
|
|
107
|
+
(s) => (s.kind_data?.pm_progress as { required?: boolean } | undefined)?.required !== false,
|
|
108
|
+
);
|
|
109
|
+
const accepted = new Set(
|
|
110
|
+
evidence
|
|
111
|
+
.filter(
|
|
112
|
+
(e) =>
|
|
113
|
+
e.sender_role === "orchestrator" &&
|
|
114
|
+
typeof e.system_key === "string" &&
|
|
115
|
+
e.system_key.startsWith("acceptance:") &&
|
|
116
|
+
e.work_item_id,
|
|
117
|
+
)
|
|
118
|
+
.map((e) => e.work_item_id as string),
|
|
119
|
+
);
|
|
120
|
+
const acceptedCount = required.filter((s) => s.status === "done" && accepted.has(s.id)).length;
|
|
121
|
+
return {
|
|
122
|
+
total: required.length,
|
|
123
|
+
accepted: acceptedCount,
|
|
124
|
+
percentage: required.length === 0 ? 0 : Math.round((acceptedCount / required.length) * 100),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
77
128
|
/**
|
|
78
129
|
* Decide the status to WRITE for an existing row, given what the CLI list says.
|
|
79
130
|
*
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @system service-boot
|
|
3
|
+
* @status handwritten
|
|
4
|
+
* @edit directly
|
|
5
|
+
*
|
|
6
|
+
* Unit tests for the rename back-write leg: renameOutcome (the pure
|
|
7
|
+
* no-task ⇒ not-updated decision) + source-contract assertions that the handler
|
|
8
|
+
* resolves the lane task BY SESSION (never pane) and updates its title. Covers
|
|
9
|
+
* `what-must-have-a-test` for the new procedure + the `lane-identity-is-cli-
|
|
10
|
+
* session-id` invariant it rides on.
|
|
11
|
+
*/
|
|
12
|
+
import { describe, it, expect } from "bun:test";
|
|
13
|
+
import { renameOutcome } from "./task-sync-rename.ts";
|
|
14
|
+
|
|
15
|
+
describe("renameOutcome (no verdict from no data)", () => {
|
|
16
|
+
it("returns not-updated with a null task_id when no task is bound to the session", () => {
|
|
17
|
+
// A rename of a tab whose lane has no resolvable task updates nothing —
|
|
18
|
+
// never an error, never a fake id. updated:false is the signal the caller
|
|
19
|
+
// treats as best-effort (the window was already renamed; this only missed
|
|
20
|
+
// the DB echo, which is the rare archived-and-pruned case).
|
|
21
|
+
expect(renameOutcome(null)).toEqual({ task_id: null, updated: false });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns the bound task id + updated:true when a task resolves", () => {
|
|
25
|
+
expect(renameOutcome({ id: "task-9" })).toEqual({ task_id: "task-9", updated: true });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe("renameLaneTask resolves BY SESSION and writes the title (source contract)", () => {
|
|
30
|
+
const renameSrc = Bun.file(new URL("./task-sync-rename.ts", import.meta.url).pathname);
|
|
31
|
+
|
|
32
|
+
it("resolves the lane task by lane_session (the CLI session id), never by pane", async () => {
|
|
33
|
+
// `lane-identity-is-cli-session-id`: binding is by session because a pane
|
|
34
|
+
// outlives the session inside it. A pane-keyed rename would let a dead
|
|
35
|
+
// session's task answer for a live lane.
|
|
36
|
+
const text = await renameSrc.text();
|
|
37
|
+
expect(text).toContain("resolveLaneTask(prisma, lane_session)");
|
|
38
|
+
// No pane matching anywhere in the resolution path.
|
|
39
|
+
expect(text).not.toContain("lane.pane");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("updates the resolved task's title by id", async () => {
|
|
43
|
+
const text = await renameSrc.text();
|
|
44
|
+
expect(text).toContain('where: { id: task.id }');
|
|
45
|
+
expect(text).toContain("data: { title }");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("requires lane_session + title at the signature (incomplete rename unconstructible)", async () => {
|
|
49
|
+
const text = await renameSrc.text();
|
|
50
|
+
expect(text).toContain('lane_session: v.pipe(v.string()');
|
|
51
|
+
expect(text).toContain('title: v.pipe(v.string()');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @system service-boot
|
|
3
|
+
* @status handwritten
|
|
4
|
+
* @edit edit directly
|
|
5
|
+
*
|
|
6
|
+
* Lane RENAME back-write for task-sync: a tab rename EMITS to update the bound
|
|
7
|
+
* work_items task's title in the DB, by CLI session id. This is the DB half of
|
|
8
|
+
* `tab-rename-emits-back-to-task-title`: the operator's tab bar is how they see
|
|
9
|
+
* what is being worked on (`lane-labels-and-task-lists`), so the tmux window
|
|
10
|
+
* name and the task title must never diverge silently. Renaming a tab from
|
|
11
|
+
* `scala-tools session rename` (or the lane renaming itself through the same
|
|
12
|
+
* surface) updates the task title so the project board agrees with the tab bar.
|
|
13
|
+
*
|
|
14
|
+
* THE EMISSION, not a poll (`actions-are-rows-then-emissions`): a caller renames
|
|
15
|
+
* the window (a row/state change) and that change emits the title update — the
|
|
16
|
+
* task-sync owner reacts by updating the row. State lives in the row, never in a
|
|
17
|
+
* return value a caller may never receive.
|
|
18
|
+
*
|
|
19
|
+
* Bound by CLI SESSION ID, never pane id (`lane-identity-is-cli-session-id`): a
|
|
20
|
+
* pane OUTLIVES the session inside it, so matching on a pane would let a dead
|
|
21
|
+
* session's task answer for a live lane. The session is the stable identity a
|
|
22
|
+
* rename resolves to (the daemon resolves the pane's tab → its stored session id
|
|
23
|
+
* and passes that here), so the rename lands on the lane that owns the tab.
|
|
24
|
+
*
|
|
25
|
+
* Split out of task-sync-router.ts for the same reason task-sync-brief/lane/
|
|
26
|
+
* assign exist: the router sits at its 1000-line commit gate, so every cohesive
|
|
27
|
+
* task-sync unit that can live in a sibling does. This owns the rename handler +
|
|
28
|
+
* its pure outcome decision.
|
|
29
|
+
*
|
|
30
|
+
* CAPABILITY HARVEST (capability-harvest-on-split): APP-LOCAL, not a capability
|
|
31
|
+
* candidate. Bound to the work_items schema and to task-sync's own
|
|
32
|
+
* kind_data.lane.session convention; no unrelated app could install this
|
|
33
|
+
* unmodified.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import * as v from "valibot";
|
|
37
|
+
import type { Prisma } from "./task-sync-router.ts";
|
|
38
|
+
import { authed, type Context } from "./auth-router.ts";
|
|
39
|
+
import { resolveLaneTask } from "./task-sync-lane.ts";
|
|
40
|
+
import { getAppLogger } from "@teamscala/logger/app-loggers";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* renameLaneTask ORPC input. `lane_session` is the lane's CLI-native session id
|
|
44
|
+
* (kind_data.lane.session) — the stable identity a pane rename resolves to.
|
|
45
|
+
* `title` is the new task title (the renamed tab's label). Both required:
|
|
46
|
+
* oRPC rejects a call missing either at the signature
|
|
47
|
+
* (`prevention-over-detection`), so a malformed rename is a 400, never a silent
|
|
48
|
+
* no-op that leaves the title stale.
|
|
49
|
+
*/
|
|
50
|
+
export const renameLaneTaskInput = v.object({
|
|
51
|
+
lane_session: v.pipe(v.string(), v.minLength(1, "lane_session is required")),
|
|
52
|
+
title: v.pipe(v.string(), v.minLength(1, "title is required")),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The rename outcome from a resolved lane task — pure so the "no task bound ⇒
|
|
57
|
+
* not updated, never an error" decision is unit-testable with no DB. A rename
|
|
58
|
+
* whose lane has no task is best-effort (returns updated:false): every spawn
|
|
59
|
+
* now mints a task, so this is the rare case (a tab whose task was archived and
|
|
60
|
+
* pruned), not a path the operator hits. Failing loudly here would refuse a
|
|
61
|
+
* rename of the WINDOW for a DB miss, which couples two surfaces that must not
|
|
62
|
+
* be — the tmux rename already succeeded before this is called.
|
|
63
|
+
*/
|
|
64
|
+
export function renameOutcome(task: { id: string } | null): {
|
|
65
|
+
task_id: string | null;
|
|
66
|
+
updated: boolean;
|
|
67
|
+
} {
|
|
68
|
+
if (!task) return { task_id: null, updated: false };
|
|
69
|
+
return { task_id: task.id, updated: true };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* renameLaneTask ORPC handler. The session-picker daemon calls this from
|
|
74
|
+
* `/rpc/rename` after it renames the tmux window: it resolves the pane's tab to
|
|
75
|
+
* its session id and posts it here. Same transport as bindLane/readTaskList:
|
|
76
|
+
* page-gate-exempt (fn.taskSync), localhost super-admin. Resolves the lane's
|
|
77
|
+
* task BY SESSION (never pane) and updates its title. Idempotent: renaming to
|
|
78
|
+
* the same title writes the same row.
|
|
79
|
+
*
|
|
80
|
+
* An archived parent is matched too (resolveLaneTask falls back to the archived
|
|
81
|
+
* lane task for the session), so a rename of a tab whose run closed still lands
|
|
82
|
+
* on its task — the title is the title regardless of run state.
|
|
83
|
+
*/
|
|
84
|
+
export const renameLaneTaskHandler = authed
|
|
85
|
+
.input(renameLaneTaskInput)
|
|
86
|
+
.handler(async ({ input, context }) => {
|
|
87
|
+
const ctx = context as Context;
|
|
88
|
+
const prisma = ctx.prisma as Prisma;
|
|
89
|
+
const { lane_session, title } = input;
|
|
90
|
+
const task = await resolveLaneTask(prisma, lane_session);
|
|
91
|
+
const outcome = renameOutcome(task);
|
|
92
|
+
if (!task) return outcome;
|
|
93
|
+
try {
|
|
94
|
+
await prisma.work_items.update({
|
|
95
|
+
where: { id: task.id },
|
|
96
|
+
data: { title },
|
|
97
|
+
select: { id: true },
|
|
98
|
+
});
|
|
99
|
+
} catch (err) {
|
|
100
|
+
// The window was already renamed by the caller; a DB update failure must
|
|
101
|
+
// not surface as an error that implies the rename failed. Report
|
|
102
|
+
// not-updated + log, so the two surfaces stay decoupled
|
|
103
|
+
// (`a-component-may-not-report-a-state-it-has-not-verified`).
|
|
104
|
+
getAppLogger().warn("[task-sync] renameLaneTask: title update failed", {
|
|
105
|
+
taskId: task.id,
|
|
106
|
+
error: err instanceof Error ? err.message : String(err),
|
|
107
|
+
});
|
|
108
|
+
return { task_id: task.id, updated: false };
|
|
109
|
+
}
|
|
110
|
+
return outcome;
|
|
111
|
+
});
|
|
@@ -337,8 +337,20 @@ describe("a blocked row survives a CLI list that cannot express it", () => {
|
|
|
337
337
|
it("planReconcile leaves a blocked subtask blocked when the list says pending", () => {
|
|
338
338
|
// The end-to-end shape: this is what re-blocked the lane three times.
|
|
339
339
|
const plan = planReconcile(
|
|
340
|
-
[
|
|
341
|
-
|
|
340
|
+
[
|
|
341
|
+
{
|
|
342
|
+
id: "row-1",
|
|
343
|
+
kind: "subtask",
|
|
344
|
+
parent_id: "task-1",
|
|
345
|
+
organisation_id: "org-1",
|
|
346
|
+
title: "Deploy the fix",
|
|
347
|
+
status: "blocked",
|
|
348
|
+
position: "0",
|
|
349
|
+
completed: false,
|
|
350
|
+
kind_data: { task_sync: { mark: "1" } },
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
[{ content: "Deploy the fix", status: "pending" }],
|
|
342
354
|
"claude-code",
|
|
343
355
|
);
|
|
344
356
|
const update = plan.toUpdate.find((u) => u.id === "row-1");
|