-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-coverage-executor.ts
More file actions
240 lines (205 loc) · 10.8 KB
/
test-coverage-executor.ts
File metadata and controls
240 lines (205 loc) · 10.8 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
236
237
238
239
240
/// <reference no-default-lib="true"/>
/* eslint-disable */
/* tslint:disable */
// @ts-nocheck
declare function CC(prompt: string): string;
function main() {
console.log("=== CVM Test Coverage Executor Started ===");
// Base context prompt for every task
var contextPrompt = "CONTEXT: You are improving test coverage for CVM (Cognitive Virtual Machine). " +
"CVM is a custom interpreter that executes TypeScript-like programs and pauses at CC() calls. " +
"PROJECT STRUCTURE: Nx monorepo with packages: @cvm/parser, @cvm/types, @cvm/vm, @cvm/storage, @cvm/mcp-server. " +
"CURRENT MISSION: Implement comprehensive tests to increase coverage from current levels to 85%+. " +
"CRITICAL: Read the test plan at /home/laco/cvm/tasks/test-implementation-plan-precise.md for exact test specifications. " +
"The line numbers in each task refer to specific sections in this plan document. " +
"METHODOLOGY: This is NOT TDD - we are adding tests for existing code. Tests should pass when written correctly.";
console.log("Context prompt created");
console.log("Test plan document: /home/laco/cvm/tasks/test-implementation-plan-precise.md");
// Coverage context
var coverageContext = "CURRENT COVERAGE GAPS: " +
"1) heap-helpers.ts has 0% coverage - completely untested. " +
"2) unified.ts has 44% coverage - GET/SET operations poorly tested. " +
"3) storage package at 59% - missing error handling tests. " +
"4) types package at 56% - missing edge case tests. " +
"TARGET: Achieve 85%+ coverage across all packages. " +
"FOCUS: heap-helpers.ts and unified.ts are highest priority.";
// Common prompt parts
var fileOpsBase = " " + contextPrompt + " " + coverageContext + " Use Read, Write, Edit tools for file operations. Use Bash tool for running commands. ";
var submitDone = " Submit task with 'done' when complete.";
var submitTest = " Submit 'passed' if tests pass, 'failed' if they fail.";
var runTest = "Run tests using 'npx nx test' command with Bash tool. ";
var checkCoverage = "Check coverage using 'npx nx test --coverage' command. ";
console.log("Common prompts initialized");
// Track completed tasks
var completedTasks = [];
// Define all test implementation tasks with line references
var tasks = [
// PHASE 1: heap-helpers.ts Tests (45 minutes)
{
name: "Test Suite 1: dereferenceArray",
implement: "Create heap-helpers.spec.ts following plan lines 17-44. Add imports and dereferenceArray test suite with 3 tests.",
test: "Run tests for dereferenceArray suite.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/heap-helpers.spec.ts",
lines: "17-44"
},
{
name: "Test Suite 2: dereferenceObject",
implement: "Add dereferenceObject tests following plan lines 48-73. Add 3 tests for object dereferencing.",
test: "Run tests for dereferenceObject suite.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/heap-helpers.spec.ts",
lines: "48-73"
},
{
name: "Test Suite 3: resolveValue",
implement: "Add resolveValue tests following plan lines 77-104. Test primitives and reference resolution.",
test: "Run tests for resolveValue suite.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/heap-helpers.spec.ts",
lines: "77-104"
},
{
name: "Test Suite 4: sameReference",
implement: "Add sameReference tests following plan lines 108-132. Test reference equality checks.",
test: "Run tests for sameReference suite.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/heap-helpers.spec.ts",
lines: "108-132"
},
{
name: "Test Suite 5: deepCopyValue",
implement: "Add deepCopyValue tests following plan lines 136-238. Test deep copying of all types.",
test: "Run tests for deepCopyValue suite.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/heap-helpers.spec.ts",
lines: "136-238"
},
// PHASE 2: unified.ts GET Tests (1 hour)
{
name: "Test Suite 6: GET Error Cases",
implement: "Add GET error cases to unified-get-set.spec.ts following plan lines 248-318. Test invalid references and types.",
test: "Run tests for GET error cases.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/handlers/unified-get-set.spec.ts",
lines: "248-318"
},
{
name: "Test Suite 7: GET Edge Cases",
implement: "Add GET edge cases following plan lines 322-436. Test string indices, out of bounds, properties.",
test: "Run tests for GET edge cases.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/handlers/unified-get-set.spec.ts",
lines: "322-436"
},
// PHASE 3: unified.ts SET Tests (45 minutes)
{
name: "Test Suite 8: SET Error Cases",
implement: "Add SET error cases following plan lines 444-543. Test invalid references and non-indexable types.",
test: "Run tests for SET error cases.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/handlers/unified-get-set.spec.ts",
lines: "444-543"
},
{
name: "Test Suite 9: SET Edge Cases",
implement: "Add SET edge cases following plan lines 666-786. Test numeric strings, array expansion, properties.",
test: "Run tests for SET edge cases.",
expectFailure: false,
project: "vm",
file: "/home/laco/cvm/packages/vm/src/lib/handlers/unified-get-set.spec.ts",
lines: "666-786"
}
];
// Process all tasks
console.log("Starting test implementation. Total test suites: " + tasks.length);
var i = 0;
while (i < tasks.length) {
console.log("\n=== Test Suite " + (i + 1) + " of " + tasks.length + " ===");
var task = tasks[i];
var taskName = task["name"];
var taskImplement = task["implement"];
var taskTest = task["test"];
var taskProject = task["project"];
var taskFile = task["file"];
var taskLines = task["lines"];
console.log("Task: " + taskName);
console.log("File: " + taskFile);
console.log("Plan lines: " + taskLines);
// First, have Claude read the test plan section
var readPlanPrompt = "" + "[" + taskName + "]: " + fileOpsBase +
"Read the test plan section at lines " + taskLines + " in /home/laco/cvm/tasks/test-implementation-plan-precise.md. " +
"Then implement the tests exactly as specified. " + taskImplement +
" File: " + taskFile + submitDone;
CC(readPlanPrompt);
// Run the tests
console.log("Running tests for: " + taskName);
var testPrompt = "" + fileOpsBase + taskTest + " " + runTest + taskProject + " -- " + taskFile + submitTest;
var testResult = CC(testPrompt);
// Tests should pass since we're testing existing code
if (testResult == "failed") {
// Fix any issues
var attempts = 0;
while (testResult != "passed" && attempts < 3) {
console.log("Tests failing. Checking implementation...");
CC("" + fileOpsBase + "Debug why tests are failing. Check if test expectations match actual behavior. " +
"Read the actual implementation code to understand correct behavior. Fix tests to match reality. " +
"Remember: we are testing EXISTING code, not implementing new features." + submitDone);
testResult = CC("" + fileOpsBase + runTest + taskProject + " -- " + taskFile + submitTest);
attempts = attempts + 1;
}
}
completedTasks.push(taskName);
console.log("Completed: " + taskName);
i = i + 1;
}
// Phase 4: Coverage Verification
console.log("\n=== Phase 4: Coverage Verification ===");
// Check coverage for vm package
var vmCoverage = CC("" + fileOpsBase + checkCoverage + " for vm package. " +
"Report the coverage percentage for heap-helpers.ts and unified.ts specifically. " +
"Submit the coverage percentages.");
console.log("VM coverage results: " + vmCoverage);
// Create integration test if time permits
var integrationPrompt = "" + fileOpsBase +
"Create integration test following plan lines 797-843 at /home/laco/cvm/test/integration/heap-unified-integration.test.ts. " +
"Test complex nested structure manipulation." + submitDone;
CC(integrationPrompt);
// Final coverage report
console.log("\n=== Generating Final Coverage Report ===");
var coverageReport = CC("" + fileOpsBase +
"Generate coverage report for all packages. Run: " +
"1) npx nx run vm:test --coverage " +
"2) npx nx run parser:test --coverage " +
"3) npx nx run storage:test --coverage " +
"4) npx nx run types:test --coverage " +
"5) npx nx run mcp-server:test --coverage " +
"Create summary of improvements. Compare to original coverage in test-coverage-analysis.md. " +
"Save report as /home/laco/cvm/tmp/test-coverage-improvements.md" + submitDone);
// Commit all test improvements
CC("" + fileOpsBase + "Git add all test files and commit with message: " +
"'test(cvm): Add comprehensive tests for heap-helpers and unified operations' " +
"Include coverage improvements in commit message." + submitDone);
// Update Memory Bank
CC("" + fileOpsBase + "Update Memory Bank current-state.md with new test coverage percentages. " +
"Mark test improvement task as complete." + submitDone);
console.log("\n=== Test Coverage Implementation Complete! ===");
console.log("Completed test suites: " + completedTasks.length);
// Summary
var summary = "";
var j = 0;
while (j < completedTasks.length) {
summary = summary + completedTasks[j] + ", ";
j = j + 1;
}
return "Test Coverage Complete. Implemented: " + summary;
}
main();