|
| 1 | +-- Plan 2 slice 2.0 spike: graph-estimated coverage tiers on fixtures/minimal. |
| 2 | +-- Run: codemap query --json "$(cat scripts/spike-crap-reachability.sql)" --root fixtures/minimal |
| 3 | +-- Expected function/method tier counts: 85% → labyrinth (direct test ref); 40% → complexity-fixture peers (reachable); 0% → rest. |
| 4 | +WITH RECURSIVE |
| 5 | +test_files(path) AS ( |
| 6 | + SELECT DISTINCT f.path |
| 7 | + FROM files f |
| 8 | + WHERE EXISTS ( |
| 9 | + SELECT 1 |
| 10 | + FROM test_suites ts |
| 11 | + WHERE ts.file_path = f.path |
| 12 | + ) |
| 13 | + OR f.path GLOB '*.test.ts' |
| 14 | + OR f.path GLOB '*.test.tsx' |
| 15 | + OR f.path GLOB '*.spec.ts' |
| 16 | + OR f.path GLOB '*.spec.tsx' |
| 17 | + OR f.path GLOB '*.test.js' |
| 18 | + OR f.path GLOB '*.spec.js' |
| 19 | + OR f.path GLOB '*.test.jsx' |
| 20 | + OR f.path GLOB '*.spec.jsx' |
| 21 | +), |
| 22 | +reachable_files(file_path, depth, visited) AS ( |
| 23 | + SELECT path, 0, char(30) || path || char(30) |
| 24 | + FROM test_files |
| 25 | + UNION ALL |
| 26 | + SELECT |
| 27 | + d.to_path, |
| 28 | + rf.depth + 1, |
| 29 | + rf.visited || d.to_path || char(30) |
| 30 | + FROM dependencies d |
| 31 | + JOIN reachable_files rf ON d.from_path = rf.file_path |
| 32 | + WHERE rf.depth < 50 |
| 33 | + AND instr(rf.visited, char(30) || d.to_path || char(30)) = 0 |
| 34 | +), |
| 35 | +symbol_tiers AS ( |
| 36 | + SELECT |
| 37 | + s.name, |
| 38 | + s.file_path, |
| 39 | + s.complexity, |
| 40 | + CASE |
| 41 | + WHEN EXISTS ( |
| 42 | + SELECT 1 |
| 43 | + FROM "references" r |
| 44 | + JOIN bindings b ON b.reference_id = r.id |
| 45 | + JOIN test_files tf ON tf.path = r.file_path |
| 46 | + WHERE b.resolved_symbol_id = s.id |
| 47 | + ) |
| 48 | + OR EXISTS ( |
| 49 | + SELECT 1 |
| 50 | + FROM calls c2 |
| 51 | + JOIN test_files tf ON tf.path = c2.file_path |
| 52 | + WHERE c2.callee_symbol_id = s.id |
| 53 | + AND (c2.provenance IS NULL OR c2.provenance = 'ast') |
| 54 | + ) |
| 55 | + THEN 85 |
| 56 | + WHEN EXISTS ( |
| 57 | + SELECT 1 |
| 58 | + FROM reachable_files rf |
| 59 | + WHERE rf.file_path = s.file_path |
| 60 | + ) |
| 61 | + THEN 40 |
| 62 | + ELSE 0 |
| 63 | + END AS estimated_pct |
| 64 | + FROM symbols s |
| 65 | + WHERE s.complexity IS NOT NULL |
| 66 | + AND s.kind IN ('function', 'method') |
| 67 | +) |
| 68 | +SELECT estimated_pct, COUNT(*) AS symbol_count |
| 69 | +FROM symbol_tiers |
| 70 | +GROUP BY estimated_pct |
| 71 | +ORDER BY estimated_pct DESC |
0 commit comments