@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.
Files changed (187) hide show
  1. package/README.md +11 -0
  2. package/dist/engine/index.d.ts +2 -0
  3. package/dist/engine/index.d.ts.map +1 -1
  4. package/dist/engine/index.js +25 -2
  5. package/dist/engine/index.js.map +1 -1
  6. package/dist/types/index.d.ts +11 -0
  7. package/dist/types/index.d.ts.map +1 -1
  8. package/package.json +5 -1
  9. package/CHANGELOG.md +0 -584
  10. package/dist/deliverables.test.d.ts +0 -2
  11. package/dist/deliverables.test.d.ts.map +0 -1
  12. package/dist/deliverables.test.js +0 -232
  13. package/dist/deliverables.test.js.map +0 -1
  14. package/dist/domain/calendar.test.d.ts +0 -2
  15. package/dist/domain/calendar.test.d.ts.map +0 -1
  16. package/dist/domain/calendar.test.js +0 -181
  17. package/dist/domain/calendar.test.js.map +0 -1
  18. package/dist/domain/cpm.test.d.ts +0 -2
  19. package/dist/domain/cpm.test.d.ts.map +0 -1
  20. package/dist/domain/cpm.test.js +0 -166
  21. package/dist/domain/cpm.test.js.map +0 -1
  22. package/dist/domain/ddd.test.d.ts +0 -2
  23. package/dist/domain/ddd.test.d.ts.map +0 -1
  24. package/dist/domain/ddd.test.js +0 -349
  25. package/dist/domain/ddd.test.js.map +0 -1
  26. package/dist/domain/ladder.test.d.ts +0 -2
  27. package/dist/domain/ladder.test.d.ts.map +0 -1
  28. package/dist/domain/ladder.test.js +0 -213
  29. package/dist/domain/ladder.test.js.map +0 -1
  30. package/dist/domain/metrics.test.d.ts +0 -2
  31. package/dist/domain/metrics.test.d.ts.map +0 -1
  32. package/dist/domain/metrics.test.js +0 -252
  33. package/dist/domain/metrics.test.js.map +0 -1
  34. package/dist/domain/task-duration.test.d.ts +0 -2
  35. package/dist/domain/task-duration.test.d.ts.map +0 -1
  36. package/dist/domain/task-duration.test.js +0 -307
  37. package/dist/domain/task-duration.test.js.map +0 -1
  38. package/dist/domain/workload.test.d.ts +0 -2
  39. package/dist/domain/workload.test.d.ts.map +0 -1
  40. package/dist/domain/workload.test.js +0 -261
  41. package/dist/domain/workload.test.js.map +0 -1
  42. package/dist/engine/actor.test.d.ts +0 -2
  43. package/dist/engine/actor.test.d.ts.map +0 -1
  44. package/dist/engine/actor.test.js +0 -54
  45. package/dist/engine/actor.test.js.map +0 -1
  46. package/dist/engine/authorization.test.d.ts +0 -2
  47. package/dist/engine/authorization.test.d.ts.map +0 -1
  48. package/dist/engine/authorization.test.js +0 -154
  49. package/dist/engine/authorization.test.js.map +0 -1
  50. package/dist/engine/cascade.test.d.ts +0 -2
  51. package/dist/engine/cascade.test.d.ts.map +0 -1
  52. package/dist/engine/cascade.test.js +0 -99
  53. package/dist/engine/cascade.test.js.map +0 -1
  54. package/dist/engine/config.test.d.ts +0 -2
  55. package/dist/engine/config.test.d.ts.map +0 -1
  56. package/dist/engine/config.test.js +0 -46
  57. package/dist/engine/config.test.js.map +0 -1
  58. package/dist/engine/entity-events.test.d.ts +0 -2
  59. package/dist/engine/entity-events.test.d.ts.map +0 -1
  60. package/dist/engine/entity-events.test.js +0 -61
  61. package/dist/engine/entity-events.test.js.map +0 -1
  62. package/dist/index.test.d.ts +0 -2
  63. package/dist/index.test.d.ts.map +0 -1
  64. package/dist/index.test.js +0 -429
  65. package/dist/index.test.js.map +0 -1
  66. package/dist/plugins/plugins.test.d.ts +0 -2
  67. package/dist/plugins/plugins.test.d.ts.map +0 -1
  68. package/dist/plugins/plugins.test.js +0 -137
  69. package/dist/plugins/plugins.test.js.map +0 -1
  70. package/dist/schemas/schemas.test.d.ts +0 -2
  71. package/dist/schemas/schemas.test.d.ts.map +0 -1
  72. package/dist/schemas/schemas.test.js +0 -58
  73. package/dist/schemas/schemas.test.js.map +0 -1
  74. package/dist/status.test.d.ts +0 -2
  75. package/dist/status.test.d.ts.map +0 -1
  76. package/dist/status.test.js +0 -295
  77. package/dist/status.test.js.map +0 -1
  78. package/dist/storage/storage.test.d.ts +0 -2
  79. package/dist/storage/storage.test.d.ts.map +0 -1
  80. package/dist/storage/storage.test.js +0 -236
  81. package/dist/storage/storage.test.js.map +0 -1
  82. package/dist/store/conformance.test.d.ts +0 -2
  83. package/dist/store/conformance.test.d.ts.map +0 -1
  84. package/dist/store/conformance.test.js +0 -15
  85. package/dist/store/conformance.test.js.map +0 -1
  86. package/dist/store/firebase.test.d.ts +0 -2
  87. package/dist/store/firebase.test.d.ts.map +0 -1
  88. package/dist/store/firebase.test.js +0 -103
  89. package/dist/store/firebase.test.js.map +0 -1
  90. package/dist/store/query.test.d.ts +0 -2
  91. package/dist/store/query.test.d.ts.map +0 -1
  92. package/dist/store/query.test.js +0 -89
  93. package/dist/store/query.test.js.map +0 -1
  94. package/dist/store/sqlite.test.d.ts +0 -2
  95. package/dist/store/sqlite.test.d.ts.map +0 -1
  96. package/dist/store/sqlite.test.js +0 -177
  97. package/dist/store/sqlite.test.js.map +0 -1
  98. package/dist/task-state.test.d.ts +0 -2
  99. package/dist/task-state.test.d.ts.map +0 -1
  100. package/dist/task-state.test.js +0 -423
  101. package/dist/task-state.test.js.map +0 -1
  102. package/dist/use-case-validation.test.d.ts +0 -2
  103. package/dist/use-case-validation.test.d.ts.map +0 -1
  104. package/dist/use-case-validation.test.js +0 -281
  105. package/dist/use-case-validation.test.js.map +0 -1
  106. package/dist/utils/fractional-index.test.d.ts +0 -2
  107. package/dist/utils/fractional-index.test.d.ts.map +0 -1
  108. package/dist/utils/fractional-index.test.js +0 -182
  109. package/dist/utils/fractional-index.test.js.map +0 -1
  110. package/dist/utils/key.test.d.ts +0 -2
  111. package/dist/utils/key.test.d.ts.map +0 -1
  112. package/dist/utils/key.test.js +0 -65
  113. package/dist/utils/key.test.js.map +0 -1
  114. package/dist/utils/mentions.test.d.ts +0 -2
  115. package/dist/utils/mentions.test.d.ts.map +0 -1
  116. package/dist/utils/mentions.test.js +0 -114
  117. package/dist/utils/mentions.test.js.map +0 -1
  118. package/dist/webhooks/webhooks.test.d.ts +0 -2
  119. package/dist/webhooks/webhooks.test.d.ts.map +0 -1
  120. package/dist/webhooks/webhooks.test.js +0 -154
  121. package/dist/webhooks/webhooks.test.js.map +0 -1
  122. package/src/deliverables.test.ts +0 -284
  123. package/src/domain/authorization.ts +0 -82
  124. package/src/domain/calendar.test.ts +0 -216
  125. package/src/domain/calendar.ts +0 -502
  126. package/src/domain/cpm.test.ts +0 -189
  127. package/src/domain/cpm.ts +0 -258
  128. package/src/domain/custom-fields.ts +0 -172
  129. package/src/domain/ddd.test.ts +0 -442
  130. package/src/domain/entities.ts +0 -798
  131. package/src/domain/errors.ts +0 -38
  132. package/src/domain/events.ts +0 -369
  133. package/src/domain/graph.ts +0 -70
  134. package/src/domain/index.ts +0 -12
  135. package/src/domain/ladder.test.ts +0 -251
  136. package/src/domain/ladder.ts +0 -474
  137. package/src/domain/metrics.test.ts +0 -288
  138. package/src/domain/metrics.ts +0 -497
  139. package/src/domain/task-duration.test.ts +0 -354
  140. package/src/domain/workload.test.ts +0 -311
  141. package/src/domain/workload.ts +0 -457
  142. package/src/engine/actor.test.ts +0 -63
  143. package/src/engine/authorization.test.ts +0 -199
  144. package/src/engine/cascade.test.ts +0 -121
  145. package/src/engine/config.test.ts +0 -51
  146. package/src/engine/entity-events.test.ts +0 -67
  147. package/src/engine/index.ts +0 -2472
  148. package/src/index.test.ts +0 -514
  149. package/src/index.ts +0 -9
  150. package/src/plugins/index.ts +0 -103
  151. package/src/plugins/plugins.test.ts +0 -161
  152. package/src/schemas/index.ts +0 -402
  153. package/src/schemas/schemas.test.ts +0 -116
  154. package/src/status.test.ts +0 -354
  155. package/src/storage/file-storage.ts +0 -200
  156. package/src/storage/firebase-storage.ts +0 -209
  157. package/src/storage/index.ts +0 -3
  158. package/src/storage/s3.ts +0 -151
  159. package/src/storage/storage.test.ts +0 -274
  160. package/src/store/conformance.test.ts +0 -15
  161. package/src/store/firebase.test.ts +0 -131
  162. package/src/store/firebase.ts +0 -658
  163. package/src/store/index.ts +0 -623
  164. package/src/store/query.test.ts +0 -110
  165. package/src/store/query.ts +0 -113
  166. package/src/store/sqlite.test.ts +0 -218
  167. package/src/store/sqlite.ts +0 -1480
  168. package/src/task-state.test.ts +0 -506
  169. package/src/testing/conformance.ts +0 -319
  170. package/src/testing/index.ts +0 -1
  171. package/src/types/index.ts +0 -859
  172. package/src/use-case-validation.test.ts +0 -324
  173. package/src/utils/fractional-index.test.ts +0 -228
  174. package/src/utils/fractional-index.ts +0 -254
  175. package/src/utils/index.ts +0 -7
  176. package/src/utils/key.test.ts +0 -76
  177. package/src/utils/key.ts +0 -62
  178. package/src/utils/mentions.test.ts +0 -132
  179. package/src/utils/mentions.ts +0 -131
  180. package/src/utils/status.ts +0 -419
  181. package/src/utils/workflow.ts +0 -306
  182. package/src/webhooks/dispatcher.ts +0 -190
  183. package/src/webhooks/index.ts +0 -2
  184. package/src/webhooks/signature.ts +0 -57
  185. package/src/webhooks/webhooks.test.ts +0 -201
  186. package/tsconfig.json +0 -8
  187. package/tsconfig.tsbuildinfo +0 -1
