@critical-path/core 0.36.0 → 0.37.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.
Files changed (214) hide show
  1. package/README.md +1 -1
  2. package/dist/domain/authorization.d.ts.map +1 -1
  3. package/dist/domain/authorization.js +10 -7
  4. package/dist/domain/authorization.js.map +1 -1
  5. package/dist/engine/index.d.ts +6 -0
  6. package/dist/engine/index.d.ts.map +1 -1
  7. package/dist/engine/index.js +28 -2
  8. package/dist/engine/index.js.map +1 -1
  9. package/dist/schemas/index.d.ts +42 -12
  10. package/dist/schemas/index.d.ts.map +1 -1
  11. package/dist/schemas/index.js +4 -1
  12. package/dist/schemas/index.js.map +1 -1
  13. package/dist/store/firebase.d.ts +2 -2
  14. package/dist/store/firebase.d.ts.map +1 -1
  15. package/dist/store/firebase.js +4 -2
  16. package/dist/store/firebase.js.map +1 -1
  17. package/dist/store/index.d.ts +7 -2
  18. package/dist/store/index.d.ts.map +1 -1
  19. package/dist/store/index.js +3 -2
  20. package/dist/store/index.js.map +1 -1
  21. package/dist/store/sqlite.d.ts +2 -2
  22. package/dist/store/sqlite.d.ts.map +1 -1
  23. package/dist/store/sqlite.js +5 -3
  24. package/dist/store/sqlite.js.map +1 -1
  25. package/dist/testing/conformance.d.ts.map +1 -1
  26. package/dist/testing/conformance.js +9 -0
  27. package/dist/testing/conformance.js.map +1 -1
  28. package/dist/types/index.d.ts +13 -2
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/package.json +5 -1
  31. package/CHANGELOG.md +0 -593
  32. package/dist/deliverables.test.d.ts +0 -2
  33. package/dist/deliverables.test.d.ts.map +0 -1
  34. package/dist/deliverables.test.js +0 -232
  35. package/dist/deliverables.test.js.map +0 -1
  36. package/dist/domain/calendar.test.d.ts +0 -2
  37. package/dist/domain/calendar.test.d.ts.map +0 -1
  38. package/dist/domain/calendar.test.js +0 -181
  39. package/dist/domain/calendar.test.js.map +0 -1
  40. package/dist/domain/cpm.test.d.ts +0 -2
  41. package/dist/domain/cpm.test.d.ts.map +0 -1
  42. package/dist/domain/cpm.test.js +0 -166
  43. package/dist/domain/cpm.test.js.map +0 -1
  44. package/dist/domain/ddd.test.d.ts +0 -2
  45. package/dist/domain/ddd.test.d.ts.map +0 -1
  46. package/dist/domain/ddd.test.js +0 -349
  47. package/dist/domain/ddd.test.js.map +0 -1
  48. package/dist/domain/ladder.test.d.ts +0 -2
  49. package/dist/domain/ladder.test.d.ts.map +0 -1
  50. package/dist/domain/ladder.test.js +0 -213
  51. package/dist/domain/ladder.test.js.map +0 -1
  52. package/dist/domain/metrics.test.d.ts +0 -2
  53. package/dist/domain/metrics.test.d.ts.map +0 -1
  54. package/dist/domain/metrics.test.js +0 -252
  55. package/dist/domain/metrics.test.js.map +0 -1
  56. package/dist/domain/task-duration.test.d.ts +0 -2
  57. package/dist/domain/task-duration.test.d.ts.map +0 -1
  58. package/dist/domain/task-duration.test.js +0 -307
  59. package/dist/domain/task-duration.test.js.map +0 -1
  60. package/dist/domain/workload.test.d.ts +0 -2
  61. package/dist/domain/workload.test.d.ts.map +0 -1
  62. package/dist/domain/workload.test.js +0 -261
  63. package/dist/domain/workload.test.js.map +0 -1
  64. package/dist/engine/actor.test.d.ts +0 -2
  65. package/dist/engine/actor.test.d.ts.map +0 -1
  66. package/dist/engine/actor.test.js +0 -54
  67. package/dist/engine/actor.test.js.map +0 -1
  68. package/dist/engine/authorization.test.d.ts +0 -2
  69. package/dist/engine/authorization.test.d.ts.map +0 -1
  70. package/dist/engine/authorization.test.js +0 -154
  71. package/dist/engine/authorization.test.js.map +0 -1
  72. package/dist/engine/cascade.test.d.ts +0 -2
  73. package/dist/engine/cascade.test.d.ts.map +0 -1
  74. package/dist/engine/cascade.test.js +0 -99
  75. package/dist/engine/cascade.test.js.map +0 -1
  76. package/dist/engine/config.test.d.ts +0 -2
  77. package/dist/engine/config.test.d.ts.map +0 -1
  78. package/dist/engine/config.test.js +0 -46
  79. package/dist/engine/config.test.js.map +0 -1
  80. package/dist/engine/entity-events.test.d.ts +0 -2
  81. package/dist/engine/entity-events.test.d.ts.map +0 -1
  82. package/dist/engine/entity-events.test.js +0 -61
  83. package/dist/engine/entity-events.test.js.map +0 -1
  84. package/dist/index.test.d.ts +0 -2
  85. package/dist/index.test.d.ts.map +0 -1
  86. package/dist/index.test.js +0 -429
  87. package/dist/index.test.js.map +0 -1
  88. package/dist/plugins/plugins.test.d.ts +0 -2
  89. package/dist/plugins/plugins.test.d.ts.map +0 -1
  90. package/dist/plugins/plugins.test.js +0 -137
  91. package/dist/plugins/plugins.test.js.map +0 -1
  92. package/dist/schemas/schemas.test.d.ts +0 -2
  93. package/dist/schemas/schemas.test.d.ts.map +0 -1
  94. package/dist/schemas/schemas.test.js +0 -58
  95. package/dist/schemas/schemas.test.js.map +0 -1
  96. package/dist/status.test.d.ts +0 -2
  97. package/dist/status.test.d.ts.map +0 -1
  98. package/dist/status.test.js +0 -295
  99. package/dist/status.test.js.map +0 -1
  100. package/dist/storage/storage.test.d.ts +0 -2
  101. package/dist/storage/storage.test.d.ts.map +0 -1
  102. package/dist/storage/storage.test.js +0 -236
  103. package/dist/storage/storage.test.js.map +0 -1
  104. package/dist/storage/upload-limits.test.d.ts +0 -2
  105. package/dist/storage/upload-limits.test.d.ts.map +0 -1
  106. package/dist/storage/upload-limits.test.js +0 -31
  107. package/dist/storage/upload-limits.test.js.map +0 -1
  108. package/dist/store/conformance.test.d.ts +0 -2
  109. package/dist/store/conformance.test.d.ts.map +0 -1
  110. package/dist/store/conformance.test.js +0 -15
  111. package/dist/store/conformance.test.js.map +0 -1
  112. package/dist/store/firebase.test.d.ts +0 -2
  113. package/dist/store/firebase.test.d.ts.map +0 -1
  114. package/dist/store/firebase.test.js +0 -103
  115. package/dist/store/firebase.test.js.map +0 -1
  116. package/dist/store/query.test.d.ts +0 -2
  117. package/dist/store/query.test.d.ts.map +0 -1
  118. package/dist/store/query.test.js +0 -89
  119. package/dist/store/query.test.js.map +0 -1
  120. package/dist/store/sqlite.test.d.ts +0 -2
  121. package/dist/store/sqlite.test.d.ts.map +0 -1
  122. package/dist/store/sqlite.test.js +0 -177
  123. package/dist/store/sqlite.test.js.map +0 -1
  124. package/dist/task-state.test.d.ts +0 -2
  125. package/dist/task-state.test.d.ts.map +0 -1
  126. package/dist/task-state.test.js +0 -423
  127. package/dist/task-state.test.js.map +0 -1
  128. package/dist/use-case-validation.test.d.ts +0 -2
  129. package/dist/use-case-validation.test.d.ts.map +0 -1
  130. package/dist/use-case-validation.test.js +0 -281
  131. package/dist/use-case-validation.test.js.map +0 -1
  132. package/dist/utils/fractional-index.test.d.ts +0 -2
  133. package/dist/utils/fractional-index.test.d.ts.map +0 -1
  134. package/dist/utils/fractional-index.test.js +0 -182
  135. package/dist/utils/fractional-index.test.js.map +0 -1
  136. package/dist/utils/key.test.d.ts +0 -2
  137. package/dist/utils/key.test.d.ts.map +0 -1
  138. package/dist/utils/key.test.js +0 -65
  139. package/dist/utils/key.test.js.map +0 -1
  140. package/dist/utils/mentions.test.d.ts +0 -2
  141. package/dist/utils/mentions.test.d.ts.map +0 -1
  142. package/dist/utils/mentions.test.js +0 -114
  143. package/dist/utils/mentions.test.js.map +0 -1
  144. package/dist/webhooks/webhooks.test.d.ts +0 -2
  145. package/dist/webhooks/webhooks.test.d.ts.map +0 -1
  146. package/dist/webhooks/webhooks.test.js +0 -154
  147. package/dist/webhooks/webhooks.test.js.map +0 -1
  148. package/src/deliverables.test.ts +0 -284
  149. package/src/domain/authorization.ts +0 -82
  150. package/src/domain/calendar.test.ts +0 -216
  151. package/src/domain/calendar.ts +0 -502
  152. package/src/domain/cpm.test.ts +0 -189
  153. package/src/domain/cpm.ts +0 -258
  154. package/src/domain/custom-fields.ts +0 -172
  155. package/src/domain/ddd.test.ts +0 -442
  156. package/src/domain/entities.ts +0 -798
  157. package/src/domain/errors.ts +0 -38
  158. package/src/domain/events.ts +0 -369
  159. package/src/domain/graph.ts +0 -70
  160. package/src/domain/index.ts +0 -12
  161. package/src/domain/ladder.test.ts +0 -251
  162. package/src/domain/ladder.ts +0 -474
  163. package/src/domain/metrics.test.ts +0 -288
  164. package/src/domain/metrics.ts +0 -497
  165. package/src/domain/task-duration.test.ts +0 -354
  166. package/src/domain/workload.test.ts +0 -311
  167. package/src/domain/workload.ts +0 -457
  168. package/src/engine/actor.test.ts +0 -63
  169. package/src/engine/authorization.test.ts +0 -199
  170. package/src/engine/cascade.test.ts +0 -121
  171. package/src/engine/config.test.ts +0 -51
  172. package/src/engine/entity-events.test.ts +0 -67
  173. package/src/engine/index.ts +0 -2495
  174. package/src/index.test.ts +0 -514
  175. package/src/index.ts +0 -9
  176. package/src/plugins/index.ts +0 -103
  177. package/src/plugins/plugins.test.ts +0 -161
  178. package/src/schemas/index.ts +0 -402
  179. package/src/schemas/schemas.test.ts +0 -116
  180. package/src/status.test.ts +0 -354
  181. package/src/storage/file-storage.ts +0 -200
  182. package/src/storage/firebase-storage.ts +0 -209
  183. package/src/storage/index.ts +0 -3
  184. package/src/storage/s3.ts +0 -151
  185. package/src/storage/storage.test.ts +0 -274
  186. package/src/storage/upload-limits.test.ts +0 -41
  187. package/src/store/conformance.test.ts +0 -15
  188. package/src/store/firebase.test.ts +0 -131
  189. package/src/store/firebase.ts +0 -658
  190. package/src/store/index.ts +0 -623
  191. package/src/store/query.test.ts +0 -110
  192. package/src/store/query.ts +0 -113
  193. package/src/store/sqlite.test.ts +0 -218
  194. package/src/store/sqlite.ts +0 -1480
  195. package/src/task-state.test.ts +0 -506
  196. package/src/testing/conformance.ts +0 -319
  197. package/src/testing/index.ts +0 -1
  198. package/src/types/index.ts +0 -871
  199. package/src/use-case-validation.test.ts +0 -324
  200. package/src/utils/fractional-index.test.ts +0 -228
  201. package/src/utils/fractional-index.ts +0 -254
  202. package/src/utils/index.ts +0 -7
  203. package/src/utils/key.test.ts +0 -76
  204. package/src/utils/key.ts +0 -62
  205. package/src/utils/mentions.test.ts +0 -132
  206. package/src/utils/mentions.ts +0 -131
  207. package/src/utils/status.ts +0 -419
  208. package/src/utils/workflow.ts +0 -306
  209. package/src/webhooks/dispatcher.ts +0 -190
  210. package/src/webhooks/index.ts +0 -2
  211. package/src/webhooks/signature.ts +0 -57
  212. package/src/webhooks/webhooks.test.ts +0 -201
  213. package/tsconfig.json +0 -8
  214. package/tsconfig.tsbuildinfo +0 -1
