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