@critical-path/core 0.15.2 → 0.17.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.
- package/CHANGELOG.md +24 -0
- package/README.md +25 -0
- package/dist/domain/cpm.d.ts +10 -0
- package/dist/domain/cpm.d.ts.map +1 -0
- package/dist/domain/cpm.js +176 -0
- package/dist/domain/cpm.js.map +1 -0
- package/dist/domain/cpm.test.d.ts +2 -0
- package/dist/domain/cpm.test.d.ts.map +1 -0
- package/dist/domain/cpm.test.js +113 -0
- package/dist/domain/cpm.test.js.map +1 -0
- package/dist/domain/entities.d.ts.map +1 -1
- package/dist/domain/entities.js +5 -0
- package/dist/domain/entities.js.map +1 -1
- package/dist/domain/index.d.ts +3 -0
- package/dist/domain/index.d.ts.map +1 -1
- package/dist/domain/index.js +3 -0
- package/dist/domain/index.js.map +1 -1
- package/dist/domain/ladder.d.ts +16 -0
- package/dist/domain/ladder.d.ts.map +1 -0
- package/dist/domain/ladder.js +352 -0
- package/dist/domain/ladder.js.map +1 -0
- package/dist/domain/ladder.test.d.ts +2 -0
- package/dist/domain/ladder.test.d.ts.map +1 -0
- package/dist/domain/ladder.test.js +213 -0
- package/dist/domain/ladder.test.js.map +1 -0
- package/dist/domain/metrics.d.ts +29 -0
- package/dist/domain/metrics.d.ts.map +1 -0
- package/dist/domain/metrics.js +403 -0
- package/dist/domain/metrics.js.map +1 -0
- package/dist/domain/metrics.test.d.ts +2 -0
- package/dist/domain/metrics.test.d.ts.map +1 -0
- package/dist/domain/metrics.test.js +251 -0
- package/dist/domain/metrics.test.js.map +1 -0
- package/dist/engine/index.d.ts +8 -1
- package/dist/engine/index.d.ts.map +1 -1
- package/dist/engine/index.js +124 -1
- package/dist/engine/index.js.map +1 -1
- package/dist/store/firebase.d.ts +3 -1
- package/dist/store/firebase.d.ts.map +1 -1
- package/dist/store/firebase.js +1 -1
- package/dist/store/firebase.js.map +1 -1
- package/dist/store/index.d.ts +6 -2
- package/dist/store/index.d.ts.map +1 -1
- package/dist/store/index.js +1 -1
- package/dist/store/index.js.map +1 -1
- package/dist/store/sqlite.d.ts +3 -1
- package/dist/store/sqlite.d.ts.map +1 -1
- package/dist/store/sqlite.js +1 -1
- package/dist/store/sqlite.js.map +1 -1
- package/dist/types/index.d.ts +177 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/domain/cpm.test.ts +128 -0
- package/src/domain/cpm.ts +215 -0
- package/src/domain/entities.ts +6 -0
- package/src/domain/index.ts +4 -0
- package/src/domain/ladder.test.ts +251 -0
- package/src/domain/ladder.ts +453 -0
- package/src/domain/metrics.test.ts +286 -0
- package/src/domain/metrics.ts +484 -0
- package/src/engine/index.ts +169 -4
- package/src/store/firebase.ts +2 -2
- package/src/store/index.ts +3 -3
- package/src/store/sqlite.ts +2 -2
- package/src/types/index.ts +206 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Task,
|
|
3
|
+
TaskDependency,
|
|
4
|
+
TaskCriticalPathSchedule,
|
|
5
|
+
CriticalPathAnalysis
|
|
6
|
+
} from '../types/index.js';
|
|
7
|
+
|
|
8
|
+
export function getTaskDurationHours(task: Task): number {
|
|
9
|
+
if (typeof task.estimatedHours === 'number' && task.estimatedHours >= 0) {
|
|
10
|
+
return task.estimatedHours;
|
|
11
|
+
}
|
|
12
|
+
if (typeof task.estimatedDurationMinutes === 'number' && task.estimatedDurationMinutes >= 0) {
|
|
13
|
+
return task.estimatedDurationMinutes / 60;
|
|
14
|
+
}
|
|
15
|
+
if (typeof task.actualHours === 'number' && task.actualHours > 0) {
|
|
16
|
+
return task.actualHours;
|
|
17
|
+
}
|
|
18
|
+
// Default to 1 hour for non-empty tasks without explicit estimate
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Calculates the Critical Path Method (CPM) schedule for a set of tasks and their dependencies.
|
|
24
|
+
* - Forward Pass: computes earlyStart and earlyFinish
|
|
25
|
+
* - Backward Pass: computes lateStart, lateFinish, and totalSlack
|
|
26
|
+
* - Identifies critical tasks (totalSlack === 0) that dictate the minimum project duration.
|
|
27
|
+
*/
|
|
28
|
+
export function calculateCPM(
|
|
29
|
+
projectId: string,
|
|
30
|
+
tasks: Task[],
|
|
31
|
+
dependencies: TaskDependency[]
|
|
32
|
+
): CriticalPathAnalysis {
|
|
33
|
+
const calculatedAt = new Date().toISOString();
|
|
34
|
+
|
|
35
|
+
if (tasks.length === 0) {
|
|
36
|
+
return {
|
|
37
|
+
projectId,
|
|
38
|
+
calculatedAt,
|
|
39
|
+
totalDurationHours: 0,
|
|
40
|
+
criticalTaskIds: [],
|
|
41
|
+
tasks: []
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const taskMap = new Map<string, Task>(tasks.map((t) => [t.id, t]));
|
|
46
|
+
const taskIds = Array.from(taskMap.keys());
|
|
47
|
+
|
|
48
|
+
// Build adjacency graph:
|
|
49
|
+
// prerequisites[v] = tasks that v depends on (must finish before v starts)
|
|
50
|
+
// successors[u] = tasks that depend on u (can only start after u finishes)
|
|
51
|
+
const prerequisites = new Map<string, Set<string>>();
|
|
52
|
+
const successors = new Map<string, Set<string>>();
|
|
53
|
+
|
|
54
|
+
for (const id of taskIds) {
|
|
55
|
+
prerequisites.set(id, new Set<string>());
|
|
56
|
+
successors.set(id, new Set<string>());
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
for (const dep of dependencies) {
|
|
60
|
+
let sourceId: string | null = null;
|
|
61
|
+
let targetId: string | null = null;
|
|
62
|
+
|
|
63
|
+
if (dep.type === 'blocking') {
|
|
64
|
+
// taskId depends on dependsOnTaskId (dependsOnTaskId -> taskId)
|
|
65
|
+
sourceId = dep.dependsOnTaskId;
|
|
66
|
+
targetId = dep.taskId;
|
|
67
|
+
} else if (dep.type === 'blocked_by') {
|
|
68
|
+
// dependsOnTaskId is blocked by taskId (taskId -> dependsOnTaskId)
|
|
69
|
+
sourceId = dep.taskId;
|
|
70
|
+
targetId = dep.dependsOnTaskId;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (sourceId && targetId && taskMap.has(sourceId) && taskMap.has(targetId) && sourceId !== targetId) {
|
|
74
|
+
prerequisites.get(targetId)!.add(sourceId);
|
|
75
|
+
successors.get(sourceId)!.add(targetId);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Topological sorting via Kahn's algorithm
|
|
80
|
+
const inDegree = new Map<string, number>();
|
|
81
|
+
for (const id of taskIds) {
|
|
82
|
+
inDegree.set(id, prerequisites.get(id)!.size);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const queue: string[] = [];
|
|
86
|
+
for (const [id, deg] of inDegree.entries()) {
|
|
87
|
+
if (deg === 0) {
|
|
88
|
+
queue.push(id);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const topoOrder: string[] = [];
|
|
93
|
+
while (queue.length > 0) {
|
|
94
|
+
const current = queue.shift()!;
|
|
95
|
+
topoOrder.push(current);
|
|
96
|
+
|
|
97
|
+
for (const next of successors.get(current)!) {
|
|
98
|
+
const updatedDeg = inDegree.get(next)! - 1;
|
|
99
|
+
inDegree.set(next, updatedDeg);
|
|
100
|
+
if (updatedDeg === 0) {
|
|
101
|
+
queue.push(next);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// If there's a cycle or disconnected nodes not processed in topoOrder, append them
|
|
107
|
+
if (topoOrder.length < taskIds.length) {
|
|
108
|
+
for (const id of taskIds) {
|
|
109
|
+
if (!topoOrder.includes(id)) {
|
|
110
|
+
topoOrder.push(id);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// --- FORWARD PASS ---
|
|
116
|
+
const earlyStart = new Map<string, number>();
|
|
117
|
+
const earlyFinish = new Map<string, number>();
|
|
118
|
+
|
|
119
|
+
for (const id of topoOrder) {
|
|
120
|
+
const task = taskMap.get(id)!;
|
|
121
|
+
const duration = getTaskDurationHours(task);
|
|
122
|
+
const prereqs = prerequisites.get(id) || new Set();
|
|
123
|
+
|
|
124
|
+
let maxPrereqFinish = 0;
|
|
125
|
+
for (const p of prereqs) {
|
|
126
|
+
const pFinish = earlyFinish.get(p) ?? 0;
|
|
127
|
+
if (pFinish > maxPrereqFinish) {
|
|
128
|
+
maxPrereqFinish = pFinish;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const es = maxPrereqFinish;
|
|
133
|
+
const ef = es + duration;
|
|
134
|
+
|
|
135
|
+
earlyStart.set(id, es);
|
|
136
|
+
earlyFinish.set(id, ef);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Total project duration
|
|
140
|
+
let totalDurationHours = 0;
|
|
141
|
+
for (const ef of earlyFinish.values()) {
|
|
142
|
+
if (ef > totalDurationHours) {
|
|
143
|
+
totalDurationHours = ef;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// --- BACKWARD PASS ---
|
|
148
|
+
const lateStart = new Map<string, number>();
|
|
149
|
+
const lateFinish = new Map<string, number>();
|
|
150
|
+
|
|
151
|
+
// Process in reverse topological order
|
|
152
|
+
for (let i = topoOrder.length - 1; i >= 0; i--) {
|
|
153
|
+
const id = topoOrder[i];
|
|
154
|
+
const task = taskMap.get(id)!;
|
|
155
|
+
const duration = getTaskDurationHours(task);
|
|
156
|
+
const succs = successors.get(id) || new Set();
|
|
157
|
+
|
|
158
|
+
let minSuccLateStart = totalDurationHours;
|
|
159
|
+
if (succs.size > 0) {
|
|
160
|
+
minSuccLateStart = Infinity;
|
|
161
|
+
for (const s of succs) {
|
|
162
|
+
const sLateStart = lateStart.get(s);
|
|
163
|
+
if (sLateStart !== undefined && sLateStart < minSuccLateStart) {
|
|
164
|
+
minSuccLateStart = sLateStart;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (!Number.isFinite(minSuccLateStart)) {
|
|
168
|
+
minSuccLateStart = totalDurationHours;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const lf = minSuccLateStart;
|
|
173
|
+
const ls = lf - duration;
|
|
174
|
+
|
|
175
|
+
lateFinish.set(id, lf);
|
|
176
|
+
lateStart.set(id, ls);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// --- SLACK & CRITICAL PATH ---
|
|
180
|
+
const schedules: TaskCriticalPathSchedule[] = [];
|
|
181
|
+
const criticalTaskIds: string[] = [];
|
|
182
|
+
|
|
183
|
+
for (const id of taskIds) {
|
|
184
|
+
const es = earlyStart.get(id) ?? 0;
|
|
185
|
+
const ef = earlyFinish.get(id) ?? 0;
|
|
186
|
+
const ls = lateStart.get(id) ?? 0;
|
|
187
|
+
const lf = lateFinish.get(id) ?? 0;
|
|
188
|
+
|
|
189
|
+
const rawSlack = lf - ef;
|
|
190
|
+
const totalSlack = Math.round(rawSlack * 100) / 100;
|
|
191
|
+
const isCritical = totalSlack <= 0.001;
|
|
192
|
+
|
|
193
|
+
if (isCritical) {
|
|
194
|
+
criticalTaskIds.push(id);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
schedules.push({
|
|
198
|
+
taskId: id,
|
|
199
|
+
earlyStart: Math.round(es * 100) / 100,
|
|
200
|
+
earlyFinish: Math.round(ef * 100) / 100,
|
|
201
|
+
lateStart: Math.round(ls * 100) / 100,
|
|
202
|
+
lateFinish: Math.round(lf * 100) / 100,
|
|
203
|
+
totalSlack,
|
|
204
|
+
isCritical
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return {
|
|
209
|
+
projectId,
|
|
210
|
+
calculatedAt,
|
|
211
|
+
totalDurationHours: Math.round(totalDurationHours * 100) / 100,
|
|
212
|
+
criticalTaskIds,
|
|
213
|
+
tasks: schedules
|
|
214
|
+
};
|
|
215
|
+
}
|
package/src/domain/entities.ts
CHANGED
|
@@ -189,6 +189,12 @@ export class TaskEntity extends BaseEntity {
|
|
|
189
189
|
const statusDef = resolveStatusDefinition(newStatus, options?.statusDefs || workflow?.statuses);
|
|
190
190
|
this.semanticStatus = statusDef.category;
|
|
191
191
|
|
|
192
|
+
const prevStatusDef = resolveStatusDefinition(previousStatus, options?.statusDefs || workflow?.statuses);
|
|
193
|
+
if ((prevStatusDef.category === 'completed' || prevStatusDef.category === 'canceled') &&
|
|
194
|
+
(statusDef.category === 'in_progress' || statusDef.category === 'not_started')) {
|
|
195
|
+
this.actualEndDate = undefined;
|
|
196
|
+
}
|
|
197
|
+
|
|
192
198
|
if (statusDef.category === 'in_progress' && !this.actualStartDate) {
|
|
193
199
|
this.actualStartDate = now;
|
|
194
200
|
}
|
package/src/domain/index.ts
CHANGED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { CriticalPathEngine } from '../engine/index.js';
|
|
3
|
+
import {
|
|
4
|
+
aggregateConcreteEvidenceForTask,
|
|
5
|
+
computeMacroPhases,
|
|
6
|
+
buildTimelineLadder
|
|
7
|
+
} from './ladder.js';
|
|
8
|
+
import type { Task, TaskContainer, Attachment, Deliverable, TimeEntry } from '../types/index.js';
|
|
9
|
+
|
|
10
|
+
describe('Ladder of Abstraction Domain Logic', () => {
|
|
11
|
+
const now = '2026-09-11T10:00:00.000Z';
|
|
12
|
+
|
|
13
|
+
it('aggregates concrete evidence, daily effort distribution, and reality delta for a task', () => {
|
|
14
|
+
const task: Task = {
|
|
15
|
+
id: 'task-design',
|
|
16
|
+
projectId: 'proj-1',
|
|
17
|
+
title: 'Design Checkout Flow',
|
|
18
|
+
status: 'in_progress',
|
|
19
|
+
semanticStatus: 'in_progress',
|
|
20
|
+
priority: 'high',
|
|
21
|
+
plannedStartDate: '2026-09-01T09:00:00.000Z',
|
|
22
|
+
actualStartDate: '2026-09-02T10:00:00.000Z',
|
|
23
|
+
dueDate: '2026-09-15T18:00:00.000Z',
|
|
24
|
+
estimatedHours: 20,
|
|
25
|
+
todos: [
|
|
26
|
+
{ id: 'todo-1', title: 'Sketch wireframes', completed: true, completedAt: '2026-09-03T12:00:00.000Z' },
|
|
27
|
+
{ id: 'todo-2', title: 'Component specs', completed: false }
|
|
28
|
+
],
|
|
29
|
+
createdAt: now,
|
|
30
|
+
updatedAt: now
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const attachments: Attachment[] = [
|
|
34
|
+
{
|
|
35
|
+
id: 'att-1',
|
|
36
|
+
taskId: 'task-design',
|
|
37
|
+
uploaderId: 'user-1',
|
|
38
|
+
filename: 'checkout_mockup.png',
|
|
39
|
+
mimeType: 'image/png',
|
|
40
|
+
sizeBytes: 204800,
|
|
41
|
+
url: 'https://cdn.example.com/checkout_mockup.png',
|
|
42
|
+
artifactType: 'deliverable',
|
|
43
|
+
createdAt: now,
|
|
44
|
+
updatedAt: now
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
const deliverables: Deliverable[] = [
|
|
49
|
+
{
|
|
50
|
+
id: 'deliv-1',
|
|
51
|
+
projectId: 'proj-1',
|
|
52
|
+
title: 'Checkout Prototype',
|
|
53
|
+
status: 'in_production',
|
|
54
|
+
format: 'Figma',
|
|
55
|
+
outputUrls: ['https://figma.com/file/12345'],
|
|
56
|
+
createdAt: now,
|
|
57
|
+
updatedAt: now
|
|
58
|
+
}
|
|
59
|
+
];
|
|
60
|
+
task.deliverableId = 'deliv-1';
|
|
61
|
+
|
|
62
|
+
const timeEntries: TimeEntry[] = [
|
|
63
|
+
{ id: 'te-1', taskId: 'task-design', userId: 'user-1', hours: 4, loggedAt: '2026-09-02T16:00:00.000Z' },
|
|
64
|
+
{ id: 'te-2', taskId: 'task-design', userId: 'user-1', hours: 6, loggedAt: '2026-09-03T17:00:00.000Z' },
|
|
65
|
+
{ id: 'te-3', taskId: 'task-design', userId: 'user-1', hours: 3, loggedAt: '2026-09-03T19:00:00.000Z' }
|
|
66
|
+
];
|
|
67
|
+
|
|
68
|
+
const evidence = aggregateConcreteEvidenceForTask(
|
|
69
|
+
task,
|
|
70
|
+
attachments,
|
|
71
|
+
deliverables,
|
|
72
|
+
timeEntries,
|
|
73
|
+
[]
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
expect(evidence.taskId).toBe('task-design');
|
|
77
|
+
expect(evidence.attachments).toHaveLength(1);
|
|
78
|
+
expect(evidence.deliverables).toHaveLength(1);
|
|
79
|
+
expect(evidence.todos).toHaveLength(2);
|
|
80
|
+
expect(evidence.timeEntries).toHaveLength(3);
|
|
81
|
+
|
|
82
|
+
// Check daily effort distribution (aggregated by day)
|
|
83
|
+
expect(evidence.dailyEffortDistribution).toEqual([
|
|
84
|
+
{ date: '2026-09-02', hours: 4 },
|
|
85
|
+
{ date: '2026-09-03', hours: 9 } // 6 + 3
|
|
86
|
+
]);
|
|
87
|
+
|
|
88
|
+
// Evidence summary
|
|
89
|
+
expect(evidence.evidenceSummary.attachmentCount).toBe(1);
|
|
90
|
+
expect(evidence.evidenceSummary.deliverableCount).toBe(1);
|
|
91
|
+
expect(evidence.evidenceSummary.completedTodoCount).toBe(1);
|
|
92
|
+
expect(evidence.evidenceSummary.totalLoggedHours).toBe(13);
|
|
93
|
+
expect(evidence.evidenceSummary.hasVisualAsset).toBe(true);
|
|
94
|
+
|
|
95
|
+
// Reality delta
|
|
96
|
+
expect(evidence.realityDelta.plannedStartDate).toBe('2026-09-01T09:00:00.000Z');
|
|
97
|
+
expect(evidence.realityDelta.actualStartDate).toBe('2026-09-02T10:00:00.000Z');
|
|
98
|
+
expect(evidence.realityDelta.estimatedHours).toBe(20);
|
|
99
|
+
expect(evidence.realityDelta.loggedHours).toBe(13);
|
|
100
|
+
expect(evidence.realityDelta.varianceHours).toBe(-7); // Under budget by 7h
|
|
101
|
+
expect(evidence.realityDelta.isOverEstimate).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('computes macro phase rollups across containers with dates and progress weighting', () => {
|
|
105
|
+
const containers: TaskContainer[] = [
|
|
106
|
+
{ id: 'c-research', projectId: 'p1', name: 'Research Phase', createdAt: now, updatedAt: now },
|
|
107
|
+
{ id: 'c-dev', projectId: 'p1', name: 'Development Phase', createdAt: now, updatedAt: now }
|
|
108
|
+
];
|
|
109
|
+
|
|
110
|
+
const tasks: Task[] = [
|
|
111
|
+
{
|
|
112
|
+
id: 't-1',
|
|
113
|
+
projectId: 'p1',
|
|
114
|
+
containerId: 'c-research',
|
|
115
|
+
title: 'User Interviews',
|
|
116
|
+
status: 'done',
|
|
117
|
+
semanticStatus: 'completed',
|
|
118
|
+
priority: 'medium',
|
|
119
|
+
progress: 100,
|
|
120
|
+
plannedStartDate: '2026-09-01',
|
|
121
|
+
dueDate: '2026-09-05',
|
|
122
|
+
estimatedHours: 10,
|
|
123
|
+
loggedHours: 10,
|
|
124
|
+
createdAt: now,
|
|
125
|
+
updatedAt: now
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 't-2',
|
|
129
|
+
projectId: 'p1',
|
|
130
|
+
containerId: 'c-dev',
|
|
131
|
+
title: 'API Setup',
|
|
132
|
+
status: 'in_progress',
|
|
133
|
+
semanticStatus: 'in_progress',
|
|
134
|
+
priority: 'high',
|
|
135
|
+
progress: 50,
|
|
136
|
+
plannedStartDate: '2026-09-06',
|
|
137
|
+
dueDate: '2026-09-20',
|
|
138
|
+
estimatedHours: 40,
|
|
139
|
+
loggedHours: 20,
|
|
140
|
+
createdAt: now,
|
|
141
|
+
updatedAt: now
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
|
|
145
|
+
const criticalTaskIds = new Set(['t-2']);
|
|
146
|
+
const phases = computeMacroPhases(tasks, containers, [], criticalTaskIds);
|
|
147
|
+
|
|
148
|
+
expect(phases).toHaveLength(2);
|
|
149
|
+
|
|
150
|
+
const researchPhase = phases.find((p) => p.id === 'c-research')!;
|
|
151
|
+
expect(researchPhase.name).toBe('Research Phase');
|
|
152
|
+
expect(researchPhase.startDate).toBe('2026-09-01');
|
|
153
|
+
expect(researchPhase.endDate).toBe('2026-09-05');
|
|
154
|
+
expect(researchPhase.progressPercentage).toBe(100);
|
|
155
|
+
expect(researchPhase.health).toBe('completed');
|
|
156
|
+
expect(researchPhase.isCritical).toBe(false);
|
|
157
|
+
|
|
158
|
+
const devPhase = phases.find((p) => p.id === 'c-dev')!;
|
|
159
|
+
expect(devPhase.name).toBe('Development Phase');
|
|
160
|
+
expect(devPhase.startDate).toBe('2026-09-06');
|
|
161
|
+
expect(devPhase.endDate).toBe('2026-09-20');
|
|
162
|
+
expect(devPhase.progressPercentage).toBe(50);
|
|
163
|
+
expect(devPhase.isCritical).toBe(true);
|
|
164
|
+
expect(devPhase.criticalTaskCount).toBe(1);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('integrates seamlessly with CriticalPathEngine APIs', async () => {
|
|
168
|
+
const engine = new CriticalPathEngine();
|
|
169
|
+
const project = await engine.createProject({ name: 'Timeline Ladder Project' });
|
|
170
|
+
|
|
171
|
+
const c1 = await engine.store.createContainer({
|
|
172
|
+
projectId: project.id,
|
|
173
|
+
name: 'Phase 1: Design'
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
const t1 = await engine.createTask({
|
|
177
|
+
projectId: project.id,
|
|
178
|
+
containerId: c1.id,
|
|
179
|
+
title: 'Wireframes',
|
|
180
|
+
status: 'done',
|
|
181
|
+
estimatedHours: 5,
|
|
182
|
+
progress: 100,
|
|
183
|
+
plannedStartDate: '2026-09-01',
|
|
184
|
+
dueDate: '2026-09-05'
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const t2 = await engine.createTask({
|
|
188
|
+
projectId: project.id,
|
|
189
|
+
containerId: c1.id,
|
|
190
|
+
title: 'Visual Assets',
|
|
191
|
+
status: 'in_progress',
|
|
192
|
+
estimatedHours: 15,
|
|
193
|
+
progress: 30,
|
|
194
|
+
plannedStartDate: '2026-09-06',
|
|
195
|
+
dueDate: '2026-09-12'
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
await engine.addDependency({
|
|
199
|
+
taskId: t2.id,
|
|
200
|
+
dependsOnTaskId: t1.id,
|
|
201
|
+
type: 'blocking'
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
await engine.logTime({
|
|
205
|
+
taskId: t2.id,
|
|
206
|
+
userId: 'designer-1',
|
|
207
|
+
hours: 4.5,
|
|
208
|
+
loggedAt: '2026-09-07T12:00:00Z'
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// 1. Calculate CPM
|
|
212
|
+
const cpmAnalysis = await engine.calculateCriticalPath(project.id);
|
|
213
|
+
expect(cpmAnalysis.totalDurationHours).toBe(20);
|
|
214
|
+
expect(cpmAnalysis.criticalTaskIds).toEqual([t1.id, t2.id]);
|
|
215
|
+
|
|
216
|
+
// 2. Query full Timeline Ladder
|
|
217
|
+
const ladder = await engine.getTimelineLadder(project.id);
|
|
218
|
+
expect(ladder.macro).toBeDefined();
|
|
219
|
+
expect(ladder.macro?.projectName).toBe('Timeline Ladder Project');
|
|
220
|
+
expect(ladder.macro?.criticalPathDurationHours).toBe(20);
|
|
221
|
+
expect(ladder.macro?.phases).toHaveLength(1);
|
|
222
|
+
expect(ladder.macro?.phases[0].name).toBe('Phase 1: Design');
|
|
223
|
+
|
|
224
|
+
expect(ladder.standard).toBeDefined();
|
|
225
|
+
expect(ladder.standard?.tasks).toHaveLength(2);
|
|
226
|
+
const standardT2 = ladder.standard?.tasks.find((t) => t.id === t2.id)!;
|
|
227
|
+
expect(standardT2.cpm?.earlyStart).toBe(5);
|
|
228
|
+
expect(standardT2.cpm?.earlyFinish).toBe(20);
|
|
229
|
+
expect(standardT2.blockingTaskIds).toEqual([t1.id]);
|
|
230
|
+
expect(standardT2.concreteEvidenceSummary.timeEntryCount).toBe(1);
|
|
231
|
+
|
|
232
|
+
expect(ladder.concrete).toBeDefined();
|
|
233
|
+
const concreteT2 = ladder.concrete?.[t2.id]!;
|
|
234
|
+
expect(concreteT2.timeEntries).toHaveLength(1);
|
|
235
|
+
expect(concreteT2.dailyEffortDistribution).toEqual([{ date: '2026-09-07', hours: 4.5 }]);
|
|
236
|
+
expect(concreteT2.realityDelta.loggedHours).toBe(4.5);
|
|
237
|
+
|
|
238
|
+
// 3. Query filtered ladder levels
|
|
239
|
+
const macroOnly = await engine.getTimelineLadder(project.id, { level: 'macro' });
|
|
240
|
+
expect(macroOnly.macro).toBeDefined();
|
|
241
|
+
expect(macroOnly.standard).toBeUndefined();
|
|
242
|
+
expect(macroOnly.concrete).toBeUndefined();
|
|
243
|
+
|
|
244
|
+
// 4. Query single task ladder zoom
|
|
245
|
+
const taskLadder = await engine.getTaskLadder(t2.id);
|
|
246
|
+
expect(taskLadder).not.toBeNull();
|
|
247
|
+
expect(taskLadder?.macroPhase?.name).toBe('Phase 1: Design');
|
|
248
|
+
expect(taskLadder?.standard.id).toBe(t2.id);
|
|
249
|
+
expect(taskLadder?.concrete.dailyEffortDistribution).toEqual([{ date: '2026-09-07', hours: 4.5 }]);
|
|
250
|
+
});
|
|
251
|
+
});
|