@codeyam/codeyam-cli 0.1.0-staging.8778565 → 0.1.0-staging.87dd4be

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 (310) 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 +2 -2
  4. package/analyzer-template/packages/ai/package.json +1 -1
  5. package/analyzer-template/packages/aws/package.json +1 -1
  6. package/analyzer-template/packages/database/package.json +1 -1
  7. package/analyzer-template/packages/database/src/lib/kysely/tables/editorScenariosTable.ts +82 -0
  8. package/analyzer-template/packages/database/src/lib/loadEntities.ts +0 -6
  9. package/analyzer-template/packages/database/src/lib/updateCommitMetadata.ts +0 -65
  10. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts +5 -0
  11. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.d.ts.map +1 -1
  12. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js +84 -0
  13. package/analyzer-template/packages/github/dist/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -1
  14. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.d.ts.map +1 -1
  15. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js +0 -6
  16. package/analyzer-template/packages/github/dist/database/src/lib/loadEntities.js.map +1 -1
  17. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.d.ts.map +1 -1
  18. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js +0 -25
  19. package/analyzer-template/packages/github/dist/database/src/lib/updateCommitMetadata.js.map +1 -1
  20. package/codeyam-cli/src/cli.js +9 -0
  21. package/codeyam-cli/src/cli.js.map +1 -1
  22. package/codeyam-cli/src/commands/__tests__/editor.isolateArgs.test.js +51 -0
  23. package/codeyam-cli/src/commands/__tests__/editor.isolateArgs.test.js.map +1 -0
  24. package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js +56 -0
  25. package/codeyam-cli/src/commands/__tests__/editor.stepDispatch.test.js.map +1 -0
  26. package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js +101 -47
  27. package/codeyam-cli/src/commands/__tests__/init.gitignore.test.js.map +1 -1
  28. package/codeyam-cli/src/commands/editor.js +2369 -346
  29. package/codeyam-cli/src/commands/editor.js.map +1 -1
  30. package/codeyam-cli/src/commands/editorIsolateArgs.js +25 -0
  31. package/codeyam-cli/src/commands/editorIsolateArgs.js.map +1 -0
  32. package/codeyam-cli/src/commands/init.js +69 -34
  33. package/codeyam-cli/src/commands/init.js.map +1 -1
  34. package/codeyam-cli/src/commands/telemetry.js +37 -0
  35. package/codeyam-cli/src/commands/telemetry.js.map +1 -0
  36. package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js +173 -0
  37. package/codeyam-cli/src/utils/__tests__/analyzerFinalization.test.js.map +1 -0
  38. package/codeyam-cli/src/utils/__tests__/editorApi.test.js +18 -8
  39. package/codeyam-cli/src/utils/__tests__/editorApi.test.js.map +1 -1
  40. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js +2046 -1
  41. package/codeyam-cli/src/utils/__tests__/editorAudit.test.js.map +1 -1
  42. package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js +76 -0
  43. package/codeyam-cli/src/utils/__tests__/editorBroadcastViewport.test.js.map +1 -0
  44. package/codeyam-cli/src/utils/__tests__/editorCaptureScenarioSeeding.test.js +137 -0
  45. package/codeyam-cli/src/utils/__tests__/editorCaptureScenarioSeeding.test.js.map +1 -0
  46. package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js +100 -0
  47. package/codeyam-cli/src/utils/__tests__/editorDeleteScenario.test.js.map +1 -0
  48. package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js +76 -3
  49. package/codeyam-cli/src/utils/__tests__/editorEntityChangeStatus.test.js.map +1 -1
  50. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js +381 -0
  51. package/codeyam-cli/src/utils/__tests__/editorEntityHelpers.test.js.map +1 -0
  52. package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js +202 -1
  53. package/codeyam-cli/src/utils/__tests__/editorLoaderHelpers.test.js.map +1 -1
  54. package/codeyam-cli/src/utils/__tests__/editorMigration.test.js +435 -0
  55. package/codeyam-cli/src/utils/__tests__/editorMigration.test.js.map +1 -0
  56. package/codeyam-cli/src/utils/__tests__/editorPreview.test.js +88 -1
  57. package/codeyam-cli/src/utils/__tests__/editorPreview.test.js.map +1 -1
  58. package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js +47 -1
  59. package/codeyam-cli/src/utils/__tests__/editorProxySession.test.js.map +1 -1
  60. package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js +70 -0
  61. package/codeyam-cli/src/utils/__tests__/editorScenarioSwitch.test.js.map +1 -1
  62. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js +1335 -1
  63. package/codeyam-cli/src/utils/__tests__/editorScenarios.test.js.map +1 -1
  64. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js +67 -0
  65. package/codeyam-cli/src/utils/__tests__/editorSeedAdapter.test.js.map +1 -1
  66. package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js +143 -0
  67. package/codeyam-cli/src/utils/__tests__/editorSeedAdapterPrismaValidation.test.js.map +1 -0
  68. package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js +66 -0
  69. package/codeyam-cli/src/utils/__tests__/editorSessionFilter.test.js.map +1 -0
  70. package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js +53 -0
  71. package/codeyam-cli/src/utils/__tests__/editorShouldRevalidate.test.js.map +1 -0
  72. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js +363 -11
  73. package/codeyam-cli/src/utils/__tests__/entityChangeStatus.test.js.map +1 -1
  74. package/codeyam-cli/src/utils/__tests__/glossaryAdd.test.js +177 -0
  75. package/codeyam-cli/src/utils/__tests__/glossaryAdd.test.js.map +1 -0
  76. package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js +30 -2
  77. package/codeyam-cli/src/utils/__tests__/parseRegisterArg.test.js.map +1 -1
  78. package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js +118 -0
  79. package/codeyam-cli/src/utils/__tests__/routePatternMatching.test.js.map +1 -0
  80. package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js +284 -0
  81. package/codeyam-cli/src/utils/__tests__/scenarioCoverage.test.js.map +1 -0
  82. package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js +649 -223
  83. package/codeyam-cli/src/utils/__tests__/scenariosManifest.test.js.map +1 -1
  84. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js +1 -0
  85. package/codeyam-cli/src/utils/__tests__/setupClaudeCodeSettings.test.js.map +1 -1
  86. package/codeyam-cli/src/utils/__tests__/telemetry.test.js +159 -0
  87. package/codeyam-cli/src/utils/__tests__/telemetry.test.js.map +1 -0
  88. package/codeyam-cli/src/utils/analysisRunner.js +3 -1
  89. package/codeyam-cli/src/utils/analysisRunner.js.map +1 -1
  90. package/codeyam-cli/src/utils/analyzer.js +9 -0
  91. package/codeyam-cli/src/utils/analyzer.js.map +1 -1
  92. package/codeyam-cli/src/utils/analyzerFinalization.js +100 -0
  93. package/codeyam-cli/src/utils/analyzerFinalization.js.map +1 -0
  94. package/codeyam-cli/src/utils/backgroundServer.js +3 -9
  95. package/codeyam-cli/src/utils/backgroundServer.js.map +1 -1
  96. package/codeyam-cli/src/utils/database.js +37 -2
  97. package/codeyam-cli/src/utils/database.js.map +1 -1
  98. package/codeyam-cli/src/utils/editorApi.js +11 -5
  99. package/codeyam-cli/src/utils/editorApi.js.map +1 -1
  100. package/codeyam-cli/src/utils/editorAudit.js +372 -5
  101. package/codeyam-cli/src/utils/editorAudit.js.map +1 -1
  102. package/codeyam-cli/src/utils/editorBroadcastViewport.js +26 -0
  103. package/codeyam-cli/src/utils/editorBroadcastViewport.js.map +1 -0
  104. package/codeyam-cli/src/utils/editorDeleteScenario.js +67 -0
  105. package/codeyam-cli/src/utils/editorDeleteScenario.js.map +1 -0
  106. package/codeyam-cli/src/utils/editorEntityChangeStatus.js +13 -7
  107. package/codeyam-cli/src/utils/editorEntityChangeStatus.js.map +1 -1
  108. package/codeyam-cli/src/utils/editorEntityHelpers.js +144 -0
  109. package/codeyam-cli/src/utils/editorEntityHelpers.js.map +1 -0
  110. package/codeyam-cli/src/utils/editorLoaderHelpers.js +72 -1
  111. package/codeyam-cli/src/utils/editorLoaderHelpers.js.map +1 -1
  112. package/codeyam-cli/src/utils/editorMigration.js +224 -0
  113. package/codeyam-cli/src/utils/editorMigration.js.map +1 -0
  114. package/codeyam-cli/src/utils/editorPreview.js +31 -0
  115. package/codeyam-cli/src/utils/editorPreview.js.map +1 -1
  116. package/codeyam-cli/src/utils/editorRecapture.js +109 -0
  117. package/codeyam-cli/src/utils/editorRecapture.js.map +1 -0
  118. package/codeyam-cli/src/utils/editorScenarioSwitch.js +24 -2
  119. package/codeyam-cli/src/utils/editorScenarioSwitch.js.map +1 -1
  120. package/codeyam-cli/src/utils/editorScenarios.js +458 -0
  121. package/codeyam-cli/src/utils/editorScenarios.js.map +1 -1
  122. package/codeyam-cli/src/utils/editorSeedAdapter.js +253 -4
  123. package/codeyam-cli/src/utils/editorSeedAdapter.js.map +1 -1
  124. package/codeyam-cli/src/utils/editorShouldRevalidate.js +21 -0
  125. package/codeyam-cli/src/utils/editorShouldRevalidate.js.map +1 -0
  126. package/codeyam-cli/src/utils/entityChangeStatus.js +53 -6
  127. package/codeyam-cli/src/utils/entityChangeStatus.js.map +1 -1
  128. package/codeyam-cli/src/utils/entityChangeStatus.server.js +41 -3
  129. package/codeyam-cli/src/utils/entityChangeStatus.server.js.map +1 -1
  130. package/codeyam-cli/src/utils/fileWatcher.js +38 -0
  131. package/codeyam-cli/src/utils/fileWatcher.js.map +1 -1
  132. package/codeyam-cli/src/utils/glossaryAdd.js +74 -0
  133. package/codeyam-cli/src/utils/glossaryAdd.js.map +1 -0
  134. package/codeyam-cli/src/utils/install-skills.js +14 -0
  135. package/codeyam-cli/src/utils/install-skills.js.map +1 -1
  136. package/codeyam-cli/src/utils/parseRegisterArg.js.map +1 -1
  137. package/codeyam-cli/src/utils/progress.js +2 -2
  138. package/codeyam-cli/src/utils/progress.js.map +1 -1
  139. package/codeyam-cli/src/utils/routePatternMatching.js +129 -0
  140. package/codeyam-cli/src/utils/routePatternMatching.js.map +1 -0
  141. package/codeyam-cli/src/utils/scenarioCoverage.js +77 -0
  142. package/codeyam-cli/src/utils/scenarioCoverage.js.map +1 -0
  143. package/codeyam-cli/src/utils/scenariosManifest.js +269 -74
  144. package/codeyam-cli/src/utils/scenariosManifest.js.map +1 -1
  145. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js +1 -0
  146. package/codeyam-cli/src/utils/setupClaudeCodeSettings.js.map +1 -1
  147. package/codeyam-cli/src/utils/simulationGateMiddleware.js +8 -1
  148. package/codeyam-cli/src/utils/simulationGateMiddleware.js.map +1 -1
  149. package/codeyam-cli/src/utils/slugUtils.js +25 -0
  150. package/codeyam-cli/src/utils/slugUtils.js.map +1 -0
  151. package/codeyam-cli/src/utils/syncMocksMiddleware.js +2 -2
  152. package/codeyam-cli/src/utils/syncMocksMiddleware.js.map +1 -1
  153. package/codeyam-cli/src/utils/telemetry.js +106 -0
  154. package/codeyam-cli/src/utils/telemetry.js.map +1 -0
  155. package/codeyam-cli/src/utils/telemetryMiddleware.js +22 -0
  156. package/codeyam-cli/src/utils/telemetryMiddleware.js.map +1 -0
  157. package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js +35 -0
  158. package/codeyam-cli/src/webserver/__tests__/buildPtyEnv.test.js.map +1 -0
  159. package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js +80 -0
  160. package/codeyam-cli/src/webserver/__tests__/clientErrors.test.js.map +1 -0
  161. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js +218 -0
  162. package/codeyam-cli/src/webserver/__tests__/editorProxy.test.js.map +1 -1
  163. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js +217 -0
  164. package/codeyam-cli/src/webserver/__tests__/idleDetector.test.js.map +1 -0
  165. package/codeyam-cli/src/webserver/app/lib/clientErrors.js +71 -0
  166. package/codeyam-cli/src/webserver/app/lib/clientErrors.js.map +1 -0
  167. package/codeyam-cli/src/webserver/app/lib/git.js +3 -2
  168. package/codeyam-cli/src/webserver/app/lib/git.js.map +1 -1
  169. package/codeyam-cli/src/webserver/app/types/editor.js +8 -0
  170. package/codeyam-cli/src/webserver/app/types/editor.js.map +1 -0
  171. package/codeyam-cli/src/webserver/backgroundServer.js +60 -61
  172. package/codeyam-cli/src/webserver/backgroundServer.js.map +1 -1
  173. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-CLe80MMu.js +1 -0
  174. package/codeyam-cli/src/webserver/build/client/assets/{EntityItem-BcgbViKV.js → EntityItem-Crt_KN_U.js} +3 -3
  175. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-CQgyEGV-.js +1 -0
  176. package/codeyam-cli/src/webserver/build/client/assets/{EntityTypeIcon-CQIG2qda.js → EntityTypeIcon-CD7lGABo.js} +1 -1
  177. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-CgTNOhnu.js +1 -0
  178. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-CKeQT5Ty.js +25 -0
  179. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-D3s1MFkb.js +3 -0
  180. package/codeyam-cli/src/webserver/build/client/assets/{LoadingDots-BU_OAEMP.js → LoadingDots-By5zI316.js} +1 -1
  181. package/codeyam-cli/src/webserver/build/client/assets/{LogViewer-ceAyBX-H.js → LogViewer-CM5zg40N.js} +3 -3
  182. package/codeyam-cli/src/webserver/build/client/assets/{ReportIssueModal-BzHcG7SE.js → ReportIssueModal-C2PLkej3.js} +2 -2
  183. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-DanvyBPb.js +1 -0
  184. package/codeyam-cli/src/webserver/build/client/assets/{ScenarioViewer-0DY_NKil.js → ScenarioViewer-DUMfcNVK.js} +3 -3
  185. package/codeyam-cli/src/webserver/build/client/assets/Spinner-D0LgAaSa.js +34 -0
  186. package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-CK7-NaPZ.js +1 -0
  187. package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-BA_Ry-rs.js +1 -0
  188. package/codeyam-cli/src/webserver/build/client/assets/{_index-DLxKhri3.js → _index-BAWd-Xjf.js} +2 -2
  189. package/codeyam-cli/src/webserver/build/client/assets/{activity.(_tab)-BcY3q6nt.js → activity.(_tab)-BOARiB-g.js} +3 -3
  190. package/codeyam-cli/src/webserver/build/client/assets/{addon-web-links-Duc5hnl7.js → addon-web-links-CHx25PAe.js} +1 -1
  191. package/codeyam-cli/src/webserver/build/client/assets/{agent-transcripts-Bni3iiUj.js → agent-transcripts-Bg3e7q4S.js} +3 -3
  192. package/codeyam-cli/src/webserver/build/client/assets/api.editor-recapture-stale-l0sNRNKZ.js +1 -0
  193. package/codeyam-cli/src/webserver/build/client/assets/api.editor-rename-scenario-l0sNRNKZ.js +1 -0
  194. package/codeyam-cli/src/webserver/build/client/assets/api.editor-save-seed-state-l0sNRNKZ.js +1 -0
  195. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-coverage-l0sNRNKZ.js +1 -0
  196. package/codeyam-cli/src/webserver/build/client/assets/api.editor-scenario-prompt-l0sNRNKZ.js +1 -0
  197. package/codeyam-cli/src/webserver/build/client/assets/api.editor-session-l0sNRNKZ.js +1 -0
  198. package/codeyam-cli/src/webserver/build/client/assets/{book-open-BYOypzCa.js → book-open-CL-lMgHh.js} +1 -1
  199. package/codeyam-cli/src/webserver/build/client/assets/{chevron-down-C_Pmso5S.js → chevron-down-GmAjGS9-.js} +1 -1
  200. package/codeyam-cli/src/webserver/build/client/assets/chunk-JZWAC4HX-BAdwhyCx.js +43 -0
  201. package/codeyam-cli/src/webserver/build/client/assets/{circle-check-BVMi9VA5.js → circle-check-DFcQkN5j.js} +1 -1
  202. package/codeyam-cli/src/webserver/build/client/assets/{copy-n2FB0_Sw.js → copy-C6iF61Xs.js} +1 -1
  203. package/codeyam-cli/src/webserver/build/client/assets/{createLucideIcon-CC6AbExI.js → createLucideIcon-4ImjHTVC.js} +1 -1
  204. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-C8y4mmyv.js +1 -0
  205. package/codeyam-cli/src/webserver/build/client/assets/editor._tab-Gbk_i5Js.js +1 -0
  206. package/codeyam-cli/src/webserver/build/client/assets/editor.entity.(_sha)-Bnx7yUP0.js +58 -0
  207. package/codeyam-cli/src/webserver/build/client/assets/editorPreview-oepecPae.js +41 -0
  208. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha._-BF4oLwaE.js → entity._sha._-Blfy9UlN.js} +2 -2
  209. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-KTQuL0aj.js +6 -0
  210. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-C6eeL24i.js +6 -0
  211. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-DQM8E7L4.js +6 -0
  212. package/codeyam-cli/src/webserver/build/client/assets/{entity._sha_.edit._scenarioId-BMvVHNXU.js → entity._sha_.edit._scenarioId-CAoXLsQr.js} +2 -2
  213. package/codeyam-cli/src/webserver/build/client/assets/{entry.client-DTvKq3TY.js → entry.client-SuW9syRS.js} +6 -6
  214. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-Daa96Fr1.js +1 -0
  215. package/codeyam-cli/src/webserver/build/client/assets/files-D-xGrg29.js +1 -0
  216. package/codeyam-cli/src/webserver/build/client/assets/git-Bq_fbXP5.js +1 -0
  217. package/codeyam-cli/src/webserver/build/client/assets/globals-fAqOD9ex.css +1 -0
  218. package/codeyam-cli/src/webserver/build/client/assets/{index-BcvgDzbZ.js → index-Bp1l4hSv.js} +1 -1
  219. package/codeyam-cli/src/webserver/build/client/assets/{index-10oVnAAH.js → index-CWV9XZiG.js} +1 -1
  220. package/codeyam-cli/src/webserver/build/client/assets/{index-yHOVb4rc.js → index-DE3jI_dv.js} +1 -1
  221. package/codeyam-cli/src/webserver/build/client/assets/jsx-runtime-D_zvdyIk.js +9 -0
  222. package/codeyam-cli/src/webserver/build/client/assets/labs-B_IX45ih.js +1 -0
  223. package/codeyam-cli/src/webserver/build/client/assets/{loader-circle-DaAZ_H2w.js → loader-circle-De-7qQ2u.js} +1 -1
  224. package/codeyam-cli/src/webserver/build/client/assets/manifest-b9d4d267.js +1 -0
  225. package/codeyam-cli/src/webserver/build/client/assets/memory-Cx2xEx7s.js +101 -0
  226. package/codeyam-cli/src/webserver/build/client/assets/{pause-f5-1lKBt.js → pause-CFxEKL1u.js} +1 -1
  227. package/codeyam-cli/src/webserver/build/client/assets/root-DB3O9_9j.js +67 -0
  228. package/codeyam-cli/src/webserver/build/client/assets/{search-Di64LWVb.js → search-BdBb5aqc.js} +1 -1
  229. package/codeyam-cli/src/webserver/build/client/assets/settings-DdE-Untf.js +1 -0
  230. package/codeyam-cli/src/webserver/build/client/assets/simulations-DSCdE99u.js +1 -0
  231. package/codeyam-cli/src/webserver/build/client/assets/{terminal-Br7MOqts.js → terminal-CrplD4b1.js} +1 -1
  232. package/codeyam-cli/src/webserver/build/client/assets/{triangle-alert-BLdiCuG-.js → triangle-alert-DqJ0j69l.js} +1 -1
  233. package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-DhXHbEjP.js +1 -0
  234. package/codeyam-cli/src/webserver/build/client/assets/{useLastLogLine-C14nCb1q.js → useLastLogLine-BNd5hYuW.js} +1 -1
  235. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-Cy5Qg_UR.js +1 -0
  236. package/codeyam-cli/src/webserver/build/client/assets/useToast-5HR2j9ZE.js +1 -0
  237. package/codeyam-cli/src/webserver/build/client/sound-test.html +98 -0
  238. package/codeyam-cli/src/webserver/build/server/assets/analysisRunner-CGwTN3V2.js +13 -0
  239. package/codeyam-cli/src/webserver/build/server/assets/index-D4meMKy3.js +1 -0
  240. package/codeyam-cli/src/webserver/build/server/assets/init-odGJ_c2-.js +10 -0
  241. package/codeyam-cli/src/webserver/build/server/assets/progress-CHTtrxFG.js +1 -0
  242. package/codeyam-cli/src/webserver/build/server/assets/server-build-TmPfF7pT.js +552 -0
  243. package/codeyam-cli/src/webserver/build/server/index.js +1 -1
  244. package/codeyam-cli/src/webserver/build-info.json +5 -5
  245. package/codeyam-cli/src/webserver/editorProxy.js +208 -17
  246. package/codeyam-cli/src/webserver/editorProxy.js.map +1 -1
  247. package/codeyam-cli/src/webserver/idleDetector.js +106 -0
  248. package/codeyam-cli/src/webserver/idleDetector.js.map +1 -0
  249. package/codeyam-cli/src/webserver/mockStateEvents.js +28 -0
  250. package/codeyam-cli/src/webserver/mockStateEvents.js.map +1 -0
  251. package/codeyam-cli/src/webserver/public/sound-test.html +98 -0
  252. package/codeyam-cli/src/webserver/scripts/journalCapture.ts +36 -0
  253. package/codeyam-cli/src/webserver/server.js +87 -4
  254. package/codeyam-cli/src/webserver/server.js.map +1 -1
  255. package/codeyam-cli/src/webserver/terminalServer.js +140 -35
  256. package/codeyam-cli/src/webserver/terminalServer.js.map +1 -1
  257. package/codeyam-cli/templates/chrome-extension-react/README.md +46 -0
  258. package/codeyam-cli/templates/chrome-extension-react/package.json +1 -0
  259. package/codeyam-cli/templates/codeyam-editor-claude.md +84 -5
  260. package/codeyam-cli/templates/codeyam-editor-reference.md +214 -0
  261. package/codeyam-cli/templates/editor-step-hook.py +114 -24
  262. package/codeyam-cli/templates/expo-react-native/README.md +41 -0
  263. package/codeyam-cli/templates/expo-react-native/package.json +1 -0
  264. package/codeyam-cli/templates/nextjs-prisma-sqlite/DATABASE.md +14 -0
  265. package/codeyam-cli/templates/nextjs-prisma-sqlite/README.md +53 -0
  266. package/codeyam-cli/templates/nextjs-prisma-sqlite/package.json +2 -1
  267. package/codeyam-cli/templates/nextjs-prisma-sqlite/seed-adapter.ts +42 -7
  268. package/codeyam-cli/templates/nextjs-prisma-supabase/README.md +52 -0
  269. package/codeyam-cli/templates/nextjs-prisma-supabase/package.json +2 -1
  270. package/codeyam-cli/templates/seed-adapters/supabase.ts +282 -0
  271. package/codeyam-cli/templates/skills/codeyam-dev-mode/SKILL.md +1 -1
  272. package/codeyam-cli/templates/skills/codeyam-editor/SKILL.md +76 -10
  273. package/package.json +2 -1
  274. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js +84 -0
  275. package/packages/database/src/lib/kysely/tables/editorScenariosTable.js.map +1 -1
  276. package/packages/database/src/lib/loadEntities.js +0 -6
  277. package/packages/database/src/lib/loadEntities.js.map +1 -1
  278. package/packages/database/src/lib/updateCommitMetadata.js +0 -25
  279. package/packages/database/src/lib/updateCommitMetadata.js.map +1 -1
  280. package/codeyam-cli/src/webserver/build/client/assets/CopyButton-BPXZwM4t.js +0 -1
  281. package/codeyam-cli/src/webserver/build/client/assets/EntityTypeBadge-g3saevPb.js +0 -1
  282. package/codeyam-cli/src/webserver/build/client/assets/InlineSpinner-Bu6c6aDe.js +0 -1
  283. package/codeyam-cli/src/webserver/build/client/assets/InteractivePreview-DYFW3lDD.js +0 -25
  284. package/codeyam-cli/src/webserver/build/client/assets/LibraryFunctionPreview-DLeucoVX.js +0 -3
  285. package/codeyam-cli/src/webserver/build/client/assets/SafeScreenshot-BED4B6sP.js +0 -1
  286. package/codeyam-cli/src/webserver/build/client/assets/Spinner-Bb5uFQ5V.js +0 -34
  287. package/codeyam-cli/src/webserver/build/client/assets/TruncatedFilePath-C8OKAR5x.js +0 -1
  288. package/codeyam-cli/src/webserver/build/client/assets/ViewportInspectBar-oAf2Kqsf.js +0 -1
  289. package/codeyam-cli/src/webserver/build/client/assets/chunk-JZWAC4HX-C4pqxYJB.js +0 -51
  290. package/codeyam-cli/src/webserver/build/client/assets/dev.empty-Csi0_PMl.js +0 -1
  291. package/codeyam-cli/src/webserver/build/client/assets/editor-DgN1LTTt.js +0 -10
  292. package/codeyam-cli/src/webserver/build/client/assets/editorPreview-BLQMSKZa.js +0 -41
  293. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.dev-C7YX6r3H.js +0 -6
  294. package/codeyam-cli/src/webserver/build/client/assets/entity._sha.scenarios._scenarioId.fullscreen-CF164ouH.js +0 -6
  295. package/codeyam-cli/src/webserver/build/client/assets/entity._sha_.create-scenario-p9hhkjJM.js +0 -6
  296. package/codeyam-cli/src/webserver/build/client/assets/fileTableUtils-cPo8LiG3.js +0 -1
  297. package/codeyam-cli/src/webserver/build/client/assets/files-BZrlFE1F.js +0 -1
  298. package/codeyam-cli/src/webserver/build/client/assets/git-DdZcvjGh.js +0 -1
  299. package/codeyam-cli/src/webserver/build/client/assets/globals-BkWJ_UNc.css +0 -1
  300. package/codeyam-cli/src/webserver/build/client/assets/labs-Zk7ryIM1.js +0 -1
  301. package/codeyam-cli/src/webserver/build/client/assets/manifest-c26eb85b.js +0 -1
  302. package/codeyam-cli/src/webserver/build/client/assets/memory-Bl2rpw8u.js +0 -96
  303. package/codeyam-cli/src/webserver/build/client/assets/root-ClvYBUSA.js +0 -67
  304. package/codeyam-cli/src/webserver/build/client/assets/settings-0OrEMU6J.js +0 -1
  305. package/codeyam-cli/src/webserver/build/client/assets/simulations-DWT-CvLy.js +0 -1
  306. package/codeyam-cli/src/webserver/build/client/assets/useCustomSizes-CrAK28Bc.js +0 -1
  307. package/codeyam-cli/src/webserver/build/client/assets/useReportContext-O-jkvSPx.js +0 -1
  308. package/codeyam-cli/src/webserver/build/client/assets/useToast-9FIWuYfK.js +0 -1
  309. package/codeyam-cli/src/webserver/build/server/assets/index-DflIr5SD.js +0 -1
  310. package/codeyam-cli/src/webserver/build/server/assets/server-build-OhKy839M.js +0 -416