@@ -1,110 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import {
3
- CriticalPathEngine,
4
- InMemoryStore,
5
- SQLiteStore,
6
- FirebaseStore,
7
- InMemoryFirestoreMock,
8
- ValidationError,
9
- createRolePolicy,
10
- MAX_PAGE_SIZE,
11
- type StorageAdapter,
12
- type Task
13
- } from '../index.js';
14
-
15
- const stores: Array<[string, () => StorageAdapter]> = [
16
- ['InMemoryStore', () => new InMemoryStore()],
17
- ['SQLiteStore', () => new SQLiteStore({ filename: ':memory:' })],
18
- ['FirebaseStore', () => new FirebaseStore({ db: new InMemoryFirestoreMock() })]
19
- ];
20
-
21
- describe.each(stores)('task and activity queries (%s)', (_name, makeStore) => {
22
- async function setup() {
23
- const engine = new CriticalPathEngine({ store: makeStore() });
24
- const project = await engine.createProject({ name: 'Query' });
25
- const other = await engine.createProject({ name: 'Other' });
26
- const sprint = await engine.createIteration({ projectId: project.id, name: 'S1', status: 'active' });
27
- const parent = await engine.createTask({ projectId: project.id, title: 'Parent', status: 'in_progress', priority: 'high', assigneeId: 'ana' });
28
- const child = await engine.createTask({ projectId: project.id, title: 'Child', parentId: parent.id, status: 'todo', priority: 'low', iterationId: sprint.id });
29
- const shared = await engine.createTask({
30
- projectId: project.id,
31
- title: 'Shared',
32
- status: 'done',
33
- priority: 'high',
34
- assignees: [{ id: 'ana', type: 'user' }, { id: 'ben', type: 'user' }]
35
- });
36
- const elsewhere = await engine.createTask({ projectId: other.id, title: 'Elsewhere', assigneeId: 'ana' });
37
- return { engine, project, other, sprint, parent, child, shared, elsewhere };
38
- }
39
- const titles = (tasks: Task[]) => tasks.map((t) => t.title).sort();
40
-
41
- it('filters by status, priority, assignee (including assignees), iteration and parent', async () => {
42
- const { engine, project, sprint, parent } = await setup();
43
- const q = (query: object) => engine.queryTasks({ projectId: project.id, ...query }).then((p) => titles(p.items));
44
-
45
- expect(await q({ status: ['todo', 'done'] })).toEqual(['Child', 'Shared']);
46
- expect(await q({ priority: ['high'] })).toEqual(['Parent', 'Shared']);
47
- expect(await q({ assigneeId: 'ana' })).toEqual(['Parent', 'Shared']);
48
- expect(await q({ assigneeId: 'ben' })).toEqual(['Shared']);
49
- expect(await q({ iterationId: sprint.id })).toEqual(['Child']);
50
- expect(await q({ parentId: parent.id })).toEqual(['Child']);
51
- expect(await q({ parentId: null })).toEqual(['Parent', 'Shared']);
52
- expect(titles((await engine.queryTasks({ assigneeId: 'ana' })).items)).toEqual(['Elsewhere', 'Parent', 'Shared']);
53
- });
54
-
55
- it('pages through every task exactly once, oldest first', async () => {
56
- const { engine, project } = await setup();
57
- for (let i = 0; i < 12; i++) await engine.createTask({ projectId: project.id, title: `Bulk ${i}` });
58
-
59
- const seen: Task[] = [];
60
- let cursor: string | undefined;
61
- do {
62
- const page = await engine.queryTasks({ projectId: project.id, limit: 5, cursor });
63
- expect(page.items.length).toBeLessThanOrEqual(5);
64
- seen.push(...page.items);
65
- cursor = page.nextCursor;
66
- } while (cursor);
67
-
68
- expect(seen).toHaveLength(15);
69
- expect(new Set(seen.map((t) => t.id)).size).toBe(15);
70
- const keys = seen.map((t) => `${t.createdAt}|${t.id}`);
71
- expect([...keys].sort()).toEqual(keys);
72
- });
73
-
74
- it('pages the activity feed newest first', async () => {
75
- const { engine, project } = await setup();
76
- const all = (await engine.queryActivities({ projectId: project.id, limit: MAX_PAGE_SIZE })).items;
77
- expect(all.length).toBeGreaterThan(3);
78
- const keys = all.map((a) => `${a.createdAt}|${a.id}`);
79
- expect([...keys].sort().reverse()).toEqual(keys);
80
-
81
- const first = await engine.queryActivities({ projectId: project.id, limit: 2 });
82
- const second = await engine.queryActivities({ projectId: project.id, limit: 2, cursor: first.nextCursor });
83
- expect([...first.items, ...second.items].map((a) => a.id)).toEqual(all.slice(0, 4).map((a) => a.id));
84
- });
85
-
86
- it('rejects malformed cursors and clamps page sizes', async () => {
87
- const { engine, project } = await setup();
88
- await expect(engine.queryTasks({ projectId: project.id, cursor: 'not-a-cursor' })).rejects.toThrow(ValidationError);
89
- expect((await engine.queryTasks({ projectId: project.id, limit: 0 })).items).toHaveLength(1);
90
- expect((await engine.queryTasks({ projectId: project.id, limit: 10_000 })).items).toHaveLength(3);
91
- });
92
- });
93
-
94
- describe('query authorization', () => {
95
- it('limits cross-project queries and activity feeds to readable projects', async () => {
96
- const engine = new CriticalPathEngine({ authorize: createRolePolicy() });
97
- const mine = await engine.createProject({ name: 'Mine', members: [{ userId: 'ana', role: 'viewer' }] });
98
- const secret = await engine.createProject({ name: 'Secret' });
99
- await engine.createTask({ projectId: mine.id, title: 'Visible' });
100
- await engine.createTask({ projectId: secret.id, title: 'Hidden' });
101
- const ana = engine.withActor({ userId: 'ana' });
102
-
103
- expect((await ana.queryTasks()).items.map((t) => t.title)).toEqual(['Visible']);
104
- expect((await ana.queryTasks({ projectId: secret.id })).items).toEqual([]);
105
- expect((await ana.queryTasks({ projectIds: [mine.id, secret.id] })).items.map((t) => t.title)).toEqual(['Visible']);
106
- const feed = (await ana.queryActivities()).items;
107
- expect(feed.length).toBeGreaterThan(0);
108
- expect(feed.every((a) => a.projectId === mine.id)).toBe(true);
109
- });
110
- });
@@ -1,113 +0,0 @@
1
- import type { Activity, Task } from '../types/index.js';
2
- import { ValidationError } from '../domain/errors.js';
3
-
4
- export const DEFAULT_PAGE_SIZE = 100;
5
- export const MAX_PAGE_SIZE = 500;
6
-
7
- /** Filters for `queryTasks`. All given filters must match. */
8
- export interface TaskQuery {
9
- projectId?: string;
10
- /** Restrict to these projects (used for authorization when no `projectId` is given). */
11
- projectIds?: string[];
12
- /** Any of these statuses. */
13
- status?: string[];
14
- /** Matches `assigneeId` or any entry in `assignees`. */
15
- assigneeId?: string;
16
- /** Any of these priorities. */
17
- priority?: string[];
18
- iterationId?: string;
19
- deliverableId?: string;
20
- containerId?: string;
21
- /** A task id for its subtasks, or `null` for top-level tasks only. */
22
- parentId?: string | null;
23
- limit?: number;
24
- /** Opaque cursor from a previous page's `nextCursor`. */
25
- cursor?: string;
26
- }
27
-
28
- export interface ActivityQuery {
29
- projectId?: string;
30
- projectIds?: string[];
31
- taskId?: string;
32
- limit?: number;
33
- cursor?: string;
34
- }
35
-
36
- /** One page of results. `nextCursor` is set when more results exist. */
37
- export interface Page<T> {
38
- items: T[];
39
- nextCursor?: string;
40
- }
41
-
42
- /** Clamps a requested page size to `[1, MAX_PAGE_SIZE]`, defaulting to `DEFAULT_PAGE_SIZE`. */
43
- export function pageSize(limit: number | undefined): number {
44
- if (limit === undefined || !Number.isFinite(limit)) return DEFAULT_PAGE_SIZE;
45
- return Math.min(Math.max(1, Math.floor(limit)), MAX_PAGE_SIZE);
46
- }
47
-
48
- /** Cursors encode the last item's sort key and id (keyset pagination). */
49
- export function encodeCursor(sortKey: string, id: string): string {
50
- return btoa(JSON.stringify([sortKey, id])).replace(/=+$/, '');
51
- }
52
-
53
- export function decodeCursor(cursor: string | undefined): [string, string] | undefined {
54
- if (!cursor) return undefined;
55
- try {
56
- const value = JSON.parse(atob(cursor));
57
- if (Array.isArray(value) && value.length === 2 && value.every((v) => typeof v === 'string')) {
58
- return value as [string, string];
59
- }
60
- } catch {
61
- // fall through
62
- }
63
- throw new ValidationError('Invalid pagination cursor.');
64
- }
65
-
66
- export function matchesTaskQuery(task: Task, query: TaskQuery): boolean {
67
- if (query.projectId && task.projectId !== query.projectId) return false;
68
- if (query.projectIds && !query.projectIds.includes(task.projectId)) return false;
69
- if (query.status?.length && !query.status.includes(task.status)) return false;
70
- if (query.priority?.length && !query.priority.includes(task.priority)) return false;
71
- if (query.iterationId && task.iterationId !== query.iterationId) return false;
72
- if (query.deliverableId && task.deliverableId !== query.deliverableId) return false;
73
- if (query.containerId && task.containerId !== query.containerId) return false;
74
- if (query.parentId === null && task.parentId) return false;
75
- if (query.parentId && task.parentId !== query.parentId) return false;
76
- if (query.assigneeId && task.assigneeId !== query.assigneeId && !task.assignees?.some((a) => a.id === query.assigneeId)) {
77
- return false;
78
- }
79
- return true;
80
- }
81
-
82
- export function matchesActivityQuery(activity: Activity, query: ActivityQuery): boolean {
83
- if (query.projectId && activity.projectId !== query.projectId) return false;
84
- if (query.projectIds && (!activity.projectId || !query.projectIds.includes(activity.projectId))) return false;
85
- if (query.taskId && activity.taskId !== query.taskId) return false;
86
- return true;
87
- }
88
-
89
- /**
90
- * Sorts by `(sortKey, id)` and returns the page after `cursor`. Tasks page oldest first
91
- * (`asc`), activity feeds newest first (`desc`).
92
- */
93
- export function paginate<T extends { id: string }>(
94
- items: T[],
95
- sortKey: (item: T) => string,
96
- direction: 'asc' | 'desc',
97
- limit: number | undefined,
98
- cursor: string | undefined
99
- ): Page<T> {
100
- const sign = direction === 'asc' ? 1 : -1;
101
- const compare = (a: [string, string], b: [string, string]) =>
102
- sign * (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : a[1] < b[1] ? -1 : a[1] > b[1] ? 1 : 0);
103
- const after = decodeCursor(cursor);
104
- const sorted = [...items].sort((a, b) => compare([sortKey(a), a.id], [sortKey(b), b.id]));
105
- const remaining = after ? sorted.filter((item) => compare([sortKey(item), item.id], after) > 0) : sorted;
106
- const size = pageSize(limit);
107
- const page = remaining.slice(0, size);
108
- const last = page[page.length - 1];
109
- return {
110
- items: page,
111
- nextCursor: remaining.length > size && last ? encodeCursor(sortKey(last), last.id) : undefined
112
- };
113
- }
@@ -1,218 +0,0 @@
1
- import { describe, it, expect, beforeEach } from 'vitest';
2
- import { execFileSync } from 'node:child_process';
3
- import { existsSync } from 'node:fs';
4
- import { fileURLToPath, pathToFileURL } from 'node:url';
5
- import { SQLiteStore } from './sqlite.js';
6
-
7
- describe('SQLiteStore', () => {
8
- let store: SQLiteStore;
9
-
10
- beforeEach(() => {
11
- store = new SQLiteStore({ filename: ':memory:' });
12
- });
13
-
14
- it('should create and retrieve projects', async () => {
15
- const project = await store.createProject({
16
- key: 'SQLITE',
17
- name: 'SQLite Test Project',
18
- description: 'Testing SQLite adapter'
19
- });
20
-
21
- expect(project.id).toMatch(/^proj_/);
22
- expect(project.name).toBe('SQLite Test Project');
23
-
24
- const fetched = await store.getProject(project.id);
25
- expect(fetched).not.toBeNull();
26
- expect(fetched?.key).toBe('SQLITE');
27
-
28
- const all = await store.getProjects();
29
- expect(all).toHaveLength(1);
30
- });
31
-
32
- it('should create, update, filter, and delete tasks', async () => {
33
- const project = await store.createProject({ key: 'P1', name: 'Proj 1' });
34
- const task = await store.createTask({
35
- projectId: project.id,
36
- title: 'SQLite Task 1',
37
- status: 'todo',
38
- priority: 'high',
39
- tags: ['sqlite', 'db']
40
- });
41
-
42
- expect(task.id).toMatch(/^task_/);
43
- expect(task.priority).toBe('high');
44
- expect(task.tags).toContain('sqlite');
45
-
46
- const updated = await store.updateTask(task.id, {
47
- status: 'in_progress',
48
- isBlocked: true,
49
- blockedReason: 'Waiting for SQLite lock'
50
- });
51
- expect(updated?.status).toBe('in_progress');
52
- expect(updated?.isBlocked).toBe(true);
53
- expect(updated?.blockedReason).toBe('Waiting for SQLite lock');
54
-
55
- const fetchedTask = await store.getTask(task.id);
56
- expect(fetchedTask?.isBlocked).toBe(true);
57
- expect(fetchedTask?.blockedReason).toBe('Waiting for SQLite lock');
58
-
59
- const unblocked = await store.updateTask(task.id, {
60
- isBlocked: false,
61
- blockedReason: null
62
- });
63
- expect(unblocked?.isBlocked).toBe(false);
64
-
65
- const projectTasks = await store.getTasks(project.id);
66
- expect(projectTasks).toHaveLength(1);
67
-
68
- const deleted = await store.deleteTask(task.id);
69
- expect(deleted).toBe(true);
70
-
71
- const remaining = await store.getTasks(project.id);
72
- expect(remaining).toHaveLength(0);
73
- });
74
-
75
- it('should handle comments, activities, and time tracking', async () => {
76
- const comment = await store.addComment({
77
- taskId: 'task_1',
78
- authorId: 'user_1',
79
- authorType: 'user',
80
- content: 'Great work!'
81
- });
82
- expect(comment.id).toMatch(/^cmt_/);
83
- expect(comment.authorType).toBe('user');
84
-
85
- // Threaded reply
86
- const reply = await store.addComment({
87
- taskId: 'task_1',
88
- authorId: 'agent_1',
89
- authorType: 'agent',
90
- parentId: comment.id,
91
- content: 'I agree!'
92
- });
93
- expect(reply.parentId).toBe(comment.id);
94
- expect(reply.authorType).toBe('agent');
95
-
96
- const comments = await store.getComments('task_1');
97
- expect(comments).toHaveLength(2);
98
-
99
- const updatedComment = await store.updateComment(comment.id, {
100
- content: 'Updated content',
101
- mentions: ['planner', 'coordinator']
102
- });
103
- expect(updatedComment?.content).toBe('Updated content');
104
- expect(updatedComment?.mentions).toEqual(['planner', 'coordinator']);
105
-
106
- const fetchedComment = await store.getComment(comment.id);
107
- expect(fetchedComment?.content).toBe('Updated content');
108
- expect(fetchedComment?.mentions).toEqual(['planner', 'coordinator']);
109
-
110
- const timeEntry = await store.logTime({
111
- taskId: 'task_1',
112
- userId: 'user_1',
113
- hours: 2.5,
114
- description: 'Code review'
115
- });
116
- expect(timeEntry.hours).toBe(2.5);
117
-
118
- const entries = await store.getTimeEntries('task_1');
119
- expect(entries).toHaveLength(1);
120
-
121
- // Emoji reactions
122
- const reactComment = await store.addReaction(comment.id, { emoji: '🔥', userId: 'user_2' });
123
- expect(reactComment?.reactions).toHaveLength(1);
124
- expect(reactComment?.reactions?.[0].emoji).toBe('🔥');
125
-
126
- const fetchedWithReactions = await store.getComment(comment.id);
127
- expect(fetchedWithReactions?.reactions).toHaveLength(1);
128
-
129
- const unreactComment = await store.removeReaction(comment.id, { emoji: '🔥', userId: 'user_2' });
130
- expect(unreactComment?.reactions).toHaveLength(0);
131
-
132
- const deletedComment = await store.deleteComment(reply.id);
133
- expect(deletedComment).toBe(true);
134
- expect(await store.getComments('task_1')).toHaveLength(1);
135
- });
136
-
137
- it('should create, filter, retrieve, and delete attachments', async () => {
138
- const attachment = await store.createAttachment({
139
- filename: 'design-mockup.fig',
140
- url: 'https://storage.example.com/design-mockup.fig',
141
- storageKey: 'attachments/task_1/design-mockup.fig',
142
- mimeType: 'application/octet-stream',
143
- sizeBytes: 2048,
144
- taskId: 'task_1',
145
- projectId: 'proj_1',
146
- uploaderId: 'user_1',
147
- uploaderType: 'user'
148
- });
149
-
150
- expect(attachment.id).toMatch(/^att_/);
151
- expect(attachment.filename).toBe('design-mockup.fig');
152
-
153
- const fetched = await store.getAttachment(attachment.id);
154
- expect(fetched?.url).toBe('https://storage.example.com/design-mockup.fig');
155
-
156
- const taskAttachments = await store.getAttachments({ taskId: 'task_1' });
157
- expect(taskAttachments).toHaveLength(1);
158
-
159
- const projectAttachments = await store.getAttachments({ projectId: 'proj_1' });
160
- expect(projectAttachments).toHaveLength(1);
161
-
162
- const nonExistent = await store.getAttachments({ taskId: 'other_task' });
163
- expect(nonExistent).toHaveLength(0);
164
-
165
- const deleted = await store.deleteAttachment(attachment.id);
166
- expect(deleted).toBe(true);
167
-
168
- const remaining = await store.getAttachments({ taskId: 'task_1' });
169
- expect(remaining).toHaveLength(0);
170
- });
171
-
172
- it('should create, retrieve, update, and delete workflows', async () => {
173
- const workflow = await store.createWorkflow({
174
- name: 'SQLite Workflow',
175
- isDefault: true,
176
- defaultStatusKey: 'todo',
177
- statuses: [{ key: 'todo', label: 'To Do', category: 'not_started' }],
178
- transitions: []
179
- });
180
-
181
- expect(workflow.id).toMatch(/^wf_/);
182
- expect(workflow.name).toBe('SQLite Workflow');
183
-
184
- const fetched = await store.getWorkflow(workflow.id);
185
- expect(fetched?.isDefault).toBe(true);
186
-
187
- const updated = await store.updateWorkflow(workflow.id, { name: 'Updated SQLite Workflow' });
188
- expect(updated?.name).toBe('Updated SQLite Workflow');
189
-
190
- const all = await store.getWorkflows();
191
- expect(all).toHaveLength(1);
192
-
193
- const deleted = await store.deleteWorkflow(workflow.id);
194
- expect(deleted).toBe(true);
195
-
196
- const remaining = await store.getWorkflows();
197
- expect(remaining).toHaveLength(0);
198
- });
199
- });
200
-
201
- describe('SQLiteStore outside the vitest runtime', () => {
202
- const distEntry = fileURLToPath(new URL('../../dist/index.js', import.meta.url));
203
-
204
- // vitest injects `require` into ESM modules, which once hid an `eval("require(...)")` failure
205
- // that broke `new SQLiteStore({ filename })` in plain Node. Run the built package in a real Node process.
206
- it.skipIf(!existsSync(distEntry))('constructs from a filename in a plain Node ESM process', () => {
207
- const script = `
208
- const { SQLiteStore } = await import(${JSON.stringify(pathToFileURL(distEntry).href)});
209
- const store = new SQLiteStore({ filename: ':memory:' });
210
- const project = await store.createProject({ key: 'SMOKE', name: 'Smoke' });
211
- process.stdout.write(project.key);
212
- `;
213
- const output = execFileSync(process.execPath, ['--input-type=module', '--no-warnings', '-e', script], {
214
- encoding: 'utf8'
215
- });
216
- expect(output).toBe('SMOKE');
217
- });
218
- });