pi-harness-runtime 1.1.349 → 1.1.351
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 +3 -0
- package/package.json +1 -1
- package/packages/a2a-adapter/package.json +1 -1
- package/packages/agent-policy/package.json +1 -1
- package/packages/architecture-generator/package.json +1 -1
- package/packages/auth/package.json +1 -1
- package/packages/autonomous-refactor/package.json +1 -1
- package/packages/autonomous-runtime/package.json +1 -1
- package/packages/cache-strategy/package.json +1 -1
- package/packages/capability-registry/package.json +1 -1
- package/packages/checkpoint/package.json +1 -1
- package/packages/cli-plugin-sdk/package.json +1 -1
- package/packages/clipboard/package.json +1 -1
- package/packages/clipboard-plugin/package.json +1 -1
- package/packages/code-generation/package.json +1 -1
- package/packages/code-review/package.json +1 -1
- package/packages/codex-adapter/package.json +1 -1
- package/packages/codex-watcher/package.json +1 -1
- package/packages/config-capture/package.json +1 -1
- package/packages/connection-runtime/package.json +1 -1
- package/packages/context-compiler/package.json +1 -1
- package/packages/context-discovery/package.json +1 -1
- package/packages/context-manager/package.json +1 -1
- package/packages/contracts/dist/delegation-assessor.d.ts +27 -0
- package/packages/contracts/dist/delegation-assessor.js +210 -0
- package/packages/contracts/dist/delegation-store.d.ts +35 -0
- package/packages/contracts/dist/delegation-store.js +172 -0
- package/packages/contracts/dist/delegation.d.ts +142 -0
- package/packages/contracts/dist/delegation.js +33 -0
- package/packages/contracts/dist/index.d.ts +5 -0
- package/packages/contracts/dist/index.js +5 -0
- package/packages/contracts/dist/scope-discovery.d.ts +65 -0
- package/packages/contracts/dist/scope-discovery.js +247 -0
- package/packages/contracts/dist/work-partitioner.d.ts +57 -0
- package/packages/contracts/dist/work-partitioner.js +165 -0
- package/packages/contracts/package.json +1 -1
- package/packages/contracts/src/delegation-assessor.ts +268 -0
- package/packages/contracts/src/delegation-store.ts +204 -0
- package/packages/contracts/src/delegation.ts +174 -0
- package/packages/contracts/src/index.ts +5 -0
- package/packages/contracts/src/scope-discovery.ts +352 -0
- package/packages/contracts/src/work-partitioner.ts +251 -0
- package/packages/contracts/test/delegation.test.ts +350 -0
- package/packages/cookie-sanitizer/package.json +1 -1
- package/packages/cost-optimizer/package.json +1 -1
- package/packages/dependency-analyzer/package.json +1 -1
- package/packages/django-plugin/package.json +1 -1
- package/packages/doc-generator/package.json +1 -1
- package/packages/durable-review/package.json +1 -1
- package/packages/e2e-tester/package.json +1 -1
- package/packages/evaluation-engine/package.json +1 -1
- package/packages/evaluation-runner/package.json +1 -1
- package/packages/event-bus/package.json +1 -1
- package/packages/event-sink/package.json +1 -1
- package/packages/event-store/package.json +1 -1
- package/packages/experience-replay/package.json +1 -1
- package/packages/feedback-collector/package.json +1 -1
- package/packages/file-copy-helper/package.json +1 -1
- package/packages/framework-detector/package.json +1 -1
- package/packages/framework-plugin-sdk/package.json +1 -1
- package/packages/frappe-plugin/package.json +1 -1
- package/packages/generic-web-plugin/package.json +1 -1
- package/packages/health-monitor/package.json +1 -1
- package/packages/intent-analyzer/package.json +1 -1
- package/packages/jev-judge/package.json +1 -1
- package/packages/knowledge-graph/package.json +1 -1
- package/packages/knowledge-retrieval/package.json +1 -1
- package/packages/laravel-plugin/package.json +1 -1
- package/packages/learning-engine/package.json +1 -1
- package/packages/mcp-adapter/package.json +1 -1
- package/packages/memory-engine/package.json +1 -1
- package/packages/milestone-manager/package.json +1 -1
- package/packages/model-registry/package.json +1 -1
- package/packages/nextjs-plugin/package.json +1 -1
- package/packages/notification/package.json +1 -1
- package/packages/observability/package.json +1 -1
- package/packages/okf-indexer/package.json +1 -1
- package/packages/paperclip-integration/package.json +1 -1
- package/packages/performance-optimizer/package.json +1 -1
- package/packages/permission-mode/package.json +1 -1
- package/packages/privilege-broker/package.json +1 -1
- package/packages/project-analyzer/package.json +1 -1
- package/packages/project-bootstrap/package.json +1 -1
- package/packages/projection-engine/package.json +1 -1
- package/packages/prompt-compiler/package.json +1 -1
- package/packages/prompt-versioning/package.json +1 -1
- package/packages/provider-adapter-sdk/package.json +1 -1
- package/packages/provider-router/package.json +1 -1
- package/packages/provider-selector/package.json +1 -1
- package/packages/providers/package.json +1 -1
- package/packages/qdrant-skills/package.json +1 -1
- package/packages/quota-manager/package.json +1 -1
- package/packages/rate-limiter/package.json +1 -1
- package/packages/react-vite-plugin/package.json +1 -1
- package/packages/relay/package.json +1 -1
- package/packages/release-manager/package.json +1 -1
- package/packages/requirement-compiler/package.json +1 -1
- package/packages/runtime/package.json +1 -1
- package/packages/scheduler/package.json +1 -1
- package/packages/scheduler-adapter/package.json +1 -1
- package/packages/session/package.json +1 -1
- package/packages/session-api/package.json +1 -1
- package/packages/session-export/package.json +1 -1
- package/packages/shared-context/package.json +1 -1
- package/packages/skill-mcp-client/package.json +1 -1
- package/packages/skill-registry/package.json +1 -1
- package/packages/skills/package.json +1 -1
- package/packages/sprint-planner/package.json +1 -1
- package/packages/subscription-engine/package.json +1 -1
- package/packages/task-compiler/package.json +1 -1
- package/packages/telegram/package.json +1 -1
- package/packages/tencentdb-memory/package.json +1 -1
- package/packages/tencentdb-sync/package.json +1 -1
- package/packages/test-data-generator/package.json +1 -1
- package/packages/test-generator/package.json +1 -1
- package/packages/todo-bd-sync/package.json +1 -1
- package/packages/token-estimation/package.json +1 -1
- package/packages/token-optimizer/package.json +1 -1
- package/packages/trajectory/package.json +1 -1
- package/packages/tui/package.json +1 -1
- package/packages/types/package.json +1 -1
- package/packages/voice-api/package.json +1 -1
- package/packages/webmcp-tester/package.json +1 -1
- package/packages/wiki/package.json +1 -1
- package/packages/workflow-events/package.json +1 -1
- package/packages/workspace-scanner/package.json +1 -1
- package/packages/worktree/package.json +1 -1
- package/packages/write-review/package.json +1 -1
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Work Partitioner
|
|
3
|
+
*
|
|
4
|
+
* Partitions work into disjoint file ownership groups.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { WorkGroup, ScopeFacts } from "./delegation.js";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* File dependency info
|
|
11
|
+
*/
|
|
12
|
+
export interface FileDependency {
|
|
13
|
+
path: string;
|
|
14
|
+
imports: string[];
|
|
15
|
+
exports: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Partition configuration
|
|
20
|
+
*/
|
|
21
|
+
export interface PartitionConfig {
|
|
22
|
+
/** Maximum files per group */
|
|
23
|
+
maxFilesPerGroup: number;
|
|
24
|
+
/** Whether to group by directory */
|
|
25
|
+
groupByDirectory: boolean;
|
|
26
|
+
/** Shared files that shouldn't be partitioned */
|
|
27
|
+
sharedPaths: string[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Default partition config
|
|
32
|
+
*/
|
|
33
|
+
export const DEFAULT_PARTITION_CONFIG: PartitionConfig = {
|
|
34
|
+
maxFilesPerGroup: 15,
|
|
35
|
+
groupByDirectory: true,
|
|
36
|
+
sharedPaths: [
|
|
37
|
+
"index.ts",
|
|
38
|
+
"index.js",
|
|
39
|
+
"main.ts",
|
|
40
|
+
"main.js",
|
|
41
|
+
"package.json",
|
|
42
|
+
"tsconfig.json",
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Partition files into ownership groups
|
|
48
|
+
*/
|
|
49
|
+
export function partitionWork(
|
|
50
|
+
files: string[],
|
|
51
|
+
facts: ScopeFacts,
|
|
52
|
+
config: Partial<PartitionConfig> = {}
|
|
53
|
+
): WorkGroup[] {
|
|
54
|
+
const cfg = { ...DEFAULT_PARTITION_CONFIG, ...config };
|
|
55
|
+
|
|
56
|
+
// Filter out shared paths
|
|
57
|
+
const ownedFiles = files.filter(
|
|
58
|
+
(f) => !cfg.sharedPaths.some((s) => f.endsWith(s))
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Group files by directory
|
|
62
|
+
const dirGroups = groupByDirectory(ownedFiles);
|
|
63
|
+
|
|
64
|
+
// Further partition large groups
|
|
65
|
+
const groups: WorkGroup[] = [];
|
|
66
|
+
let groupId = 1;
|
|
67
|
+
|
|
68
|
+
for (const [dir, dirFiles] of Object.entries(dirGroups)) {
|
|
69
|
+
if (dirFiles.length <= cfg.maxFilesPerGroup) {
|
|
70
|
+
groups.push(createGroup(groupId++, dir, dirFiles, facts.isMechanical));
|
|
71
|
+
} else {
|
|
72
|
+
// Split large directories
|
|
73
|
+
const subGroups = splitGroup(dirFiles, cfg.maxFilesPerGroup);
|
|
74
|
+
for (const subFiles of subGroups) {
|
|
75
|
+
groups.push(createGroup(groupId++, dir, subFiles, facts.isMechanical));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return groups;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Group files by directory
|
|
85
|
+
*/
|
|
86
|
+
function groupByDirectory(files: string[]): Record<string, string[]> {
|
|
87
|
+
const groups: Record<string, string[]> = {};
|
|
88
|
+
|
|
89
|
+
for (const file of files) {
|
|
90
|
+
// Get directory part of path
|
|
91
|
+
const parts = file.split("/");
|
|
92
|
+
const dir = parts.length > 1 ? parts.slice(0, -1).join("/") : ".";
|
|
93
|
+
|
|
94
|
+
if (!groups[dir]) {
|
|
95
|
+
groups[dir] = [];
|
|
96
|
+
}
|
|
97
|
+
groups[dir].push(file);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return groups;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Create a work group
|
|
105
|
+
*/
|
|
106
|
+
function createGroup(
|
|
107
|
+
id: number,
|
|
108
|
+
description: string,
|
|
109
|
+
files: string[],
|
|
110
|
+
isMechanical: boolean
|
|
111
|
+
): WorkGroup {
|
|
112
|
+
return {
|
|
113
|
+
groupId: `group-${id}`,
|
|
114
|
+
description: `${description} (${files.length} files)`,
|
|
115
|
+
ownedPaths: files,
|
|
116
|
+
isMechanical,
|
|
117
|
+
status: "pending",
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Split a group into smaller subgroups
|
|
123
|
+
*/
|
|
124
|
+
function splitGroup(files: string[], maxSize: number): string[][] {
|
|
125
|
+
const subgroups: string[][] = [];
|
|
126
|
+
|
|
127
|
+
for (let i = 0; i < files.length; i += maxSize) {
|
|
128
|
+
subgroups.push(files.slice(i, i + maxSize));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return subgroups;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Detect ownership conflicts
|
|
136
|
+
*/
|
|
137
|
+
export function detectOwnershipConflicts(
|
|
138
|
+
groups: WorkGroup[],
|
|
139
|
+
newPaths: string[]
|
|
140
|
+
): string[] {
|
|
141
|
+
const conflicts: string[] = [];
|
|
142
|
+
|
|
143
|
+
for (const path of newPaths) {
|
|
144
|
+
for (const group of groups) {
|
|
145
|
+
if (
|
|
146
|
+
group.status !== "cancelled" &&
|
|
147
|
+
group.status !== "failed" &&
|
|
148
|
+
group.ownedPaths.includes(path)
|
|
149
|
+
) {
|
|
150
|
+
conflicts.push(`${path} already owned by ${group.groupId}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return conflicts;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Assign work to group
|
|
160
|
+
*/
|
|
161
|
+
export function assignWorkToGroup(
|
|
162
|
+
groups: WorkGroup[],
|
|
163
|
+
groupId: string,
|
|
164
|
+
paths: string[]
|
|
165
|
+
): WorkGroup | null {
|
|
166
|
+
const group = groups.find((g) => g.groupId === groupId);
|
|
167
|
+
|
|
168
|
+
if (!group) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Check for conflicts
|
|
173
|
+
const conflicts = detectOwnershipConflicts(
|
|
174
|
+
groups.filter((g) => g.groupId !== groupId),
|
|
175
|
+
paths
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
if (conflicts.length > 0) {
|
|
179
|
+
// Return group with conflict info
|
|
180
|
+
return {
|
|
181
|
+
...group,
|
|
182
|
+
status: "failed",
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
...group,
|
|
188
|
+
ownedPaths: [...new Set([...group.ownedPaths, ...paths])],
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get unowned files
|
|
194
|
+
*/
|
|
195
|
+
export function getUnownedFiles(
|
|
196
|
+
allFiles: string[],
|
|
197
|
+
groups: WorkGroup[]
|
|
198
|
+
): string[] {
|
|
199
|
+
const ownedFiles = new Set<string>();
|
|
200
|
+
|
|
201
|
+
for (const group of groups) {
|
|
202
|
+
if (group.status !== "cancelled" && group.status !== "failed") {
|
|
203
|
+
for (const path of group.ownedPaths) {
|
|
204
|
+
ownedFiles.add(path);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return allFiles.filter((f) => !ownedFiles.has(f));
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Update group status
|
|
214
|
+
*/
|
|
215
|
+
export function updateGroupStatus(
|
|
216
|
+
groups: WorkGroup[],
|
|
217
|
+
groupId: string,
|
|
218
|
+
status: WorkGroup["status"],
|
|
219
|
+
childId?: string
|
|
220
|
+
): WorkGroup[] {
|
|
221
|
+
return groups.map((g) => {
|
|
222
|
+
if (g.groupId !== groupId) {
|
|
223
|
+
return g;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
...g,
|
|
228
|
+
status,
|
|
229
|
+
childId: childId || g.childId,
|
|
230
|
+
};
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Check if all groups are complete
|
|
236
|
+
*/
|
|
237
|
+
export function areAllGroupsComplete(groups: WorkGroup[]): boolean {
|
|
238
|
+
return groups.every(
|
|
239
|
+
(g) =>
|
|
240
|
+
g.status === "completed" ||
|
|
241
|
+
g.status === "failed" ||
|
|
242
|
+
g.status === "cancelled"
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get pending groups
|
|
248
|
+
*/
|
|
249
|
+
export function getPendingGroups(groups: WorkGroup[]): WorkGroup[] {
|
|
250
|
+
return groups.filter((g) => g.status === "pending");
|
|
251
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Delegation Assessment Tests
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach } from "bun:test";
|
|
6
|
+
import {
|
|
7
|
+
shouldTriggerAssessment,
|
|
8
|
+
DEFAULT_DELEGATION_TRIGGERS,
|
|
9
|
+
type ScopeFacts,
|
|
10
|
+
type DelegationTriggerConfig,
|
|
11
|
+
type DelegationStrategy,
|
|
12
|
+
type WorkGroup,
|
|
13
|
+
} from "../src/delegation.js";
|
|
14
|
+
import {
|
|
15
|
+
partitionWork,
|
|
16
|
+
detectOwnershipConflicts,
|
|
17
|
+
getUnownedFiles,
|
|
18
|
+
updateGroupStatus,
|
|
19
|
+
areAllGroupsComplete,
|
|
20
|
+
DEFAULT_PARTITION_CONFIG,
|
|
21
|
+
} from "../src/work-partitioner.js";
|
|
22
|
+
|
|
23
|
+
describe("Delegation Triggers", () => {
|
|
24
|
+
it("should trigger on 10+ files", () => {
|
|
25
|
+
const facts: ScopeFacts = {
|
|
26
|
+
estimatedFiles: 15,
|
|
27
|
+
observedFiles: 15,
|
|
28
|
+
estimatedCallSites: 20,
|
|
29
|
+
observedCallSites: 20,
|
|
30
|
+
independentComponents: 1,
|
|
31
|
+
tightlyCoupled: false,
|
|
32
|
+
isMechanical: false,
|
|
33
|
+
isComplex: false,
|
|
34
|
+
fileTypes: {},
|
|
35
|
+
fingerprint: "",
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
expect(shouldTriggerAssessment(facts)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should trigger on 50+ call sites", () => {
|
|
42
|
+
const facts: ScopeFacts = {
|
|
43
|
+
estimatedFiles: 5,
|
|
44
|
+
observedFiles: 5,
|
|
45
|
+
estimatedCallSites: 60,
|
|
46
|
+
observedCallSites: 60,
|
|
47
|
+
independentComponents: 1,
|
|
48
|
+
tightlyCoupled: false,
|
|
49
|
+
isMechanical: false,
|
|
50
|
+
isComplex: false,
|
|
51
|
+
fileTypes: {},
|
|
52
|
+
fingerprint: "",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
expect(shouldTriggerAssessment(facts)).toBe(true);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should trigger on 2+ independent components", () => {
|
|
59
|
+
const facts: ScopeFacts = {
|
|
60
|
+
estimatedFiles: 5,
|
|
61
|
+
observedFiles: 5,
|
|
62
|
+
estimatedCallSites: 10,
|
|
63
|
+
observedCallSites: 10,
|
|
64
|
+
independentComponents: 3,
|
|
65
|
+
tightlyCoupled: false,
|
|
66
|
+
isMechanical: false,
|
|
67
|
+
isComplex: false,
|
|
68
|
+
fileTypes: {},
|
|
69
|
+
fingerprint: "",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
expect(shouldTriggerAssessment(facts)).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should not trigger on small scope", () => {
|
|
76
|
+
const facts: ScopeFacts = {
|
|
77
|
+
estimatedFiles: 3,
|
|
78
|
+
observedFiles: 3,
|
|
79
|
+
estimatedCallSites: 5,
|
|
80
|
+
observedCallSites: 5,
|
|
81
|
+
independentComponents: 1,
|
|
82
|
+
tightlyCoupled: false,
|
|
83
|
+
isMechanical: false,
|
|
84
|
+
isComplex: false,
|
|
85
|
+
fileTypes: {},
|
|
86
|
+
fingerprint: "",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
expect(shouldTriggerAssessment(facts)).toBe(false);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should respect custom config", () => {
|
|
93
|
+
const facts: ScopeFacts = {
|
|
94
|
+
estimatedFiles: 5,
|
|
95
|
+
observedFiles: 5,
|
|
96
|
+
estimatedCallSites: 10,
|
|
97
|
+
observedCallSites: 10,
|
|
98
|
+
independentComponents: 1,
|
|
99
|
+
tightlyCoupled: false,
|
|
100
|
+
isMechanical: false,
|
|
101
|
+
isComplex: false,
|
|
102
|
+
fileTypes: {},
|
|
103
|
+
fingerprint: "",
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const customConfig: DelegationTriggerConfig = {
|
|
107
|
+
minFiles: 5,
|
|
108
|
+
minCallSites: 10,
|
|
109
|
+
minIndependentComponents: 1,
|
|
110
|
+
assessOnDiscovery: true,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
expect(shouldTriggerAssessment(facts, customConfig)).toBe(true);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
describe("Work Partitioning", () => {
|
|
118
|
+
it("should partition files by directory", () => {
|
|
119
|
+
const files = [
|
|
120
|
+
"src/components/Button.ts",
|
|
121
|
+
"src/components/Modal.ts",
|
|
122
|
+
"src/utils/helper.ts",
|
|
123
|
+
"src/utils/format.ts",
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
const facts: ScopeFacts = {
|
|
127
|
+
estimatedFiles: 4,
|
|
128
|
+
observedFiles: 4,
|
|
129
|
+
estimatedCallSites: 10,
|
|
130
|
+
observedCallSites: 10,
|
|
131
|
+
independentComponents: 2,
|
|
132
|
+
tightlyCoupled: false,
|
|
133
|
+
isMechanical: false,
|
|
134
|
+
isComplex: false,
|
|
135
|
+
fileTypes: { ".ts": 4 },
|
|
136
|
+
fingerprint: "",
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const groups = partitionWork(files, facts);
|
|
140
|
+
|
|
141
|
+
expect(groups.length).toBe(2);
|
|
142
|
+
expect(groups.some((g) => g.description.includes("components"))).toBe(true);
|
|
143
|
+
expect(groups.some((g) => g.description.includes("utils"))).toBe(true);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("should limit files per group", () => {
|
|
147
|
+
const files = Array.from({ length: 40 }, (_, i) => `src/dir${i % 3}/file${i}.ts`);
|
|
148
|
+
|
|
149
|
+
const facts: ScopeFacts = {
|
|
150
|
+
estimatedFiles: 40,
|
|
151
|
+
observedFiles: 40,
|
|
152
|
+
estimatedCallSites: 100,
|
|
153
|
+
observedCallSites: 100,
|
|
154
|
+
independentComponents: 3,
|
|
155
|
+
tightlyCoupled: false,
|
|
156
|
+
isMechanical: false,
|
|
157
|
+
isComplex: false,
|
|
158
|
+
fileTypes: { ".ts": 40 },
|
|
159
|
+
fingerprint: "",
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const groups = partitionWork(files, facts);
|
|
163
|
+
|
|
164
|
+
// Should have multiple groups (max 15 files per group for 40 files = 3 groups)
|
|
165
|
+
expect(groups.length).toBeGreaterThanOrEqual(3);
|
|
166
|
+
for (const group of groups) {
|
|
167
|
+
expect(group.ownedPaths.length).toBeLessThanOrEqual(
|
|
168
|
+
DEFAULT_PARTITION_CONFIG.maxFilesPerGroup + 5 // Allow small overflow
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("should exclude shared paths", () => {
|
|
174
|
+
const files = [
|
|
175
|
+
"index.ts",
|
|
176
|
+
"src/main.ts",
|
|
177
|
+
"src/index.ts",
|
|
178
|
+
"src/components/Button.ts",
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
const facts: ScopeFacts = {
|
|
182
|
+
estimatedFiles: 4,
|
|
183
|
+
observedFiles: 4,
|
|
184
|
+
estimatedCallSites: 10,
|
|
185
|
+
observedCallSites: 10,
|
|
186
|
+
independentComponents: 1,
|
|
187
|
+
tightlyCoupled: false,
|
|
188
|
+
isMechanical: false,
|
|
189
|
+
isComplex: false,
|
|
190
|
+
fileTypes: { ".ts": 4 },
|
|
191
|
+
fingerprint: "",
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const groups = partitionWork(files, facts);
|
|
195
|
+
|
|
196
|
+
// All groups combined should not include shared paths
|
|
197
|
+
const allOwned = groups.flatMap((g) => g.ownedPaths);
|
|
198
|
+
expect(allOwned).not.toContain("index.ts");
|
|
199
|
+
expect(allOwned).not.toContain("main.ts");
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe("Ownership Conflicts", () => {
|
|
204
|
+
it("should detect conflicts", () => {
|
|
205
|
+
const groups: WorkGroup[] = [
|
|
206
|
+
{
|
|
207
|
+
groupId: "group-1",
|
|
208
|
+
description: "components",
|
|
209
|
+
ownedPaths: ["src/components/Button.ts"],
|
|
210
|
+
isMechanical: false,
|
|
211
|
+
status: "pending",
|
|
212
|
+
},
|
|
213
|
+
];
|
|
214
|
+
|
|
215
|
+
const conflicts = detectOwnershipConflicts(groups, ["src/components/Button.ts"]);
|
|
216
|
+
|
|
217
|
+
expect(conflicts.length).toBe(1);
|
|
218
|
+
expect(conflicts[0]).toContain("already owned");
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("should detect conflict with completed groups (already owned)", () => {
|
|
222
|
+
const groups: WorkGroup[] = [
|
|
223
|
+
{
|
|
224
|
+
groupId: "group-1",
|
|
225
|
+
description: "components",
|
|
226
|
+
ownedPaths: ["src/components/Button.ts"],
|
|
227
|
+
isMechanical: false,
|
|
228
|
+
status: "completed",
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
// Completed groups still own files - conflict should be detected
|
|
233
|
+
const conflicts = detectOwnershipConflicts(groups, ["src/components/Button.ts"]);
|
|
234
|
+
|
|
235
|
+
expect(conflicts.length).toBe(1);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it("should not conflict with cancelled groups", () => {
|
|
239
|
+
const groups: WorkGroup[] = [
|
|
240
|
+
{
|
|
241
|
+
groupId: "group-1",
|
|
242
|
+
description: "components",
|
|
243
|
+
ownedPaths: ["src/components/Button.ts"],
|
|
244
|
+
isMechanical: false,
|
|
245
|
+
status: "cancelled",
|
|
246
|
+
},
|
|
247
|
+
];
|
|
248
|
+
|
|
249
|
+
const conflicts = detectOwnershipConflicts(groups, ["src/components/Button.ts"]);
|
|
250
|
+
|
|
251
|
+
expect(conflicts.length).toBe(0);
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe("Group Status Updates", () => {
|
|
256
|
+
it("should update group status", () => {
|
|
257
|
+
const groups: WorkGroup[] = [
|
|
258
|
+
{
|
|
259
|
+
groupId: "group-1",
|
|
260
|
+
description: "test",
|
|
261
|
+
ownedPaths: ["file.ts"],
|
|
262
|
+
isMechanical: false,
|
|
263
|
+
status: "pending",
|
|
264
|
+
},
|
|
265
|
+
];
|
|
266
|
+
|
|
267
|
+
const updated = updateGroupStatus(groups, "group-1", "dispatched", "child-123");
|
|
268
|
+
|
|
269
|
+
expect(updated[0].status).toBe("dispatched");
|
|
270
|
+
expect(updated[0].childId).toBe("child-123");
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("should check completion", () => {
|
|
274
|
+
const groups: WorkGroup[] = [
|
|
275
|
+
{
|
|
276
|
+
groupId: "group-1",
|
|
277
|
+
description: "test1",
|
|
278
|
+
ownedPaths: ["file1.ts"],
|
|
279
|
+
isMechanical: false,
|
|
280
|
+
status: "completed",
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
groupId: "group-2",
|
|
284
|
+
description: "test2",
|
|
285
|
+
ownedPaths: ["file2.ts"],
|
|
286
|
+
isMechanical: false,
|
|
287
|
+
status: "completed",
|
|
288
|
+
},
|
|
289
|
+
];
|
|
290
|
+
|
|
291
|
+
expect(areAllGroupsComplete(groups)).toBe(true);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("should not report complete with pending", () => {
|
|
295
|
+
const groups: WorkGroup[] = [
|
|
296
|
+
{
|
|
297
|
+
groupId: "group-1",
|
|
298
|
+
description: "test1",
|
|
299
|
+
ownedPaths: ["file1.ts"],
|
|
300
|
+
isMechanical: false,
|
|
301
|
+
status: "completed",
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
groupId: "group-2",
|
|
305
|
+
description: "test2",
|
|
306
|
+
ownedPaths: ["file2.ts"],
|
|
307
|
+
isMechanical: false,
|
|
308
|
+
status: "pending",
|
|
309
|
+
},
|
|
310
|
+
];
|
|
311
|
+
|
|
312
|
+
expect(areAllGroupsComplete(groups)).toBe(false);
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe("Unowned Files", () => {
|
|
317
|
+
it("should identify unowned files", () => {
|
|
318
|
+
const allFiles = ["file1.ts", "file2.ts", "file3.ts"];
|
|
319
|
+
const groups: WorkGroup[] = [
|
|
320
|
+
{
|
|
321
|
+
groupId: "group-1",
|
|
322
|
+
description: "test",
|
|
323
|
+
ownedPaths: ["file1.ts", "file2.ts"],
|
|
324
|
+
isMechanical: false,
|
|
325
|
+
status: "pending",
|
|
326
|
+
},
|
|
327
|
+
];
|
|
328
|
+
|
|
329
|
+
const unowned = getUnownedFiles(allFiles, groups);
|
|
330
|
+
|
|
331
|
+
expect(unowned).toEqual(["file3.ts"]);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
it("should consider completed groups as owned", () => {
|
|
335
|
+
const allFiles = ["file1.ts", "file2.ts"];
|
|
336
|
+
const groups: WorkGroup[] = [
|
|
337
|
+
{
|
|
338
|
+
groupId: "group-1",
|
|
339
|
+
description: "test",
|
|
340
|
+
ownedPaths: ["file1.ts"],
|
|
341
|
+
isMechanical: false,
|
|
342
|
+
status: "completed",
|
|
343
|
+
},
|
|
344
|
+
];
|
|
345
|
+
|
|
346
|
+
const unowned = getUnownedFiles(allFiles, groups);
|
|
347
|
+
|
|
348
|
+
expect(unowned).toEqual(["file2.ts"]);
|
|
349
|
+
});
|
|
350
|
+
});
|