@@ -1,82 +0,0 @@
1
- import type {
2
- Actor,
3
- AuthorizationAction,
4
- AuthorizationPolicy,
5
- AuthorizationRequest,
6
- ProjectRole
7
- } from '../types/index.js';
8
-
9
- const VIEWER: AuthorizationAction[] = ['project.read'];
10
- const CONTRIBUTOR: AuthorizationAction[] = [
11
- ...VIEWER,
12
- 'task.create',
13
- 'task.update',
14
- 'comment.create',
15
- 'attachment.create',
16
- 'time.log'
17
- ];
18
- const PROJECT_MANAGER: AuthorizationAction[] = [
19
- ...CONTRIBUTOR,
20
- 'task.delete',
21
- 'plan.manage',
22
- 'project.update',
23
- 'project.manage_members',
24
- 'comment.moderate',
25
- 'attachment.delete'
26
- ];
27
- const PROJECT_ADMIN: AuthorizationAction[] = [...PROJECT_MANAGER, 'project.delete'];
28
-
29
- /** Actions each project role grants by default. */
30
- export const DEFAULT_ROLE_PERMISSIONS: Record<ProjectRole, readonly AuthorizationAction[]> = {
31
- viewer: VIEWER,
32
- contributor: CONTRIBUTOR,
33
- project_manager: PROJECT_MANAGER,
34
- admin: PROJECT_ADMIN
35
- };
36
-
37
- export interface RolePolicyOptions {
38
- /** Override or extend the actions granted to each project role. */
39
- rolePermissions?: Partial<Record<ProjectRole, readonly AuthorizationAction[]>>;
40
- /** Workspace roles (from `actor.roles`) that may do anything within their tenant. Default `['admin']`. */
41
- superuserRoles?: string[];
42
- /**
43
- * Who may create projects (they become the project's `admin`). Default: any actor except the
44
- * anonymous one (`userId === 'anonymous'`).
45
- */
46
- canCreateProjects?: (actor: Actor) => boolean;
47
- /** Who may manage workflows, teams and webhooks. Default: superusers only. */
48
- canManageWorkspace?: (actor: Actor) => boolean;
49
- }
50
-
51
- /**
52
- * Role-based policy driven by `project.members`. Members get their role's actions on that project;
53
- * authors may edit and delete their own comments and attachments; workspace superusers may do
54
- * everything. Everyone else is denied.
55
- */
56
- export function createRolePolicy(options: RolePolicyOptions = {}): AuthorizationPolicy {
57
- const permissions = { ...DEFAULT_ROLE_PERMISSIONS, ...options.rolePermissions };
58
- const superuserRoles = options.superuserRoles ?? ['admin'];
59
- const isSuperuser = (actor: Actor) => (actor.roles ?? []).some((r) => superuserRoles.includes(r));
60
- const canCreateProjects = options.canCreateProjects ?? ((actor: Actor) => actor.userId !== 'anonymous');
61
- const canManageWorkspace = options.canManageWorkspace ?? isSuperuser;
62
-
63
- return ({ actor, action, project, resource }: AuthorizationRequest): boolean => {
64
- if (isSuperuser(actor)) return true;
65
- if (action === 'project.create') return canCreateProjects(actor);
66
- if (action === 'workspace.manage') return canManageWorkspace(actor);
67
- if (!project) return false;
68
-
69
- const role = project.members?.find((m) => m.userId === actor.userId)?.role;
70
- if (!role) return false;
71
-
72
- const granted = permissions[role] ?? [];
73
- if (granted.includes(action)) return true;
74
-
75
- // Authors manage their own comments and attachments without moderator rights.
76
- const ownsResource = resource?.ownerId !== undefined && resource.ownerId === actor.userId;
77
- if (action === 'comment.moderate' && ownsResource && granted.includes('comment.create')) return true;
78
- if (action === 'attachment.delete' && ownsResource && granted.includes('attachment.create')) return true;
79
-
80
- return false;
81
- };
82
- }
@@ -1,216 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import {
3
- DEFAULT_WORK_SCHEDULE,
4
- resolveEffectiveSchedule,
5
- isWorkingDay,
6
- getWorkingHoursInDay,
7
- addWorkingHours,
8
- subtractWorkingHours,
9
- getWorkingHoursBetween,
10
- getWorkingDaysBetween,
11
- getWorkingDaysList,
12
- getNetAvailableCapacity,
13
- formatTaskDuration
14
- } from './calendar.js';
15
- import type { WorkSchedule } from '../types/index.js';
16
-
17
- describe('Calendar and Work Schedule Domain', () => {
18
- describe('resolveEffectiveSchedule', () => {
19
- const customUserSchedule: WorkSchedule = {
20
- name: 'User 30h',
21
- defaultHoursPerDay: 6,
22
- days: [{ dayOfWeek: 1, isWorkingDay: true }]
23
- };
24
- const customTeamSchedule: WorkSchedule = {
25
- name: 'Team 35h',
26
- defaultHoursPerDay: 7,
27
- days: [{ dayOfWeek: 1, isWorkingDay: true }]
28
- };
29
- const customProjectSchedule: WorkSchedule = {
30
- name: 'Project 4-Day',
31
- defaultHoursPerDay: 10,
32
- days: [{ dayOfWeek: 1, isWorkingDay: true }]
33
- };
34
-
35
- it('prioritizes user schedule when present', () => {
36
- const resolved = resolveEffectiveSchedule({
37
- user: { id: 'u1', name: 'Alice', email: 'alice@test.com', role: 'contributor', schedule: customUserSchedule, createdAt: '' },
38
- team: { id: 't1', name: 'Dev', memberIds: [], schedule: customTeamSchedule, createdAt: '', updatedAt: '' },
39
- project: { id: 'p1', name: 'Proj', schedule: customProjectSchedule, createdAt: '', updatedAt: '' }
40
- });
41
- expect(resolved.name).toBe('User 30h');
42
- });
43
-
44
- it('falls back to team schedule when user has no custom schedule', () => {
45
- const resolved = resolveEffectiveSchedule({
46
- user: { id: 'u1', name: 'Alice', email: 'alice@test.com', role: 'contributor', createdAt: '' },
47
- team: { id: 't1', name: 'Dev', memberIds: [], schedule: customTeamSchedule, createdAt: '', updatedAt: '' },
48
- project: { id: 'p1', name: 'Proj', schedule: customProjectSchedule, createdAt: '', updatedAt: '' }
49
- });
50
- expect(resolved.name).toBe('Team 35h');
51
- });
52
-
53
- it('falls back to project schedule when user and team have no schedule', () => {
54
- const resolved = resolveEffectiveSchedule({
55
- project: { id: 'p1', name: 'Proj', schedule: customProjectSchedule, createdAt: '', updatedAt: '' }
56
- });
57
- expect(resolved.name).toBe('Project 4-Day');
58
- });
59
-
60
- it('falls back to engine default or DEFAULT_WORK_SCHEDULE', () => {
61
- const resolved = resolveEffectiveSchedule();
62
- expect(resolved.name).toBe(DEFAULT_WORK_SCHEDULE.name);
63
- expect(resolved.defaultHoursPerDay).toBe(8);
64
- });
65
- });
66
-
67
- describe('isWorkingDay and getWorkingHoursInDay', () => {
68
- // 2026-09-18 is Friday, 2026-09-19 is Saturday, 2026-09-20 is Sunday, 2026-09-21 is Monday
69
- it('identifies weekdays as working days and weekends as non-working days by default', () => {
70
- expect(isWorkingDay('2026-09-18')).toBe(true); // Friday
71
- expect(isWorkingDay('2026-09-19')).toBe(false); // Saturday
72
- expect(isWorkingDay('2026-09-20')).toBe(false); // Sunday
73
- expect(isWorkingDay('2026-09-21')).toBe(true); // Monday
74
-
75
- expect(getWorkingHoursInDay('2026-09-18')).toBe(8);
76
- expect(getWorkingHoursInDay('2026-09-19')).toBe(0);
77
- expect(getWorkingHoursInDay('2026-09-20')).toBe(0);
78
- });
79
-
80
- it('accounts for full and half-day holidays', () => {
81
- const holidaySchedule: WorkSchedule = {
82
- ...DEFAULT_WORK_SCHEDULE,
83
- holidays: [
84
- { date: '2026-09-21', name: 'Labor Day' },
85
- { date: '2026-09-22', name: 'Eve', halfDay: true }
86
- ]
87
- };
88
-
89
- expect(isWorkingDay('2026-09-21', holidaySchedule)).toBe(false);
90
- expect(getWorkingHoursInDay('2026-09-21', holidaySchedule)).toBe(0);
91
-
92
- expect(isWorkingDay('2026-09-22', holidaySchedule)).toBe(true);
93
- expect(getWorkingHoursInDay('2026-09-22', holidaySchedule)).toBe(4);
94
- });
95
- });
96
-
97
- describe('addWorkingHours', () => {
98
- it('advances hours within the same working day', () => {
99
- // Monday 2026-09-21 at 09:00 + 4 hours -> 13:00
100
- const start = '2026-09-21T09:00:00Z';
101
- const finish = addWorkingHours(start, 4);
102
- expect(finish.toISOString()).toBe('2026-09-21T13:00:00.000Z');
103
- });
104
-
105
- it('rolls over weekends seamlessly', () => {
106
- // Friday 2026-09-18 at 15:00 + 4 hours
107
- // 15:00-17:00 is 2h on Friday. Sat & Sun skipped.
108
- // Remaining 2h starts Monday 2026-09-21 at 09:00 -> finishes 11:00!
109
- const start = '2026-09-18T15:00:00Z';
110
- const finish = addWorkingHours(start, 4);
111
- expect(finish.toISOString()).toBe('2026-09-21T11:00:00.000Z');
112
- });
113
-
114
- it('skips holidays when rolling over', () => {
115
- const scheduleWithMondayHoliday: WorkSchedule = {
116
- ...DEFAULT_WORK_SCHEDULE,
117
- holidays: [{ date: '2026-09-21', name: 'Bank Holiday' }]
118
- };
119
- // Friday 2026-09-18 at 15:00 + 4 hours -> 2h Friday, Sat/Sun skipped, Mon skipped -> finishes Tuesday 11:00!
120
- const start = '2026-09-18T15:00:00Z';
121
- const finish = addWorkingHours(start, 4, scheduleWithMondayHoliday);
122
- expect(finish.toISOString()).toBe('2026-09-22T11:00:00.000Z');
123
- });
124
- });
125
-
126
- describe('subtractWorkingHours', () => {
127
- it('moves backward within the same working day', () => {
128
- // Monday 2026-09-21 at 15:00 - 4 hours -> 11:00
129
- const end = '2026-09-21T15:00:00Z';
130
- const start = subtractWorkingHours(end, 4);
131
- expect(start.toISOString()).toBe('2026-09-21T11:00:00.000Z');
132
- });
133
-
134
- it('moves backward across weekends', () => {
135
- // Monday 2026-09-21 at 11:00 - 4 hours
136
- // 2h backwards to 09:00 on Monday. Sunday & Saturday skipped.
137
- // Remaining 2h backwards from Friday 17:00 -> 15:00!
138
- const end = '2026-09-21T11:00:00Z';
139
- const start = subtractWorkingHours(end, 4);
140
- expect(start.toISOString()).toBe('2026-09-18T15:00:00.000Z');
141
- });
142
- });
143
-
144
- describe('getWorkingHoursBetween and getWorkingDaysBetween', () => {
145
- it('calculates working hours between two dates excluding weekends', () => {
146
- // Friday 09:00 to Monday 17:00 = 8h (Friday) + 0h (weekend) + 8h (Monday) = 16h
147
- const start = '2026-09-18T09:00:00Z';
148
- const end = '2026-09-21T17:00:00Z';
149
- expect(getWorkingHoursBetween(start, end)).toBe(16);
150
- expect(getWorkingDaysBetween('2026-09-18', '2026-09-21')).toBe(2);
151
- expect(getWorkingDaysList('2026-09-18', '2026-09-21')).toEqual(['2026-09-18', '2026-09-21']);
152
- });
153
-
154
- it('calculates net capacity deducting holidays', () => {
155
- const scheduleWithHoliday: WorkSchedule = {
156
- ...DEFAULT_WORK_SCHEDULE,
157
- holidays: [{ date: '2026-09-21', name: 'Holiday' }]
158
- };
159
- // Friday 2026-09-18 to Tuesday 2026-09-22:
160
- // Friday (8) + Sat (0) + Sun (0) + Mon (0, holiday) + Tue (8) = 16h
161
- const cap = getNetAvailableCapacity('2026-09-18', '2026-09-22', scheduleWithHoliday);
162
- expect(cap).toBe(16);
163
- });
164
- });
165
-
166
- describe('formatTaskDuration', () => {
167
- it('handles null, undefined, NaN, and negative values', () => {
168
- expect(formatTaskDuration(null)).toBe('0s');
169
- expect(formatTaskDuration(undefined)).toBe('0s');
170
- expect(formatTaskDuration(NaN)).toBe('0s');
171
- expect(formatTaskDuration(-5)).toBe('0s');
172
- expect(formatTaskDuration(0)).toBe('0s');
173
- });
174
-
175
- it('formats short durations under 120s with seconds', () => {
176
- expect(formatTaskDuration(45)).toBe('45s');
177
- expect(formatTaskDuration(110.3)).toBe('110.3s');
178
- expect(formatTaskDuration(119.9)).toBe('119.9s');
179
- expect(formatTaskDuration(1.5)).toBe('1.5s');
180
- });
181
-
182
- it('formats sub-day durations with hours and minutes', () => {
183
- // 44 minutes = 2640s
184
- expect(formatTaskDuration(2640)).toBe('0h 44m');
185
- // 2h 15m = 8100s
186
- expect(formatTaskDuration(8100)).toBe('2h 15m');
187
- // 7h 59m = 28740s (< 8h working day)
188
- expect(formatTaskDuration(28740)).toBe('7h 59m');
189
- });
190
-
191
- it('formats multi-day durations using default 8h working days', () => {
192
- // 8 hours = 28800s -> 1 day
193
- expect(formatTaskDuration(28800)).toBe('1 day');
194
- // 12 hours = 43200s -> 1.5 days
195
- expect(formatTaskDuration(43200)).toBe('1.5 days');
196
- // 25.6 hours = 92160s -> 3.2 days
197
- expect(formatTaskDuration(92160)).toBe('3.2 days');
198
- });
199
-
200
- it('supports calendar_days basis (24h per day)', () => {
201
- // 12 hours on calendar days basis -> 12h 0m (< 24h)
202
- expect(formatTaskDuration(43200, { dayBasis: 'calendar_days' })).toBe('12h 0m');
203
- // 36 hours on calendar days basis -> 1.5 days
204
- expect(formatTaskDuration(129600, { dayBasis: 'calendar_days' })).toBe('1.5 days');
205
- });
206
-
207
- it('supports custom work schedules', () => {
208
- const fourHourDaySchedule: WorkSchedule = {
209
- ...DEFAULT_WORK_SCHEDULE,
210
- defaultHoursPerDay: 4
211
- };
212
- // 6 hours with 4h/day schedule = 1.5 days
213
- expect(formatTaskDuration(21600, { schedule: fourHourDaySchedule })).toBe('1.5 days');
214
- });
215
- });
216
- });