@codeyam/codeyam-cli 0.1.0-staging.1a2737b → 0.1.0-staging.26dc674

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (770) hide show
  1. package/analyzer-template/.build-info.json +8 -8
  2. package/analyzer-template/log.txt +3 -3
  3. package/analyzer-template/package.json +12 -12
  4. package/analyzer-template/packages/ai/package.json +3 -3
  5. package/analyzer-template/packages/ai/src/lib/astScopes/astScopeAnalyzer.ts +34 -3
  6. package/analyzer-template/packages/ai/src/lib/completionCall.ts +114 -113
  7. package/analyzer-template/packages/ai/src/lib/dataStructure/ScopeDataStructure.ts +32 -1
  8. package/analyzer-template/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.ts +62 -0
  9. package/analyzer-template/packages/ai/src/lib/generateEntityScenarioData.ts +78 -2
  10. package/analyzer-template/packages/ai/src/lib/generateExecutionFlows.ts +0 -33
  11. package/analyzer-template/packages/analyze/src/lib/ProjectAnalyzer.ts +19 -7
  12. package/analyzer-template/packages/analyze/src/lib/asts/index.ts +7 -2
  13. package/analyzer-template/packages/analyze/src/lib/files/analyze/analyzeEntities.ts +9 -1
  14. package/analyzer-template/packages/analyze/src/lib/files/analyze/dependencyResolver.ts +0 -6
  15. package/analyzer-template/packages/analyze/src/lib/files/analyze/findOrCreateEntity.ts +22 -6
  16. package/analyzer-template/packages/analyze/src/lib/files/analyze/gatherEntityMap.ts +9 -12
  17. package/analyzer-template/packages/analyze/src/lib/files/analyzeChange.ts +4 -0
  18. package/analyzer-template/packages/analyze/src/lib/files/analyzeInitial.ts +4 -0
  19. package/analyzer-template/packages/analyze/src/lib/files/scenarios/TransformationTracer.ts +65 -28
  20. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateDataStructure.ts +83 -0
  21. package/analyzer-template/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.ts +0 -98
  22. package/analyzer-template/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.ts +23 -4
  23. package/analyzer-template/packages/aws/package.json +2 -2
  24. package/analyzer-template/packages/database/index.ts +1 -0
  25. package/analyzer-template/packages/database/package.json +4 -4
  26. package/analyzer-template/packages/database/src/lib/kysely/db.ts +8 -0
  27. package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +164 -0
  28. package/analyzer-template/packages/database/src/lib/loadAnalysis.ts +19 -15
  29. package/analyzer-template/packages/database/src/lib/loadCommits.ts +31 -20
  30. package/analyzer-template/packages/database/src/lib/loadEntities.ts +0 -6
  31. package/analyzer-template/packages/database/src/lib/loadEntity.ts +19 -8
  32. package/analyzer-template/packages/database/src/lib/loadReadyToBeCapturedAnalyses.ts +0 -5
  33. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +94 -143
  34. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatus.ts +58 -42
  35. package/analyzer-template/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.ts +81 -65
  36. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.ts +29 -1
  37. package/analyzer-template/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.ts +33 -5
  38. package/analyzer-template/packages/github/dist/database/index.d.ts +1 -0
  39. package/analyzer-template/packages/github/dist/database/index.d.ts.map +1 -1
  40. package/analyzer-template/packages/github/dist/database/index.js +1 -0
  41. package/analyzer-template/packages/github/dist/database/index.js.map +1 -1
  42. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts +2 -0
  43. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.d.ts.map +1 -1
  44. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js +5 -0
  45. package/analyzer-template/packages/github/dist/database/src/lib/kysely/db.js.map +1 -1
  46. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +29 -0
  47. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -0
  48. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +149 -0
  49. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  50. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts +5 -0
  51. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/scenariosTable.d.ts.map +1 -1
  52. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.d.ts.map +1 -1
  53. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js +1 -1
  54. package/analyzer-template/packages/github/dist/database/src/lib/loadAnalysis.js.map +1 -1
  55. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.d.ts.map +1 -1
  56. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js +23 -13
  57. package/analyzer-template/packages/github/dist/database/src/lib/loadCommits.js.map +1 -1
  58. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  59. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +0 -6
  60. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  61. package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.d.ts +4 -1
  62. package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.d.ts.map +1 -1
  63. package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.js +5 -5
  64. package/analyzer-template/packages/github/dist/database/src/lib/loadEntity.js.map +1 -1
  65. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.d.ts.map +1 -1
  66. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  67. package/analyzer-template/packages/github/dist/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  68. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  69. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +76 -90
  70. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  71. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.d.ts.map +1 -1
  72. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  73. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  74. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.d.ts.map +1 -1
  75. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  76. package/analyzer-template/packages/github/dist/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  77. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.d.ts.map +1 -1
  78. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  79. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  80. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.d.ts.map +1 -1
  81. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  82. package/analyzer-template/packages/github/dist/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  83. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.d.ts +2 -0
  84. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.d.ts.map +1 -1
  85. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.js +2 -0
  86. package/analyzer-template/packages/github/dist/types/src/enums/ProjectFramework.js.map +1 -1
  87. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts +1 -0
  88. package/analyzer-template/packages/github/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  89. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts +10 -0
  90. package/analyzer-template/packages/github/dist/types/src/types/Scenario.d.ts.map +1 -1
  91. package/analyzer-template/packages/github/package.json +1 -1
  92. package/analyzer-template/packages/types/src/enums/ProjectFramework.ts +2 -0
  93. package/analyzer-template/packages/types/src/types/ProjectMetadata.ts +1 -0
  94. package/analyzer-template/packages/types/src/types/Scenario.ts +10 -0
  95. package/analyzer-template/packages/ui-components/package.json +1 -1
  96. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.d.ts +2 -0
  97. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.d.ts.map +1 -1
  98. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.js +2 -0
  99. package/analyzer-template/packages/utils/dist/types/src/enums/ProjectFramework.js.map +1 -1
  100. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts +1 -0
  101. package/analyzer-template/packages/utils/dist/types/src/types/ProjectMetadata.d.ts.map +1 -1
  102. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts +10 -0
  103. package/analyzer-template/packages/utils/dist/types/src/types/Scenario.d.ts.map +1 -1
  104. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts +3 -1
  105. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.d.ts.map +1 -1
  106. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js +28 -3
  107. package/analyzer-template/packages/utils/dist/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  108. package/analyzer-template/packages/utils/src/lib/fs/rsyncCopy.ts +41 -2
  109. package/analyzer-template/playwright/captureFromUrl.ts +89 -82
  110. package/analyzer-template/project/analyzeFileEntities.ts +26 -0
  111. package/analyzer-template/project/constructMockCode.ts +136 -43
  112. package/analyzer-template/project/reconcileMockDataKeys.ts +19 -14
  113. package/analyzer-template/project/start.ts +3 -0
  114. package/analyzer-template/project/startScenarioCapture.ts +9 -0
  115. package/analyzer-template/project/writeClientLogRoute.ts +125 -0
  116. package/analyzer-template/project/writeMockDataTsx.ts +17 -0
  117. package/analyzer-template/project/writeScenarioComponents.ts +36 -7
  118. package/analyzer-template/tsconfig.json +13 -1
  119. package/background/src/lib/virtualized/project/analyzeFileEntities.js +22 -0
  120. package/background/src/lib/virtualized/project/analyzeFileEntities.js.map +1 -1
  121. package/background/src/lib/virtualized/project/constructMockCode.js +115 -34
  122. package/background/src/lib/virtualized/project/constructMockCode.js.map +1 -1
  123. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js +17 -11
  124. package/background/src/lib/virtualized/project/reconcileMockDataKeys.js.map +1 -1
  125. package/background/src/lib/virtualized/project/start.js +2 -0
  126. package/background/src/lib/virtualized/project/start.js.map +1 -1
  127. package/background/src/lib/virtualized/project/startScenarioCapture.js +5 -0
  128. package/background/src/lib/virtualized/project/startScenarioCapture.js.map +1 -1
  129. package/background/src/lib/virtualized/project/writeClientLogRoute.js +110 -0
  130. package/background/src/lib/virtualized/project/writeClientLogRoute.js.map +1 -0
  131. package/background/src/lib/virtualized/project/writeMockDataTsx.js +12 -0
  132. package/background/src/lib/virtualized/project/writeMockDataTsx.js.map +1 -1
  133. package/background/src/lib/virtualized/project/writeScenarioComponents.js +29 -7
  134. package/background/src/lib/virtualized/project/writeScenarioComponents.js.map +1 -1
  135. package/codeyam-cli/scripts/apply-setup.js +208 -11
  136. package/codeyam-cli/scripts/apply-setup.js.map +1 -1
  137. package/codeyam-cli/src/__tests__/memory-scripts/filter-session.test.js +196 -0
  138. package/codeyam-cli/src/__tests__/memory-scripts/filter-session.test.js.map +1 -0
  139. package/codeyam-cli/src/__tests__/memory-scripts/read-json-field.test.js +114 -0
  140. package/codeyam-cli/src/__tests__/memory-scripts/read-json-field.test.js.map +1 -0
  141. package/codeyam-cli/src/__tests__/memory-scripts/ripgrep-fallback.test.js +149 -0
  142. package/codeyam-cli/src/__tests__/memory-scripts/ripgrep-fallback.test.js.map +1 -0
  143. package/codeyam-cli/src/cli.js +33 -12
  144. package/codeyam-cli/src/cli.js.map +1 -1
  145. package/codeyam-cli/src/commands/__tests__/editor.isolateArgs.test.js +51 -0
  146. package/codeyam-cli/src/commands/__tests__/editor.isolateArgs.test.js.map +1 -0
  147. package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js +56 -0
  148. package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js.map +1 -0
  149. package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js +101 -47
  150. package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js.map +1 -1
  151. package/codeyam-cli/src/commands/analyze.js +17 -7
  152. package/codeyam-cli/src/commands/analyze.js.map +1 -1
  153. package/codeyam-cli/src/commands/default.js +14 -2
  154. package/codeyam-cli/src/commands/default.js.map +1 -1
  155. package/codeyam-cli/src/commands/editor.js +5206 -0
  156. package/codeyam-cli/src/commands/editor.js.map +1 -0
  157. package/codeyam-cli/src/commands/editorIsolateArgs.js +25 -0
  158. package/codeyam-cli/src/commands/editorIsolateArgs.js.map +1 -0
  159. package/codeyam-cli/src/commands/init.js +109 -45
  160. package/codeyam-cli/src/commands/init.js.map +1 -1
  161. package/codeyam-cli/src/commands/memory.js +29 -58
  162. package/codeyam-cli/src/commands/memory.js.map +1 -1
  163. package/codeyam-cli/src/commands/telemetry.js +37 -0
  164. package/codeyam-cli/src/commands/telemetry.js.map +1 -0
  165. package/codeyam-cli/src/data/techStacks.js +77 -0
  166. package/codeyam-cli/src/data/techStacks.js.map +1 -0
  167. package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js +173 -0
  168. package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js.map +1 -0
  169. package/codeyam-cli/src/utils/__tests__/backgroundServer.test.js +46 -0
  170. package/codeyam-cli/src/utils/__tests__/backgroundServer.test.js.map +1 -0
  171. package/codeyam-cli/src/utils/__tests__/devServerState.test.js +134 -0
  172. package/codeyam-cli/src/utils/__tests__/devServerState.test.js.map +1 -0
  173. package/codeyam-cli/src/utils/__tests__/editorApi.test.js +137 -0
  174. package/codeyam-cli/src/utils/__tests__/editorApi.test.js.map +1 -0
  175. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +3559 -0
  176. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -0
  177. package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js +76 -0
  178. package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js.map +1 -0
  179. package/codeyam-cli/src/utils/__tests__/editorCapture.test.js +93 -0
  180. package/codeyam-cli/src/utils/__tests__/editorCapture.test.js.map +1 -0
  181. package/codeyam-cli/src/utils/__tests__/editorCaptureScenarioSeeding.test.js +137 -0
  182. package/codeyam-cli/src/utils/__tests__/editorCaptureScenarioSeeding.test.js.map +1 -0
  183. package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js +100 -0
  184. package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js.map +1 -0
  185. package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js +304 -0
  186. package/codeyam-cli/src/utils/__tests__/editorDevServer.test.js.map +1 -0
  187. package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js +194 -0
  188. package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js.map +1 -0
  189. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js +381 -0
  190. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js.map +1 -0
  191. package/codeyam-cli/src/utils/__tests__/editorGuardMiddleware.test.js +67 -0
  192. package/codeyam-cli/src/utils/__tests__/editorGuardMiddleware.test.js.map +1 -0
  193. package/codeyam-cli/src/utils/__tests__/editorImageVerifier.test.js +294 -0
  194. package/codeyam-cli/src/utils/__tests__/editorImageVerifier.test.js.map +1 -0
  195. package/codeyam-cli/src/utils/__tests__/editorJournal.test.js +542 -0
  196. package/codeyam-cli/src/utils/__tests__/editorJournal.test.js.map +1 -0
  197. package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js +594 -0
  198. package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js.map +1 -0
  199. package/codeyam-cli/src/utils/__tests__/editorMigration.test.js +435 -0
  200. package/codeyam-cli/src/utils/__tests__/editorMigration.test.js.map +1 -0
  201. package/codeyam-cli/src/utils/__tests__/editorMockState.test.js +270 -0
  202. package/codeyam-cli/src/utils/__tests__/editorMockState.test.js.map +1 -0
  203. package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js +217 -0
  204. package/codeyam-cli/src/utils/__tests__/editorPreloadHelpers.test.js.map +1 -0
  205. package/codeyam-cli/src/utils/__tests__/editorPreview.test.js +353 -0
  206. package/codeyam-cli/src/utils/__tests__/editorPreview.test.js.map +1 -0
  207. package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js +153 -0
  208. package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js.map +1 -0
  209. package/codeyam-cli/src/utils/__tests__/editorScenarioLookup.test.js +139 -0
  210. package/codeyam-cli/src/utils/__tests__/editorScenarioLookup.test.js.map +1 -0
  211. package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js +291 -0
  212. package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js.map +1 -0
  213. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js +1629 -0
  214. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -0
  215. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js +280 -0
  216. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js.map +1 -0
  217. package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js +143 -0
  218. package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js.map +1 -0
  219. package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js +66 -0
  220. package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js.map +1 -0
  221. package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js +53 -0
  222. package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js.map +1 -0
  223. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js +2089 -0
  224. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js.map +1 -0
  225. package/codeyam-cli/src/utils/__tests__/git.editor.test.js +134 -0
  226. package/codeyam-cli/src/utils/__tests__/git.editor.test.js.map +1 -0
  227. package/codeyam-cli/src/utils/__tests__/glossaryAdd.test.js +177 -0
  228. package/codeyam-cli/src/utils/__tests__/glossaryAdd.test.js.map +1 -0
  229. package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js +122 -0
  230. package/codeyam-cli/src/utils/__tests__/journalCaptureStabilization.test.js.map +1 -0
  231. package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js +6 -0
  232. package/codeyam-cli/src/utils/__tests__/npmVersionCheck.test.js.map +1 -1
  233. package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js +129 -0
  234. package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js.map +1 -0
  235. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js +9 -0
  236. package/codeyam-cli/src/utils/__tests__/pathIgnoring.test.js.map +1 -1
  237. package/codeyam-cli/src/utils/__tests__/project.test.js +65 -0
  238. package/codeyam-cli/src/utils/__tests__/project.test.js.map +1 -0
  239. package/codeyam-cli/src/utils/__tests__/registerScenarioResult.test.js +127 -0
  240. package/codeyam-cli/src/utils/__tests__/registerScenarioResult.test.js.map +1 -0
  241. package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js +118 -0
  242. package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js.map +1 -0
  243. package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js +284 -0
  244. package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js.map +1 -0
  245. package/codeyam-cli/src/utils/__tests__/scenarioMarkers.test.js +121 -0
  246. package/codeyam-cli/src/utils/__tests__/scenarioMarkers.test.js.map +1 -0
  247. package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js +672 -0
  248. package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js.map +1 -0
  249. package/codeyam-cli/src/utils/__tests__/screenshotHash.test.js +84 -0
  250. package/codeyam-cli/src/utils/__tests__/screenshotHash.test.js.map +1 -0
  251. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +51 -4
  252. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  253. package/codeyam-cli/src/utils/__tests__/telemetry.test.js +159 -0
  254. package/codeyam-cli/src/utils/__tests__/telemetry.test.js.map +1 -0
  255. package/codeyam-cli/src/utils/__tests__/templateConsistency.test.js +51 -0
  256. package/codeyam-cli/src/utils/__tests__/templateConsistency.test.js.map +1 -0
  257. package/codeyam-cli/src/utils/__tests__/webappDetection.test.js +142 -0
  258. package/codeyam-cli/src/utils/__tests__/webappDetection.test.js.map +1 -0
  259. package/codeyam-cli/src/utils/analysisRunner.js +11 -7
  260. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  261. package/codeyam-cli/src/utils/analyzer.js +17 -0
  262. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  263. package/codeyam-cli/src/utils/analyzerFinalization.js +100 -0
  264. package/codeyam-cli/src/utils/analyzerFinalization.js.map +1 -0
  265. package/codeyam-cli/src/utils/backgroundServer.js +105 -13
  266. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  267. package/codeyam-cli/src/utils/buildFlags.js +4 -0
  268. package/codeyam-cli/src/utils/buildFlags.js.map +1 -0
  269. package/codeyam-cli/src/utils/database.js +37 -2
  270. package/codeyam-cli/src/utils/database.js.map +1 -1
  271. package/codeyam-cli/src/utils/devModeEvents.js +40 -0
  272. package/codeyam-cli/src/utils/devModeEvents.js.map +1 -0
  273. package/codeyam-cli/src/utils/devServerState.js +71 -0
  274. package/codeyam-cli/src/utils/devServerState.js.map +1 -0
  275. package/codeyam-cli/src/utils/editorApi.js +79 -0
  276. package/codeyam-cli/src/utils/editorApi.js.map +1 -0
  277. package/codeyam-cli/src/utils/editorAudit.js +696 -0
  278. package/codeyam-cli/src/utils/editorAudit.js.map +1 -0
  279. package/codeyam-cli/src/utils/editorBroadcastViewport.js +26 -0
  280. package/codeyam-cli/src/utils/editorBroadcastViewport.js.map +1 -0
  281. package/codeyam-cli/src/utils/editorCapture.js +102 -0
  282. package/codeyam-cli/src/utils/editorCapture.js.map +1 -0
  283. package/codeyam-cli/src/utils/editorDeleteScenario.js +67 -0
  284. package/codeyam-cli/src/utils/editorDeleteScenario.js.map +1 -0
  285. package/codeyam-cli/src/utils/editorDevServer.js +197 -0
  286. package/codeyam-cli/src/utils/editorDevServer.js.map +1 -0
  287. package/codeyam-cli/src/utils/editorEntityChangeStatus.js +50 -0
  288. package/codeyam-cli/src/utils/editorEntityChangeStatus.js.map +1 -0
  289. package/codeyam-cli/src/utils/editorEntityHelpers.js +144 -0
  290. package/codeyam-cli/src/utils/editorEntityHelpers.js.map +1 -0
  291. package/codeyam-cli/src/utils/editorGuard.js +36 -0
  292. package/codeyam-cli/src/utils/editorGuard.js.map +1 -0
  293. package/codeyam-cli/src/utils/editorImageVerifier.js +155 -0
  294. package/codeyam-cli/src/utils/editorImageVerifier.js.map +1 -0
  295. package/codeyam-cli/src/utils/editorJournal.js +225 -0
  296. package/codeyam-cli/src/utils/editorJournal.js.map +1 -0
  297. package/codeyam-cli/src/utils/editorLoaderHelpers.js +152 -0
  298. package/codeyam-cli/src/utils/editorLoaderHelpers.js.map +1 -0
  299. package/codeyam-cli/src/utils/editorMigration.js +224 -0
  300. package/codeyam-cli/src/utils/editorMigration.js.map +1 -0
  301. package/codeyam-cli/src/utils/editorMockState.js +248 -0
  302. package/codeyam-cli/src/utils/editorMockState.js.map +1 -0
  303. package/codeyam-cli/src/utils/editorPreloadHelpers.js +135 -0
  304. package/codeyam-cli/src/utils/editorPreloadHelpers.js.map +1 -0
  305. package/codeyam-cli/src/utils/editorPreview.js +137 -0
  306. package/codeyam-cli/src/utils/editorPreview.js.map +1 -0
  307. package/codeyam-cli/src/utils/editorRecapture.js +109 -0
  308. package/codeyam-cli/src/utils/editorRecapture.js.map +1 -0
  309. package/codeyam-cli/src/utils/editorScenarioSwitch.js +134 -0
  310. package/codeyam-cli/src/utils/editorScenarioSwitch.js.map +1 -0
  311. package/codeyam-cli/src/utils/editorScenarios.js +616 -0
  312. package/codeyam-cli/src/utils/editorScenarios.js.map +1 -0
  313. package/codeyam-cli/src/utils/editorSeedAdapter.js +422 -0
  314. package/codeyam-cli/src/utils/editorSeedAdapter.js.map +1 -0
  315. package/codeyam-cli/src/utils/editorShouldRevalidate.js +21 -0
  316. package/codeyam-cli/src/utils/editorShouldRevalidate.js.map +1 -0
  317. package/codeyam-cli/src/utils/entityChangeStatus.js +394 -0
  318. package/codeyam-cli/src/utils/entityChangeStatus.js.map +1 -0
  319. package/codeyam-cli/src/utils/entityChangeStatus.server.js +196 -0
  320. package/codeyam-cli/src/utils/entityChangeStatus.server.js.map +1 -0
  321. package/codeyam-cli/src/utils/fileMetadata.js +5 -0
  322. package/codeyam-cli/src/utils/fileMetadata.js.map +1 -1
  323. package/codeyam-cli/src/utils/fileWatcher.js +63 -9
  324. package/codeyam-cli/src/utils/fileWatcher.js.map +1 -1
  325. package/codeyam-cli/src/utils/git.js +103 -0
  326. package/codeyam-cli/src/utils/git.js.map +1 -1
  327. package/codeyam-cli/src/utils/glossaryAdd.js +74 -0
  328. package/codeyam-cli/src/utils/glossaryAdd.js.map +1 -0
  329. package/codeyam-cli/src/utils/install-skills.js +71 -15
  330. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  331. package/codeyam-cli/src/utils/interactiveSyncWatcher.js +126 -0
  332. package/codeyam-cli/src/utils/interactiveSyncWatcher.js.map +1 -0
  333. package/codeyam-cli/src/utils/npmVersionCheck.js +2 -2
  334. package/codeyam-cli/src/utils/npmVersionCheck.js.map +1 -1
  335. package/codeyam-cli/src/utils/parseRegisterArg.js +31 -0
  336. package/codeyam-cli/src/utils/parseRegisterArg.js.map +1 -0
  337. package/codeyam-cli/src/utils/pathIgnoring.js +19 -7
  338. package/codeyam-cli/src/utils/pathIgnoring.js.map +1 -1
  339. package/codeyam-cli/src/utils/progress.js +2 -2
  340. package/codeyam-cli/src/utils/progress.js.map +1 -1
  341. package/codeyam-cli/src/utils/project.js +15 -5
  342. package/codeyam-cli/src/utils/project.js.map +1 -1
  343. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js +11 -11
  344. package/codeyam-cli/src/utils/queue/__tests__/heartbeat.test.js.map +1 -1
  345. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js +22 -0
  346. package/codeyam-cli/src/utils/queue/__tests__/manager.test.js.map +1 -1
  347. package/codeyam-cli/src/utils/queue/heartbeat.js +13 -5
  348. package/codeyam-cli/src/utils/queue/heartbeat.js.map +1 -1
  349. package/codeyam-cli/src/utils/queue/job.js +76 -4
  350. package/codeyam-cli/src/utils/queue/job.js.map +1 -1
  351. package/codeyam-cli/src/utils/queue/manager.js +7 -6
  352. package/codeyam-cli/src/utils/queue/manager.js.map +1 -1
  353. package/codeyam-cli/src/utils/registerScenarioResult.js +52 -0
  354. package/codeyam-cli/src/utils/registerScenarioResult.js.map +1 -0
  355. package/codeyam-cli/src/utils/requireSimulations.js +1 -1
  356. package/codeyam-cli/src/utils/requireSimulations.js.map +1 -1
  357. package/codeyam-cli/src/utils/routePatternMatching.js +129 -0
  358. package/codeyam-cli/src/utils/routePatternMatching.js.map +1 -0
  359. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js +5 -6
  360. package/codeyam-cli/src/utils/ruleReflection/__tests__/contextBuilder.test.js.map +1 -1
  361. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js +2 -5
  362. package/codeyam-cli/src/utils/ruleReflection/__tests__/promptBuilder.test.js.map +1 -1
  363. package/codeyam-cli/src/utils/rules/__tests__/parser.test.js +83 -0
  364. package/codeyam-cli/src/utils/rules/__tests__/parser.test.js.map +1 -0
  365. package/codeyam-cli/src/utils/rules/__tests__/pathMatcher.test.js +118 -0
  366. package/codeyam-cli/src/utils/rules/__tests__/pathMatcher.test.js.map +1 -0
  367. package/codeyam-cli/src/utils/rules/__tests__/rulePlacement.test.js +72 -0
  368. package/codeyam-cli/src/utils/rules/__tests__/rulePlacement.test.js.map +1 -0
  369. package/codeyam-cli/src/utils/rules/__tests__/sourceFiles.test.js +76 -0
  370. package/codeyam-cli/src/utils/rules/__tests__/sourceFiles.test.js.map +1 -0
  371. package/codeyam-cli/src/utils/rules/index.js +1 -0
  372. package/codeyam-cli/src/utils/rules/index.js.map +1 -1
  373. package/codeyam-cli/src/utils/rules/parser.js +14 -4
  374. package/codeyam-cli/src/utils/rules/parser.js.map +1 -1
  375. package/codeyam-cli/src/utils/rules/pathMatcher.js +34 -3
  376. package/codeyam-cli/src/utils/rules/pathMatcher.js.map +1 -1
  377. package/codeyam-cli/src/utils/rules/rulePlacement.js +65 -0
  378. package/codeyam-cli/src/utils/rules/rulePlacement.js.map +1 -0
  379. package/codeyam-cli/src/utils/rules/sourceFiles.js +43 -0
  380. package/codeyam-cli/src/utils/rules/sourceFiles.js.map +1 -0
  381. package/codeyam-cli/src/utils/scenarioCoverage.js +77 -0
  382. package/codeyam-cli/src/utils/scenarioCoverage.js.map +1 -0
  383. package/codeyam-cli/src/utils/scenarioMarkers.js +134 -0
  384. package/codeyam-cli/src/utils/scenarioMarkers.js.map +1 -0
  385. package/codeyam-cli/src/utils/scenariosManifest.js +307 -0
  386. package/codeyam-cli/src/utils/scenariosManifest.js.map +1 -0
  387. package/codeyam-cli/src/utils/screenshotHash.js +26 -0
  388. package/codeyam-cli/src/utils/screenshotHash.js.map +1 -0
  389. package/codeyam-cli/src/utils/serverState.js +57 -2
  390. package/codeyam-cli/src/utils/serverState.js.map +1 -1
  391. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +83 -11
  392. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  393. package/codeyam-cli/src/utils/simulationGateMiddleware.js +80 -43
  394. package/codeyam-cli/src/utils/simulationGateMiddleware.js.map +1 -1
  395. package/codeyam-cli/src/utils/slugUtils.js +25 -0
  396. package/codeyam-cli/src/utils/slugUtils.js.map +1 -0
  397. package/codeyam-cli/src/utils/syncMocksMiddleware.js +2 -2
  398. package/codeyam-cli/src/utils/syncMocksMiddleware.js.map +1 -1
  399. package/codeyam-cli/src/utils/telemetry.js +106 -0
  400. package/codeyam-cli/src/utils/telemetry.js.map +1 -0
  401. package/codeyam-cli/src/utils/telemetryMiddleware.js +22 -0
  402. package/codeyam-cli/src/utils/telemetryMiddleware.js.map +1 -0
  403. package/codeyam-cli/src/utils/testRunner.js +158 -0
  404. package/codeyam-cli/src/utils/testRunner.js.map +1 -0
  405. package/codeyam-cli/src/utils/transcriptPruning.js +67 -0
  406. package/codeyam-cli/src/utils/transcriptPruning.js.map +1 -0
  407. package/codeyam-cli/src/utils/versionInfo.js +21 -0
  408. package/codeyam-cli/src/utils/versionInfo.js.map +1 -1
  409. package/codeyam-cli/src/utils/webappDetection.js +35 -2
  410. package/codeyam-cli/src/utils/webappDetection.js.map +1 -1
  411. package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js +35 -0
  412. package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js.map +1 -0
  413. package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js +107 -0
  414. package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js.map +1 -0
  415. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js +628 -0
  416. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js.map +1 -0
  417. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js +248 -0
  418. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js.map +1 -0
  419. package/codeyam-cli/src/webserver/__tests__/stripClaudeCommand.test.js +135 -0
  420. package/codeyam-cli/src/webserver/__tests__/stripClaudeCommand.test.js.map +1 -0
  421. package/codeyam-cli/src/webserver/app/lib/clientErrors.js +86 -0
  422. package/codeyam-cli/src/webserver/app/lib/clientErrors.js.map +1 -0
  423. package/codeyam-cli/src/webserver/app/lib/database.js +41 -27
  424. package/codeyam-cli/src/webserver/app/lib/database.js.map +1 -1
  425. package/codeyam-cli/src/webserver/app/lib/dbNotifier.js.map +1 -1
  426. package/codeyam-cli/src/webserver/app/lib/git.js +397 -0
  427. package/codeyam-cli/src/webserver/app/lib/git.js.map +1 -0
  428. package/codeyam-cli/src/webserver/app/types/editor.js +8 -0
  429. package/codeyam-cli/src/webserver/app/types/editor.js.map +1 -0
  430. package/codeyam-cli/src/webserver/backgroundServer.js +141 -42
  431. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  432. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CLe80MMu.js +1 -0
  433. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-bwuHPyTa.js → EntityItem-Crt_KN_U.js} +5 -5
  434. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-CQgyEGV-.js +1 -0
  435. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-BH0XDim7.js → EntityTypeIcon-CD7lGABo.js} +9 -9
  436. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-CgTNOhnu.js +1 -0
  437. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-CKeQT5Ty.js +25 -0
  438. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-D3s1MFkb.js +3 -0
  439. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-BvMu2i-g.js → LoadingDots-By5zI316.js} +1 -1
  440. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-kgBTLoJD.js → LogViewer-CM5zg40N.js} +3 -3
  441. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-BzPgx-xO.js → ReportIssueModal-C2PLkej3.js} +4 -4
  442. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-DanvyBPb.js +1 -0
  443. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-BX2Ny2Qj.js → ScenarioViewer-DUMfcNVK.js} +3 -3
  444. package/codeyam-cli/src/webserver/build/client/assets/Spinner-D0LgAaSa.js +34 -0
  445. package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-CK7-NaPZ.js +1 -0
  446. package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-BA_Ry-rs.js +1 -0
  447. package/codeyam-cli/src/webserver/build/client/assets/{_index-BRx8ZGZo.js → _index-BAWd-Xjf.js} +4 -4
  448. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-4S4yPfFw.js → activity.(_tab)-BOARiB-g.js} +8 -8
  449. package/codeyam-cli/src/webserver/build/client/assets/addon-canvas-DpzMmAy5.js +1 -0
  450. package/codeyam-cli/src/webserver/build/client/assets/addon-fit-YJmn1quW.js +12 -0
  451. package/codeyam-cli/src/webserver/build/client/assets/addon-web-links-CHx25PAe.js +1 -0
  452. package/codeyam-cli/src/webserver/build/client/assets/addon-webgl-DI8QOUvO.js +58 -0
  453. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-Bg3e7q4S.js +22 -0
  454. package/codeyam-cli/src/webserver/build/client/assets/api.dev-mode-events-l0sNRNKZ.js +1 -0
  455. package/codeyam-cli/src/webserver/build/client/assets/api.editor-audit-l0sNRNKZ.js +1 -0
  456. package/codeyam-cli/src/webserver/build/client/assets/api.editor-capture-scenario-l0sNRNKZ.js +1 -0
  457. package/codeyam-cli/src/webserver/build/client/assets/api.editor-client-errors-l0sNRNKZ.js +1 -0
  458. package/codeyam-cli/src/webserver/build/client/assets/api.editor-commit-l0sNRNKZ.js +1 -0
  459. package/codeyam-cli/src/webserver/build/client/assets/api.editor-dev-server-l0sNRNKZ.js +1 -0
  460. package/codeyam-cli/src/webserver/build/client/assets/api.editor-entity-status-l0sNRNKZ.js +1 -0
  461. package/codeyam-cli/src/webserver/build/client/assets/api.editor-file-diff-l0sNRNKZ.js +1 -0
  462. package/codeyam-cli/src/webserver/build/client/assets/api.editor-file-l0sNRNKZ.js +1 -0
  463. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-entry-l0sNRNKZ.js +1 -0
  464. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-image._-l0sNRNKZ.js +1 -0
  465. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-l0sNRNKZ.js +1 -0
  466. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-screenshot-l0sNRNKZ.js +1 -0
  467. package/codeyam-cli/src/webserver/build/client/assets/api.editor-journal-update-l0sNRNKZ.js +1 -0
  468. package/codeyam-cli/src/webserver/build/client/assets/api.editor-load-commit-l0sNRNKZ.js +1 -0
  469. package/codeyam-cli/src/webserver/build/client/assets/api.editor-project-info-l0sNRNKZ.js +1 -0
  470. package/codeyam-cli/src/webserver/build/client/assets/api.editor-recapture-stale-l0sNRNKZ.js +1 -0
  471. package/codeyam-cli/src/webserver/build/client/assets/api.editor-refresh-l0sNRNKZ.js +1 -0
  472. package/codeyam-cli/src/webserver/build/client/assets/api.editor-register-scenario-l0sNRNKZ.js +1 -0
  473. package/codeyam-cli/src/webserver/build/client/assets/api.editor-rename-scenario-l0sNRNKZ.js +1 -0
  474. package/codeyam-cli/src/webserver/build/client/assets/api.editor-save-scenario-data-l0sNRNKZ.js +1 -0
  475. package/codeyam-cli/src/webserver/build/client/assets/api.editor-save-seed-state-l0sNRNKZ.js +1 -0
  476. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-coverage-l0sNRNKZ.js +1 -0
  477. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-data-l0sNRNKZ.js +1 -0
  478. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-image._-l0sNRNKZ.js +1 -0
  479. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-prompt-l0sNRNKZ.js +1 -0
  480. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenarios-l0sNRNKZ.js +1 -0
  481. package/codeyam-cli/src/webserver/build/client/assets/api.editor-schema-l0sNRNKZ.js +1 -0
  482. package/codeyam-cli/src/webserver/build/client/assets/api.editor-session-l0sNRNKZ.js +1 -0
  483. package/codeyam-cli/src/webserver/build/client/assets/api.editor-switch-scenario-l0sNRNKZ.js +1 -0
  484. package/codeyam-cli/src/webserver/build/client/assets/api.editor-test-results-l0sNRNKZ.js +1 -0
  485. package/codeyam-cli/src/webserver/build/client/assets/api.rule-path-l0sNRNKZ.js +1 -0
  486. package/codeyam-cli/src/webserver/build/client/assets/{book-open-D4IPYH_y.js → book-open-CL-lMgHh.js} +2 -2
  487. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-CG65viiV.js → chevron-down-GmAjGS9-.js} +2 -2
  488. package/codeyam-cli/src/webserver/build/client/assets/chunk-JZWAC4HX-BAdwhyCx.js +43 -0
  489. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-igfMr5DY.js → circle-check-DFcQkN5j.js} +2 -2
  490. package/codeyam-cli/src/webserver/build/client/assets/{copy-Coc4o_8c.js → copy-C6iF61Xs.js} +3 -3
  491. package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-4ImjHTVC.js +41 -0
  492. package/codeyam-cli/src/webserver/build/client/assets/{cy-logo-cli-CCKUIm0S.svg → cy-logo-cli-CJzc4vOH.svg} +2 -2
  493. package/codeyam-cli/src/webserver/build/client/assets/cy-logo-cli-DODLxLcw.js +1 -0
  494. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-C8y4mmyv.js +1 -0
  495. package/codeyam-cli/src/webserver/build/client/assets/editor._tab-Gbk_i5Js.js +1 -0
  496. package/codeyam-cli/src/webserver/build/client/assets/editor.entity.(_sha)-Dx-h1rJK.js +130 -0
  497. package/codeyam-cli/src/webserver/build/client/assets/editorPreview-NTuLi4Xg.js +41 -0
  498. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-B0h9AqE6.js → entity._sha._-Blfy9UlN.js} +11 -11
  499. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-BA5L8bU-.js +6 -0
  500. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-D4dmRgvO.js +6 -0
  501. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-DQM8E7L4.js +6 -0
  502. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-PePWg17F.js → entity._sha_.edit._scenarioId-CAoXLsQr.js} +2 -2
  503. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-I-Wo99C_.js → entry.client-SuW9syRS.js} +6 -6
  504. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-Daa96Fr1.js +1 -0
  505. package/codeyam-cli/src/webserver/build/client/assets/files-D-xGrg29.js +1 -0
  506. package/codeyam-cli/src/webserver/build/client/assets/git-Bq_fbXP5.js +1 -0
  507. package/codeyam-cli/src/webserver/build/client/assets/globals-BrPXT1iR.css +1 -0
  508. package/codeyam-cli/src/webserver/build/client/assets/{index-_417gcQW.js → index-Bp1l4hSv.js} +1 -1
  509. package/codeyam-cli/src/webserver/build/client/assets/{index-CUM5iXwc.js → index-CWV9XZiG.js} +1 -1
  510. package/codeyam-cli/src/webserver/build/client/assets/index-DE3jI_dv.js +15 -0
  511. package/codeyam-cli/src/webserver/build/client/assets/jsx-runtime-D_zvdyIk.js +9 -0
  512. package/codeyam-cli/src/webserver/build/client/assets/labs-B_IX45ih.js +1 -0
  513. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-TzRHMVog.js → loader-circle-De-7qQ2u.js} +2 -2
  514. package/codeyam-cli/src/webserver/build/client/assets/manifest-5025e428.js +1 -0
  515. package/codeyam-cli/src/webserver/build/client/assets/memory-Cx2xEx7s.js +101 -0
  516. package/codeyam-cli/src/webserver/build/client/assets/{pause-hjzB7t2z.js → pause-CFxEKL1u.js} +3 -3
  517. package/codeyam-cli/src/webserver/build/client/assets/root-BCx1S8Z3.js +80 -0
  518. package/codeyam-cli/src/webserver/build/client/assets/{search-DcAwD_Ln.js → search-BdBb5aqc.js} +2 -2
  519. package/codeyam-cli/src/webserver/build/client/assets/settings-DdE-Untf.js +1 -0
  520. package/codeyam-cli/src/webserver/build/client/assets/simulations-DSCdE99u.js +1 -0
  521. package/codeyam-cli/src/webserver/build/client/assets/{terminal-DbEAHMbA.js → terminal-CrplD4b1.js} +3 -3
  522. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-CAD5b1o_.js → triangle-alert-DqJ0j69l.js} +2 -2
  523. package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-DhXHbEjP.js +1 -0
  524. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-BNd5hYuW.js +2 -0
  525. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-Cy5Qg_UR.js +1 -0
  526. package/codeyam-cli/src/webserver/build/client/assets/useToast-5HR2j9ZE.js +1 -0
  527. package/codeyam-cli/src/webserver/build/client/assets/xterm-BqvuqXEL.js +27 -0
  528. package/codeyam-cli/src/webserver/build/client/sound-test.html +98 -0
  529. package/codeyam-cli/src/webserver/build/server/assets/analysisRunner-C1kjC9UJ.js +13 -0
  530. package/codeyam-cli/src/webserver/build/server/assets/index-C91yWWCI.js +1 -0
  531. package/codeyam-cli/src/webserver/build/server/assets/init-Dkas-RUS.js +10 -0
  532. package/codeyam-cli/src/webserver/build/server/assets/progress-CHTtrxFG.js +1 -0
  533. package/codeyam-cli/src/webserver/build/server/assets/server-build-pulXLTrG.js +640 -0
  534. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  535. package/codeyam-cli/src/webserver/build-info.json +5 -5
  536. package/codeyam-cli/src/webserver/devServer.js +39 -5
  537. package/codeyam-cli/src/webserver/devServer.js.map +1 -1
  538. package/codeyam-cli/src/webserver/editorProxy.js +976 -0
  539. package/codeyam-cli/src/webserver/editorProxy.js.map +1 -0
  540. package/codeyam-cli/src/webserver/idleDetector.js +106 -0
  541. package/codeyam-cli/src/webserver/idleDetector.js.map +1 -0
  542. package/codeyam-cli/src/webserver/mockStateEvents.js +28 -0
  543. package/codeyam-cli/src/webserver/mockStateEvents.js.map +1 -0
  544. package/codeyam-cli/src/webserver/public/sound-test.html +98 -0
  545. package/codeyam-cli/src/webserver/scripts/codeyam-preload.mjs +414 -0
  546. package/codeyam-cli/src/webserver/scripts/journalCapture.ts +283 -0
  547. package/codeyam-cli/src/webserver/server.js +379 -1
  548. package/codeyam-cli/src/webserver/server.js.map +1 -1
  549. package/codeyam-cli/src/webserver/terminalServer.js +945 -0
  550. package/codeyam-cli/src/webserver/terminalServer.js.map +1 -0
  551. package/codeyam-cli/templates/__tests__/editor-step-hook.prompt-capture.test.ts +118 -0
  552. package/codeyam-cli/templates/chrome-extension-react/EXTENSION_SETUP.md +75 -0
  553. package/codeyam-cli/templates/chrome-extension-react/README.md +46 -0
  554. package/codeyam-cli/templates/chrome-extension-react/gitignore +15 -0
  555. package/codeyam-cli/templates/chrome-extension-react/index.html +12 -0
  556. package/codeyam-cli/templates/chrome-extension-react/package.json +27 -0
  557. package/codeyam-cli/templates/chrome-extension-react/popup.html +12 -0
  558. package/codeyam-cli/templates/chrome-extension-react/public/manifest.json +15 -0
  559. package/codeyam-cli/templates/chrome-extension-react/src/background/service-worker.ts +7 -0
  560. package/codeyam-cli/templates/chrome-extension-react/src/globals.css +6 -0
  561. package/codeyam-cli/templates/chrome-extension-react/src/lib/storage.ts +37 -0
  562. package/codeyam-cli/templates/chrome-extension-react/src/popup/App.tsx +12 -0
  563. package/codeyam-cli/templates/chrome-extension-react/src/popup/main.tsx +10 -0
  564. package/codeyam-cli/templates/chrome-extension-react/tsconfig.json +24 -0
  565. package/codeyam-cli/templates/chrome-extension-react/vite.config.ts +41 -0
  566. package/codeyam-cli/templates/codeyam-editor-claude.md +149 -0
  567. package/codeyam-cli/templates/codeyam-editor-reference.md +214 -0
  568. package/codeyam-cli/templates/editor-step-hook.py +368 -0
  569. package/codeyam-cli/templates/expo-react-native/MOBILE_SETUP.md +89 -0
  570. package/codeyam-cli/templates/expo-react-native/README.md +41 -0
  571. package/codeyam-cli/templates/expo-react-native/app/(tabs)/_layout.tsx +33 -0
  572. package/codeyam-cli/templates/expo-react-native/app/(tabs)/index.tsx +12 -0
  573. package/codeyam-cli/templates/expo-react-native/app/(tabs)/settings.tsx +12 -0
  574. package/codeyam-cli/templates/expo-react-native/app/_layout.tsx +12 -0
  575. package/codeyam-cli/templates/expo-react-native/app.json +18 -0
  576. package/codeyam-cli/templates/expo-react-native/babel.config.js +9 -0
  577. package/codeyam-cli/templates/expo-react-native/gitignore +12 -0
  578. package/codeyam-cli/templates/expo-react-native/global.css +3 -0
  579. package/codeyam-cli/templates/expo-react-native/lib/storage.ts +32 -0
  580. package/codeyam-cli/templates/expo-react-native/metro.config.js +6 -0
  581. package/codeyam-cli/templates/expo-react-native/nativewind-env.d.ts +1 -0
  582. package/codeyam-cli/templates/expo-react-native/package.json +38 -0
  583. package/codeyam-cli/templates/expo-react-native/tailwind.config.js +10 -0
  584. package/codeyam-cli/templates/expo-react-native/tsconfig.json +10 -0
  585. package/codeyam-cli/templates/hooks/staleness-check.sh +43 -0
  586. package/codeyam-cli/templates/isolation-route/next-app.tsx.template +80 -0
  587. package/codeyam-cli/templates/isolation-route/next-pages.tsx.template +79 -0
  588. package/codeyam-cli/templates/isolation-route/vite-react.tsx.template +78 -0
  589. package/codeyam-cli/templates/msw/browser-setup.ts.template +47 -0
  590. package/codeyam-cli/templates/msw/handler-router.ts.template +47 -0
  591. package/codeyam-cli/templates/msw/server-setup.ts.template +52 -0
  592. package/codeyam-cli/templates/nextjs-prisma-sqlite/AUTH_PATTERNS.md +308 -0
  593. package/codeyam-cli/templates/nextjs-prisma-sqlite/AUTH_UPGRADE.md +304 -0
  594. package/codeyam-cli/templates/nextjs-prisma-sqlite/DATABASE.md +126 -0
  595. package/codeyam-cli/templates/nextjs-prisma-sqlite/FEATURE_PATTERNS.md +37 -0
  596. package/codeyam-cli/templates/nextjs-prisma-sqlite/README.md +53 -0
  597. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/api/todos/route.ts +17 -0
  598. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/codeyam-isolate/layout.tsx +12 -0
  599. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/globals.css +26 -0
  600. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/layout.tsx +34 -0
  601. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/lib/prisma.ts +24 -0
  602. package/codeyam-cli/templates/nextjs-prisma-sqlite/app/page.tsx +10 -0
  603. package/codeyam-cli/templates/nextjs-prisma-sqlite/env +4 -0
  604. package/codeyam-cli/templates/nextjs-prisma-sqlite/eslint.config.mjs +11 -0
  605. package/codeyam-cli/templates/nextjs-prisma-sqlite/gitignore +64 -0
  606. package/codeyam-cli/templates/nextjs-prisma-sqlite/next.config.ts +14 -0
  607. package/codeyam-cli/templates/nextjs-prisma-sqlite/package.json +39 -0
  608. package/codeyam-cli/templates/nextjs-prisma-sqlite/postcss.config.mjs +7 -0
  609. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/schema.prisma +27 -0
  610. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma/seed.ts +40 -0
  611. package/codeyam-cli/templates/nextjs-prisma-sqlite/prisma.config.ts +12 -0
  612. package/codeyam-cli/templates/nextjs-prisma-sqlite/seed-adapter.ts +127 -0
  613. package/codeyam-cli/templates/nextjs-prisma-sqlite/tsconfig.json +34 -0
  614. package/codeyam-cli/templates/nextjs-prisma-sqlite/vitest.config.ts +13 -0
  615. package/codeyam-cli/templates/nextjs-prisma-supabase/README.md +52 -0
  616. package/codeyam-cli/templates/nextjs-prisma-supabase/SUPABASE_SETUP.md +104 -0
  617. package/codeyam-cli/templates/nextjs-prisma-supabase/app/api/todos/route.ts +17 -0
  618. package/codeyam-cli/templates/nextjs-prisma-supabase/app/globals.css +26 -0
  619. package/codeyam-cli/templates/nextjs-prisma-supabase/app/layout.tsx +34 -0
  620. package/codeyam-cli/templates/nextjs-prisma-supabase/app/lib/prisma.ts +20 -0
  621. package/codeyam-cli/templates/nextjs-prisma-supabase/app/lib/supabase.ts +12 -0
  622. package/codeyam-cli/templates/nextjs-prisma-supabase/app/page.tsx +10 -0
  623. package/codeyam-cli/templates/nextjs-prisma-supabase/env +9 -0
  624. package/codeyam-cli/templates/nextjs-prisma-supabase/eslint.config.mjs +11 -0
  625. package/codeyam-cli/templates/nextjs-prisma-supabase/gitignore +40 -0
  626. package/codeyam-cli/templates/nextjs-prisma-supabase/next.config.ts +11 -0
  627. package/codeyam-cli/templates/nextjs-prisma-supabase/package.json +37 -0
  628. package/codeyam-cli/templates/nextjs-prisma-supabase/postcss.config.mjs +7 -0
  629. package/codeyam-cli/templates/nextjs-prisma-supabase/prisma/schema.prisma +27 -0
  630. package/codeyam-cli/templates/nextjs-prisma-supabase/prisma/seed.ts +39 -0
  631. package/codeyam-cli/templates/nextjs-prisma-supabase/prisma.config.ts +12 -0
  632. package/codeyam-cli/templates/nextjs-prisma-supabase/tsconfig.json +34 -0
  633. package/codeyam-cli/templates/prompts/conversation-guidance.txt +44 -0
  634. package/codeyam-cli/templates/prompts/conversation-prompt.txt +28 -0
  635. package/codeyam-cli/templates/prompts/interruption-prompt.txt +31 -0
  636. package/codeyam-cli/templates/prompts/stale-rules-prompt.txt +24 -0
  637. package/codeyam-cli/templates/rule-notification-hook.py +44 -17
  638. package/codeyam-cli/templates/rule-reflection-hook.py +24 -4
  639. package/codeyam-cli/templates/rules-instructions.md +34 -88
  640. package/codeyam-cli/templates/seed-adapters/supabase.ts +282 -0
  641. package/codeyam-cli/templates/skills/codeyam-dev-mode/SKILL.md +237 -0
  642. package/codeyam-cli/templates/skills/codeyam-editor/SKILL.md +229 -0
  643. package/codeyam-cli/templates/{codeyam-memory.md → skills/codeyam-memory/SKILL.md} +215 -0
  644. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/deprecated-prompt.md +100 -0
  645. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/detect-deprecated-patterns.mjs +139 -0
  646. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/find-exports.mjs +52 -0
  647. package/codeyam-cli/templates/skills/codeyam-memory/scripts/holistic-analysis/misleading-api-prompt.md +117 -0
  648. package/codeyam-cli/templates/skills/codeyam-memory/scripts/lib/read-json-field.mjs +61 -0
  649. package/codeyam-cli/templates/skills/codeyam-memory/scripts/lib/ripgrep-fallback.mjs +155 -0
  650. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/analyze-prompt.md +46 -0
  651. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/cleanup.mjs +13 -0
  652. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/filter-session.mjs +95 -0
  653. package/codeyam-cli/templates/skills/codeyam-memory/scripts/session-mining/preprocess.mjs +160 -0
  654. package/codeyam-cli/templates/{codeyam-new-rule.md → skills/codeyam-new-rule/SKILL.md} +0 -2
  655. package/package.json +18 -10
  656. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js +22 -4
  657. package/packages/ai/src/lib/astScopes/astScopeAnalyzer.js.map +1 -1
  658. package/packages/ai/src/lib/completionCall.js +10 -7
  659. package/packages/ai/src/lib/completionCall.js.map +1 -1
  660. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js +25 -1
  661. package/packages/ai/src/lib/dataStructure/ScopeDataStructure.js.map +1 -1
  662. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js +54 -0
  663. package/packages/ai/src/lib/dataStructure/helpers/coercePrimitivesToArraysBySchema.js.map +1 -0
  664. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js +34 -0
  665. package/packages/ai/src/lib/dataStructure/helpers/stripNullableMarkers.js.map +1 -0
  666. package/packages/ai/src/lib/generateEntityScenarioData.js +57 -2
  667. package/packages/ai/src/lib/generateEntityScenarioData.js.map +1 -1
  668. package/packages/ai/src/lib/generateExecutionFlows.js +0 -11
  669. package/packages/ai/src/lib/generateExecutionFlows.js.map +1 -1
  670. package/packages/analyze/src/lib/ProjectAnalyzer.js +13 -4
  671. package/packages/analyze/src/lib/ProjectAnalyzer.js.map +1 -1
  672. package/packages/analyze/src/lib/asts/index.js +4 -2
  673. package/packages/analyze/src/lib/asts/index.js.map +1 -1
  674. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js +8 -1
  675. package/packages/analyze/src/lib/files/analyze/analyzeEntities.js.map +1 -1
  676. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js +0 -5
  677. package/packages/analyze/src/lib/files/analyze/dependencyResolver.js.map +1 -1
  678. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js +12 -2
  679. package/packages/analyze/src/lib/files/analyze/findOrCreateEntity.js.map +1 -1
  680. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js +9 -7
  681. package/packages/analyze/src/lib/files/analyze/gatherEntityMap.js.map +1 -1
  682. package/packages/analyze/src/lib/files/analyzeChange.js +1 -0
  683. package/packages/analyze/src/lib/files/analyzeChange.js.map +1 -1
  684. package/packages/analyze/src/lib/files/analyzeInitial.js +1 -0
  685. package/packages/analyze/src/lib/files/analyzeInitial.js.map +1 -1
  686. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js +54 -27
  687. package/packages/analyze/src/lib/files/scenarios/TransformationTracer.js.map +1 -1
  688. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js +65 -0
  689. package/packages/analyze/src/lib/files/scenarios/generateDataStructure.js.map +1 -1
  690. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js +0 -40
  691. package/packages/analyze/src/lib/files/scenarios/generateExecutionFlows.js.map +1 -1
  692. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js +18 -4
  693. package/packages/analyze/src/lib/files/scenarios/mergeInDependentDataStructure.js.map +1 -1
  694. package/packages/database/index.js +1 -0
  695. package/packages/database/index.js.map +1 -1
  696. package/packages/database/src/lib/kysely/db.js +5 -0
  697. package/packages/database/src/lib/kysely/db.js.map +1 -1
  698. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +149 -0
  699. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -0
  700. package/packages/database/src/lib/loadAnalysis.js +1 -1
  701. package/packages/database/src/lib/loadAnalysis.js.map +1 -1
  702. package/packages/database/src/lib/loadCommits.js +23 -13
  703. package/packages/database/src/lib/loadCommits.js.map +1 -1
  704. package/packages/database/src/lib/loadEntities.js +0 -6
  705. package/packages/database/src/lib/loadEntities.js.map +1 -1
  706. package/packages/database/src/lib/loadEntity.js +5 -5
  707. package/packages/database/src/lib/loadEntity.js.map +1 -1
  708. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js +1 -4
  709. package/packages/database/src/lib/loadReadyToBeCapturedAnalyses.js.map +1 -1
  710. package/packages/database/src/lib/updateCommitMetadata.js +76 -90
  711. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  712. package/packages/database/src/lib/updateFreshAnalysisStatus.js +41 -30
  713. package/packages/database/src/lib/updateFreshAnalysisStatus.js.map +1 -1
  714. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js +68 -57
  715. package/packages/database/src/lib/updateFreshAnalysisStatusWithScenarios.js.map +1 -1
  716. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js +29 -1
  717. package/packages/generate/src/lib/componentScenarioPage/generateScenarioClientWrapper.js.map +1 -1
  718. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js +33 -5
  719. package/packages/generate/src/lib/componentScenarioPage/getIFrameMessageListenerCode.js.map +1 -1
  720. package/packages/types/src/enums/ProjectFramework.js +2 -0
  721. package/packages/types/src/enums/ProjectFramework.js.map +1 -1
  722. package/packages/utils/src/lib/fs/rsyncCopy.js +28 -3
  723. package/packages/utils/src/lib/fs/rsyncCopy.js.map +1 -1
  724. package/scripts/npm-post-install.cjs +34 -0
  725. package/codeyam-cli/src/commands/detect-universal-mocks.js +0 -120
  726. package/codeyam-cli/src/commands/detect-universal-mocks.js.map +0 -1
  727. package/codeyam-cli/src/commands/list.js +0 -31
  728. package/codeyam-cli/src/commands/list.js.map +0 -1
  729. package/codeyam-cli/src/commands/webapp-info.js +0 -146
  730. package/codeyam-cli/src/commands/webapp-info.js.map +0 -1
  731. package/codeyam-cli/src/utils/universal-mocks.js +0 -152
  732. package/codeyam-cli/src/utils/universal-mocks.js.map +0 -1
  733. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-jNYXRRNI.js +0 -1
  734. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-CvzqMxcu.js +0 -1
  735. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-EhOseatT.js +0 -34
  736. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-yjIHlOGa.js +0 -25
  737. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-Cq5o8jL4.js +0 -3
  738. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-CwZrv-Ok.js +0 -1
  739. package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-CDpEprKa.js +0 -1
  740. package/codeyam-cli/src/webserver/build/client/assets/agent-transcripts-DHKuQSmR.js +0 -17
  741. package/codeyam-cli/src/webserver/build/client/assets/chunk-JZWAC4HX-DB3aFuEO.js +0 -51
  742. package/codeyam-cli/src/webserver/build/client/assets/createLucideIcon-D1zB-pYc.js +0 -21
  743. package/codeyam-cli/src/webserver/build/client/assets/cy-logo-cli-DcX-ZS3p.js +0 -1
  744. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-JTAjQ54M.js +0 -1
  745. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-DjLxr2JB.js +0 -6
  746. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-CtYowLOt.js +0 -6
  747. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-9sMMAiWJ.js +0 -1
  748. package/codeyam-cli/src/webserver/build/client/assets/files-Co65J0s3.js +0 -1
  749. package/codeyam-cli/src/webserver/build/client/assets/git-BdHOxVfg.js +0 -15
  750. package/codeyam-cli/src/webserver/build/client/assets/globals-BSZfYCkU.css +0 -1
  751. package/codeyam-cli/src/webserver/build/client/assets/labs-BK0C1H1T.js +0 -1
  752. package/codeyam-cli/src/webserver/build/client/assets/manifest-040dab1c.js +0 -1
  753. package/codeyam-cli/src/webserver/build/client/assets/memory-UIDVz141.js +0 -92
  754. package/codeyam-cli/src/webserver/build/client/assets/root-D1WadSdf.js +0 -62
  755. package/codeyam-cli/src/webserver/build/client/assets/settings-CclxrcPK.js +0 -1
  756. package/codeyam-cli/src/webserver/build/client/assets/simulations-DVNJVQgD.js +0 -1
  757. package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-BqgrAzs3.js +0 -1
  758. package/codeyam-cli/src/webserver/build/client/assets/useLastLogLine-DAFqfEDH.js +0 -2
  759. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-DZlYx2c4.js +0 -1
  760. package/codeyam-cli/src/webserver/build/client/assets/useToast-ihdMtlf6.js +0 -1
  761. package/codeyam-cli/src/webserver/build/server/assets/index-B3dE0r28.js +0 -1
  762. package/codeyam-cli/src/webserver/build/server/assets/server-build-DYbfdxa3.js +0 -273
  763. package/codeyam-cli/templates/codeyam-stop-hook.sh +0 -284
  764. package/scripts/finalize-analyzer.cjs +0 -13
  765. /package/codeyam-cli/templates/{codeyam-diagnose.md → commands/codeyam-diagnose.md} +0 -0
  766. /package/codeyam-cli/templates/{codeyam-debug.md → skills/codeyam-debug/SKILL.md} +0 -0
  767. /package/codeyam-cli/templates/{codeyam-setup.md → skills/codeyam-setup/SKILL.md} +0 -0
  768. /package/codeyam-cli/templates/{codeyam-sim.md → skills/codeyam-sim/SKILL.md} +0 -0
  769. /package/codeyam-cli/templates/{codeyam-test.md → skills/codeyam-test/SKILL.md} +0 -0
  770. /package/codeyam-cli/templates/{codeyam-verify.md → skills/codeyam-verify/SKILL.md} +0 -0