@@ -1,4 +1,6 @@
1
- import { isComponent, classifyGlossaryEntries, computeAudit, filterGlossaryByChangeStatus, } from "../editorAudit.js";
1
+ import Database from 'better-sqlite3';
2
+ import { Kysely, SqliteDialect } from 'kysely';
3
+ import { isComponent, classifyGlossaryEntries, computeAudit, filterGlossaryByChangeStatus, resolveAuditSessionScope, queryScenarioCounts, queryPageScenarioCounts, queryIncompleteEntities, queryMiscategorizedScenarios, isOnlyIncompleteEntities, isAutoRemediable, identifyScenariosNeedingRecapture, detectDuplicateNames, } from "../editorAudit.js";
2
4
  describe('editorAudit', () => {
3
5
  describe('isComponent', () => {
4
6
  it('should return true for JSX.Element return type', () => {
@@ -288,6 +290,29 @@ describe('editorAudit', () => {
288
290
  expect(result.functions[0].testsPassing).toBe(false);
289
291
  expect(result.functions[0].testsVisibleInUi).toBe(true);
290
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
+ });
291
316
  it('should mark function as name_mismatch when tests pass but no describe matches', () => {
292
317
  const result = computeAudit({
293
318
  components: [],
@@ -631,5 +656,2025 @@ describe('editorAudit', () => {
631
656
  expect(filtered.map((e) => e.name)).toContain('DrinkCard');
632
657
  });
633
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
+ // ── queryMiscategorizedScenarios ─────────────────────────────────────
1470
+ describe('queryMiscategorizedScenarios', () => {
1471
+ let db;
1472
+ let rawDb;
1473
+ const projectId = 'test-project-id';
1474
+ beforeEach(async () => {
1475
+ rawDb = new Database(':memory:');
1476
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
1477
+ await db.schema
1478
+ .createTable('editor_scenarios')
1479
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1480
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
1481
+ .addColumn('name', 'varchar', (col) => col.notNull())
1482
+ .addColumn('component_name', 'varchar')
1483
+ .addColumn('component_path', 'varchar')
1484
+ .addColumn('entity_sha', 'varchar')
1485
+ .addColumn('display_name', 'varchar')
1486
+ .addColumn('page_file_path', 'varchar')
1487
+ .addColumn('url', 'varchar')
1488
+ .addColumn('created_at', 'datetime')
1489
+ .addColumn('updated_at', 'datetime')
1490
+ .execute();
1491
+ });
1492
+ afterEach(async () => {
1493
+ await db.destroy();
1494
+ });
1495
+ it('should return empty when all component scenarios use isolation routes', async () => {
1496
+ await db
1497
+ .insertInto('editor_scenarios')
1498
+ .values({
1499
+ id: 'sc-1',
1500
+ project_id: projectId,
1501
+ name: 'LibraryCard - Default',
1502
+ component_name: 'LibraryCard',
1503
+ url: '/isolated-components/LibraryCard?s=Default',
1504
+ created_at: '2026-03-17 12:00:00',
1505
+ })
1506
+ .execute();
1507
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1508
+ expect(result).toEqual([]);
1509
+ });
1510
+ it('should flag component scenarios that use non-isolation URLs', async () => {
1511
+ // This is the bug: "Full Library Page" registered as component_name=LibraryPage
1512
+ // but url=/library — it's pointing at the real page, not an isolation route
1513
+ await db
1514
+ .insertInto('editor_scenarios')
1515
+ .values({
1516
+ id: 'sc-1',
1517
+ project_id: projectId,
1518
+ name: 'Full Library Page',
1519
+ component_name: 'LibraryPage',
1520
+ url: '/library',
1521
+ created_at: '2026-03-17 12:41:40',
1522
+ })
1523
+ .execute();
1524
+ await db
1525
+ .insertInto('editor_scenarios')
1526
+ .values({
1527
+ id: 'sc-2',
1528
+ project_id: projectId,
1529
+ name: 'Empty Library Page',
1530
+ component_name: 'LibraryPage',
1531
+ url: '/library',
1532
+ created_at: '2026-03-17 12:41:51',
1533
+ })
1534
+ .execute();
1535
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1536
+ expect(result).toEqual([
1537
+ {
1538
+ componentName: 'LibraryPage',
1539
+ scenarioNames: ['Full Library Page', 'Empty Library Page'],
1540
+ url: '/library',
1541
+ },
1542
+ ]);
1543
+ });
1544
+ it('should not flag page-level scenarios (no component_name)', async () => {
1545
+ // App-level scenarios have no component_name — they're fine with real URLs
1546
+ await db
1547
+ .insertInto('editor_scenarios')
1548
+ .values({
1549
+ id: 'sc-1',
1550
+ project_id: projectId,
1551
+ name: 'Library with Articles',
1552
+ url: '/',
1553
+ created_at: '2026-03-17 12:25:14',
1554
+ })
1555
+ .execute();
1556
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1557
+ expect(result).toEqual([]);
1558
+ });
1559
+ it('should group miscategorized scenarios by component and URL', async () => {
1560
+ // Two different components both misusing real URLs
1561
+ await db
1562
+ .insertInto('editor_scenarios')
1563
+ .values({
1564
+ id: 'sc-1',
1565
+ project_id: projectId,
1566
+ name: 'Full Library Page',
1567
+ component_name: 'LibraryPage',
1568
+ url: '/library',
1569
+ created_at: '2026-03-17 12:41:40',
1570
+ })
1571
+ .execute();
1572
+ await db
1573
+ .insertInto('editor_scenarios')
1574
+ .values({
1575
+ id: 'sc-2',
1576
+ project_id: projectId,
1577
+ name: 'Dashboard - Full',
1578
+ component_name: 'Dashboard',
1579
+ url: '/dashboard',
1580
+ created_at: '2026-03-17 12:50:00',
1581
+ })
1582
+ .execute();
1583
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1584
+ expect(result).toHaveLength(2);
1585
+ expect(result.map((r) => r.componentName).sort()).toEqual([
1586
+ 'Dashboard',
1587
+ 'LibraryPage',
1588
+ ]);
1589
+ });
1590
+ it('should scope to session when featureStartedAt is provided', async () => {
1591
+ // Old miscategorized scenario — before session
1592
+ await db
1593
+ .insertInto('editor_scenarios')
1594
+ .values({
1595
+ id: 'sc-old',
1596
+ project_id: projectId,
1597
+ name: 'Old Page',
1598
+ component_name: 'OldComponent',
1599
+ url: '/old',
1600
+ created_at: '2026-03-16 10:00:00',
1601
+ })
1602
+ .execute();
1603
+ // New miscategorized scenario — in session
1604
+ await db
1605
+ .insertInto('editor_scenarios')
1606
+ .values({
1607
+ id: 'sc-new',
1608
+ project_id: projectId,
1609
+ name: 'Full Library Page',
1610
+ component_name: 'LibraryPage',
1611
+ url: '/library',
1612
+ created_at: '2026-03-17 12:41:40',
1613
+ })
1614
+ .execute();
1615
+ const result = await queryMiscategorizedScenarios(db, projectId, '2026-03-17T11:58:55.562Z');
1616
+ expect(result).toHaveLength(1);
1617
+ expect(result[0].componentName).toBe('LibraryPage');
1618
+ });
1619
+ it('should not flag component scenarios with null URL', async () => {
1620
+ await db
1621
+ .insertInto('editor_scenarios')
1622
+ .values({
1623
+ id: 'sc-1',
1624
+ project_id: projectId,
1625
+ name: 'NoUrl - Default',
1626
+ component_name: 'NoUrl',
1627
+ created_at: '2026-03-17 12:00:00',
1628
+ })
1629
+ .execute();
1630
+ const result = await queryMiscategorizedScenarios(db, projectId, null);
1631
+ expect(result).toEqual([]);
1632
+ });
1633
+ });
1634
+ // ── isOnlyIncompleteEntities ─────────────────────────────────────────
1635
+ describe('isOnlyIncompleteEntities', () => {
1636
+ it('should return true when incompleteEntities is the only failure', () => {
1637
+ expect(isOnlyIncompleteEntities({
1638
+ componentsMissing: 0,
1639
+ componentsWithErrors: 0,
1640
+ functionsFailing: 0,
1641
+ functionsNameMismatch: 0,
1642
+ functionsMissing: 0,
1643
+ missingFromGlossary: 0,
1644
+ incompleteEntities: 3,
1645
+ allPassing: false,
1646
+ })).toBe(true);
1647
+ });
1648
+ it('should return false when there are also missing components', () => {
1649
+ expect(isOnlyIncompleteEntities({
1650
+ componentsMissing: 1,
1651
+ componentsWithErrors: 0,
1652
+ functionsFailing: 0,
1653
+ functionsNameMismatch: 0,
1654
+ functionsMissing: 0,
1655
+ missingFromGlossary: 0,
1656
+ incompleteEntities: 2,
1657
+ allPassing: false,
1658
+ })).toBe(false);
1659
+ });
1660
+ it('should return false when there are also failing tests', () => {
1661
+ expect(isOnlyIncompleteEntities({
1662
+ componentsMissing: 0,
1663
+ componentsWithErrors: 0,
1664
+ functionsFailing: 1,
1665
+ functionsNameMismatch: 0,
1666
+ functionsMissing: 0,
1667
+ missingFromGlossary: 0,
1668
+ incompleteEntities: 2,
1669
+ allPassing: false,
1670
+ })).toBe(false);
1671
+ });
1672
+ it('should return false when there are also missing glossary entries', () => {
1673
+ expect(isOnlyIncompleteEntities({
1674
+ componentsMissing: 0,
1675
+ componentsWithErrors: 0,
1676
+ functionsFailing: 0,
1677
+ functionsNameMismatch: 0,
1678
+ functionsMissing: 0,
1679
+ missingFromGlossary: 1,
1680
+ incompleteEntities: 2,
1681
+ allPassing: false,
1682
+ })).toBe(false);
1683
+ });
1684
+ it('should return true even when incompleteEntities is 0 (no failures at all)', () => {
1685
+ // Edge case: all zeros means nothing is failing
1686
+ expect(isOnlyIncompleteEntities({
1687
+ componentsMissing: 0,
1688
+ componentsWithErrors: 0,
1689
+ functionsFailing: 0,
1690
+ functionsNameMismatch: 0,
1691
+ functionsMissing: 0,
1692
+ missingFromGlossary: 0,
1693
+ incompleteEntities: 0,
1694
+ allPassing: true,
1695
+ })).toBe(true);
1696
+ });
1697
+ it('should return false when there are also miscategorized scenarios', () => {
1698
+ expect(isOnlyIncompleteEntities({
1699
+ componentsMissing: 0,
1700
+ componentsWithErrors: 0,
1701
+ functionsFailing: 0,
1702
+ functionsNameMismatch: 0,
1703
+ functionsMissing: 0,
1704
+ missingFromGlossary: 0,
1705
+ miscategorizedScenarios: 1,
1706
+ incompleteEntities: 2,
1707
+ allPassing: false,
1708
+ })).toBe(false);
1709
+ });
1710
+ it('should handle missing fields gracefully', () => {
1711
+ // Summary from older API version might not have all fields
1712
+ expect(isOnlyIncompleteEntities({
1713
+ incompleteEntities: 2,
1714
+ allPassing: false,
1715
+ })).toBe(true);
1716
+ });
1717
+ });
1718
+ // ── isAutoRemediable ─────────────────────────────────────────────────
1719
+ describe('isAutoRemediable', () => {
1720
+ it('should return true on first attempt when only incomplete entities', () => {
1721
+ const result = isAutoRemediable({
1722
+ componentsMissing: 0,
1723
+ componentsWithErrors: 0,
1724
+ functionsFailing: 0,
1725
+ functionsNameMismatch: 0,
1726
+ functionsMissing: 0,
1727
+ missingFromGlossary: 0,
1728
+ miscategorizedScenarios: 0,
1729
+ incompleteEntities: 3,
1730
+ allPassing: false,
1731
+ }, false);
1732
+ expect(result).toBe(true);
1733
+ });
1734
+ it('should return false on second attempt (already tried once)', () => {
1735
+ // This is the key fix: if we already tried analyze-imports and
1736
+ // entities are STILL incomplete, don't try again — report the failure
1737
+ const result = isAutoRemediable({
1738
+ componentsMissing: 0,
1739
+ componentsWithErrors: 0,
1740
+ functionsFailing: 0,
1741
+ functionsNameMismatch: 0,
1742
+ functionsMissing: 0,
1743
+ missingFromGlossary: 0,
1744
+ miscategorizedScenarios: 0,
1745
+ incompleteEntities: 3,
1746
+ allPassing: false,
1747
+ }, true);
1748
+ expect(result).toBe(false);
1749
+ });
1750
+ it('should return false when there are other failures besides incomplete entities', () => {
1751
+ const result = isAutoRemediable({
1752
+ componentsMissing: 1,
1753
+ incompleteEntities: 3,
1754
+ allPassing: false,
1755
+ }, false);
1756
+ expect(result).toBe(false);
1757
+ });
1758
+ it('should return false when there are no incomplete entities', () => {
1759
+ const result = isAutoRemediable({
1760
+ componentsMissing: 1,
1761
+ allPassing: false,
1762
+ }, false);
1763
+ expect(result).toBe(false);
1764
+ });
1765
+ });
1766
+ // ── queryIncompleteEntities ─────────────────────────────────────────
1767
+ describe('queryIncompleteEntities', () => {
1768
+ let db;
1769
+ let rawDb;
1770
+ const projectId = 'test-project-id';
1771
+ beforeEach(async () => {
1772
+ rawDb = new Database(':memory:');
1773
+ db = new Kysely({ dialect: new SqliteDialect({ database: rawDb }) });
1774
+ await db.schema
1775
+ .createTable('editor_scenarios')
1776
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1777
+ .addColumn('project_id', 'varchar', (col) => col.notNull())
1778
+ .addColumn('name', 'varchar', (col) => col.notNull())
1779
+ .addColumn('component_name', 'varchar')
1780
+ .addColumn('component_path', 'varchar')
1781
+ .addColumn('entity_sha', 'varchar')
1782
+ .addColumn('display_name', 'varchar')
1783
+ .addColumn('page_file_path', 'varchar')
1784
+ .addColumn('url', 'varchar')
1785
+ .addColumn('created_at', 'datetime')
1786
+ .addColumn('updated_at', 'datetime')
1787
+ .execute();
1788
+ await db.schema
1789
+ .createTable('analyses')
1790
+ .addColumn('id', 'varchar', (col) => col.primaryKey())
1791
+ .addColumn('entity_sha', 'varchar')
1792
+ .addColumn('entity_name', 'varchar')
1793
+ .addColumn('project_id', 'varchar')
1794
+ .execute();
1795
+ await db.schema
1796
+ .createTable('entities')
1797
+ .addColumn('sha', 'varchar', (col) => col.primaryKey())
1798
+ .addColumn('name', 'varchar')
1799
+ .addColumn('entity_type', 'varchar')
1800
+ .addColumn('file_path', 'varchar')
1801
+ .execute();
1802
+ });
1803
+ afterEach(async () => {
1804
+ await db.destroy();
1805
+ });
1806
+ it('should return empty when all scenario entity SHAs have analyses', async () => {
1807
+ // Entity with analysis
1808
+ await db
1809
+ .insertInto('entities')
1810
+ .values({
1811
+ sha: 'sha-header',
1812
+ name: 'Header',
1813
+ entity_type: 'visual',
1814
+ file_path: 'src/Header.tsx',
1815
+ })
1816
+ .execute();
1817
+ await db
1818
+ .insertInto('analyses')
1819
+ .values({
1820
+ id: 'a-1',
1821
+ entity_sha: 'sha-header',
1822
+ entity_name: 'Header',
1823
+ project_id: projectId,
1824
+ })
1825
+ .execute();
1826
+ await db
1827
+ .insertInto('editor_scenarios')
1828
+ .values({
1829
+ id: 'sc-1',
1830
+ project_id: projectId,
1831
+ name: 'Header - Default',
1832
+ component_name: 'Header',
1833
+ entity_sha: 'sha-header',
1834
+ created_at: '2026-03-16 23:00:00',
1835
+ })
1836
+ .execute();
1837
+ const result = await queryIncompleteEntities(db, projectId, null);
1838
+ expect(result).toEqual([]);
1839
+ });
1840
+ it('should return entities with scenarios but no analyses', async () => {
1841
+ // Entity WITHOUT analysis
1842
+ await db
1843
+ .insertInto('entities')
1844
+ .values({
1845
+ sha: 'sha-chips',
1846
+ name: 'CollectionChips',
1847
+ entity_type: 'visual',
1848
+ file_path: 'src/components/CollectionChips.tsx',
1849
+ })
1850
+ .execute();
1851
+ // Scenario referencing that entity
1852
+ await db
1853
+ .insertInto('editor_scenarios')
1854
+ .values({
1855
+ id: 'sc-1',
1856
+ project_id: projectId,
1857
+ name: 'CollectionChips - Default',
1858
+ component_name: 'CollectionChips',
1859
+ entity_sha: 'sha-chips',
1860
+ created_at: '2026-03-16 23:00:00',
1861
+ })
1862
+ .execute();
1863
+ await db
1864
+ .insertInto('editor_scenarios')
1865
+ .values({
1866
+ id: 'sc-2',
1867
+ project_id: projectId,
1868
+ name: 'CollectionChips - Many',
1869
+ component_name: 'CollectionChips',
1870
+ entity_sha: 'sha-chips',
1871
+ created_at: '2026-03-16 23:01:00',
1872
+ })
1873
+ .execute();
1874
+ const result = await queryIncompleteEntities(db, projectId, null);
1875
+ expect(result).toEqual([
1876
+ {
1877
+ entitySha: 'sha-chips',
1878
+ name: 'CollectionChips',
1879
+ scenarioCount: 2,
1880
+ preExisting: false,
1881
+ },
1882
+ ]);
1883
+ });
1884
+ it('should only return entities without analyses, not those with analyses', async () => {
1885
+ // Entity WITH analysis (Header)
1886
+ await db
1887
+ .insertInto('entities')
1888
+ .values({
1889
+ sha: 'sha-header',
1890
+ name: 'Header',
1891
+ entity_type: 'visual',
1892
+ file_path: 'src/Header.tsx',
1893
+ })
1894
+ .execute();
1895
+ await db
1896
+ .insertInto('analyses')
1897
+ .values({
1898
+ id: 'a-1',
1899
+ entity_sha: 'sha-header',
1900
+ entity_name: 'Header',
1901
+ project_id: projectId,
1902
+ })
1903
+ .execute();
1904
+ await db
1905
+ .insertInto('editor_scenarios')
1906
+ .values({
1907
+ id: 'sc-1',
1908
+ project_id: projectId,
1909
+ name: 'Header - Default',
1910
+ component_name: 'Header',
1911
+ entity_sha: 'sha-header',
1912
+ created_at: '2026-03-16 23:00:00',
1913
+ })
1914
+ .execute();
1915
+ // Entity WITHOUT analysis (CollectionPicker)
1916
+ await db
1917
+ .insertInto('entities')
1918
+ .values({
1919
+ sha: 'sha-picker',
1920
+ name: 'CollectionPicker',
1921
+ entity_type: 'visual',
1922
+ file_path: 'src/components/CollectionPicker.tsx',
1923
+ })
1924
+ .execute();
1925
+ await db
1926
+ .insertInto('editor_scenarios')
1927
+ .values({
1928
+ id: 'sc-2',
1929
+ project_id: projectId,
1930
+ name: 'CollectionPicker - Default',
1931
+ component_name: 'CollectionPicker',
1932
+ entity_sha: 'sha-picker',
1933
+ created_at: '2026-03-16 23:00:00',
1934
+ })
1935
+ .execute();
1936
+ const result = await queryIncompleteEntities(db, projectId, null);
1937
+ expect(result).toEqual([
1938
+ {
1939
+ entitySha: 'sha-picker',
1940
+ name: 'CollectionPicker',
1941
+ scenarioCount: 1,
1942
+ preExisting: false,
1943
+ },
1944
+ ]);
1945
+ });
1946
+ it('should return both pre-session and in-session entities with preExisting flags', async () => {
1947
+ // Entity without analysis, scenario created BEFORE session
1948
+ await db
1949
+ .insertInto('entities')
1950
+ .values({
1951
+ sha: 'sha-old',
1952
+ name: 'OldComponent',
1953
+ entity_type: 'visual',
1954
+ file_path: 'src/OldComponent.tsx',
1955
+ })
1956
+ .execute();
1957
+ await db
1958
+ .insertInto('editor_scenarios')
1959
+ .values({
1960
+ id: 'sc-old',
1961
+ project_id: projectId,
1962
+ name: 'OldComponent - Default',
1963
+ component_name: 'OldComponent',
1964
+ entity_sha: 'sha-old',
1965
+ created_at: '2026-03-16 20:00:00',
1966
+ })
1967
+ .execute();
1968
+ // Entity without analysis, scenario created DURING session
1969
+ await db
1970
+ .insertInto('entities')
1971
+ .values({
1972
+ sha: 'sha-new',
1973
+ name: 'NewComponent',
1974
+ entity_type: 'visual',
1975
+ file_path: 'src/NewComponent.tsx',
1976
+ })
1977
+ .execute();
1978
+ await db
1979
+ .insertInto('editor_scenarios')
1980
+ .values({
1981
+ id: 'sc-new',
1982
+ project_id: projectId,
1983
+ name: 'NewComponent - Default',
1984
+ component_name: 'NewComponent',
1985
+ entity_sha: 'sha-new',
1986
+ created_at: '2026-03-16 23:10:00',
1987
+ })
1988
+ .execute();
1989
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
1990
+ // Both should be returned — OldComponent is preExisting, NewComponent is not
1991
+ expect(result).toEqual(expect.arrayContaining([
1992
+ {
1993
+ entitySha: 'sha-old',
1994
+ name: 'OldComponent',
1995
+ scenarioCount: 1,
1996
+ preExisting: true,
1997
+ },
1998
+ {
1999
+ entitySha: 'sha-new',
2000
+ name: 'NewComponent',
2001
+ scenarioCount: 1,
2002
+ preExisting: false,
2003
+ },
2004
+ ]));
2005
+ expect(result).toHaveLength(2);
2006
+ });
2007
+ it('should flag preExisting: false when scenario was updated in session even if created before', async () => {
2008
+ await db
2009
+ .insertInto('entities')
2010
+ .values({
2011
+ sha: 'sha-updated',
2012
+ name: 'UpdatedComponent',
2013
+ entity_type: 'visual',
2014
+ file_path: 'src/Updated.tsx',
2015
+ })
2016
+ .execute();
2017
+ await db
2018
+ .insertInto('editor_scenarios')
2019
+ .values({
2020
+ id: 'sc-updated',
2021
+ project_id: projectId,
2022
+ name: 'UpdatedComponent - Default',
2023
+ component_name: 'UpdatedComponent',
2024
+ entity_sha: 'sha-updated',
2025
+ created_at: '2026-03-16 20:00:00',
2026
+ updated_at: '2026-03-16 23:20:00', // Updated in session
2027
+ })
2028
+ .execute();
2029
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2030
+ expect(result).toEqual([
2031
+ {
2032
+ entitySha: 'sha-updated',
2033
+ name: 'UpdatedComponent',
2034
+ scenarioCount: 1,
2035
+ preExisting: false,
2036
+ },
2037
+ ]);
2038
+ });
2039
+ it('should skip scenarios with null entity_sha', async () => {
2040
+ await db
2041
+ .insertInto('editor_scenarios')
2042
+ .values({
2043
+ id: 'sc-null',
2044
+ project_id: projectId,
2045
+ name: 'Orphan Scenario',
2046
+ component_name: 'Orphan',
2047
+ created_at: '2026-03-16 23:00:00',
2048
+ })
2049
+ .execute();
2050
+ const result = await queryIncompleteEntities(db, projectId, null);
2051
+ expect(result).toEqual([]);
2052
+ });
2053
+ it('should return empty when there are no scenarios', async () => {
2054
+ const result = await queryIncompleteEntities(db, projectId, null);
2055
+ expect(result).toEqual([]);
2056
+ });
2057
+ it('should not flag entities when a sibling version (same name+filePath) has analyses', async () => {
2058
+ // Old entity version WITH analysis
2059
+ await db
2060
+ .insertInto('entities')
2061
+ .values({
2062
+ sha: 'sha-btn-v1',
2063
+ name: 'OpenLibraryButton',
2064
+ entity_type: 'visual',
2065
+ file_path: 'src/components/OpenLibraryButton.tsx',
2066
+ })
2067
+ .execute();
2068
+ await db
2069
+ .insertInto('analyses')
2070
+ .values({
2071
+ id: 'a-btn-v1',
2072
+ entity_sha: 'sha-btn-v1',
2073
+ entity_name: 'OpenLibraryButton',
2074
+ project_id: projectId,
2075
+ })
2076
+ .execute();
2077
+ // New entity version WITHOUT analysis (created by file watcher)
2078
+ await db
2079
+ .insertInto('entities')
2080
+ .values({
2081
+ sha: 'sha-btn-v2',
2082
+ name: 'OpenLibraryButton',
2083
+ entity_type: 'visual',
2084
+ file_path: 'src/components/OpenLibraryButton.tsx',
2085
+ })
2086
+ .execute();
2087
+ // Scenario points to the NEW version (backfilled after file watcher)
2088
+ await db
2089
+ .insertInto('editor_scenarios')
2090
+ .values({
2091
+ id: 'sc-btn',
2092
+ project_id: projectId,
2093
+ name: 'OpenLibraryButton - Default',
2094
+ component_name: 'OpenLibraryButton',
2095
+ entity_sha: 'sha-btn-v2',
2096
+ created_at: '2026-03-16 23:00:00',
2097
+ })
2098
+ .execute();
2099
+ // Should NOT flag as incomplete — sibling version has analyses
2100
+ const result = await queryIncompleteEntities(db, projectId, null);
2101
+ expect(result).toEqual([]);
2102
+ });
2103
+ it('should flag entity when sibling has analyses but different filePath (extracted component)', async () => {
2104
+ // Old entity version WITH analysis at ORIGINAL file path
2105
+ await db
2106
+ .insertInto('entities')
2107
+ .values({
2108
+ sha: 'sha-card-v1',
2109
+ name: 'TaskCard',
2110
+ entity_type: 'visual',
2111
+ file_path: 'app/page.tsx',
2112
+ })
2113
+ .execute();
2114
+ await db
2115
+ .insertInto('analyses')
2116
+ .values({
2117
+ id: 'a-card-v1',
2118
+ entity_sha: 'sha-card-v1',
2119
+ entity_name: 'TaskCard',
2120
+ project_id: projectId,
2121
+ })
2122
+ .execute();
2123
+ // New entity version WITHOUT analysis at EXTRACTED file path
2124
+ await db
2125
+ .insertInto('entities')
2126
+ .values({
2127
+ sha: 'sha-card-v2',
2128
+ name: 'TaskCard',
2129
+ entity_type: 'visual',
2130
+ file_path: 'app/components/TaskCard.tsx',
2131
+ })
2132
+ .execute();
2133
+ // Scenario points to the new version (synced by syncScenarioEntityShas)
2134
+ await db
2135
+ .insertInto('editor_scenarios')
2136
+ .values({
2137
+ id: 'sc-card',
2138
+ project_id: projectId,
2139
+ name: 'TaskCard - Default',
2140
+ component_name: 'TaskCard',
2141
+ entity_sha: 'sha-card-v2',
2142
+ created_at: '2026-03-16 23:00:00',
2143
+ })
2144
+ .execute();
2145
+ // SHOULD flag as incomplete — sibling has analyses but at a different filePath,
2146
+ // so getAllEntities() won't inherit (it matches by name+filePath)
2147
+ const result = await queryIncompleteEntities(db, projectId, null);
2148
+ expect(result).toEqual([
2149
+ {
2150
+ entitySha: 'sha-card-v2',
2151
+ name: 'TaskCard',
2152
+ scenarioCount: 1,
2153
+ preExisting: false,
2154
+ },
2155
+ ]);
2156
+ });
2157
+ it('should still flag entities when no sibling version has analyses', async () => {
2158
+ // Only one version, no analyses
2159
+ await db
2160
+ .insertInto('entities')
2161
+ .values({
2162
+ sha: 'sha-icon',
2163
+ name: 'ExternalLinkIcon',
2164
+ entity_type: 'visual',
2165
+ file_path: 'src/components/ExternalLinkIcon.tsx',
2166
+ })
2167
+ .execute();
2168
+ await db
2169
+ .insertInto('editor_scenarios')
2170
+ .values({
2171
+ id: 'sc-icon',
2172
+ project_id: projectId,
2173
+ name: 'ExternalLinkIcon - Default',
2174
+ component_name: 'ExternalLinkIcon',
2175
+ entity_sha: 'sha-icon',
2176
+ created_at: '2026-03-16 23:00:00',
2177
+ })
2178
+ .execute();
2179
+ // Should flag as incomplete — no version has analyses
2180
+ const result = await queryIncompleteEntities(db, projectId, null);
2181
+ expect(result).toEqual([
2182
+ {
2183
+ entitySha: 'sha-icon',
2184
+ name: 'ExternalLinkIcon',
2185
+ scenarioCount: 1,
2186
+ preExisting: false,
2187
+ },
2188
+ ]);
2189
+ });
2190
+ it('should use entity name from entities table, falling back to component_name', async () => {
2191
+ // Scenario has entity_sha but entity record doesn't exist
2192
+ await db
2193
+ .insertInto('editor_scenarios')
2194
+ .values({
2195
+ id: 'sc-1',
2196
+ project_id: projectId,
2197
+ name: 'Ghost - Default',
2198
+ component_name: 'GhostComponent',
2199
+ entity_sha: 'sha-ghost',
2200
+ created_at: '2026-03-16 23:00:00',
2201
+ })
2202
+ .execute();
2203
+ const result = await queryIncompleteEntities(db, projectId, null);
2204
+ expect(result).toEqual([
2205
+ {
2206
+ entitySha: 'sha-ghost',
2207
+ name: 'GhostComponent',
2208
+ scenarioCount: 1,
2209
+ preExisting: false,
2210
+ },
2211
+ ]);
2212
+ });
2213
+ it('should detect incomplete entity whose scenario predates the session', async () => {
2214
+ // Entity with no analyses, scenario created BEFORE session
2215
+ await db
2216
+ .insertInto('entities')
2217
+ .values({
2218
+ sha: 'sha-preexisting',
2219
+ name: 'PreExistingComponent',
2220
+ entity_type: 'visual',
2221
+ file_path: 'src/PreExistingComponent.tsx',
2222
+ })
2223
+ .execute();
2224
+ await db
2225
+ .insertInto('editor_scenarios')
2226
+ .values({
2227
+ id: 'sc-preexisting',
2228
+ project_id: projectId,
2229
+ name: 'PreExistingComponent - Default',
2230
+ component_name: 'PreExistingComponent',
2231
+ entity_sha: 'sha-preexisting',
2232
+ created_at: '2026-03-16 20:00:00',
2233
+ updated_at: '2026-03-16 20:00:00',
2234
+ })
2235
+ .execute();
2236
+ // Session started well after scenario was created/updated
2237
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2238
+ // Should still be detected — the old time filter would have excluded it
2239
+ expect(result).toEqual([
2240
+ {
2241
+ entitySha: 'sha-preexisting',
2242
+ name: 'PreExistingComponent',
2243
+ scenarioCount: 1,
2244
+ preExisting: true,
2245
+ },
2246
+ ]);
2247
+ });
2248
+ it('should flag preExisting: true when all scenarios predate the session', async () => {
2249
+ await db
2250
+ .insertInto('entities')
2251
+ .values({
2252
+ sha: 'sha-old-entity',
2253
+ name: 'OldEntity',
2254
+ entity_type: 'visual',
2255
+ file_path: 'src/OldEntity.tsx',
2256
+ })
2257
+ .execute();
2258
+ // Two scenarios, both before session
2259
+ await db
2260
+ .insertInto('editor_scenarios')
2261
+ .values({
2262
+ id: 'sc-old-1',
2263
+ project_id: projectId,
2264
+ name: 'OldEntity - Default',
2265
+ component_name: 'OldEntity',
2266
+ entity_sha: 'sha-old-entity',
2267
+ created_at: '2026-03-16 19:00:00',
2268
+ updated_at: '2026-03-16 19:00:00',
2269
+ })
2270
+ .execute();
2271
+ await db
2272
+ .insertInto('editor_scenarios')
2273
+ .values({
2274
+ id: 'sc-old-2',
2275
+ project_id: projectId,
2276
+ name: 'OldEntity - Hover',
2277
+ component_name: 'OldEntity',
2278
+ entity_sha: 'sha-old-entity',
2279
+ created_at: '2026-03-16 19:30:00',
2280
+ updated_at: '2026-03-16 19:30:00',
2281
+ })
2282
+ .execute();
2283
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2284
+ expect(result).toEqual([
2285
+ {
2286
+ entitySha: 'sha-old-entity',
2287
+ name: 'OldEntity',
2288
+ scenarioCount: 2,
2289
+ preExisting: true,
2290
+ },
2291
+ ]);
2292
+ });
2293
+ it('should flag preExisting: false when scenario is from the current session', async () => {
2294
+ await db
2295
+ .insertInto('entities')
2296
+ .values({
2297
+ sha: 'sha-session-entity',
2298
+ name: 'SessionEntity',
2299
+ entity_type: 'visual',
2300
+ file_path: 'src/SessionEntity.tsx',
2301
+ })
2302
+ .execute();
2303
+ await db
2304
+ .insertInto('editor_scenarios')
2305
+ .values({
2306
+ id: 'sc-session',
2307
+ project_id: projectId,
2308
+ name: 'SessionEntity - Default',
2309
+ component_name: 'SessionEntity',
2310
+ entity_sha: 'sha-session-entity',
2311
+ created_at: '2026-03-16 23:30:00',
2312
+ updated_at: '2026-03-16 23:30:00',
2313
+ })
2314
+ .execute();
2315
+ const result = await queryIncompleteEntities(db, projectId, '2026-03-16T23:07:12.698Z');
2316
+ expect(result).toEqual([
2317
+ {
2318
+ entitySha: 'sha-session-entity',
2319
+ name: 'SessionEntity',
2320
+ scenarioCount: 1,
2321
+ preExisting: false,
2322
+ },
2323
+ ]);
2324
+ });
2325
+ });
2326
+ // ── identifyScenariosNeedingRecapture ──────────────────────────────
2327
+ describe('identifyScenariosNeedingRecapture', () => {
2328
+ // Reproduces the Margo bug: Feature 1 built app-level popup scenarios,
2329
+ // Feature 2 edited LibraryView (used by App), but app-level scenarios
2330
+ // were never flagged for recapture because the audit only checked
2331
+ // component scenario existence — not whether app-level scenarios are stale.
2332
+ //
2333
+ // Each scenario's entityName is resolved by the caller via
2334
+ // entity_sha → entities.name (the default export for app-level scenarios).
2335
+ it('should flag app-level scenario when its entity is impacted by transitive dependency change', () => {
2336
+ // LibraryView was edited → App is impacted (imports LibraryView)
2337
+ // App-level scenario "Library - Rich Library" has entity_sha pointing to App
2338
+ // It was NOT recaptured during Feature 2 → should be flagged
2339
+ const entityChangeStatus = {
2340
+ LibraryView: { status: 'edited' },
2341
+ App: {
2342
+ status: 'impacted',
2343
+ impactedBy: [
2344
+ {
2345
+ name: 'LibraryView',
2346
+ filePath: 'src/components/LibraryView.tsx',
2347
+ changeType: 'edited',
2348
+ },
2349
+ ],
2350
+ },
2351
+ };
2352
+ const result = identifyScenariosNeedingRecapture({
2353
+ scenarios: [
2354
+ {
2355
+ name: 'Library - Rich Library',
2356
+ entityName: 'App', // resolved from entity_sha → entities.name
2357
+ updatedInSession: false,
2358
+ },
2359
+ ],
2360
+ entityChangeStatus,
2361
+ });
2362
+ expect(result).toHaveLength(1);
2363
+ expect(result[0].scenarioName).toBe('Library - Rich Library');
2364
+ expect(result[0].entityName).toBe('App');
2365
+ expect(result[0].status.status).toBe('impacted');
2366
+ });
2367
+ it('should flag component scenario when its entity is directly edited and not recaptured', () => {
2368
+ const entityChangeStatus = {
2369
+ LibraryView: { status: 'edited' },
2370
+ };
2371
+ const result = identifyScenariosNeedingRecapture({
2372
+ scenarios: [
2373
+ {
2374
+ name: 'LibraryView - Empty',
2375
+ entityName: 'LibraryView',
2376
+ updatedInSession: false,
2377
+ },
2378
+ ],
2379
+ entityChangeStatus,
2380
+ });
2381
+ expect(result).toHaveLength(1);
2382
+ expect(result[0].scenarioName).toBe('LibraryView - Empty');
2383
+ expect(result[0].entityName).toBe('LibraryView');
2384
+ expect(result[0].status.status).toBe('edited');
2385
+ });
2386
+ it('should NOT flag scenario that was already recaptured in the current session', () => {
2387
+ const entityChangeStatus = {
2388
+ App: {
2389
+ status: 'impacted',
2390
+ impactedBy: [
2391
+ {
2392
+ name: 'LibraryView',
2393
+ filePath: 'src/components/LibraryView.tsx',
2394
+ changeType: 'edited',
2395
+ },
2396
+ ],
2397
+ },
2398
+ };
2399
+ const result = identifyScenariosNeedingRecapture({
2400
+ scenarios: [
2401
+ {
2402
+ name: 'App - Default',
2403
+ entityName: 'App',
2404
+ updatedInSession: true, // re-registered during Feature 2
2405
+ },
2406
+ ],
2407
+ entityChangeStatus,
2408
+ });
2409
+ expect(result).toHaveLength(0);
2410
+ });
2411
+ it('should NOT flag scenario whose entity has no change status', () => {
2412
+ const entityChangeStatus = {
2413
+ LibraryView: { status: 'edited' },
2414
+ };
2415
+ const result = identifyScenariosNeedingRecapture({
2416
+ scenarios: [
2417
+ {
2418
+ name: 'WelcomeScreen - Default',
2419
+ entityName: 'WelcomeScreen',
2420
+ updatedInSession: false,
2421
+ },
2422
+ ],
2423
+ entityChangeStatus,
2424
+ });
2425
+ expect(result).toHaveLength(0);
2426
+ });
2427
+ it('should return empty array when entityChangeStatus is undefined', () => {
2428
+ const result = identifyScenariosNeedingRecapture({
2429
+ scenarios: [
2430
+ {
2431
+ name: 'Library - Rich Library',
2432
+ entityName: 'App',
2433
+ updatedInSession: false,
2434
+ },
2435
+ ],
2436
+ entityChangeStatus: undefined,
2437
+ });
2438
+ expect(result).toHaveLength(0);
2439
+ });
2440
+ it('should return empty array when entityChangeStatus is empty', () => {
2441
+ const result = identifyScenariosNeedingRecapture({
2442
+ scenarios: [
2443
+ {
2444
+ name: 'Library - Rich Library',
2445
+ entityName: 'App',
2446
+ updatedInSession: false,
2447
+ },
2448
+ ],
2449
+ entityChangeStatus: {},
2450
+ });
2451
+ expect(result).toHaveLength(0);
2452
+ });
2453
+ it('should flag multiple app-level scenarios sharing the same impacted entity', () => {
2454
+ const entityChangeStatus = {
2455
+ LibraryView: { status: 'edited' },
2456
+ App: {
2457
+ status: 'impacted',
2458
+ impactedBy: [
2459
+ {
2460
+ name: 'LibraryView',
2461
+ filePath: 'src/components/LibraryView.tsx',
2462
+ changeType: 'edited',
2463
+ },
2464
+ ],
2465
+ },
2466
+ };
2467
+ const result = identifyScenariosNeedingRecapture({
2468
+ scenarios: [
2469
+ {
2470
+ name: 'Library - Empty',
2471
+ entityName: 'App',
2472
+ updatedInSession: false,
2473
+ },
2474
+ {
2475
+ name: 'Library - Rich Library',
2476
+ entityName: 'App',
2477
+ updatedInSession: false,
2478
+ },
2479
+ {
2480
+ name: 'First Article Saved',
2481
+ entityName: 'App',
2482
+ updatedInSession: false,
2483
+ },
2484
+ ],
2485
+ entityChangeStatus,
2486
+ });
2487
+ expect(result).toHaveLength(3);
2488
+ expect(result.map((r) => r.scenarioName).sort()).toEqual([
2489
+ 'First Article Saved',
2490
+ 'Library - Empty',
2491
+ 'Library - Rich Library',
2492
+ ]);
2493
+ expect(result.every((r) => r.entityName === 'App')).toBe(true);
2494
+ });
2495
+ it('should skip scenarios with null entityName (no entity_sha set)', () => {
2496
+ const entityChangeStatus = {
2497
+ App: { status: 'edited' },
2498
+ };
2499
+ const result = identifyScenariosNeedingRecapture({
2500
+ scenarios: [
2501
+ {
2502
+ name: 'Mystery Scenario',
2503
+ entityName: null, // no entity_sha → no entity name
2504
+ updatedInSession: false,
2505
+ },
2506
+ ],
2507
+ entityChangeStatus,
2508
+ });
2509
+ expect(result).toHaveLength(0);
2510
+ });
2511
+ });
2512
+ // ── detectDuplicateNames ──────────────────────────────────────────
2513
+ describe('detectDuplicateNames', () => {
2514
+ it('should return empty map when no duplicates exist', () => {
2515
+ const entries = [
2516
+ { name: 'Header', filePath: 'app/components/Header.tsx' },
2517
+ { name: 'Footer', filePath: 'app/components/Footer.tsx' },
2518
+ { name: 'Sidebar', filePath: 'app/components/Sidebar.tsx' },
2519
+ ];
2520
+ const result = detectDuplicateNames(entries);
2521
+ expect(result.size).toBe(0);
2522
+ });
2523
+ it('should group entries that share a name', () => {
2524
+ const entries = [
2525
+ { name: 'Page', filePath: 'app/isolated-components/Foo/page.tsx' },
2526
+ { name: 'Page', filePath: 'app/isolated-components/Bar/page.tsx' },
2527
+ { name: 'Page', filePath: 'app/isolated-components/Baz/page.tsx' },
2528
+ { name: 'Header', filePath: 'app/components/Header.tsx' },
2529
+ ];
2530
+ const result = detectDuplicateNames(entries);
2531
+ expect(result.size).toBe(1);
2532
+ expect(result.has('Page')).toBe(true);
2533
+ const pageGroup = result.get('Page');
2534
+ expect(pageGroup).toHaveLength(3);
2535
+ expect(pageGroup.map((e) => e.filePath)).toEqual([
2536
+ 'app/isolated-components/Foo/page.tsx',
2537
+ 'app/isolated-components/Bar/page.tsx',
2538
+ 'app/isolated-components/Baz/page.tsx',
2539
+ ]);
2540
+ });
2541
+ it('should exclude single-occurrence names', () => {
2542
+ const entries = [
2543
+ { name: 'Page', filePath: 'app/isolated-components/Foo/page.tsx' },
2544
+ { name: 'Page', filePath: 'app/isolated-components/Bar/page.tsx' },
2545
+ { name: 'Header', filePath: 'app/components/Header.tsx' },
2546
+ { name: 'Footer', filePath: 'app/components/Footer.tsx' },
2547
+ ];
2548
+ const result = detectDuplicateNames(entries);
2549
+ expect(result.size).toBe(1);
2550
+ expect(result.has('Header')).toBe(false);
2551
+ expect(result.has('Footer')).toBe(false);
2552
+ });
2553
+ it('should handle multiple duplicate groups', () => {
2554
+ const entries = [
2555
+ { name: 'Page', filePath: 'app/isolated-components/A/page.tsx' },
2556
+ { name: 'Page', filePath: 'app/isolated-components/B/page.tsx' },
2557
+ { name: 'Layout', filePath: 'app/isolated-components/A/layout.tsx' },
2558
+ { name: 'Layout', filePath: 'app/isolated-components/B/layout.tsx' },
2559
+ { name: 'Unique', filePath: 'app/components/Unique.tsx' },
2560
+ ];
2561
+ const result = detectDuplicateNames(entries);
2562
+ expect(result.size).toBe(2);
2563
+ expect(result.has('Page')).toBe(true);
2564
+ expect(result.has('Layout')).toBe(true);
2565
+ expect(result.get('Page')).toHaveLength(2);
2566
+ expect(result.get('Layout')).toHaveLength(2);
2567
+ });
2568
+ it('should return empty map for empty input', () => {
2569
+ const result = detectDuplicateNames([]);
2570
+ expect(result.size).toBe(0);
2571
+ });
2572
+ });
2573
+ // ── computeAudit: impacted components with stale scenarios ──────────
2574
+ describe('computeAudit — impacted components with stale scenarios', () => {
2575
+ it('should mark impacted component as needs_recapture when it has total scenarios but none in session', () => {
2576
+ // Library page has 3 scenarios from Feature 1 (totalScenarioCounts),
2577
+ // 0 in the current session (scenarioCounts), and is "impacted" in entityChangeStatus.
2578
+ // It should NOT be marked "missing" — it needs recapture, not new scenarios.
2579
+ const result = computeAudit({
2580
+ components: [
2581
+ {
2582
+ name: 'Library',
2583
+ filePath: 'app/library/page.tsx',
2584
+ returnType: 'JSX.Element',
2585
+ },
2586
+ {
2587
+ name: 'ArticleTable',
2588
+ filePath: 'app/components/ArticleTable.tsx',
2589
+ returnType: 'JSX.Element',
2590
+ },
2591
+ ],
2592
+ functions: [],
2593
+ scenarioCounts: { ArticleTable: 2 },
2594
+ testFileExistence: {},
2595
+ totalScenarioCounts: { Library: 3 },
2596
+ entityChangeStatus: {
2597
+ Library: { status: 'impacted' },
2598
+ ArticleTable: { status: 'edited' },
2599
+ },
2600
+ });
2601
+ // Library: impacted + has total scenarios but 0 in session → needs_recapture
2602
+ expect(result.components[0].status).toBe('needs_recapture');
2603
+ expect(result.components[0].scenarioCount).toBe(3);
2604
+ // ArticleTable: edited + has session scenarios → ok
2605
+ expect(result.components[1].status).toBe('ok');
2606
+ // needs_recapture should NOT count as missing
2607
+ expect(result.summary.componentsMissing).toBe(0);
2608
+ expect(result.summary.componentsNeedingRecapture).toBe(1);
2609
+ // should NOT fail the audit (scenariosNeedingRecapture handles it)
2610
+ expect(result.summary.allPassing).toBe(true);
2611
+ });
2612
+ it('should still mark component as missing when impacted but has zero total scenarios', () => {
2613
+ // New page added to glossary but never had scenarios — truly missing
2614
+ const result = computeAudit({
2615
+ components: [
2616
+ {
2617
+ name: 'NewPage',
2618
+ filePath: 'app/new/page.tsx',
2619
+ returnType: 'JSX.Element',
2620
+ },
2621
+ ],
2622
+ functions: [],
2623
+ scenarioCounts: {},
2624
+ testFileExistence: {},
2625
+ totalScenarioCounts: {},
2626
+ entityChangeStatus: {
2627
+ NewPage: { status: 'impacted' },
2628
+ },
2629
+ });
2630
+ expect(result.components[0].status).toBe('missing');
2631
+ expect(result.summary.componentsMissing).toBe(1);
2632
+ });
2633
+ it('should use needs_recapture for edited entities with existing scenarios from prior sessions', () => {
2634
+ // Edited entities that already have scenarios from prior sessions
2635
+ // need recapture, not re-registration. The code changed, but the
2636
+ // scenarios exist — they just need fresh screenshots.
2637
+ const result = computeAudit({
2638
+ components: [
2639
+ {
2640
+ name: 'EditedComp',
2641
+ filePath: 'app/components/Edited.tsx',
2642
+ returnType: 'JSX.Element',
2643
+ },
2644
+ ],
2645
+ functions: [],
2646
+ scenarioCounts: {},
2647
+ testFileExistence: {},
2648
+ totalScenarioCounts: { EditedComp: 2 },
2649
+ entityChangeStatus: {
2650
+ EditedComp: { status: 'edited' },
2651
+ },
2652
+ });
2653
+ expect(result.components[0].status).toBe('needs_recapture');
2654
+ expect(result.summary.componentsMissing).toBe(0);
2655
+ expect(result.summary.componentsNeedingRecapture).toBe(1);
2656
+ });
2657
+ it('should still mark as missing when new entity has zero total scenarios', () => {
2658
+ // Truly new component with no scenarios ever — needs scenarios created
2659
+ const result = computeAudit({
2660
+ components: [
2661
+ {
2662
+ name: 'BrandNew',
2663
+ filePath: 'app/components/BrandNew.tsx',
2664
+ returnType: 'JSX.Element',
2665
+ },
2666
+ ],
2667
+ functions: [],
2668
+ scenarioCounts: {},
2669
+ testFileExistence: {},
2670
+ totalScenarioCounts: {},
2671
+ entityChangeStatus: {
2672
+ BrandNew: { status: 'new' },
2673
+ },
2674
+ });
2675
+ expect(result.components[0].status).toBe('missing');
2676
+ expect(result.summary.componentsMissing).toBe(1);
2677
+ });
2678
+ });
634
2679
  });
635
2680
  //# sourceMappingURL=editorAudit.test.js.map