@wenathlan/devthink 2.0.15 → 2.0.19
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.
- package/CHANGELOG.md +45 -0
- package/{dist/bridge.d.ts → bridge.d.ts} +1 -1
- package/bridge.d.ts.map +1 -0
- package/bridge.js +1877 -0
- package/bun.d.ts.map +1 -0
- package/bun.js +52329 -0
- package/caps/background.json +712 -0
- package/caps/cli.json +360 -0
- package/caps/library.json +3611 -0
- package/caps/mcp.json +126 -0
- package/caps/pagebridge.json +377 -0
- package/caps/popup.json +51 -0
- package/caps/sidepanel.json +522 -0
- package/checksums.txt +142 -0
- package/cli.d.ts.map +1 -0
- package/{dist/cli.js → cli.js} +2 -2
- package/companion.d.ts.map +1 -0
- package/companion.js +389 -0
- package/crossbrowser.d.ts.map +1 -0
- package/crossbrowser.js +1191 -0
- package/dashdone.d.ts.map +1 -0
- package/dashdone.js +368 -0
- package/deno.d.ts.map +1 -0
- package/deno.js +52325 -0
- package/devthink.umd.js +52346 -0
- package/fixtures/bun.ts +7 -0
- package/fixtures/cjs.js +6 -0
- package/fixtures/deno.ts +6 -0
- package/fixtures/example-org-pagestate.json +22 -0
- package/fixtures/importers/automa-workflow.json +18 -0
- package/fixtures/importers/selenium-side.json +20 -0
- package/fixtures/importers/tabular-plan.csv +7 -0
- package/fixtures/importers/uivision-macro.json +10 -0
- package/fixtures/importers/v1-plan.json +13 -0
- package/fixtures/mcp-client.mjs +14 -0
- package/fixtures/pages/checkout.html +192 -0
- package/fixtures/pages/dashboard.html +110 -0
- package/fixtures/pages/feed.html +113 -0
- package/fixtures/pages/product-grid.html +150 -0
- package/fixtures/plans/form-inventory-plan.json +11 -0
- package/fixtures/plans/release-notes-plan.json +11 -0
- package/fixtures/recipes/agentscompete.json +11 -0
- package/fixtures/recipes/agentsforms.json +11 -0
- package/fixtures/recipes/agentsmonitor.json +11 -0
- package/fixtures/recipes/agentsreview.json +29 -0
- package/fixtures/recipes/agentswarm.json +11 -0
- package/fixtures/recipes/fillcalendar.json +12 -0
- package/fixtures/recipes/fillcheckout.json +13 -0
- package/fixtures/recipes/filldependentdropdowns.json +12 -0
- package/fixtures/recipes/fillfromcsv.json +13 -0
- package/fixtures/recipes/fillloginform.json +12 -0
- package/fixtures/recipes/fillmultistepwizard.json +13 -0
- package/fixtures/recipes/fillregistration.json +12 -0
- package/fixtures/recipes/fillsearchfilters.json +12 -0
- package/fixtures/recipes/filltypeahead.json +11 -0
- package/fixtures/recipes/monitoralerts.json +12 -0
- package/fixtures/recipes/monitoravailability.json +11 -0
- package/fixtures/recipes/monitornetworkquiet.json +12 -0
- package/fixtures/recipes/monitorpagechanges.json +11 -0
- package/fixtures/recipes/monitorpricechange.json +11 -0
- package/fixtures/recipes/monitorschedule.json +12 -0
- package/fixtures/recipes/scrapedynamicprices.json +13 -0
- package/fixtures/recipes/scrapeimagegallery.json +12 -0
- package/fixtures/recipes/scrapeinfinitefeed.json +13 -0
- package/fixtures/recipes/scrapenestedlists.json +12 -0
- package/fixtures/recipes/scrapeproductgrid.json +12 -0
- package/fixtures/recipes/scrapereviews.json +12 -0
- package/fixtures/recipes/scrapesearchresults.json +12 -0
- package/fixtures/recipes/scrapetablepagination.json +12 -0
- package/fixtures/recipes/testaccessibility.json +34 -0
- package/fixtures/recipes/testconsoleerrors.json +12 -0
- package/fixtures/recipes/testdeeplinks.json +12 -0
- package/fixtures/recipes/testformvalidation.json +13 -0
- package/fixtures/recipes/testlayoutshift.json +12 -0
- package/fixtures/recipes/testlinkcheck.json +12 -0
- package/fixtures/recipes/testloadtiming.json +12 -0
- package/fixtures/recipes/testvisualdiff.json +12 -0
- package/fixtures/workflows/changelog-digest-workflow.json +13 -0
- package/fixtures/workflows/form-survey-workflow.json +13 -0
- package/gallery.json +706 -0
- package/hardening.d.ts.map +1 -0
- package/hardening.js +188 -0
- package/headless.d.ts.map +1 -0
- package/headless.js +11522 -0
- package/http.d.ts.map +1 -0
- package/http.js +2165 -0
- package/index.cjs +54682 -0
- package/index.d.ts.map +1 -0
- package/index.js +52310 -0
- package/index.neutral.js +46343 -0
- package/{web/manifest.json → manifest.json} +1 -1
- package/mcp.d.ts.map +1 -0
- package/mcp.js +20515 -0
- package/memory.d.ts.map +1 -0
- package/{memory.ts → memory.js} +2310 -3834
- package/nativehost.template.json +10 -0
- package/node.cjs +54686 -0
- package/node.d.ts.map +1 -0
- package/pack.d.ts.map +1 -0
- package/pack.js +805 -0
- package/package.json +83 -176
- package/policy.d.ts.map +1 -0
- package/{policy.ts → policy.js} +4679 -5073
- package/progress.d.ts.map +1 -0
- package/progress.js +645 -0
- package/protocol.d.ts.map +1 -0
- package/protocol.js +8334 -0
- package/schemas/audit.schema.json +226 -0
- package/schemas/capability.schema.json +113 -0
- package/schemas/envelope.schema.json +162 -0
- package/schemas/memory.schema.json +51 -0
- package/schemas/observation.schema.json +113 -0
- package/schemas/plan.schema.json +208 -0
- package/schemas/progress.schema.json +126 -0
- package/schemas/proposal.schema.json +68 -0
- package/schemas/session.schema.json +82 -0
- package/schemas/tool.schema.json +94 -0
- package/server.d.ts.map +1 -0
- package/server.js +28877 -0
- package/umd-example.html +18 -0
- package/umd.d.ts.map +1 -0
- package/accounts.ts +0 -2087
- package/agent.ts +0 -2331
- package/antigravity.ts +0 -2139
- package/apifreeze.ts +0 -4146
- package/auth.ts +0 -642
- package/background.ts +0 -16837
- package/bridge.ts +0 -2080
- package/build.ts +0 -54
- package/bun.ts +0 -26
- package/capture.ts +0 -1614
- package/checksecrets.ts +0 -72
- package/cjs.ts +0 -9
- package/cli.ts +0 -3500
- package/commands.ts +0 -1101
- package/companion.ts +0 -450
- package/compatibility.ts +0 -37
- package/config.ts +0 -3137
- package/constants.ts +0 -943
- package/core.ts +0 -1473
- package/crossbrowser.ts +0 -1359
- package/dashdone.ts +0 -605
- package/data.ts +0 -943
- package/database.ts +0 -133
- package/debug.ts +0 -850
- package/deno.ts +0 -27
- package/devthink.ts +0 -707
- package/dist/accounts.d.ts +0 -409
- package/dist/agent.d.ts +0 -837
- package/dist/antigravity.d.ts +0 -380
- package/dist/apifreeze.d.ts +0 -113
- package/dist/auth.d.ts +0 -224
- package/dist/capture.d.ts +0 -595
- package/dist/cjs.d.ts +0 -6
- package/dist/commands.d.ts +0 -310
- package/dist/compatibility.d.ts +0 -17
- package/dist/config.d.ts +0 -1853
- package/dist/constants.d.ts +0 -637
- package/dist/core.d.ts +0 -361
- package/dist/data.d.ts +0 -330
- package/dist/database.d.ts +0 -24
- package/dist/debug.d.ts +0 -270
- package/dist/engine.d.ts +0 -74
- package/dist/environments.d.ts +0 -244
- package/dist/evidence.d.ts +0 -277
- package/dist/export.d.ts +0 -311
- package/dist/fingerprint.d.ts +0 -594
- package/dist/flow.d.ts +0 -300
- package/dist/gates.d.ts +0 -103
- package/dist/identity.d.ts +0 -51
- package/dist/ids.d.ts +0 -7
- package/dist/llm.d.ts +0 -652
- package/dist/models.d.ts +0 -1807
- package/dist/net.d.ts +0 -325
- package/dist/neutral.d.ts +0 -41
- package/dist/oauth.d.ts +0 -703
- package/dist/page.d.ts +0 -1166
- package/dist/perf.d.ts +0 -481
- package/dist/plan.d.ts +0 -134
- package/dist/project.d.ts +0 -395
- package/dist/providers.d.ts +0 -37
- package/dist/quota.d.ts +0 -453
- package/dist/recovery.d.ts +0 -621
- package/dist/request.d.ts +0 -1492
- package/dist/run.d.ts +0 -779
- package/dist/runtime.d.ts +0 -212
- package/dist/search.d.ts +0 -375
- package/dist/security.d.ts +0 -534
- package/dist/serve.d.ts +0 -136
- package/dist/session.d.ts +0 -296
- package/dist/storage.d.ts +0 -53
- package/dist/streaming.d.ts +0 -1119
- package/dist/swarm.d.ts +0 -328
- package/dist/tools.d.ts +0 -170
- package/dist/types.d.ts +0 -8357
- package/dist/utils.d.ts +0 -82
- package/dist/version.d.ts +0 -7
- package/dist/versionregistry.d.ts +0 -406
- package/dist/views.d.ts +0 -579
- package/dist/workbenchsession.d.ts +0 -69
- package/dist/workflow.d.ts +0 -649
- package/docs/readme.md +0 -92
- package/docs/schemas/antigravity.json +0 -192
- package/engine.ts +0 -1524
- package/environments.ts +0 -1005
- package/evidence.ts +0 -643
- package/export.ts +0 -889
- package/fingerprint.ts +0 -1458
- package/flow.ts +0 -1190
- package/gates.ts +0 -307
- package/gateway.ts +0 -34
- package/hardening.ts +0 -191
- package/headless.ts +0 -369
- package/http.ts +0 -2110
- package/identity.ts +0 -246
- package/ids.ts +0 -26
- package/index.ts +0 -369
- package/llm.ts +0 -2682
- package/mcp.ts +0 -1835
- package/models.ts +0 -3805
- package/modes.ts +0 -43
- package/net.ts +0 -1214
- package/neutral.ts +0 -362
- package/node.ts +0 -26
- package/oauth.ts +0 -2216
- package/offscreen.ts +0 -170
- package/pack.ts +0 -956
- package/page.ts +0 -7824
- package/pagebridge.ts +0 -1116
- package/perf.ts +0 -957
- package/plan.ts +0 -672
- package/plugin.ts +0 -76
- package/prisma.config.ts +0 -27
- package/progress.ts +0 -1308
- package/project.ts +0 -1291
- package/protocol.ts +0 -4187
- package/providers.ts +0 -246
- package/quota.ts +0 -1887
- package/recovery.ts +0 -2433
- package/request.ts +0 -4482
- package/run.ts +0 -2135
- package/runtime.ts +0 -526
- package/search.ts +0 -1760
- package/security.ts +0 -1673
- package/serve.ts +0 -419
- package/server.ts +0 -5538
- package/session.ts +0 -1162
- package/storage.ts +0 -182
- package/streaming.ts +0 -4101
- package/swarm.ts +0 -884
- package/sync.ts +0 -56
- package/tests/agentcert.test.ts +0 -128
- package/tests/agentfleet.test.ts +0 -214
- package/tests/agentreview.test.ts +0 -241
- package/tests/agentstream.test.ts +0 -335
- package/tests/agentwork.test.ts +0 -356
- package/tests/apifreeze.test.ts +0 -290
- package/tests/apimap.test.ts +0 -112
- package/tests/approvalgate.test.ts +0 -175
- package/tests/artifactmanifest.test.ts +0 -204
- package/tests/attentionfeed.test.ts +0 -163
- package/tests/backgroundruns.test.ts +0 -100
- package/tests/batchscheduling.test.ts +0 -131
- package/tests/blackboard.test.ts +0 -238
- package/tests/bridge.test.ts +0 -1088
- package/tests/browsercoverage.test.ts +0 -134
- package/tests/browserpolyfills.test.ts +0 -124
- package/tests/build.mjs +0 -1260
- package/tests/clientauth.test.ts +0 -223
- package/tests/clitools.test.ts +0 -578
- package/tests/confirmgates.test.ts +0 -190
- package/tests/containerpack.test.ts +0 -143
- package/tests/controlflow.test.ts +0 -2120
- package/tests/coordination.test.ts +0 -345
- package/tests/copyscreen.test.ts +0 -139
- package/tests/core.test.ts +0 -417
- package/tests/costcert.test.ts +0 -95
- package/tests/crossbrowser.test.ts +0 -115
- package/tests/cspaudit.test.ts +0 -79
- package/tests/dashdone.test.ts +0 -615
- package/tests/datagrid.test.ts +0 -137
- package/tests/doccheck.test.ts +0 -107
- package/tests/dombatch.test.ts +0 -109
- package/tests/emulation.test.ts +0 -282
- package/tests/environments.test.ts +0 -259
- package/tests/evidenceviews.test.ts +0 -88
- package/tests/exporttools.test.ts +0 -185
- package/tests/firefoxprep.test.ts +0 -134
- package/tests/flowlibrary.test.ts +0 -242
- package/tests/flowrun.test.ts +0 -303
- package/tests/forensics.test.ts +0 -439
- package/tests/gateway.test.ts +0 -939
- package/tests/headlesslib.test.ts +0 -171
- package/tests/httpstream.test.ts +0 -277
- package/tests/immutablelog.test.ts +0 -157
- package/tests/inboundguard.test.ts +0 -177
- package/tests/lazyload.test.ts +0 -72
- package/tests/librarymodes.test.ts +0 -623
- package/tests/llm.test.ts +0 -696
- package/tests/manifest.test.ts +0 -226
- package/tests/maskinputs.test.ts +0 -150
- package/tests/matrixverify.test.ts +0 -111
- package/tests/mavenpack.test.ts +0 -75
- package/tests/mcpserver.test.ts +0 -704
- package/tests/memory.test.ts +0 -4155
- package/tests/memorycare.test.ts +0 -230
- package/tests/migrateplan.test.ts +0 -349
- package/tests/minimization.test.ts +0 -414
- package/tests/modelroute.test.ts +0 -112
- package/tests/multiagent.test.ts +0 -440
- package/tests/nativebridge.test.ts +0 -807
- package/tests/navigation.test.ts +0 -284
- package/tests/nugetpack.test.ts +0 -83
- package/tests/orchestration.test.ts +0 -449
- package/tests/originpolicy.test.ts +0 -405
- package/tests/outputcompare.test.ts +0 -97
- package/tests/package.test.ts +0 -91
- package/tests/pagebridge.test.ts +0 -5909
- package/tests/pentest.test.ts +0 -75
- package/tests/perfrecords.test.ts +0 -257
- package/tests/permdiff.test.ts +0 -85
- package/tests/phishguard.test.ts +0 -128
- package/tests/pickerviews.test.ts +0 -155
- package/tests/pipelines.test.ts +0 -381
- package/tests/planlint.test.ts +0 -240
- package/tests/planreview.test.ts +0 -383
- package/tests/platformtargets.test.ts +0 -56
- package/tests/policy.test.ts +0 -8284
- package/tests/portability.test.ts +0 -96
- package/tests/progress.test.ts +0 -1036
- package/tests/promptlibrary.test.ts +0 -116
- package/tests/protocol.test.ts +0 -4793
- package/tests/publishingpipeline.test.ts +0 -314
- package/tests/quickactions.test.ts +0 -164
- package/tests/readiness.test.ts +0 -78
- package/tests/recipes.test.ts +0 -163
- package/tests/redactshots.test.ts +0 -216
- package/tests/registernvidiakeys.ts +0 -51
- package/tests/relayserve.test.ts +0 -304
- package/tests/releasenotes.test.ts +0 -276
- package/tests/resilience.test.ts +0 -467
- package/tests/resourceaware.test.ts +0 -187
- package/tests/runbudget.test.ts +0 -125
- package/tests/runhistory.test.ts +0 -299
- package/tests/runreplay.test.ts +0 -113
- package/tests/runresume.test.ts +0 -184
- package/tests/runstate.test.ts +0 -288
- package/tests/runtimeadapters.test.ts +0 -251
- package/tests/safariskeleton.test.ts +0 -115
- package/tests/sandboxframe.test.ts +0 -196
- package/tests/sbom.test.ts +0 -105
- package/tests/secretvault.test.ts +0 -188
- package/tests/selcache.test.ts +0 -111
- package/tests/sessioninterface.test.ts +0 -791
- package/tests/sessions.test.ts +0 -591
- package/tests/siteprefs.test.ts +0 -228
- package/tests/snapshotdelta.test.ts +0 -165
- package/tests/statusviews.test.ts +0 -237
- package/tests/stepmeter.test.ts +0 -200
- package/tests/streamparse.test.ts +0 -163
- package/tests/stylepruning.test.ts +0 -90
- package/tests/surfaces.test.ts +0 -282
- package/tests/sweep.test.ts +0 -78
- package/tests/syncbridge.test.ts +0 -164
- package/tests/taskqueue.test.ts +0 -206
- package/tests/toolcalls.test.ts +0 -336
- package/tests/toolcatalog.test.ts +0 -201
- package/tests/torture-agent.test.ts +0 -706
- package/tests/torture-auth.test.ts +0 -461
- package/tests/torture-commands.test.ts +0 -895
- package/tests/torture-data.test.ts +0 -923
- package/tests/torture-environments.test.ts +0 -285
- package/tests/torture-export.test.ts +0 -263
- package/tests/torture-http.test.ts +0 -1379
- package/tests/torture-llm.test.ts +0 -808
- package/tests/torture-memory.test.ts +0 -1084
- package/tests/torture-plan.test.ts +0 -829
- package/tests/torture-run.test.ts +0 -626
- package/tests/torture-session.test.ts +0 -928
- package/tests/torture-swarm.test.ts +0 -1245
- package/tests/torture-tools.test.ts +0 -964
- package/tests/torture-workflow.test.ts +0 -2354
- package/tests/tourviews.test.ts +0 -52
- package/tests/transparency.test.ts +0 -147
- package/tests/trigger.test.ts +0 -941
- package/tests/v1sunset.test.ts +0 -428
- package/tests/virtlist.test.ts +0 -94
- package/tests/vision.test.ts +0 -540
- package/tests/vsixpack.test.ts +0 -145
- package/tests/webapi.test.ts +0 -523
- package/tests/workflow.test.ts +0 -1785
- package/tests/workfloweditor.test.ts +0 -759
- package/tests/xpipack.test.ts +0 -128
- package/tools.ts +0 -734
- package/types.ts +0 -9908
- package/umd.ts +0 -9
- package/utils.ts +0 -249
- package/version.ts +0 -8
- package/versionregistry.ts +0 -1310
- package/views.ts +0 -2153
- package/vitest.config.ts +0 -12
- package/web/App.tsx +0 -78
- package/web/README.md +0 -47
- package/web/capacitor.config.ts +0 -46
- package/web/const.ts +0 -19
- package/web/control.shell.tsx +0 -66
- package/web/dashboardpage.ts +0 -554
- package/web/db.ts +0 -493
- package/web/design.html +0 -541
- package/web/gatewayview/Gateway.tsx +0 -345
- package/web/gatewayview/config.ts +0 -1042
- package/web/gatewayview/definition.ts +0 -174
- package/web/icons.ts +0 -15
- package/web/optionspage.ts +0 -691
- package/web/popup.ts +0 -1651
- package/web/schema.prisma +0 -176
- package/web/sidepanel.ts +0 -7941
- package/web/sitemanifest.json +0 -13
- package/web/terminal-ui.tsx +0 -622
- package/web/transparencypage.ts +0 -541
- package/web/vite.config.ts +0 -39
- package/web/workspace.ts +0 -23
- package/workbenchmemory.ts +0 -104
- package/workbenchsession.ts +0 -304
- package/workflow.ts +0 -4495
- /package/{dist/bun.d.ts → bun.d.ts} +0 -0
- /package/{dist/cli.d.ts → cli.d.ts} +0 -0
- /package/{dist/companion.d.ts → companion.d.ts} +0 -0
- /package/{dist/crossbrowser.d.ts → crossbrowser.d.ts} +0 -0
- /package/{dist/dashdone.d.ts → dashdone.d.ts} +0 -0
- /package/{dist/deno.d.ts → deno.d.ts} +0 -0
- /package/{dist/hardening.d.ts → hardening.d.ts} +0 -0
- /package/{dist/headless.d.ts → headless.d.ts} +0 -0
- /package/{dist/http.d.ts → http.d.ts} +0 -0
- /package/{dist/index.d.ts → index.d.ts} +0 -0
- /package/{dist/mcp.d.ts → mcp.d.ts} +0 -0
- /package/{dist/memory.d.ts → memory.d.ts} +0 -0
- /package/{dist/node.d.ts → node.d.ts} +0 -0
- /package/{dist/pack.d.ts → pack.d.ts} +0 -0
- /package/{dist/policy.d.ts → policy.d.ts} +0 -0
- /package/{dist/progress.d.ts → progress.d.ts} +0 -0
- /package/{dist/protocol.d.ts → protocol.d.ts} +0 -0
- /package/{dist/server.d.ts → server.d.ts} +0 -0
- /package/{dist/umd.d.ts → umd.d.ts} +0 -0
|
@@ -1,895 +0,0 @@
|
|
|
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
|
-
});
|