@wenathlan/devthink 2.0.13 → 2.0.15

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 (444) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/accounts.ts +2087 -0
  3. package/agent.ts +2331 -0
  4. package/antigravity.ts +2139 -0
  5. package/apifreeze.ts +4146 -0
  6. package/auth.ts +642 -0
  7. package/background.ts +16837 -0
  8. package/bridge.ts +2080 -0
  9. package/build.ts +54 -0
  10. package/bun.ts +26 -0
  11. package/capture.ts +1614 -0
  12. package/checksecrets.ts +72 -0
  13. package/cjs.ts +9 -0
  14. package/cli.ts +3500 -0
  15. package/commands.ts +1101 -0
  16. package/companion.ts +450 -0
  17. package/compatibility.ts +37 -0
  18. package/config.ts +3137 -0
  19. package/constants.ts +943 -0
  20. package/core.ts +1473 -0
  21. package/crossbrowser.ts +1359 -0
  22. package/dashdone.ts +605 -0
  23. package/data.ts +943 -0
  24. package/database.ts +133 -0
  25. package/debug.ts +850 -0
  26. package/deno.ts +27 -0
  27. package/devthink.ts +707 -0
  28. package/dist/accounts.d.ts +409 -0
  29. package/dist/agent.d.ts +837 -0
  30. package/dist/antigravity.d.ts +380 -0
  31. package/dist/apifreeze.d.ts +113 -0
  32. package/dist/auth.d.ts +224 -0
  33. package/{bridge.d.ts → dist/bridge.d.ts} +1 -1
  34. package/dist/capture.d.ts +595 -0
  35. package/dist/cjs.d.ts +6 -0
  36. package/{cli.js → dist/cli.js} +2 -2
  37. package/dist/commands.d.ts +310 -0
  38. package/dist/compatibility.d.ts +17 -0
  39. package/dist/config.d.ts +1853 -0
  40. package/dist/constants.d.ts +637 -0
  41. package/dist/core.d.ts +361 -0
  42. package/dist/data.d.ts +330 -0
  43. package/dist/database.d.ts +24 -0
  44. package/dist/debug.d.ts +270 -0
  45. package/dist/engine.d.ts +74 -0
  46. package/dist/environments.d.ts +244 -0
  47. package/dist/evidence.d.ts +277 -0
  48. package/dist/export.d.ts +311 -0
  49. package/dist/fingerprint.d.ts +594 -0
  50. package/dist/flow.d.ts +300 -0
  51. package/dist/gates.d.ts +103 -0
  52. package/dist/identity.d.ts +51 -0
  53. package/dist/ids.d.ts +7 -0
  54. package/dist/llm.d.ts +652 -0
  55. package/dist/models.d.ts +1807 -0
  56. package/dist/net.d.ts +325 -0
  57. package/dist/neutral.d.ts +41 -0
  58. package/dist/oauth.d.ts +703 -0
  59. package/dist/page.d.ts +1166 -0
  60. package/dist/perf.d.ts +481 -0
  61. package/dist/plan.d.ts +134 -0
  62. package/dist/project.d.ts +395 -0
  63. package/dist/providers.d.ts +37 -0
  64. package/dist/quota.d.ts +453 -0
  65. package/dist/recovery.d.ts +621 -0
  66. package/dist/request.d.ts +1492 -0
  67. package/dist/run.d.ts +779 -0
  68. package/dist/runtime.d.ts +212 -0
  69. package/dist/search.d.ts +375 -0
  70. package/dist/security.d.ts +534 -0
  71. package/dist/serve.d.ts +136 -0
  72. package/dist/session.d.ts +296 -0
  73. package/dist/storage.d.ts +53 -0
  74. package/dist/streaming.d.ts +1119 -0
  75. package/dist/swarm.d.ts +328 -0
  76. package/dist/tools.d.ts +170 -0
  77. package/dist/types.d.ts +8357 -0
  78. package/dist/utils.d.ts +82 -0
  79. package/dist/version.d.ts +7 -0
  80. package/dist/versionregistry.d.ts +406 -0
  81. package/dist/views.d.ts +579 -0
  82. package/dist/workbenchsession.d.ts +69 -0
  83. package/dist/workflow.d.ts +649 -0
  84. package/docs/readme.md +92 -0
  85. package/docs/schemas/antigravity.json +192 -0
  86. package/engine.ts +1524 -0
  87. package/environments.ts +1005 -0
  88. package/evidence.ts +643 -0
  89. package/export.ts +889 -0
  90. package/fingerprint.ts +1458 -0
  91. package/flow.ts +1190 -0
  92. package/gates.ts +307 -0
  93. package/gateway.ts +34 -0
  94. package/hardening.ts +191 -0
  95. package/headless.ts +369 -0
  96. package/http.ts +2110 -0
  97. package/identity.ts +246 -0
  98. package/ids.ts +26 -0
  99. package/index.ts +369 -0
  100. package/llm.ts +2682 -0
  101. package/mcp.ts +1835 -0
  102. package/{memory.js → memory.ts} +3834 -2310
  103. package/models.ts +3805 -0
  104. package/modes.ts +43 -0
  105. package/net.ts +1214 -0
  106. package/neutral.ts +362 -0
  107. package/node.ts +26 -0
  108. package/oauth.ts +2216 -0
  109. package/offscreen.ts +170 -0
  110. package/pack.ts +956 -0
  111. package/package.json +175 -82
  112. package/page.ts +7824 -0
  113. package/pagebridge.ts +1116 -0
  114. package/perf.ts +957 -0
  115. package/plan.ts +672 -0
  116. package/plugin.ts +76 -0
  117. package/{policy.js → policy.ts} +5073 -4679
  118. package/prisma.config.ts +27 -0
  119. package/progress.ts +1308 -0
  120. package/project.ts +1291 -0
  121. package/protocol.ts +4187 -0
  122. package/providers.ts +246 -0
  123. package/quota.ts +1887 -0
  124. package/recovery.ts +2433 -0
  125. package/request.ts +4482 -0
  126. package/run.ts +2135 -0
  127. package/runtime.ts +526 -0
  128. package/search.ts +1760 -0
  129. package/security.ts +1673 -0
  130. package/serve.ts +419 -0
  131. package/server.ts +5538 -0
  132. package/session.ts +1162 -0
  133. package/storage.ts +182 -0
  134. package/streaming.ts +4101 -0
  135. package/swarm.ts +884 -0
  136. package/sync.ts +56 -0
  137. package/tests/agentcert.test.ts +128 -0
  138. package/tests/agentfleet.test.ts +214 -0
  139. package/tests/agentreview.test.ts +241 -0
  140. package/tests/agentstream.test.ts +335 -0
  141. package/tests/agentwork.test.ts +356 -0
  142. package/tests/apifreeze.test.ts +290 -0
  143. package/tests/apimap.test.ts +112 -0
  144. package/tests/approvalgate.test.ts +175 -0
  145. package/tests/artifactmanifest.test.ts +204 -0
  146. package/tests/attentionfeed.test.ts +163 -0
  147. package/tests/backgroundruns.test.ts +100 -0
  148. package/tests/batchscheduling.test.ts +131 -0
  149. package/tests/blackboard.test.ts +238 -0
  150. package/tests/bridge.test.ts +1088 -0
  151. package/tests/browsercoverage.test.ts +134 -0
  152. package/tests/browserpolyfills.test.ts +124 -0
  153. package/tests/build.mjs +1260 -0
  154. package/tests/clientauth.test.ts +223 -0
  155. package/tests/clitools.test.ts +578 -0
  156. package/tests/confirmgates.test.ts +190 -0
  157. package/tests/containerpack.test.ts +143 -0
  158. package/tests/controlflow.test.ts +2120 -0
  159. package/tests/coordination.test.ts +345 -0
  160. package/tests/copyscreen.test.ts +139 -0
  161. package/tests/core.test.ts +417 -0
  162. package/tests/costcert.test.ts +95 -0
  163. package/tests/crossbrowser.test.ts +115 -0
  164. package/tests/cspaudit.test.ts +79 -0
  165. package/tests/dashdone.test.ts +615 -0
  166. package/tests/datagrid.test.ts +137 -0
  167. package/tests/doccheck.test.ts +107 -0
  168. package/tests/dombatch.test.ts +109 -0
  169. package/tests/emulation.test.ts +282 -0
  170. package/tests/environments.test.ts +259 -0
  171. package/tests/evidenceviews.test.ts +88 -0
  172. package/tests/exporttools.test.ts +185 -0
  173. package/tests/firefoxprep.test.ts +134 -0
  174. package/tests/flowlibrary.test.ts +242 -0
  175. package/tests/flowrun.test.ts +303 -0
  176. package/tests/forensics.test.ts +439 -0
  177. package/tests/gateway.test.ts +939 -0
  178. package/tests/headlesslib.test.ts +171 -0
  179. package/tests/httpstream.test.ts +277 -0
  180. package/tests/immutablelog.test.ts +157 -0
  181. package/tests/inboundguard.test.ts +177 -0
  182. package/tests/lazyload.test.ts +72 -0
  183. package/tests/librarymodes.test.ts +623 -0
  184. package/tests/llm.test.ts +696 -0
  185. package/tests/manifest.test.ts +226 -0
  186. package/tests/maskinputs.test.ts +150 -0
  187. package/tests/matrixverify.test.ts +111 -0
  188. package/tests/mavenpack.test.ts +75 -0
  189. package/tests/mcpserver.test.ts +704 -0
  190. package/tests/memory.test.ts +4155 -0
  191. package/tests/memorycare.test.ts +230 -0
  192. package/tests/migrateplan.test.ts +349 -0
  193. package/tests/minimization.test.ts +414 -0
  194. package/tests/modelroute.test.ts +112 -0
  195. package/tests/multiagent.test.ts +440 -0
  196. package/tests/nativebridge.test.ts +807 -0
  197. package/tests/navigation.test.ts +284 -0
  198. package/tests/nugetpack.test.ts +83 -0
  199. package/tests/orchestration.test.ts +449 -0
  200. package/tests/originpolicy.test.ts +405 -0
  201. package/tests/outputcompare.test.ts +97 -0
  202. package/tests/package.test.ts +91 -0
  203. package/tests/pagebridge.test.ts +5909 -0
  204. package/tests/pentest.test.ts +75 -0
  205. package/tests/perfrecords.test.ts +257 -0
  206. package/tests/permdiff.test.ts +85 -0
  207. package/tests/phishguard.test.ts +128 -0
  208. package/tests/pickerviews.test.ts +155 -0
  209. package/tests/pipelines.test.ts +381 -0
  210. package/tests/planlint.test.ts +240 -0
  211. package/tests/planreview.test.ts +383 -0
  212. package/tests/platformtargets.test.ts +56 -0
  213. package/tests/policy.test.ts +8284 -0
  214. package/tests/portability.test.ts +96 -0
  215. package/tests/progress.test.ts +1036 -0
  216. package/tests/promptlibrary.test.ts +116 -0
  217. package/tests/protocol.test.ts +4793 -0
  218. package/tests/publishingpipeline.test.ts +314 -0
  219. package/tests/quickactions.test.ts +164 -0
  220. package/tests/readiness.test.ts +78 -0
  221. package/tests/recipes.test.ts +163 -0
  222. package/tests/redactshots.test.ts +216 -0
  223. package/tests/registernvidiakeys.ts +51 -0
  224. package/tests/relayserve.test.ts +304 -0
  225. package/tests/releasenotes.test.ts +276 -0
  226. package/tests/resilience.test.ts +467 -0
  227. package/tests/resourceaware.test.ts +187 -0
  228. package/tests/runbudget.test.ts +125 -0
  229. package/tests/runhistory.test.ts +299 -0
  230. package/tests/runreplay.test.ts +113 -0
  231. package/tests/runresume.test.ts +184 -0
  232. package/tests/runstate.test.ts +288 -0
  233. package/tests/runtimeadapters.test.ts +251 -0
  234. package/tests/safariskeleton.test.ts +115 -0
  235. package/tests/sandboxframe.test.ts +196 -0
  236. package/tests/sbom.test.ts +105 -0
  237. package/tests/secretvault.test.ts +188 -0
  238. package/tests/selcache.test.ts +111 -0
  239. package/tests/sessioninterface.test.ts +791 -0
  240. package/tests/sessions.test.ts +591 -0
  241. package/tests/siteprefs.test.ts +228 -0
  242. package/tests/snapshotdelta.test.ts +165 -0
  243. package/tests/statusviews.test.ts +237 -0
  244. package/tests/stepmeter.test.ts +200 -0
  245. package/tests/streamparse.test.ts +163 -0
  246. package/tests/stylepruning.test.ts +90 -0
  247. package/tests/surfaces.test.ts +282 -0
  248. package/tests/sweep.test.ts +78 -0
  249. package/tests/syncbridge.test.ts +164 -0
  250. package/tests/taskqueue.test.ts +206 -0
  251. package/tests/toolcalls.test.ts +336 -0
  252. package/tests/toolcatalog.test.ts +201 -0
  253. package/tests/torture-agent.test.ts +706 -0
  254. package/tests/torture-auth.test.ts +461 -0
  255. package/tests/torture-commands.test.ts +895 -0
  256. package/tests/torture-data.test.ts +923 -0
  257. package/tests/torture-environments.test.ts +285 -0
  258. package/tests/torture-export.test.ts +263 -0
  259. package/tests/torture-http.test.ts +1379 -0
  260. package/tests/torture-llm.test.ts +808 -0
  261. package/tests/torture-memory.test.ts +1084 -0
  262. package/tests/torture-plan.test.ts +829 -0
  263. package/tests/torture-run.test.ts +626 -0
  264. package/tests/torture-session.test.ts +928 -0
  265. package/tests/torture-swarm.test.ts +1245 -0
  266. package/tests/torture-tools.test.ts +964 -0
  267. package/tests/torture-workflow.test.ts +2354 -0
  268. package/tests/tourviews.test.ts +52 -0
  269. package/tests/transparency.test.ts +147 -0
  270. package/tests/trigger.test.ts +941 -0
  271. package/tests/v1sunset.test.ts +428 -0
  272. package/tests/virtlist.test.ts +94 -0
  273. package/tests/vision.test.ts +540 -0
  274. package/tests/vsixpack.test.ts +145 -0
  275. package/tests/webapi.test.ts +523 -0
  276. package/tests/workflow.test.ts +1785 -0
  277. package/tests/workfloweditor.test.ts +759 -0
  278. package/tests/xpipack.test.ts +128 -0
  279. package/tools.ts +734 -0
  280. package/types.ts +9908 -0
  281. package/umd.ts +9 -0
  282. package/utils.ts +249 -0
  283. package/version.ts +8 -0
  284. package/versionregistry.ts +1310 -0
  285. package/views.ts +2153 -0
  286. package/vitest.config.ts +12 -0
  287. package/web/App.tsx +78 -0
  288. package/web/README.md +47 -0
  289. package/web/capacitor.config.ts +46 -0
  290. package/web/const.ts +19 -0
  291. package/web/control.shell.tsx +66 -0
  292. package/web/dashboardpage.ts +554 -0
  293. package/web/db.ts +493 -0
  294. package/web/design.html +541 -0
  295. package/web/gatewayview/Gateway.tsx +345 -0
  296. package/web/gatewayview/config.ts +1042 -0
  297. package/web/gatewayview/definition.ts +174 -0
  298. package/web/icons.ts +15 -0
  299. package/{manifest.json → web/manifest.json} +1 -1
  300. package/web/optionspage.ts +691 -0
  301. package/web/popup.ts +1651 -0
  302. package/web/schema.prisma +176 -0
  303. package/web/sidepanel.ts +7941 -0
  304. package/web/sitemanifest.json +13 -0
  305. package/web/terminal-ui.tsx +622 -0
  306. package/web/transparencypage.ts +541 -0
  307. package/web/vite.config.ts +39 -0
  308. package/web/workspace.ts +23 -0
  309. package/workbenchmemory.ts +104 -0
  310. package/workbenchsession.ts +304 -0
  311. package/workflow.ts +4495 -0
  312. package/bridge.d.ts.map +0 -1
  313. package/bridge.js +0 -1877
  314. package/bun.d.ts.map +0 -1
  315. package/bun.js +0 -52329
  316. package/caps/background.json +0 -712
  317. package/caps/cli.json +0 -360
  318. package/caps/library.json +0 -3611
  319. package/caps/mcp.json +0 -126
  320. package/caps/pagebridge.json +0 -377
  321. package/caps/popup.json +0 -51
  322. package/caps/sidepanel.json +0 -522
  323. package/checksums.txt +0 -142
  324. package/cli.d.ts.map +0 -1
  325. package/companion.d.ts.map +0 -1
  326. package/companion.js +0 -389
  327. package/crossbrowser.d.ts.map +0 -1
  328. package/crossbrowser.js +0 -1191
  329. package/dashdone.d.ts.map +0 -1
  330. package/dashdone.js +0 -368
  331. package/deno.d.ts.map +0 -1
  332. package/deno.js +0 -52325
  333. package/devthink.umd.js +0 -52346
  334. package/fixtures/bun.ts +0 -7
  335. package/fixtures/cjs.js +0 -6
  336. package/fixtures/deno.ts +0 -6
  337. package/fixtures/example-org-pagestate.json +0 -22
  338. package/fixtures/importers/automa-workflow.json +0 -18
  339. package/fixtures/importers/selenium-side.json +0 -20
  340. package/fixtures/importers/tabular-plan.csv +0 -7
  341. package/fixtures/importers/uivision-macro.json +0 -10
  342. package/fixtures/importers/v1-plan.json +0 -13
  343. package/fixtures/mcp-client.mjs +0 -14
  344. package/fixtures/pages/checkout.html +0 -192
  345. package/fixtures/pages/dashboard.html +0 -110
  346. package/fixtures/pages/feed.html +0 -113
  347. package/fixtures/pages/product-grid.html +0 -150
  348. package/fixtures/plans/form-inventory-plan.json +0 -11
  349. package/fixtures/plans/release-notes-plan.json +0 -11
  350. package/fixtures/recipes/agentscompete.json +0 -11
  351. package/fixtures/recipes/agentsforms.json +0 -11
  352. package/fixtures/recipes/agentsmonitor.json +0 -11
  353. package/fixtures/recipes/agentsreview.json +0 -29
  354. package/fixtures/recipes/agentswarm.json +0 -11
  355. package/fixtures/recipes/fillcalendar.json +0 -12
  356. package/fixtures/recipes/fillcheckout.json +0 -13
  357. package/fixtures/recipes/filldependentdropdowns.json +0 -12
  358. package/fixtures/recipes/fillfromcsv.json +0 -13
  359. package/fixtures/recipes/fillloginform.json +0 -12
  360. package/fixtures/recipes/fillmultistepwizard.json +0 -13
  361. package/fixtures/recipes/fillregistration.json +0 -12
  362. package/fixtures/recipes/fillsearchfilters.json +0 -12
  363. package/fixtures/recipes/filltypeahead.json +0 -11
  364. package/fixtures/recipes/monitoralerts.json +0 -12
  365. package/fixtures/recipes/monitoravailability.json +0 -11
  366. package/fixtures/recipes/monitornetworkquiet.json +0 -12
  367. package/fixtures/recipes/monitorpagechanges.json +0 -11
  368. package/fixtures/recipes/monitorpricechange.json +0 -11
  369. package/fixtures/recipes/monitorschedule.json +0 -12
  370. package/fixtures/recipes/scrapedynamicprices.json +0 -13
  371. package/fixtures/recipes/scrapeimagegallery.json +0 -12
  372. package/fixtures/recipes/scrapeinfinitefeed.json +0 -13
  373. package/fixtures/recipes/scrapenestedlists.json +0 -12
  374. package/fixtures/recipes/scrapeproductgrid.json +0 -12
  375. package/fixtures/recipes/scrapereviews.json +0 -12
  376. package/fixtures/recipes/scrapesearchresults.json +0 -12
  377. package/fixtures/recipes/scrapetablepagination.json +0 -12
  378. package/fixtures/recipes/testaccessibility.json +0 -34
  379. package/fixtures/recipes/testconsoleerrors.json +0 -12
  380. package/fixtures/recipes/testdeeplinks.json +0 -12
  381. package/fixtures/recipes/testformvalidation.json +0 -13
  382. package/fixtures/recipes/testlayoutshift.json +0 -12
  383. package/fixtures/recipes/testlinkcheck.json +0 -12
  384. package/fixtures/recipes/testloadtiming.json +0 -12
  385. package/fixtures/recipes/testvisualdiff.json +0 -12
  386. package/fixtures/workflows/changelog-digest-workflow.json +0 -13
  387. package/fixtures/workflows/form-survey-workflow.json +0 -13
  388. package/gallery.json +0 -706
  389. package/hardening.d.ts.map +0 -1
  390. package/hardening.js +0 -188
  391. package/headless.d.ts.map +0 -1
  392. package/headless.js +0 -11522
  393. package/http.d.ts.map +0 -1
  394. package/http.js +0 -2165
  395. package/index.cjs +0 -54682
  396. package/index.d.ts.map +0 -1
  397. package/index.js +0 -52310
  398. package/index.neutral.js +0 -46343
  399. package/mcp.d.ts.map +0 -1
  400. package/mcp.js +0 -20515
  401. package/memory.d.ts.map +0 -1
  402. package/nativehost.template.json +0 -10
  403. package/node.cjs +0 -54686
  404. package/node.d.ts.map +0 -1
  405. package/pack.d.ts.map +0 -1
  406. package/pack.js +0 -805
  407. package/policy.d.ts.map +0 -1
  408. package/progress.d.ts.map +0 -1
  409. package/progress.js +0 -645
  410. package/protocol.d.ts.map +0 -1
  411. package/protocol.js +0 -8334
  412. package/schemas/audit.schema.json +0 -226
  413. package/schemas/capability.schema.json +0 -113
  414. package/schemas/envelope.schema.json +0 -162
  415. package/schemas/memory.schema.json +0 -51
  416. package/schemas/observation.schema.json +0 -113
  417. package/schemas/plan.schema.json +0 -208
  418. package/schemas/progress.schema.json +0 -126
  419. package/schemas/proposal.schema.json +0 -68
  420. package/schemas/session.schema.json +0 -82
  421. package/schemas/tool.schema.json +0 -94
  422. package/server.d.ts.map +0 -1
  423. package/server.js +0 -28877
  424. package/umd-example.html +0 -18
  425. package/umd.d.ts.map +0 -1
  426. /package/{bun.d.ts → dist/bun.d.ts} +0 -0
  427. /package/{cli.d.ts → dist/cli.d.ts} +0 -0
  428. /package/{companion.d.ts → dist/companion.d.ts} +0 -0
  429. /package/{crossbrowser.d.ts → dist/crossbrowser.d.ts} +0 -0
  430. /package/{dashdone.d.ts → dist/dashdone.d.ts} +0 -0
  431. /package/{deno.d.ts → dist/deno.d.ts} +0 -0
  432. /package/{hardening.d.ts → dist/hardening.d.ts} +0 -0
  433. /package/{headless.d.ts → dist/headless.d.ts} +0 -0
  434. /package/{http.d.ts → dist/http.d.ts} +0 -0
  435. /package/{index.d.ts → dist/index.d.ts} +0 -0
  436. /package/{mcp.d.ts → dist/mcp.d.ts} +0 -0
  437. /package/{memory.d.ts → dist/memory.d.ts} +0 -0
  438. /package/{node.d.ts → dist/node.d.ts} +0 -0
  439. /package/{pack.d.ts → dist/pack.d.ts} +0 -0
  440. /package/{policy.d.ts → dist/policy.d.ts} +0 -0
  441. /package/{progress.d.ts → dist/progress.d.ts} +0 -0
  442. /package/{protocol.d.ts → dist/protocol.d.ts} +0 -0
  443. /package/{server.d.ts → dist/server.d.ts} +0 -0
  444. /package/{umd.d.ts → dist/umd.d.ts} +0 -0
