@hiroleague/taskmanager 0.0.3 → 0.0.4

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.
Files changed (62) hide show
  1. package/README.md +1 -1
  2. package/dist/assets/index-BpzHnKdP.css +1 -0
  3. package/dist/assets/index-DmNErTAP.js +273 -0
  4. package/dist/index.html +2 -2
  5. package/package.json +1 -1
  6. package/skills/hiro-task-manager-cli/SKILL.md +6 -4
  7. package/skills/hiro-task-manager-cli/reference/cli-access-policy.md +1 -0
  8. package/skills/hiro-task-manager-cli/reference/releases.md +14 -0
  9. package/src/cli/commands/query.ts +56 -56
  10. package/src/cli/commands/releases.ts +22 -0
  11. package/src/cli/handlers/boards.test.ts +669 -669
  12. package/src/cli/handlers/cli-wiring.test.ts +38 -1
  13. package/src/cli/handlers/releases.ts +15 -0
  14. package/src/cli/handlers/search.test.ts +374 -374
  15. package/src/cli/handlers/search.ts +17 -17
  16. package/src/cli/lib/cli-http-errors.test.ts +85 -85
  17. package/src/cli/lib/write/releases.ts +64 -1
  18. package/src/cli/lib/write-result.test.ts +3 -0
  19. package/src/cli/lib/write-result.ts +3 -0
  20. package/src/cli/lib/writeCommands.breadth.test.ts +143 -0
  21. package/src/cli/lib/writeCommands.ts +1 -0
  22. package/src/cli/subprocess.real-stack.test.ts +625 -611
  23. package/src/cli/subprocess.smoke.test.ts +954 -954
  24. package/src/client/api/useBoardChangeStream.ts +421 -168
  25. package/src/client/api/useBoardIndexStream.ts +35 -0
  26. package/src/client/components/board/BoardStatsChips.tsx +233 -233
  27. package/src/client/components/board/BoardStatsContext.tsx +41 -41
  28. package/src/client/components/board/boardHeaderButtonStyles.ts +38 -38
  29. package/src/client/components/board/shortcuts/useBoardShortcutKeydown.ts +49 -49
  30. package/src/client/components/board/useBoardCanvasPanScroll.ts +108 -108
  31. package/src/client/components/board/useBoardTaskContainerDroppableReact.ts +33 -33
  32. package/src/client/components/board/useBoardTaskSortableReact.ts +26 -26
  33. package/src/client/components/layout/AppShell.tsx +5 -2
  34. package/src/client/components/layout/NotificationToasts.tsx +38 -1
  35. package/src/client/components/multi-select.tsx +1206 -1206
  36. package/src/client/components/routing/BoardPage.tsx +20 -20
  37. package/src/client/components/routing/NavigationRegistrar.tsx +13 -13
  38. package/src/client/components/task/TaskCard.tsx +643 -643
  39. package/src/client/components/ui/badge.tsx +49 -49
  40. package/src/client/components/ui/button.tsx +65 -65
  41. package/src/client/components/ui/command.tsx +193 -193
  42. package/src/client/components/ui/dialog.tsx +163 -163
  43. package/src/client/components/ui/input-group.tsx +155 -155
  44. package/src/client/components/ui/input.tsx +19 -19
  45. package/src/client/components/ui/popover.tsx +87 -87
  46. package/src/client/components/ui/separator.tsx +28 -28
  47. package/src/client/components/ui/textarea.tsx +18 -18
  48. package/src/client/index.css +248 -248
  49. package/src/client/lib/appNavigate.ts +16 -16
  50. package/src/client/lib/taskCardDate.ts +111 -111
  51. package/src/client/lib/utils.ts +6 -6
  52. package/src/client/store/notificationUi.ts +14 -0
  53. package/src/server/auth.ts +351 -351
  54. package/src/server/events.ts +31 -4
  55. package/src/server/migrations/registry.ts +43 -43
  56. package/src/server/notificationEvents.ts +8 -1
  57. package/src/server/routes/boards.ts +15 -1
  58. package/src/server/routes/trash.ts +6 -1
  59. package/src/shared/boardEvents.ts +6 -0
  60. package/src/shared/runtimeConfig.ts +256 -256
  61. package/dist/assets/index-hMFTu7sr.css +0 -1
  62. package/dist/assets/index-oKG1C41_.js +0 -273