@@ -0,0 +1,3559 @@
1
+ import Database from 'better-sqlite3';
2
+ import { Kysely, SqliteDialect } from 'kysely';
3
+ import { isComponent, classifyGlossaryEntries, computeAudit, filterGlossaryByChangeStatus, resolveAuditSessionScope, queryScenarioCounts, queryPageScenarioCounts, queryIncompleteEntities, queryMiscategorizedScenarios, queryUnassociatedScenarios, isOnlyIncompleteEntities, isOnlyPreExistingIncomplete, isAutoRemediable, identifyScenariosNeedingRecapture, detectDuplicateNames, } from "../editorAudit.js";
4
+ describe('editorAudit', () => {
5
+ describe('isComponent', () => {
6
+ it('should return true for JSX.Element return type', () => {
7
+ expect(isComponent({ returnType: 'JSX.Element' })).toBe(true);
8
+ });
9
+ it('should return true for React.ReactElement return type', () => {
10
+ expect(isComponent({ returnType: 'React.ReactElement' })).toBe(true);
11
+ });
12
+ it('should return true for ReactNode return type', () => {
13
+ expect(isComponent({ returnType: 'ReactNode' })).toBe(true);
14
+ });
15
+ it('should return true for Element return type', () => {
16
+ expect(isComponent({ returnType: 'Element' })).toBe(true);
17
+ });
18
+ it('should return true when JSX appears anywhere in the return type', () => {
19
+ expect(isComponent({ returnType: 'Promise<JSX.Element>' })).toBe(true);
20
+ });
21
+ it('should return false for non-component return types', () => {
22
+ expect(isComponent({ returnType: 'number' })).toBe(false);
23
+ expect(isComponent({ returnType: 'string' })).toBe(false);
24
+ expect(isComponent({ returnType: 'void' })).toBe(false);
25
+ });
26
+ it('should return false when returnType is undefined', () => {
27
+ expect(isComponent({})).toBe(false);
28
+ });
29
+ it('should return false when returnType is empty string', () => {
30
+ expect(isComponent({ returnType: '' })).toBe(false);
31
+ });
32
+ });
33
+ describe('classifyGlossaryEntries', () => {
34
+ it('should classify entries with JSX return types as components', () => {
35
+ const entries = [
36
+ {
37
+ name: 'DrinkCard',
38
+ filePath: 'app/components/DrinkCard.tsx',
39
+ returnType: 'JSX.Element',
40
+ },
41
+ {
42
+ name: 'calculatePrice',
43
+ filePath: 'app/lib/pricing.ts',
44
+ returnType: 'number',
45
+ },
46
+ ];
47
+ const result = classifyGlossaryEntries(entries);
48
+ expect(result.components).toHaveLength(1);
49
+ expect(result.components[0].name).toBe('DrinkCard');
50
+ expect(result.functions).toHaveLength(1);
51
+ expect(result.functions[0].name).toBe('calculatePrice');
52
+ });
53
+ it('should return empty arrays for empty input', () => {
54
+ const result = classifyGlossaryEntries([]);
55
+ expect(result.components).toEqual([]);
56
+ expect(result.functions).toEqual([]);
57
+ });
58
+ it('should treat entries without returnType as functions', () => {
59
+ const entries = [{ name: 'helper', filePath: 'app/lib/helper.ts' }];
60
+ const result = classifyGlossaryEntries(entries);
61
+ expect(result.components).toHaveLength(0);
62
+ expect(result.functions).toHaveLength(1);
63
+ });
64
+ it('should handle all components', () => {
65
+ const entries = [
66
+ {
67
+ name: 'Header',
68
+ filePath: 'app/components/Header.tsx',
69
+ returnType: 'ReactNode',
70
+ },
71
+ {
72
+ name: 'Footer',
73
+ filePath: 'app/components/Footer.tsx',
74
+ returnType: 'JSX.Element',
75
+ },
76
+ ];
77
+ const result = classifyGlossaryEntries(entries);
78
+ expect(result.components).toHaveLength(2);
79
+ expect(result.functions).toHaveLength(0);
80
+ });
81
+ it('should handle all functions', () => {
82
+ const entries = [
83
+ { name: 'add', filePath: 'app/lib/math.ts', returnType: 'number' },
84
+ { name: 'format', filePath: 'app/lib/format.ts', returnType: 'string' },
85
+ ];
86
+ const result = classifyGlossaryEntries(entries);
87
+ expect(result.components).toHaveLength(0);
88
+ expect(result.functions).toHaveLength(2);
89
+ });
90
+ });
91
+ describe('computeAudit', () => {
92
+ it('should mark components with scenarios as ok', () => {
93
+ const result = computeAudit({
94
+ components: [
95
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
96
+ ],
97
+ functions: [],
98
+ scenarioCounts: { DrinkCard: 2 },
99
+ testFileExistence: {},
100
+ });
101
+ expect(result.components[0].status).toBe('ok');
102
+ expect(result.components[0].scenarioCount).toBe(2);
103
+ expect(result.summary.componentsOk).toBe(1);
104
+ expect(result.summary.componentsMissing).toBe(0);
105
+ });
106
+ it('should mark components without scenarios as missing', () => {
107
+ const result = computeAudit({
108
+ components: [
109
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
110
+ ],
111
+ functions: [],
112
+ scenarioCounts: {},
113
+ testFileExistence: {},
114
+ });
115
+ expect(result.components[0].status).toBe('missing');
116
+ expect(result.components[0].scenarioCount).toBe(0);
117
+ expect(result.summary.componentsMissing).toBe(1);
118
+ });
119
+ it('should mark functions with existing test files as ok', () => {
120
+ const result = computeAudit({
121
+ components: [],
122
+ functions: [
123
+ {
124
+ name: 'calculatePrice',
125
+ filePath: 'app/lib/pricing.ts',
126
+ testFile: 'app/lib/pricing.test.ts',
127
+ },
128
+ ],
129
+ scenarioCounts: {},
130
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
131
+ });
132
+ expect(result.functions[0].status).toBe('ok');
133
+ expect(result.functions[0].testFileExists).toBe(true);
134
+ expect(result.summary.functionsOk).toBe(1);
135
+ expect(result.summary.functionsMissing).toBe(0);
136
+ });
137
+ it('should mark functions with missing test files as missing', () => {
138
+ const result = computeAudit({
139
+ components: [],
140
+ functions: [
141
+ {
142
+ name: 'calculatePrice',
143
+ filePath: 'app/lib/pricing.ts',
144
+ testFile: 'app/lib/pricing.test.ts',
145
+ },
146
+ ],
147
+ scenarioCounts: {},
148
+ testFileExistence: { 'app/lib/pricing.test.ts': false },
149
+ });
150
+ expect(result.functions[0].status).toBe('missing');
151
+ expect(result.functions[0].testFileExists).toBe(false);
152
+ expect(result.summary.functionsMissing).toBe(1);
153
+ });
154
+ it('should mark functions without testFile field as missing', () => {
155
+ const result = computeAudit({
156
+ components: [],
157
+ functions: [{ name: 'calculatePrice', filePath: 'app/lib/pricing.ts' }],
158
+ scenarioCounts: {},
159
+ testFileExistence: {},
160
+ });
161
+ expect(result.functions[0].status).toBe('missing');
162
+ expect(result.functions[0].testFile).toBeUndefined();
163
+ expect(result.functions[0].testFileExists).toBe(false);
164
+ });
165
+ it('should set allPassing to true when everything is ok', () => {
166
+ const result = computeAudit({
167
+ components: [
168
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
169
+ ],
170
+ functions: [
171
+ {
172
+ name: 'calculatePrice',
173
+ filePath: 'app/lib/pricing.ts',
174
+ testFile: 'app/lib/pricing.test.ts',
175
+ },
176
+ ],
177
+ scenarioCounts: { DrinkCard: 1 },
178
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
179
+ });
180
+ expect(result.summary.allPassing).toBe(true);
181
+ });
182
+ it('should set allPassing to false when any component is missing', () => {
183
+ const result = computeAudit({
184
+ components: [
185
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
186
+ ],
187
+ functions: [],
188
+ scenarioCounts: {},
189
+ testFileExistence: {},
190
+ });
191
+ expect(result.summary.allPassing).toBe(false);
192
+ });
193
+ it('should set allPassing to false when any function is missing', () => {
194
+ const result = computeAudit({
195
+ components: [],
196
+ functions: [{ name: 'calculatePrice', filePath: 'app/lib/pricing.ts' }],
197
+ scenarioCounts: {},
198
+ testFileExistence: {},
199
+ });
200
+ expect(result.summary.allPassing).toBe(false);
201
+ });
202
+ it('should set allPassing to true for empty inputs', () => {
203
+ const result = computeAudit({
204
+ components: [],
205
+ functions: [],
206
+ scenarioCounts: {},
207
+ testFileExistence: {},
208
+ });
209
+ expect(result.summary.allPassing).toBe(true);
210
+ expect(result.summary.totalComponents).toBe(0);
211
+ expect(result.summary.totalFunctions).toBe(0);
212
+ });
213
+ it('should compute correct summary totals', () => {
214
+ const result = computeAudit({
215
+ components: [
216
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
217
+ { name: 'Header', filePath: 'app/components/Header.tsx' },
218
+ { name: 'Footer', filePath: 'app/components/Footer.tsx' },
219
+ ],
220
+ functions: [
221
+ {
222
+ name: 'calculatePrice',
223
+ filePath: 'app/lib/pricing.ts',
224
+ testFile: 'app/lib/pricing.test.ts',
225
+ },
226
+ {
227
+ name: 'formatDate',
228
+ filePath: 'app/lib/format.ts',
229
+ testFile: 'app/lib/format.test.ts',
230
+ },
231
+ ],
232
+ scenarioCounts: { DrinkCard: 3, Header: 1 },
233
+ testFileExistence: {
234
+ 'app/lib/pricing.test.ts': true,
235
+ 'app/lib/format.test.ts': false,
236
+ },
237
+ });
238
+ expect(result.summary.totalComponents).toBe(3);
239
+ expect(result.summary.componentsOk).toBe(2);
240
+ expect(result.summary.componentsMissing).toBe(1);
241
+ expect(result.summary.totalFunctions).toBe(2);
242
+ expect(result.summary.functionsOk).toBe(1);
243
+ expect(result.summary.functionsMissing).toBe(1);
244
+ expect(result.summary.allPassing).toBe(false);
245
+ });
246
+ // ── Test results integration ────────────────────────────────────
247
+ it('should mark function as ok when tests pass and describe matches entity name', () => {
248
+ const result = computeAudit({
249
+ components: [],
250
+ functions: [
251
+ {
252
+ name: 'calculatePrice',
253
+ filePath: 'app/lib/pricing.ts',
254
+ testFile: 'app/lib/pricing.test.ts',
255
+ },
256
+ ],
257
+ scenarioCounts: {},
258
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
259
+ testResults: {
260
+ 'app/lib/pricing.test.ts': {
261
+ passing: true,
262
+ hasEntityNameDescribe: true,
263
+ },
264
+ },
265
+ });
266
+ expect(result.functions[0].status).toBe('ok');
267
+ expect(result.functions[0].testsPassing).toBe(true);
268
+ expect(result.functions[0].testsVisibleInUi).toBe(true);
269
+ });
270
+ it('should mark function as failing when tests fail', () => {
271
+ const result = computeAudit({
272
+ components: [],
273
+ functions: [
274
+ {
275
+ name: 'calculatePrice',
276
+ filePath: 'app/lib/pricing.ts',
277
+ testFile: 'app/lib/pricing.test.ts',
278
+ },
279
+ ],
280
+ scenarioCounts: {},
281
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
282
+ testResults: {
283
+ 'app/lib/pricing.test.ts': {
284
+ passing: false,
285
+ hasEntityNameDescribe: true,
286
+ },
287
+ },
288
+ });
289
+ expect(result.functions[0].status).toBe('failing');
290
+ expect(result.functions[0].testsPassing).toBe(false);
291
+ expect(result.functions[0].testsVisibleInUi).toBe(true);
292
+ });
293
+ it('should distinguish runner errors from test failures and include error message', () => {
294
+ const result = computeAudit({
295
+ components: [],
296
+ functions: [
297
+ {
298
+ name: 'getTimeAgo',
299
+ filePath: 'src/lib/format.ts',
300
+ testFile: 'src/lib/format.test.ts',
301
+ },
302
+ ],
303
+ scenarioCounts: {},
304
+ testFileExistence: { 'src/lib/format.test.ts': true },
305
+ testResults: {
306
+ 'src/lib/format.test.ts': {
307
+ passing: false,
308
+ hasEntityNameDescribe: false,
309
+ errorMessage: 'Error: Cannot find module "@/lib/format" from "src/lib/format.test.ts"',
310
+ },
311
+ },
312
+ });
313
+ expect(result.functions[0].status).toBe('runner_error');
314
+ expect(result.functions[0].errorMessage).toBe('Error: Cannot find module "@/lib/format" from "src/lib/format.test.ts"');
315
+ });
316
+ it('should mark function as name_mismatch when tests pass but no describe matches', () => {
317
+ const result = computeAudit({
318
+ components: [],
319
+ functions: [
320
+ {
321
+ name: 'useDrinks',
322
+ filePath: 'app/hooks/useDrinks.ts',
323
+ testFile: 'app/hooks/useDrinks.test.ts',
324
+ },
325
+ ],
326
+ scenarioCounts: {},
327
+ testFileExistence: { 'app/hooks/useDrinks.test.ts': true },
328
+ testResults: {
329
+ 'app/hooks/useDrinks.test.ts': {
330
+ passing: true,
331
+ hasEntityNameDescribe: false,
332
+ },
333
+ },
334
+ });
335
+ expect(result.functions[0].status).toBe('name_mismatch');
336
+ expect(result.functions[0].testsPassing).toBe(true);
337
+ expect(result.functions[0].testsVisibleInUi).toBe(false);
338
+ });
339
+ it('should still mark function as missing when test file does not exist even with testResults', () => {
340
+ const result = computeAudit({
341
+ components: [],
342
+ functions: [
343
+ {
344
+ name: 'calculatePrice',
345
+ filePath: 'app/lib/pricing.ts',
346
+ testFile: 'app/lib/pricing.test.ts',
347
+ },
348
+ ],
349
+ scenarioCounts: {},
350
+ testFileExistence: { 'app/lib/pricing.test.ts': false },
351
+ testResults: {},
352
+ });
353
+ expect(result.functions[0].status).toBe('missing');
354
+ expect(result.functions[0].testsPassing).toBeUndefined();
355
+ expect(result.functions[0].testsVisibleInUi).toBeUndefined();
356
+ });
357
+ it('should include functionsFailing and functionsNameMismatch in summary', () => {
358
+ const result = computeAudit({
359
+ components: [],
360
+ functions: [
361
+ {
362
+ name: 'fnOk',
363
+ filePath: 'a.ts',
364
+ testFile: 'a.test.ts',
365
+ },
366
+ {
367
+ name: 'fnFailing',
368
+ filePath: 'b.ts',
369
+ testFile: 'b.test.ts',
370
+ },
371
+ {
372
+ name: 'fnMismatch',
373
+ filePath: 'c.ts',
374
+ testFile: 'c.test.ts',
375
+ },
376
+ {
377
+ name: 'fnMissing',
378
+ filePath: 'd.ts',
379
+ testFile: 'd.test.ts',
380
+ },
381
+ ],
382
+ scenarioCounts: {},
383
+ testFileExistence: {
384
+ 'a.test.ts': true,
385
+ 'b.test.ts': true,
386
+ 'c.test.ts': true,
387
+ 'd.test.ts': false,
388
+ },
389
+ testResults: {
390
+ 'a.test.ts': { passing: true, hasEntityNameDescribe: true },
391
+ 'b.test.ts': { passing: false, hasEntityNameDescribe: true },
392
+ 'c.test.ts': { passing: true, hasEntityNameDescribe: false },
393
+ },
394
+ });
395
+ expect(result.summary.functionsOk).toBe(1);
396
+ expect(result.summary.functionsFailing).toBe(1);
397
+ expect(result.summary.functionsNameMismatch).toBe(1);
398
+ expect(result.summary.functionsMissing).toBe(1);
399
+ expect(result.summary.allPassing).toBe(false);
400
+ });
401
+ it('should set allPassing to true only when all functions are ok', () => {
402
+ const result = computeAudit({
403
+ components: [
404
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
405
+ ],
406
+ functions: [
407
+ {
408
+ name: 'calculatePrice',
409
+ filePath: 'app/lib/pricing.ts',
410
+ testFile: 'app/lib/pricing.test.ts',
411
+ },
412
+ ],
413
+ scenarioCounts: { DrinkCard: 1 },
414
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
415
+ testResults: {
416
+ 'app/lib/pricing.test.ts': {
417
+ passing: true,
418
+ hasEntityNameDescribe: true,
419
+ },
420
+ },
421
+ });
422
+ expect(result.summary.allPassing).toBe(true);
423
+ });
424
+ it('should set allPassing to false when any function is failing', () => {
425
+ const result = computeAudit({
426
+ components: [],
427
+ functions: [
428
+ {
429
+ name: 'calculatePrice',
430
+ filePath: 'app/lib/pricing.ts',
431
+ testFile: 'app/lib/pricing.test.ts',
432
+ },
433
+ ],
434
+ scenarioCounts: {},
435
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
436
+ testResults: {
437
+ 'app/lib/pricing.test.ts': {
438
+ passing: false,
439
+ hasEntityNameDescribe: true,
440
+ },
441
+ },
442
+ });
443
+ expect(result.summary.allPassing).toBe(false);
444
+ });
445
+ it('should set allPassing to false when any function has name_mismatch', () => {
446
+ const result = computeAudit({
447
+ components: [],
448
+ functions: [
449
+ {
450
+ name: 'useDrinks',
451
+ filePath: 'app/hooks/useDrinks.ts',
452
+ testFile: 'app/hooks/useDrinks.test.ts',
453
+ },
454
+ ],
455
+ scenarioCounts: {},
456
+ testFileExistence: { 'app/hooks/useDrinks.test.ts': true },
457
+ testResults: {
458
+ 'app/hooks/useDrinks.test.ts': {
459
+ passing: true,
460
+ hasEntityNameDescribe: false,
461
+ },
462
+ },
463
+ });
464
+ expect(result.summary.allPassing).toBe(false);
465
+ });
466
+ it('should fall back to file-existence-only behavior when testResults is not provided', () => {
467
+ // Backward compat: no testResults → existing behavior
468
+ const result = computeAudit({
469
+ components: [],
470
+ functions: [
471
+ {
472
+ name: 'calculatePrice',
473
+ filePath: 'app/lib/pricing.ts',
474
+ testFile: 'app/lib/pricing.test.ts',
475
+ },
476
+ ],
477
+ scenarioCounts: {},
478
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
479
+ });
480
+ expect(result.functions[0].status).toBe('ok');
481
+ expect(result.functions[0].testsPassing).toBeUndefined();
482
+ expect(result.functions[0].testsVisibleInUi).toBeUndefined();
483
+ });
484
+ it('should fall back to file-existence-only when testResults is empty for a given file', () => {
485
+ const result = computeAudit({
486
+ components: [],
487
+ functions: [
488
+ {
489
+ name: 'calculatePrice',
490
+ filePath: 'app/lib/pricing.ts',
491
+ testFile: 'app/lib/pricing.test.ts',
492
+ },
493
+ ],
494
+ scenarioCounts: {},
495
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
496
+ testResults: {},
497
+ });
498
+ // No test result for this file → fall back to existence check
499
+ expect(result.functions[0].status).toBe('ok');
500
+ expect(result.functions[0].testsPassing).toBeUndefined();
501
+ expect(result.functions[0].testsVisibleInUi).toBeUndefined();
502
+ });
503
+ // ── Client errors integration ─────────────────────────────────────
504
+ it('should mark component as has_errors when clientErrors reports errors', () => {
505
+ const result = computeAudit({
506
+ components: [
507
+ { name: 'DrinkInfo', filePath: 'app/components/DrinkInfo.tsx' },
508
+ ],
509
+ functions: [],
510
+ scenarioCounts: { DrinkInfo: 3 },
511
+ testFileExistence: {},
512
+ clientErrors: {
513
+ DrinkInfo: ['Cannot read properties of undefined'],
514
+ },
515
+ });
516
+ expect(result.components[0].status).toBe('has_errors');
517
+ expect(result.components[0].clientErrors).toEqual([
518
+ 'Cannot read properties of undefined',
519
+ ]);
520
+ expect(result.summary.componentsWithErrors).toBe(1);
521
+ expect(result.summary.allPassing).toBe(false);
522
+ });
523
+ it('should not count client errors for components with no scenarios', () => {
524
+ // If a component has no scenarios AND errors, it's still "missing"
525
+ // (errors come from scenarios, so if there are none, errors are stale)
526
+ const result = computeAudit({
527
+ components: [
528
+ { name: 'DrinkInfo', filePath: 'app/components/DrinkInfo.tsx' },
529
+ ],
530
+ functions: [],
531
+ scenarioCounts: {},
532
+ testFileExistence: {},
533
+ clientErrors: {
534
+ DrinkInfo: ['Cannot read properties of undefined'],
535
+ },
536
+ });
537
+ expect(result.components[0].status).toBe('missing');
538
+ });
539
+ it('should set allPassing false when any component has errors', () => {
540
+ const result = computeAudit({
541
+ components: [
542
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
543
+ { name: 'DrinkInfo', filePath: 'app/components/DrinkInfo.tsx' },
544
+ ],
545
+ functions: [],
546
+ scenarioCounts: { DrinkCard: 2, DrinkInfo: 3 },
547
+ testFileExistence: {},
548
+ clientErrors: {
549
+ DrinkInfo: ['TypeError: something broke'],
550
+ },
551
+ });
552
+ expect(result.summary.allPassing).toBe(false);
553
+ expect(result.summary.componentsOk).toBe(1);
554
+ expect(result.summary.componentsWithErrors).toBe(1);
555
+ });
556
+ });
557
+ // ── filterGlossaryByChangeStatus ──────────────────────────────────
558
+ describe('filterGlossaryByChangeStatus', () => {
559
+ const allEntries = [
560
+ // Feature 1 components (unchanged)
561
+ {
562
+ name: 'StarRating',
563
+ filePath: 'app/components/StarRating.tsx',
564
+ returnType: 'JSX.Element',
565
+ },
566
+ {
567
+ name: 'CategoryBadge',
568
+ filePath: 'app/components/CategoryBadge.tsx',
569
+ returnType: 'JSX.Element',
570
+ },
571
+ {
572
+ name: 'DrinkCard',
573
+ filePath: 'app/components/DrinkCard.tsx',
574
+ returnType: 'JSX.Element',
575
+ },
576
+ // Feature 2 components (new)
577
+ {
578
+ name: 'HeroImage',
579
+ filePath: 'app/components/HeroImage.tsx',
580
+ returnType: 'JSX.Element',
581
+ },
582
+ {
583
+ name: 'ReviewCard',
584
+ filePath: 'app/components/ReviewCard.tsx',
585
+ returnType: 'JSX.Element',
586
+ },
587
+ // Feature 1 function (unchanged)
588
+ {
589
+ name: 'computeAvgRating',
590
+ filePath: 'app/lib/ratings.ts',
591
+ returnType: 'number',
592
+ testFile: 'app/lib/ratings.test.ts',
593
+ },
594
+ // Feature 2 function (new)
595
+ {
596
+ name: 'formatReviewCount',
597
+ filePath: 'app/lib/formatting.ts',
598
+ returnType: 'string',
599
+ testFile: 'app/lib/formatting.test.ts',
600
+ },
601
+ ];
602
+ it('should only include entries whose files are new, edited, or impacted', () => {
603
+ const entityChangeStatus = {
604
+ HeroImage: { status: 'new' },
605
+ ReviewCard: { status: 'new' },
606
+ formatReviewCount: { status: 'new' },
607
+ // DrinkCard edited because it now links to detail page
608
+ DrinkCard: { status: 'edited' },
609
+ // StarRating impacted because DrinkInfo uses it
610
+ StarRating: {
611
+ status: 'impacted',
612
+ impactedBy: [
613
+ {
614
+ name: 'DrinkInfo',
615
+ filePath: 'app/components/DrinkInfo.tsx',
616
+ changeType: 'new',
617
+ },
618
+ ],
619
+ },
620
+ };
621
+ const filtered = filterGlossaryByChangeStatus(allEntries, entityChangeStatus);
622
+ const names = filtered.map((e) => e.name).sort();
623
+ expect(names).toEqual([
624
+ 'DrinkCard',
625
+ 'HeroImage',
626
+ 'ReviewCard',
627
+ 'StarRating',
628
+ 'formatReviewCount',
629
+ ]);
630
+ });
631
+ it('should return all entries when entityChangeStatus is empty', () => {
632
+ // When there's no change status data (e.g., no git changes), fall back to auditing everything
633
+ const filtered = filterGlossaryByChangeStatus(allEntries, {});
634
+ expect(filtered).toEqual(allEntries);
635
+ });
636
+ it('should return all entries when entityChangeStatus is undefined', () => {
637
+ const filtered = filterGlossaryByChangeStatus(allEntries, undefined);
638
+ expect(filtered).toEqual(allEntries);
639
+ });
640
+ it('should exclude unchanged entries that have no status', () => {
641
+ const entityChangeStatus = {
642
+ HeroImage: { status: 'new' },
643
+ };
644
+ const filtered = filterGlossaryByChangeStatus(allEntries, entityChangeStatus);
645
+ expect(filtered).toHaveLength(1);
646
+ expect(filtered[0].name).toBe('HeroImage');
647
+ });
648
+ it('should match entries by filePath when name does not match any status key', () => {
649
+ // Sometimes entity names in entityChangeStatus are derived from file paths
650
+ // and may not exactly match glossary names. Fall back to filePath matching.
651
+ const entityChangeStatus = {
652
+ // Entity name derived differently, but filePath matches
653
+ 'app/components/DrinkCard.tsx': { status: 'edited' },
654
+ };
655
+ const filtered = filterGlossaryByChangeStatus(allEntries, entityChangeStatus);
656
+ expect(filtered.map((e) => e.name)).toContain('DrinkCard');
657
+ });
658
+ });
659
+ // ── resolveAuditSessionScope ──────────────────────────────────────
660
+ describe('resolveAuditSessionScope', () => {
661
+ it('should scope to session when entityChangeStatus has entries and featureStartedAt exists', () => {
662
+ const result = resolveAuditSessionScope({
663
+ featureStartedAt: '2026-03-12T14:01:31.291Z',
664
+ entityChangeStatus: {
665
+ ArticleCard: { status: 'new' },
666
+ LibraryHeader: { status: 'new' },
667
+ },
668
+ });
669
+ expect(result.featureStartedAt).toBe('2026-03-12T14:01:31.291Z');
670
+ expect(result.entityChangeStatus).toEqual({
671
+ ArticleCard: { status: 'new' },
672
+ LibraryHeader: { status: 'new' },
673
+ });
674
+ });
675
+ it('should NOT scope scenario counts to session when entityChangeStatus is empty', () => {
676
+ // This is the testapp bug: entityChangeStatus computation returned empty,
677
+ // so the glossary filter falls back to "audit all components", but the
678
+ // scenario count query still filters by featureStartedAt — causing
679
+ // Feature 1 components to appear as "no scenarios" even though they have them.
680
+ const result = resolveAuditSessionScope({
681
+ featureStartedAt: '2026-03-12T14:01:31.291Z',
682
+ entityChangeStatus: undefined,
683
+ });
684
+ // When we can't scope the glossary, we shouldn't scope scenario counts either
685
+ expect(result.featureStartedAt).toBeNull();
686
+ });
687
+ it('should NOT scope scenario counts to session when entityChangeStatus is an empty object', () => {
688
+ const result = resolveAuditSessionScope({
689
+ featureStartedAt: '2026-03-12T14:01:31.291Z',
690
+ entityChangeStatus: {},
691
+ });
692
+ expect(result.featureStartedAt).toBeNull();
693
+ });
694
+ it('should return null featureStartedAt when none was provided', () => {
695
+ const result = resolveAuditSessionScope({
696
+ featureStartedAt: null,
697
+ entityChangeStatus: { Header: { status: 'new' } },
698
+ });
699
+ expect(result.featureStartedAt).toBeNull();
700
+ });
701
+ it('should pass through entityChangeStatus unchanged when it has entries', () => {
702
+ const ecs = {
703
+ ArticleCard: { status: 'new' },
704
+ Header: { status: 'edited' },
705
+ };
706
+ const result = resolveAuditSessionScope({
707
+ featureStartedAt: '2026-03-12T14:01:31.291Z',
708
+ entityChangeStatus: ecs,
709
+ });
710
+ expect(result.entityChangeStatus).toBe(ecs);
711
+ });
712
+ describe('multi-feature audit scenario (testapp reproduction)', () => {
713
+ // Reproduces the exact testapp bug:
714
+ // - Feature 1 built 8 components with scenarios at 13:28-13:30
715
+ // - Feature 2 starts at 14:01, builds 4 new components with scenarios at 14:14-14:16
716
+ // - entityChangeStatus computation returns empty (fails/returns {})
717
+ // - Glossary includes ALL 12 components
718
+ // - Scenario counts only include Feature 2 scenarios (after 14:01)
719
+ // - Result: Feature 1's 8 components reported as "no scenarios"
720
+ const allComponents = [
721
+ // Feature 1 components
722
+ {
723
+ name: 'Header',
724
+ filePath: 'src/components/Header.tsx',
725
+ returnType: 'JSX.Element',
726
+ },
727
+ {
728
+ name: 'Logo',
729
+ filePath: 'src/components/Logo.tsx',
730
+ returnType: 'JSX.Element',
731
+ },
732
+ {
733
+ name: 'TabBar',
734
+ filePath: 'src/components/TabBar.tsx',
735
+ returnType: 'JSX.Element',
736
+ },
737
+ {
738
+ name: 'ArticlePreview',
739
+ filePath: 'src/components/ArticlePreview.tsx',
740
+ returnType: 'JSX.Element',
741
+ },
742
+ {
743
+ name: 'SaveButton',
744
+ filePath: 'src/components/SaveButton.tsx',
745
+ returnType: 'JSX.Element',
746
+ },
747
+ {
748
+ name: 'StatusBanner',
749
+ filePath: 'src/components/StatusBanner.tsx',
750
+ returnType: 'JSX.Element',
751
+ },
752
+ {
753
+ name: 'EmptyState',
754
+ filePath: 'src/components/EmptyState.tsx',
755
+ returnType: 'JSX.Element',
756
+ },
757
+ {
758
+ name: 'ArticleRow',
759
+ filePath: 'src/components/ArticleRow.tsx',
760
+ returnType: 'JSX.Element',
761
+ },
762
+ // Feature 2 components
763
+ {
764
+ name: 'ArticleCard',
765
+ filePath: 'src/components/ArticleCard.tsx',
766
+ returnType: 'JSX.Element',
767
+ },
768
+ {
769
+ name: 'LibraryHeader',
770
+ filePath: 'src/components/LibraryHeader.tsx',
771
+ returnType: 'JSX.Element',
772
+ },
773
+ {
774
+ name: 'ArticleCardGrid',
775
+ filePath: 'src/components/ArticleCardGrid.tsx',
776
+ returnType: 'JSX.Element',
777
+ },
778
+ {
779
+ name: 'OpenLibraryButton',
780
+ filePath: 'src/components/OpenLibraryButton.tsx',
781
+ returnType: 'JSX.Element',
782
+ },
783
+ ];
784
+ // All scenarios that exist in the DB (both features)
785
+ const allScenarioCounts = {
786
+ Header: 2,
787
+ Logo: 1,
788
+ TabBar: 3,
789
+ ArticlePreview: 4,
790
+ SaveButton: 2,
791
+ StatusBanner: 2,
792
+ EmptyState: 2,
793
+ ArticleRow: 3,
794
+ ArticleCard: 4,
795
+ LibraryHeader: 3,
796
+ ArticleCardGrid: 2,
797
+ OpenLibraryButton: 1,
798
+ };
799
+ // Only Feature 2 scenarios (created after featureStartedAt)
800
+ const sessionScopedCounts = {
801
+ ArticleCard: 4,
802
+ LibraryHeader: 3,
803
+ ArticleCardGrid: 2,
804
+ OpenLibraryButton: 1,
805
+ };
806
+ it('should pass audit when entityChangeStatus is empty and all scenarios are counted', () => {
807
+ // With the fix: resolveAuditSessionScope nullifies featureStartedAt
808
+ // when entityChangeStatus is empty, so ALL scenarios are counted
809
+ const scope = resolveAuditSessionScope({
810
+ featureStartedAt: '2026-03-12T14:01:31.291Z',
811
+ entityChangeStatus: undefined,
812
+ });
813
+ // Glossary filter: returns all (no change status to filter by)
814
+ const filtered = filterGlossaryByChangeStatus(allComponents, scope.entityChangeStatus);
815
+ expect(filtered).toHaveLength(12);
816
+ // Since featureStartedAt is now null, the route would query ALL scenarios
817
+ // (not session-scoped), giving us allScenarioCounts
818
+ const countsToUse = scope.featureStartedAt
819
+ ? sessionScopedCounts
820
+ : allScenarioCounts;
821
+ const { components } = classifyGlossaryEntries(filtered);
822
+ const result = computeAudit({
823
+ components,
824
+ functions: [],
825
+ scenarioCounts: countsToUse,
826
+ testFileExistence: {},
827
+ });
828
+ // Every component should have scenarios
829
+ expect(result.summary.componentsMissing).toBe(0);
830
+ expect(result.summary.componentsOk).toBe(12);
831
+ expect(result.summary.allPassing).toBe(true);
832
+ });
833
+ it('demonstrates the bug: session-scoped counts with unscoped glossary fails Feature 1', () => {
834
+ // WITHOUT the fix: entityChangeStatus is empty so all 12 components are audited,
835
+ // but scenario counts are session-scoped so Feature 1 components get 0
836
+ const filtered = filterGlossaryByChangeStatus(allComponents, undefined);
837
+ expect(filtered).toHaveLength(12);
838
+ const { components } = classifyGlossaryEntries(filtered);
839
+ const result = computeAudit({
840
+ components,
841
+ functions: [],
842
+ scenarioCounts: sessionScopedCounts, // BUG: only Feature 2 scenarios
843
+ testFileExistence: {},
844
+ });
845
+ // This is the broken behavior — 8 components incorrectly flagged
846
+ expect(result.summary.componentsMissing).toBe(8);
847
+ expect(result.summary.allPassing).toBe(false);
848
+ });
849
+ it('should correctly scope audit when entityChangeStatus is available', () => {
850
+ // When entityChangeStatus works, only Feature 2 components are audited
851
+ // and only Feature 2 scenarios are counted — both filters agree
852
+ const ecs = {
853
+ ArticleCard: { status: 'new' },
854
+ LibraryHeader: { status: 'new' },
855
+ ArticleCardGrid: { status: 'new' },
856
+ OpenLibraryButton: { status: 'new' },
857
+ };
858
+ const scope = resolveAuditSessionScope({
859
+ featureStartedAt: '2026-03-12T14:01:31.291Z',
860
+ entityChangeStatus: ecs,
861
+ });
862
+ // featureStartedAt preserved — session scoping is valid
863
+ expect(scope.featureStartedAt).toBe('2026-03-12T14:01:31.291Z');
864
+ const filtered = filterGlossaryByChangeStatus(allComponents, scope.entityChangeStatus);
865
+ expect(filtered).toHaveLength(4); // Only Feature 2 components
866
+ const { components } = classifyGlossaryEntries(filtered);
867
+ const result = computeAudit({
868
+ components,
869
+ functions: [],
870
+ scenarioCounts: sessionScopedCounts,
871
+ testFileExistence: {},
872
+ });
873
+ expect(result.summary.componentsMissing).toBe(0);
874
+ expect(result.summary.componentsOk).toBe(4);
875
+ expect(result.summary.allPassing).toBe(true);
876
+ });
877
+ });
878
+ });
879
+ // ── queryScenarioCounts ─────────────────────────────────────────────
880
+ describe('queryScenarioCounts', () => {
881
+ let db;
882
+ let rawDb;
883
+ const projectId = 'test-project-id';
884
+ beforeEach(async () => {
885
+ rawDb = new Database(':memory:');
886
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
887
+ await db.schema
888
+ .createTable('editor_scenarios')
889
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
890
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
891
+ .addColumn('name', 'varchar', (col) => col.notNull())
892
+ .addColumn('description', 'text')
893
+ .addColumn('component_name', 'varchar')
894
+ .addColumn('component_path', 'varchar')
895
+ .addColumn('url', 'varchar')
896
+ .addColumn('type', 'varchar')
897
+ .addColumn('screenshot_path', 'varchar')
898
+ .addColumn('viewport_width', 'integer')
899
+ .addColumn('viewport_height', 'integer')
900
+ .addColumn('dimension', 'varchar')
901
+ .addColumn('created_at', 'datetime')
902
+ .addColumn('updated_at', 'datetime')
903
+ .execute();
904
+ });
905
+ afterEach(async () => {
906
+ await db.destroy();
907
+ });
908
+ it('should count all scenarios when featureStartedAt is null', async () => {
909
+ await db
910
+ .insertInto('editor_scenarios')
911
+ .values({
912
+ id: 'sc-1',
913
+ project_id: projectId,
914
+ name: 'ArticleRow - Default',
915
+ component_name: 'ArticleRow',
916
+ viewport_width: 1280,
917
+ viewport_height: 720,
918
+ created_at: '2026-03-12 13:00:00',
919
+ })
920
+ .execute();
921
+ const counts = await queryScenarioCounts(db, projectId, null);
922
+ expect(counts).toEqual({ ArticleRow: 1 });
923
+ });
924
+ it('should count scenarios created after featureStartedAt', async () => {
925
+ await db
926
+ .insertInto('editor_scenarios')
927
+ .values({
928
+ id: 'sc-1',
929
+ project_id: projectId,
930
+ name: 'ArticleRow - Default',
931
+ component_name: 'ArticleRow',
932
+ viewport_width: 1280,
933
+ viewport_height: 720,
934
+ created_at: '2026-03-12 14:30:00',
935
+ })
936
+ .execute();
937
+ const counts = await queryScenarioCounts(db, projectId, '2026-03-12T14:01:31.291Z');
938
+ expect(counts).toEqual({ ArticleRow: 1 });
939
+ });
940
+ it('should exclude scenarios created before featureStartedAt', async () => {
941
+ await db
942
+ .insertInto('editor_scenarios')
943
+ .values({
944
+ id: 'sc-1',
945
+ project_id: projectId,
946
+ name: 'ArticleRow - Default',
947
+ component_name: 'ArticleRow',
948
+ viewport_width: 1280,
949
+ viewport_height: 720,
950
+ created_at: '2026-03-12 13:00:00',
951
+ })
952
+ .execute();
953
+ const counts = await queryScenarioCounts(db, projectId, '2026-03-12T14:01:31.291Z');
954
+ expect(counts).toEqual({});
955
+ });
956
+ it('should count re-registered scenarios whose updated_at is after featureStartedAt', async () => {
957
+ // This is the bug: a scenario from Feature 1 (created_at before featureStartedAt)
958
+ // is re-registered in Feature 2 (updated_at after featureStartedAt).
959
+ // The audit should count it because it was actively re-registered in this session.
960
+ await db
961
+ .insertInto('editor_scenarios')
962
+ .values({
963
+ id: 'sc-1',
964
+ project_id: projectId,
965
+ name: 'ArticleRow - Default',
966
+ component_name: 'ArticleRow',
967
+ viewport_width: 400,
968
+ viewport_height: 600,
969
+ created_at: '2026-03-12 13:28:00', // Feature 1
970
+ updated_at: '2026-03-12 14:32:00', // Re-registered in Feature 2
971
+ })
972
+ .execute();
973
+ const counts = await queryScenarioCounts(db, projectId, '2026-03-12T14:01:31.291Z');
974
+ // Should count because updated_at is after featureStartedAt
975
+ expect(counts).toEqual({ ArticleRow: 1 });
976
+ });
977
+ it('should handle mixed scenarios: some new, some re-registered', async () => {
978
+ // ArticleCard: new in Feature 2 (created_at after featureStartedAt)
979
+ await db
980
+ .insertInto('editor_scenarios')
981
+ .values({
982
+ id: 'sc-1',
983
+ project_id: projectId,
984
+ name: 'ArticleCard - Default',
985
+ component_name: 'ArticleCard',
986
+ viewport_width: 1280,
987
+ viewport_height: 720,
988
+ created_at: '2026-03-12 14:14:00',
989
+ })
990
+ .execute();
991
+ // ArticleRow: from Feature 1, re-registered in Feature 2
992
+ await db
993
+ .insertInto('editor_scenarios')
994
+ .values({
995
+ id: 'sc-2',
996
+ project_id: projectId,
997
+ name: 'ArticleRow - Default',
998
+ component_name: 'ArticleRow',
999
+ viewport_width: 400,
1000
+ viewport_height: 600,
1001
+ created_at: '2026-03-12 13:28:00', // Feature 1
1002
+ updated_at: '2026-03-12 14:32:00', // Re-registered in Feature 2
1003
+ })
1004
+ .execute();
1005
+ const counts = await queryScenarioCounts(db, projectId, '2026-03-12T14:01:31.291Z');
1006
+ expect(counts).toEqual({ ArticleCard: 1, ArticleRow: 1 });
1007
+ });
1008
+ });
1009
+ // ── queryPageScenarioCounts ──────────────────────────────────────────
1010
+ describe('queryPageScenarioCounts', () => {
1011
+ let db;
1012
+ let rawDb;
1013
+ const projectId = 'test-project-id';
1014
+ beforeEach(async () => {
1015
+ rawDb = new Database(':memory:');
1016
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
1017
+ await db.schema
1018
+ .createTable('editor_scenarios')
1019
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1020
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
1021
+ .addColumn('name', 'varchar', (col) => col.notNull())
1022
+ .addColumn('description', 'text')
1023
+ .addColumn('component_name', 'varchar')
1024
+ .addColumn('component_path', 'varchar')
1025
+ .addColumn('page_file_path', 'varchar')
1026
+ .addColumn('url', 'varchar')
1027
+ .addColumn('type', 'varchar')
1028
+ .addColumn('screenshot_path', 'varchar')
1029
+ .addColumn('viewport_width', 'integer')
1030
+ .addColumn('viewport_height', 'integer')
1031
+ .addColumn('dimension', 'varchar')
1032
+ .addColumn('created_at', 'datetime')
1033
+ .addColumn('updated_at', 'datetime')
1034
+ .execute();
1035
+ });
1036
+ afterEach(async () => {
1037
+ await db.destroy();
1038
+ });
1039
+ it('should count app-level scenarios by page_file_path', async () => {
1040
+ // App-level scenario: has page_file_path but no component_name
1041
+ await db
1042
+ .insertInto('editor_scenarios')
1043
+ .values({
1044
+ id: 'sc-1',
1045
+ project_id: projectId,
1046
+ name: 'Library - Default',
1047
+ component_name: null,
1048
+ page_file_path: 'app/library/page.tsx',
1049
+ created_at: '2026-03-12 13:00:00',
1050
+ })
1051
+ .execute();
1052
+ await db
1053
+ .insertInto('editor_scenarios')
1054
+ .values({
1055
+ id: 'sc-2',
1056
+ project_id: projectId,
1057
+ name: 'Library - Empty',
1058
+ component_name: null,
1059
+ page_file_path: 'app/library/page.tsx',
1060
+ created_at: '2026-03-12 13:05:00',
1061
+ })
1062
+ .execute();
1063
+ const counts = await queryPageScenarioCounts(db, projectId, null);
1064
+ expect(counts).toEqual({ 'app/library/page.tsx': 2 });
1065
+ });
1066
+ it('should not count component scenarios (those have component_name)', async () => {
1067
+ // Component scenario — should NOT appear in page counts
1068
+ await db
1069
+ .insertInto('editor_scenarios')
1070
+ .values({
1071
+ id: 'sc-1',
1072
+ project_id: projectId,
1073
+ name: 'ArticleRow - Default',
1074
+ component_name: 'ArticleRow',
1075
+ page_file_path: null,
1076
+ created_at: '2026-03-12 13:00:00',
1077
+ })
1078
+ .execute();
1079
+ const counts = await queryPageScenarioCounts(db, projectId, null);
1080
+ expect(counts).toEqual({});
1081
+ });
1082
+ it('should respect featureStartedAt filter', async () => {
1083
+ await db
1084
+ .insertInto('editor_scenarios')
1085
+ .values({
1086
+ id: 'sc-1',
1087
+ project_id: projectId,
1088
+ name: 'Library - Old',
1089
+ component_name: null,
1090
+ page_file_path: 'app/library/page.tsx',
1091
+ created_at: '2026-03-12 13:00:00',
1092
+ })
1093
+ .execute();
1094
+ await db
1095
+ .insertInto('editor_scenarios')
1096
+ .values({
1097
+ id: 'sc-2',
1098
+ project_id: projectId,
1099
+ name: 'Library - New',
1100
+ component_name: null,
1101
+ page_file_path: 'app/library/page.tsx',
1102
+ created_at: '2026-03-12 15:00:00',
1103
+ })
1104
+ .execute();
1105
+ const counts = await queryPageScenarioCounts(db, projectId, '2026-03-12T14:01:31.291Z');
1106
+ expect(counts).toEqual({ 'app/library/page.tsx': 1 });
1107
+ });
1108
+ it('should count re-registered page scenarios via updated_at', async () => {
1109
+ await db
1110
+ .insertInto('editor_scenarios')
1111
+ .values({
1112
+ id: 'sc-1',
1113
+ project_id: projectId,
1114
+ name: 'Library - Default',
1115
+ component_name: null,
1116
+ page_file_path: 'app/library/page.tsx',
1117
+ created_at: '2026-03-12 13:00:00',
1118
+ updated_at: '2026-03-12 15:00:00',
1119
+ })
1120
+ .execute();
1121
+ const counts = await queryPageScenarioCounts(db, projectId, '2026-03-12T14:01:31.291Z');
1122
+ expect(counts).toEqual({ 'app/library/page.tsx': 1 });
1123
+ });
1124
+ it('should group counts by page_file_path across multiple pages', async () => {
1125
+ await db
1126
+ .insertInto('editor_scenarios')
1127
+ .values([
1128
+ {
1129
+ id: 'sc-1',
1130
+ project_id: projectId,
1131
+ name: 'Library - Default',
1132
+ component_name: null,
1133
+ page_file_path: 'app/library/page.tsx',
1134
+ created_at: '2026-03-12 13:00:00',
1135
+ },
1136
+ {
1137
+ id: 'sc-2',
1138
+ project_id: projectId,
1139
+ name: 'Library - Rich',
1140
+ component_name: null,
1141
+ page_file_path: 'app/library/page.tsx',
1142
+ created_at: '2026-03-12 13:00:00',
1143
+ },
1144
+ {
1145
+ id: 'sc-3',
1146
+ project_id: projectId,
1147
+ name: 'Collections - Default',
1148
+ component_name: null,
1149
+ page_file_path: 'app/library/collections/page.tsx',
1150
+ created_at: '2026-03-12 13:00:00',
1151
+ },
1152
+ ])
1153
+ .execute();
1154
+ const counts = await queryPageScenarioCounts(db, projectId, null);
1155
+ expect(counts).toEqual({
1156
+ 'app/library/page.tsx': 2,
1157
+ 'app/library/collections/page.tsx': 1,
1158
+ });
1159
+ });
1160
+ });
1161
+ // ── Audit + entity completeness integration ─────────────────────────
1162
+ describe('audit should catch incomplete entities (bug reproduction)', () => {
1163
+ let db;
1164
+ let rawDb;
1165
+ const projectId = 'test-project-id';
1166
+ beforeEach(async () => {
1167
+ rawDb = new Database(':memory:');
1168
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
1169
+ await db.schema
1170
+ .createTable('editor_scenarios')
1171
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1172
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
1173
+ .addColumn('name', 'varchar', (col) => col.notNull())
1174
+ .addColumn('component_name', 'varchar')
1175
+ .addColumn('component_path', 'varchar')
1176
+ .addColumn('entity_sha', 'varchar')
1177
+ .addColumn('display_name', 'varchar')
1178
+ .addColumn('page_file_path', 'varchar')
1179
+ .addColumn('url', 'varchar')
1180
+ .addColumn('created_at', 'datetime')
1181
+ .addColumn('updated_at', 'datetime')
1182
+ .execute();
1183
+ await db.schema
1184
+ .createTable('analyses')
1185
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1186
+ .addColumn('entity_sha', 'varchar')
1187
+ .addColumn('entity_name', 'varchar')
1188
+ .addColumn('project_id', 'varchar')
1189
+ .execute();
1190
+ await db.schema
1191
+ .createTable('entities')
1192
+ .addColumn('sha', 'varchar', (col) => col.primaryKey())
1193
+ .addColumn('name', 'varchar')
1194
+ .addColumn('entity_type', 'varchar')
1195
+ .addColumn('file_path', 'varchar')
1196
+ .execute();
1197
+ });
1198
+ afterEach(async () => {
1199
+ await db.destroy();
1200
+ });
1201
+ it('demonstrates the bug: computeAudit passes but entities are incomplete', async () => {
1202
+ // Setup: Two components in glossary, both have scenarios registered.
1203
+ // CollectionChips has scenarios but NO analysis records — it's "incomplete."
1204
+ // The glossary-based audit (computeAudit) doesn't know about entity analyses
1205
+ // so it says allPassing: true. This is the bug.
1206
+ // Entities in DB
1207
+ await db
1208
+ .insertInto('entities')
1209
+ .values({
1210
+ sha: 'sha-header',
1211
+ name: 'Header',
1212
+ entity_type: 'visual',
1213
+ file_path: 'src/components/Header.tsx',
1214
+ })
1215
+ .execute();
1216
+ await db
1217
+ .insertInto('entities')
1218
+ .values({
1219
+ sha: 'sha-chips',
1220
+ name: 'CollectionChips',
1221
+ entity_type: 'visual',
1222
+ file_path: 'src/components/CollectionChips.tsx',
1223
+ })
1224
+ .execute();
1225
+ // Header has an analysis — it's complete
1226
+ await db
1227
+ .insertInto('analyses')
1228
+ .values({
1229
+ id: 'a-1',
1230
+ entity_sha: 'sha-header',
1231
+ entity_name: 'Header',
1232
+ project_id: projectId,
1233
+ })
1234
+ .execute();
1235
+ // CollectionChips has NO analysis — it's incomplete
1236
+ // Both have scenarios
1237
+ await db
1238
+ .insertInto('editor_scenarios')
1239
+ .values({
1240
+ id: 'sc-1',
1241
+ project_id: projectId,
1242
+ name: 'Header - Default',
1243
+ component_name: 'Header',
1244
+ entity_sha: 'sha-header',
1245
+ created_at: '2026-03-16 23:00:00',
1246
+ })
1247
+ .execute();
1248
+ await db
1249
+ .insertInto('editor_scenarios')
1250
+ .values({
1251
+ id: 'sc-2',
1252
+ project_id: projectId,
1253
+ name: 'CollectionChips - Default',
1254
+ component_name: 'CollectionChips',
1255
+ entity_sha: 'sha-chips',
1256
+ created_at: '2026-03-16 23:19:00',
1257
+ })
1258
+ .execute();
1259
+ await db
1260
+ .insertInto('editor_scenarios')
1261
+ .values({
1262
+ id: 'sc-3',
1263
+ project_id: projectId,
1264
+ name: 'CollectionChips - Many',
1265
+ component_name: 'CollectionChips',
1266
+ entity_sha: 'sha-chips',
1267
+ created_at: '2026-03-16 23:19:05',
1268
+ })
1269
+ .execute();
1270
+ // The glossary says both are components with scenarios
1271
+ const scenarioCounts = await queryScenarioCounts(db, projectId, null);
1272
+ expect(scenarioCounts).toEqual({ Header: 1, CollectionChips: 2 });
1273
+ // computeAudit only checks glossary coverage — it passes!
1274
+ const auditResult = computeAudit({
1275
+ components: [
1276
+ {
1277
+ name: 'Header',
1278
+ filePath: 'src/components/Header.tsx',
1279
+ returnType: 'JSX.Element',
1280
+ },
1281
+ {
1282
+ name: 'CollectionChips',
1283
+ filePath: 'src/components/CollectionChips.tsx',
1284
+ returnType: 'JSX.Element',
1285
+ },
1286
+ ],
1287
+ functions: [],
1288
+ scenarioCounts,
1289
+ testFileExistence: {},
1290
+ });
1291
+ // BUG: computeAudit alone says everything is fine
1292
+ expect(auditResult.summary.allPassing).toBe(true);
1293
+ expect(auditResult.summary.componentsOk).toBe(2);
1294
+ // But queryIncompleteEntities catches the real issue
1295
+ const incomplete = await queryIncompleteEntities(db, projectId, null);
1296
+ expect(incomplete).toHaveLength(1);
1297
+ expect(incomplete[0].name).toBe('CollectionChips');
1298
+ expect(incomplete[0].scenarioCount).toBe(2);
1299
+ });
1300
+ it('audit should fail when combining computeAudit with incomplete entity check', async () => {
1301
+ // Same setup as above — this test shows the FIX working:
1302
+ // after computeAudit, we also check queryIncompleteEntities,
1303
+ // and if any are found, allPassing becomes false.
1304
+ await db
1305
+ .insertInto('entities')
1306
+ .values({
1307
+ sha: 'sha-header',
1308
+ name: 'Header',
1309
+ entity_type: 'visual',
1310
+ file_path: 'src/components/Header.tsx',
1311
+ })
1312
+ .execute();
1313
+ await db
1314
+ .insertInto('entities')
1315
+ .values({
1316
+ sha: 'sha-chips',
1317
+ name: 'CollectionChips',
1318
+ entity_type: 'visual',
1319
+ file_path: 'src/components/CollectionChips.tsx',
1320
+ })
1321
+ .execute();
1322
+ await db
1323
+ .insertInto('analyses')
1324
+ .values({
1325
+ id: 'a-1',
1326
+ entity_sha: 'sha-header',
1327
+ entity_name: 'Header',
1328
+ project_id: projectId,
1329
+ })
1330
+ .execute();
1331
+ await db
1332
+ .insertInto('editor_scenarios')
1333
+ .values({
1334
+ id: 'sc-1',
1335
+ project_id: projectId,
1336
+ name: 'Header - Default',
1337
+ component_name: 'Header',
1338
+ entity_sha: 'sha-header',
1339
+ created_at: '2026-03-16 23:00:00',
1340
+ })
1341
+ .execute();
1342
+ await db
1343
+ .insertInto('editor_scenarios')
1344
+ .values({
1345
+ id: 'sc-2',
1346
+ project_id: projectId,
1347
+ name: 'CollectionChips - Default',
1348
+ component_name: 'CollectionChips',
1349
+ entity_sha: 'sha-chips',
1350
+ created_at: '2026-03-16 23:19:00',
1351
+ })
1352
+ .execute();
1353
+ const scenarioCounts = await queryScenarioCounts(db, projectId, null);
1354
+ const auditResult = computeAudit({
1355
+ components: [
1356
+ {
1357
+ name: 'Header',
1358
+ filePath: 'src/components/Header.tsx',
1359
+ returnType: 'JSX.Element',
1360
+ },
1361
+ {
1362
+ name: 'CollectionChips',
1363
+ filePath: 'src/components/CollectionChips.tsx',
1364
+ returnType: 'JSX.Element',
1365
+ },
1366
+ ],
1367
+ functions: [],
1368
+ scenarioCounts,
1369
+ testFileExistence: {},
1370
+ });
1371
+ // Apply the same post-processing the audit endpoint does
1372
+ const incomplete = await queryIncompleteEntities(db, projectId, null);
1373
+ if (incomplete.length > 0) {
1374
+ auditResult.summary.allPassing = false;
1375
+ auditResult.summary.incompleteEntities = incomplete.length;
1376
+ }
1377
+ // NOW the audit correctly fails
1378
+ expect(auditResult.summary.allPassing).toBe(false);
1379
+ expect(auditResult.summary.incompleteEntities).toBe(1);
1380
+ });
1381
+ it('audit should pass when all entities have analyses', async () => {
1382
+ // Both entities have analyses — everything is complete
1383
+ await db
1384
+ .insertInto('entities')
1385
+ .values({
1386
+ sha: 'sha-header',
1387
+ name: 'Header',
1388
+ entity_type: 'visual',
1389
+ file_path: 'src/components/Header.tsx',
1390
+ })
1391
+ .execute();
1392
+ await db
1393
+ .insertInto('entities')
1394
+ .values({
1395
+ sha: 'sha-chips',
1396
+ name: 'CollectionChips',
1397
+ entity_type: 'visual',
1398
+ file_path: 'src/components/CollectionChips.tsx',
1399
+ })
1400
+ .execute();
1401
+ await db
1402
+ .insertInto('analyses')
1403
+ .values({
1404
+ id: 'a-1',
1405
+ entity_sha: 'sha-header',
1406
+ entity_name: 'Header',
1407
+ project_id: projectId,
1408
+ })
1409
+ .execute();
1410
+ await db
1411
+ .insertInto('analyses')
1412
+ .values({
1413
+ id: 'a-2',
1414
+ entity_sha: 'sha-chips',
1415
+ entity_name: 'CollectionChips',
1416
+ project_id: projectId,
1417
+ })
1418
+ .execute();
1419
+ await db
1420
+ .insertInto('editor_scenarios')
1421
+ .values({
1422
+ id: 'sc-1',
1423
+ project_id: projectId,
1424
+ name: 'Header - Default',
1425
+ component_name: 'Header',
1426
+ entity_sha: 'sha-header',
1427
+ created_at: '2026-03-16 23:00:00',
1428
+ })
1429
+ .execute();
1430
+ await db
1431
+ .insertInto('editor_scenarios')
1432
+ .values({
1433
+ id: 'sc-2',
1434
+ project_id: projectId,
1435
+ name: 'CollectionChips - Default',
1436
+ component_name: 'CollectionChips',
1437
+ entity_sha: 'sha-chips',
1438
+ created_at: '2026-03-16 23:19:00',
1439
+ })
1440
+ .execute();
1441
+ const scenarioCounts = await queryScenarioCounts(db, projectId, null);
1442
+ const auditResult = computeAudit({
1443
+ components: [
1444
+ {
1445
+ name: 'Header',
1446
+ filePath: 'src/components/Header.tsx',
1447
+ returnType: 'JSX.Element',
1448
+ },
1449
+ {
1450
+ name: 'CollectionChips',
1451
+ filePath: 'src/components/CollectionChips.tsx',
1452
+ returnType: 'JSX.Element',
1453
+ },
1454
+ ],
1455
+ functions: [],
1456
+ scenarioCounts,
1457
+ testFileExistence: {},
1458
+ });
1459
+ const incomplete = await queryIncompleteEntities(db, projectId, null);
1460
+ if (incomplete.length > 0) {
1461
+ auditResult.summary.allPassing = false;
1462
+ auditResult.summary.incompleteEntities = incomplete.length;
1463
+ }
1464
+ // Everything complete — audit passes
1465
+ expect(auditResult.summary.allPassing).toBe(true);
1466
+ expect(auditResult.summary.incompleteEntities).toBeUndefined();
1467
+ });
1468
+ });
1469
+ // ── filterToIncompleteFilePaths ──────────────────────────────────────
1470
+ describe('filterToIncompleteFilePaths', () => {
1471
+ // analyze-imports processes ALL file paths (~120 files) even when only
1472
+ // a few need analysis. This function filters to files that have no
1473
+ // entity with an analysis record.
1474
+ let db;
1475
+ let rawDb;
1476
+ const projectId = 'test-project-id';
1477
+ beforeEach(async () => {
1478
+ rawDb = new Database(':memory:');
1479
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
1480
+ await db.schema
1481
+ .createTable('analyses')
1482
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1483
+ .addColumn('entity_sha', 'varchar')
1484
+ .addColumn('entity_name', 'varchar')
1485
+ .addColumn('project_id', 'varchar')
1486
+ .execute();
1487
+ await db.schema
1488
+ .createTable('entities')
1489
+ .addColumn('sha', 'varchar', (col) => col.primaryKey())
1490
+ .addColumn('name', 'varchar')
1491
+ .addColumn('entity_type', 'varchar')
1492
+ .addColumn('file_path', 'varchar')
1493
+ .execute();
1494
+ });
1495
+ afterEach(async () => {
1496
+ await db.destroy();
1497
+ });
1498
+ it('should exclude files that have an entity with an analysis', async () => {
1499
+ const { filterToIncompleteFilePaths } = require('../editorAudit');
1500
+ // Entity with analysis — skip
1501
+ await db
1502
+ .insertInto('entities')
1503
+ .values({
1504
+ sha: 'sha-header',
1505
+ name: 'Header',
1506
+ entity_type: 'visual',
1507
+ file_path: 'app/components/Header.tsx',
1508
+ })
1509
+ .execute();
1510
+ await db
1511
+ .insertInto('analyses')
1512
+ .values({
1513
+ id: 'a-1',
1514
+ entity_sha: 'sha-header',
1515
+ entity_name: 'Header',
1516
+ project_id: projectId,
1517
+ })
1518
+ .execute();
1519
+ // Entity without analysis — needs analysis
1520
+ await db
1521
+ .insertInto('entities')
1522
+ .values({
1523
+ sha: 'sha-rule',
1524
+ name: 'RuleBuilder',
1525
+ entity_type: 'visual',
1526
+ file_path: 'app/components/RuleBuilder.tsx',
1527
+ })
1528
+ .execute();
1529
+ const allFilePaths = [
1530
+ 'app/components/Header.tsx',
1531
+ 'app/components/RuleBuilder.tsx',
1532
+ 'app/components/Footer.tsx', // no entity — needs analysis
1533
+ ];
1534
+ const result = await filterToIncompleteFilePaths(db, projectId, allFilePaths);
1535
+ expect(result).toContain('app/components/RuleBuilder.tsx');
1536
+ expect(result).toContain('app/components/Footer.tsx');
1537
+ expect(result).not.toContain('app/components/Header.tsx');
1538
+ });
1539
+ it('should return all file paths when no entities exist yet', async () => {
1540
+ const { filterToIncompleteFilePaths } = require('../editorAudit');
1541
+ const filePaths = ['app/Foo.tsx', 'app/Bar.tsx'];
1542
+ const result = await filterToIncompleteFilePaths(db, projectId, filePaths);
1543
+ expect(result).toEqual(filePaths);
1544
+ });
1545
+ it('should return empty when all files have analyzed entities', async () => {
1546
+ const { filterToIncompleteFilePaths } = require('../editorAudit');
1547
+ await db
1548
+ .insertInto('entities')
1549
+ .values({
1550
+ sha: 'sha-a',
1551
+ name: 'CompA',
1552
+ entity_type: 'visual',
1553
+ file_path: 'app/CompA.tsx',
1554
+ })
1555
+ .execute();
1556
+ await db
1557
+ .insertInto('analyses')
1558
+ .values({
1559
+ id: 'a-1',
1560
+ entity_sha: 'sha-a',
1561
+ entity_name: 'CompA',
1562
+ project_id: projectId,
1563
+ })
1564
+ .execute();
1565
+ const result = await filterToIncompleteFilePaths(db, projectId, [
1566
+ 'app/CompA.tsx',
1567
+ ]);
1568
+ expect(result).toEqual([]);
1569
+ });
1570
+ it('should skip files with analysis even without scenarios', async () => {
1571
+ const { filterToIncompleteFilePaths } = require('../editorAudit');
1572
+ // Entity with analysis but NO scenarios — still complete
1573
+ await db
1574
+ .insertInto('entities')
1575
+ .values({
1576
+ sha: 'sha-util',
1577
+ name: 'utils',
1578
+ entity_type: 'library',
1579
+ file_path: 'app/lib/utils.ts',
1580
+ })
1581
+ .execute();
1582
+ await db
1583
+ .insertInto('analyses')
1584
+ .values({
1585
+ id: 'a-1',
1586
+ entity_sha: 'sha-util',
1587
+ entity_name: 'utils',
1588
+ project_id: projectId,
1589
+ })
1590
+ .execute();
1591
+ const result = await filterToIncompleteFilePaths(db, projectId, [
1592
+ 'app/lib/utils.ts',
1593
+ ]);
1594
+ expect(result).toEqual([]);
1595
+ });
1596
+ });
1597
+ // ── phantom entity SHAs ─────────────────────────────────────────────
1598
+ describe('queryIncompleteEntities with phantom entity SHAs', () => {
1599
+ // Root cause of the Margo/reader step-blocking bug:
1600
+ // Scenarios registered without component_path got a phantom entity_sha
1601
+ // computed from component_name alone. These SHAs have NO entity record
1602
+ // in the entities table and NO analyses. syncScenarioEntityShas can't
1603
+ // fix them (it skips scenarios without component_path). So they remain
1604
+ // "incomplete" forever, blocking step progression.
1605
+ //
1606
+ // Fix: queryIncompleteEntities should not report scenarios whose
1607
+ // entity_sha has no entity record — these are orphaned data, not
1608
+ // fixable by running analyze-imports.
1609
+ let db;
1610
+ let rawDb;
1611
+ const projectId = 'test-project-id';
1612
+ beforeEach(async () => {
1613
+ rawDb = new Database(':memory:');
1614
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
1615
+ await db.schema
1616
+ .createTable('editor_scenarios')
1617
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1618
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
1619
+ .addColumn('name', 'varchar', (col) => col.notNull())
1620
+ .addColumn('component_name', 'varchar')
1621
+ .addColumn('component_path', 'varchar')
1622
+ .addColumn('entity_sha', 'varchar')
1623
+ .addColumn('display_name', 'varchar')
1624
+ .addColumn('page_file_path', 'varchar')
1625
+ .addColumn('url', 'varchar')
1626
+ .addColumn('created_at', 'datetime')
1627
+ .addColumn('updated_at', 'datetime')
1628
+ .execute();
1629
+ await db.schema
1630
+ .createTable('analyses')
1631
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1632
+ .addColumn('entity_sha', 'varchar')
1633
+ .addColumn('entity_name', 'varchar')
1634
+ .addColumn('project_id', 'varchar')
1635
+ .execute();
1636
+ await db.schema
1637
+ .createTable('entities')
1638
+ .addColumn('sha', 'varchar', (col) => col.primaryKey())
1639
+ .addColumn('name', 'varchar')
1640
+ .addColumn('entity_type', 'varchar')
1641
+ .addColumn('file_path', 'varchar')
1642
+ .execute();
1643
+ });
1644
+ afterEach(async () => {
1645
+ await db.destroy();
1646
+ });
1647
+ it('should not report scenarios with phantom entity SHAs (no entity record exists)', async () => {
1648
+ // Real entity — has an entity record, analyses, and scenarios. Complete.
1649
+ await db
1650
+ .insertInto('entities')
1651
+ .values({
1652
+ sha: 'sha-real',
1653
+ name: 'RuleBuilder',
1654
+ entity_type: 'visual',
1655
+ file_path: 'app/components/RuleBuilder.tsx',
1656
+ })
1657
+ .execute();
1658
+ await db
1659
+ .insertInto('analyses')
1660
+ .values({
1661
+ id: 'a-1',
1662
+ entity_sha: 'sha-real',
1663
+ entity_name: 'RuleBuilder',
1664
+ project_id: projectId,
1665
+ })
1666
+ .execute();
1667
+ await db
1668
+ .insertInto('editor_scenarios')
1669
+ .values({
1670
+ id: 'sc-good',
1671
+ project_id: projectId,
1672
+ name: 'RuleBuilder - Empty',
1673
+ component_name: 'RuleBuilder',
1674
+ component_path: 'app/components/RuleBuilder.tsx',
1675
+ entity_sha: 'sha-real',
1676
+ created_at: '2026-03-16 23:00:00',
1677
+ })
1678
+ .execute();
1679
+ // Phantom entity — scenario points to a SHA that doesn't exist
1680
+ // in the entities table (registered without component_path).
1681
+ // No entity record, no analyses, unfixable by analyze-imports.
1682
+ await db
1683
+ .insertInto('editor_scenarios')
1684
+ .values({
1685
+ id: 'sc-phantom',
1686
+ project_id: projectId,
1687
+ name: 'Empty',
1688
+ component_name: 'RuleBuilder',
1689
+ component_path: null,
1690
+ entity_sha: 'sha-phantom-no-entity-record',
1691
+ created_at: '2026-03-16 22:00:00',
1692
+ })
1693
+ .execute();
1694
+ const incomplete = await queryIncompleteEntities(db, projectId, null);
1695
+ // Should NOT report phantom SHAs as incomplete — they can't be fixed
1696
+ // by running analyze-imports (no entity record exists to resolve).
1697
+ expect(incomplete).toHaveLength(0);
1698
+ });
1699
+ it('should still report real incomplete entities (entity exists but no analysis)', async () => {
1700
+ // Real entity without analysis — this IS a legitimate incomplete entity
1701
+ await db
1702
+ .insertInto('entities')
1703
+ .values({
1704
+ sha: 'sha-noanalysis',
1705
+ name: 'Footer',
1706
+ entity_type: 'visual',
1707
+ file_path: 'app/components/Footer.tsx',
1708
+ })
1709
+ .execute();
1710
+ await db
1711
+ .insertInto('editor_scenarios')
1712
+ .values({
1713
+ id: 'sc-1',
1714
+ project_id: projectId,
1715
+ name: 'Footer - Default',
1716
+ component_name: 'Footer',
1717
+ component_path: 'app/components/Footer.tsx',
1718
+ entity_sha: 'sha-noanalysis',
1719
+ created_at: '2026-03-16 23:00:00',
1720
+ })
1721
+ .execute();
1722
+ // Phantom scenario (shouldn't affect results)
1723
+ await db
1724
+ .insertInto('editor_scenarios')
1725
+ .values({
1726
+ id: 'sc-phantom',
1727
+ project_id: projectId,
1728
+ name: 'Footer - Alt',
1729
+ component_name: 'Footer',
1730
+ component_path: null,
1731
+ entity_sha: 'sha-phantom-does-not-exist',
1732
+ created_at: '2026-03-16 22:00:00',
1733
+ })
1734
+ .execute();
1735
+ const incomplete = await queryIncompleteEntities(db, projectId, null);
1736
+ // Should report Footer (real entity, no analysis) but NOT the phantom
1737
+ expect(incomplete).toHaveLength(1);
1738
+ expect(incomplete[0].name).toBe('Footer');
1739
+ expect(incomplete[0].entitySha).toBe('sha-noanalysis');
1740
+ });
1741
+ });
1742
+ // ── queryMiscategorizedScenarios ─────────────────────────────────────
1743
+ describe('queryMiscategorizedScenarios', () => {
1744
+ let db;
1745
+ let rawDb;
1746
+ const projectId = 'test-project-id';
1747
+ beforeEach(async () => {
1748
+ rawDb = new Database(':memory:');
1749
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
1750
+ await db.schema
1751
+ .createTable('editor_scenarios')
1752
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1753
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
1754
+ .addColumn('name', 'varchar', (col) => col.notNull())
1755
+ .addColumn('component_name', 'varchar')
1756
+ .addColumn('component_path', 'varchar')
1757
+ .addColumn('entity_sha', 'varchar')
1758
+ .addColumn('display_name', 'varchar')
1759
+ .addColumn('page_file_path', 'varchar')
1760
+ .addColumn('url', 'varchar')
1761
+ .addColumn('created_at', 'datetime')
1762
+ .addColumn('updated_at', 'datetime')
1763
+ .execute();
1764
+ });
1765
+ afterEach(async () => {
1766
+ await db.destroy();
1767
+ });
1768
+ it('should return empty when all component scenarios use isolation routes', async () => {
1769
+ await db
1770
+ .insertInto('editor_scenarios')
1771
+ .values({
1772
+ id: 'sc-1',
1773
+ project_id: projectId,
1774
+ name: 'LibraryCard - Default',
1775
+ component_name: 'LibraryCard',
1776
+ url: '/isolated-components/LibraryCard?s=Default',
1777
+ created_at: '2026-03-17 12:00:00',
1778
+ })
1779
+ .execute();
1780
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1781
+ expect(result).toEqual([]);
1782
+ });
1783
+ it('should flag component scenarios that use non-isolation URLs', async () => {
1784
+ // This is the bug: "Full Library Page" registered as component_name=LibraryPage
1785
+ // but url=/library — it's pointing at the real page, not an isolation route
1786
+ await db
1787
+ .insertInto('editor_scenarios')
1788
+ .values({
1789
+ id: 'sc-1',
1790
+ project_id: projectId,
1791
+ name: 'Full Library Page',
1792
+ component_name: 'LibraryPage',
1793
+ url: '/library',
1794
+ created_at: '2026-03-17 12:41:40',
1795
+ })
1796
+ .execute();
1797
+ await db
1798
+ .insertInto('editor_scenarios')
1799
+ .values({
1800
+ id: 'sc-2',
1801
+ project_id: projectId,
1802
+ name: 'Empty Library Page',
1803
+ component_name: 'LibraryPage',
1804
+ url: '/library',
1805
+ created_at: '2026-03-17 12:41:51',
1806
+ })
1807
+ .execute();
1808
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1809
+ expect(result).toEqual([
1810
+ {
1811
+ componentName: 'LibraryPage',
1812
+ scenarioNames: ['Full Library Page', 'Empty Library Page'],
1813
+ url: '/library',
1814
+ },
1815
+ ]);
1816
+ });
1817
+ it('should not flag page-level scenarios (no component_name)', async () => {
1818
+ // App-level scenarios have no component_name — they're fine with real URLs
1819
+ await db
1820
+ .insertInto('editor_scenarios')
1821
+ .values({
1822
+ id: 'sc-1',
1823
+ project_id: projectId,
1824
+ name: 'Library with Articles',
1825
+ url: '/',
1826
+ created_at: '2026-03-17 12:25:14',
1827
+ })
1828
+ .execute();
1829
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1830
+ expect(result).toEqual([]);
1831
+ });
1832
+ it('should group miscategorized scenarios by component and URL', async () => {
1833
+ // Two different components both misusing real URLs
1834
+ await db
1835
+ .insertInto('editor_scenarios')
1836
+ .values({
1837
+ id: 'sc-1',
1838
+ project_id: projectId,
1839
+ name: 'Full Library Page',
1840
+ component_name: 'LibraryPage',
1841
+ url: '/library',
1842
+ created_at: '2026-03-17 12:41:40',
1843
+ })
1844
+ .execute();
1845
+ await db
1846
+ .insertInto('editor_scenarios')
1847
+ .values({
1848
+ id: 'sc-2',
1849
+ project_id: projectId,
1850
+ name: 'Dashboard - Full',
1851
+ component_name: 'Dashboard',
1852
+ url: '/dashboard',
1853
+ created_at: '2026-03-17 12:50:00',
1854
+ })
1855
+ .execute();
1856
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1857
+ expect(result).toHaveLength(2);
1858
+ expect(result.map((r) => r.componentName).sort()).toEqual([
1859
+ 'Dashboard',
1860
+ 'LibraryPage',
1861
+ ]);
1862
+ });
1863
+ it('should scope to session when featureStartedAt is provided', async () => {
1864
+ // Old miscategorized scenario — before session
1865
+ await db
1866
+ .insertInto('editor_scenarios')
1867
+ .values({
1868
+ id: 'sc-old',
1869
+ project_id: projectId,
1870
+ name: 'Old Page',
1871
+ component_name: 'OldComponent',
1872
+ url: '/old',
1873
+ created_at: '2026-03-16 10:00:00',
1874
+ })
1875
+ .execute();
1876
+ // New miscategorized scenario — in session
1877
+ await db
1878
+ .insertInto('editor_scenarios')
1879
+ .values({
1880
+ id: 'sc-new',
1881
+ project_id: projectId,
1882
+ name: 'Full Library Page',
1883
+ component_name: 'LibraryPage',
1884
+ url: '/library',
1885
+ created_at: '2026-03-17 12:41:40',
1886
+ })
1887
+ .execute();
1888
+ const result = await queryMiscategorizedScenarios(db, projectId, '2026-03-17T11:58:55.562Z');
1889
+ expect(result).toHaveLength(1);
1890
+ expect(result[0].componentName).toBe('LibraryPage');
1891
+ });
1892
+ it('should not flag component scenarios with null URL', async () => {
1893
+ await db
1894
+ .insertInto('editor_scenarios')
1895
+ .values({
1896
+ id: 'sc-1',
1897
+ project_id: projectId,
1898
+ name: 'NoUrl - Default',
1899
+ component_name: 'NoUrl',
1900
+ created_at: '2026-03-17 12:00:00',
1901
+ })
1902
+ .execute();
1903
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1904
+ expect(result).toEqual([]);
1905
+ });
1906
+ });
1907
+ // ── isOnlyIncompleteEntities ─────────────────────────────────────────
1908
+ describe('isOnlyIncompleteEntities', () => {
1909
+ it('should return true when incompleteEntities is the only failure', () => {
1910
+ expect(isOnlyIncompleteEntities({
1911
+ componentsMissing: 0,
1912
+ componentsWithErrors: 0,
1913
+ functionsFailing: 0,
1914
+ functionsNameMismatch: 0,
1915
+ functionsMissing: 0,
1916
+ missingFromGlossary: 0,
1917
+ incompleteEntities: 3,
1918
+ allPassing: false,
1919
+ })).toBe(true);
1920
+ });
1921
+ it('should return false when there are also missing components', () => {
1922
+ expect(isOnlyIncompleteEntities({
1923
+ componentsMissing: 1,
1924
+ componentsWithErrors: 0,
1925
+ functionsFailing: 0,
1926
+ functionsNameMismatch: 0,
1927
+ functionsMissing: 0,
1928
+ missingFromGlossary: 0,
1929
+ incompleteEntities: 2,
1930
+ allPassing: false,
1931
+ })).toBe(false);
1932
+ });
1933
+ it('should return false when there are also failing tests', () => {
1934
+ expect(isOnlyIncompleteEntities({
1935
+ componentsMissing: 0,
1936
+ componentsWithErrors: 0,
1937
+ functionsFailing: 1,
1938
+ functionsNameMismatch: 0,
1939
+ functionsMissing: 0,
1940
+ missingFromGlossary: 0,
1941
+ incompleteEntities: 2,
1942
+ allPassing: false,
1943
+ })).toBe(false);
1944
+ });
1945
+ it('should return false when there are also missing glossary entries', () => {
1946
+ expect(isOnlyIncompleteEntities({
1947
+ componentsMissing: 0,
1948
+ componentsWithErrors: 0,
1949
+ functionsFailing: 0,
1950
+ functionsNameMismatch: 0,
1951
+ functionsMissing: 0,
1952
+ missingFromGlossary: 1,
1953
+ incompleteEntities: 2,
1954
+ allPassing: false,
1955
+ })).toBe(false);
1956
+ });
1957
+ it('should return true even when incompleteEntities is 0 (no failures at all)', () => {
1958
+ // Edge case: all zeros means nothing is failing
1959
+ expect(isOnlyIncompleteEntities({
1960
+ componentsMissing: 0,
1961
+ componentsWithErrors: 0,
1962
+ functionsFailing: 0,
1963
+ functionsNameMismatch: 0,
1964
+ functionsMissing: 0,
1965
+ missingFromGlossary: 0,
1966
+ incompleteEntities: 0,
1967
+ allPassing: true,
1968
+ })).toBe(true);
1969
+ });
1970
+ it('should return false when there are also miscategorized scenarios', () => {
1971
+ expect(isOnlyIncompleteEntities({
1972
+ componentsMissing: 0,
1973
+ componentsWithErrors: 0,
1974
+ functionsFailing: 0,
1975
+ functionsNameMismatch: 0,
1976
+ functionsMissing: 0,
1977
+ missingFromGlossary: 0,
1978
+ miscategorizedScenarios: 1,
1979
+ incompleteEntities: 2,
1980
+ allPassing: false,
1981
+ })).toBe(false);
1982
+ });
1983
+ it('should handle missing fields gracefully', () => {
1984
+ // Summary from older API version might not have all fields
1985
+ expect(isOnlyIncompleteEntities({
1986
+ incompleteEntities: 2,
1987
+ allPassing: false,
1988
+ })).toBe(true);
1989
+ });
1990
+ });
1991
+ // ── isAutoRemediable ─────────────────────────────────────────────────
1992
+ describe('isAutoRemediable', () => {
1993
+ // isAutoRemediable always returns false — the audit never triggers
1994
+ // full analyze-imports inline. It takes minutes on large projects.
1995
+ // Only lightweight backfill is acceptable during audit.
1996
+ it('should return false even on first attempt with only incomplete entities', () => {
1997
+ const result = isAutoRemediable({
1998
+ componentsMissing: 0,
1999
+ componentsWithErrors: 0,
2000
+ functionsFailing: 0,
2001
+ functionsNameMismatch: 0,
2002
+ functionsMissing: 0,
2003
+ missingFromGlossary: 0,
2004
+ miscategorizedScenarios: 0,
2005
+ incompleteEntities: 3,
2006
+ allPassing: false,
2007
+ }, false);
2008
+ expect(result).toBe(false);
2009
+ });
2010
+ it('should return false on second attempt', () => {
2011
+ const result = isAutoRemediable({
2012
+ componentsMissing: 0,
2013
+ componentsWithErrors: 0,
2014
+ functionsFailing: 0,
2015
+ functionsNameMismatch: 0,
2016
+ functionsMissing: 0,
2017
+ missingFromGlossary: 0,
2018
+ miscategorizedScenarios: 0,
2019
+ incompleteEntities: 3,
2020
+ allPassing: false,
2021
+ }, true);
2022
+ expect(result).toBe(false);
2023
+ });
2024
+ it('should return false when there are other failures besides incomplete entities', () => {
2025
+ const result = isAutoRemediable({
2026
+ componentsMissing: 1,
2027
+ incompleteEntities: 3,
2028
+ allPassing: false,
2029
+ }, false);
2030
+ expect(result).toBe(false);
2031
+ });
2032
+ it('should return false when there are no incomplete entities', () => {
2033
+ const result = isAutoRemediable({
2034
+ componentsMissing: 1,
2035
+ allPassing: false,
2036
+ }, false);
2037
+ expect(result).toBe(false);
2038
+ });
2039
+ });
2040
+ // ── queryIncompleteEntities ─────────────────────────────────────────
2041
+ describe('queryIncompleteEntities', () => {
2042
+ let db;
2043
+ let rawDb;
2044
+ const projectId = 'test-project-id';
2045
+ beforeEach(async () => {
2046
+ rawDb = new Database(':memory:');
2047
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
2048
+ await db.schema
2049
+ .createTable('editor_scenarios')
2050
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
2051
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
2052
+ .addColumn('name', 'varchar', (col) => col.notNull())
2053
+ .addColumn('component_name', 'varchar')
2054
+ .addColumn('component_path', 'varchar')
2055
+ .addColumn('entity_sha', 'varchar')
2056
+ .addColumn('display_name', 'varchar')
2057
+ .addColumn('page_file_path', 'varchar')
2058
+ .addColumn('url', 'varchar')
2059
+ .addColumn('created_at', 'datetime')
2060
+ .addColumn('updated_at', 'datetime')
2061
+ .execute();
2062
+ await db.schema
2063
+ .createTable('analyses')
2064
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
2065
+ .addColumn('entity_sha', 'varchar')
2066
+ .addColumn('entity_name', 'varchar')
2067
+ .addColumn('project_id', 'varchar')
2068
+ .execute();
2069
+ await db.schema
2070
+ .createTable('entities')
2071
+ .addColumn('sha', 'varchar', (col) => col.primaryKey())
2072
+ .addColumn('name', 'varchar')
2073
+ .addColumn('entity_type', 'varchar')
2074
+ .addColumn('file_path', 'varchar')
2075
+ .execute();
2076
+ });
2077
+ afterEach(async () => {
2078
+ await db.destroy();
2079
+ });
2080
+ it('should return empty when all scenario entity SHAs have analyses', async () => {
2081
+ // Entity with analysis
2082
+ await db
2083
+ .insertInto('entities')
2084
+ .values({
2085
+ sha: 'sha-header',
2086
+ name: 'Header',
2087
+ entity_type: 'visual',
2088
+ file_path: 'src/Header.tsx',
2089
+ })
2090
+ .execute();
2091
+ await db
2092
+ .insertInto('analyses')
2093
+ .values({
2094
+ id: 'a-1',
2095
+ entity_sha: 'sha-header',
2096
+ entity_name: 'Header',
2097
+ project_id: projectId,
2098
+ })
2099
+ .execute();
2100
+ await db
2101
+ .insertInto('editor_scenarios')
2102
+ .values({
2103
+ id: 'sc-1',
2104
+ project_id: projectId,
2105
+ name: 'Header - Default',
2106
+ component_name: 'Header',
2107
+ entity_sha: 'sha-header',
2108
+ created_at: '2026-03-16 23:00:00',
2109
+ })
2110
+ .execute();
2111
+ const result = await queryIncompleteEntities(db, projectId, null);
2112
+ expect(result).toEqual([]);
2113
+ });
2114
+ it('should return entities with scenarios but no analyses', async () => {
2115
+ // Entity WITHOUT analysis
2116
+ await db
2117
+ .insertInto('entities')
2118
+ .values({
2119
+ sha: 'sha-chips',
2120
+ name: 'CollectionChips',
2121
+ entity_type: 'visual',
2122
+ file_path: 'src/components/CollectionChips.tsx',
2123
+ })
2124
+ .execute();
2125
+ // Scenario referencing that entity
2126
+ await db
2127
+ .insertInto('editor_scenarios')
2128
+ .values({
2129
+ id: 'sc-1',
2130
+ project_id: projectId,
2131
+ name: 'CollectionChips - Default',
2132
+ component_name: 'CollectionChips',
2133
+ entity_sha: 'sha-chips',
2134
+ created_at: '2026-03-16 23:00:00',
2135
+ })
2136
+ .execute();
2137
+ await db
2138
+ .insertInto('editor_scenarios')
2139
+ .values({
2140
+ id: 'sc-2',
2141
+ project_id: projectId,
2142
+ name: 'CollectionChips - Many',
2143
+ component_name: 'CollectionChips',
2144
+ entity_sha: 'sha-chips',
2145
+ created_at: '2026-03-16 23:01:00',
2146
+ })
2147
+ .execute();
2148
+ const result = await queryIncompleteEntities(db, projectId, null);
2149
+ expect(result).toEqual([
2150
+ {
2151
+ entitySha: 'sha-chips',
2152
+ name: 'CollectionChips',
2153
+ scenarioCount: 2,
2154
+ preExisting: false,
2155
+ },
2156
+ ]);
2157
+ });
2158
+ it('should only return entities without analyses, not those with analyses', async () => {
2159
+ // Entity WITH analysis (Header)
2160
+ await db
2161
+ .insertInto('entities')
2162
+ .values({
2163
+ sha: 'sha-header',
2164
+ name: 'Header',
2165
+ entity_type: 'visual',
2166
+ file_path: 'src/Header.tsx',
2167
+ })
2168
+ .execute();
2169
+ await db
2170
+ .insertInto('analyses')
2171
+ .values({
2172
+ id: 'a-1',
2173
+ entity_sha: 'sha-header',
2174
+ entity_name: 'Header',
2175
+ project_id: projectId,
2176
+ })
2177
+ .execute();
2178
+ await db
2179
+ .insertInto('editor_scenarios')
2180
+ .values({
2181
+ id: 'sc-1',
2182
+ project_id: projectId,
2183
+ name: 'Header - Default',
2184
+ component_name: 'Header',
2185
+ entity_sha: 'sha-header',
2186
+ created_at: '2026-03-16 23:00:00',
2187
+ })
2188
+ .execute();
2189
+ // Entity WITHOUT analysis (CollectionPicker)
2190
+ await db
2191
+ .insertInto('entities')
2192
+ .values({
2193
+ sha: 'sha-picker',
2194
+ name: 'CollectionPicker',
2195
+ entity_type: 'visual',
2196
+ file_path: 'src/components/CollectionPicker.tsx',
2197
+ })
2198
+ .execute();
2199
+ await db
2200
+ .insertInto('editor_scenarios')
2201
+ .values({
2202
+ id: 'sc-2',
2203
+ project_id: projectId,
2204
+ name: 'CollectionPicker - Default',
2205
+ component_name: 'CollectionPicker',
2206
+ entity_sha: 'sha-picker',
2207
+ created_at: '2026-03-16 23:00:00',
2208
+ })
2209
+ .execute();
2210
+ const result = await queryIncompleteEntities(db, projectId, null);
2211
+ expect(result).toEqual([
2212
+ {
2213
+ entitySha: 'sha-picker',
2214
+ name: 'CollectionPicker',
2215
+ scenarioCount: 1,
2216
+ preExisting: false,
2217
+ },
2218
+ ]);
2219
+ });
2220
+ it('should return both pre-session and in-session entities with preExisting flags', async () => {
2221
+ // Entity without analysis, scenario created BEFORE session
2222
+ await db
2223
+ .insertInto('entities')
2224
+ .values({
2225
+ sha: 'sha-old',
2226
+ name: 'OldComponent',
2227
+ entity_type: 'visual',
2228
+ file_path: 'src/OldComponent.tsx',
2229
+ })
2230
+ .execute();
2231
+ await db
2232
+ .insertInto('editor_scenarios')
2233
+ .values({
2234
+ id: 'sc-old',
2235
+ project_id: projectId,
2236
+ name: 'OldComponent - Default',
2237
+ component_name: 'OldComponent',
2238
+ entity_sha: 'sha-old',
2239
+ created_at: '2026-03-16 20:00:00',
2240
+ })
2241
+ .execute();
2242
+ // Entity without analysis, scenario created DURING session
2243
+ await db
2244
+ .insertInto('entities')
2245
+ .values({
2246
+ sha: 'sha-new',
2247
+ name: 'NewComponent',
2248
+ entity_type: 'visual',
2249
+ file_path: 'src/NewComponent.tsx',
2250
+ })
2251
+ .execute();
2252
+ await db
2253
+ .insertInto('editor_scenarios')
2254
+ .values({
2255
+ id: 'sc-new',
2256
+ project_id: projectId,
2257
+ name: 'NewComponent - Default',
2258
+ component_name: 'NewComponent',
2259
+ entity_sha: 'sha-new',
2260
+ created_at: '2026-03-16 23:10:00',
2261
+ })
2262
+ .execute();
2263
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2264
+ // Both should be returned — OldComponent is preExisting, NewComponent is not
2265
+ expect(result).toEqual(expect.arrayContaining([
2266
+ {
2267
+ entitySha: 'sha-old',
2268
+ name: 'OldComponent',
2269
+ scenarioCount: 1,
2270
+ preExisting: true,
2271
+ },
2272
+ {
2273
+ entitySha: 'sha-new',
2274
+ name: 'NewComponent',
2275
+ scenarioCount: 1,
2276
+ preExisting: false,
2277
+ },
2278
+ ]));
2279
+ expect(result).toHaveLength(2);
2280
+ });
2281
+ it('should flag preExisting: false when scenario was updated in session even if created before', async () => {
2282
+ await db
2283
+ .insertInto('entities')
2284
+ .values({
2285
+ sha: 'sha-updated',
2286
+ name: 'UpdatedComponent',
2287
+ entity_type: 'visual',
2288
+ file_path: 'src/Updated.tsx',
2289
+ })
2290
+ .execute();
2291
+ await db
2292
+ .insertInto('editor_scenarios')
2293
+ .values({
2294
+ id: 'sc-updated',
2295
+ project_id: projectId,
2296
+ name: 'UpdatedComponent - Default',
2297
+ component_name: 'UpdatedComponent',
2298
+ entity_sha: 'sha-updated',
2299
+ created_at: '2026-03-16 20:00:00',
2300
+ updated_at: '2026-03-16 23:20:00', // Updated in session
2301
+ })
2302
+ .execute();
2303
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2304
+ expect(result).toEqual([
2305
+ {
2306
+ entitySha: 'sha-updated',
2307
+ name: 'UpdatedComponent',
2308
+ scenarioCount: 1,
2309
+ preExisting: false,
2310
+ },
2311
+ ]);
2312
+ });
2313
+ it('should skip scenarios with null entity_sha', async () => {
2314
+ await db
2315
+ .insertInto('editor_scenarios')
2316
+ .values({
2317
+ id: 'sc-null',
2318
+ project_id: projectId,
2319
+ name: 'Orphan Scenario',
2320
+ component_name: 'Orphan',
2321
+ created_at: '2026-03-16 23:00:00',
2322
+ })
2323
+ .execute();
2324
+ const result = await queryIncompleteEntities(db, projectId, null);
2325
+ expect(result).toEqual([]);
2326
+ });
2327
+ it('should return empty when there are no scenarios', async () => {
2328
+ const result = await queryIncompleteEntities(db, projectId, null);
2329
+ expect(result).toEqual([]);
2330
+ });
2331
+ it('should not flag entities when a sibling version (same name+filePath) has analyses', async () => {
2332
+ // Old entity version WITH analysis
2333
+ await db
2334
+ .insertInto('entities')
2335
+ .values({
2336
+ sha: 'sha-btn-v1',
2337
+ name: 'OpenLibraryButton',
2338
+ entity_type: 'visual',
2339
+ file_path: 'src/components/OpenLibraryButton.tsx',
2340
+ })
2341
+ .execute();
2342
+ await db
2343
+ .insertInto('analyses')
2344
+ .values({
2345
+ id: 'a-btn-v1',
2346
+ entity_sha: 'sha-btn-v1',
2347
+ entity_name: 'OpenLibraryButton',
2348
+ project_id: projectId,
2349
+ })
2350
+ .execute();
2351
+ // New entity version WITHOUT analysis (created by file watcher)
2352
+ await db
2353
+ .insertInto('entities')
2354
+ .values({
2355
+ sha: 'sha-btn-v2',
2356
+ name: 'OpenLibraryButton',
2357
+ entity_type: 'visual',
2358
+ file_path: 'src/components/OpenLibraryButton.tsx',
2359
+ })
2360
+ .execute();
2361
+ // Scenario points to the NEW version (backfilled after file watcher)
2362
+ await db
2363
+ .insertInto('editor_scenarios')
2364
+ .values({
2365
+ id: 'sc-btn',
2366
+ project_id: projectId,
2367
+ name: 'OpenLibraryButton - Default',
2368
+ component_name: 'OpenLibraryButton',
2369
+ entity_sha: 'sha-btn-v2',
2370
+ created_at: '2026-03-16 23:00:00',
2371
+ })
2372
+ .execute();
2373
+ // Should NOT flag as incomplete — sibling version has analyses
2374
+ const result = await queryIncompleteEntities(db, projectId, null);
2375
+ expect(result).toEqual([]);
2376
+ });
2377
+ it('should flag entity when sibling has analyses but different filePath (extracted component)', async () => {
2378
+ // Old entity version WITH analysis at ORIGINAL file path
2379
+ await db
2380
+ .insertInto('entities')
2381
+ .values({
2382
+ sha: 'sha-card-v1',
2383
+ name: 'TaskCard',
2384
+ entity_type: 'visual',
2385
+ file_path: 'app/page.tsx',
2386
+ })
2387
+ .execute();
2388
+ await db
2389
+ .insertInto('analyses')
2390
+ .values({
2391
+ id: 'a-card-v1',
2392
+ entity_sha: 'sha-card-v1',
2393
+ entity_name: 'TaskCard',
2394
+ project_id: projectId,
2395
+ })
2396
+ .execute();
2397
+ // New entity version WITHOUT analysis at EXTRACTED file path
2398
+ await db
2399
+ .insertInto('entities')
2400
+ .values({
2401
+ sha: 'sha-card-v2',
2402
+ name: 'TaskCard',
2403
+ entity_type: 'visual',
2404
+ file_path: 'app/components/TaskCard.tsx',
2405
+ })
2406
+ .execute();
2407
+ // Scenario points to the new version (synced by syncScenarioEntityShas)
2408
+ await db
2409
+ .insertInto('editor_scenarios')
2410
+ .values({
2411
+ id: 'sc-card',
2412
+ project_id: projectId,
2413
+ name: 'TaskCard - Default',
2414
+ component_name: 'TaskCard',
2415
+ entity_sha: 'sha-card-v2',
2416
+ created_at: '2026-03-16 23:00:00',
2417
+ })
2418
+ .execute();
2419
+ // SHOULD flag as incomplete — sibling has analyses but at a different filePath,
2420
+ // so getAllEntities() won't inherit (it matches by name+filePath)
2421
+ const result = await queryIncompleteEntities(db, projectId, null);
2422
+ expect(result).toEqual([
2423
+ {
2424
+ entitySha: 'sha-card-v2',
2425
+ name: 'TaskCard',
2426
+ scenarioCount: 1,
2427
+ preExisting: false,
2428
+ },
2429
+ ]);
2430
+ });
2431
+ it('should still flag entities when no sibling version has analyses', async () => {
2432
+ // Only one version, no analyses
2433
+ await db
2434
+ .insertInto('entities')
2435
+ .values({
2436
+ sha: 'sha-icon',
2437
+ name: 'ExternalLinkIcon',
2438
+ entity_type: 'visual',
2439
+ file_path: 'src/components/ExternalLinkIcon.tsx',
2440
+ })
2441
+ .execute();
2442
+ await db
2443
+ .insertInto('editor_scenarios')
2444
+ .values({
2445
+ id: 'sc-icon',
2446
+ project_id: projectId,
2447
+ name: 'ExternalLinkIcon - Default',
2448
+ component_name: 'ExternalLinkIcon',
2449
+ entity_sha: 'sha-icon',
2450
+ created_at: '2026-03-16 23:00:00',
2451
+ })
2452
+ .execute();
2453
+ // Should flag as incomplete — no version has analyses
2454
+ const result = await queryIncompleteEntities(db, projectId, null);
2455
+ expect(result).toEqual([
2456
+ {
2457
+ entitySha: 'sha-icon',
2458
+ name: 'ExternalLinkIcon',
2459
+ scenarioCount: 1,
2460
+ preExisting: false,
2461
+ },
2462
+ ]);
2463
+ });
2464
+ it('should skip phantom SHAs (entity_sha with no entity record)', async () => {
2465
+ // Scenario has entity_sha but entity record doesn't exist.
2466
+ // These are "phantom SHAs" created when scenarios were registered
2467
+ // without component_path — they can never be fixed by analyze-imports
2468
+ // and should not block audit progression.
2469
+ await db
2470
+ .insertInto('editor_scenarios')
2471
+ .values({
2472
+ id: 'sc-1',
2473
+ project_id: projectId,
2474
+ name: 'Ghost - Default',
2475
+ component_name: 'GhostComponent',
2476
+ entity_sha: 'sha-ghost',
2477
+ created_at: '2026-03-16 23:00:00',
2478
+ })
2479
+ .execute();
2480
+ const result = await queryIncompleteEntities(db, projectId, null);
2481
+ // Phantom SHAs are excluded — not reportable as incomplete
2482
+ expect(result).toEqual([]);
2483
+ });
2484
+ it('should detect incomplete entity whose scenario predates the session', async () => {
2485
+ // Entity with no analyses, scenario created BEFORE session
2486
+ await db
2487
+ .insertInto('entities')
2488
+ .values({
2489
+ sha: 'sha-preexisting',
2490
+ name: 'PreExistingComponent',
2491
+ entity_type: 'visual',
2492
+ file_path: 'src/PreExistingComponent.tsx',
2493
+ })
2494
+ .execute();
2495
+ await db
2496
+ .insertInto('editor_scenarios')
2497
+ .values({
2498
+ id: 'sc-preexisting',
2499
+ project_id: projectId,
2500
+ name: 'PreExistingComponent - Default',
2501
+ component_name: 'PreExistingComponent',
2502
+ entity_sha: 'sha-preexisting',
2503
+ created_at: '2026-03-16 20:00:00',
2504
+ updated_at: '2026-03-16 20:00:00',
2505
+ })
2506
+ .execute();
2507
+ // Session started well after scenario was created/updated
2508
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2509
+ // Should still be detected — the old time filter would have excluded it
2510
+ expect(result).toEqual([
2511
+ {
2512
+ entitySha: 'sha-preexisting',
2513
+ name: 'PreExistingComponent',
2514
+ scenarioCount: 1,
2515
+ preExisting: true,
2516
+ },
2517
+ ]);
2518
+ });
2519
+ it('should flag preExisting: true when all scenarios predate the session', async () => {
2520
+ await db
2521
+ .insertInto('entities')
2522
+ .values({
2523
+ sha: 'sha-old-entity',
2524
+ name: 'OldEntity',
2525
+ entity_type: 'visual',
2526
+ file_path: 'src/OldEntity.tsx',
2527
+ })
2528
+ .execute();
2529
+ // Two scenarios, both before session
2530
+ await db
2531
+ .insertInto('editor_scenarios')
2532
+ .values({
2533
+ id: 'sc-old-1',
2534
+ project_id: projectId,
2535
+ name: 'OldEntity - Default',
2536
+ component_name: 'OldEntity',
2537
+ entity_sha: 'sha-old-entity',
2538
+ created_at: '2026-03-16 19:00:00',
2539
+ updated_at: '2026-03-16 19:00:00',
2540
+ })
2541
+ .execute();
2542
+ await db
2543
+ .insertInto('editor_scenarios')
2544
+ .values({
2545
+ id: 'sc-old-2',
2546
+ project_id: projectId,
2547
+ name: 'OldEntity - Hover',
2548
+ component_name: 'OldEntity',
2549
+ entity_sha: 'sha-old-entity',
2550
+ created_at: '2026-03-16 19:30:00',
2551
+ updated_at: '2026-03-16 19:30:00',
2552
+ })
2553
+ .execute();
2554
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2555
+ expect(result).toEqual([
2556
+ {
2557
+ entitySha: 'sha-old-entity',
2558
+ name: 'OldEntity',
2559
+ scenarioCount: 2,
2560
+ preExisting: true,
2561
+ },
2562
+ ]);
2563
+ });
2564
+ it('should flag preExisting: false when scenario is from the current session', async () => {
2565
+ await db
2566
+ .insertInto('entities')
2567
+ .values({
2568
+ sha: 'sha-session-entity',
2569
+ name: 'SessionEntity',
2570
+ entity_type: 'visual',
2571
+ file_path: 'src/SessionEntity.tsx',
2572
+ })
2573
+ .execute();
2574
+ await db
2575
+ .insertInto('editor_scenarios')
2576
+ .values({
2577
+ id: 'sc-session',
2578
+ project_id: projectId,
2579
+ name: 'SessionEntity - Default',
2580
+ component_name: 'SessionEntity',
2581
+ entity_sha: 'sha-session-entity',
2582
+ created_at: '2026-03-16 23:30:00',
2583
+ updated_at: '2026-03-16 23:30:00',
2584
+ })
2585
+ .execute();
2586
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2587
+ expect(result).toEqual([
2588
+ {
2589
+ entitySha: 'sha-session-entity',
2590
+ name: 'SessionEntity',
2591
+ scenarioCount: 1,
2592
+ preExisting: false,
2593
+ },
2594
+ ]);
2595
+ });
2596
+ });
2597
+ // ── identifyScenariosNeedingRecapture ──────────────────────────────
2598
+ describe('identifyScenariosNeedingRecapture', () => {
2599
+ // Reproduces the Margo bug: Feature 1 built app-level popup scenarios,
2600
+ // Feature 2 edited LibraryView (used by App), but app-level scenarios
2601
+ // were never flagged for recapture because the audit only checked
2602
+ // component scenario existence — not whether app-level scenarios are stale.
2603
+ //
2604
+ // Each scenario's entityName is resolved by the caller via
2605
+ // entity_sha → entities.name (the default export for app-level scenarios).
2606
+ it('should flag app-level scenario when its entity is impacted by transitive dependency change', () => {
2607
+ // LibraryView was edited → App is impacted (imports LibraryView)
2608
+ // App-level scenario "Library - Rich Library" has entity_sha pointing to App
2609
+ // It was NOT recaptured during Feature 2 → should be flagged
2610
+ const entityChangeStatus = {
2611
+ LibraryView: { status: 'edited' },
2612
+ App: {
2613
+ status: 'impacted',
2614
+ impactedBy: [
2615
+ {
2616
+ name: 'LibraryView',
2617
+ filePath: 'src/components/LibraryView.tsx',
2618
+ changeType: 'edited',
2619
+ },
2620
+ ],
2621
+ },
2622
+ };
2623
+ const result = identifyScenariosNeedingRecapture({
2624
+ scenarios: [
2625
+ {
2626
+ name: 'Library - Rich Library',
2627
+ entityName: 'App', // resolved from entity_sha → entities.name
2628
+ updatedInSession: false,
2629
+ },
2630
+ ],
2631
+ entityChangeStatus,
2632
+ });
2633
+ expect(result).toHaveLength(1);
2634
+ expect(result[0].scenarioName).toBe('Library - Rich Library');
2635
+ expect(result[0].entityName).toBe('App');
2636
+ expect(result[0].status.status).toBe('impacted');
2637
+ });
2638
+ it('should flag component scenario when its entity is directly edited and not recaptured', () => {
2639
+ const entityChangeStatus = {
2640
+ LibraryView: { status: 'edited' },
2641
+ };
2642
+ const result = identifyScenariosNeedingRecapture({
2643
+ scenarios: [
2644
+ {
2645
+ name: 'LibraryView - Empty',
2646
+ entityName: 'LibraryView',
2647
+ updatedInSession: false,
2648
+ },
2649
+ ],
2650
+ entityChangeStatus,
2651
+ });
2652
+ expect(result).toHaveLength(1);
2653
+ expect(result[0].scenarioName).toBe('LibraryView - Empty');
2654
+ expect(result[0].entityName).toBe('LibraryView');
2655
+ expect(result[0].status.status).toBe('edited');
2656
+ });
2657
+ it('should NOT flag scenario that was already recaptured in the current session', () => {
2658
+ const entityChangeStatus = {
2659
+ App: {
2660
+ status: 'impacted',
2661
+ impactedBy: [
2662
+ {
2663
+ name: 'LibraryView',
2664
+ filePath: 'src/components/LibraryView.tsx',
2665
+ changeType: 'edited',
2666
+ },
2667
+ ],
2668
+ },
2669
+ };
2670
+ const result = identifyScenariosNeedingRecapture({
2671
+ scenarios: [
2672
+ {
2673
+ name: 'App - Default',
2674
+ entityName: 'App',
2675
+ updatedInSession: true, // re-registered during Feature 2
2676
+ },
2677
+ ],
2678
+ entityChangeStatus,
2679
+ });
2680
+ expect(result).toHaveLength(0);
2681
+ });
2682
+ it('should NOT flag scenario whose entity has no change status', () => {
2683
+ const entityChangeStatus = {
2684
+ LibraryView: { status: 'edited' },
2685
+ };
2686
+ const result = identifyScenariosNeedingRecapture({
2687
+ scenarios: [
2688
+ {
2689
+ name: 'WelcomeScreen - Default',
2690
+ entityName: 'WelcomeScreen',
2691
+ updatedInSession: false,
2692
+ },
2693
+ ],
2694
+ entityChangeStatus,
2695
+ });
2696
+ expect(result).toHaveLength(0);
2697
+ });
2698
+ it('should return empty array when entityChangeStatus is undefined', () => {
2699
+ const result = identifyScenariosNeedingRecapture({
2700
+ scenarios: [
2701
+ {
2702
+ name: 'Library - Rich Library',
2703
+ entityName: 'App',
2704
+ updatedInSession: false,
2705
+ },
2706
+ ],
2707
+ entityChangeStatus: undefined,
2708
+ });
2709
+ expect(result).toHaveLength(0);
2710
+ });
2711
+ it('should return empty array when entityChangeStatus is empty', () => {
2712
+ const result = identifyScenariosNeedingRecapture({
2713
+ scenarios: [
2714
+ {
2715
+ name: 'Library - Rich Library',
2716
+ entityName: 'App',
2717
+ updatedInSession: false,
2718
+ },
2719
+ ],
2720
+ entityChangeStatus: {},
2721
+ });
2722
+ expect(result).toHaveLength(0);
2723
+ });
2724
+ it('should flag multiple app-level scenarios sharing the same impacted entity', () => {
2725
+ const entityChangeStatus = {
2726
+ LibraryView: { status: 'edited' },
2727
+ App: {
2728
+ status: 'impacted',
2729
+ impactedBy: [
2730
+ {
2731
+ name: 'LibraryView',
2732
+ filePath: 'src/components/LibraryView.tsx',
2733
+ changeType: 'edited',
2734
+ },
2735
+ ],
2736
+ },
2737
+ };
2738
+ const result = identifyScenariosNeedingRecapture({
2739
+ scenarios: [
2740
+ {
2741
+ name: 'Library - Empty',
2742
+ entityName: 'App',
2743
+ updatedInSession: false,
2744
+ },
2745
+ {
2746
+ name: 'Library - Rich Library',
2747
+ entityName: 'App',
2748
+ updatedInSession: false,
2749
+ },
2750
+ {
2751
+ name: 'First Article Saved',
2752
+ entityName: 'App',
2753
+ updatedInSession: false,
2754
+ },
2755
+ ],
2756
+ entityChangeStatus,
2757
+ });
2758
+ expect(result).toHaveLength(3);
2759
+ expect(result.map((r) => r.scenarioName).sort()).toEqual([
2760
+ 'First Article Saved',
2761
+ 'Library - Empty',
2762
+ 'Library - Rich Library',
2763
+ ]);
2764
+ expect(result.every((r) => r.entityName === 'App')).toBe(true);
2765
+ });
2766
+ it('should skip scenarios with null entityName (no entity_sha set)', () => {
2767
+ const entityChangeStatus = {
2768
+ App: { status: 'edited' },
2769
+ };
2770
+ const result = identifyScenariosNeedingRecapture({
2771
+ scenarios: [
2772
+ {
2773
+ name: 'Mystery Scenario',
2774
+ entityName: null, // no entity_sha → no entity name
2775
+ updatedInSession: false,
2776
+ },
2777
+ ],
2778
+ entityChangeStatus,
2779
+ });
2780
+ expect(result).toHaveLength(0);
2781
+ });
2782
+ });
2783
+ // ── detectDuplicateNames ──────────────────────────────────────────
2784
+ describe('detectDuplicateNames', () => {
2785
+ it('should return empty map when no duplicates exist', () => {
2786
+ const entries = [
2787
+ { name: 'Header', filePath: 'app/components/Header.tsx' },
2788
+ { name: 'Footer', filePath: 'app/components/Footer.tsx' },
2789
+ { name: 'Sidebar', filePath: 'app/components/Sidebar.tsx' },
2790
+ ];
2791
+ const result = detectDuplicateNames(entries);
2792
+ expect(result.size).toBe(0);
2793
+ });
2794
+ it('should group entries that share a name', () => {
2795
+ const entries = [
2796
+ { name: 'Page', filePath: 'app/isolated-components/Foo/page.tsx' },
2797
+ { name: 'Page', filePath: 'app/isolated-components/Bar/page.tsx' },
2798
+ { name: 'Page', filePath: 'app/isolated-components/Baz/page.tsx' },
2799
+ { name: 'Header', filePath: 'app/components/Header.tsx' },
2800
+ ];
2801
+ const result = detectDuplicateNames(entries);
2802
+ expect(result.size).toBe(1);
2803
+ expect(result.has('Page')).toBe(true);
2804
+ const pageGroup = result.get('Page');
2805
+ expect(pageGroup).toHaveLength(3);
2806
+ expect(pageGroup.map((e) => e.filePath)).toEqual([
2807
+ 'app/isolated-components/Foo/page.tsx',
2808
+ 'app/isolated-components/Bar/page.tsx',
2809
+ 'app/isolated-components/Baz/page.tsx',
2810
+ ]);
2811
+ });
2812
+ it('should exclude single-occurrence names', () => {
2813
+ const entries = [
2814
+ { name: 'Page', filePath: 'app/isolated-components/Foo/page.tsx' },
2815
+ { name: 'Page', filePath: 'app/isolated-components/Bar/page.tsx' },
2816
+ { name: 'Header', filePath: 'app/components/Header.tsx' },
2817
+ { name: 'Footer', filePath: 'app/components/Footer.tsx' },
2818
+ ];
2819
+ const result = detectDuplicateNames(entries);
2820
+ expect(result.size).toBe(1);
2821
+ expect(result.has('Header')).toBe(false);
2822
+ expect(result.has('Footer')).toBe(false);
2823
+ });
2824
+ it('should handle multiple duplicate groups', () => {
2825
+ const entries = [
2826
+ { name: 'Page', filePath: 'app/isolated-components/A/page.tsx' },
2827
+ { name: 'Page', filePath: 'app/isolated-components/B/page.tsx' },
2828
+ { name: 'Layout', filePath: 'app/isolated-components/A/layout.tsx' },
2829
+ { name: 'Layout', filePath: 'app/isolated-components/B/layout.tsx' },
2830
+ { name: 'Unique', filePath: 'app/components/Unique.tsx' },
2831
+ ];
2832
+ const result = detectDuplicateNames(entries);
2833
+ expect(result.size).toBe(2);
2834
+ expect(result.has('Page')).toBe(true);
2835
+ expect(result.has('Layout')).toBe(true);
2836
+ expect(result.get('Page')).toHaveLength(2);
2837
+ expect(result.get('Layout')).toHaveLength(2);
2838
+ });
2839
+ it('should return empty map for empty input', () => {
2840
+ const result = detectDuplicateNames([]);
2841
+ expect(result.size).toBe(0);
2842
+ });
2843
+ });
2844
+ // ── computeAudit: impacted components with stale scenarios ──────────
2845
+ describe('computeAudit — impacted components with stale scenarios', () => {
2846
+ it('should mark impacted component as needs_recapture when it has total scenarios but none in session', () => {
2847
+ // Library page has 3 scenarios from Feature 1 (totalScenarioCounts),
2848
+ // 0 in the current session (scenarioCounts), and is "impacted" in entityChangeStatus.
2849
+ // It should NOT be marked "missing" — it needs recapture, not new scenarios.
2850
+ const result = computeAudit({
2851
+ components: [
2852
+ {
2853
+ name: 'Library',
2854
+ filePath: 'app/library/page.tsx',
2855
+ returnType: 'JSX.Element',
2856
+ },
2857
+ {
2858
+ name: 'ArticleTable',
2859
+ filePath: 'app/components/ArticleTable.tsx',
2860
+ returnType: 'JSX.Element',
2861
+ },
2862
+ ],
2863
+ functions: [],
2864
+ scenarioCounts: { ArticleTable: 2 },
2865
+ testFileExistence: {},
2866
+ totalScenarioCounts: { Library: 3 },
2867
+ entityChangeStatus: {
2868
+ Library: { status: 'impacted' },
2869
+ ArticleTable: { status: 'edited' },
2870
+ },
2871
+ });
2872
+ // Library: impacted + has total scenarios but 0 in session → needs_recapture
2873
+ expect(result.components[0].status).toBe('needs_recapture');
2874
+ expect(result.components[0].scenarioCount).toBe(3);
2875
+ // ArticleTable: edited + has session scenarios → ok
2876
+ expect(result.components[1].status).toBe('ok');
2877
+ // needs_recapture should NOT count as missing
2878
+ expect(result.summary.componentsMissing).toBe(0);
2879
+ expect(result.summary.componentsNeedingRecapture).toBe(1);
2880
+ // should NOT fail the audit (scenariosNeedingRecapture handles it)
2881
+ expect(result.summary.allPassing).toBe(true);
2882
+ });
2883
+ it('should still mark component as missing when impacted but has zero total scenarios', () => {
2884
+ // New page added to glossary but never had scenarios — truly missing
2885
+ const result = computeAudit({
2886
+ components: [
2887
+ {
2888
+ name: 'NewPage',
2889
+ filePath: 'app/new/page.tsx',
2890
+ returnType: 'JSX.Element',
2891
+ },
2892
+ ],
2893
+ functions: [],
2894
+ scenarioCounts: {},
2895
+ testFileExistence: {},
2896
+ totalScenarioCounts: {},
2897
+ entityChangeStatus: {
2898
+ NewPage: { status: 'impacted' },
2899
+ },
2900
+ });
2901
+ expect(result.components[0].status).toBe('missing');
2902
+ expect(result.summary.componentsMissing).toBe(1);
2903
+ });
2904
+ it('should use needs_recapture for edited entities with existing scenarios from prior sessions', () => {
2905
+ // Edited entities that already have scenarios from prior sessions
2906
+ // need recapture, not re-registration. The code changed, but the
2907
+ // scenarios exist — they just need fresh screenshots.
2908
+ const result = computeAudit({
2909
+ components: [
2910
+ {
2911
+ name: 'EditedComp',
2912
+ filePath: 'app/components/Edited.tsx',
2913
+ returnType: 'JSX.Element',
2914
+ },
2915
+ ],
2916
+ functions: [],
2917
+ scenarioCounts: {},
2918
+ testFileExistence: {},
2919
+ totalScenarioCounts: { EditedComp: 2 },
2920
+ entityChangeStatus: {
2921
+ EditedComp: { status: 'edited' },
2922
+ },
2923
+ });
2924
+ expect(result.components[0].status).toBe('needs_recapture');
2925
+ expect(result.summary.componentsMissing).toBe(0);
2926
+ expect(result.summary.componentsNeedingRecapture).toBe(1);
2927
+ });
2928
+ it('should still mark as missing when new entity has zero total scenarios', () => {
2929
+ // Truly new component with no scenarios ever — needs scenarios created
2930
+ const result = computeAudit({
2931
+ components: [
2932
+ {
2933
+ name: 'BrandNew',
2934
+ filePath: 'app/components/BrandNew.tsx',
2935
+ returnType: 'JSX.Element',
2936
+ },
2937
+ ],
2938
+ functions: [],
2939
+ scenarioCounts: {},
2940
+ testFileExistence: {},
2941
+ totalScenarioCounts: {},
2942
+ entityChangeStatus: {
2943
+ BrandNew: { status: 'new' },
2944
+ },
2945
+ });
2946
+ expect(result.components[0].status).toBe('missing');
2947
+ expect(result.summary.componentsMissing).toBe(1);
2948
+ });
2949
+ });
2950
+ // ── queryUnassociatedScenarios ──────────────────────────────────────
2951
+ describe('queryUnassociatedScenarios', () => {
2952
+ let db;
2953
+ let rawDb;
2954
+ const projectId = 'test-project-id';
2955
+ beforeEach(async () => {
2956
+ rawDb = new Database(':memory:');
2957
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
2958
+ await db.schema
2959
+ .createTable('editor_scenarios')
2960
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
2961
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
2962
+ .addColumn('name', 'varchar', (col) => col.notNull())
2963
+ .addColumn('component_name', 'varchar')
2964
+ .addColumn('component_path', 'varchar')
2965
+ .addColumn('entity_sha', 'varchar')
2966
+ .addColumn('display_name', 'varchar')
2967
+ .addColumn('page_file_path', 'varchar')
2968
+ .addColumn('url', 'varchar')
2969
+ .addColumn('type', 'varchar')
2970
+ .addColumn('created_at', 'datetime')
2971
+ .addColumn('updated_at', 'datetime')
2972
+ .execute();
2973
+ });
2974
+ afterEach(async () => {
2975
+ await db.destroy();
2976
+ });
2977
+ it('should return empty when all scenarios have entity_sha', async () => {
2978
+ await db
2979
+ .insertInto('editor_scenarios')
2980
+ .values({
2981
+ id: 'sc-1',
2982
+ project_id: projectId,
2983
+ name: 'Header - Default',
2984
+ component_name: 'Header',
2985
+ component_path: 'src/components/Header.tsx',
2986
+ entity_sha: 'sha-header',
2987
+ created_at: '2026-03-16 23:00:00',
2988
+ updated_at: '2026-03-16 23:00:00',
2989
+ })
2990
+ .execute();
2991
+ const result = await queryUnassociatedScenarios(db, projectId, null);
2992
+ expect(result).toEqual([]);
2993
+ });
2994
+ it('should find component scenarios with NULL entity_sha', async () => {
2995
+ // This reproduces the Margo testapp bug: subagent registered scenarios
2996
+ // but entity records didn't exist yet, so entity_sha was never set
2997
+ await db
2998
+ .insertInto('editor_scenarios')
2999
+ .values({
3000
+ id: 'sc-1',
3001
+ project_id: projectId,
3002
+ name: 'SearchBar - Default',
3003
+ component_name: 'SearchBar',
3004
+ component_path: 'src/components/SearchBar.tsx',
3005
+ entity_sha: null,
3006
+ created_at: '2026-03-20 18:45:00',
3007
+ updated_at: '2026-03-20 18:45:00',
3008
+ })
3009
+ .execute();
3010
+ await db
3011
+ .insertInto('editor_scenarios')
3012
+ .values({
3013
+ id: 'sc-2',
3014
+ project_id: projectId,
3015
+ name: 'SearchBar - With Results',
3016
+ component_name: 'SearchBar',
3017
+ component_path: 'src/components/SearchBar.tsx',
3018
+ entity_sha: null,
3019
+ created_at: '2026-03-20 18:45:05',
3020
+ updated_at: '2026-03-20 18:45:05',
3021
+ })
3022
+ .execute();
3023
+ const result = await queryUnassociatedScenarios(db, projectId, null);
3024
+ expect(result).toHaveLength(1);
3025
+ expect(result[0].name).toBe('SearchBar');
3026
+ expect(result[0].filePath).toBe('src/components/SearchBar.tsx');
3027
+ expect(result[0].scenarioCount).toBe(2);
3028
+ expect(result[0].scenarioNames).toEqual(expect.arrayContaining([
3029
+ 'SearchBar - Default',
3030
+ 'SearchBar - With Results',
3031
+ ]));
3032
+ });
3033
+ it('should find page scenarios with NULL entity_sha', async () => {
3034
+ await db
3035
+ .insertInto('editor_scenarios')
3036
+ .values({
3037
+ id: 'sc-1',
3038
+ project_id: projectId,
3039
+ name: 'Full Page — Rich Library',
3040
+ component_name: null,
3041
+ component_path: null,
3042
+ page_file_path: 'src/library/LibraryApp.tsx',
3043
+ entity_sha: null,
3044
+ created_at: '2026-03-20 18:50:00',
3045
+ updated_at: '2026-03-20 18:50:00',
3046
+ })
3047
+ .execute();
3048
+ const result = await queryUnassociatedScenarios(db, projectId, null);
3049
+ expect(result).toHaveLength(1);
3050
+ expect(result[0].name).toBe('LibraryApp');
3051
+ expect(result[0].filePath).toBe('src/library/LibraryApp.tsx');
3052
+ expect(result[0].scenarioCount).toBe(1);
3053
+ });
3054
+ it('should ignore scenarios without any file path (orphans without component_path or page_file_path)', async () => {
3055
+ // Scenarios with no file path at all can't be associated — they're not
3056
+ // actionable, so don't report them as unassociated
3057
+ await db
3058
+ .insertInto('editor_scenarios')
3059
+ .values({
3060
+ id: 'sc-1',
3061
+ project_id: projectId,
3062
+ name: 'Some Orphan',
3063
+ component_name: null,
3064
+ component_path: null,
3065
+ page_file_path: null,
3066
+ entity_sha: null,
3067
+ created_at: '2026-03-20 18:50:00',
3068
+ updated_at: '2026-03-20 18:50:00',
3069
+ })
3070
+ .execute();
3071
+ const result = await queryUnassociatedScenarios(db, projectId, null);
3072
+ expect(result).toEqual([]);
3073
+ });
3074
+ it('should group multiple components separately', async () => {
3075
+ // Two different components both missing entity_sha
3076
+ await db
3077
+ .insertInto('editor_scenarios')
3078
+ .values({
3079
+ id: 'sc-1',
3080
+ project_id: projectId,
3081
+ name: 'FullPageHeader - Default',
3082
+ component_name: 'FullPageHeader',
3083
+ component_path: 'src/components/FullPageHeader.tsx',
3084
+ entity_sha: null,
3085
+ created_at: '2026-03-20 18:45:00',
3086
+ updated_at: '2026-03-20 18:45:00',
3087
+ })
3088
+ .execute();
3089
+ await db
3090
+ .insertInto('editor_scenarios')
3091
+ .values({
3092
+ id: 'sc-2',
3093
+ project_id: projectId,
3094
+ name: 'SaveConfirmation - Visible',
3095
+ component_name: 'SaveConfirmation',
3096
+ component_path: 'src/components/SaveConfirmation.tsx',
3097
+ entity_sha: null,
3098
+ created_at: '2026-03-20 19:00:00',
3099
+ updated_at: '2026-03-20 19:00:00',
3100
+ })
3101
+ .execute();
3102
+ const result = await queryUnassociatedScenarios(db, projectId, null);
3103
+ expect(result).toHaveLength(2);
3104
+ const names = result.map((r) => r.name).sort();
3105
+ expect(names).toEqual(['FullPageHeader', 'SaveConfirmation']);
3106
+ });
3107
+ it('should only include scenarios from the specified project', async () => {
3108
+ await db
3109
+ .insertInto('editor_scenarios')
3110
+ .values({
3111
+ id: 'sc-1',
3112
+ project_id: 'other-project',
3113
+ name: 'SearchBar - Default',
3114
+ component_name: 'SearchBar',
3115
+ component_path: 'src/components/SearchBar.tsx',
3116
+ entity_sha: null,
3117
+ created_at: '2026-03-20 18:45:00',
3118
+ updated_at: '2026-03-20 18:45:00',
3119
+ })
3120
+ .execute();
3121
+ const result = await queryUnassociatedScenarios(db, projectId, null);
3122
+ expect(result).toEqual([]);
3123
+ });
3124
+ it('should scope to feature session when featureStartedAt is provided', async () => {
3125
+ // Pre-existing unassociated scenario (before session)
3126
+ await db
3127
+ .insertInto('editor_scenarios')
3128
+ .values({
3129
+ id: 'sc-old',
3130
+ project_id: projectId,
3131
+ name: 'OldComponent - Default',
3132
+ component_name: 'OldComponent',
3133
+ component_path: 'src/components/OldComponent.tsx',
3134
+ entity_sha: null,
3135
+ created_at: '2026-03-19 10:00:00',
3136
+ updated_at: '2026-03-19 10:00:00',
3137
+ })
3138
+ .execute();
3139
+ // New unassociated scenario (during session)
3140
+ await db
3141
+ .insertInto('editor_scenarios')
3142
+ .values({
3143
+ id: 'sc-new',
3144
+ project_id: projectId,
3145
+ name: 'NewComponent - Default',
3146
+ component_name: 'NewComponent',
3147
+ component_path: 'src/components/NewComponent.tsx',
3148
+ entity_sha: null,
3149
+ created_at: '2026-03-20 18:45:00',
3150
+ updated_at: '2026-03-20 18:45:00',
3151
+ })
3152
+ .execute();
3153
+ const result = await queryUnassociatedScenarios(db, projectId, '2026-03-20T18:00:00.000Z');
3154
+ // Should only find the session-scoped one
3155
+ expect(result).toHaveLength(1);
3156
+ expect(result[0].name).toBe('NewComponent');
3157
+ });
3158
+ it('should include re-registered scenarios (updated_at in session) even if created before', async () => {
3159
+ await db
3160
+ .insertInto('editor_scenarios')
3161
+ .values({
3162
+ id: 'sc-1',
3163
+ project_id: projectId,
3164
+ name: 'SearchBar - Default',
3165
+ component_name: 'SearchBar',
3166
+ component_path: 'src/components/SearchBar.tsx',
3167
+ entity_sha: null,
3168
+ created_at: '2026-03-19 10:00:00',
3169
+ updated_at: '2026-03-20 18:45:00', // re-registered during session
3170
+ })
3171
+ .execute();
3172
+ const result = await queryUnassociatedScenarios(db, projectId, '2026-03-20T18:00:00.000Z');
3173
+ expect(result).toHaveLength(1);
3174
+ expect(result[0].name).toBe('SearchBar');
3175
+ });
3176
+ it('should not include scenarios with entity_sha set (even if stale)', async () => {
3177
+ // This scenario has an entity_sha — even if it's stale, that's a
3178
+ // different problem (handled by queryIncompleteEntities)
3179
+ await db
3180
+ .insertInto('editor_scenarios')
3181
+ .values({
3182
+ id: 'sc-1',
3183
+ project_id: projectId,
3184
+ name: 'Header - Default',
3185
+ component_name: 'Header',
3186
+ component_path: 'src/components/Header.tsx',
3187
+ entity_sha: 'sha-old-version',
3188
+ created_at: '2026-03-20 18:45:00',
3189
+ updated_at: '2026-03-20 18:45:00',
3190
+ })
3191
+ .execute();
3192
+ const result = await queryUnassociatedScenarios(db, projectId, null);
3193
+ expect(result).toEqual([]);
3194
+ });
3195
+ });
3196
+ // ── isAutoRemediable with unassociatedScenarios ────────────────────
3197
+ describe('isAutoRemediable always returns false (no inline full analysis)', () => {
3198
+ // Full analyze-imports takes minutes on large projects. The audit should
3199
+ // never trigger it — only the lightweight backfill path is acceptable.
3200
+ it('should return false for unassociatedScenarios only', () => {
3201
+ expect(isAutoRemediable({ unassociatedScenarios: 3 }, false)).toBe(false);
3202
+ });
3203
+ it('should return false for incompleteEntities + unassociatedScenarios', () => {
3204
+ expect(isAutoRemediable({ incompleteEntities: 1, unassociatedScenarios: 2 }, false)).toBe(false);
3205
+ });
3206
+ it('should return false even with no other failures', () => {
3207
+ expect(isAutoRemediable({ unassociatedScenarios: 2 }, false)).toBe(false);
3208
+ });
3209
+ it('should return false when already attempted', () => {
3210
+ expect(isAutoRemediable({ unassociatedScenarios: 3 }, true)).toBe(false);
3211
+ });
3212
+ });
3213
+ describe('suggestedTestFile for functions without testFile', () => {
3214
+ it('should suggest conventional .test.ts path when testFile is undefined', () => {
3215
+ const result = computeAudit({
3216
+ components: [],
3217
+ functions: [
3218
+ { name: 'useLibraryShell', filePath: 'app/library/context.tsx' },
3219
+ ],
3220
+ scenarioCounts: {},
3221
+ testFileExistence: {},
3222
+ });
3223
+ expect(result.functions[0].suggestedTestFile).toBe('app/library/context.test.ts');
3224
+ expect(result.functions[0].status).toBe('missing');
3225
+ });
3226
+ it('should suggest .test.ts for .ts files', () => {
3227
+ const result = computeAudit({
3228
+ components: [],
3229
+ functions: [{ name: 'calculatePrice', filePath: 'app/lib/pricing.ts' }],
3230
+ scenarioCounts: {},
3231
+ testFileExistence: {},
3232
+ });
3233
+ expect(result.functions[0].suggestedTestFile).toBe('app/lib/pricing.test.ts');
3234
+ });
3235
+ it('should not set suggestedTestFile when testFile is already specified', () => {
3236
+ const result = computeAudit({
3237
+ components: [],
3238
+ functions: [
3239
+ {
3240
+ name: 'calculatePrice',
3241
+ filePath: 'app/lib/pricing.ts',
3242
+ testFile: 'app/lib/pricing.test.ts',
3243
+ },
3244
+ ],
3245
+ scenarioCounts: {},
3246
+ testFileExistence: { 'app/lib/pricing.test.ts': true },
3247
+ });
3248
+ expect(result.functions[0].suggestedTestFile).toBeUndefined();
3249
+ });
3250
+ });
3251
+ describe('hint for missing components', () => {
3252
+ it('should hint that layout files need app-level scenarios', () => {
3253
+ const result = computeAudit({
3254
+ components: [
3255
+ { name: 'LibraryLayout', filePath: 'app/library/layout.tsx' },
3256
+ ],
3257
+ functions: [],
3258
+ scenarioCounts: {},
3259
+ testFileExistence: {},
3260
+ });
3261
+ expect(result.components[0].hint).toContain('layout');
3262
+ expect(result.components[0].hint).toContain('pageFilePath');
3263
+ });
3264
+ it('should hint that page files need app-level scenarios', () => {
3265
+ const result = computeAudit({
3266
+ components: [
3267
+ { name: 'InboxPage', filePath: 'app/library/inbox/page.tsx' },
3268
+ ],
3269
+ functions: [],
3270
+ scenarioCounts: {},
3271
+ testFileExistence: {},
3272
+ });
3273
+ expect(result.components[0].hint).toContain('page');
3274
+ expect(result.components[0].hint).toContain('pageFilePath');
3275
+ });
3276
+ it('should hint that regular components need isolation routes', () => {
3277
+ const result = computeAudit({
3278
+ components: [
3279
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
3280
+ ],
3281
+ functions: [],
3282
+ scenarioCounts: {},
3283
+ testFileExistence: {},
3284
+ });
3285
+ expect(result.components[0].hint).toContain('isolated-components');
3286
+ });
3287
+ it('should not set hint when component has scenarios', () => {
3288
+ const result = computeAudit({
3289
+ components: [
3290
+ { name: 'DrinkCard', filePath: 'app/components/DrinkCard.tsx' },
3291
+ ],
3292
+ functions: [],
3293
+ scenarioCounts: { DrinkCard: 2 },
3294
+ testFileExistence: {},
3295
+ });
3296
+ expect(result.components[0].hint).toBeUndefined();
3297
+ });
3298
+ });
3299
+ describe('formatIncompleteEntityGuidance', () => {
3300
+ it('should include the entity name and scenario count', () => {
3301
+ const { formatIncompleteEntityGuidance } = require('../editorAudit');
3302
+ const result = formatIncompleteEntityGuidance({
3303
+ entitySha: 'abc123',
3304
+ name: 'RuleBuilder',
3305
+ scenarioCount: 5,
3306
+ preExisting: false,
3307
+ });
3308
+ expect(result).toContain('RuleBuilder');
3309
+ expect(result).toContain('5');
3310
+ });
3311
+ it('should tell Claude the exact fix command', () => {
3312
+ const { formatIncompleteEntityGuidance } = require('../editorAudit');
3313
+ const result = formatIncompleteEntityGuidance({
3314
+ entitySha: 'abc123',
3315
+ name: 'RuleBuilder',
3316
+ scenarioCount: 5,
3317
+ preExisting: false,
3318
+ });
3319
+ expect(result).toContain('codeyam editor analyze-imports');
3320
+ });
3321
+ it('should flag pre-existing issues as non-blocking', () => {
3322
+ const { formatIncompleteEntityGuidance } = require('../editorAudit');
3323
+ const result = formatIncompleteEntityGuidance({
3324
+ entitySha: 'abc123',
3325
+ name: 'RuleBuilder',
3326
+ scenarioCount: 5,
3327
+ preExisting: true,
3328
+ });
3329
+ expect(result).toContain('pre-existing');
3330
+ });
3331
+ it('should explain what incomplete means', () => {
3332
+ const { formatIncompleteEntityGuidance } = require('../editorAudit');
3333
+ const result = formatIncompleteEntityGuidance({
3334
+ entitySha: 'abc123',
3335
+ name: 'RuleBuilder',
3336
+ scenarioCount: 5,
3337
+ preExisting: false,
3338
+ });
3339
+ // Should explain the root cause, not just the symptom
3340
+ expect(result).toMatch(/scenario.*without.*import graph|import graph.*not.*built/i);
3341
+ });
3342
+ });
3343
+ describe('getIncompleteEntityFilePaths', () => {
3344
+ // The audit should auto-fix incomplete entities by running analysis on
3345
+ // just their specific file paths, not all 117+ files. This function
3346
+ // resolves entity SHAs to file paths for targeted analysis.
3347
+ let db;
3348
+ let rawDb;
3349
+ beforeEach(async () => {
3350
+ rawDb = new Database(':memory:');
3351
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
3352
+ await db.schema
3353
+ .createTable('entities')
3354
+ .addColumn('sha', 'varchar', (col) => col.primaryKey())
3355
+ .addColumn('name', 'varchar')
3356
+ .addColumn('file_path', 'varchar')
3357
+ .addColumn('project_id', 'varchar')
3358
+ .addColumn('entity_type', 'varchar')
3359
+ .execute();
3360
+ });
3361
+ afterEach(() => {
3362
+ rawDb.close();
3363
+ });
3364
+ it('should resolve entity SHAs to file paths from the entities table', async () => {
3365
+ const { getIncompleteEntityFilePaths } = require('../editorAudit');
3366
+ await db
3367
+ .insertInto('entities')
3368
+ .values([
3369
+ {
3370
+ sha: 'sha-rule',
3371
+ name: 'RuleBuilder',
3372
+ file_path: 'app/components/RuleBuilder.tsx',
3373
+ project_id: 'p1',
3374
+ entity_type: 'component',
3375
+ },
3376
+ {
3377
+ sha: 'sha-row',
3378
+ name: 'ArticleTableRow',
3379
+ file_path: 'app/components/ArticleTableRow.tsx',
3380
+ project_id: 'p1',
3381
+ entity_type: 'component',
3382
+ },
3383
+ ])
3384
+ .execute();
3385
+ const result = await getIncompleteEntityFilePaths(db, [
3386
+ {
3387
+ entitySha: 'sha-rule',
3388
+ name: 'RuleBuilder',
3389
+ scenarioCount: 5,
3390
+ preExisting: false,
3391
+ },
3392
+ {
3393
+ entitySha: 'sha-row',
3394
+ name: 'ArticleTableRow',
3395
+ scenarioCount: 2,
3396
+ preExisting: false,
3397
+ },
3398
+ ]);
3399
+ expect(result).toContain('app/components/RuleBuilder.tsx');
3400
+ expect(result).toContain('app/components/ArticleTableRow.tsx');
3401
+ expect(result).toHaveLength(2);
3402
+ });
3403
+ it('should skip entities whose SHA is not in the entities table', async () => {
3404
+ const { getIncompleteEntityFilePaths } = require('../editorAudit');
3405
+ const result = await getIncompleteEntityFilePaths(db, [
3406
+ {
3407
+ entitySha: 'nonexistent-sha',
3408
+ name: 'Ghost',
3409
+ scenarioCount: 1,
3410
+ preExisting: false,
3411
+ },
3412
+ ]);
3413
+ expect(result).toHaveLength(0);
3414
+ });
3415
+ it('should deduplicate file paths', async () => {
3416
+ const { getIncompleteEntityFilePaths } = require('../editorAudit');
3417
+ await db
3418
+ .insertInto('entities')
3419
+ .values([
3420
+ {
3421
+ sha: 'sha-v1',
3422
+ name: 'Foo',
3423
+ file_path: 'app/Foo.tsx',
3424
+ project_id: 'p1',
3425
+ entity_type: 'component',
3426
+ },
3427
+ {
3428
+ sha: 'sha-v2',
3429
+ name: 'Foo',
3430
+ file_path: 'app/Foo.tsx',
3431
+ project_id: 'p1',
3432
+ entity_type: 'component',
3433
+ },
3434
+ ])
3435
+ .execute();
3436
+ const result = await getIncompleteEntityFilePaths(db, [
3437
+ {
3438
+ entitySha: 'sha-v1',
3439
+ name: 'Foo',
3440
+ scenarioCount: 3,
3441
+ preExisting: false,
3442
+ },
3443
+ {
3444
+ entitySha: 'sha-v2',
3445
+ name: 'Foo',
3446
+ scenarioCount: 1,
3447
+ preExisting: false,
3448
+ },
3449
+ ]);
3450
+ expect(result).toEqual(['app/Foo.tsx']);
3451
+ });
3452
+ });
3453
+ describe('isAutoRemediable never triggers full analysis', () => {
3454
+ // The audit must NEVER run handleAnalyzeImports inline — it takes minutes
3455
+ // for large projects. Auto-remediation should only do the lightweight
3456
+ // entity SHA backfill. isAutoRemediable is now always false; the callers
3457
+ // use needsBackfillOnly for the fast path instead.
3458
+ it('should always return false regardless of summary state', () => {
3459
+ expect(isAutoRemediable({ incompleteEntities: 5 }, false)).toBe(false);
3460
+ expect(isAutoRemediable({ unassociatedScenarios: 3 }, false)).toBe(false);
3461
+ expect(isAutoRemediable({ incompleteEntities: 1, unassociatedScenarios: 2 }, false)).toBe(false);
3462
+ });
3463
+ });
3464
+ // ── isOnlyPreExistingIncomplete ─────────────────────────────────────
3465
+ describe('isOnlyPreExistingIncomplete', () => {
3466
+ it('should return true when all incomplete entities are pre-existing and no other failures', () => {
3467
+ expect(isOnlyPreExistingIncomplete({
3468
+ incompleteEntities: 2,
3469
+ preExistingIncompleteEntities: 2,
3470
+ componentsMissing: 0,
3471
+ componentsWithErrors: 0,
3472
+ functionsFailing: 0,
3473
+ functionsNameMismatch: 0,
3474
+ functionsMissing: 0,
3475
+ missingFromGlossary: 0,
3476
+ miscategorizedScenarios: 0,
3477
+ scenariosNeedingRecapture: 0,
3478
+ }, [
3479
+ {
3480
+ entitySha: 'a',
3481
+ name: 'RuleBuilder',
3482
+ scenarioCount: 5,
3483
+ preExisting: true,
3484
+ },
3485
+ {
3486
+ entitySha: 'b',
3487
+ name: 'ArticleTableRow',
3488
+ scenarioCount: 2,
3489
+ preExisting: true,
3490
+ },
3491
+ ])).toBe(true);
3492
+ });
3493
+ it('should return false when some incomplete entities are NOT pre-existing', () => {
3494
+ expect(isOnlyPreExistingIncomplete({
3495
+ incompleteEntities: 2,
3496
+ preExistingIncompleteEntities: 1,
3497
+ componentsMissing: 0,
3498
+ componentsWithErrors: 0,
3499
+ functionsFailing: 0,
3500
+ functionsNameMismatch: 0,
3501
+ functionsMissing: 0,
3502
+ missingFromGlossary: 0,
3503
+ miscategorizedScenarios: 0,
3504
+ scenariosNeedingRecapture: 0,
3505
+ }, [
3506
+ {
3507
+ entitySha: 'a',
3508
+ name: 'RuleBuilder',
3509
+ scenarioCount: 5,
3510
+ preExisting: true,
3511
+ },
3512
+ {
3513
+ entitySha: 'b',
3514
+ name: 'NewComponent',
3515
+ scenarioCount: 1,
3516
+ preExisting: false,
3517
+ },
3518
+ ])).toBe(false);
3519
+ });
3520
+ it('should return false when there are other failures besides incomplete entities', () => {
3521
+ expect(isOnlyPreExistingIncomplete({
3522
+ incompleteEntities: 2,
3523
+ preExistingIncompleteEntities: 2,
3524
+ componentsMissing: 1,
3525
+ }, [
3526
+ {
3527
+ entitySha: 'a',
3528
+ name: 'RuleBuilder',
3529
+ scenarioCount: 5,
3530
+ preExisting: true,
3531
+ },
3532
+ {
3533
+ entitySha: 'b',
3534
+ name: 'ArticleTableRow',
3535
+ scenarioCount: 2,
3536
+ preExisting: true,
3537
+ },
3538
+ ])).toBe(false);
3539
+ });
3540
+ it('should return false when incomplete entities array is empty', () => {
3541
+ expect(isOnlyPreExistingIncomplete({ incompleteEntities: 0 }, [])).toBe(false);
3542
+ });
3543
+ it('should return false when incomplete entities array is missing', () => {
3544
+ expect(isOnlyPreExistingIncomplete({ incompleteEntities: 2, preExistingIncompleteEntities: 2 }, undefined)).toBe(false);
3545
+ });
3546
+ });
3547
+ describe('isOnlyIncompleteEntities with unassociatedScenarios', () => {
3548
+ it('should return true when only unassociatedScenarios present', () => {
3549
+ expect(isOnlyIncompleteEntities({ unassociatedScenarios: 5 })).toBe(true);
3550
+ });
3551
+ it('should return false when unassociatedScenarios present with other failures', () => {
3552
+ expect(isOnlyIncompleteEntities({
3553
+ unassociatedScenarios: 5,
3554
+ functionsMissing: 1,
3555
+ })).toBe(false);
3556
+ });
3557
+ });
3558
+ });
3559
+ //# sourceMappingURL=editorAudit.test.js.map