MCPcopy Create free account
hub / github.com/Houseofmvps/codesight / evalFixture

Function evalFixture

src/eval.ts:85–149  ·  view source on GitHub ↗
(fixturePath: string)

Source from the content-addressed store, hash-verified

83 const tmpDir = join(
84 (await import("node:os")).tmpdir(),
85 `codesight-eval-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
86 );
87
88 for (const [filePath, content] of Object.entries(fixture.files)) {
89 const fullPath = join(tmpDir, filePath);
90 await mkdir(dirname(fullPath), { recursive: true });
91 await writeFile(fullPath, content as string);
92 }
93
94 return tmpDir;
95}
96
97async function evalFixture(fixturePath: string): Promise<FixtureResult> {
98 const repoJson = JSON.parse(await readFile(join(fixturePath, "repo.json"), "utf-8"));
99 const groundTruth: GroundTruth = JSON.parse(
100 await readFile(join(fixturePath, "ground-truth.json"), "utf-8")
101 );
102
103 // Create temp repo from fixture
104 const tmpDir = await createTempRepo(repoJson);
105
106 const startTime = Date.now();
107
108 try {
109 // Run codesight detectors
110 const project = await detectProject(tmpDir);
111 const files = await collectFiles(tmpDir, 10);
112 const [routes, schemas, components, config, middleware, graph] = await Promise.all([
113 detectRoutes(files, project),
114 detectSchemas(files, project),
115 detectComponents(files, project),
116 detectConfig(files, project),
117 detectMiddleware(files, project),
118 detectDependencyGraph(files, project),
119 ]);
120
121 const runtime = Date.now() - startTime;
122
123 // Compare routes: method:path
124 const detectedRoutes = new Set(routes.map((r) => `${r.method}:${r.path}`));
125 const expectedRoutes = new Set((groundTruth.routes || []).map((r) => `${r.method}:${r.path}`));
126
127 // Compare models: name
128 const detectedModels = new Set(schemas.map((s) => s.name.toLowerCase()));
129 const expectedModels = new Set((groundTruth.models || []).map((m) => m.name.toLowerCase()));
130
131 // Compare env vars
132 const detectedEnvVars = new Set(config.envVars.map((e) => e.name));
133 const expectedEnvVars = new Set(groundTruth.envVars || []);
134
135 const result: FixtureResult = {
136 name: repoJson.name,
137 routes: calcMetrics(detectedRoutes, expectedRoutes),
138 models: calcMetrics(detectedModels, expectedModels),
139 envVars: calcMetrics(detectedEnvVars, expectedEnvVars),
140 runtime,
141 };
142

Callers 1

runEvalFromDirFunction · 0.85

Calls 10

joinFunction · 0.85
createTempRepoFunction · 0.85
detectProjectFunction · 0.85
collectFilesFunction · 0.85
detectRoutesFunction · 0.85
detectSchemasFunction · 0.85
detectComponentsFunction · 0.85
detectConfigFunction · 0.85
detectMiddlewareFunction · 0.85
calcMetricsFunction · 0.85

Tested by

no test coverage detected