@wenathlan/devthink 2.0.14 → 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 +60 -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
package/tests/trigger.test.ts
DELETED
|
@@ -1,941 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { composeworkflow, newworkflowrun, workflowstepof } from "../workflow.js";
|
|
3
|
-
import {
|
|
4
|
-
applycooldown,
|
|
5
|
-
armrule,
|
|
6
|
-
confirmmanualrun,
|
|
7
|
-
cronnext,
|
|
8
|
-
cronparse,
|
|
9
|
-
defaulttriggercooldown,
|
|
10
|
-
drainqueue,
|
|
11
|
-
evaluatetrigger,
|
|
12
|
-
eventrulematches,
|
|
13
|
-
listdue,
|
|
14
|
-
manualpreview,
|
|
15
|
-
matchurl,
|
|
16
|
-
observeevents,
|
|
17
|
-
pauseall,
|
|
18
|
-
queuefire,
|
|
19
|
-
resumeall,
|
|
20
|
-
ruleoriginsgranted,
|
|
21
|
-
runurllist,
|
|
22
|
-
schedulecron,
|
|
23
|
-
scheduleinterval,
|
|
24
|
-
timezonevalid,
|
|
25
|
-
triggereventcatalog,
|
|
26
|
-
triggerfamilyof,
|
|
27
|
-
triggerkinds,
|
|
28
|
-
triggersummary,
|
|
29
|
-
updaterule,
|
|
30
|
-
verifywebhook,
|
|
31
|
-
visitmatch,
|
|
32
|
-
webhooksecretok,
|
|
33
|
-
} from "../workflow.js";
|
|
34
|
-
import {
|
|
35
|
-
actionrisk,
|
|
36
|
-
canexecute,
|
|
37
|
-
isworkflowkind,
|
|
38
|
-
istriggeraction,
|
|
39
|
-
triggergate,
|
|
40
|
-
triggerorigins,
|
|
41
|
-
validatestep,
|
|
42
|
-
} from "../policy.js";
|
|
43
|
-
import { manualrunpreview, outcomeresponse, parseproposal, triggerfired, triggerlist } from "../protocol.js";
|
|
44
|
-
import { protocolversion } from "../types.js";
|
|
45
|
-
import { recordtrigger, triggerevidences } from "../progress.js";
|
|
46
|
-
import { sessionmemory } from "../memory.js";
|
|
47
|
-
import type {
|
|
48
|
-
agentplan,
|
|
49
|
-
agentsession,
|
|
50
|
-
manualrun,
|
|
51
|
-
toolstep,
|
|
52
|
-
triggerfire,
|
|
53
|
-
triggerule,
|
|
54
|
-
workflowrecord,
|
|
55
|
-
} from "../types.js";
|
|
56
|
-
|
|
57
|
-
const now = 1_800_000_000_000;
|
|
58
|
-
const session: agentsession = {
|
|
59
|
-
id: "sess",
|
|
60
|
-
tabid: 4,
|
|
61
|
-
origin: "https://example.com",
|
|
62
|
-
startedat: now - 1000,
|
|
63
|
-
expiresat: now + 600_000,
|
|
64
|
-
grants: ["https://example.com"],
|
|
65
|
-
};
|
|
66
|
-
const plan: agentplan = {
|
|
67
|
-
id: "run",
|
|
68
|
-
objective: "Run the reviewed triggers",
|
|
69
|
-
origin: "https://example.com",
|
|
70
|
-
steps: [],
|
|
71
|
-
createdat: now - 2000,
|
|
72
|
-
expiresat: now + 600_000,
|
|
73
|
-
state: "approved",
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
function kindallowed(kind: string): boolean {
|
|
77
|
-
try {
|
|
78
|
-
actionrisk(kind as toolstep["kind"]);
|
|
79
|
-
return true;
|
|
80
|
-
} catch {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
function riskof(kind: string): "read" | "interaction" | "sensitive" {
|
|
85
|
-
return actionrisk(kind as toolstep["kind"]);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** Builds one trigger step of the given family with its reviewed rule payload. */
|
|
89
|
-
function triggerstep(kind: string, payload: Record<string, unknown>, extra: Record<string, unknown> = {}): toolstep {
|
|
90
|
-
return {
|
|
91
|
-
id: "t1",
|
|
92
|
-
kind: kind as toolstep["kind"],
|
|
93
|
-
summary: `The reviewed ${kind} step`,
|
|
94
|
-
risk: "sensitive",
|
|
95
|
-
options: JSON.stringify({ workflowid: "wf1", reviewed: true, rule: payload, ...extra }),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/** Arms one rule of the given family through the engine normalizer. */
|
|
100
|
-
function armedrule(kind: string, payload: Record<string, unknown>, extra: Record<string, unknown> = {}): triggerule {
|
|
101
|
-
const family = triggerfamilyof(kind);
|
|
102
|
-
if (!family) throw new Error(`The ${kind} step is not a trigger kind.`);
|
|
103
|
-
const rule = armrule({ family, workflowid: "wf1", payload, ...extra, now });
|
|
104
|
-
if (!rule) throw new Error(`The ${kind} rule did not arm.`);
|
|
105
|
-
return rule;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
class fakeadapter {
|
|
109
|
-
private readonly data = new Map<string, unknown>();
|
|
110
|
-
async get<T>(key: string): Promise<T | undefined> {
|
|
111
|
-
return this.data.get(key) as T | undefined;
|
|
112
|
-
}
|
|
113
|
-
async set<T>(key: string, value: T): Promise<void> {
|
|
114
|
-
this.data.set(key, value);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
describe("trigger kinds, families and rule arming", () => {
|
|
119
|
-
it("lists the ten trigger kinds and grades every automatic launcher sensitive", () => {
|
|
120
|
-
expect(triggerkinds).toEqual([
|
|
121
|
-
"visitrule",
|
|
122
|
-
"urlrule",
|
|
123
|
-
"menurule",
|
|
124
|
-
"keyrule",
|
|
125
|
-
"buttonrule",
|
|
126
|
-
"cronrule",
|
|
127
|
-
"intervalrule",
|
|
128
|
-
"urllistrule",
|
|
129
|
-
"webhookrule",
|
|
130
|
-
"eventrule",
|
|
131
|
-
]);
|
|
132
|
-
for (const kind of triggerkinds) {
|
|
133
|
-
expect(istriggeraction(kind as toolstep["kind"])).toBe(true);
|
|
134
|
-
expect(isworkflowkind(kind as toolstep["kind"])).toBe(false);
|
|
135
|
-
expect(kindallowed(kind)).toBe(true);
|
|
136
|
-
expect(actionrisk(kind as toolstep["kind"])).toBe("sensitive");
|
|
137
|
-
expect(triggerfamilyof(kind)).toBeDefined();
|
|
138
|
-
}
|
|
139
|
-
expect(istriggeraction("runworkflow")).toBe(false);
|
|
140
|
-
expect(triggerfamilyof("click")).toBeUndefined();
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it("arms every family behind its grammar and applies the documented webhook and event cooldown defaults", () => {
|
|
144
|
-
expect(armedrule("visitrule", { origins: ["https://example.com"] }).state.cooldown).toBe(0);
|
|
145
|
-
expect(armedrule("urlrule", { pattern: "https://example.com/*/detail" }).pattern).toBe(
|
|
146
|
-
"https://example.com/*/detail",
|
|
147
|
-
);
|
|
148
|
-
expect(armedrule("menurule", { title: "Run the reader" }).title).toBe("Run the reader");
|
|
149
|
-
expect(armedrule("keyrule", { command: "run-reader", key: "Ctrl+Shift+R" }).command).toBe("run-reader");
|
|
150
|
-
expect(armedrule("buttonrule", {}).kind).toBe("button");
|
|
151
|
-
expect(armedrule("cronrule", { cron: "*/15 * * * *", timezone: "America/New_York" }).timezone).toBe(
|
|
152
|
-
"America/New_York",
|
|
153
|
-
);
|
|
154
|
-
expect(armedrule("intervalrule", { period: 60_000, jitter: 10_000 }).jitter).toBe(10_000);
|
|
155
|
-
expect(armedrule("urllistrule", { urls: ["https://example.com/a", "https://example.com/b"] }).urls).toHaveLength(2);
|
|
156
|
-
expect(
|
|
157
|
-
armedrule("webhookrule", {
|
|
158
|
-
secret: "devthink-secret-2026-abc123",
|
|
159
|
-
schema: [{ name: "task", kind: "string", required: true }],
|
|
160
|
-
}).state.cooldown,
|
|
161
|
-
).toBe(defaulttriggercooldown);
|
|
162
|
-
expect(armedrule("eventrule", { events: ["mutate", "navigate"] }).state.cooldown).toBe(defaulttriggercooldown);
|
|
163
|
-
expect(armedrule("eventrule", { events: ["mutate"] }, { cooldown: 60_000 }).state.cooldown).toBe(60_000);
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("refuses malformed family payloads and cooldown windows", () => {
|
|
167
|
-
expect(
|
|
168
|
-
armrule({ family: "visit", workflowid: "wf1", payload: { origins: ["http://insecure.example"] }, now }),
|
|
169
|
-
).toBeUndefined();
|
|
170
|
-
expect(armrule({ family: "visit", workflowid: "wf1", payload: { origins: [] }, now })).toBeUndefined();
|
|
171
|
-
expect(armrule({ family: "url", workflowid: "wf1", payload: { pattern: "example.com/*" }, now })).toBeUndefined();
|
|
172
|
-
expect(armrule({ family: "cron", workflowid: "wf1", payload: { cron: "not a cron" }, now })).toBeUndefined();
|
|
173
|
-
expect(
|
|
174
|
-
armrule({ family: "cron", workflowid: "wf1", payload: { cron: "* * * * *", timezone: "Not/AZone" }, now }),
|
|
175
|
-
).toBeUndefined();
|
|
176
|
-
expect(armrule({ family: "interval", workflowid: "wf1", payload: { period: 0 }, now })).toBeUndefined();
|
|
177
|
-
expect(
|
|
178
|
-
armrule({ family: "interval", workflowid: "wf1", payload: { period: 1000, jitter: -1 }, now }),
|
|
179
|
-
).toBeUndefined();
|
|
180
|
-
expect(
|
|
181
|
-
armrule({ family: "urllist", workflowid: "wf1", payload: { urls: ["https://example.com/a", "nope"] }, now }),
|
|
182
|
-
).toBeUndefined();
|
|
183
|
-
expect(
|
|
184
|
-
armrule({
|
|
185
|
-
family: "webhook",
|
|
186
|
-
workflowid: "wf1",
|
|
187
|
-
payload: { secret: "short", schema: [{ name: "task", kind: "string" }] },
|
|
188
|
-
now,
|
|
189
|
-
}),
|
|
190
|
-
).toBeUndefined();
|
|
191
|
-
expect(
|
|
192
|
-
armrule({
|
|
193
|
-
family: "webhook",
|
|
194
|
-
workflowid: "wf1",
|
|
195
|
-
payload: { secret: "devthink-secret-2026-abc123", schema: [] },
|
|
196
|
-
now,
|
|
197
|
-
}),
|
|
198
|
-
).toBeUndefined();
|
|
199
|
-
expect(armrule({ family: "event", workflowid: "wf1", payload: { events: ["nope"] }, now })).toBeUndefined();
|
|
200
|
-
expect(
|
|
201
|
-
armrule({ family: "event", workflowid: "wf1", payload: { events: ["mutate"] }, cooldown: 0, now }),
|
|
202
|
-
).toBeUndefined();
|
|
203
|
-
expect(armrule({ family: "event", workflowid: "", payload: { events: ["mutate"] }, now })).toBeUndefined();
|
|
204
|
-
expect(timezonevalid("America/New_York")).toBe(true);
|
|
205
|
-
expect(timezonevalid("Mars/Olympus")).toBe(false);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("summarizes every family for the review panel and checks the rule origins against the workflow grants", () => {
|
|
209
|
-
expect(triggersummary(armedrule("cronrule", { cron: "0 9 * * *" })).cron).toBe("0 9 * * *");
|
|
210
|
-
expect(
|
|
211
|
-
triggersummary(
|
|
212
|
-
armedrule("webhookrule", { secret: "devthink-secret-2026-abc123", schema: [{ name: "task", kind: "string" }] }),
|
|
213
|
-
).fields,
|
|
214
|
-
).toBe(1);
|
|
215
|
-
const visit = armedrule("visitrule", { origins: ["https://example.com"] });
|
|
216
|
-
expect(ruleoriginsgranted(visit, ["https://example.com"])).toBe(true);
|
|
217
|
-
expect(ruleoriginsgranted(visit, ["https://other.example"])).toBe(false);
|
|
218
|
-
const list = armedrule("urllistrule", { urls: ["https://example.com/a", "https://elsewhere.example/b"] });
|
|
219
|
-
expect(ruleoriginsgranted(list, ["https://example.com"])).toBe(false);
|
|
220
|
-
const pattern = armedrule("urlrule", { pattern: "https://example.com/*" });
|
|
221
|
-
expect(ruleoriginsgranted(pattern, ["https://example.com"])).toBe(true);
|
|
222
|
-
expect(ruleoriginsgranted(armedrule("buttonrule", {}), [])).toBe(true);
|
|
223
|
-
});
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
describe("trigger url matching", () => {
|
|
227
|
-
it("matches glob patterns across segments and honors explicit ports", () => {
|
|
228
|
-
expect(matchurl("https://example.com/*/detail", "https://example.com/a/detail")).toBe(true);
|
|
229
|
-
expect(matchurl("https://example.com/*/detail", "https://example.com/a/b/detail")).toBe(false);
|
|
230
|
-
expect(matchurl("https://example.com/**/detail", "https://example.com/a/b/detail")).toBe(true);
|
|
231
|
-
expect(matchurl("https://example.com/articles/*?id=*", "https://example.com/articles/one?id=7")).toBe(true);
|
|
232
|
-
expect(matchurl("https://example.com/*", "https://other.example/x")).toBe(false);
|
|
233
|
-
expect(matchurl("https://example.com/*", "http://example.com/x")).toBe(false);
|
|
234
|
-
expect(matchurl("https://example.com:8443/*", "https://example.com:8443/x")).toBe(true);
|
|
235
|
-
expect(matchurl("https://example.com:8443/*", "https://example.com/x")).toBe(false);
|
|
236
|
-
expect(matchurl("https://example.com/*", "https://example.com:8443/x")).toBe(true);
|
|
237
|
-
expect(matchurl("https://example.com/*", "not a url")).toBe(false);
|
|
238
|
-
});
|
|
239
|
-
|
|
240
|
-
it("fires visit rules when a navigation lands on a reviewed origin", () => {
|
|
241
|
-
const rule = armedrule("visitrule", { origins: ["https://example.com", "https://docs.example.com"] });
|
|
242
|
-
expect(visitmatch(rule.origins as string[], "https://example.com/articles/one")).toBe(true);
|
|
243
|
-
expect(visitmatch(rule.origins as string[], "https://docs.example.com/guide")).toBe(true);
|
|
244
|
-
expect(visitmatch(rule.origins as string[], "https://other.example/articles/one")).toBe(false);
|
|
245
|
-
expect(visitmatch(rule.origins as string[], "about:blank")).toBe(false);
|
|
246
|
-
const decision = evaluatetrigger({
|
|
247
|
-
rule,
|
|
248
|
-
now,
|
|
249
|
-
cause: "visit",
|
|
250
|
-
url: "https://example.com/articles/one",
|
|
251
|
-
title: "One",
|
|
252
|
-
runactive: false,
|
|
253
|
-
workflowreviewed: true,
|
|
254
|
-
});
|
|
255
|
-
expect(decision.fired).toBe(true);
|
|
256
|
-
expect(decision.fire?.url).toBe("https://example.com/articles/one");
|
|
257
|
-
expect(decision.fire?.title).toBe("One");
|
|
258
|
-
expect(decision.fire?.ruleid).toBe(rule.id);
|
|
259
|
-
});
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
describe("cron parsing and scheduling", () => {
|
|
263
|
-
it("parses five field expressions with lists, ranges, steps and named weekdays and months", () => {
|
|
264
|
-
expect(cronparse("*/15 * * * *")?.minutes).toEqual([0, 15, 30, 45]);
|
|
265
|
-
expect(cronparse("0,30 9-17 * * *")?.hours).toEqual([9, 10, 11, 12, 13, 14, 15, 16, 17]);
|
|
266
|
-
expect(cronparse("0 0 1 jan *")?.months).toEqual([1]);
|
|
267
|
-
expect(cronparse("0 9 * * mon-fri")?.daysofweek).toEqual([1, 2, 3, 4, 5]);
|
|
268
|
-
expect(cronparse("0 0 * * 7")?.daysofweek).toEqual([0]);
|
|
269
|
-
expect(cronparse("5 4 * * sun,sat")?.daysofweek).toEqual([0, 6]);
|
|
270
|
-
expect(cronparse("1-10/3 * * * *")?.minutes).toEqual([1, 4, 7, 10]);
|
|
271
|
-
expect(cronparse("* * * * *")?.minutes).toHaveLength(60);
|
|
272
|
-
expect(cronparse("61 * * * *")).toBeUndefined();
|
|
273
|
-
expect(cronparse("* 24 * * *")).toBeUndefined();
|
|
274
|
-
expect(cronparse("* * 0 * *")).toBeUndefined();
|
|
275
|
-
expect(cronparse("* * * 13 *")).toBeUndefined();
|
|
276
|
-
expect(cronparse("not a cron")).toBeUndefined();
|
|
277
|
-
expect(cronparse("* * * *")).toBeUndefined();
|
|
278
|
-
expect(cronparse("60 * * * *")).toBeUndefined();
|
|
279
|
-
expect(cronparse("5-1 * * * *")).toBeUndefined();
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
it("computes the next fire time on minute boundaries and walks sparse schedules", () => {
|
|
283
|
-
const from = Date.UTC(2026, 0, 15, 8, 59, 30);
|
|
284
|
-
expect(cronnext("*/15 * * * *", from)).toBe(Date.UTC(2026, 0, 15, 9, 0));
|
|
285
|
-
expect(cronnext("30,45 * * * *", Date.UTC(2026, 0, 15, 9, 10))).toBe(Date.UTC(2026, 0, 15, 9, 30));
|
|
286
|
-
expect(cronnext("0 9 * * *", Date.UTC(2026, 0, 15, 9, 0))).toBe(Date.UTC(2026, 0, 16, 9, 0));
|
|
287
|
-
expect(cronnext("0 9 * * mon", Date.UTC(2026, 0, 15, 10, 0))).toBe(Date.UTC(2026, 0, 19, 9, 0));
|
|
288
|
-
expect(cronnext("0 0 1 jan *", Date.UTC(2026, 5, 1))).toBe(Date.UTC(2027, 0, 1, 0, 0));
|
|
289
|
-
expect(cronnext("0 0 29 2 *", Date.UTC(2026, 0, 1))).toBe(Date.UTC(2028, 1, 29, 0, 0));
|
|
290
|
-
expect(cronnext("0 0 30 2 *", Date.UTC(2026, 0, 1))).toBeUndefined();
|
|
291
|
-
expect(cronnext("bad", Date.UTC(2026, 0, 1))).toBeUndefined();
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
it("honors the classic day of month and day of week or semantics", () => {
|
|
295
|
-
expect(cronnext("0 0 1 * 1", Date.UTC(2025, 11, 31, 12, 0))).toBe(Date.UTC(2026, 0, 1, 0, 0));
|
|
296
|
-
expect(cronnext("0 0 1 * 1", Date.UTC(2026, 0, 1, 1, 0))).toBe(Date.UTC(2026, 0, 5, 0, 0));
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it("computes cron fire times inside the reviewed timezone through the runtime timezone database", () => {
|
|
300
|
-
const utcfrom = Date.UTC(2026, 0, 15, 13, 0, 0);
|
|
301
|
-
expect(cronnext("0 9 * * *", utcfrom, "America/New_York")).toBe(Date.UTC(2026, 0, 15, 14, 0));
|
|
302
|
-
expect(cronnext("0 9 * * *", Date.UTC(2026, 0, 15, 14, 0), "America/New_York")).toBe(Date.UTC(2026, 0, 16, 14, 0));
|
|
303
|
-
expect(schedulecron({ cron: "0 9 * * *", timezone: "America/New_York" }, utcfrom)).toBe(
|
|
304
|
-
Date.UTC(2026, 0, 15, 14, 0),
|
|
305
|
-
);
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it("spreads interval fires inside the reviewed jitter window with the seeded random source", () => {
|
|
309
|
-
const samples = new Set<number>();
|
|
310
|
-
for (let seed = 0; seed < 200; seed += 1)
|
|
311
|
-
samples.add(scheduleinterval({ period: 60_000, jitter: 20_000 }, 1_000_000, 500_000, seed));
|
|
312
|
-
expect(samples.size).toBeGreaterThan(100);
|
|
313
|
-
for (const sample of samples) {
|
|
314
|
-
expect(sample).toBeGreaterThanOrEqual(1_060_000 - 10_000);
|
|
315
|
-
expect(sample).toBeLessThanOrEqual(1_060_000 + 10_000);
|
|
316
|
-
}
|
|
317
|
-
expect(scheduleinterval({ period: 60_000 }, 1_000_000, 500_000, 1)).toBe(1_060_000);
|
|
318
|
-
expect(scheduleinterval({ period: 60_000, jitter: 0 }, 1_000_000, 500_000, 1)).toBe(1_060_000);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it("returns the scheduled rules whose next fire time has passed", () => {
|
|
322
|
-
const due = armedrule("cronrule", { cron: "* * * * *" });
|
|
323
|
-
const later = armedrule("cronrule", { cron: "0 0 1 1 *" });
|
|
324
|
-
const interval = armedrule("intervalrule", { period: 1000 });
|
|
325
|
-
const disabled = updaterule(armedrule("cronrule", { cron: "* * * * *" }), { state: { enabled: false } });
|
|
326
|
-
const paused = updaterule(armedrule("cronrule", { cron: "* * * * *" }), { state: { pausedat: now } });
|
|
327
|
-
const listed = listdue(
|
|
328
|
-
[
|
|
329
|
-
{ ...due, state: { ...due.state, nextfireat: now - 5000 } },
|
|
330
|
-
{ ...later, state: { ...later.state, nextfireat: now + 500_000 } },
|
|
331
|
-
{ ...interval, state: { ...interval.state, nextfireat: now - 1 } },
|
|
332
|
-
{ ...disabled, state: { ...disabled.state, nextfireat: now - 1 } },
|
|
333
|
-
{ ...paused, state: { ...paused.state, nextfireat: now - 1 } },
|
|
334
|
-
],
|
|
335
|
-
now,
|
|
336
|
-
);
|
|
337
|
-
expect(listed.map((entry) => entry.rule.kind)).toEqual(["cron", "interval"]);
|
|
338
|
-
expect(listed[0]?.overdueby).toBe(5000);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe("trigger evaluation, cooldown, dedupe and the queue", () => {
|
|
343
|
-
it("suppresses fires inside the cooldown window and reports the remaining window", () => {
|
|
344
|
-
const rule = armedrule("eventrule", { events: ["mutate"] }, { cooldown: 60_000 });
|
|
345
|
-
const cooled = { ...rule, state: { ...rule.state, lastfireat: now - 10_000 } };
|
|
346
|
-
expect(applycooldown(cooled, now).suppressed).toBe(true);
|
|
347
|
-
expect(applycooldown(cooled, now).remaining).toBe(50_000);
|
|
348
|
-
const decision = evaluatetrigger({ rule: cooled, now, cause: "event", runactive: false, workflowreviewed: true });
|
|
349
|
-
expect(decision.fired).toBe(false);
|
|
350
|
-
expect(decision.suppressed).toBe("cooldown");
|
|
351
|
-
expect(decision.remaining).toBe(50_000);
|
|
352
|
-
expect(
|
|
353
|
-
evaluatetrigger({
|
|
354
|
-
rule: { ...cooled, state: { ...cooled.state, lastfireat: now - 60_000 } },
|
|
355
|
-
now,
|
|
356
|
-
cause: "event",
|
|
357
|
-
runactive: false,
|
|
358
|
-
workflowreviewed: true,
|
|
359
|
-
}).fired,
|
|
360
|
-
).toBe(true);
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
it("never fires disabled, paused or unreviewed rules and dedupes while a run is active", () => {
|
|
364
|
-
const rule = armedrule("visitrule", { origins: ["https://example.com"] });
|
|
365
|
-
expect(
|
|
366
|
-
evaluatetrigger({
|
|
367
|
-
rule: updaterule(rule, { state: { enabled: false } }),
|
|
368
|
-
now,
|
|
369
|
-
cause: "visit",
|
|
370
|
-
runactive: false,
|
|
371
|
-
workflowreviewed: true,
|
|
372
|
-
}).suppressed,
|
|
373
|
-
).toBe("disabled");
|
|
374
|
-
expect(
|
|
375
|
-
evaluatetrigger({
|
|
376
|
-
rule: updaterule(rule, { state: { pausedat: now } }),
|
|
377
|
-
now,
|
|
378
|
-
cause: "visit",
|
|
379
|
-
runactive: false,
|
|
380
|
-
workflowreviewed: true,
|
|
381
|
-
}).suppressed,
|
|
382
|
-
).toBe("paused");
|
|
383
|
-
expect(evaluatetrigger({ rule, now, cause: "visit", runactive: false, workflowreviewed: false }).suppressed).toBe(
|
|
384
|
-
"unreviewed",
|
|
385
|
-
);
|
|
386
|
-
expect(evaluatetrigger({ rule, now, cause: "visit", runactive: true, workflowreviewed: true }).suppressed).toBe(
|
|
387
|
-
"dedupe",
|
|
388
|
-
);
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
it("keeps one pending fire per rule in the queue while a run is active", () => {
|
|
392
|
-
const first: triggerfire = { id: "f1", ruleid: "r1", at: now, cause: "visit", url: "https://example.com/a" };
|
|
393
|
-
const second: triggerfire = { id: "f2", ruleid: "r1", at: now + 1, cause: "visit", url: "https://example.com/b" };
|
|
394
|
-
const other: triggerfire = { id: "f3", ruleid: "r2", at: now + 2, cause: "visit" };
|
|
395
|
-
const queued = queuefire([], first);
|
|
396
|
-
expect(queued.queued).toBe(true);
|
|
397
|
-
const deduped = queuefire(queued.queue, second);
|
|
398
|
-
expect(deduped.deduped).toBe(true);
|
|
399
|
-
expect(deduped.queue).toHaveLength(1);
|
|
400
|
-
const both = queuefire(deduped.queue, other);
|
|
401
|
-
expect(both.queue).toHaveLength(2);
|
|
402
|
-
expect(both.queued).toBe(true);
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it("drains the queued fires in arrival order and keeps the rest when a launch fails", async () => {
|
|
406
|
-
const fires: triggerfire[] = [
|
|
407
|
-
{ id: "f1", ruleid: "r1", at: now, cause: "visit" },
|
|
408
|
-
{ id: "f2", ruleid: "r2", at: now + 1, cause: "url" },
|
|
409
|
-
];
|
|
410
|
-
const launched: string[] = [];
|
|
411
|
-
const drained = await drainqueue(fires, async (fire) => {
|
|
412
|
-
launched.push(fire.id);
|
|
413
|
-
});
|
|
414
|
-
expect(launched).toEqual(["f1", "f2"]);
|
|
415
|
-
expect(drained).toEqual({ launched: 2, remaining: [] });
|
|
416
|
-
const failing = await drainqueue(fires, async (fire) => {
|
|
417
|
-
if (fire.id === "f1") throw new Error("the run refused the launch");
|
|
418
|
-
launched.push(fire.id);
|
|
419
|
-
});
|
|
420
|
-
expect(failing.launched).toBe(0);
|
|
421
|
-
expect(failing.remaining).toHaveLength(2);
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it("suspends every enabled rule on session pause and releases them on resume", () => {
|
|
425
|
-
const rules = [
|
|
426
|
-
armedrule("visitrule", { origins: ["https://example.com"] }),
|
|
427
|
-
armedrule("cronrule", { cron: "* * * * *" }),
|
|
428
|
-
updaterule(armedrule("eventrule", { events: ["mutate"] }), { state: { enabled: false } }),
|
|
429
|
-
];
|
|
430
|
-
const paused = pauseall(rules, now);
|
|
431
|
-
expect(paused.filter((rule) => rule.state.pausedat !== undefined)).toHaveLength(2);
|
|
432
|
-
const resumed = resumeall(paused);
|
|
433
|
-
expect(resumed.every((rule) => rule.state.pausedat === undefined)).toBe(true);
|
|
434
|
-
expect(resumed[2]?.state.enabled).toBe(false);
|
|
435
|
-
});
|
|
436
|
-
|
|
437
|
-
it("plans one run per url of a url list rule", () => {
|
|
438
|
-
const rule = armedrule("urllistrule", {
|
|
439
|
-
urls: ["https://example.com/a", "https://example.com/b", "https://example.com/c"],
|
|
440
|
-
});
|
|
441
|
-
const fires = runurllist(rule, now);
|
|
442
|
-
expect(fires).toHaveLength(3);
|
|
443
|
-
expect(fires.every((fire) => fire.ruleid === rule.id && fire.cause === "urllist")).toBe(true);
|
|
444
|
-
expect(fires.map((fire) => fire.url)).toEqual([
|
|
445
|
-
"https://example.com/a",
|
|
446
|
-
"https://example.com/b",
|
|
447
|
-
"https://example.com/c",
|
|
448
|
-
]);
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
describe("webhook verification and page event subscription", () => {
|
|
453
|
-
it("verifies the shared secret and the payload schema before anything persists", () => {
|
|
454
|
-
const rule = armedrule("webhookrule", {
|
|
455
|
-
secret: "devthink-secret-2026-abc123",
|
|
456
|
-
schema: [
|
|
457
|
-
{ name: "task", kind: "string", required: true },
|
|
458
|
-
{ name: "count", kind: "number" },
|
|
459
|
-
{ name: "urgent", kind: "boolean" },
|
|
460
|
-
],
|
|
461
|
-
});
|
|
462
|
-
expect(
|
|
463
|
-
verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { task: "read", count: 3 } }).verified,
|
|
464
|
-
).toBe(true);
|
|
465
|
-
expect(verifywebhook({ rule, secret: "wrong-secret-2026-abc1234", payload: { task: "read" } }).reason).toContain(
|
|
466
|
-
"secret",
|
|
467
|
-
);
|
|
468
|
-
expect(verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { count: 3 } }).reason).toContain(
|
|
469
|
-
"task",
|
|
470
|
-
);
|
|
471
|
-
expect(verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { task: 7 } }).reason).toContain(
|
|
472
|
-
"task",
|
|
473
|
-
);
|
|
474
|
-
expect(
|
|
475
|
-
verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: { task: "read", urgent: "yes" } }).reason,
|
|
476
|
-
).toContain("urgent");
|
|
477
|
-
expect(verifywebhook({ rule, secret: "devthink-secret-2026-abc123", payload: "not an object" }).reason).toContain(
|
|
478
|
-
"object",
|
|
479
|
-
);
|
|
480
|
-
expect(
|
|
481
|
-
verifywebhook({ rule: { ...rule, secret: undefined } as unknown as triggerule, secret: "", payload: {} })
|
|
482
|
-
.verified,
|
|
483
|
-
).toBe(false);
|
|
484
|
-
expect(webhooksecretok("devthink-secret-2026-abc123")).toBe(true);
|
|
485
|
-
expect(webhooksecretok("short")).toBe(false);
|
|
486
|
-
expect(webhooksecretok("aaaaaaaaaaaaaaaaaaaaaaaa")).toBe(false);
|
|
487
|
-
expect(webhooksecretok("123456789012345678901234")).toBe(false);
|
|
488
|
-
});
|
|
489
|
-
|
|
490
|
-
it("subscribes event rules to the observed event catalog only", () => {
|
|
491
|
-
expect(triggereventcatalog).toEqual(["mutate", "focus", "banner", "console", "error", "navigate"]);
|
|
492
|
-
const rule = armedrule("eventrule", { events: ["mutate", "navigate"] });
|
|
493
|
-
expect(eventrulematches(rule, "mutate")).toBe(true);
|
|
494
|
-
expect(eventrulematches(rule, "focus")).toBe(false);
|
|
495
|
-
const decision = evaluatetrigger({
|
|
496
|
-
rule,
|
|
497
|
-
now,
|
|
498
|
-
cause: "event",
|
|
499
|
-
payload: { event: "mutate" },
|
|
500
|
-
runactive: false,
|
|
501
|
-
workflowreviewed: true,
|
|
502
|
-
});
|
|
503
|
-
expect(decision.fire?.payload).toEqual({ event: "mutate" });
|
|
504
|
-
expect(observeevents([rule], "mutate")).toEqual([rule]);
|
|
505
|
-
expect(observeevents([rule], "focus")).toEqual([]);
|
|
506
|
-
expect(observeevents([rule], "unknown")).toEqual([]);
|
|
507
|
-
const disabled = updaterule(rule, { state: { enabled: false } });
|
|
508
|
-
expect(observeevents([disabled], "mutate")).toEqual([]);
|
|
509
|
-
const paused = updaterule(rule, { state: { pausedat: now } });
|
|
510
|
-
expect(observeevents([paused], "mutate")).toEqual([]);
|
|
511
|
-
const visitrule = armedrule("visitrule", { origins: ["https://example.com"] });
|
|
512
|
-
expect(observeevents([visitrule], "navigate")).toEqual([]);
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
|
|
516
|
-
describe("manual runs with the step preview", () => {
|
|
517
|
-
it("renders the expanded step preview with control summaries before anything runs", () => {
|
|
518
|
-
const record: workflowrecord = composeworkflow({
|
|
519
|
-
id: "wf1",
|
|
520
|
-
name: "reader",
|
|
521
|
-
version: 1,
|
|
522
|
-
origins: ["https://example.com"],
|
|
523
|
-
steps: [
|
|
524
|
-
workflowstepof({ id: "s1", kind: "readtext", label: "Read the heading", target: "h1" }) as never,
|
|
525
|
-
{
|
|
526
|
-
id: "s2",
|
|
527
|
-
kind: "branch",
|
|
528
|
-
label: "Branch by title",
|
|
529
|
-
options: JSON.stringify({
|
|
530
|
-
branch: {
|
|
531
|
-
paths: [
|
|
532
|
-
{
|
|
533
|
-
name: "short",
|
|
534
|
-
when: {
|
|
535
|
-
left: { ref: "title" },
|
|
536
|
-
right: { literal: "x" },
|
|
537
|
-
operator: "contains",
|
|
538
|
-
result: "match",
|
|
539
|
-
resultkind: "boolean",
|
|
540
|
-
},
|
|
541
|
-
steps: [{ id: "s3", kind: "wait", label: "Wait a beat", value: "10" }],
|
|
542
|
-
},
|
|
543
|
-
],
|
|
544
|
-
else: { name: "else", steps: [{ id: "s4", kind: "wait", label: "Wait longer", value: "20" }] },
|
|
545
|
-
},
|
|
546
|
-
}),
|
|
547
|
-
} as never,
|
|
548
|
-
],
|
|
549
|
-
now,
|
|
550
|
-
kindallowed,
|
|
551
|
-
riskof,
|
|
552
|
-
});
|
|
553
|
-
const preview = manualpreview(record, now);
|
|
554
|
-
expect(preview.workflowid).toBe("wf1");
|
|
555
|
-
expect(preview.preview).toHaveLength(2);
|
|
556
|
-
expect(preview.preview[1]?.control?.paths).toEqual(["short"]);
|
|
557
|
-
expect(preview.preview[1]?.control?.elsepath).toBe("else");
|
|
558
|
-
expect(preview.confirmed).toBeUndefined();
|
|
559
|
-
const confirmed = confirmmanualrun(preview, true, now + 5);
|
|
560
|
-
expect(confirmed.confirmed).toBe(true);
|
|
561
|
-
expect(confirmed.decidedat).toBe(now + 5);
|
|
562
|
-
expect(confirmmanualrun(preview, false, now + 6).confirmed).toBe(false);
|
|
563
|
-
const envelope = manualrunpreview({ preview: confirmed, workflowname: record.name });
|
|
564
|
-
expect(envelope.workflowname).toBe("reader");
|
|
565
|
-
expect(envelope.manualrun.preview).toHaveLength(2);
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
|
|
569
|
-
describe("trigger policy validation and sensitivity grading", () => {
|
|
570
|
-
it("validates the grammar of every trigger kind", () => {
|
|
571
|
-
expect(
|
|
572
|
-
validatestep(triggerstep("visitrule", { origins: ["https://example.com"] }), "https://example.com").allowed,
|
|
573
|
-
).toBe(true);
|
|
574
|
-
expect(
|
|
575
|
-
validatestep(triggerstep("urlrule", { pattern: "https://example.com/*" }), "https://example.com").allowed,
|
|
576
|
-
).toBe(true);
|
|
577
|
-
expect(validatestep(triggerstep("menurule", { title: "Run the reader" }), "https://example.com").allowed).toBe(
|
|
578
|
-
true,
|
|
579
|
-
);
|
|
580
|
-
expect(validatestep(triggerstep("keyrule", { command: "run-reader" }), "https://example.com").allowed).toBe(true);
|
|
581
|
-
expect(validatestep(triggerstep("buttonrule", {}), "https://example.com").allowed).toBe(true);
|
|
582
|
-
expect(validatestep(triggerstep("cronrule", { cron: "*/15 * * * *" }), "https://example.com").allowed).toBe(true);
|
|
583
|
-
expect(
|
|
584
|
-
validatestep(triggerstep("intervalrule", { period: 60_000, jitter: 5_000 }), "https://example.com").allowed,
|
|
585
|
-
).toBe(true);
|
|
586
|
-
expect(
|
|
587
|
-
validatestep(triggerstep("urllistrule", { urls: ["https://example.com/a"] }), "https://example.com").allowed,
|
|
588
|
-
).toBe(true);
|
|
589
|
-
expect(
|
|
590
|
-
validatestep(
|
|
591
|
-
triggerstep("webhookrule", {
|
|
592
|
-
secret: "devthink-secret-2026-abc123",
|
|
593
|
-
schema: [{ name: "task", kind: "string", required: true }],
|
|
594
|
-
}),
|
|
595
|
-
"https://example.com",
|
|
596
|
-
).allowed,
|
|
597
|
-
).toBe(true);
|
|
598
|
-
expect(validatestep(triggerstep("eventrule", { events: ["mutate"] }), "https://example.com").allowed).toBe(true);
|
|
599
|
-
expect(
|
|
600
|
-
validatestep(triggerstep("eventrule", { events: ["mutate"] }, { label: "Panel rule" }), "https://example.com")
|
|
601
|
-
.allowed,
|
|
602
|
-
).toBe(true);
|
|
603
|
-
});
|
|
604
|
-
|
|
605
|
-
it("refuses rules without the arm review, weak secrets, unparseable crons and unknown events", () => {
|
|
606
|
-
expect(
|
|
607
|
-
validatestep(
|
|
608
|
-
triggerstep("visitrule", { origins: ["https://example.com"] }, { reviewed: false }),
|
|
609
|
-
"https://example.com",
|
|
610
|
-
).reason,
|
|
611
|
-
).toContain("arm review");
|
|
612
|
-
expect(
|
|
613
|
-
validatestep(
|
|
614
|
-
triggerstep("visitrule", { origins: ["https://example.com"] }, { workflowid: "" }),
|
|
615
|
-
"https://example.com",
|
|
616
|
-
).reason,
|
|
617
|
-
).toContain("workflow");
|
|
618
|
-
expect(validatestep(triggerstep("cronrule", { cron: "99 * * * *" }), "https://example.com").reason).toContain(
|
|
619
|
-
"cron",
|
|
620
|
-
);
|
|
621
|
-
expect(
|
|
622
|
-
validatestep(
|
|
623
|
-
triggerstep("webhookrule", { secret: "short", schema: [{ name: "task", kind: "string" }] }),
|
|
624
|
-
"https://example.com",
|
|
625
|
-
).reason,
|
|
626
|
-
).toContain("secret");
|
|
627
|
-
expect(validatestep(triggerstep("eventrule", { events: ["nope"] }), "https://example.com").reason).toContain(
|
|
628
|
-
"event",
|
|
629
|
-
);
|
|
630
|
-
expect(validatestep(triggerstep("intervalrule", { period: -1 }), "https://example.com").reason).toContain("period");
|
|
631
|
-
expect(validatestep(triggerstep("urllistrule", { urls: [] }), "https://example.com").reason).toContain("url list");
|
|
632
|
-
expect(validatestep(triggerstep("menurule", { title: "" }), "https://example.com").reason).toContain("menu");
|
|
633
|
-
expect(validatestep(triggerstep("keyrule", { command: "Bad Command" }), "https://example.com").reason).toContain(
|
|
634
|
-
"keyboard",
|
|
635
|
-
);
|
|
636
|
-
expect(
|
|
637
|
-
validatestep(triggerstep("visitrule", { origins: ["http://insecure.example"] }), "https://example.com").reason,
|
|
638
|
-
).toContain("visit");
|
|
639
|
-
expect(validatestep(triggerstep("urlrule", { pattern: "no-scheme/*" }), "https://example.com").reason).toContain(
|
|
640
|
-
"url rule",
|
|
641
|
-
);
|
|
642
|
-
expect(
|
|
643
|
-
validatestep(triggerstep("eventrule", { events: ["mutate"] }, { cooldown: 0 }), "https://example.com").reason,
|
|
644
|
-
).toContain("cooldown");
|
|
645
|
-
expect(
|
|
646
|
-
validatestep(triggerstep("eventrule", { events: ["mutate"] }, { label: "" }), "https://example.com").reason,
|
|
647
|
-
).toContain("label");
|
|
648
|
-
expect(
|
|
649
|
-
validatestep({ ...triggerstep("buttonrule", {}), kind: "nope" as toolstep["kind"] }, "https://example.com")
|
|
650
|
-
.reason,
|
|
651
|
-
).toContain("Unsupported");
|
|
652
|
-
});
|
|
653
|
-
|
|
654
|
-
it("gates every trigger kind behind the live session, the approved plan and the arm review", () => {
|
|
655
|
-
const step = triggerstep("visitrule", { origins: ["https://example.com"] });
|
|
656
|
-
expect(triggergate({ session, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(true);
|
|
657
|
-
expect(triggergate({ session: undefined, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(
|
|
658
|
-
false,
|
|
659
|
-
);
|
|
660
|
-
expect(
|
|
661
|
-
triggergate({ session: { ...session, stoppedat: now }, plan, step, tabid: 4, origin: "https://example.com", now })
|
|
662
|
-
.allowed,
|
|
663
|
-
).toBe(false);
|
|
664
|
-
expect(
|
|
665
|
-
triggergate({ session, plan: { ...plan, state: "pending" }, step, tabid: 4, origin: "https://example.com", now })
|
|
666
|
-
.reason,
|
|
667
|
-
).toContain("approved plan");
|
|
668
|
-
expect(
|
|
669
|
-
triggergate({
|
|
670
|
-
session,
|
|
671
|
-
plan,
|
|
672
|
-
step: triggerstep("visitrule", { origins: ["https://example.com"] }, { reviewed: false }),
|
|
673
|
-
tabid: 4,
|
|
674
|
-
origin: "https://example.com",
|
|
675
|
-
now,
|
|
676
|
-
}).reason,
|
|
677
|
-
).toContain("arm review");
|
|
678
|
-
expect(canexecute({ session: undefined, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(
|
|
679
|
-
false,
|
|
680
|
-
);
|
|
681
|
-
expect(canexecute({ session, plan, step, tabid: 4, origin: "https://example.com", now }).allowed).toBe(true);
|
|
682
|
-
});
|
|
683
|
-
|
|
684
|
-
it("extracts the match origins of a rule so proposals stay inside the grants", () => {
|
|
685
|
-
expect(
|
|
686
|
-
triggerorigins(triggerstep("visitrule", { origins: ["https://example.com", "https://example.com"] })),
|
|
687
|
-
).toEqual(["https://example.com"]);
|
|
688
|
-
expect(triggerorigins(triggerstep("urlrule", { pattern: "https://example.com/*" }))).toEqual([
|
|
689
|
-
"https://example.com",
|
|
690
|
-
]);
|
|
691
|
-
expect(
|
|
692
|
-
triggerorigins(triggerstep("urllistrule", { urls: ["https://example.com/a", "https://other.example/b"] })),
|
|
693
|
-
).toEqual(["https://example.com", "https://other.example"]);
|
|
694
|
-
expect(triggerorigins(triggerstep("buttonrule", {}))).toEqual([]);
|
|
695
|
-
expect(triggerorigins(triggerstep("visitrule", { origins: ["https://example.com"] }, { reviewed: false }))).toEqual(
|
|
696
|
-
["https://example.com"],
|
|
697
|
-
);
|
|
698
|
-
});
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
describe("trigger protocol envelopes", () => {
|
|
702
|
-
it("builds the trigger list with workflow names, counters and the queue depth", () => {
|
|
703
|
-
const cronrule = {
|
|
704
|
-
...armedrule("cronrule", { cron: "0 9 * * *" }),
|
|
705
|
-
state: { ...armedrule("cronrule", { cron: "0 9 * * *" }).state, nextfireat: now + 3600_000 },
|
|
706
|
-
};
|
|
707
|
-
const unbound = armrule({ family: "button", workflowid: "wfmissing", payload: {}, now });
|
|
708
|
-
if (!unbound) throw new Error("The button rule did not arm.");
|
|
709
|
-
const list = triggerlist({
|
|
710
|
-
rules: [cronrule, unbound],
|
|
711
|
-
workflows: [
|
|
712
|
-
{
|
|
713
|
-
id: "wf1",
|
|
714
|
-
name: "reader",
|
|
715
|
-
version: 1,
|
|
716
|
-
origins: ["https://example.com"],
|
|
717
|
-
steps: [],
|
|
718
|
-
blocks: [],
|
|
719
|
-
risk: "read",
|
|
720
|
-
createdat: now,
|
|
721
|
-
},
|
|
722
|
-
],
|
|
723
|
-
queue: [{ id: "f1", ruleid: "r1", at: now, cause: "visit" }],
|
|
724
|
-
});
|
|
725
|
-
expect(list.version).toBe(protocolversion);
|
|
726
|
-
expect(list.queued).toBe(1);
|
|
727
|
-
expect(list.rules[0]?.workflowname).toBe("reader");
|
|
728
|
-
expect(list.rules[0]?.nextfireat).toBe(now + 3600_000);
|
|
729
|
-
expect(list.rules[0]?.summary.cron).toBe("0 9 * * *");
|
|
730
|
-
expect(list.rules[1]?.workflowname).toBeUndefined();
|
|
731
|
-
});
|
|
732
|
-
|
|
733
|
-
it("builds the trigger fired notification with the run binding and returns the next fire time per rule", () => {
|
|
734
|
-
const fired = triggerfired({
|
|
735
|
-
fire: {
|
|
736
|
-
id: "f1",
|
|
737
|
-
ruleid: "r1",
|
|
738
|
-
at: now,
|
|
739
|
-
cause: "webhook",
|
|
740
|
-
url: "https://example.com",
|
|
741
|
-
payload: { task: "read" },
|
|
742
|
-
},
|
|
743
|
-
workflowid: "wf1",
|
|
744
|
-
runid: "run1",
|
|
745
|
-
});
|
|
746
|
-
expect(fired.triggerfired).toEqual({
|
|
747
|
-
fireid: "f1",
|
|
748
|
-
ruleid: "r1",
|
|
749
|
-
workflowid: "wf1",
|
|
750
|
-
at: now,
|
|
751
|
-
cause: "webhook",
|
|
752
|
-
url: "https://example.com",
|
|
753
|
-
runid: "run1",
|
|
754
|
-
});
|
|
755
|
-
const body = JSON.parse(
|
|
756
|
-
outcomeresponse({
|
|
757
|
-
outcome: { stepid: "t1", ok: true, summary: "Armed.", at: now },
|
|
758
|
-
plan,
|
|
759
|
-
trigger: { ruleid: "r1", kind: "cron", enabled: true, nextfireat: now + 60_000 },
|
|
760
|
-
}),
|
|
761
|
-
);
|
|
762
|
-
expect(body.trigger).toEqual({ ruleid: "r1", kind: "cron", enabled: true, nextfireat: now + 60_000 });
|
|
763
|
-
const without = JSON.parse(
|
|
764
|
-
outcomeresponse({ outcome: { stepid: "t1", ok: true, summary: "Armed.", at: now }, plan }),
|
|
765
|
-
);
|
|
766
|
-
expect(without.trigger).toBeUndefined();
|
|
767
|
-
});
|
|
768
|
-
|
|
769
|
-
it("refuses trigger proposals without the arm review or with origins outside the grants", () => {
|
|
770
|
-
const proposal = parseproposal(
|
|
771
|
-
{
|
|
772
|
-
version: protocolversion,
|
|
773
|
-
plan: {
|
|
774
|
-
objective: "Arm triggers",
|
|
775
|
-
steps: [
|
|
776
|
-
{
|
|
777
|
-
kind: "visitrule",
|
|
778
|
-
options: JSON.stringify({
|
|
779
|
-
workflowid: "wf1",
|
|
780
|
-
reviewed: true,
|
|
781
|
-
rule: { origins: ["https://example.com"] },
|
|
782
|
-
}),
|
|
783
|
-
summary: "Arm the visit rule.",
|
|
784
|
-
},
|
|
785
|
-
],
|
|
786
|
-
},
|
|
787
|
-
},
|
|
788
|
-
"https://example.com",
|
|
789
|
-
);
|
|
790
|
-
expect(proposal.plan.steps[0]?.kind).toBe("visitrule");
|
|
791
|
-
expect(() =>
|
|
792
|
-
parseproposal(
|
|
793
|
-
{
|
|
794
|
-
version: protocolversion,
|
|
795
|
-
plan: {
|
|
796
|
-
objective: "Unreviewed arm",
|
|
797
|
-
steps: [
|
|
798
|
-
{
|
|
799
|
-
kind: "visitrule",
|
|
800
|
-
options: JSON.stringify({ workflowid: "wf1", rule: { origins: ["https://example.com"] } }),
|
|
801
|
-
summary: "Arm without review.",
|
|
802
|
-
},
|
|
803
|
-
],
|
|
804
|
-
},
|
|
805
|
-
},
|
|
806
|
-
"https://example.com",
|
|
807
|
-
),
|
|
808
|
-
).toThrow("arm review");
|
|
809
|
-
expect(() =>
|
|
810
|
-
parseproposal(
|
|
811
|
-
{
|
|
812
|
-
version: protocolversion,
|
|
813
|
-
plan: {
|
|
814
|
-
objective: "Outside grants",
|
|
815
|
-
steps: [
|
|
816
|
-
{
|
|
817
|
-
kind: "visitrule",
|
|
818
|
-
options: JSON.stringify({
|
|
819
|
-
workflowid: "wf1",
|
|
820
|
-
reviewed: true,
|
|
821
|
-
rule: { origins: ["https://other.example"] },
|
|
822
|
-
}),
|
|
823
|
-
summary: "Arm outside the grants.",
|
|
824
|
-
},
|
|
825
|
-
],
|
|
826
|
-
},
|
|
827
|
-
},
|
|
828
|
-
"https://example.com",
|
|
829
|
-
),
|
|
830
|
-
).toThrow("outside the grants");
|
|
831
|
-
expect(() =>
|
|
832
|
-
parseproposal(
|
|
833
|
-
{
|
|
834
|
-
version: protocolversion,
|
|
835
|
-
plan: {
|
|
836
|
-
objective: "Url list outside grants",
|
|
837
|
-
steps: [
|
|
838
|
-
{
|
|
839
|
-
kind: "urllistrule",
|
|
840
|
-
options: JSON.stringify({
|
|
841
|
-
workflowid: "wf1",
|
|
842
|
-
reviewed: true,
|
|
843
|
-
rule: { urls: ["https://elsewhere.example/a"] },
|
|
844
|
-
}),
|
|
845
|
-
summary: "Arm the url list.",
|
|
846
|
-
},
|
|
847
|
-
],
|
|
848
|
-
},
|
|
849
|
-
},
|
|
850
|
-
"https://example.com",
|
|
851
|
-
),
|
|
852
|
-
).toThrow("outside the grants");
|
|
853
|
-
});
|
|
854
|
-
});
|
|
855
|
-
|
|
856
|
-
describe("trigger memory persistence", () => {
|
|
857
|
-
it("stores rules with their workflow names, replaces state and removes disarmed rules", async () => {
|
|
858
|
-
const store = new sessionmemory(new fakeadapter());
|
|
859
|
-
const rule = armedrule("visitrule", { origins: ["https://example.com"] });
|
|
860
|
-
await store.addtriggerule(rule);
|
|
861
|
-
await store.addworkflowrecord({
|
|
862
|
-
id: "wf1",
|
|
863
|
-
name: "reader",
|
|
864
|
-
version: 1,
|
|
865
|
-
origins: ["https://example.com"],
|
|
866
|
-
steps: [],
|
|
867
|
-
blocks: [],
|
|
868
|
-
risk: "read",
|
|
869
|
-
createdat: now,
|
|
870
|
-
});
|
|
871
|
-
const listed = await store.listtriggers();
|
|
872
|
-
expect(listed[0]?.workflowname).toBe("reader");
|
|
873
|
-
expect((await store.gettriggerule(rule.id))?.id).toBe(rule.id);
|
|
874
|
-
await store.settriggerule(updaterule(rule, { state: { enabled: false } }));
|
|
875
|
-
expect((await store.gettriggerule(rule.id))?.state.enabled).toBe(false);
|
|
876
|
-
await store.removetriggerule(rule.id);
|
|
877
|
-
expect(await store.gettriggerules()).toHaveLength(0);
|
|
878
|
-
expect(await store.listtriggers()).toHaveLength(0);
|
|
879
|
-
});
|
|
880
|
-
|
|
881
|
-
it("stores fire records under the reviewed retention and keeps the queue", async () => {
|
|
882
|
-
const store = new sessionmemory(new fakeadapter());
|
|
883
|
-
await store.setsettings({ triggerretention: 2 });
|
|
884
|
-
await store.addtriggerfire({ id: "f1", ruleid: "r1", at: now, cause: "visit" });
|
|
885
|
-
await store.addtriggerfire({ id: "f2", ruleid: "r1", at: now + 1, cause: "url" });
|
|
886
|
-
await store.addtriggerfire({ id: "f3", ruleid: "r2", at: now + 2, cause: "schedule" });
|
|
887
|
-
expect((await store.listtriggerfires()).map((fire) => fire.id)).toEqual(["f3", "f2"]);
|
|
888
|
-
expect((await store.listtriggerfires("r1")).map((fire) => fire.id)).toEqual(["f2"]);
|
|
889
|
-
await store.settriggerqueue([{ id: "f4", ruleid: "r1", at: now + 3, cause: "menu" }]);
|
|
890
|
-
expect((await store.gettriggerqueue()).map((fire) => fire.cause)).toEqual(["menu"]);
|
|
891
|
-
});
|
|
892
|
-
|
|
893
|
-
it("stores webhook payloads and manual run previews with their confirmation outcomes", async () => {
|
|
894
|
-
const store = new sessionmemory(new fakeadapter());
|
|
895
|
-
await store.addwebhookpayload("r1", { task: "read" }, now);
|
|
896
|
-
await store.addwebhookpayload("r1", { task: "extract" }, now + 1);
|
|
897
|
-
expect((await store.listwebhookpayloads("r1")).map((entry) => entry.payload.task)).toEqual(["extract", "read"]);
|
|
898
|
-
expect(await store.listwebhookpayloads("r2")).toHaveLength(0);
|
|
899
|
-
const preview: manualrun = {
|
|
900
|
-
id: "m1",
|
|
901
|
-
workflowid: "wf1",
|
|
902
|
-
preview: [{ stepid: "s1", kind: "readtext", label: "Read the heading" }],
|
|
903
|
-
at: now,
|
|
904
|
-
};
|
|
905
|
-
await store.addmanualrun(preview);
|
|
906
|
-
await store.addmanualrun({ ...preview, confirmed: true, decidedat: now + 1 });
|
|
907
|
-
const stored = await store.listmanualruns();
|
|
908
|
-
expect(stored[0]?.confirmed).toBe(true);
|
|
909
|
-
expect(stored[0]?.preview[0]?.stepid).toBe("s1");
|
|
910
|
-
await store.settriggerules([armedrule("buttonrule", {}), armedrule("keyrule", { command: "run" })]);
|
|
911
|
-
expect(await store.gettriggerules()).toHaveLength(2);
|
|
912
|
-
});
|
|
913
|
-
|
|
914
|
-
it("records trigger evidence with the fire, launch and suppression counts", () => {
|
|
915
|
-
let progress = recordtrigger(
|
|
916
|
-
undefined,
|
|
917
|
-
plan.id,
|
|
918
|
-
"t1",
|
|
919
|
-
{ family: "arm", detail: "Armed the visit rule", ruleid: "r1", nextfireat: now + 60_000 },
|
|
920
|
-
now,
|
|
921
|
-
);
|
|
922
|
-
progress = recordtrigger(
|
|
923
|
-
progress,
|
|
924
|
-
plan.id,
|
|
925
|
-
"t1",
|
|
926
|
-
{ family: "fire", detail: "The visit rule fired", ruleid: "r1", fires: 1, launches: 1 },
|
|
927
|
-
now + 1,
|
|
928
|
-
);
|
|
929
|
-
progress = recordtrigger(
|
|
930
|
-
progress,
|
|
931
|
-
plan.id,
|
|
932
|
-
"t1",
|
|
933
|
-
{ family: "suppress", detail: "The visit rule suppressed a fire", ruleid: "r1", suppressions: 1, queued: 0 },
|
|
934
|
-
now + 2,
|
|
935
|
-
);
|
|
936
|
-
const evidence = triggerevidences(progress, plan.id, "t1");
|
|
937
|
-
expect(evidence.map((entry) => entry.family)).toEqual(["arm", "fire", "suppress"]);
|
|
938
|
-
expect(evidence[1]?.fires).toBe(1);
|
|
939
|
-
expect(triggerevidences(progress, "other", "t1")).toHaveLength(0);
|
|
940
|
-
});
|
|
941
|
-
});
|