@@ -1,374 +1,374 @@
1
- import { afterEach, describe, expect, test } from "bun:test";
2
- import type { PaginatedListBody } from "../../shared/pagination";
3
- import type { SearchHit } from "../../shared/models";
4
- import { CLI_ERR } from "../types/errors";
5
- import { syncCliOutputFormatFromGlobals } from "../lib/cliFormat";
6
- import { createTestCliRuntime } from "../lib/runtime";
7
- import { resetCliOutputFormat } from "../lib/output";
8
- import { createDefaultCliContext } from "./context";
9
- import { handleSearch } from "./search";
10
- import type { CliContext } from "./context";
11
-
12
- function mockContext(overrides: Partial<CliContext> = {}): CliContext {
13
- return {
14
- ...createDefaultCliContext(),
15
- resolvePort: () => 3002,
16
- fetchApi: async () => {
17
- throw new Error("fetchApi not stubbed");
18
- },
19
- fetchApiMutate: async () => {
20
- throw new Error("fetchApiMutate not stubbed");
21
- },
22
- fetchApiTrashMutate: async () => {
23
- throw new Error("fetchApiTrashMutate not stubbed");
24
- },
25
- printJson: () => {},
26
- getRuntime: () => createTestCliRuntime({ port: 3002 }),
27
- ...overrides,
28
- };
29
- }
30
-
31
- describe("handleSearch", () => {
32
- afterEach(() => {
33
- resetCliOutputFormat();
34
- });
35
-
36
- test("requires non-empty query", async () => {
37
- const ctx = mockContext();
38
- await expect(handleSearch(ctx, ["", " "], {})).rejects.toMatchObject({
39
- exitCode: 2,
40
- details: expect.objectContaining({ code: CLI_ERR.missingRequired }),
41
- });
42
- });
43
-
44
- test("ndjson output prints one JSON object per hit line", async () => {
45
- const hits: SearchHit[] = [
46
- {
47
- boardId: 1,
48
- boardSlug: "b",
49
- taskId: 9,
50
- boardName: "B",
51
- listId: 2,
52
- listName: "L",
53
- title: "T",
54
- snippet: "s",
55
- score: 0.1,
56
- },
57
- ];
58
- const body: PaginatedListBody<SearchHit> = {
59
- items: hits,
60
- total: hits.length,
61
- limit: 5,
62
- offset: 0,
63
- };
64
- let fetchedPath = "";
65
- const ctx = mockContext({
66
- fetchApi: (async (path) => {
67
- fetchedPath = path;
68
- return body;
69
- }) as CliContext["fetchApi"],
70
- });
71
-
72
- let out = "";
73
- const origWrite = process.stdout.write.bind(process.stdout);
74
- process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
75
- out +=
76
- typeof chunk === "string"
77
- ? chunk
78
- : new TextDecoder().decode(chunk as Uint8Array);
79
- void args;
80
- return true;
81
- };
82
- try {
83
- await handleSearch(ctx, ["hello", "world"], {
84
- board: "b1",
85
- limit: "5",
86
- noPrefix: true,
87
- });
88
- } finally {
89
- process.stdout.write = origWrite;
90
- }
91
-
92
- expect(fetchedPath).toContain("/search?");
93
- expect(fetchedPath).toContain("q=hello+world");
94
- expect(fetchedPath).toContain("limit=5");
95
- expect(fetchedPath).toContain("board=b1");
96
- expect(fetchedPath).toContain("prefix=0");
97
- const lines = out.trimEnd().split("\n").filter((l) => l.length > 0);
98
- expect(lines.length).toBe(1);
99
- expect(JSON.parse(lines[0]!)).toEqual(hits[0]);
100
- });
101
-
102
- test("rejects --fields when global format is human", async () => {
103
- syncCliOutputFormatFromGlobals({ format: "human" });
104
- const ctx = mockContext();
105
- await expect(
106
- handleSearch(ctx, ["q"], { fields: "taskId" }),
107
- ).rejects.toMatchObject({
108
- exitCode: 2,
109
- details: expect.objectContaining({ code: CLI_ERR.invalidValue }),
110
- });
111
- });
112
-
113
- test("ndjson --fields projects items", async () => {
114
- const hits: SearchHit[] = [
115
- {
116
- boardId: 1,
117
- boardSlug: "b",
118
- taskId: 9,
119
- boardName: "B",
120
- listId: 2,
121
- listName: "L",
122
- title: "T",
123
- snippet: "s",
124
- score: 0.1,
125
- },
126
- ];
127
- const body: PaginatedListBody<SearchHit> = {
128
- items: hits,
129
- total: 1,
130
- limit: 20,
131
- offset: 0,
132
- };
133
- const ctx = mockContext({
134
- fetchApi: (async () => body) as CliContext["fetchApi"],
135
- });
136
-
137
- let out = "";
138
- const origWrite = process.stdout.write.bind(process.stdout);
139
- process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
140
- out +=
141
- typeof chunk === "string"
142
- ? chunk
143
- : new TextDecoder().decode(chunk as Uint8Array);
144
- void args;
145
- return true;
146
- };
147
- try {
148
- await handleSearch(ctx, ["q"], { fields: "taskId,title" });
149
- } finally {
150
- process.stdout.write = origWrite;
151
- }
152
-
153
- const lines = out.trimEnd().split("\n").filter((l) => l.length > 0);
154
- expect(lines.length).toBe(1);
155
- expect(JSON.parse(lines[0]!)).toEqual({ taskId: 9, title: "T" });
156
- });
157
-
158
- test("human format prints a fixed-width table", async () => {
159
- syncCliOutputFormatFromGlobals({ format: "human" });
160
- const hits: SearchHit[] = [
161
- {
162
- boardId: 1,
163
- boardSlug: "b",
164
- taskId: 1,
165
- boardName: "B",
166
- listId: 2,
167
- listName: "L",
168
- title: "T",
169
- snippet: "s",
170
- score: 0.2,
171
- },
172
- ];
173
- const body: PaginatedListBody<SearchHit> = {
174
- items: hits,
175
- total: 1,
176
- limit: 20,
177
- offset: 0,
178
- };
179
- const ctx = mockContext({
180
- fetchApi: (async () => body) as CliContext["fetchApi"],
181
- });
182
-
183
- let out = "";
184
- const origWrite = process.stdout.write.bind(process.stdout);
185
- process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
186
- out +=
187
- typeof chunk === "string"
188
- ? chunk
189
- : new TextDecoder().decode(chunk as Uint8Array);
190
- void args;
191
- return true;
192
- };
193
- try {
194
- await handleSearch(ctx, ["q"], {});
195
- } finally {
196
- process.stdout.write = origWrite;
197
- }
198
-
199
- expect(out).toContain("Board");
200
- expect(out).toContain("Snippet");
201
- expect(out).toContain("total 1");
202
- });
203
-
204
- test("omitted --limit sends default limit=20 in request URL (aspect 3 bounded default)", async () => {
205
- let fetchedPath = "";
206
- const emptyBody: PaginatedListBody<SearchHit> = {
207
- items: [],
208
- total: 0,
209
- limit: 20,
210
- offset: 0,
211
- };
212
- const ctx = mockContext({
213
- fetchApi: (async (path) => {
214
- fetchedPath = path;
215
- return emptyBody;
216
- }) as CliContext["fetchApi"],
217
- printJson: () => {},
218
- });
219
-
220
- await handleSearch(ctx, ["term"], {});
221
-
222
- expect(fetchedPath).toContain("limit=20");
223
- });
224
-
225
- test("--quiet — taskId per line", async () => {
226
- syncCliOutputFormatFromGlobals({ format: "ndjson", quiet: true });
227
- const hits: SearchHit[] = [
228
- {
229
- boardId: 1,
230
- boardSlug: "b",
231
- taskId: 77,
232
- boardName: "B",
233
- listId: 1,
234
- listName: "L",
235
- title: "T",
236
- snippet: "s",
237
- score: 0.1,
238
- },
239
- ];
240
- const body: PaginatedListBody<SearchHit> = {
241
- items: hits,
242
- total: 1,
243
- limit: 20,
244
- offset: 0,
245
- };
246
- const ctx = mockContext({
247
- fetchApi: (async () => body) as CliContext["fetchApi"],
248
- });
249
-
250
- let out = "";
251
- const origWrite = process.stdout.write.bind(process.stdout);
252
- process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
253
- out +=
254
- typeof chunk === "string"
255
- ? chunk
256
- : new TextDecoder().decode(chunk as Uint8Array);
257
- void args;
258
- return true;
259
- };
260
- try {
261
- await handleSearch(ctx, ["q"], {});
262
- } finally {
263
- process.stdout.write = origWrite;
264
- }
265
-
266
- expect(out.trimEnd()).toBe("77");
267
- });
268
-
269
- test("--limit 50 — URL contains limit=50", async () => {
270
- let fetchedPath = "";
271
- const emptyBody: PaginatedListBody<SearchHit> = {
272
- items: [],
273
- total: 0,
274
- limit: 50,
275
- offset: 0,
276
- };
277
- const ctx = mockContext({
278
- fetchApi: (async (path) => {
279
- fetchedPath = path;
280
- return emptyBody;
281
- }) as CliContext["fetchApi"],
282
- printJson: () => {},
283
- });
284
-
285
- await handleSearch(ctx, ["x"], { limit: "50" });
286
-
287
- expect(fetchedPath).toContain("limit=50");
288
- });
289
-
290
- test("--limit 999 — capped to 500 in URL", async () => {
291
- let fetchedPath = "";
292
- const emptyBody: PaginatedListBody<SearchHit> = {
293
- items: [],
294
- total: 0,
295
- limit: 500,
296
- offset: 0,
297
- };
298
- const ctx = mockContext({
299
- fetchApi: (async (path) => {
300
- fetchedPath = path;
301
- return emptyBody;
302
- }) as CliContext["fetchApi"],
303
- printJson: () => {},
304
- });
305
-
306
- await handleSearch(ctx, ["x"], { limit: "999" });
307
-
308
- expect(fetchedPath).toContain("limit=500");
309
- });
310
-
311
- test("no results — NDJSON empty; human No rows.", async () => {
312
- const emptyBody: PaginatedListBody<SearchHit> = {
313
- items: [],
314
- total: 0,
315
- limit: 20,
316
- offset: 0,
317
- };
318
- syncCliOutputFormatFromGlobals({ format: "ndjson", quiet: false });
319
- const ctxNd = mockContext({
320
- fetchApi: (async () => emptyBody) as CliContext["fetchApi"],
321
- });
322
- let outNd = "";
323
- const orig = process.stdout.write.bind(process.stdout);
324
- process.stdout.write = (c: string | Uint8Array, ...a: unknown[]) => {
325
- outNd += typeof c === "string" ? c : new TextDecoder().decode(c);
326
- void a;
327
- return true;
328
- };
329
- try {
330
- await handleSearch(ctxNd, ["q"], {});
331
- } finally {
332
- process.stdout.write = orig;
333
- }
334
- expect(outNd.trim()).toBe("");
335
-
336
- syncCliOutputFormatFromGlobals({ format: "human", quiet: false });
337
- const ctxHu = mockContext({
338
- fetchApi: (async () => emptyBody) as CliContext["fetchApi"],
339
- });
340
- let outHu = "";
341
- process.stdout.write = (c: string | Uint8Array, ...a: unknown[]) => {
342
- outHu += typeof c === "string" ? c : new TextDecoder().decode(c);
343
- void a;
344
- return true;
345
- };
346
- try {
347
- await handleSearch(ctxHu, ["q"], {});
348
- } finally {
349
- process.stdout.write = orig;
350
- }
351
- expect(outHu).toContain("No rows.");
352
- });
353
-
354
- test("--board appears in search URL", async () => {
355
- let fetchedPath = "";
356
- const emptyBody: PaginatedListBody<SearchHit> = {
357
- items: [],
358
- total: 0,
359
- limit: 20,
360
- offset: 0,
361
- };
362
- const ctx = mockContext({
363
- fetchApi: (async (path) => {
364
- fetchedPath = path;
365
- return emptyBody;
366
- }) as CliContext["fetchApi"],
367
- printJson: () => {},
368
- });
369
-
370
- await handleSearch(ctx, ["term"], { board: "my-slug" });
371
-
372
- expect(fetchedPath).toContain("board=my-slug");
373
- });
374
- });
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import type { PaginatedListBody } from "../../shared/pagination";
3
+ import type { SearchHit } from "../../shared/models";
4
+ import { CLI_ERR } from "../types/errors";
5
+ import { syncCliOutputFormatFromGlobals } from "../lib/cliFormat";
6
+ import { createTestCliRuntime } from "../lib/runtime";
7
+ import { resetCliOutputFormat } from "../lib/output";
8
+ import { createDefaultCliContext } from "./context";
9
+ import { handleSearch } from "./search";
10
+ import type { CliContext } from "./context";
11
+
12
+ function mockContext(overrides: Partial<CliContext> = {}): CliContext {
13
+ return {
14
+ ...createDefaultCliContext(),
15
+ resolvePort: () => 3002,
16
+ fetchApi: async () => {
17
+ throw new Error("fetchApi not stubbed");
18
+ },
19
+ fetchApiMutate: async () => {
20
+ throw new Error("fetchApiMutate not stubbed");
21
+ },
22
+ fetchApiTrashMutate: async () => {
23
+ throw new Error("fetchApiTrashMutate not stubbed");
24
+ },
25
+ printJson: () => {},
26
+ getRuntime: () => createTestCliRuntime({ port: 3002 }),
27
+ ...overrides,
28
+ };
29
+ }
30
+
31
+ describe("handleSearch", () => {
32
+ afterEach(() => {
33
+ resetCliOutputFormat();
34
+ });
35
+
36
+ test("requires non-empty query", async () => {
37
+ const ctx = mockContext();
38
+ await expect(handleSearch(ctx, ["", " "], {})).rejects.toMatchObject({
39
+ exitCode: 2,
40
+ details: expect.objectContaining({ code: CLI_ERR.missingRequired }),
41
+ });
42
+ });
43
+
44
+ test("ndjson output prints one JSON object per hit line", async () => {
45
+ const hits: SearchHit[] = [
46
+ {
47
+ boardId: 1,
48
+ boardSlug: "b",
49
+ taskId: 9,
50
+ boardName: "B",
51
+ listId: 2,
52
+ listName: "L",
53
+ title: "T",
54
+ snippet: "s",
55
+ score: 0.1,
56
+ },
57
+ ];
58
+ const body: PaginatedListBody<SearchHit> = {
59
+ items: hits,
60
+ total: hits.length,
61
+ limit: 5,
62
+ offset: 0,
63
+ };
64
+ let fetchedPath = "";
65
+ const ctx = mockContext({
66
+ fetchApi: (async (path) => {
67
+ fetchedPath = path;
68
+ return body;
69
+ }) as CliContext["fetchApi"],
70
+ });
71
+
72
+ let out = "";
73
+ const origWrite = process.stdout.write.bind(process.stdout);
74
+ process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
75
+ out +=
76
+ typeof chunk === "string"
77
+ ? chunk
78
+ : new TextDecoder().decode(chunk as Uint8Array);
79
+ void args;
80
+ return true;
81
+ };
82
+ try {
83
+ await handleSearch(ctx, ["hello", "world"], {
84
+ board: "b1",
85
+ limit: "5",
86
+ noPrefix: true,
87
+ });
88
+ } finally {
89
+ process.stdout.write = origWrite;
90
+ }
91
+
92
+ expect(fetchedPath).toContain("/search?");
93
+ expect(fetchedPath).toContain("q=hello+world");
94
+ expect(fetchedPath).toContain("limit=5");
95
+ expect(fetchedPath).toContain("board=b1");
96
+ expect(fetchedPath).toContain("prefix=0");
97
+ const lines = out.trimEnd().split("\n").filter((l) => l.length > 0);
98
+ expect(lines.length).toBe(1);
99
+ expect(JSON.parse(lines[0]!)).toEqual(hits[0]);
100
+ });
101
+
102
+ test("rejects --fields when global format is human", async () => {
103
+ syncCliOutputFormatFromGlobals({ format: "human" });
104
+ const ctx = mockContext();
105
+ await expect(
106
+ handleSearch(ctx, ["q"], { fields: "taskId" }),
107
+ ).rejects.toMatchObject({
108
+ exitCode: 2,
109
+ details: expect.objectContaining({ code: CLI_ERR.invalidValue }),
110
+ });
111
+ });
112
+
113
+ test("ndjson --fields projects items", async () => {
114
+ const hits: SearchHit[] = [
115
+ {
116
+ boardId: 1,
117
+ boardSlug: "b",
118
+ taskId: 9,
119
+ boardName: "B",
120
+ listId: 2,
121
+ listName: "L",
122
+ title: "T",
123
+ snippet: "s",
124
+ score: 0.1,
125
+ },
126
+ ];
127
+ const body: PaginatedListBody<SearchHit> = {
128
+ items: hits,
129
+ total: 1,
130
+ limit: 20,
131
+ offset: 0,
132
+ };
133
+ const ctx = mockContext({
134
+ fetchApi: (async () => body) as CliContext["fetchApi"],
135
+ });
136
+
137
+ let out = "";
138
+ const origWrite = process.stdout.write.bind(process.stdout);
139
+ process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
140
+ out +=
141
+ typeof chunk === "string"
142
+ ? chunk
143
+ : new TextDecoder().decode(chunk as Uint8Array);
144
+ void args;
145
+ return true;
146
+ };
147
+ try {
148
+ await handleSearch(ctx, ["q"], { fields: "taskId,title" });
149
+ } finally {
150
+ process.stdout.write = origWrite;
151
+ }
152
+
153
+ const lines = out.trimEnd().split("\n").filter((l) => l.length > 0);
154
+ expect(lines.length).toBe(1);
155
+ expect(JSON.parse(lines[0]!)).toEqual({ taskId: 9, title: "T" });
156
+ });
157
+
158
+ test("human format prints a fixed-width table", async () => {
159
+ syncCliOutputFormatFromGlobals({ format: "human" });
160
+ const hits: SearchHit[] = [
161
+ {
162
+ boardId: 1,
163
+ boardSlug: "b",
164
+ taskId: 1,
165
+ boardName: "B",
166
+ listId: 2,
167
+ listName: "L",
168
+ title: "T",
169
+ snippet: "s",
170
+ score: 0.2,
171
+ },
172
+ ];
173
+ const body: PaginatedListBody<SearchHit> = {
174
+ items: hits,
175
+ total: 1,
176
+ limit: 20,
177
+ offset: 0,
178
+ };
179
+ const ctx = mockContext({
180
+ fetchApi: (async () => body) as CliContext["fetchApi"],
181
+ });
182
+
183
+ let out = "";
184
+ const origWrite = process.stdout.write.bind(process.stdout);
185
+ process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
186
+ out +=
187
+ typeof chunk === "string"
188
+ ? chunk
189
+ : new TextDecoder().decode(chunk as Uint8Array);
190
+ void args;
191
+ return true;
192
+ };
193
+ try {
194
+ await handleSearch(ctx, ["q"], {});
195
+ } finally {
196
+ process.stdout.write = origWrite;
197
+ }
198
+
199
+ expect(out).toContain("Board");
200
+ expect(out).toContain("Snippet");
201
+ expect(out).toContain("total 1");
202
+ });
203
+
204
+ test("omitted --limit sends default limit=20 in request URL (aspect 3 bounded default)", async () => {
205
+ let fetchedPath = "";
206
+ const emptyBody: PaginatedListBody<SearchHit> = {
207
+ items: [],
208
+ total: 0,
209
+ limit: 20,
210
+ offset: 0,
211
+ };
212
+ const ctx = mockContext({
213
+ fetchApi: (async (path) => {
214
+ fetchedPath = path;
215
+ return emptyBody;
216
+ }) as CliContext["fetchApi"],
217
+ printJson: () => {},
218
+ });
219
+
220
+ await handleSearch(ctx, ["term"], {});
221
+
222
+ expect(fetchedPath).toContain("limit=20");
223
+ });
224
+
225
+ test("--quiet — taskId per line", async () => {
226
+ syncCliOutputFormatFromGlobals({ format: "ndjson", quiet: true });
227
+ const hits: SearchHit[] = [
228
+ {
229
+ boardId: 1,
230
+ boardSlug: "b",
231
+ taskId: 77,
232
+ boardName: "B",
233
+ listId: 1,
234
+ listName: "L",
235
+ title: "T",
236
+ snippet: "s",
237
+ score: 0.1,
238
+ },
239
+ ];
240
+ const body: PaginatedListBody<SearchHit> = {
241
+ items: hits,
242
+ total: 1,
243
+ limit: 20,
244
+ offset: 0,
245
+ };
246
+ const ctx = mockContext({
247
+ fetchApi: (async () => body) as CliContext["fetchApi"],
248
+ });
249
+
250
+ let out = "";
251
+ const origWrite = process.stdout.write.bind(process.stdout);
252
+ process.stdout.write = (chunk: string | Uint8Array, ...args: unknown[]) => {
253
+ out +=
254
+ typeof chunk === "string"
255
+ ? chunk
256
+ : new TextDecoder().decode(chunk as Uint8Array);
257
+ void args;
258
+ return true;
259
+ };
260
+ try {
261
+ await handleSearch(ctx, ["q"], {});
262
+ } finally {
263
+ process.stdout.write = origWrite;
264
+ }
265
+
266
+ expect(out.trimEnd()).toBe("77");
267
+ });
268
+
269
+ test("--limit 50 — URL contains limit=50", async () => {
270
+ let fetchedPath = "";
271
+ const emptyBody: PaginatedListBody<SearchHit> = {
272
+ items: [],
273
+ total: 0,
274
+ limit: 50,
275
+ offset: 0,
276
+ };
277
+ const ctx = mockContext({
278
+ fetchApi: (async (path) => {
279
+ fetchedPath = path;
280
+ return emptyBody;
281
+ }) as CliContext["fetchApi"],
282
+ printJson: () => {},
283
+ });
284
+
285
+ await handleSearch(ctx, ["x"], { limit: "50" });
286
+
287
+ expect(fetchedPath).toContain("limit=50");
288
+ });
289
+
290
+ test("--limit 999 — capped to 500 in URL", async () => {
291
+ let fetchedPath = "";
292
+ const emptyBody: PaginatedListBody<SearchHit> = {
293
+ items: [],
294
+ total: 0,
295
+ limit: 500,
296
+ offset: 0,
297
+ };
298
+ const ctx = mockContext({
299
+ fetchApi: (async (path) => {
300
+ fetchedPath = path;
301
+ return emptyBody;
302
+ }) as CliContext["fetchApi"],
303
+ printJson: () => {},
304
+ });
305
+
306
+ await handleSearch(ctx, ["x"], { limit: "999" });
307
+
308
+ expect(fetchedPath).toContain("limit=500");
309
+ });
310
+
311
+ test("no results — NDJSON empty; human No rows.", async () => {
312
+ const emptyBody: PaginatedListBody<SearchHit> = {
313
+ items: [],
314
+ total: 0,
315
+ limit: 20,
316
+ offset: 0,
317
+ };
318
+ syncCliOutputFormatFromGlobals({ format: "ndjson", quiet: false });
319
+ const ctxNd = mockContext({
320
+ fetchApi: (async () => emptyBody) as CliContext["fetchApi"],
321
+ });
322
+ let outNd = "";
323
+ const orig = process.stdout.write.bind(process.stdout);
324
+ process.stdout.write = (c: string | Uint8Array, ...a: unknown[]) => {
325
+ outNd += typeof c === "string" ? c : new TextDecoder().decode(c);
326
+ void a;
327
+ return true;
328
+ };
329
+ try {
330
+ await handleSearch(ctxNd, ["q"], {});
331
+ } finally {
332
+ process.stdout.write = orig;
333
+ }
334
+ expect(outNd.trim()).toBe("");
335
+
336
+ syncCliOutputFormatFromGlobals({ format: "human", quiet: false });
337
+ const ctxHu = mockContext({
338
+ fetchApi: (async () => emptyBody) as CliContext["fetchApi"],
339
+ });
340
+ let outHu = "";
341
+ process.stdout.write = (c: string | Uint8Array, ...a: unknown[]) => {
342
+ outHu += typeof c === "string" ? c : new TextDecoder().decode(c);
343
+ void a;
344
+ return true;
345
+ };
346
+ try {
347
+ await handleSearch(ctxHu, ["q"], {});
348
+ } finally {
349
+ process.stdout.write = orig;
350
+ }
351
+ expect(outHu).toContain("No rows.");
352
+ });
353
+
354
+ test("--board appears in search URL", async () => {
355
+ let fetchedPath = "";
356
+ const emptyBody: PaginatedListBody<SearchHit> = {
357
+ items: [],
358
+ total: 0,
359
+ limit: 20,
360
+ offset: 0,
361
+ };
362
+ const ctx = mockContext({
363
+ fetchApi: (async (path) => {
364
+ fetchedPath = path;
365
+ return emptyBody;
366
+ }) as CliContext["fetchApi"],
367
+ printJson: () => {},
368
+ });
369
+
370
+ await handleSearch(ctx, ["term"], { board: "my-slug" });
371
+
372
+ expect(fetchedPath).toContain("board=my-slug");
373
+ });
374
+ });