@wenathlan/devthink 2.0.12 → 2.0.14

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 +20 -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,895 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import {
3
+ audiotabs,
4
+ advancedownload,
5
+ badgefromprogress,
6
+ batchopenlinks,
7
+ buildlayout,
8
+ checksafeurl,
9
+ capturefilename,
10
+ capturenames,
11
+ capturesteps,
12
+ clipentryof,
13
+ cliphash,
14
+ clonetabs,
15
+ closeselection,
16
+ concurrentwindow,
17
+ conflictfree,
18
+ deeplinkapp,
19
+ discardcandidates,
20
+ downloadfilename,
21
+ layoutrestoreplan,
22
+ mimeallowed,
23
+ navintent,
24
+ navratelimit,
25
+ netlogentry,
26
+ netlogforstep,
27
+ newquarantine,
28
+ normalizedtaburl,
29
+ openclipboardurl,
30
+ parsetabquery,
31
+ pausenavconsent,
32
+ prefetchpage,
33
+ preconnectorigin,
34
+ quarantinedpath,
35
+ querymatches,
36
+ redactheaders,
37
+ reopentab,
38
+ resumenavconsent,
39
+ restoretrail,
40
+ referencedartifacts,
41
+ regroupaftermoves,
42
+ renamegroup,
43
+ restorediscarded,
44
+ released,
45
+ scanresult,
46
+ scanverdictof,
47
+ searchtabmatches,
48
+ sweepplan,
49
+ switcherlist,
50
+ switchtarget,
51
+ tabpatternmatches,
52
+ tasktabsinwindow,
53
+ tasktabgauge,
54
+ transitionallowed,
55
+ verifybytes,
56
+ watchtabdispatch,
57
+ windowprofilegrants,
58
+ zoomstep,
59
+ } from "../commands.js";
60
+ import type {
61
+ closedtabrecord,
62
+ ratelimitwindow,
63
+ tabgrouprecord,
64
+ toolstep,
65
+ urlvisit,
66
+ artifactinventoryentry,
67
+ cleanuprule,
68
+ } from "../types.js";
69
+
70
+ const now = 1_800_000_000_000;
71
+
72
+ /** Builds one live tab shape fixture. */
73
+ function tab(
74
+ over: Partial<{
75
+ tabid: number;
76
+ url: string;
77
+ title: string;
78
+ index: number;
79
+ windowid: number;
80
+ active: boolean;
81
+ pinned: boolean;
82
+ audible: boolean;
83
+ muted: boolean;
84
+ discarded: boolean;
85
+ }> = {},
86
+ ) {
87
+ return {
88
+ tabid: 1,
89
+ url: "https://example.com/page",
90
+ title: "Example",
91
+ index: 0,
92
+ windowid: 1,
93
+ active: true,
94
+ pinned: false,
95
+ audible: false,
96
+ muted: false,
97
+ discarded: false,
98
+ ...over,
99
+ };
100
+ }
101
+
102
+ /** Builds one toolstep fixture. */
103
+ function step(kind: toolstep["kind"], over: Partial<toolstep> = {}): toolstep {
104
+ return { id: "s1", kind, summary: "", risk: "interaction", ...over };
105
+ }
106
+
107
+ describe("torture: tab queries, patterns and the star storm", () => {
108
+ it("parses reviewed tab queries from step options and refuses malformed carriers", () => {
109
+ expect(
110
+ parsetabquery(
111
+ step("querytabs", {
112
+ options: JSON.stringify({
113
+ tabquery: { url: "https://example.com", title: "Example", id: 3, pattern: "https://example.com/*" },
114
+ }),
115
+ }),
116
+ ),
117
+ ).toEqual({ url: "https://example.com", title: "Example", id: 3, pattern: "https://example.com/*" });
118
+ expect(
119
+ parsetabquery(step("querytabs", { options: JSON.stringify({ tabquery: { id: -1, url: "", title: 5 } }) })),
120
+ ).toEqual({});
121
+ expect(parsetabquery(step("querytabs", { options: JSON.stringify({ tabquery: "nope" }) }))).toBeNull();
122
+ expect(parsetabquery(step("querytabs", { options: JSON.stringify({ tabquery: ["nope"] }) }))).toBeNull();
123
+ expect(parsetabquery(step("querytabs", { options: "not json" }))).toBeNull();
124
+ expect(parsetabquery(step("querytabs", {}))).toBeNull();
125
+ });
126
+
127
+ it("matches wildcard patterns with segment and subtree spans, regex metacharacters and empties", () => {
128
+ expect(tabpatternmatches("*", "anything")).toBe(true);
129
+ expect(tabpatternmatches("*", "a/b")).toBe(false);
130
+ expect(tabpatternmatches("**", "a/b/c")).toBe(true);
131
+ expect(tabpatternmatches("https://example.com/*", "https://example.com/pricing")).toBe(true);
132
+ expect(tabpatternmatches("https://example.com/*", "https://example.com/a/b")).toBe(false);
133
+ expect(tabpatternmatches("https://example.com/**", "https://example.com/a/b")).toBe(true);
134
+ expect(tabpatternmatches("https://example.com/**", "https://other.example/a")).toBe(false);
135
+ expect(tabpatternmatches("https://example.com/?q=1", "https://example.com/?q=1")).toBe(true);
136
+ expect(tabpatternmatches("https://example.com/?q=1", "https://example.com/xq=1")).toBe(false);
137
+ expect(tabpatternmatches("a.b", "axb")).toBe(false);
138
+ expect(tabpatternmatches("a*b*c", "a-b-c")).toBe(true);
139
+ expect(tabpatternmatches("", "")).toBe(true);
140
+ expect(tabpatternmatches("", "x")).toBe(false);
141
+ expect(tabpatternmatches("****", "a/b/c")).toBe(true);
142
+ });
143
+
144
+ it("stays linear on adversarial star storms instead of backtracking catastrophically", () => {
145
+ const started = Date.now();
146
+ expect(tabpatternmatches("*a".repeat(1500), "b".repeat(2000))).toBe(false);
147
+ expect(tabpatternmatches("a*".repeat(1500), "a".repeat(2000) + "/")).toBe(false);
148
+ expect(tabpatternmatches("*".repeat(3000), "https://example.com/" + "a/".repeat(1500))).toBe(true);
149
+ expect(tabpatternmatches(("ab*" + "a".repeat(20)).repeat(500), "ab" + "a".repeat(30))).toBe(false);
150
+ /* the linearity budget stays one second on native runners and scales with the same env the emulated arm64 container leg sets, because a qemu-interpreted second is not a native second while the linearity it proves is the same */
151
+ expect(Date.now() - started).toBeLessThan(Number(process.env.DEVTHINK_TEST_BUDGET_MS ?? 1000));
152
+ });
153
+
154
+ it("resolves tab queries where every matcher that exists must hold", () => {
155
+ const tabs = [
156
+ tab({ tabid: 1, url: "https://example.com/a", title: "Alpha" }),
157
+ tab({ tabid: 2, url: "https://example.com/b", title: "beta" }),
158
+ tab({ tabid: 3, url: "https://other.example/c", title: "Gamma" }),
159
+ ];
160
+ expect(querymatches({ url: "https://example.com/a" }, tabs)).toHaveLength(1);
161
+ expect(querymatches({ title: "ALPHA" }, tabs)).toHaveLength(1);
162
+ expect(querymatches({ id: 2 }, tabs).map((entry) => entry.tabid)).toEqual([2]);
163
+ expect(querymatches({ pattern: "https://example.com/*" }, tabs)).toHaveLength(2);
164
+ expect(querymatches({}, tabs)).toHaveLength(3);
165
+ expect(querymatches({ url: "https://example.com/a", title: "beta" }, tabs)).toHaveLength(0);
166
+ });
167
+
168
+ it("normalizes urls for clone comparison by dropping fragments and trailing slashes", () => {
169
+ expect(normalizedtaburl("https://example.com/page/")).toBe("https://example.com/page");
170
+ expect(normalizedtaburl("https://example.com/page///")).toBe("https://example.com/page");
171
+ expect(normalizedtaburl("https://example.com/page#frag")).toBe("https://example.com/page");
172
+ expect(normalizedtaburl("https://example.com/page#frag/more")).toBe("https://example.com/page");
173
+ expect(normalizedtaburl("/")).toBe("/");
174
+ expect(normalizedtaburl("")).toBe("");
175
+ const tabs = [
176
+ tab({ tabid: 1, url: "https://example.com/p" }),
177
+ tab({ tabid: 2, url: "https://example.com/p/" }),
178
+ tab({ tabid: 3, url: "https://example.com/p#x" }),
179
+ tab({ tabid: 4, url: "https://other.example" }),
180
+ ];
181
+ expect(clonetabs(tabs)).toEqual([{ url: "https://example.com/p", tabids: [1, 2, 3] }]);
182
+ expect(clonetabs([tab({ tabid: 9, url: "" }), tab({ tabid: 10, url: "" })])).toEqual([]);
183
+ });
184
+
185
+ it("searches, audio lists, discard candidates and restores across the live tab set", () => {
186
+ const tabs = [
187
+ tab({ tabid: 1, title: "Pricing table", url: "https://example.com/pricing" }),
188
+ tab({ tabid: 2, title: "Docs", url: "https://docs.example.org/guide", audible: true, active: false }),
189
+ tab({ tabid: 3, title: "Music", muted: true, audible: true, discarded: true, active: false }),
190
+ ];
191
+ expect(searchtabmatches(tabs, " pricing ")).toHaveLength(1);
192
+ expect(searchtabmatches(tabs, "DOCS")).toHaveLength(1);
193
+ expect(searchtabmatches(tabs, " ")).toEqual([]);
194
+ expect(audiotabs(tabs).map((entry) => entry.tabid)).toEqual([2, 3]);
195
+ expect(discardcandidates(tabs).map((entry) => entry.tabid)).toEqual([2]);
196
+ expect(restorediscarded(tabs)).toEqual([{ tabid: 3, url: tabs[2]!.url }]);
197
+ });
198
+
199
+ it("captures layouts, restores only the closed urls and regroups membership through moves", () => {
200
+ const tabs = [
201
+ tab({ tabid: 1, index: 0, pinned: true }),
202
+ tab({ tabid: 2, index: 1 }),
203
+ tab({ tabid: 3, index: 2, windowid: 7 }),
204
+ ];
205
+ const windows = [
206
+ {
207
+ windowid: 1,
208
+ left: 0,
209
+ top: 0,
210
+ width: 800,
211
+ height: 600,
212
+ state: "normal" as const,
213
+ incognito: false,
214
+ focused: true,
215
+ },
216
+ {
217
+ windowid: 7,
218
+ left: 10,
219
+ top: 10,
220
+ width: 400,
221
+ height: 300,
222
+ state: "maximized" as const,
223
+ incognito: false,
224
+ focused: false,
225
+ },
226
+ ];
227
+ const groups: tabgrouprecord[] = [
228
+ { groupid: "g1", name: "Research", color: "blue", tabids: [3, 2, 99], collapsed: false, savedat: now - 10 },
229
+ ];
230
+ const layout = buildlayout("daily", tabs, windows, groups, [7], now);
231
+ expect(layout.name).toBe("daily");
232
+ expect(layout.tabs).toHaveLength(3);
233
+ expect(layout.groups[0]?.tabids).toEqual([3, 2]);
234
+ expect(layout.windows[1]?.state).toEqual({
235
+ bounds: { left: 10, top: 10, width: 400, height: 300 },
236
+ maximized: true,
237
+ profile: "scratch",
238
+ });
239
+ expect(layoutrestoreplan(layout, ["https://example.com/page/"])).toEqual([]);
240
+ expect(layoutrestoreplan(layout, ["https://other.example/x"])).toEqual([
241
+ "https://example.com/page",
242
+ "https://example.com/page",
243
+ "https://example.com/page",
244
+ ]);
245
+ const moved = regroupaftermoves(groups, [tab({ tabid: 2, index: 0 }), tab({ tabid: 3, index: 1 })], now);
246
+ expect(moved[0]?.tabids).toEqual([2, 3]);
247
+ expect(moved[0]?.savedat).toBe(now);
248
+ expect(renamegroup(groups, "Research", "Study", now)[0]?.name).toBe("Study");
249
+ expect(regroupaftermoves(groups, [], now)[0]?.tabids).toEqual([3, 2, 99]);
250
+ });
251
+
252
+ it("protects the session tab from closepattern selections and counts task tabs per window", () => {
253
+ const tabs = [tab({ tabid: 1 }), tab({ tabid: 2 }), tab({ tabid: 3 })];
254
+ const selection = closeselection({ pattern: "https://example.com/*" }, tabs, 2);
255
+ expect(selection.targets.map((entry) => entry.tabid)).toEqual([1, 3]);
256
+ expect(selection.refused.map((entry) => entry.tabid)).toEqual([2]);
257
+ expect(closeselection({ id: 9 }, tabs, 2).targets).toEqual([]);
258
+ expect(tasktabsinwindow(tabs, 1, [1, 3, 99])).toBe(2);
259
+ expect(tasktabsinwindow(tabs, 5, [1])).toBe(0);
260
+ });
261
+
262
+ it("zooms without crossing zero, switches with wraparound and orders the switcher by recency", () => {
263
+ expect(zoomstep(1, "in", 0.25)).toBe(1.25);
264
+ expect(zoomstep(0.1, "out", 0.2)).toBe(0.1);
265
+ expect(zoomstep(0.5, "in", 0)).toBe(0.5);
266
+ const tabs = [
267
+ tab({ tabid: 1, index: 0, title: "Alpha" }),
268
+ tab({ tabid: 2, index: 1, title: "Beta tab 2" }),
269
+ tab({ tabid: 3, index: 2, title: "Gamma" }),
270
+ ];
271
+ expect(switchtarget(tabs, "next", 2)).toBe(0);
272
+ expect(switchtarget(tabs, "previous", 0)).toBe(2);
273
+ expect(switchtarget([], "next", 0)).toBeUndefined();
274
+ const recency = [
275
+ { tabid: 3, at: now },
276
+ { tabid: 1, at: now - 100 },
277
+ ];
278
+ expect(switcherlist(tabs, recency, "").map((entry) => entry.tabid)).toEqual([3, 1, 2]);
279
+ expect(switcherlist(tabs, recency, "tab 2").map((entry) => entry.tabid)).toEqual([2]);
280
+ expect(switcherlist(tabs, recency, "nomatch")).toEqual([]);
281
+ });
282
+
283
+ it("dispatches watched tab events through filters and derives badges and tab budgets", () => {
284
+ const events = [
285
+ { watchid: "w1", event: "title" as const, tabid: 1, at: now },
286
+ { watchid: "w1", event: "closed" as const, tabid: 2, at: now + 1 },
287
+ { watchid: "w2", event: "title" as const, tabid: 3, at: now + 2 },
288
+ ];
289
+ expect(watchtabdispatch(events, "w1", ["title"])).toHaveLength(1);
290
+ expect(watchtabdispatch(events, "w1", [])).toHaveLength(2);
291
+ expect(watchtabdispatch(events, "w9", [])).toEqual([]);
292
+ expect(badgefromprogress(3, 0)).toEqual({ label: "idle", done: false });
293
+ expect(badgefromprogress(5, 5)).toEqual({ label: "done", done: true });
294
+ expect(badgefromprogress(2, 5)).toEqual({ label: "2/5", done: false });
295
+ expect(tasktabgauge(3, undefined)).toEqual({ used: 3, ceiling: undefined, over: false });
296
+ expect(tasktabgauge(3, 2)).toEqual({ used: 3, ceiling: 2, over: true });
297
+ expect(tasktabgauge(2, 2).over).toBe(false);
298
+ expect(windowprofilegrants("normal")).toBe(true);
299
+ expect(windowprofilegrants("scratch")).toBe(true);
300
+ expect(windowprofilegrants("incognito")).toBe(false);
301
+ });
302
+ });
303
+
304
+ describe("torture: download states, filenames, mime filters and quarantine routing", () => {
305
+ const record = {
306
+ id: "d1",
307
+ url: "https://example.com/file.bin",
308
+ filename: "file.bin",
309
+ state: "queued" as const,
310
+ at: now,
311
+ updatedat: now,
312
+ };
313
+
314
+ it("walks only the legal batch queue transitions and merges evidence", () => {
315
+ expect(transitionallowed("queued", "running")).toBe(true);
316
+ expect(transitionallowed("queued", "paused")).toBe(false);
317
+ expect(transitionallowed("complete", "failed")).toBe(false);
318
+ expect(transitionallowed("failed", "queued")).toBe(false);
319
+ const impossible = advancedownload({ ...record, state: "complete" }, "running", now + 1);
320
+ expect(impossible.state).toBe("complete");
321
+ expect(impossible.updatedat).toBe(now);
322
+ const running = advancedownload(record, "running", now + 1, {
323
+ bytes: 42,
324
+ checksum: "sha",
325
+ downloadid: 7,
326
+ path: "/tmp/file.bin",
327
+ });
328
+ expect(running).toMatchObject({
329
+ state: "running",
330
+ bytes: 42,
331
+ checksum: "sha",
332
+ downloadid: 7,
333
+ path: "/tmp/file.bin",
334
+ });
335
+ const kept = advancedownload(record, "running", now + 2);
336
+ expect(kept.path).toBeUndefined();
337
+ expect(concurrentwindow(3, undefined)).toBe(true);
338
+ expect(concurrentwindow(3, 3)).toBe(false);
339
+ expect(concurrentwindow(2, 3)).toBe(true);
340
+ });
341
+
342
+ it("resolves filename conflicts with sequence suffixes and keeps extensions", () => {
343
+ expect(conflictfree("report.pdf", ["other.pdf"])).toBe("report.pdf");
344
+ expect(conflictfree("report.pdf", ["report.pdf"])).toBe("report-2.pdf");
345
+ expect(conflictfree("report.pdf", ["report.pdf", "report-2.pdf"])).toBe("report-3.pdf");
346
+ expect(conflictfree("noext", ["noext"])).toBe("noext-2");
347
+ expect(conflictfree(".gitignore", [".gitignore"])).toBe(".gitignore-2");
348
+ expect(conflictfree("archive.tar.gz", ["archive.tar.gz", "archive.tar-2.gz"])).toBe("archive.tar-3.gz");
349
+ });
350
+
351
+ it("derives download filenames from urls with decoding, hostnames and reviewed rules", () => {
352
+ expect(downloadfilename("https://example.com/files/report.pdf", undefined)).toBe("report.pdf");
353
+ expect(downloadfilename("https://example.com/files/my%20file.txt", undefined)).toBe("my file.txt");
354
+ expect(downloadfilename("https://example.com/", undefined)).toBe("example.com");
355
+ expect(downloadfilename("https://example.com", undefined)).toBe("example.com");
356
+ expect(downloadfilename("not a url", undefined)).toBe("not a url");
357
+ expect(downloadfilename("https://example.com/x.bin", " reviewed.bin ")).toBe("reviewed.bin");
358
+ expect(downloadfilename("https://example.com/a/b/", undefined)).toBe("b");
359
+ });
360
+
361
+ it("verifies completed downloads against size and checksum expectations", () => {
362
+ const complete = { ...record, state: "complete" as const, bytes: 100, checksum: "sha-1" };
363
+ expect(verifybytes(complete, { bytes: 100, checksum: "sha-1" }).ok).toBe(true);
364
+ expect(verifybytes(complete, { bytes: 101 }).ok).toBe(false);
365
+ expect(verifybytes(complete, { checksum: "sha-2" }).ok).toBe(false);
366
+ expect(verifybytes(record, {}).ok).toBe(false);
367
+ expect(verifybytes(complete, {}).matches).toEqual({ state: true, size: true, checksum: true });
368
+ const { bytes: _bytes, ...unknownsize } = complete;
369
+ expect(verifybytes(unknownsize, { bytes: 5 }).summary).toContain("unknown");
370
+ });
371
+
372
+ it("filters mime types where exclude wins, then include, then the default", () => {
373
+ const filter = { include: ["image/*"], exclude: ["image/svg+xml"], default: "allow" as const };
374
+ expect(mimeallowed(filter, "image/png")).toBe(true);
375
+ expect(mimeallowed(filter, "image/svg+xml")).toBe(false);
376
+ expect(mimeallowed(filter, "text/html")).toBe(true);
377
+ expect(mimeallowed({ include: ["text/plain"], exclude: [], default: "deny" as const }, "text/html")).toBe(false);
378
+ expect(mimeallowed({ include: [], exclude: [], default: "deny" as const }, "text/html")).toBe(false);
379
+ expect(
380
+ mimeallowed({ include: ["application/json"], exclude: [], default: "deny" as const }, "application/json"),
381
+ ).toBe(true);
382
+ expect(mimeallowed({ include: ["exact"], exclude: [], default: "allow" as const }, "exact")).toBe(true);
383
+ expect(mimeallowed({ include: ["exact"], exclude: [], default: "allow" as const }, "exactly")).toBe(true);
384
+ });
385
+
386
+ it("redacts every header value, correlates netlog rows and hashes clipboard payloads", () => {
387
+ expect(redactheaders({ Authorization: "Bearer abc", "X-Safe": "1" })).toEqual({
388
+ Authorization: "[redacted]",
389
+ "X-Safe": "[redacted]",
390
+ });
391
+ const entries = [
392
+ netlogentry({
393
+ url: "https://example.com/a",
394
+ method: "GET",
395
+ status: 200,
396
+ timing: 12,
397
+ requestid: "r1",
398
+ stepid: "s1",
399
+ at: now,
400
+ }),
401
+ netlogentry({
402
+ url: "https://example.com/b",
403
+ method: "POST",
404
+ status: 500,
405
+ timing: 30,
406
+ requestid: "r2",
407
+ stepid: "s2",
408
+ at: now + 1,
409
+ }),
410
+ ];
411
+ expect(netlogforstep(entries, "s1")).toHaveLength(1);
412
+ expect(netlogforstep(entries, "s9")).toEqual([]);
413
+ expect(clipentryof("read", { hash: cliphash("payload"), length: 7 }, "https://example.com", "s1", now)).toEqual({
414
+ kind: "read",
415
+ hash: cliphash("payload"),
416
+ length: 7,
417
+ origin: "https://example.com",
418
+ stepid: "s1",
419
+ at: now,
420
+ });
421
+ expect(cliphash("a")).not.toBe(cliphash("b"));
422
+ expect(
423
+ JSON.stringify(clipentryof("write", { hash: "h", length: 2 }, "https://example.com", "s", now)),
424
+ ).not.toContain("payload");
425
+ });
426
+
427
+ it("routes quarantined paths that no traversal, backslash or absolute prefix escapes", () => {
428
+ expect(quarantinedpath("invoice.pdf")).toBe("devthink-quarantine/invoice.pdf");
429
+ expect(quarantinedpath("/absolute/path.bin")).toBe("devthink-quarantine/absolute/path.bin");
430
+ expect(quarantinedpath("../../etc/passwd")).toBe("devthink-quarantine/etc/passwd");
431
+ expect(quarantinedpath("..\\..\\windows\\evil.exe")).toBe("devthink-quarantine/windows/evil.exe");
432
+ expect(quarantinedpath("nested/../inner/./file.bin")).toBe("devthink-quarantine/nested/inner/file.bin");
433
+ expect(quarantinedpath("..")).toBe("devthink-quarantine/");
434
+ expect(quarantinedpath("")).toBe("devthink-quarantine/");
435
+ expect(newquarantine("q1", "../../etc/passwd", "reviewed quarantine", now).path).toBe(
436
+ "devthink-quarantine/etc/passwd",
437
+ );
438
+ });
439
+
440
+ it("maps scan hook verdicts onto quarantine entries and release refs", () => {
441
+ const entry = newquarantine("q1", "invoice.pdf", "reviewed quarantine", now);
442
+ expect(entry).toMatchObject({
443
+ id: "q1",
444
+ path: "devthink-quarantine/invoice.pdf",
445
+ scan: "pending",
446
+ at: now,
447
+ updatedat: now,
448
+ });
449
+ expect(scanresult(entry, "clean", now + 1)).toMatchObject({ scan: "clean", updatedat: now + 1 });
450
+ expect(scanresult(entry, "error", now + 1).scan).toBe("error");
451
+ expect(scanverdictof({ verdict: "clean" })).toBe("clean");
452
+ expect(scanverdictof({ verdict: "flagged" })).toBe("flagged");
453
+ expect(scanverdictof({ verdict: "error" })).toBe("error");
454
+ expect(scanverdictof({ verdict: "weird" })).toBe("pending");
455
+ expect(scanverdictof(null)).toBe("pending");
456
+ expect(scanverdictof("clean")).toBe("pending");
457
+ expect(scanverdictof({})).toBe("pending");
458
+ expect(released(entry, "user-9", now + 2)).toMatchObject({ release: "user-9", updatedat: now + 2 });
459
+ });
460
+
461
+ it("stamps capture filenames that slugs hostile task and step names into safe parts", () => {
462
+ expect(capturefilename({ task: "Order Run", step: "Snap Shot", sequence: 4 }, ".PNG")).toBe(
463
+ "order-run-snap-shot-4.png",
464
+ );
465
+ expect(capturefilename({ task: "../evil", step: "sh/../ot", sequence: 1 }, "png")).toBe("evil-sh-ot-1.png");
466
+ expect(capturefilename({ task: "TÄSK é", step: "!", sequence: 2 }, "png")).toBe("t-sk-capture-2.png");
467
+ expect(capturefilename({ task: "", step: "", sequence: 1 }, "")).toBe("capture-capture-1.png");
468
+ expect(capturefilename({ task: "a", step: "b", sequence: 0 }, "png")).toBe("a-b-0.png");
469
+ const stamped = capturenames({}, "task-1", ["snap", "peek", "snap"], "png");
470
+ expect(stamped.names).toEqual(["task-1-snap-1.png", "task-1-peek-1.png", "task-1-snap-2.png"]);
471
+ expect(stamped.counters).toEqual({ snap: 2, peek: 1 });
472
+ });
473
+
474
+ it("reads namecaptures step lists from options or the plan and sweeps cleanup rules", () => {
475
+ expect(capturesteps({ steps: ["a", " ", 5] }, { steps: [] } as unknown as { steps: toolstep[] })).toEqual(["a"]);
476
+ expect(
477
+ capturesteps({}, { steps: [step("observe", { id: "one", risk: "read" }), step("click", { id: "two" })] }),
478
+ ).toEqual(["one", "two"]);
479
+ expect(referencedartifacts(undefined, [])).toEqual([]);
480
+ const plan = {
481
+ steps: [
482
+ step("attachfile", { id: "af1", value: "invoice.pdf" }),
483
+ step("attachfile", { id: "af2", value: "gone.pdf" }),
484
+ step("attachfile", { id: "af3", value: " " }),
485
+ step("observe", { id: "o1" }),
486
+ ],
487
+ };
488
+ expect(referencedartifacts(plan, ["af1"])).toEqual(["gone.pdf"]);
489
+ const entries: artifactinventoryentry[] = [
490
+ { id: "a0", kind: "export-csv", name: "ancient.csv", size: 100, at: now - 9999 },
491
+ { id: "a1", kind: "export-csv", name: "old.csv", size: 100, at: now - 5000 },
492
+ { id: "a2", kind: "export-csv", name: "new.csv", size: 100, at: now - 1000 },
493
+ { id: "a3", kind: "screenshot", name: "shot.png", size: 100, at: now - 9999 },
494
+ ];
495
+ const rules: cleanuprule[] = [{ age: 2000, kind: "export-csv", keep: "latest" }];
496
+ expect(sweepplan(entries, rules, now, ["a0"]).remove).toEqual([]);
497
+ expect(sweepplan(entries, rules, now, []).remove).toEqual(["a0"]);
498
+ expect(sweepplan(entries, [{ age: 2000, kind: "any", keep: "all" }], now, []).remove).toEqual([]);
499
+ expect(sweepplan(entries, [{ age: 0, kind: "any", keep: "none" }], now, ["shot.png"]).keep).toContain("a3");
500
+ expect(sweepplan([], [{ age: 0, kind: "any", keep: "none" }], now, [])).toEqual({ remove: [], keep: [] });
501
+ });
502
+ });
503
+
504
+ describe("torture: navigation intent, prefetch and deep links", () => {
505
+ it("predicts nav intent from https step values with dedupe and history weighting", () => {
506
+ const steps = [
507
+ step("navigate", { value: "https://example.com/one" }),
508
+ step("navigate", { value: "https://example.com/one" }),
509
+ step("navigate", { value: "https://example.com/two" }),
510
+ step("navigate", { value: "http://insecure.example" }),
511
+ step("navigate", { value: " " }),
512
+ ];
513
+ const visits: urlvisit[] = [
514
+ { url: "https://example.com/two", at: now - 100, runid: "run1" },
515
+ { url: "https://example.com/two", at: now - 50, runid: "run1" },
516
+ ];
517
+ const plan = navintent({ id: "pf1", steps, visits, now });
518
+ expect(plan.predictedurls.map((entry) => entry.url)).toEqual([
519
+ "https://example.com/two",
520
+ "https://example.com/one",
521
+ ]);
522
+ expect(plan.predictedurls[0]?.confidence).toBeGreaterThan(plan.predictedurls[1]?.confidence ?? 0);
523
+ expect(navintent({ id: "pf1", steps: [], now }).predictedurls).toEqual([]);
524
+ expect(() => navintent({ id: " ", steps, now })).toThrow(/needs its id/);
525
+ const bare = navintent({ id: "pf2", steps: [step("navigate", { value: "https://example.com/x" })], now });
526
+ expect(bare.predictedurls[0]?.confidence).toBeGreaterThan(0);
527
+ expect(bare.predictedurls[0]?.confidence).toBeLessThanOrEqual(1);
528
+ });
529
+
530
+ it("warms only the granted origins while a stale plan drops every prediction", () => {
531
+ const warmed = prefetchpage({
532
+ id: "w1",
533
+ planid: "plan1",
534
+ urls: ["https://example.com/a", "https://example.com/a", "https://other.example/b", "not a url"],
535
+ grants: ["https://example.com"],
536
+ now,
537
+ });
538
+ expect(warmed.allowed).toEqual(["https://example.com/a"]);
539
+ expect(warmed.refused).toEqual(["https://other.example/b", "not a url"]);
540
+ expect(warmed.plan.predictedurls).toHaveLength(1);
541
+ const stale = prefetchpage({
542
+ id: "w2",
543
+ planid: "plan2",
544
+ urls: ["https://example.com/a"],
545
+ grants: ["https://example.com"],
546
+ stored: {
547
+ id: "w1",
548
+ planid: "plan1",
549
+ predictedurls: [{ url: "https://example.com/old", confidence: 0.9 }],
550
+ createdat: now,
551
+ },
552
+ now,
553
+ });
554
+ expect(stale.dropped).toEqual(["https://example.com/old"]);
555
+ expect(() => prefetchpage({ id: " ", planid: "p", urls: [], grants: [], now })).toThrow(/needs its id/);
556
+ expect(() => prefetchpage({ id: "w", planid: " ", urls: [], grants: [], now })).toThrow(/names the plan/i);
557
+ expect(prefetchpage({ id: "w", planid: "p", urls: [], grants: [], now }).allowed).toEqual([]);
558
+ });
559
+
560
+ it("preconnects only granted, deduped, non empty origins", () => {
561
+ const result = preconnectorigin({
562
+ origins: ["https://example.com", "https://example.com", " ", "https://other.example"],
563
+ grants: ["https://example.com"],
564
+ now,
565
+ });
566
+ expect(result.targets).toEqual([{ origin: "https://example.com", expectedat: now, connected: true }]);
567
+ expect(result.refused).toEqual(["https://other.example"]);
568
+ expect(preconnectorigin({ origins: [], grants: [], now })).toEqual({ targets: [], refused: [] });
569
+ });
570
+
571
+ it("builds deep links with encoded parameters and refuses unknown apps and half parameters", () => {
572
+ expect(deeplinkapp({ app: "github", params: { owner: "wenathlan", repo: "extension" } }).url).toBe(
573
+ "https://github.com/wenathlan/extension",
574
+ );
575
+ expect(deeplinkapp({ app: "github", params: { owner: "wenathlan" } }).url).toBe("https://github.com/wenathlan");
576
+ expect(deeplinkapp({ app: "youtube", params: { id: "dQw4w9WgXcQ" } }).url).toBe(
577
+ "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
578
+ );
579
+ expect(deeplinkapp({ app: "youtube", params: { search: "dev think" } }).url).toBe(
580
+ "https://www.youtube.com/results?search_query=dev%20think",
581
+ );
582
+ expect(deeplinkapp({ app: "wikipedia", params: { title: "Ünicode" } }).url).toBe(
583
+ "https://en.wikipedia.org/wiki/%C3%9Cnicode",
584
+ );
585
+ expect(deeplinkapp({ app: "maps", params: { query: "a b&c" } }).url).toBe(
586
+ "https://www.google.com/maps/search/a%20b%26c",
587
+ );
588
+ expect(
589
+ deeplinkapp({
590
+ app: "custom",
591
+ params: { p: "v" },
592
+ patterns: [{ app: "custom", origin: "https://custom.example", route: "/{p}", params: ["p"] }],
593
+ }).url,
594
+ ).toBe("https://custom.example/v");
595
+ expect(() =>
596
+ deeplinkapp({
597
+ app: "custom",
598
+ params: {},
599
+ patterns: [{ app: "custom", origin: "https://custom.example", route: "/{p}", params: ["p"] }],
600
+ }),
601
+ ).toThrow(/needs its reviewed parameters/);
602
+ expect(
603
+ deeplinkapp({
604
+ app: "github",
605
+ params: { owner: "wenathlan" },
606
+ patterns: [
607
+ { app: "github", origin: "https://evil.example", route: "/{owner}/{repo}", params: ["owner", "repo"] },
608
+ ],
609
+ }).url,
610
+ ).toBe("https://github.com/wenathlan");
611
+ expect(() => deeplinkapp({ app: "", params: {} })).toThrow(/names its web app/);
612
+ expect(() => deeplinkapp({ app: "nope", params: {} })).toThrow(/not a known web app/);
613
+ });
614
+ });
615
+
616
+ describe("torture: reopening, trails and consent pauses", () => {
617
+ const records: closedtabrecord[] = [
618
+ { id: "c1", url: "https://example.com/a", title: "A", tabid: 1, windowid: 1, closedat: now },
619
+ { id: "c2", url: "https://example.com/b", title: "B", tabid: 2, windowid: 1, closedat: now - 100 },
620
+ { id: "c3", url: "https://other.example/c", title: "C", tabid: 3, windowid: 1, closedat: now - 50 },
621
+ ];
622
+
623
+ it("reopens the most recent fresh record under a grant recheck and refuses replayed records", () => {
624
+ const reopened = reopentab({ records, grants: ["https://example.com"], now: now + 10 });
625
+ expect(reopened.id).toBe("c1");
626
+ expect(reopened.reopenedat).toBe(now + 10);
627
+ const nextfresh = reopentab({
628
+ records: [{ ...records[0]!, reopenedat: now - 5 }, records[1]!, { ...records[2]!, reopenedat: now - 4 }],
629
+ grants: ["https://example.com"],
630
+ now: now + 10,
631
+ });
632
+ expect(nextfresh.id).toBe("c2");
633
+ expect(nextfresh.reopenedat).toBe(now + 10);
634
+ expect(() =>
635
+ reopentab({
636
+ records: [{ ...records[0]!, reopenedat: now - 5 }],
637
+ grants: ["https://example.com"],
638
+ url: "https://example.com/a",
639
+ now,
640
+ }),
641
+ ).toThrow(/already reopened/);
642
+ expect(() => reopentab({ records: [{ ...records[2]! }], grants: ["https://example.com"], now })).toThrow(
643
+ /lost its grant/,
644
+ );
645
+ expect(() => reopentab({ records: [], grants: [], now })).toThrow(/remembers none/);
646
+ const explicit = reopentab({ records, grants: ["https://other.example"], url: "https://other.example/c", now });
647
+ expect(explicit.id).toBe("c3");
648
+ expect(() => reopentab({ records, grants: [], url: "https://example.com/a", now })).toThrow(/lost its grant/);
649
+ expect(() => reopentab({ records, grants: [], url: "https://missing.example/z", now })).toThrow(
650
+ /No closed tab record/,
651
+ );
652
+ });
653
+
654
+ it("restores the navigation trail in visit order folding consecutive duplicates per run", () => {
655
+ const visits: urlvisit[] = [
656
+ { url: "https://example.com/a", at: now + 10, runid: "run1" },
657
+ { url: "https://example.com/b", at: now + 20, runid: "run1" },
658
+ { url: "https://example.com/b", at: now + 30, runid: "run1" },
659
+ { url: "https://example.com/c", at: now + 5, runid: "run2" },
660
+ { url: "https://example.com/a", at: now + 40, runid: "run2" },
661
+ ];
662
+ expect(restoretrail({ visits, runid: "run1" }).map((entry) => entry.url)).toEqual([
663
+ "https://example.com/a",
664
+ "https://example.com/b",
665
+ ]);
666
+ expect(restoretrail({ visits, runid: "run2" }).map((entry) => entry.url)).toEqual([
667
+ "https://example.com/c",
668
+ "https://example.com/a",
669
+ ]);
670
+ expect(restoretrail({ visits }).map((entry) => entry.runid)).toEqual([undefined, undefined, undefined, undefined]);
671
+ expect(restoretrail({ visits: [], runid: "run1" })).toEqual([]);
672
+ const ties: urlvisit[] = [
673
+ { url: "https://b.example", at: now, runid: "r" },
674
+ { url: "https://a.example", at: now, runid: "r" },
675
+ ];
676
+ expect(restoretrail({ visits: ties }).map((entry) => entry.url)).toEqual([
677
+ "https://a.example",
678
+ "https://b.example",
679
+ ]);
680
+ });
681
+
682
+ it("freezes navigation behind a consent prompt and hands the queued navigation back on resume", () => {
683
+ const paused = pausenavconsent({
684
+ reason: "a payment consent is open",
685
+ url: "https://example.com/pay",
686
+ stepid: "s9",
687
+ now,
688
+ });
689
+ expect(paused).toMatchObject({
690
+ pausedat: now,
691
+ reason: "a payment consent is open",
692
+ pendingurl: "https://example.com/pay",
693
+ pendingstepid: "s9",
694
+ });
695
+ const queued = pausenavconsent({ url: "https://example.com/next", stored: paused, now: now + 100 });
696
+ expect(queued.pausedat).toBe(now);
697
+ expect(queued.pendingurl).toBe("https://example.com/next");
698
+ const resumed = resumenavconsent({ stored: queued, now: now + 200 });
699
+ expect(resumed).toEqual({ resumed: true, queued });
700
+ expect(resumenavconsent({ now }).resumed).toBe(false);
701
+ expect(pausenavconsent({ now }).reason).toMatch(/consent prompt is open/);
702
+ });
703
+ });
704
+
705
+ describe("torture: navigation rate windows at their exact boundaries", () => {
706
+ it("counts with no configured window and ceiling while the sliding window ages hits exactly at the boundary", () => {
707
+ const manual = navratelimit({ url: "https://example.com/a", now });
708
+ expect(manual.allowed).toBe(true);
709
+ expect(manual.window.count).toBe(1);
710
+ expect(manual.window.window).toBeUndefined();
711
+ const boundary = navratelimit({
712
+ stored: { domain: "example.com", count: 2, resetat: now, hits: [now - 1000], window: 1000, ceiling: 2 },
713
+ url: "https://example.com/a",
714
+ now,
715
+ });
716
+ expect(boundary.allowed).toBe(true);
717
+ expect(boundary.window.count).toBe(1);
718
+ const onebefore = navratelimit({
719
+ stored: { domain: "example.com", count: 2, resetat: now, hits: [now - 1, now - 1], window: 1000, ceiling: 2 },
720
+ url: "https://example.com/a",
721
+ now,
722
+ });
723
+ expect(onebefore.allowed).toBe(false);
724
+ expect(onebefore.waitms).toBe(999);
725
+ expect(onebefore.reason).toMatch(/waits 999 milliseconds/);
726
+ const blocked = navratelimit({
727
+ stored: { domain: "example.com", count: 2, resetat: now, hits: [now - 500, now - 250], window: 1000, ceiling: 2 },
728
+ url: "https://example.com/a",
729
+ now,
730
+ });
731
+ expect(blocked.allowed).toBe(false);
732
+ expect(blocked.waitms).toBe(500);
733
+ expect(blocked.window.count).toBe(2);
734
+ const single = navratelimit({
735
+ stored: { domain: "example.com", count: 1, resetat: now, hits: [now - 250], window: 1000, ceiling: 1 },
736
+ url: "https://example.com/a",
737
+ now,
738
+ });
739
+ expect(single.allowed).toBe(false);
740
+ expect(single.reason).toMatch(/1 navigation/);
741
+ expect(() => navratelimit({ url: "not a url", now })).toThrow(/needs its url/);
742
+ expect(navratelimit({ url: "https://EXAMPLE.com/a", now }).window.domain).toBe("example.com");
743
+ });
744
+
745
+ it("opens clipboard urls only when https, parseable and granted", () => {
746
+ expect(openclipboardurl({ text: "https://example.com/notes", grants: ["https://example.com"] }).url).toBe(
747
+ "https://example.com/notes",
748
+ );
749
+ expect(() => openclipboardurl({ text: " not a url ", grants: [] })).toThrow(/no valid url/);
750
+ expect(() => openclipboardurl({ text: "http://example.com/notes", grants: ["http://example.com"] })).toThrow(
751
+ /HTTPS/,
752
+ );
753
+ expect(() => openclipboardurl({ text: "ftp://example.com/f", grants: [] })).toThrow(/HTTPS/);
754
+ expect(() => openclipboardurl({ text: "https://other.example/x", grants: ["https://example.com"] })).toThrow(
755
+ /outside the session grants/,
756
+ );
757
+ });
758
+ });
759
+
760
+ describe("torture: url safety with lookalikes, homographs and scheme tricks", () => {
761
+ it("refuses lookalike hosts that imitate granted origins", () => {
762
+ const granted = ["https://example.com"];
763
+ expect(checksafeurl({ url: "https://sub.example.com/x", granted, now }).safe).toBe(true);
764
+ expect(checksafeurl({ url: "https://example.com.evil.com/", granted, now }).safe).toBe(false);
765
+ expect(checksafeurl({ url: "https://example.com.evil.com/", granted, now }).reasons.join(" ")).toContain(
766
+ "imitates the granted origin",
767
+ );
768
+ expect(checksafeurl({ url: "https://evil-example.com/", granted, now }).safe).toBe(false);
769
+ expect(checksafeurl({ url: "https://notexample.com/", granted, now }).safe).toBe(false);
770
+ expect(checksafeurl({ url: "https://example.com/", granted, now }).safe).toBe(true);
771
+ expect(checksafeurl({ url: "https://example.com/", granted: ["https://sub.example.com"], now }).safe).toBe(true);
772
+ });
773
+
774
+ it("refuses punycode and unicode homograph hosts", () => {
775
+ expect(checksafeurl({ url: "https://xn--80ak6aa92e.com/", granted: [], now }).reasons.join(" ")).toContain(
776
+ "punycode",
777
+ );
778
+ expect(checksafeurl({ url: "https://аpple.com/", granted: ["https://apple.com"], now }).safe).toBe(false);
779
+ expect(
780
+ checksafeurl({ url: "https://аpple.com/", granted: ["https://apple.com"], now }).reasons.join(" "),
781
+ ).toContain("punycode");
782
+ });
783
+
784
+ it("refuses weak schemes, embedded credentials, private and raw hosts, and unparseable urls", () => {
785
+ expect(checksafeurl({ url: "http://example.com/", granted: [], now }).reasons).toContain("the url must use HTTPS");
786
+ expect(checksafeurl({ url: "data:text/html;base64,PHNjcmlwdD4=", granted: [], now }).safe).toBe(false);
787
+ expect(checksafeurl({ url: "blob:https://example.com/x", granted: [], now }).safe).toBe(false);
788
+ expect(checksafeurl({ url: "file:///etc/passwd", granted: [], now }).safe).toBe(false);
789
+ expect(checksafeurl({ url: "https://user:pass@example.com/", granted: [], now }).reasons.join(" ")).toContain(
790
+ "embedded credentials",
791
+ );
792
+ expect(checksafeurl({ url: "https://localhost/app", granted: [], now }).reasons.join(" ")).toContain(
793
+ "private network",
794
+ );
795
+ expect(checksafeurl({ url: "https://127.0.0.1/app", granted: [], now }).reasons.join(" ")).toContain(
796
+ "private network",
797
+ );
798
+ expect(checksafeurl({ url: "https://10.1.2.3/", granted: [], now }).reasons.join(" ")).toContain("private network");
799
+ expect(checksafeurl({ url: "https://192.168.0.9/", granted: [], now }).reasons.join(" ")).toContain(
800
+ "private network",
801
+ );
802
+ expect(checksafeurl({ url: "https://172.16.0.1/", granted: [], now }).reasons.join(" ")).toContain(
803
+ "private network",
804
+ );
805
+ expect(checksafeurl({ url: "https://172.99.0.1/", granted: [], now }).reasons.join(" ")).toContain("raw address");
806
+ expect(checksafeurl({ url: "https://[::1]/", granted: [], now }).reasons.join(" ")).toContain("private network");
807
+ expect(checksafeurl({ url: "https://8.8.8.8/", granted: [], now }).reasons.join(" ")).toContain("raw address");
808
+ expect(checksafeurl({ url: "not a url at all", granted: [], now })).toMatchObject({
809
+ safe: false,
810
+ reasons: ["the url does not parse"],
811
+ });
812
+ expect(checksafeurl({ url: "https://example.com/", granted: ["not a url"], now }).safe).toBe(true);
813
+ });
814
+ });
815
+
816
+ describe("torture: curated batch opening with size bounds and full rate windows", () => {
817
+ it("refuses the whole batch when one url is unsafe and never opens a tab", () => {
818
+ const batch = batchopenlinks({
819
+ id: "b1",
820
+ urls: ["https://example.com/a", "https://example.com.evil.com/"],
821
+ grants: ["https://example.com"],
822
+ windows: [],
823
+ now,
824
+ });
825
+ expect(batch.open).toEqual([]);
826
+ expect(batch.ordered).toEqual([]);
827
+ expect(batch.waits).toEqual([]);
828
+ expect(batch.refused).toHaveLength(1);
829
+ expect(batch.refused[0]?.reasons.join(" ")).toContain("imitates");
830
+ expect(batch.reason).toMatch(/refuses as a whole/);
831
+ expect(batch.batch.reviewedat).toBeUndefined();
832
+ expect(() => batchopenlinks({ id: " ", urls: [], grants: [], windows: [], now })).toThrow(/needs its id/);
833
+ });
834
+
835
+ it("refuses a batch that passes the user ceiling without a code cap", () => {
836
+ expect(() =>
837
+ batchopenlinks({
838
+ id: "b2",
839
+ urls: ["https://example.com/a", "https://example.com/b"],
840
+ grants: ["https://example.com"],
841
+ windows: [],
842
+ now,
843
+ sizelimit: 1,
844
+ }),
845
+ ).toThrow(/passes the user configured ceiling/);
846
+ expect(
847
+ batchopenlinks({
848
+ id: "b3",
849
+ urls: ["https://example.com/a", "https://example.com/b"],
850
+ grants: ["https://example.com"],
851
+ windows: [],
852
+ now,
853
+ sizelimit: 2,
854
+ }).open,
855
+ ).toHaveLength(2);
856
+ expect(batchopenlinks({ id: "b4", urls: [], grants: [], windows: [], now, sizelimit: 1 }).open).toEqual([]);
857
+ });
858
+
859
+ it("moves urls onto waits when the per domain window is full instead of dropping them", () => {
860
+ const full: ratelimitwindow = {
861
+ domain: "example.com",
862
+ count: 2,
863
+ resetat: now + 500,
864
+ hits: [now - 400, now - 300],
865
+ window: 1000,
866
+ ceiling: 2,
867
+ };
868
+ const batch = batchopenlinks({
869
+ id: "b5",
870
+ urls: ["https://example.com/a", "https://example.com/b", "https://other.example/c"],
871
+ grants: ["https://example.com", "https://other.example"],
872
+ windows: [full],
873
+ now,
874
+ window: 1000,
875
+ });
876
+ expect(batch.open.map((entry) => entry.url)).toEqual(["https://other.example/c"]);
877
+ expect(batch.waits).toEqual([
878
+ { url: "https://example.com/a", waitms: 600 },
879
+ { url: "https://example.com/b", waitms: 600 },
880
+ ]);
881
+ expect(batch.reason).toMatch(/never drops silently/);
882
+ expect(batch.windows.find((window) => window.domain === "example.com")?.count).toBe(2);
883
+ });
884
+
885
+ it("opens a thousand curated links with one tab per link under no ceiling", () => {
886
+ const urls = Array.from({ length: 1000 }, (_, index) => `https://example.com/item/${index}`);
887
+ const started = Date.now();
888
+ const batch = batchopenlinks({ id: "b6", urls, grants: ["https://example.com"], windows: [], now });
889
+ expect(batch.open).toHaveLength(1000);
890
+ expect(batch.ordered).toHaveLength(1000);
891
+ expect(batch.waits).toEqual([]);
892
+ expect(new Set(batch.windows.map((window) => window.domain))).toEqual(new Set(["example.com"]));
893
+ expect(Date.now() - started).toBeLessThan(2000);
894
+ });
895
+ });