MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / main

Function main

scripts/agent-eval/probe-allocation.mjs:263–330  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

261}
262
263async function main() {
264 const spec = JSON.parse(readFileSync(SPEC_PATH, 'utf-8'));
265 const fixtures = spec.fixtures.filter((f) => wanted.length === 0 || wanted.includes(f.id));
266 if (fixtures.length === 0) {
267 console.error(`no fixture matched ${JSON.stringify(wanted)}; known: ${spec.fixtures.map((f) => f.id).join(', ')}`);
268 process.exit(2);
269 }
270
271 const dist = await loadDist();
272 const sidecarDir = mkdtempSync(join(tmpdir(), 'cg-alloc-diag-'));
273 const results = [];
274 const temps = [];
275
276 for (const fixture of fixtures) {
277 let repoPath;
278 if (fixture.kind === 'fixture') {
279 repoPath = await materializeFixture(dist, fixture.path);
280 temps.push(repoPath);
281 } else {
282 repoPath = resolve(REPO_ROOT, fixture.path);
283 if (!existsSync(join(repoPath, '.codegraph'))) {
284 console.error(`${fixture.id}: ${repoPath} has no .codegraph index — run \`codegraph init\` there first.`);
285 process.exit(2);
286 }
287 }
288
289 const sidecar = join(sidecarDir, `${fixture.id}.jsonl`);
290 mkdirSync(dirname(sidecar), { recursive: true });
291 const { report, text } = await runExplore(dist, repoPath, fixture.query, sidecar);
292 const evaluated = evaluate(fixture, report, text);
293 printReport(fixture, report, evaluated);
294 results.push({
295 id: fixture.id,
296 kind: fixture.kind,
297 query: fixture.query,
298 passed: evaluated.checks.every((c) => c.pass),
299 checks: evaluated.checks,
300 shares: {
301 delivered: Object.fromEntries(evaluated.delivered),
302 allocated: Object.fromEntries(evaluated.allocated),
303 },
304 envelope: report.envelope,
305 files: report.files.filter((f) => f.emittedChars > 0 || f.finalChars > 0),
306 });
307 }
308
309 if (!keepTemp) {
310 for (const dir of temps) rmSync(dir, { recursive: true, force: true });
311 rmSync(sidecarDir, { recursive: true, force: true });
312 } else {
313 say('');
314 say(` kept: ${[...temps, sidecarDir].join(' ')}`);
315 }
316
317 const allPassed = results.every((r) => r.passed);
318 if (asJson) {
319 console.log(JSON.stringify({ passed: allPassed, fixtures: results }, null, 2));
320 } else {

Callers 1

Calls 9

loadDistFunction · 0.85
materializeFixtureFunction · 0.85
runExploreFunction · 0.85
evaluateFunction · 0.85
printReportFunction · 0.85
errorMethod · 0.80
sayFunction · 0.70
resolveFunction · 0.50
joinMethod · 0.45

Tested by

no test coverage detected