-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcompound-engineering.test.mjs
More file actions
235 lines (235 loc) · 10 KB
/
compound-engineering.test.mjs
File metadata and controls
235 lines (235 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import assert from "node:assert/strict";
import { rm } from "node:fs/promises";
import { join } from "node:path";
import { after, before, describe, test } from "node:test";
import CompoundEngineering from "../lib/compound-engineering.mjs";
describe("Compound Engineering", () => {
let compoundEngineering;
let testDir = "";
before(() => {
testDir = join(process.cwd(), "test-compound");
compoundEngineering = new CompoundEngineering({
workspace: join(testDir, "workspace"),
learningsPath: join(testDir, "learnings.json"),
verbose: false,
});
});
after(async () => {
try {
await rm(testDir, { recursive: true, force: true });
}
catch {
// ignore cleanup errors
}
});
test("should start a new session", async () => {
const session = await compoundEngineering.startSession("Test Project", "Build a new feature for user management");
assert.ok(session.id);
assert.equal(session.projectName, "Test Project");
assert.equal(session.objective, "Build a new feature for user management");
assert.equal(session.phase, "brainstorming");
assert.equal(session.phases.brainstorming.status, "active");
assert.ok(session.startTime);
});
test("should execute brainstorming phase", async () => {
await compoundEngineering.startSession("Test Project", "Test objective");
const brainstormResults = await compoundEngineering.brainstorm({
context: "Some context for brainstorming",
timeline: "2 weeks",
});
assert.ok(brainstormResults.ideas.length > 0);
assert.ok(brainstormResults.constraints.length > 0);
assert.ok(brainstormResults.assumptions.length > 0);
assert.ok(brainstormResults.risks.length > 0);
assert.ok(brainstormResults.opportunities.length > 0);
assert.ok(brainstormResults.constraints.some((constraint) => constraint.toLowerCase().includes("timeline")));
assert.ok(brainstormResults.timestamp);
});
test("should execute planning phase", async () => {
await compoundEngineering.startSession("Test Project", "Test objective");
const plan = await compoundEngineering.plan({
ideas: ["Idea 1", "Idea 2"],
constraints: ["Constraint 1"],
assumptions: ["Assumption 1"],
risks: ["Risk 1"],
opportunities: ["Opportunity 1"],
}, { timeline: "2 weeks", budget: "$1000" });
assert.ok(plan.objective);
assert.ok(plan.approach);
assert.ok(plan.steps);
assert.ok(plan.timeline);
assert.ok(plan.resources);
assert.ok(plan.risks);
assert.ok(plan.mitigations);
assert.ok(plan.successCriteria);
assert.ok(plan.decisions.length >= 2);
assert.ok(plan.resources.tools.length > 0);
assert.ok(plan.timeline.estimated.length > 0);
assert.ok(plan.timestamp);
});
test("should execute working phase", async () => {
await compoundEngineering.startSession("Test Project", "Test objective");
const plan = {
steps: [
{ description: "Step 1", estimatedTime: "30 minutes" },
{ description: "Step 2", estimatedTime: "1 hour" },
],
};
const workResults = await compoundEngineering.work(plan);
assert.ok(workResults.steps);
assert.equal(workResults.steps.length, 2);
assert.ok(workResults.issues);
assert.ok(workResults.solutions);
assert.ok(workResults.timestamp);
for (const step of workResults.steps) {
assert.ok(step.step);
assert.ok(step.status);
assert.ok(step.startTime);
assert.ok(step.endTime);
}
});
test("should execute reviewing phase", async () => {
await compoundEngineering.startSession("Test Project", "Test objective");
const workResults = {
steps: [
{
step: "Step 1",
status: "completed",
startTime: new Date().toISOString(),
issues: [],
solutions: [],
artifacts: [],
},
{
step: "Step 2",
status: "completed",
startTime: new Date().toISOString(),
issues: [],
solutions: [],
artifacts: [],
},
],
issues: [],
solutions: [],
};
const reviewResults = await compoundEngineering.review(workResults);
assert.ok(reviewResults.review);
assert.ok(reviewResults.learnings);
assert.ok(reviewResults.review.sessionId);
assert.ok(reviewResults.review.overallScore);
assert.ok(reviewResults.review.strengths);
assert.ok(reviewResults.review.weaknesses);
assert.ok(reviewResults.review.improvements);
assert.ok(reviewResults.review.recommendations);
});
test("should save and load learnings", async () => {
await compoundEngineering.startSession("Test Project", "Test objective");
const brainstormResults = await compoundEngineering.brainstorm();
const plan = await compoundEngineering.plan(brainstormResults);
const workResults = await compoundEngineering.work(plan);
await compoundEngineering.review(workResults);
await compoundEngineering.loadLearnings();
const allLearnings = compoundEngineering.getAllLearnings();
assert.ok(Array.isArray(allLearnings));
const searchResults = compoundEngineering.searchLearnings("test");
assert.ok(Array.isArray(searchResults));
});
test("should generate session IDs and learning IDs correctly", () => {
const sessionId1 = compoundEngineering.generateSessionId();
const sessionId2 = compoundEngineering.generateSessionId();
assert.notEqual(sessionId1, sessionId2);
assert.ok(sessionId1.startsWith("session_"));
assert.ok(sessionId2.startsWith("session_"));
const learningId1 = compoundEngineering.generateLearningId();
const learningId2 = compoundEngineering.generateLearningId();
assert.notEqual(learningId1, learningId2);
assert.ok(learningId1.startsWith("learning_"));
assert.ok(learningId2.startsWith("learning_"));
});
test("createExecutionSteps returns structured steps", () => {
const steps = compoundEngineering.createExecutionSteps({ description: "Build a test API integration" }, ["API contract must remain stable"]);
assert.ok(Array.isArray(steps));
assert.ok(steps.length > 0);
assert.ok(steps.some((step) => step.description.toLowerCase().includes("validate constraints")));
assert.ok(steps.some((step) => step.description.toLowerCase().includes("verification")));
for (const s of steps) {
assert.ok(s.description);
assert.ok(s.estimatedTime);
}
});
test("reviewPhase identifies weaknesses for shallow brainstorming output", () => {
const review = compoundEngineering.reviewPhase("brainstorming", {
ideas: [],
constraints: [],
assumptions: [],
risks: [],
opportunities: [],
timestamp: new Date().toISOString(),
});
assert.ok(review.weaknesses.length > 0);
assert.ok(review.improvements.length > 0);
});
test("should calculate process metrics correctly", () => {
const mockSession = {
id: "test-session",
projectName: "Test",
objective: "Objective",
phase: "reviewing",
startTime: "2024-01-01T10:00:00.000Z",
endTime: "2024-01-01T12:00:00.000Z",
phases: {
brainstorming: { status: "completed", startTime: "2024-01-01T10:00:00.000Z", endTime: "2024-01-01T10:30:00.000Z" },
planning: { status: "completed", startTime: "2024-01-01T10:30:00.000Z", endTime: "2024-01-01T11:00:00.000Z" },
working: { status: "completed", startTime: "2024-01-01T11:00:00.000Z", endTime: "2024-01-01T11:45:00.000Z" },
reviewing: { status: "completed", startTime: "2024-01-01T11:45:00.000Z", endTime: "2024-01-01T12:00:00.000Z" },
},
artifacts: {},
learnings: [],
decisions: [],
};
const metrics = compoundEngineering.calculateProcessMetrics(mockSession);
assert.ok(metrics.totalDuration);
const phaseDurations = metrics.phaseDurations;
assert.ok(phaseDurations.brainstorming);
assert.ok(phaseDurations.planning);
assert.ok(phaseDurations.working);
assert.ok(phaseDurations.reviewing);
});
test("should calculate outcome metrics correctly", () => {
const workResults = {
steps: [
{
step: "a",
status: "completed",
startTime: "x",
issues: [],
solutions: [],
artifacts: [],
},
{
step: "b",
status: "completed",
startTime: "x",
issues: [],
solutions: [],
artifacts: [],
},
{
step: "c",
status: "failed",
startTime: "x",
issues: [],
solutions: [],
artifacts: [],
},
],
issues: ["Issue 1", "Issue 2"],
solutions: ["Solution 1"],
timestamp: new Date().toISOString(),
};
const metrics = compoundEngineering.calculateOutcomeMetrics(workResults);
assert.equal(metrics.stepsCompleted, 2);
assert.equal(metrics.issuesEncountered, 2);
assert.equal(metrics.solutionsApplied, 1);
});
});