Repository navigation
Expand file tree
/
Copy pathtest-graph-fields.js
More file actions
306 lines (268 loc) · 9.08 KB
/
Copy pathtest-graph-fields.js
File metadata and controls
306 lines (268 loc) · 9.08 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
/**
* Integration test for new graph and enriched tech stack fields
* Run with: doppler run -- node test-graph-fields.js
*/
import { PredevAPI } from "./predev-api-node/dist/index.js";
const API_KEY = process.env.PREDEV_API_KEY || "6308d5be-66a5-4b59-ac98-721c2902751f";
const BASE_URL = process.env.PREDEV_API_URL || "http://localhost:3001";
const client = new PredevAPI({ apiKey: API_KEY, baseUrl: BASE_URL });
console.log(`Using API at ${BASE_URL}`);
async function pollUntilComplete(specId, label, timeoutMs = 300000) {
const start = Date.now();
console.log(`\n⏳ [${label}] Polling spec ${specId}...`);
while (Date.now() - start < timeoutMs) {
const status = await client.getSpecStatus(specId);
if (status.status === "completed") {
console.log(
`✅ [${label}] Completed in ${((Date.now() - start) / 1000).toFixed(1)}s`
);
return status;
}
if (status.status === "failed") {
console.error(`❌ [${label}] Failed: ${status.errorMessage}`);
return status;
}
console.log(
` ${status.progress ?? 0}% - ${status.progressMessage ?? status.status}`
);
await new Promise((r) => setTimeout(r, 10000));
}
throw new Error(`[${label}] Timed out after ${timeoutMs / 1000}s`);
}
// Actual production vocabulary emitted by predev-agent formatSpecOutput.ts:
// passthrough of persisted node types plus the derivation ladder
// (main_system / external_system / containerType values / bare C1='system' /
// bare C2='container'). The old set (frontend/api-services/databases/
// external-services) was aspirational — no producer ever emitted it.
const VALID_ARCH_TYPES = new Set([
"main_system",
"external_system",
"system",
"container",
"frontend_web",
"frontend_mobile",
"backend_api",
"backend_worker",
"backend_auth",
"database",
"infrastructure_cache",
"infrastructure_queue",
"infrastructure_gateway",
"infrastructure_storage",
]);
function validateGraph(graph, label) {
if (!graph) {
console.log(` ⚠️ ${label}: missing`);
return false;
}
if (!Array.isArray(graph.nodes) || !Array.isArray(graph.edges)) {
console.log(` ❌ ${label}: nodes/edges not arrays`);
return false;
}
console.log(
` ✅ ${label}: ${graph.nodes.length} nodes, ${graph.edges.length} edges`
);
// Validate node shape
let nodeOk = true;
for (const n of graph.nodes) {
if (!n.id || !n.label) {
console.log(` ❌ Node missing id/label: ${JSON.stringify(n)}`);
nodeOk = false;
break;
}
}
if (nodeOk && graph.nodes.length > 0) {
const sample = graph.nodes[0];
console.log(
` Sample node: { id: "${sample.id}", label: "${sample.label}", type: "${sample.type ?? ""}", level: ${sample.level ?? "N/A"} }`
);
}
// Validate architecture graph specific: type categories and C1/C2 level
if (label === "architectureGraph") {
for (const n of graph.nodes) {
if (!VALID_ARCH_TYPES.has(n.type)) {
console.log(` ❌ Architecture node "${n.id}" has invalid type: "${n.type}" (expected one of: ${[...VALID_ARCH_TYPES].join(", ")})`);
nodeOk = false;
}
// Production emits level 'C1' | 'C2' on architecture nodes (the
// diagram levels); anything else is a projection regression.
if (n.level !== "C1" && n.level !== "C2") {
console.log(` ❌ Architecture node "${n.id}" has invalid level: ${JSON.stringify(n.level)} (expected "C1" or "C2")`);
nodeOk = false;
}
}
if (nodeOk) {
const types = [...new Set(graph.nodes.map(n => n.type))];
console.log(` ✅ Architecture types: ${types.join(", ")}`);
}
}
// Validate user flow graph specific: numeric levels. BFS roots (role
// nodes) are level 0; flows are 1+; nodes unreachable from any role are
// null — all three occur in production output.
if (label === "userFlowGraph") {
for (const n of graph.nodes) {
const validLevel = n.level === null || (typeof n.level === "number" && n.level >= 0);
if (!validLevel) {
console.log(` ❌ UserFlow node "${n.id}" has invalid level: ${JSON.stringify(n.level)} (expected number >= 0 or null)`);
nodeOk = false;
}
}
if (nodeOk) {
const levels = [...new Set(graph.nodes.map(n => n.level))].sort((a, b) => a - b);
console.log(` ✅ UserFlow levels: ${levels.join(", ")}`);
}
}
// Validate edge shape
let edgeOk = true;
for (const e of graph.edges) {
if (!e.source || !e.target) {
console.log(` ❌ Edge missing source/target: ${JSON.stringify(e)}`);
edgeOk = false;
break;
}
}
if (edgeOk && graph.edges.length > 0) {
const sample = graph.edges[0];
console.log(
` Sample edge: { source: "${sample.source}", target: "${sample.target}", edgeType: "${sample.edgeType ?? ""}" }`
);
}
// Verify no MongoDB internals leaked
for (const n of graph.nodes) {
if (n._id || n.graphId || n.projectId || n.created || n.action) {
console.log(` ❌ Node has MongoDB internals: ${Object.keys(n)}`);
return false;
}
}
for (const e of graph.edges) {
if (e._id || e.graphId || e.projectId || e.created || e.action) {
console.log(` ❌ Edge has MongoDB internals: ${Object.keys(e)}`);
return false;
}
}
console.log(` ✅ No MongoDB internals leaked`);
return nodeOk && edgeOk;
}
function validateTechStack(stack, label) {
if (!stack) {
console.log(` ⚠️ ${label}: missing`);
return false;
}
if (!Array.isArray(stack)) {
console.log(` ❌ ${label}: not an array`);
return false;
}
console.log(` ✅ ${label}: ${stack.length} items`);
let ok = true;
for (const item of stack) {
if (!item.name || !item.useFor || !item.reason || !item.description) {
console.log(
` ❌ Item missing required fields: ${JSON.stringify(item)}`
);
ok = false;
break;
}
}
if (ok && stack.length > 0) {
const sample = stack[0];
console.log(
` Sample: { name: "${sample.name}", useFor: "${sample.useFor}", reason: "${sample.reason?.substring(0, 60)}...", link: "${sample.link ?? "none"}" }`
);
if (sample.alternatives?.length > 0) {
console.log(
` Alternatives: ${sample.alternatives.map((a) => a.name).join(", ")}`
);
}
if (sample.helpfulLinks?.length > 0) {
console.log(` Helpful links: ${sample.helpfulLinks.length}`);
}
}
return ok;
}
function validateListSpecsOmitsGraphs(specs) {
let ok = true;
for (const spec of specs) {
if (spec.userFlowGraph || spec.architectureGraph || spec.enrichedTechStack) {
console.log(
` ❌ listSpecs returned graph fields for spec ${spec._id}`
);
ok = false;
}
}
if (ok) {
console.log(
` ✅ listSpecs correctly omits graph fields (checked ${specs.length} specs)`
);
}
return ok;
}
async function runTest(specType) {
console.log(`\n${"=".repeat(60)}`);
console.log(`🚀 Testing ${specType} with async mode`);
console.log("=".repeat(60));
// Submit async spec
const input = "Build a simple todo app with user authentication, task CRUD, and a dashboard";
let asyncResult;
if (specType === "fast_spec") {
asyncResult = await client.fastSpecAsync({ input });
} else {
asyncResult = await client.deepSpecAsync({ input });
}
console.log(`📝 Submitted: specId = ${asyncResult.specId}`);
// Poll until complete
const result = await pollUntilComplete(asyncResult.specId, specType);
if (result.status !== "completed") {
console.log(`\n❌ [${specType}] Spec did not complete, skipping validation`);
return false;
}
// Validate new fields
console.log(`\n📊 Validating new fields for ${specType}:`);
const ufOk = validateGraph(result.userFlowGraph, "userFlowGraph");
const archOk = validateGraph(result.architectureGraph, "architectureGraph");
const tsOk = validateTechStack(result.enrichedTechStack, "enrichedTechStack");
// Verify existing fields still present
const existingOk =
result.codingAgentSpecJson && result.humanSpecJson && result.predevUrl;
console.log(
` ${existingOk ? "✅" : "❌"} Existing fields still present (codingAgentSpecJson, humanSpecJson, predevUrl)`
);
const allOk = ufOk && archOk && tsOk && existingOk;
console.log(`\n${allOk ? "✅" : "❌"} [${specType}] ${allOk ? "PASSED" : "FAILED"}`);
return allOk;
}
async function main() {
console.log("🧪 Integration test: Graph & Enriched Tech Stack fields\n");
let allPassed = true;
// Test fast spec
try {
const fastOk = await runTest("fast_spec");
allPassed = allPassed && fastOk;
} catch (err) {
console.error("❌ fast_spec test error:", err.message);
allPassed = false;
}
// Test deep spec
try {
const deepOk = await runTest("deep_spec");
allPassed = allPassed && deepOk;
} catch (err) {
console.error("❌ deep_spec test error:", err.message);
allPassed = false;
}
// Test that listSpecs omits graph fields
console.log(`\n${"=".repeat(60)}`);
console.log("📋 Testing listSpecs omits graph fields");
console.log("=".repeat(60));
try {
const list = await client.listSpecs({ limit: 5, status: "completed" });
validateListSpecsOmitsGraphs(list.specs);
} catch (err) {
console.error("❌ listSpecs test error:", err.message);
allPassed = false;
}
console.log(`\n${"=".repeat(60)}`);
console.log(allPassed ? "✅ ALL TESTS PASSED" : "❌ SOME TESTS FAILED");
console.log("=".repeat(60));
process.exit(allPassed ? 0 : 1);
}
main();