@@ -0,0 +1,623 @@
1
+ import { afterAll, describe, expect, it } from "vitest";
2
+ import { execFile } from "node:child_process";
3
+ import { createHash } from "node:crypto";
4
+ import { existsSync } from "node:fs";
5
+ import { access, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
6
+ import { tmpdir } from "node:os";
7
+ import { dirname, join, resolve } from "node:path";
8
+ import { createRequire } from "node:module";
9
+ import { promisify } from "node:util";
10
+ import { build } from "esbuild";
11
+ import { stripstrings, underscorednames } from "./bundlescan.mjs";
12
+ import { umdwrap } from "./umdwrap.mjs";
13
+ import { matrixverify, matrixtargetof, platformtargets, targetoutput } from "../runtime.js";
14
+ import { clicommands, surfacepalette } from "../views.js";
15
+ import {
16
+ browserplatformadapter,
17
+ defaultclock,
18
+ denoplatformadapter,
19
+ detectadapterruntime,
20
+ loggeradapterof,
21
+ nodeplatformadapter,
22
+ platformadapterof,
23
+ setsharedadapter,
24
+ sharedadapter,
25
+ } from "../runtime.js";
26
+ import { denoconfigread } from "../deno.js";
27
+ import { memorystorageadapter } from "../runtime.js";
28
+ import { sessionmemory } from "../memory.js";
29
+ import { progressnow, recordoutcomewithclock } from "../progress.js";
30
+ import { parseheadlessfixture, resolvefixture } from "../cli.js";
31
+ import * as policymodule from "../policy.js";
32
+ import * as protocolmodule from "../protocol.js";
33
+ import * as memorymodule from "../memory.js";
34
+ import * as progressmodule from "../progress.js";
35
+ import type { stepoutcome } from "../types.js";
36
+
37
+ const execute = promisify(execFile);
38
+ const require = createRequire(import.meta.url);
39
+ const outbase = await mkdtemp(join(tmpdir(), "devthink-library-"));
40
+
41
+ /** Resolves the repo-local tsc binary the declaration pass rides: the merged repo carries typescript as its own devdependency, so the emission needs no package-manager exec indirection (pnpm exec retired with the merge — the same resolution tests/build.mjs uses). */
42
+ function resolvetsc(): string {
43
+ const self = require.resolve("typescript/package.json");
44
+ return join(dirname(self), "bin", "tsc");
45
+ }
46
+
47
+ /** Builds one entry of the matrix into the temp directory with the format and platform its target declares; the umd format wraps its cjs core in the umd envelope the build ships. */
48
+ async function buildtarget(
49
+ entry: string,
50
+ format: "esm" | "cjs" | "umd",
51
+ platform: "browser" | "node" | "neutral",
52
+ output: string,
53
+ ): Promise<string> {
54
+ if (format === "umd") {
55
+ const core = output.replace(/\.js$/, ".core.cjs");
56
+ await build({
57
+ entryPoints: [entry],
58
+ outfile: core,
59
+ bundle: true,
60
+ format: "cjs",
61
+ platform,
62
+ target: platform === "browser" ? "chrome120" : "es2022",
63
+ sourcemap: false,
64
+ });
65
+ const body = await readFile(core, "utf8");
66
+ await writeFile(output, umdwrap(body, "devthink"), "utf8");
67
+ await rm(core, { force: true });
68
+ return output;
69
+ }
70
+ await build({
71
+ entryPoints: [entry],
72
+ outfile: output,
73
+ bundle: true,
74
+ format,
75
+ platform,
76
+ target: platform === "browser" ? "chrome120" : platform === "node" ? "node22" : "es2022",
77
+ sourcemap: true,
78
+ });
79
+ return output;
80
+ }
81
+
82
+ describe("the library on every runtime", () => {
83
+ /* the bundle builds answer the slowest runners and the emulated container legs with the env-scaled ceiling the vitest config reads, because one esbuild pass over the whole matrix legitimately runs past the five second default on a two vcpu runner (the 2.0.10 container leg proved a sixteen millisecond overrun fails a green test) */
84
+ it("builds and loads the esm core in node with tree shakable exports", {
85
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 60000),
86
+ }, async () => {
87
+ const output = await buildtarget("index.ts", "esm", "neutral", join(outbase, "index.mjs"));
88
+ const loaded = await import(output);
89
+ expect(typeof loaded.surfacepalette).toBe("function");
90
+ expect(typeof loaded.portablerulesetof).toBe("function");
91
+ expect(loaded.platformtargets()).toHaveLength(4);
92
+ const content = await readFile(output, "utf8");
93
+ expect(content).toContain("export");
94
+ });
95
+
96
+ it("builds and loads the cjs core in node for require based consumers", async () => {
97
+ const output = await buildtarget("index.ts", "cjs", "node", join(outbase, "index.cjs"));
98
+ const loaded = require(output) as Record<string, unknown>;
99
+ expect(typeof loaded.surfacepalette).toBe("function");
100
+ expect(typeof loaded.runflow).toBe("function");
101
+ expect(typeof loaded.exportrecords).toBe("function");
102
+ });
103
+
104
+ it("builds every platform target of the matrix in one run and loads each bundle", {
105
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 120000),
106
+ }, async () => {
107
+ const present: string[] = [];
108
+ for (const target of platformtargets()) {
109
+ const output = await buildtarget(
110
+ target.entry,
111
+ target.format,
112
+ target.platform,
113
+ join(outbase, targetoutput(target)),
114
+ );
115
+ present.push(target.entry);
116
+ const content = await readFile(output, "utf8");
117
+ expect(content.length).toBeGreaterThan(0);
118
+ if (target.format === "esm") {
119
+ const loaded = await import(output);
120
+ expect(typeof loaded.surfacepalette).toBe("function");
121
+ } else {
122
+ const loaded = require(output) as Record<string, unknown>;
123
+ const expected =
124
+ matrixtargetof(platformtargets(), target.runtime).runtime === "node" ? "nodeadapter" : "surfacepalette";
125
+ expect(typeof loaded[expected]).toBe("function");
126
+ }
127
+ }
128
+ expect(matrixverify({ targets: platformtargets(), present }).complete).toBe(true);
129
+ });
130
+
131
+ it("keeps the deno entry free of node shims and loads it as neutral esm", async () => {
132
+ const output = await buildtarget("deno.ts", "esm", "neutral", join(outbase, "deno-check.mjs"));
133
+ const content = await readFile(output, "utf8");
134
+ expect(content).not.toMatch(/from\s*["']node:/);
135
+ expect(content).not.toMatch(/require\(\s*["']node:/);
136
+ const loaded = await import(output);
137
+ expect(typeof loaded.denoadapter).toBe("function");
138
+ const deno = await execute("deno", ["--version"]).catch(() => undefined);
139
+ if (deno === undefined)
140
+ return; /* the deno binary stays optional in the local matrix; the neutral bundle above still proves the entry */
141
+ await writeFile(
142
+ join(outbase, "deno-entry.test.ts"),
143
+ 'import { surfacepalette } from "./deno-check.mjs";\nDeno.test("loads the deno entry", () => { if (surfacepalette().length === 0) throw new Error("The deno entry loaded an empty palette."); });\n',
144
+ "utf8",
145
+ );
146
+ await execute("deno", ["test", "--allow-read", "deno-entry.test.ts"], { cwd: outbase });
147
+ });
148
+
149
+ it("runs the bun entry under bun test", async () => {
150
+ const bunversion = await execute("bun", ["--version"]).catch(() => undefined);
151
+ if (bunversion === undefined) return; /* the bun binary stays optional in the local matrix */
152
+ const output = await buildtarget("bun.ts", "esm", "node", join(outbase, "bun-entry.mjs"));
153
+ await writeFile(
154
+ join(outbase, "bun-entry.test.ts"),
155
+ `import { expect, test } from "bun:test";\nimport * as library from "${output}";\ntest("loads the bun entry", () => { expect(typeof library.bunadapter).toBe("function"); expect(typeof library.surfacepalette).toBe("function"); });\n`,
156
+ "utf8",
157
+ );
158
+ const result = await execute("bun", ["test", join(outbase, "bun-entry.test.ts")]);
159
+ expect(`${result.stdout}${result.stderr}`).toContain("1 pass");
160
+ });
161
+
162
+ it("emits declaration files for every entry point of the matrix", async () => {
163
+ const outdir = await mkdtemp(join(tmpdir(), "devthink-types-"));
164
+ await execute(resolvetsc(), ["-p", "tsconfig.build.json", "--outDir", outdir]);
165
+ for (const entry of [
166
+ "index",
167
+ "umd",
168
+ "node",
169
+ "bun",
170
+ "deno",
171
+ "plan",
172
+ "flow",
173
+ "export",
174
+ "headless",
175
+ "cli",
176
+ "agent",
177
+ "auth",
178
+ "http",
179
+ "server",
180
+ "page",
181
+ "memory",
182
+ "mcp",
183
+ "runtime",
184
+ ]) {
185
+ const declaration = await readFile(join(outdir, `${entry}.d.ts`), "utf8");
186
+ expect(declaration.length).toBeGreaterThan(0);
187
+ }
188
+ await rm(outdir, { recursive: true, force: true });
189
+ }, 120_000);
190
+
191
+ it("shares the command registry between the cli and the commandpalette definitions", () => {
192
+ const palette = surfacepalette();
193
+ const registry = clicommands(palette);
194
+ const terminal = registry.filter((command) => command.terminal);
195
+ const shared = registry.filter((command) => !command.terminal);
196
+ expect(terminal.map((command) => command.id)).toEqual([
197
+ "manifest",
198
+ "describe",
199
+ "commands",
200
+ "planlint",
201
+ "migrateplan",
202
+ "recipes",
203
+ "flowrun",
204
+ "runworkflow",
205
+ "exportdata",
206
+ "headless",
207
+ "serve",
208
+ "native",
209
+ "export",
210
+ "init",
211
+ "doctor",
212
+ "help",
213
+ ]);
214
+ expect(shared).toHaveLength(palette.length);
215
+ for (const entry of palette) {
216
+ const command = shared.find((item) => item.id === entry.id);
217
+ expect(command?.label).toBe(entry.label);
218
+ expect(command?.keywords).toEqual(entry.keywords);
219
+ }
220
+ });
221
+ });
222
+
223
+ /** Builds one consumption mode bundle once for the whole mode suite: the cached build lets every mode test read one bundle instead of rebuilding per assertion. */
224
+ const modecache = new Map<string, Promise<string>>();
225
+ async function modebundle(key: string, buildit: () => Promise<string>): Promise<string> {
226
+ const cached = modecache.get(key);
227
+ if (cached !== undefined) return cached;
228
+ const built = buildit();
229
+ modecache.set(key, built);
230
+ return built;
231
+ }
232
+
233
+ /** Reads the sorted export names of one mode bundle: an esm or neutral bundle answers through import and a cjs bundle answers through require. */
234
+ async function modekeys(output: string): Promise<string[]> {
235
+ if (output.endsWith(".cjs")) return Object.keys(require(output) as Record<string, unknown>).sort();
236
+ return Object.keys(await import(output)).sort();
237
+ }
238
+
239
+ /** Runs one umd bundle source against a sandbox global and answers the sandbox, so the global surface and the deprecation shim verify without a browser. */
240
+ function umdglobal(source: string): Record<string, unknown> {
241
+ const sandbox: Record<string, unknown> = {};
242
+ sandbox.self = sandbox;
243
+ new Function("self", source)(sandbox);
244
+ return sandbox;
245
+ }
246
+
247
+ describe("the library modes of 1.1.81", () => {
248
+ it("freezes the public api surface across the esm, cjs and umd modes", {
249
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 120000),
250
+ }, async () => {
251
+ const esm = await modekeys(
252
+ await modebundle("esm", () => buildtarget("index.ts", "esm", "neutral", join(outbase, "mode-index.mjs"))),
253
+ );
254
+ const cjs = await modekeys(
255
+ await modebundle("cjs", () => buildtarget("cjs.ts", "cjs", "node", join(outbase, "mode-index.cjs"))),
256
+ );
257
+ expect(cjs).toEqual(esm);
258
+ const umdsource = await readFile(
259
+ await modebundle("umd", () => buildtarget("umd.ts", "umd", "browser", join(outbase, "mode-devthink.umd.js"))),
260
+ "utf8",
261
+ );
262
+ const globalkeys = Object.keys(umdglobal(umdsource).devthink as Record<string, unknown>).sort();
263
+ expect(globalkeys).toEqual(esm);
264
+ expect(esm.length).toBeGreaterThan(1000);
265
+ const probes: Array<[string, string, Record<string, unknown>]> = [
266
+ ["policy", "canexecute", policymodule],
267
+ ["protocol", "parseproposal", protocolmodule],
268
+ ["memory", "sessionmemory", memorymodule],
269
+ ["progress", "recordstep", progressmodule],
270
+ ];
271
+ for (const [modulename, probe, source] of probes) {
272
+ const output = await modebundle(`module-${modulename}`, () =>
273
+ buildtarget(`${modulename}.ts`, "esm", "neutral", join(outbase, `mode-${modulename}.mjs`)),
274
+ );
275
+ const loaded = await import(output);
276
+ expect(typeof loaded[probe]).toBe("function");
277
+ expect(Object.keys(loaded).sort()).toEqual(Object.keys(source).sort());
278
+ expect(Object.keys(loaded).length).toBeGreaterThan(1);
279
+ }
280
+ });
281
+
282
+ it("keeps the shared adapter registry consistent across the esm and cjs modes of one process", {
283
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 60000),
284
+ }, async () => {
285
+ const esm = await import(
286
+ await modebundle("esm", () => buildtarget("index.ts", "esm", "neutral", join(outbase, "mode-index.mjs")))
287
+ );
288
+ const cjs = require(
289
+ await modebundle("cjs", () => buildtarget("cjs.ts", "cjs", "node", join(outbase, "mode-index.cjs"))),
290
+ ) as typeof esm;
291
+ expect(esm.bundlestamp().mode).toBe("esm");
292
+ expect(cjs.bundlestamp().mode).toBe("cjs");
293
+ expect(cjs.bundlestamp().version).toBe(esm.bundlestamp().version);
294
+ expect(cjs.bundlestamp().target).toBe("index.cjs");
295
+ esm.setsharedadapter(esm.platformadapterof({ runtime: "node", storage: esm.memorystorageadapter() }));
296
+ const throughcjs = cjs.sharedadapter();
297
+ expect(throughcjs?.runtime).toBe("node");
298
+ expect(throughcjs?.mode).toBe("cjs");
299
+ await throughcjs?.storage.set("sharedstate", { written: "esm" });
300
+ expect(await esm.sharedadapter()?.storage.get("sharedstate")).toEqual({ written: "esm" });
301
+ expect(await cjs.sharedadapter()?.storage.get("sharedstate")).toEqual({ written: "esm" });
302
+ });
303
+
304
+ it("exposes the window.devthink global with the consent gates intact and the sunset removed the deprecated uppercase shim", {
305
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 60000),
306
+ }, async () => {
307
+ const umdsource = await readFile(
308
+ await modebundle("umd", () => buildtarget("umd.ts", "umd", "browser", join(outbase, "mode-devthink.umd.js"))),
309
+ "utf8",
310
+ );
311
+ const notices: string[] = [];
312
+ const originalwarn = console.warn;
313
+ console.warn = ((line: string) => {
314
+ notices.push(line);
315
+ }) as typeof console.warn;
316
+ try {
317
+ const sandbox = umdglobal(umdsource);
318
+ const globalobject = sandbox.devthink as Record<string, unknown>;
319
+ expect(typeof globalobject.surfacepalette).toBe("function");
320
+ expect(typeof globalobject.canexecute).toBe("function");
321
+ expect(typeof globalobject.planlint).toBe("function");
322
+ expect(typeof globalobject.cookiegate).toBe("function");
323
+ expect(typeof globalobject.openheadlesssession).toBe("function");
324
+ expect((globalobject.bundlestamp as () => { mode: string })().mode).toBe("umd");
325
+ expect(sandbox.devthink).toBe(globalobject);
326
+ /* the 2.0.0 sunset removed the deprecated uppercase global the deprecation window carried: the envelope declares the lowercase surface only and no deprecation notice fires anywhere */
327
+ expect((sandbox as Record<string, unknown>).Devthink).toBeUndefined();
328
+ expect(notices).toHaveLength(0);
329
+ } finally {
330
+ console.warn = originalwarn;
331
+ }
332
+ });
333
+
334
+ it("covers the node, browser and deno default adapters behind the platform seam", async () => {
335
+ const files = new Map<string, string>();
336
+ const node = nodeplatformadapter({
337
+ profiledir: "profiles",
338
+ fs: {
339
+ readfile: async (path) => {
340
+ if (!files.has(path)) throw new Error(`No file at ${path}.`);
341
+ return files.get(path) as string;
342
+ },
343
+ writefile: async (path, data) => {
344
+ files.set(path, data);
345
+ },
346
+ mkdir: async () => undefined,
347
+ join: (...parts) => parts.join("/"),
348
+ },
349
+ });
350
+ expect(node.mode).toBe("cjs");
351
+ expect(node.declaration.storage).toBe("filesystem");
352
+ expect(node.probes.dom).toBe(false);
353
+ await node.storage.set("plan", { goal: "read" });
354
+ expect(await node.storage.get<{ goal: string }>("plan")).toEqual({ goal: "read" });
355
+
356
+ const area = new Map<string, unknown>();
357
+ const browser = browserplatformadapter({
358
+ area: {
359
+ get: async (key) => area.get(key),
360
+ set: async (key, value) => {
361
+ area.set(key, value);
362
+ },
363
+ },
364
+ });
365
+ expect(browser.mode).toBe("umd");
366
+ expect(browser.declaration.storage).toBe("chrome");
367
+ expect(browser.probes.dom).toBe(true);
368
+ await browser.storage.set("session", { state: "active" });
369
+ expect(area.get("session")).toEqual({ state: "active" });
370
+ const fallback = browserplatformadapter();
371
+ await fallback.storage.set("key", "value");
372
+ expect(await fallback.storage.get("key")).toBe("value");
373
+
374
+ const kv = new Map<string, unknown>();
375
+ const deno = denoplatformadapter({
376
+ kv: {
377
+ get: async (key: string) => kv.get(key),
378
+ set: async (key: string, value: unknown) => {
379
+ kv.set(key, value);
380
+ },
381
+ } as never,
382
+ });
383
+ expect(deno.declaration.storage).toBe("denokv");
384
+ await deno.storage.set("kv", 1);
385
+ expect(kv.get("kv")).toBe(1);
386
+
387
+ expect(typeof defaultclock().now()).toBe("number");
388
+ const lines: string[] = [];
389
+ const sink = loggeradapterof({
390
+ log: (line) => lines.push(`log:${line}`),
391
+ warn: (line) => lines.push(`warn:${line}`),
392
+ error: (line) => lines.push(`error:${line}`),
393
+ });
394
+ sink.log("a");
395
+ sink.warn("b");
396
+ sink.error("c");
397
+ expect(lines).toEqual(["log:a", "warn:b", "error:c"]);
398
+ expect(detectadapterruntime()).toBe("node");
399
+
400
+ const memory = new sessionmemory(memorystorageadapter());
401
+ await memory.setplan({} as never);
402
+ expect(await memory.getplan()).toEqual({});
403
+ const clock = { now: () => 1_000, schedule: () => 0 };
404
+ expect(progressnow(clock)).toBe(1_000);
405
+ const outcome: stepoutcome = { stepid: "observe", ok: true, summary: "observed", at: 1_000 } as stepoutcome;
406
+ const stepped = recordoutcomewithclock(undefined, "plan", outcome, clock);
407
+ expect(stepped.updatedat).toBe(1_000);
408
+ expect(stepped.outcomes).toHaveLength(1);
409
+
410
+ const fixturefile = JSON.parse(await readFile("tests/code/example-org-pagestate.json", "utf8")) as unknown;
411
+ const fixture = parseheadlessfixture(fixturefile);
412
+ expect(resolvefixture([fixture], fixture.origin)).toBe(fixture);
413
+ if (!existsSync("deno.json"))
414
+ return; /* the deno runtime config rides the deno lane of the matrix: the adapter seam above proves the deno platform adapter without it, and the exports pass below carries the config contract once the deno.json restoration lands */
415
+ const config = await denoconfigread(async () => await readFile("deno.json", "utf8"));
416
+ expect(config.imports).toBeDefined();
417
+ expect(config.tasks).toBeDefined();
418
+ });
419
+
420
+ it("resolves every exports condition, selects the neutral target under the browser condition and keeps the engines in sync", async () => {
421
+ const packagejson = JSON.parse(await readFile("package.json", "utf8")) as {
422
+ version: string;
423
+ sideEffects?: boolean;
424
+ publishConfig?: { registry?: string };
425
+ engines: Record<string, string>;
426
+ exports: Record<string, Record<string, string>>;
427
+ };
428
+ const root = packagejson.exports["."];
429
+ if (root === undefined) throw new Error("The package exports map carries no root entry.");
430
+ expect(Object.keys(root)).toEqual(["types", "browser", "import", "require", "default"]);
431
+ expect(root.browser).toBe("./dist/index.neutral.js");
432
+ expect(root.import).toBe("./dist/index.js");
433
+ expect(root.require).toBe("./dist/index.cjs");
434
+ for (const entry of [
435
+ "./policy",
436
+ "./protocol",
437
+ "./memory",
438
+ "./progress",
439
+ "./cli",
440
+ "./umd",
441
+ "./node",
442
+ "./bun",
443
+ "./deno",
444
+ "./headless",
445
+ ]) {
446
+ if (packagejson.exports[entry] === undefined)
447
+ throw new Error(`The package exports map lacks the ${entry} entry.`);
448
+ }
449
+ expect(packagejson.exports["./umd"]?.default).toBe("./dist/devthink.umd.js");
450
+ expect(packagejson.exports["./policy"]?.import).toBe("./dist/policy.js");
451
+ expect(packagejson.exports["./progress"]?.import).toBe("./dist/progress.js");
452
+ expect(packagejson.exports["./cli"]?.import).toBe("./dist/cli.js");
453
+ expect(packagejson.sideEffects).toBe(false);
454
+ expect(packagejson.publishConfig?.registry).toBe("https://registry.npmjs.org/");
455
+ const nvmversion = (await readFile(".nvmrc", "utf8")).trim();
456
+ expect(packagejson.engines.node).toContain(nvmversion);
457
+ const verifyworkflow = await readFile(".github/workflows/verify.yml", "utf8");
458
+ const bunminimum = (packagejson.engines.bun ?? "").match(/>=([\d.]+)/)?.[1];
459
+ expect(verifyworkflow).toContain(`bun-version: ${bunminimum}`);
460
+ expect(verifyworkflow).toContain("denoland/setup-deno");
461
+ const denojson = JSON.parse(await readFile("deno.json", "utf8")) as {
462
+ imports: Record<string, string>;
463
+ tasks: Record<string, string>;
464
+ };
465
+ expect(denojson.imports["@wenathlan/devthink"]).toBe(`npm:@wenathlan/devthink@${packagejson.version}`);
466
+ expect(denojson.tasks.check).toContain("dist/deno.js");
467
+ if (!existsSync("dist/checksums.txt"))
468
+ return; /* the validate chain runs the tests before the build; the file existence pass runs on the next pass and in the ci lanes that build first */
469
+ const referenced = new Set<string>();
470
+ for (const entry of Object.values(packagejson.exports))
471
+ for (const target of Object.values(entry)) referenced.add(target.replace(/^\.\//, ""));
472
+ for (const file of referenced) await access(join(process.cwd(), file));
473
+ });
474
+
475
+ it("stamps the version, the mode and the license banner into every built bundle", {
476
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 60000),
477
+ }, async () => {
478
+ if (!existsSync("dist/checksums.txt"))
479
+ return; /* the validate chain runs the tests before the build; the stamp pass runs on the next pass and in the ci lanes that build first */
480
+ const packagejson = JSON.parse(await readFile("package.json", "utf8")) as { version: string };
481
+ const checksums = (await readFile("dist/checksums.txt", "utf8")).trim().split("\n");
482
+ expect(checksums.length).toBeGreaterThan(20);
483
+ for (const line of checksums) {
484
+ const file = line.slice(66);
485
+ if (file === "manifest.json key")
486
+ continue; /* the identity record of the published key pins the manifest identity digest beside the bundle checksums, so the pin rides the generated artifact and no license banner applies */
487
+ if (file === "gallery.json")
488
+ continue; /* the example gallery index ships as data the recipes runner reads: the checksum and the artifact manifest cover it, no license banner rides a data file */
489
+ if (file.startsWith("site/"))
490
+ continue; /* the static site assets carry their own manifest, not the library banner */
491
+ if (file.endsWith(".zip"))
492
+ continue; /* the zipped declaration bundle of the publishing pipeline is an assembled binary artifact: its checksum and manifest entry carry it, no text banner rides a zip */
493
+ if (file.startsWith("caps/") || file.startsWith("schemas/") || file.startsWith("fixtures/"))
494
+ continue; /* the contract data artifacts the 1.1.98 consolidation emits for the packages carry the frozen lists and the example set: the checksum, the artifact manifest and the freeze gate cover them, no license banner rides a data file */
495
+ const content = await readFile(join("dist", file), "utf8");
496
+ expect(content).toContain(`devthink ${packagejson.version}`);
497
+ expect(content).toContain("GPL-3.0-only");
498
+ }
499
+ const esm = await import(resolve("dist/index.js"));
500
+ const cjs = require(resolve("dist/index.cjs")) as Record<string, () => { version: string; mode: string }>;
501
+ const neutral = await import(resolve("dist/index.neutral.js"));
502
+ expect(esm.bundlestamp().version).toBe(packagejson.version);
503
+ expect(esm.bundlestamp().mode).toBe("esm");
504
+ expect(cjs.bundlestamp!().version).toBe(packagejson.version);
505
+ expect(cjs.bundlestamp!().mode).toBe("cjs");
506
+ expect(neutral.bundlestamp().mode).toBe("neutral");
507
+ expect(neutral.bundlestamp().version).toBe(packagejson.version);
508
+ const umdsource = await readFile("dist/devthink.umd.js", "utf8");
509
+ const sandbox = umdglobal(umdsource);
510
+ expect((sandbox.devthink as Record<string, () => { version: string }>).bundlestamp!().version).toBe(
511
+ packagejson.version,
512
+ );
513
+ });
514
+
515
+ it("verifies the checksums, the sourcemaps and the minified parity of every dist target", {
516
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 60000),
517
+ }, async () => {
518
+ if (!existsSync("dist/checksums.txt"))
519
+ return; /* the validate chain runs the tests before the build; the artifact pass runs on the next pass and in the ci lanes that build first */
520
+ const packagejson = JSON.parse(await readFile("package.json", "utf8")) as { version: string };
521
+ const checksums = (await readFile("dist/checksums.txt", "utf8")).trim().split("\n");
522
+ for (const line of checksums) {
523
+ const digest = line.slice(0, 64);
524
+ const file = line.slice(66);
525
+ if (file === "manifest.json key") {
526
+ /* the identity record of the published key: the build writes the manifest key digest beside the bundle checksums so the pin rides the generated artifact, never a hard coded source constant */
527
+ const manifestsource = JSON.parse(await readFile("web/manifest.json", "utf8")) as { key: string };
528
+ expect(createHash("sha256").update(Buffer.from(manifestsource.key, "base64")).digest("hex")).toBe(digest);
529
+ continue;
530
+ }
531
+ expect(
532
+ createHash("sha256")
533
+ .update(await readFile(join("dist", file)))
534
+ .digest("hex"),
535
+ ).toBe(digest);
536
+ if (file.startsWith("site/")) continue; /* the static site assets carry no sourcemaps or minified pairs */
537
+ if (file.startsWith("caps/") || file.startsWith("schemas/") || file.startsWith("fixtures/"))
538
+ continue; /* the contract data artifacts ship as data for the packages, not as built bundles: no sourcemap and no minified pair */
539
+ if (!file.endsWith(".js") && !file.endsWith(".cjs"))
540
+ continue; /* the json template of the native bridge carries the banner and the checksum without a minified pair, because a manifest template is data the installer stamps, not a runnable bundle */
541
+ const map = JSON.parse(await readFile(join("dist", `${file}.map`), "utf8")) as {
542
+ version: number;
543
+ sources: string[];
544
+ };
545
+ expect(map.version).toBe(3);
546
+ expect(map.sources.length).toBeGreaterThan(0);
547
+ if (file.includes(".min.")) continue; /* the minified variant is itself the pair of its unminified bundle */
548
+ const minified = file.replace(/\.js$/, ".min.js").replace(/\.cjs$/, ".min.cjs");
549
+ await access(join("dist", minified));
550
+ expect((await stat(join("dist", minified))).size).toBeLessThan((await stat(join("dist", file))).size);
551
+ }
552
+ const minifiedesm = await import(resolve("dist/index.min.js"));
553
+ expect(typeof minifiedesm.surfacepalette).toBe("function");
554
+ expect(minifiedesm.bundlestamp().version).toBe(packagejson.version);
555
+ const minifiedcjs = require(resolve("dist/index.min.cjs")) as Record<string, unknown>;
556
+ expect(typeof minifiedcjs.surfacepalette).toBe("function");
557
+ const headless = await import(resolve("dist/headless.js"));
558
+ expect(headless.bundlestamp().mode).toBe("headless");
559
+ });
560
+
561
+ it("keeps the policy and protocol modules free of platform imports and the browser bundles free of node imports", async () => {
562
+ for (const module of ["policy.ts", "protocol.ts", "progress.ts", "runtime.ts", "memory.ts"]) {
563
+ const source = await readFile(module, "utf8");
564
+ expect(source).not.toMatch(/from\s*["']node:/);
565
+ expect(source).not.toMatch(/require\(/);
566
+ expect(source).not.toMatch(/import\(\s*["']node:/);
567
+ }
568
+ if (!existsSync("dist/checksums.txt"))
569
+ return; /* the source purity holds on every pass; the bundle purity pass runs on the built dist */
570
+ for (const file of [
571
+ "index.neutral.js",
572
+ "index.neutral.min.js",
573
+ "devthink.umd.js",
574
+ "devthink.umd.min.js",
575
+ "policy.js",
576
+ "protocol.js",
577
+ "progress.js",
578
+ "memory.js",
579
+ ]) {
580
+ const content = await readFile(join("dist", file), "utf8");
581
+ expect(content).not.toMatch(/(?:from\s*|require\(\s*)["']node:/);
582
+ }
583
+ for (const file of [
584
+ "index.js",
585
+ "index.cjs",
586
+ "index.neutral.js",
587
+ "devthink.umd.js",
588
+ "policy.js",
589
+ "protocol.js",
590
+ "memory.js",
591
+ "progress.js",
592
+ "headless.js",
593
+ "cli.js",
594
+ ]) {
595
+ const stripped = stripstrings(await readFile(join("dist", file), "utf8"));
596
+ expect(underscorednames(stripped)).toHaveLength(0);
597
+ }
598
+ }, 480_000);
599
+
600
+ it("loads the headless entry under the esm and cjs modes without browser globals", {
601
+ timeout: Number(process.env.DEVTHINK_TEST_TIMEOUT_MS ?? 120000),
602
+ }, async () => {
603
+ const esm = await import(
604
+ await modebundle("headless-esm", () =>
605
+ buildtarget("headless.ts", "esm", "node", join(outbase, "mode-headless.mjs")),
606
+ )
607
+ );
608
+ expect(typeof esm.openlibraryrun).toBe("function");
609
+ expect(typeof esm.openheadlesssession).toBe("function");
610
+ expect(esm.bundlestamp().mode).toBe("headless");
611
+ const cjs = require(
612
+ await modebundle("headless-cjs", () =>
613
+ buildtarget("headless.ts", "cjs", "node", join(outbase, "mode-headless.cjs")),
614
+ ),
615
+ ) as Record<string, unknown>;
616
+ expect(typeof cjs.openlibraryrun).toBe("function");
617
+ expect(typeof cjs.openheadlesssession).toBe("function");
618
+ });
619
+ });
620
+
621
+ afterAll(async () => {
622
+ await rm(outbase, { recursive: true, force: true });
623
+ }, 120_000);