@critical-path/core 0.35.0 → 0.36.1
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/README.md +11 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +25 -2
- package/dist/engine/index.js.map +1 -1
- package/dist/types/index.d.ts +11 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -1
- package/CHANGELOG.md +0 -584
- package/dist/deliverables.test.d.ts +0 -2
- package/dist/deliverables.test.d.ts.map +0 -1
- package/dist/deliverables.test.js +0 -232
- package/dist/deliverables.test.js.map +0 -1
- package/dist/domain/calendar.test.d.ts +0 -2
- package/dist/domain/calendar.test.d.ts.map +0 -1
- package/dist/domain/calendar.test.js +0 -181
- package/dist/domain/calendar.test.js.map +0 -1
- package/dist/domain/cpm.test.d.ts +0 -2
- package/dist/domain/cpm.test.d.ts.map +0 -1
- package/dist/domain/cpm.test.js +0 -166
- package/dist/domain/cpm.test.js.map +0 -1
- package/dist/domain/ddd.test.d.ts +0 -2
- package/dist/domain/ddd.test.d.ts.map +0 -1
- package/dist/domain/ddd.test.js +0 -349
- package/dist/domain/ddd.test.js.map +0 -1
- package/dist/domain/ladder.test.d.ts +0 -2
- package/dist/domain/ladder.test.d.ts.map +0 -1
- package/dist/domain/ladder.test.js +0 -213
- package/dist/domain/ladder.test.js.map +0 -1
- package/dist/domain/metrics.test.d.ts +0 -2
- package/dist/domain/metrics.test.d.ts.map +0 -1
- package/dist/domain/metrics.test.js +0 -252
- package/dist/domain/metrics.test.js.map +0 -1
- package/dist/domain/task-duration.test.d.ts +0 -2
- package/dist/domain/task-duration.test.d.ts.map +0 -1
- package/dist/domain/task-duration.test.js +0 -307
- package/dist/domain/task-duration.test.js.map +0 -1
- package/dist/domain/workload.test.d.ts +0 -2
- package/dist/domain/workload.test.d.ts.map +0 -1
- package/dist/domain/workload.test.js +0 -261
- package/dist/domain/workload.test.js.map +0 -1
- package/dist/engine/actor.test.d.ts +0 -2
- package/dist/engine/actor.test.d.ts.map +0 -1
- package/dist/engine/actor.test.js +0 -54
- package/dist/engine/actor.test.js.map +0 -1
- package/dist/engine/authorization.test.d.ts +0 -2
- package/dist/engine/authorization.test.d.ts.map +0 -1
- package/dist/engine/authorization.test.js +0 -154
- package/dist/engine/authorization.test.js.map +0 -1
- package/dist/engine/cascade.test.d.ts +0 -2
- package/dist/engine/cascade.test.d.ts.map +0 -1
- package/dist/engine/cascade.test.js +0 -99
- package/dist/engine/cascade.test.js.map +0 -1
- package/dist/engine/config.test.d.ts +0 -2
- package/dist/engine/config.test.d.ts.map +0 -1
- package/dist/engine/config.test.js +0 -46
- package/dist/engine/config.test.js.map +0 -1
- package/dist/engine/entity-events.test.d.ts +0 -2
- package/dist/engine/entity-events.test.d.ts.map +0 -1
- package/dist/engine/entity-events.test.js +0 -61
- package/dist/engine/entity-events.test.js.map +0 -1
- package/dist/index.test.d.ts +0 -2
- package/dist/index.test.d.ts.map +0 -1
- package/dist/index.test.js +0 -429
- package/dist/index.test.js.map +0 -1
- package/dist/plugins/plugins.test.d.ts +0 -2
- package/dist/plugins/plugins.test.d.ts.map +0 -1
- package/dist/plugins/plugins.test.js +0 -137
- package/dist/plugins/plugins.test.js.map +0 -1
- package/dist/schemas/schemas.test.d.ts +0 -2
- package/dist/schemas/schemas.test.d.ts.map +0 -1
- package/dist/schemas/schemas.test.js +0 -58
- package/dist/schemas/schemas.test.js.map +0 -1
- package/dist/status.test.d.ts +0 -2
- package/dist/status.test.d.ts.map +0 -1
- package/dist/status.test.js +0 -295
- package/dist/status.test.js.map +0 -1
- package/dist/storage/storage.test.d.ts +0 -2
- package/dist/storage/storage.test.d.ts.map +0 -1
- package/dist/storage/storage.test.js +0 -236
- package/dist/storage/storage.test.js.map +0 -1
- package/dist/store/conformance.test.d.ts +0 -2
- package/dist/store/conformance.test.d.ts.map +0 -1
- package/dist/store/conformance.test.js +0 -15
- package/dist/store/conformance.test.js.map +0 -1
- package/dist/store/firebase.test.d.ts +0 -2
- package/dist/store/firebase.test.d.ts.map +0 -1
- package/dist/store/firebase.test.js +0 -103
- package/dist/store/firebase.test.js.map +0 -1
- package/dist/store/query.test.d.ts +0 -2
- package/dist/store/query.test.d.ts.map +0 -1
- package/dist/store/query.test.js +0 -89
- package/dist/store/query.test.js.map +0 -1
- package/dist/store/sqlite.test.d.ts +0 -2
- package/dist/store/sqlite.test.d.ts.map +0 -1
- package/dist/store/sqlite.test.js +0 -177
- package/dist/store/sqlite.test.js.map +0 -1
- package/dist/task-state.test.d.ts +0 -2
- package/dist/task-state.test.d.ts.map +0 -1
- package/dist/task-state.test.js +0 -423
- package/dist/task-state.test.js.map +0 -1
- package/dist/use-case-validation.test.d.ts +0 -2
- package/dist/use-case-validation.test.d.ts.map +0 -1
- package/dist/use-case-validation.test.js +0 -281
- package/dist/use-case-validation.test.js.map +0 -1
- package/dist/utils/fractional-index.test.d.ts +0 -2
- package/dist/utils/fractional-index.test.d.ts.map +0 -1
- package/dist/utils/fractional-index.test.js +0 -182
- package/dist/utils/fractional-index.test.js.map +0 -1
- package/dist/utils/key.test.d.ts +0 -2
- package/dist/utils/key.test.d.ts.map +0 -1
- package/dist/utils/key.test.js +0 -65
- package/dist/utils/key.test.js.map +0 -1
- package/dist/utils/mentions.test.d.ts +0 -2
- package/dist/utils/mentions.test.d.ts.map +0 -1
- package/dist/utils/mentions.test.js +0 -114
- package/dist/utils/mentions.test.js.map +0 -1
- package/dist/webhooks/webhooks.test.d.ts +0 -2
- package/dist/webhooks/webhooks.test.d.ts.map +0 -1
- package/dist/webhooks/webhooks.test.js +0 -154
- package/dist/webhooks/webhooks.test.js.map +0 -1
- package/src/deliverables.test.ts +0 -284
- package/src/domain/authorization.ts +0 -82
- package/src/domain/calendar.test.ts +0 -216
- package/src/domain/calendar.ts +0 -502
- package/src/domain/cpm.test.ts +0 -189
- package/src/domain/cpm.ts +0 -258
- package/src/domain/custom-fields.ts +0 -172
- package/src/domain/ddd.test.ts +0 -442
- package/src/domain/entities.ts +0 -798
- package/src/domain/errors.ts +0 -38
- package/src/domain/events.ts +0 -369
- package/src/domain/graph.ts +0 -70
- package/src/domain/index.ts +0 -12
- package/src/domain/ladder.test.ts +0 -251
- package/src/domain/ladder.ts +0 -474
- package/src/domain/metrics.test.ts +0 -288
- package/src/domain/metrics.ts +0 -497
- package/src/domain/task-duration.test.ts +0 -354
- package/src/domain/workload.test.ts +0 -311
- package/src/domain/workload.ts +0 -457
- package/src/engine/actor.test.ts +0 -63
- package/src/engine/authorization.test.ts +0 -199
- package/src/engine/cascade.test.ts +0 -121
- package/src/engine/config.test.ts +0 -51
- package/src/engine/entity-events.test.ts +0 -67
- package/src/engine/index.ts +0 -2472
- package/src/index.test.ts +0 -514
- package/src/index.ts +0 -9
- package/src/plugins/index.ts +0 -103
- package/src/plugins/plugins.test.ts +0 -161
- package/src/schemas/index.ts +0 -402
- package/src/schemas/schemas.test.ts +0 -116
- package/src/status.test.ts +0 -354
- package/src/storage/file-storage.ts +0 -200
- package/src/storage/firebase-storage.ts +0 -209
- package/src/storage/index.ts +0 -3
- package/src/storage/s3.ts +0 -151
- package/src/storage/storage.test.ts +0 -274
- package/src/store/conformance.test.ts +0 -15
- package/src/store/firebase.test.ts +0 -131
- package/src/store/firebase.ts +0 -658
- package/src/store/index.ts +0 -623
- package/src/store/query.test.ts +0 -110
- package/src/store/query.ts +0 -113
- package/src/store/sqlite.test.ts +0 -218
- package/src/store/sqlite.ts +0 -1480
- package/src/task-state.test.ts +0 -506
- package/src/testing/conformance.ts +0 -319
- package/src/testing/index.ts +0 -1
- package/src/types/index.ts +0 -859
- package/src/use-case-validation.test.ts +0 -324
- package/src/utils/fractional-index.test.ts +0 -228
- package/src/utils/fractional-index.ts +0 -254
- package/src/utils/index.ts +0 -7
- package/src/utils/key.test.ts +0 -76
- package/src/utils/key.ts +0 -62
- package/src/utils/mentions.test.ts +0 -132
- package/src/utils/mentions.ts +0 -131
- package/src/utils/status.ts +0 -419
- package/src/utils/workflow.ts +0 -306
- package/src/webhooks/dispatcher.ts +0 -190
- package/src/webhooks/index.ts +0 -2
- package/src/webhooks/signature.ts +0 -57
- package/src/webhooks/webhooks.test.ts +0 -201
- package/tsconfig.json +0 -8
- package/tsconfig.tsbuildinfo +0 -1
package/src/status.test.ts
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from 'vitest';
|
|
2
|
-
import { CriticalPathEngine } from './engine/index.js';
|
|
3
|
-
import {
|
|
4
|
-
resolveStatusDefinition,
|
|
5
|
-
deriveTaskLifecycleState,
|
|
6
|
-
isDraftTask,
|
|
7
|
-
isArchivedTask,
|
|
8
|
-
isTrashedTask,
|
|
9
|
-
isTrashedOrArchivedTask,
|
|
10
|
-
isWorkflowTask,
|
|
11
|
-
getTaskSemanticStatus,
|
|
12
|
-
isTaskCompleted,
|
|
13
|
-
isTaskInProgress,
|
|
14
|
-
isTaskNotStarted,
|
|
15
|
-
isTaskCanceled,
|
|
16
|
-
isTaskActive,
|
|
17
|
-
isTaskUnassigned
|
|
18
|
-
} from './utils/status.js';
|
|
19
|
-
import type { Task, StatusDefinition, Workflow } from './types/index.js';
|
|
20
|
-
|
|
21
|
-
describe('Universal Semantic Statuses & Implied Statuses', () => {
|
|
22
|
-
describe('resolveStatusDefinition', () => {
|
|
23
|
-
it('resolves core standard statuses to their semantic category', () => {
|
|
24
|
-
expect(resolveStatusDefinition('todo').category).toBe('not_started');
|
|
25
|
-
expect(resolveStatusDefinition('backlog').category).toBe('not_started');
|
|
26
|
-
expect(resolveStatusDefinition('in_progress').category).toBe('in_progress');
|
|
27
|
-
expect(resolveStatusDefinition('in_review').category).toBe('in_progress');
|
|
28
|
-
expect(resolveStatusDefinition('done').category).toBe('completed');
|
|
29
|
-
expect(resolveStatusDefinition('canceled').category).toBe('canceled');
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('resolves custom status definitions when provided', () => {
|
|
33
|
-
const customDefs: StatusDefinition[] = [
|
|
34
|
-
{ key: 'concept', label: 'Concept & Brainstorming', category: 'not_started' },
|
|
35
|
-
{ key: 'client_review', label: 'Client Feedback Session', category: 'in_progress' },
|
|
36
|
-
{ key: 'shipped', label: 'Shipped to Customer', category: 'completed' },
|
|
37
|
-
{ key: 'abandoned', label: 'Abandoned Initiative', category: 'canceled' }
|
|
38
|
-
];
|
|
39
|
-
|
|
40
|
-
expect(resolveStatusDefinition('concept', customDefs).category).toBe('not_started');
|
|
41
|
-
expect(resolveStatusDefinition('client_review', customDefs).category).toBe('in_progress');
|
|
42
|
-
expect(resolveStatusDefinition('shipped', customDefs).category).toBe('completed');
|
|
43
|
-
expect(resolveStatusDefinition('abandoned', customDefs).category).toBe('canceled');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('infers category heuristically when unknown status key is provided', () => {
|
|
47
|
-
expect(resolveStatusDefinition('draft_v2').category).toBe('not_started');
|
|
48
|
-
expect(resolveStatusDefinition('final_approved').category).toBe('completed');
|
|
49
|
-
expect(resolveStatusDefinition('active_development').category).toBe('in_progress');
|
|
50
|
-
expect(resolveStatusDefinition('rejected_proposal').category).toBe('canceled');
|
|
51
|
-
expect(resolveStatusDefinition('custom_arbitrary_key').category).toBe('not_started');
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe('deriveTaskLifecycleState', () => {
|
|
56
|
-
const baseTask: Task = {
|
|
57
|
-
id: 'task_1',
|
|
58
|
-
projectId: 'proj_1',
|
|
59
|
-
title: 'Design Wireframes',
|
|
60
|
-
status: 'todo',
|
|
61
|
-
priority: 'high',
|
|
62
|
-
createdAt: '2026-09-01T00:00:00.000Z',
|
|
63
|
-
updatedAt: '2026-09-01T00:00:00.000Z'
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
it('derives basic state for not_started task', () => {
|
|
67
|
-
const derived = deriveTaskLifecycleState(baseTask);
|
|
68
|
-
expect(derived.semanticStatus).toBe('not_started');
|
|
69
|
-
expect(derived.isActive).toBe(false);
|
|
70
|
-
expect(derived.isDone).toBe(false);
|
|
71
|
-
expect(derived.isCancelled).toBe(false);
|
|
72
|
-
expect(derived.isReady).toBe(true);
|
|
73
|
-
expect(derived.isBlocked).toBe(false);
|
|
74
|
-
expect(derived.isUnassigned).toBe(true);
|
|
75
|
-
expect(derived.isUnplanned).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('derives blocked and ready states based on upstream tasks', () => {
|
|
79
|
-
const upstream1: Task = {
|
|
80
|
-
...baseTask,
|
|
81
|
-
id: 'task_up1',
|
|
82
|
-
status: 'in_progress',
|
|
83
|
-
semanticStatus: 'in_progress'
|
|
84
|
-
};
|
|
85
|
-
const upstream2: Task = {
|
|
86
|
-
...baseTask,
|
|
87
|
-
id: 'task_up2',
|
|
88
|
-
status: 'done',
|
|
89
|
-
semanticStatus: 'completed'
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// When upstream1 is in progress, task_1 is blocked
|
|
93
|
-
const blockedState = deriveTaskLifecycleState(baseTask, {
|
|
94
|
-
upstreamTasks: [upstream1, upstream2]
|
|
95
|
-
});
|
|
96
|
-
expect(blockedState.isBlocked).toBe(true);
|
|
97
|
-
expect(blockedState.isReady).toBe(false);
|
|
98
|
-
expect(blockedState.blockingTaskIds).toEqual(['task_up1']);
|
|
99
|
-
|
|
100
|
-
// When all upstream tasks are completed, task_1 becomes ready
|
|
101
|
-
const allDoneState = deriveTaskLifecycleState(baseTask, {
|
|
102
|
-
upstreamTasks: [
|
|
103
|
-
{ ...upstream1, status: 'done', semanticStatus: 'completed' },
|
|
104
|
-
upstream2
|
|
105
|
-
]
|
|
106
|
-
});
|
|
107
|
-
expect(allDoneState.isBlocked).toBe(false);
|
|
108
|
-
expect(allDoneState.isReady).toBe(true);
|
|
109
|
-
expect(allDoneState.blockingTaskIds).toHaveLength(0);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('derives schedule indicators: overdue, upcoming, unplanned', () => {
|
|
113
|
-
const refDate = new Date('2026-09-10T12:00:00.000Z');
|
|
114
|
-
|
|
115
|
-
// Overdue task
|
|
116
|
-
const overdueTask: Task = {
|
|
117
|
-
...baseTask,
|
|
118
|
-
dueDate: '2026-09-08T00:00:00.000Z'
|
|
119
|
-
};
|
|
120
|
-
const overdueDerived = deriveTaskLifecycleState(overdueTask, { referenceDate: refDate });
|
|
121
|
-
expect(overdueDerived.isOverdue).toBe(true);
|
|
122
|
-
expect(overdueDerived.isUnplanned).toBe(false);
|
|
123
|
-
|
|
124
|
-
// Completed task is not overdue even if dueDate is past
|
|
125
|
-
const completedTask: Task = {
|
|
126
|
-
...overdueTask,
|
|
127
|
-
status: 'done'
|
|
128
|
-
};
|
|
129
|
-
const completedDerived = deriveTaskLifecycleState(completedTask, { referenceDate: refDate });
|
|
130
|
-
expect(completedDerived.isOverdue).toBe(false);
|
|
131
|
-
expect(completedDerived.isDone).toBe(true);
|
|
132
|
-
|
|
133
|
-
// Upcoming task
|
|
134
|
-
const upcomingTask: Task = {
|
|
135
|
-
...baseTask,
|
|
136
|
-
plannedStartDate: '2026-09-12T00:00:00.000Z' // within 3 days of Sept 10
|
|
137
|
-
};
|
|
138
|
-
const upcomingDerived = deriveTaskLifecycleState(upcomingTask, { referenceDate: refDate });
|
|
139
|
-
expect(upcomingDerived.isUpcoming).toBe(true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('derives resource indicators: unassigned and stalled', () => {
|
|
143
|
-
const refDate = new Date('2026-09-15T12:00:00.000Z');
|
|
144
|
-
|
|
145
|
-
// Assigned via assigneeId
|
|
146
|
-
const assignedTask1: Task = {
|
|
147
|
-
...baseTask,
|
|
148
|
-
assigneeId: 'user_alice'
|
|
149
|
-
};
|
|
150
|
-
expect(deriveTaskLifecycleState(assignedTask1).isUnassigned).toBe(false);
|
|
151
|
-
|
|
152
|
-
// Assigned via assignees array
|
|
153
|
-
const assignedTask2: Task = {
|
|
154
|
-
...baseTask,
|
|
155
|
-
assignees: [{ id: 'user_bob' }]
|
|
156
|
-
};
|
|
157
|
-
expect(deriveTaskLifecycleState(assignedTask2).isUnassigned).toBe(false);
|
|
158
|
-
|
|
159
|
-
// Stalled task: in_progress with no update in > 7 days
|
|
160
|
-
const stalledTask: Task = {
|
|
161
|
-
...baseTask,
|
|
162
|
-
status: 'in_progress',
|
|
163
|
-
updatedAt: '2026-09-01T00:00:00.000Z'
|
|
164
|
-
};
|
|
165
|
-
const stalledDerived = deriveTaskLifecycleState(stalledTask, { referenceDate: refDate, stalledThresholdDays: 7 });
|
|
166
|
-
expect(stalledDerived.isStalled).toBe(true);
|
|
167
|
-
|
|
168
|
-
// Not stalled if updated recently
|
|
169
|
-
const activeTask: Task = {
|
|
170
|
-
...stalledTask,
|
|
171
|
-
updatedAt: '2026-09-14T00:00:00.000Z'
|
|
172
|
-
};
|
|
173
|
-
expect(deriveTaskLifecycleState(activeTask, { referenceDate: refDate, stalledThresholdDays: 7 }).isStalled).toBe(false);
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it('derives estimate indicators: isOverEstimate and isPaceWarning', () => {
|
|
177
|
-
// Over estimate by logged hours
|
|
178
|
-
const overEstimateTask: Task = {
|
|
179
|
-
...baseTask,
|
|
180
|
-
status: 'in_progress',
|
|
181
|
-
estimatedHours: 10,
|
|
182
|
-
loggedHours: 12
|
|
183
|
-
};
|
|
184
|
-
const overEstDerived = deriveTaskLifecycleState(overEstimateTask);
|
|
185
|
-
expect(overEstDerived.isOverEstimate).toBe(true);
|
|
186
|
-
|
|
187
|
-
// Pace warning: in_progress task that has been active longer than estimated duration
|
|
188
|
-
const refDate = new Date('2026-09-10T00:00:00.000Z');
|
|
189
|
-
const paceWarningTask: Task = {
|
|
190
|
-
...baseTask,
|
|
191
|
-
status: 'in_progress',
|
|
192
|
-
actualStartDate: '2026-09-01T00:00:00.000Z', // 9 days = 216 hours elapsed
|
|
193
|
-
estimatedHours: 40 // only 40 hours estimated
|
|
194
|
-
};
|
|
195
|
-
const paceDerived = deriveTaskLifecycleState(paceWarningTask, { referenceDate: refDate });
|
|
196
|
-
expect(paceDerived.isPaceWarning).toBe(true);
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
describe('Engine Integration', () => {
|
|
201
|
-
it('computes full lifecycle state with dependency graph integration', async () => {
|
|
202
|
-
const engine = new CriticalPathEngine();
|
|
203
|
-
const proj = await engine.createProject({ key: 'LIFECYCLE', name: 'Lifecycle Test' });
|
|
204
|
-
|
|
205
|
-
const taskA = await engine.createTask({
|
|
206
|
-
projectId: proj.id,
|
|
207
|
-
title: 'Task A (Dependency)',
|
|
208
|
-
status: 'todo',
|
|
209
|
-
priority: 'high'
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
const taskB = await engine.createTask({
|
|
213
|
-
projectId: proj.id,
|
|
214
|
-
title: 'Task B (Dependent)',
|
|
215
|
-
status: 'todo',
|
|
216
|
-
priority: 'medium'
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
await engine.store.addDependency({
|
|
220
|
-
taskId: taskB.id,
|
|
221
|
-
dependsOnTaskId: taskA.id,
|
|
222
|
-
type: 'blocking'
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
// Task B should be blocked by Task A
|
|
226
|
-
let stateB = await engine.getTaskLifecycleState(taskB.id);
|
|
227
|
-
expect(stateB?.isBlocked).toBe(true);
|
|
228
|
-
expect(stateB?.isReady).toBe(false);
|
|
229
|
-
expect(stateB?.blockingTaskIds).toEqual([taskA.id]);
|
|
230
|
-
|
|
231
|
-
// Complete Task A
|
|
232
|
-
await engine.updateTask(taskA.id, { status: 'done' });
|
|
233
|
-
|
|
234
|
-
// Task B should now be ready
|
|
235
|
-
stateB = await engine.getTaskLifecycleState(taskB.id);
|
|
236
|
-
expect(stateB?.isBlocked).toBe(false);
|
|
237
|
-
expect(stateB?.isReady).toBe(true);
|
|
238
|
-
expect(stateB?.blockingTaskIds).toEqual([]);
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
describe('Canonical Task Lifecycle & Semantic Status Predicates', () => {
|
|
243
|
-
it('identifies draft, archived, and trashed tasks properly', () => {
|
|
244
|
-
expect(isDraftTask(null)).toBe(false);
|
|
245
|
-
expect(isDraftTask({ isDraft: true })).toBe(true);
|
|
246
|
-
expect(isDraftTask({ isDraft: false })).toBe(false);
|
|
247
|
-
|
|
248
|
-
expect(isArchivedTask(null)).toBe(false);
|
|
249
|
-
expect(isArchivedTask({ archived: true })).toBe(true);
|
|
250
|
-
expect(isArchivedTask({ archivedAt: '2026-09-01T00:00:00Z' })).toBe(true);
|
|
251
|
-
expect(isArchivedTask({ status: 'archived' })).toBe(true);
|
|
252
|
-
expect(isArchivedTask({ customFields: { isArchived: true } })).toBe(true);
|
|
253
|
-
expect(isArchivedTask({ status: 'todo' })).toBe(false);
|
|
254
|
-
|
|
255
|
-
expect(isTrashedTask(null)).toBe(false);
|
|
256
|
-
expect(isTrashedTask({ trashed: true })).toBe(true);
|
|
257
|
-
expect(isTrashedTask({ trashedAt: '2026-09-01T00:00:00Z' })).toBe(true);
|
|
258
|
-
expect(isTrashedTask({ status: 'trashed' })).toBe(true);
|
|
259
|
-
expect(isTrashedTask({ customFields: { isTrashed: true } })).toBe(true);
|
|
260
|
-
expect(isTrashedTask({ status: 'todo' })).toBe(false);
|
|
261
|
-
|
|
262
|
-
expect(isTrashedOrArchivedTask({ trashed: true })).toBe(true);
|
|
263
|
-
expect(isTrashedOrArchivedTask({ archived: true })).toBe(true);
|
|
264
|
-
expect(isTrashedOrArchivedTask({ status: 'todo' })).toBe(false);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('identifies workflow tasks excluding draft, trashed, and archived tasks (UCH-137)', () => {
|
|
268
|
-
expect(isWorkflowTask(null)).toBe(false);
|
|
269
|
-
expect(isWorkflowTask({ status: 'todo' })).toBe(true);
|
|
270
|
-
expect(isWorkflowTask({ status: 'in_progress' })).toBe(true);
|
|
271
|
-
expect(isWorkflowTask({ status: 'done' })).toBe(true);
|
|
272
|
-
|
|
273
|
-
// Draft tasks are excluded
|
|
274
|
-
expect(isWorkflowTask({ status: 'todo', isDraft: true })).toBe(false);
|
|
275
|
-
// Trashed tasks are excluded
|
|
276
|
-
expect(isWorkflowTask({ status: 'todo', trashed: true })).toBe(false);
|
|
277
|
-
// Archived tasks are excluded
|
|
278
|
-
expect(isWorkflowTask({ status: 'done', archived: true })).toBe(false);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it('resolves semantic status using workflow, defaults, and custom definitions', () => {
|
|
282
|
-
const mockWorkflow: Workflow = {
|
|
283
|
-
id: 'wf_custom',
|
|
284
|
-
name: 'Custom Flow',
|
|
285
|
-
isDefault: true,
|
|
286
|
-
statuses: [
|
|
287
|
-
{ key: 'discovery', label: 'Discovery', category: 'not_started' },
|
|
288
|
-
{ key: 'developing', label: 'Developing', category: 'in_progress' },
|
|
289
|
-
{ key: 'delivered', label: 'Delivered', category: 'completed' },
|
|
290
|
-
{ key: 'dropped', label: 'Dropped', category: 'canceled' }
|
|
291
|
-
],
|
|
292
|
-
transitions: [],
|
|
293
|
-
createdAt: '2026-09-01T00:00:00Z',
|
|
294
|
-
updatedAt: '2026-09-01T00:00:00Z'
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
expect(getTaskSemanticStatus({ status: 'developing' }, mockWorkflow)).toBe('in_progress');
|
|
298
|
-
expect(getTaskSemanticStatus({ status: 'delivered' }, mockWorkflow)).toBe('completed');
|
|
299
|
-
expect(getTaskSemanticStatus({ status: 'dropped' }, mockWorkflow)).toBe('canceled');
|
|
300
|
-
expect(getTaskSemanticStatus({ status: 'discovery' }, mockWorkflow)).toBe('not_started');
|
|
301
|
-
|
|
302
|
-
// Falls back to standard defaults when not in custom workflow
|
|
303
|
-
expect(getTaskSemanticStatus({ status: 'in_progress' }, mockWorkflow)).toBe('in_progress');
|
|
304
|
-
expect(getTaskSemanticStatus({ status: 'done' })).toBe('completed');
|
|
305
|
-
expect(getTaskSemanticStatus({ status: 'todo' })).toBe('not_started');
|
|
306
|
-
expect(getTaskSemanticStatus({ status: 'canceled' })).toBe('canceled');
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it('verifies lifecycle predicates (completed, in_progress, not_started, canceled, active)', () => {
|
|
310
|
-
const taskDone = { status: 'done' };
|
|
311
|
-
const taskActive = { status: 'in_progress' };
|
|
312
|
-
const taskTodo = { status: 'todo' };
|
|
313
|
-
const taskCanceled = { status: 'canceled' };
|
|
314
|
-
|
|
315
|
-
expect(isTaskCompleted(taskDone)).toBe(true);
|
|
316
|
-
expect(isTaskCompleted(taskActive)).toBe(false);
|
|
317
|
-
|
|
318
|
-
expect(isTaskInProgress(taskActive)).toBe(true);
|
|
319
|
-
expect(isTaskInProgress(taskDone)).toBe(false);
|
|
320
|
-
|
|
321
|
-
expect(isTaskNotStarted(taskTodo)).toBe(true);
|
|
322
|
-
expect(isTaskNotStarted(taskActive)).toBe(false);
|
|
323
|
-
|
|
324
|
-
expect(isTaskCanceled(taskCanceled)).toBe(true);
|
|
325
|
-
expect(isTaskCanceled(taskDone)).toBe(false);
|
|
326
|
-
|
|
327
|
-
// Active tasks
|
|
328
|
-
expect(isTaskActive(taskTodo)).toBe(true);
|
|
329
|
-
expect(isTaskActive(taskActive)).toBe(true);
|
|
330
|
-
expect(isTaskActive(taskDone)).toBe(false);
|
|
331
|
-
expect(isTaskActive(taskCanceled)).toBe(false);
|
|
332
|
-
expect(isTaskActive({ ...taskActive, isDraft: true })).toBe(false);
|
|
333
|
-
expect(isTaskActive({ ...taskActive, archived: true })).toBe(false);
|
|
334
|
-
expect(isTaskActive({ ...taskActive, trashed: true })).toBe(false);
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it('identifies unassigned tasks properly', () => {
|
|
338
|
-
expect(isTaskUnassigned(null)).toBe(true);
|
|
339
|
-
expect(isTaskUnassigned({})).toBe(true);
|
|
340
|
-
expect(isTaskUnassigned({ assigneeId: undefined })).toBe(true);
|
|
341
|
-
expect(isTaskUnassigned({ assigneeId: '' })).toBe(true);
|
|
342
|
-
expect(isTaskUnassigned({ assigneeId: 'unassigned' })).toBe(true);
|
|
343
|
-
expect(isTaskUnassigned({ assigneeId: ' UNASSIGNED ' })).toBe(true);
|
|
344
|
-
expect(isTaskUnassigned({ assigneeId: 'user_123' })).toBe(false);
|
|
345
|
-
|
|
346
|
-
// Assignees array checks
|
|
347
|
-
expect(isTaskUnassigned({ assignees: [] })).toBe(true);
|
|
348
|
-
expect(isTaskUnassigned({ assignees: ['unassigned'] })).toBe(true);
|
|
349
|
-
expect(isTaskUnassigned({ assignees: [{ id: 'unassigned', name: 'unassigned' }] })).toBe(true);
|
|
350
|
-
expect(isTaskUnassigned({ assignees: ['user_456'] })).toBe(false);
|
|
351
|
-
expect(isTaskUnassigned({ assignees: [{ id: 'user_456', name: 'Alice' }] })).toBe(false);
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
});
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
FileStorageAdapter,
|
|
3
|
-
UploadFileInput,
|
|
4
|
-
UploadFileResult,
|
|
5
|
-
PresignedUrlOptions,
|
|
6
|
-
PresignedUploadResult
|
|
7
|
-
} from '../types/index.js';
|
|
8
|
-
|
|
9
|
-
export interface StoredFile {
|
|
10
|
-
storageKey: string;
|
|
11
|
-
data: Uint8Array;
|
|
12
|
-
mimeType: string;
|
|
13
|
-
sizeBytes: number;
|
|
14
|
-
url: string;
|
|
15
|
-
createdAt: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Builds a storage key `<prefix>/<timestamp>_<random>_<filename>`. The prefix is validated (no
|
|
20
|
-
* `.`/`..` segments, no leading slash, safe characters only) so callers cannot write outside it.
|
|
21
|
-
*/
|
|
22
|
-
export function buildStorageKey(pathPrefix: string | undefined, filename: string): string {
|
|
23
|
-
let prefix = '';
|
|
24
|
-
if (pathPrefix) {
|
|
25
|
-
const trimmed = pathPrefix.replace(/\/+$/, '');
|
|
26
|
-
const segments = trimmed.split('/');
|
|
27
|
-
if (
|
|
28
|
-
trimmed.startsWith('/') ||
|
|
29
|
-
segments.some((segment) => segment === '' || segment === '.' || segment === '..' || !/^[A-Za-z0-9._-]+$/.test(segment))
|
|
30
|
-
) {
|
|
31
|
-
throw new Error(`Invalid storage path prefix "${pathPrefix}".`);
|
|
32
|
-
}
|
|
33
|
-
prefix = `${trimmed}/`;
|
|
34
|
-
}
|
|
35
|
-
const random = Array.from(crypto.getRandomValues(new Uint8Array(6)), (b) => b.toString(16).padStart(2, '0')).join('');
|
|
36
|
-
const safeName = filename.replace(/[^a-zA-Z0-9._-]/g, '_').replace(/^\.+/, '_') || 'file';
|
|
37
|
-
return `${prefix}${Date.now()}_${random}_${safeName}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Content types a browser would execute or render as a page if opened from the storage host. */
|
|
41
|
-
const ACTIVE_CONTENT_TYPES = new Set([
|
|
42
|
-
'text/html',
|
|
43
|
-
'application/xhtml+xml',
|
|
44
|
-
'image/svg+xml',
|
|
45
|
-
'text/javascript',
|
|
46
|
-
'application/javascript',
|
|
47
|
-
'text/xml',
|
|
48
|
-
'application/xml'
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* `Content-Disposition` for stored files: active content (HTML, SVG, scripts) is forced to
|
|
53
|
-
* download so a stored file cannot run script on the storage origin.
|
|
54
|
-
*/
|
|
55
|
-
export function contentDispositionFor(mimeType: string, filename: string): string | undefined {
|
|
56
|
-
const base = mimeType.split(';')[0].trim().toLowerCase();
|
|
57
|
-
if (!ACTIVE_CONTENT_TYPES.has(base)) return undefined;
|
|
58
|
-
return `attachment; filename="${filename.replace(/["\\\r\n]/g, '_')}"`;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function normalizeUploadData(
|
|
62
|
-
data: Uint8Array | ArrayBuffer | Buffer | Blob | string | unknown,
|
|
63
|
-
encoding?: 'base64' | 'utf-8' | 'binary',
|
|
64
|
-
mimeType?: string
|
|
65
|
-
): Uint8Array {
|
|
66
|
-
if (data instanceof Uint8Array) {
|
|
67
|
-
return data;
|
|
68
|
-
}
|
|
69
|
-
if (data instanceof ArrayBuffer) {
|
|
70
|
-
return new Uint8Array(data);
|
|
71
|
-
}
|
|
72
|
-
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(data)) {
|
|
73
|
-
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
74
|
-
}
|
|
75
|
-
if (typeof data === 'string') {
|
|
76
|
-
let str = data.trim();
|
|
77
|
-
|
|
78
|
-
// Data URI support (e.g. data:image/png;base64,iVBORw...)
|
|
79
|
-
if (str.startsWith('data:')) {
|
|
80
|
-
const commaIndex = str.indexOf(',');
|
|
81
|
-
if (commaIndex !== -1) {
|
|
82
|
-
str = str.substring(commaIndex + 1).trim();
|
|
83
|
-
}
|
|
84
|
-
if (typeof Buffer !== 'undefined') {
|
|
85
|
-
const buf = Buffer.from(str, 'base64');
|
|
86
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Explicit base64 encoding requested
|
|
91
|
-
if (encoding === 'base64') {
|
|
92
|
-
if (typeof Buffer !== 'undefined') {
|
|
93
|
-
const buf = Buffer.from(str, 'base64');
|
|
94
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
|
|
95
|
-
}
|
|
96
|
-
if (typeof atob === 'function') {
|
|
97
|
-
const binaryString = atob(str);
|
|
98
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
99
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
100
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
101
|
-
}
|
|
102
|
-
return bytes;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Auto-detect base64 string for non-text MIME types
|
|
107
|
-
const isTextMime = mimeType && (mimeType.startsWith('text/') || mimeType === 'application/json' || mimeType === 'application/xml');
|
|
108
|
-
if (!isTextMime && encoding !== 'utf-8' && encoding !== 'binary') {
|
|
109
|
-
const isBase64Pattern = /^[A-Za-z0-9+/=_\-\r\n\s]+$/.test(str) && str.length > 0 && str.length % 4 === 0;
|
|
110
|
-
if (isBase64Pattern) {
|
|
111
|
-
if (typeof Buffer !== 'undefined') {
|
|
112
|
-
try {
|
|
113
|
-
const buf = Buffer.from(str, 'base64');
|
|
114
|
-
if (buf.length > 0) {
|
|
115
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.length);
|
|
116
|
-
}
|
|
117
|
-
} catch {
|
|
118
|
-
// Fall back to text encoding
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return new TextEncoder().encode(data);
|
|
125
|
-
}
|
|
126
|
-
return new Uint8Array();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export class InMemoryFileStore implements FileStorageAdapter {
|
|
130
|
-
private files = new Map<string, StoredFile>();
|
|
131
|
-
private publicBaseUrl: string;
|
|
132
|
-
|
|
133
|
-
constructor(options: { publicBaseUrl?: string; publicUrlBase?: string } = {}) {
|
|
134
|
-
this.publicBaseUrl = options.publicUrlBase || options.publicBaseUrl || 'memory://attachments';
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async upload(input: UploadFileInput): Promise<UploadFileResult> {
|
|
138
|
-
const storageKey = buildStorageKey(input.pathPrefix, input.filename);
|
|
139
|
-
|
|
140
|
-
const buffer = normalizeUploadData(input.data, input.encoding, input.mimeType);
|
|
141
|
-
const mimeType = input.mimeType || 'application/octet-stream';
|
|
142
|
-
const sizeBytes = buffer.byteLength;
|
|
143
|
-
const url = `${this.publicBaseUrl}/${storageKey}`;
|
|
144
|
-
|
|
145
|
-
this.files.set(storageKey, {
|
|
146
|
-
storageKey,
|
|
147
|
-
data: buffer,
|
|
148
|
-
mimeType,
|
|
149
|
-
sizeBytes,
|
|
150
|
-
url,
|
|
151
|
-
createdAt: new Date().toISOString()
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
return {
|
|
155
|
-
storageKey,
|
|
156
|
-
url,
|
|
157
|
-
sizeBytes,
|
|
158
|
-
mimeType
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
async delete(storageKey: string): Promise<boolean> {
|
|
163
|
-
return this.files.delete(storageKey);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async download(storageKey: string): Promise<Buffer | Uint8Array> {
|
|
167
|
-
const file = this.files.get(storageKey);
|
|
168
|
-
if (!file) {
|
|
169
|
-
throw new Error(`File with storageKey "${storageKey}" not found`);
|
|
170
|
-
}
|
|
171
|
-
return file.data;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
async getDownloadUrl(storageKey: string): Promise<string> {
|
|
175
|
-
const file = this.files.get(storageKey);
|
|
176
|
-
if (!file) {
|
|
177
|
-
throw new Error(`File with storageKey "${storageKey}" not found`);
|
|
178
|
-
}
|
|
179
|
-
return file.url;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
async getPresignedUploadUrl(options: PresignedUrlOptions): Promise<PresignedUploadResult> {
|
|
183
|
-
const storageKey = options.storageKey;
|
|
184
|
-
const uploadUrl = `${this.publicBaseUrl}/upload/${encodeURIComponent(storageKey)}`;
|
|
185
|
-
return {
|
|
186
|
-
uploadUrl,
|
|
187
|
-
storageKey,
|
|
188
|
-
method: 'PUT',
|
|
189
|
-
headers: options.contentType ? { 'Content-Type': options.contentType } : {}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
getFile(storageKey: string): StoredFile | undefined {
|
|
194
|
-
return this.files.get(storageKey);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
clear(): void {
|
|
198
|
-
this.files.clear();
|
|
199
|
-
}
|
|
200
|
-
}
|