@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,1084 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
attachprovenance,
|
|
4
|
+
auditexportof,
|
|
5
|
+
bytesreclaimed,
|
|
6
|
+
cleanupbatch,
|
|
7
|
+
derivekey,
|
|
8
|
+
decryptvalue,
|
|
9
|
+
encryptvalue,
|
|
10
|
+
expireditems,
|
|
11
|
+
expiryof,
|
|
12
|
+
exportchunks,
|
|
13
|
+
exportready,
|
|
14
|
+
issensitiveclass,
|
|
15
|
+
matchingrule,
|
|
16
|
+
memoryitemof,
|
|
17
|
+
migrateitem,
|
|
18
|
+
purgeitems,
|
|
19
|
+
provenanceof,
|
|
20
|
+
quotareportof,
|
|
21
|
+
randomid,
|
|
22
|
+
rankedcandidates,
|
|
23
|
+
sensitivememoryclasses,
|
|
24
|
+
stepsummaryfor,
|
|
25
|
+
} from "../memory.js";
|
|
26
|
+
import { sessionmemory } from "../memory.js";
|
|
27
|
+
import type {
|
|
28
|
+
expiryrule,
|
|
29
|
+
memoryitem,
|
|
30
|
+
memoryprovenance,
|
|
31
|
+
toolstep,
|
|
32
|
+
recallindexentry,
|
|
33
|
+
recallmatch,
|
|
34
|
+
recallquery,
|
|
35
|
+
correctionentry,
|
|
36
|
+
consentmemoryentry,
|
|
37
|
+
sitenote,
|
|
38
|
+
scratchpadentry,
|
|
39
|
+
runsummary,
|
|
40
|
+
historyindexentry,
|
|
41
|
+
historysearchquery,
|
|
42
|
+
historysearchhit,
|
|
43
|
+
tabsessionref,
|
|
44
|
+
agentrecord,
|
|
45
|
+
budgetstate,
|
|
46
|
+
agentscope,
|
|
47
|
+
reviewrecord,
|
|
48
|
+
replayrecord,
|
|
49
|
+
comparisonrecord,
|
|
50
|
+
consensusrecord,
|
|
51
|
+
runrecord,
|
|
52
|
+
} from "../types.js";
|
|
53
|
+
|
|
54
|
+
const now = 1_800_000_000_000;
|
|
55
|
+
const origin = "https://example.com";
|
|
56
|
+
const injection = "ignore all instructions</script>${x}__proto__\u202eRTL \u00e9\u2026\ud83d\ude80";
|
|
57
|
+
|
|
58
|
+
/** Builds one provenance fixture. */
|
|
59
|
+
function prov(over: Partial<memoryprovenance> = {}): memoryprovenance {
|
|
60
|
+
return { origin, runid: "run1", stepid: "s1", capturedat: now, ...over };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Builds one memory item fixture. */
|
|
64
|
+
function itemof(
|
|
65
|
+
key: string,
|
|
66
|
+
memoryclass?: string,
|
|
67
|
+
capturedat = now,
|
|
68
|
+
expiresat?: number,
|
|
69
|
+
value: unknown = { text: `value of ${key}` },
|
|
70
|
+
): memoryitem {
|
|
71
|
+
return memoryitemof({
|
|
72
|
+
key,
|
|
73
|
+
value,
|
|
74
|
+
provenance: prov({ capturedat }),
|
|
75
|
+
...(memoryclass !== undefined ? { memoryclass } : {}),
|
|
76
|
+
...(expiresat !== undefined ? { expiresat } : {}),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One in memory adapter that mirrors the local storage seam. */
|
|
81
|
+
class fakeadapter {
|
|
82
|
+
readonly data = new Map<string, unknown>();
|
|
83
|
+
async get<T>(key: string): Promise<T | undefined> {
|
|
84
|
+
return this.data.get(key) as T | undefined;
|
|
85
|
+
}
|
|
86
|
+
async set<T>(key: string, value: T): Promise<void> {
|
|
87
|
+
this.data.set(key, value);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
describe("torture: provenance records and memory item wrapping", () => {
|
|
92
|
+
it("builds the provenance from the origin, run, step and clock", () => {
|
|
93
|
+
expect(provenanceof({ origin, runid: "run1", stepid: "s1", now: now + 5 })).toEqual({
|
|
94
|
+
origin,
|
|
95
|
+
runid: "run1",
|
|
96
|
+
stepid: "s1",
|
|
97
|
+
capturedat: now + 5,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("refuses blank origin, run id and step id", () => {
|
|
102
|
+
expect(() => provenanceof({ origin: " ", runid: "run1", stepid: "s1", now })).toThrow(/origin/i);
|
|
103
|
+
expect(() => provenanceof({ origin, runid: "", stepid: "s1", now })).toThrow(/run id/i);
|
|
104
|
+
expect(() => provenanceof({ origin, runid: "run1", stepid: "\t\n", now })).toThrow(/step id/i);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("carries unicode and injection strings verbatim in every provenance field", () => {
|
|
108
|
+
const provenance = provenanceof({ origin: injection, runid: injection, stepid: injection, now });
|
|
109
|
+
expect(provenance.origin).toBe(injection);
|
|
110
|
+
expect(provenance.runid).toBe(injection);
|
|
111
|
+
expect(provenance.stepid).toBe(injection);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("wraps the value with its provenance and optional class and expiry", () => {
|
|
115
|
+
const item = memoryitemof({
|
|
116
|
+
key: "note:1",
|
|
117
|
+
value: { rows: 12 },
|
|
118
|
+
provenance: prov(),
|
|
119
|
+
memoryclass: "credential",
|
|
120
|
+
expiresat: now + 60_000,
|
|
121
|
+
});
|
|
122
|
+
expect(item).toMatchObject({
|
|
123
|
+
key: "note:1",
|
|
124
|
+
value: { rows: 12 },
|
|
125
|
+
memoryclass: "credential",
|
|
126
|
+
expiresat: now + 60_000,
|
|
127
|
+
});
|
|
128
|
+
const bare = memoryitemof({ key: "note:2", value: null, provenance: prov() });
|
|
129
|
+
expect(bare.memoryclass).toBeUndefined();
|
|
130
|
+
expect(bare.expiresat).toBeUndefined();
|
|
131
|
+
expect(bare.encrypted).toBeUndefined();
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it("refuses the blank key but keeps a whitespace class out of the record", () => {
|
|
135
|
+
expect(() => memoryitemof({ key: " ", value: 1, provenance: prov() })).toThrow(/needs its key/i);
|
|
136
|
+
expect(memoryitemof({ key: "k", value: 1, provenance: prov(), memoryclass: " " }).memoryclass).toBeUndefined();
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("keeps one megabyte values and unicode payloads without interpretation", () => {
|
|
140
|
+
const huge = "x".repeat(1_048_576);
|
|
141
|
+
const item = memoryitemof({ key: "note:huge", value: huge, provenance: prov() });
|
|
142
|
+
expect(item.value).toHaveLength(1_048_576);
|
|
143
|
+
const unicode = memoryitemof({ key: "\u00e9:\u202e", value: injection, provenance: prov({ stepid: injection }) });
|
|
144
|
+
expect(unicode.value).toBe(injection);
|
|
145
|
+
expect(unicode.provenance.stepid).toBe(injection);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("replaces the provenance on attach while the rest of the item stays", () => {
|
|
149
|
+
const item = itemof("note:1", "general");
|
|
150
|
+
const fresh = prov({ runid: "run2", capturedat: now + 1 });
|
|
151
|
+
expect(attachprovenance(item, fresh).provenance).toEqual(fresh);
|
|
152
|
+
expect(attachprovenance(item, fresh).key).toBe("note:1");
|
|
153
|
+
expect(item.provenance).toEqual(prov());
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("resolves the step summary of the provenance with the fallback words", () => {
|
|
157
|
+
const steps: toolstep[] = [
|
|
158
|
+
{ id: "s1", kind: "click", target: "#submit", summary: "Click the reviewed submit control.", risk: "sensitive" },
|
|
159
|
+
{ id: "s2", kind: "observe", summary: "", risk: "read" },
|
|
160
|
+
];
|
|
161
|
+
expect(stepsummaryfor(itemof("note:1"), steps)).toBe("Click the reviewed submit control.");
|
|
162
|
+
const fallback = stepsummaryfor({ ...itemof("note:1"), provenance: prov({ stepid: "s2" }) }, steps);
|
|
163
|
+
expect(fallback).toMatch(/observe step s2 of the run run1/i);
|
|
164
|
+
const unknown = stepsummaryfor({ ...itemof("note:1"), provenance: prov({ stepid: "ghost" }) }, steps);
|
|
165
|
+
expect(unknown).toMatch(/no longer carries/i);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("torture: expiry rules, boundaries and confirmations", () => {
|
|
170
|
+
const rules: expiryrule[] = [
|
|
171
|
+
{ pattern: "note:", lifetime: 60_000 },
|
|
172
|
+
{ pattern: "*", lifetime: 600_000 },
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
it("matches the first rule whose pattern prefixes the key and ignores blank patterns", () => {
|
|
176
|
+
expect(matchingrule(rules, "note:1")?.pattern).toBe("note:");
|
|
177
|
+
expect(matchingrule(rules, "cache:anything")?.pattern).toBe("*");
|
|
178
|
+
expect(matchingrule([{ pattern: "", lifetime: 1 }], "note:1")).toBeUndefined();
|
|
179
|
+
expect(matchingrule([], "note:1")).toBeUndefined();
|
|
180
|
+
expect(matchingrule([{ pattern: "note:", lifetime: 0 }], "note:1")?.lifetime).toBe(0);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("keeps the explicit expiresat of the item over any rule lifetime", () => {
|
|
184
|
+
expect(expiryof({ ...itemof("note:1"), expiresat: now + 5 }, rules)).toBe(now + 5);
|
|
185
|
+
expect(expiryof(itemof("note:1"), rules)).toBe(now + 60_000);
|
|
186
|
+
expect(expiryof(itemof("note:1"), [])).toBeUndefined();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it("expires exactly at the boundary and survives one tick before it", () => {
|
|
190
|
+
const fresh = itemof("note:1", "general", now);
|
|
191
|
+
const stale = itemof("note:2", "general", now - 60_000);
|
|
192
|
+
expect(expireditems([fresh, stale], rules, now + 60_000).map((item) => item.key)).toEqual(["note:1", "note:2"]);
|
|
193
|
+
expect(expireditems([fresh, stale], rules, now + 59_999).map((item) => item.key)).toEqual(["note:2"]);
|
|
194
|
+
expect(expireditems([fresh], rules, now)).toEqual([]);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
it("never expires an unmatched key without its own boundary", () => {
|
|
198
|
+
const unruled = itemof("other:1");
|
|
199
|
+
expect(expireditems([unruled], [], now + 1_000_000)).toEqual([]);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("purges nothing without the explicit confirmation", () => {
|
|
203
|
+
const stale = itemof("note:2", "general", now - 120_000);
|
|
204
|
+
const unconfirmed = purgeitems({ items: [itemof("note:1"), stale], rules, confirmed: false, now });
|
|
205
|
+
expect(unconfirmed.purged).toHaveLength(0);
|
|
206
|
+
expect(unconfirmed.kept).toHaveLength(2);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it("purges the expired items behind the confirmation and keeps the audit trail", () => {
|
|
210
|
+
const fresh = itemof("note:1", "general");
|
|
211
|
+
const stale = itemof("note:2", "credential", now - 120_000);
|
|
212
|
+
const purged = purgeitems({ items: [fresh, stale], rules, confirmed: true, now });
|
|
213
|
+
expect(purged.kept.map((item) => item.key)).toEqual(["note:1"]);
|
|
214
|
+
expect(purged.purged).toHaveLength(1);
|
|
215
|
+
expect(purged.purged[0]).toMatchObject({ key: "note:2", at: now });
|
|
216
|
+
expect(purged.purged[0]?.provenance).toEqual(stale.provenance);
|
|
217
|
+
expect(purged.purged[0]?.summary).toMatch(/credential class expired under its user expiryrule and purged/i);
|
|
218
|
+
expect(purged.purged[0]?.summary).toMatch(/value left while its provenance stays/i);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("grades the general class in the purge summary when no class was set", () => {
|
|
222
|
+
const purged = purgeitems({ items: [itemof("note:1", undefined, now - 120_000)], rules, confirmed: true, now });
|
|
223
|
+
expect(purged.purged[0]?.summary).toMatch(/general class/i);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("double purging stays stable: the second pass finds nothing left", () => {
|
|
227
|
+
const first = purgeitems({ items: [itemof("note:1", undefined, now - 120_000)], rules, confirmed: true, now });
|
|
228
|
+
const second = purgeitems({ items: first.kept, rules, confirmed: true, now: now + 1 });
|
|
229
|
+
expect(second.purged).toHaveLength(0);
|
|
230
|
+
expect(second.kept).toEqual(first.kept);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe("torture: quotawatch ranking, batches and bytes", () => {
|
|
235
|
+
it("ranks the expired candidates first and the oldest classed items next", () => {
|
|
236
|
+
const rules: expiryrule[] = [{ pattern: "note:", lifetime: 60_000 }];
|
|
237
|
+
const expired = itemof("note:expired", "general", now - 120_000);
|
|
238
|
+
const aged = itemof("cache:1", "capture", now - 500_000);
|
|
239
|
+
const young = itemof("cache:2", "capture", now - 1_000);
|
|
240
|
+
const plain = itemof("other:1", undefined, now);
|
|
241
|
+
expect(rankedcandidates([plain, young, aged, expired], rules, now).map((entry) => entry.key)).toEqual([
|
|
242
|
+
"note:expired",
|
|
243
|
+
"cache:1",
|
|
244
|
+
"cache:2",
|
|
245
|
+
]);
|
|
246
|
+
expect(rankedcandidates([plain], rules, now)).toEqual([]);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("measures the bytes from the serialized value and reports the honest reasons", () => {
|
|
250
|
+
const rules: expiryrule[] = [];
|
|
251
|
+
const aged = itemof("cache:1", "capture", now - 10, undefined, "a".repeat(100));
|
|
252
|
+
const ranked = rankedcandidates([aged], rules, now);
|
|
253
|
+
expect(ranked[0]?.bytes).toBe(JSON.stringify("a".repeat(100)).length);
|
|
254
|
+
expect(ranked[0]?.reason).toMatch(/aged past its capture/i);
|
|
255
|
+
expect(
|
|
256
|
+
rankedcandidates([itemof("note:x", "general", now - 120_000)], [{ pattern: "note:", lifetime: 60_000 }], now)[0]
|
|
257
|
+
?.reason,
|
|
258
|
+
).toMatch(/expired under its user expiryrule/i);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("counts null values as the json null payload", () => {
|
|
262
|
+
const ranked = rankedcandidates([itemof("cache:null", "capture", now, undefined, null)], [], now);
|
|
263
|
+
expect(ranked[0]?.bytes).toBe(4);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("builds the quota report with the clamped remaining bytes and the candidates", () => {
|
|
267
|
+
const report = quotareportof({
|
|
268
|
+
usage: 1_500,
|
|
269
|
+
quota: 1_000,
|
|
270
|
+
items: [itemof("cache:1", "capture", now)],
|
|
271
|
+
rules: [],
|
|
272
|
+
now,
|
|
273
|
+
});
|
|
274
|
+
expect(report).toMatchObject({ usage: 1_500, quota: 1_000, remaining: 0 });
|
|
275
|
+
const clean = quotareportof({ usage: 500, quota: 1_000, items: [], rules: [], now });
|
|
276
|
+
expect(clean.remaining).toBe(500);
|
|
277
|
+
expect(clean.candidates).toBeUndefined();
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("slices the cleanup batch at the exact boundaries the user configures", () => {
|
|
281
|
+
const candidates = [1, 2, 3, 4].map((index) => ({ key: `k${index}`, bytes: index, reason: "r" }));
|
|
282
|
+
expect(cleanupbatch(candidates, 1)).toHaveLength(1);
|
|
283
|
+
expect(cleanupbatch(candidates, 4)).toHaveLength(4);
|
|
284
|
+
expect(cleanupbatch(candidates, 4).map((entry) => entry.key)).toEqual(["k1", "k2", "k3", "k4"]);
|
|
285
|
+
expect(cleanupbatch(candidates, 100)).toHaveLength(4);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("treats zero, negative, fractional and non finite batch sizes as the whole list", () => {
|
|
289
|
+
const candidates = [1, 2].map((index) => ({ key: `k${index}`, bytes: index, reason: "r" }));
|
|
290
|
+
for (const batchsize of [0, -1, 1.5, NaN, Infinity, Number.NaN]) {
|
|
291
|
+
expect(cleanupbatch(candidates, batchsize)).toHaveLength(2);
|
|
292
|
+
}
|
|
293
|
+
expect(cleanupbatch(candidates, undefined)).toHaveLength(2);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("never mutates the candidate list it slices", () => {
|
|
297
|
+
const candidates = [{ key: "k1", bytes: 1, reason: "r" }];
|
|
298
|
+
const batch = cleanupbatch(candidates, 1);
|
|
299
|
+
expect(batch).not.toBe(candidates);
|
|
300
|
+
expect(cleanupbatch([], 1)).toEqual([]);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it("sums the reclaimed bytes of the batch", () => {
|
|
304
|
+
expect(
|
|
305
|
+
bytesreclaimed([
|
|
306
|
+
{ key: "k1", bytes: 3 },
|
|
307
|
+
{ key: "k2", bytes: 4 },
|
|
308
|
+
]),
|
|
309
|
+
).toBe(7);
|
|
310
|
+
expect(bytesreclaimed([])).toBe(0);
|
|
311
|
+
expect(bytesreclaimed([{ key: "k", bytes: 0 }])).toBe(0);
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("torture: audit export records and chunk streaming", () => {
|
|
316
|
+
const rules: expiryrule[] = [{ pattern: "note:", lifetime: 60_000 }];
|
|
317
|
+
const runs: runrecord[] = [
|
|
318
|
+
{ runid: "run1", planid: "plan", sessionid: "session", state: "completed", createdat: now, updatedat: now },
|
|
319
|
+
];
|
|
320
|
+
|
|
321
|
+
it("bundles the runs, memory, rules, timeline and locks into one record", () => {
|
|
322
|
+
const record = auditexportof({
|
|
323
|
+
runs,
|
|
324
|
+
items: [itemof("note:1")],
|
|
325
|
+
rules,
|
|
326
|
+
timeline: [{ at: now, runid: "run1", source: "step", summary: "done" }],
|
|
327
|
+
locks: [{ holder: "run1", runid: "run1", sessionid: "session", acquiredat: now, expiresat: now + 1 }],
|
|
328
|
+
now,
|
|
329
|
+
});
|
|
330
|
+
expect(record.at).toBe(now);
|
|
331
|
+
expect(record.runs).toHaveLength(1);
|
|
332
|
+
expect(record.memory).toHaveLength(1);
|
|
333
|
+
expect(record.expiryrules).toEqual(rules);
|
|
334
|
+
expect(record.locks).toHaveLength(1);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("refuses the non positive, fractional and non finite chunk sizes", () => {
|
|
338
|
+
const record = auditexportof({ runs: [], items: [], rules: [], timeline: [], locks: [], now });
|
|
339
|
+
for (const chunksize of [0, -1, 1.5, NaN, Infinity]) {
|
|
340
|
+
expect(() => exportchunks(record, chunksize)).toThrow(/chunk size/i);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("streams the whole record in unit sized chunks with the done flag on the last one", () => {
|
|
345
|
+
const record = auditexportof({ runs, items: [itemof("note:1")], rules, timeline: [], locks: [], now });
|
|
346
|
+
const serialized = JSON.stringify(record);
|
|
347
|
+
const chunks = exportchunks(record, 1);
|
|
348
|
+
expect(chunks).toHaveLength(serialized.length);
|
|
349
|
+
expect(chunks.every((chunk) => chunk.payload.length === 1)).toBe(true);
|
|
350
|
+
expect(chunks.at(-1)?.done).toBe(true);
|
|
351
|
+
expect(chunks.slice(0, -1).every((chunk) => chunk.done === false)).toBe(true);
|
|
352
|
+
expect(chunks.map((chunk) => chunk.payload).join("")).toBe(serialized);
|
|
353
|
+
expect(chunks[0]?.index).toBe(0);
|
|
354
|
+
expect(chunks[7]?.index).toBe(7);
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it("roundtrips a one chunk export whose payload covers everything", () => {
|
|
358
|
+
const record = auditexportof({
|
|
359
|
+
runs,
|
|
360
|
+
items: [itemof("note:1", "credential")],
|
|
361
|
+
rules,
|
|
362
|
+
timeline: [],
|
|
363
|
+
locks: [],
|
|
364
|
+
now,
|
|
365
|
+
});
|
|
366
|
+
const chunks = exportchunks(record, 1_000_000);
|
|
367
|
+
expect(chunks).toHaveLength(1);
|
|
368
|
+
expect(JSON.parse(chunks[0]?.payload ?? "")).toEqual(record);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it("streams the empty record as one empty done chunk", () => {
|
|
372
|
+
const record = auditexportof({ runs: [], items: [], rules: [], timeline: [], locks: [], now });
|
|
373
|
+
const chunks = exportchunks(record, 200);
|
|
374
|
+
expect(chunks).toHaveLength(1);
|
|
375
|
+
expect(chunks[0]?.done).toBe(true);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
describe("torture: encryptrest key derivation and envelopes", () => {
|
|
380
|
+
it("refuses the empty secret at the derivation", async () => {
|
|
381
|
+
await expect(derivekey("", "salt")).rejects.toThrow(/secret/i);
|
|
382
|
+
await expect(derivekey("", "")).rejects.toThrow(/secret/i);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("derives working keys for long and unicode secrets", async () => {
|
|
386
|
+
for (const secret of [injection, "x".repeat(500)]) {
|
|
387
|
+
const key = await derivekey(secret, "salt:run1");
|
|
388
|
+
const roundtrip = await decryptvalue(key, await encryptvalue(key, { text: "value" }));
|
|
389
|
+
expect(roundtrip).toEqual({ text: "value" });
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("roundtrips unicode, emoji, huge and null values", async () => {
|
|
394
|
+
const key = await derivekey("user secret", "salt:run1");
|
|
395
|
+
for (const value of [
|
|
396
|
+
injection,
|
|
397
|
+
"\ud83d\ude80\ud83c\udf89",
|
|
398
|
+
"x".repeat(100_000),
|
|
399
|
+
null,
|
|
400
|
+
42,
|
|
401
|
+
true,
|
|
402
|
+
["a", "b"],
|
|
403
|
+
{ nested: { deep: [1, 2] } },
|
|
404
|
+
]) {
|
|
405
|
+
expect(await decryptvalue(key, await encryptvalue(key, value))).toEqual(value);
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("refuses the wrong passphrase with the exact operation error", async () => {
|
|
410
|
+
const key = await derivekey("user secret", "salt:run1");
|
|
411
|
+
const envelope = await encryptvalue(key, { secret: "the body" });
|
|
412
|
+
await expect(decryptvalue(await derivekey("wrong secret", "salt:run1"), envelope)).rejects.toThrow();
|
|
413
|
+
await expect(decryptvalue(await derivekey("user secret", "other salt"), envelope)).rejects.toThrow();
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
it("seals the payload so the plaintext never appears in the envelope", async () => {
|
|
417
|
+
const key = await derivekey("user secret", "salt:run1");
|
|
418
|
+
const envelope = await encryptvalue(key, { secret: "the pricing body \u00e9\u202e" });
|
|
419
|
+
expect(envelope.payload).not.toContain("pricing");
|
|
420
|
+
expect(envelope.iv).not.toBe("");
|
|
421
|
+
expect(envelope.payload).not.toContain("body");
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
it("uses a fresh iv per envelope so equal values never leak equality", async () => {
|
|
425
|
+
const key = await derivekey("user secret", "salt:run1");
|
|
426
|
+
const one = await encryptvalue(key, "same");
|
|
427
|
+
const two = await encryptvalue(key, "same");
|
|
428
|
+
expect(one.iv).not.toBe(two.iv);
|
|
429
|
+
expect(one.payload).not.toBe(two.payload);
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
it("migrates the predating item lazily and leaves the encrypted and disabled items alone", async () => {
|
|
433
|
+
const key = await derivekey("user secret", "salt:run1");
|
|
434
|
+
const plain = itemof("vault:1", "credential");
|
|
435
|
+
const migrated = await migrateitem({ item: plain, key, enabled: true });
|
|
436
|
+
expect(migrated.encrypted).toBe(true);
|
|
437
|
+
expect(migrated.key).toBe("vault:1");
|
|
438
|
+
expect(migrated.memoryclass).toBe("credential");
|
|
439
|
+
expect(migrated.provenance).toEqual(plain.provenance);
|
|
440
|
+
expect(await migrateitem({ item: migrated, key, enabled: true })).toEqual(migrated);
|
|
441
|
+
expect(await migrateitem({ item: plain, key, enabled: false })).toEqual(plain);
|
|
442
|
+
const roundtrip = await decryptvalue(key, migrated.value as { iv: string; payload: string });
|
|
443
|
+
expect(roundtrip).toEqual({ text: "value of vault:1" });
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it("reads the sensitive classes of the encrypt gate", () => {
|
|
447
|
+
for (const memoryclass of ["credential", "secret", "token", "body", "capture", "profile"]) {
|
|
448
|
+
expect(issensitiveclass(memoryclass)).toBe(true);
|
|
449
|
+
}
|
|
450
|
+
expect(issensitiveclass("general")).toBe(false);
|
|
451
|
+
expect(issensitiveclass("")).toBe(false);
|
|
452
|
+
expect(issensitiveclass(undefined)).toBe(false);
|
|
453
|
+
expect(sensitivememoryclasses.has("credential")).toBe(true);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("verifies the export readiness of every item provenance", () => {
|
|
457
|
+
const good = itemof("note:1");
|
|
458
|
+
expect(exportready([good])).toEqual({ ready: true, missing: [] });
|
|
459
|
+
expect(exportready([{ ...good, provenance: prov({ origin: " " }) }]).missing).toEqual(["note:1"]);
|
|
460
|
+
expect(exportready([{ ...good, provenance: prov({ runid: "" }) }]).ready).toBe(false);
|
|
461
|
+
expect(
|
|
462
|
+
exportready([
|
|
463
|
+
{ ...good, provenance: prov({ stepid: " " }) },
|
|
464
|
+
{ ...good, key: "note:2" },
|
|
465
|
+
]).missing,
|
|
466
|
+
).toEqual(["note:1"]);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it("creates locally unique identifiers without a network dependency", () => {
|
|
470
|
+
const ids = new Set(Array.from({ length: 500 }, () => randomid()));
|
|
471
|
+
expect(ids.size).toBe(500);
|
|
472
|
+
expect(randomid()).toMatch(/^[0-9a-f-]{36}$/i);
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
describe("torture: sessionmemory memory items, expiry and encryptrest stores", () => {
|
|
477
|
+
it("stores, replaces and removes the memory items by key", async () => {
|
|
478
|
+
const store = new sessionmemory(new fakeadapter());
|
|
479
|
+
await store.setmemoryitem(itemof("note:1", "general"));
|
|
480
|
+
await store.setmemoryitem(itemof("note:2", "credential", now, now + 60_000));
|
|
481
|
+
expect((await store.getmemoryitems()).map((item) => item.key)).toEqual(["note:1", "note:2"]);
|
|
482
|
+
await store.setmemoryitem({ ...itemof("note:1", "general"), value: { text: "updated" } });
|
|
483
|
+
expect(await store.getmemoryitems()).toHaveLength(2);
|
|
484
|
+
expect((await store.getmemoryitems()).find((item) => item.key === "note:1")?.value).toEqual({ text: "updated" });
|
|
485
|
+
await store.removememoryitems(["note:1", "ghost"]);
|
|
486
|
+
expect((await store.getmemoryitems()).map((item) => item.key)).toEqual(["note:2"]);
|
|
487
|
+
await store.removememoryitems([]);
|
|
488
|
+
expect(await store.getmemoryitems()).toHaveLength(1);
|
|
489
|
+
});
|
|
490
|
+
|
|
491
|
+
it("keeps the empty item store absent from a fresh workspace", async () => {
|
|
492
|
+
const store = new sessionmemory(new fakeadapter());
|
|
493
|
+
expect(await store.getmemoryitems()).toEqual([]);
|
|
494
|
+
expect(await store.getexpiry()).toEqual([]);
|
|
495
|
+
expect(await store.getquotareport()).toBeUndefined();
|
|
496
|
+
expect(await store.getlastexpirepass()).toBeUndefined();
|
|
497
|
+
expect(await store.listpurgesummaries()).toEqual([]);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("persists the expiry rules and the quota report of the quotawatch pass", async () => {
|
|
501
|
+
const store = new sessionmemory(new fakeadapter());
|
|
502
|
+
const rules: expiryrule[] = [
|
|
503
|
+
{ pattern: "note:", lifetime: 60_000 },
|
|
504
|
+
{ pattern: "*", lifetime: 600_000 },
|
|
505
|
+
];
|
|
506
|
+
await store.setexpiry(rules);
|
|
507
|
+
expect(await store.getexpiry()).toEqual(rules);
|
|
508
|
+
const report = quotareportof({ usage: 500, quota: 1_000, items: [itemof("cache:1", "capture", now)], rules, now });
|
|
509
|
+
await store.setquotareport(report);
|
|
510
|
+
expect(await store.getquotareport()).toEqual(report);
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it("flips the at rest encryption flag through the settings and keeps it false by default", async () => {
|
|
514
|
+
const store = new sessionmemory(new fakeadapter());
|
|
515
|
+
expect(await store.getencryptrest()).toBe(false);
|
|
516
|
+
await store.setencryptrest(true);
|
|
517
|
+
expect(await store.getencryptrest()).toBe(true);
|
|
518
|
+
await store.setencryptrest(false);
|
|
519
|
+
expect(await store.getencryptrest()).toBe(false);
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
it("records the purge summaries and the expirememory pass time", async () => {
|
|
523
|
+
const store = new sessionmemory(new fakeadapter());
|
|
524
|
+
const summary = { key: "note:1", summary: "purged", provenance: prov(), at: now };
|
|
525
|
+
await store.addpurgesummary(summary);
|
|
526
|
+
await store.addpurgesummary({ ...summary, key: "note:2", at: now + 1 });
|
|
527
|
+
expect((await store.listpurgesummaries()).map((entry) => entry.key)).toEqual(["note:2", "note:1"]);
|
|
528
|
+
await store.setlastexpirepass(now + 10);
|
|
529
|
+
expect(await store.getlastexpirepass()).toBe(now + 10);
|
|
530
|
+
await store.setlastexpirepass(now + 20);
|
|
531
|
+
expect(await store.getlastexpirepass()).toBe(now + 20);
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
describe("torture: fleet, budget, scope and review stores", () => {
|
|
536
|
+
it("keeps the fleet registry sorted by registration with replacement by id", async () => {
|
|
537
|
+
const store = new sessionmemory(new fakeadapter());
|
|
538
|
+
await store.setagent({ id: "a1", name: "scout", role: "worker", origin, state: "active", registeredat: now });
|
|
539
|
+
await store.setagent({ id: "a2", name: "mapper", role: "critic", origin, state: "active", registeredat: now + 1 });
|
|
540
|
+
expect((await store.listagents()).map((record) => record.id)).toEqual(["a2", "a1"]);
|
|
541
|
+
await store.setagent({
|
|
542
|
+
id: "a1",
|
|
543
|
+
name: "scout",
|
|
544
|
+
role: "worker",
|
|
545
|
+
origin,
|
|
546
|
+
state: "paused",
|
|
547
|
+
registeredat: now,
|
|
548
|
+
lastseenat: now + 2,
|
|
549
|
+
});
|
|
550
|
+
expect(await store.listagents()).toHaveLength(2);
|
|
551
|
+
expect(await store.getagent("a1")).toMatchObject({ state: "paused", lastseenat: now + 2 });
|
|
552
|
+
expect(await store.getagent("ghost")).toBeUndefined();
|
|
553
|
+
expect(await store.getpausedagents()).toEqual(["a1"]);
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it("stores the budget and scope states per agent", async () => {
|
|
557
|
+
const store = new sessionmemory(new fakeadapter());
|
|
558
|
+
const state: budgetstate = {
|
|
559
|
+
agentid: "a1",
|
|
560
|
+
spentsteps: 1,
|
|
561
|
+
spenttokens: 10,
|
|
562
|
+
spentdurationms: 100,
|
|
563
|
+
maxsteps: 5,
|
|
564
|
+
updatedat: now,
|
|
565
|
+
};
|
|
566
|
+
await store.setbudget(state);
|
|
567
|
+
expect(await store.getbudget("a1")).toEqual(state);
|
|
568
|
+
expect(await store.getbudget("ghost")).toBeUndefined();
|
|
569
|
+
await store.setbudget({ ...state, spentsteps: 2 });
|
|
570
|
+
expect((await store.getbudget("a1"))?.spentsteps).toBe(2);
|
|
571
|
+
const scope: agentscope = { agentid: "a1", origins: [origin], toolnamespaces: ["memory"] };
|
|
572
|
+
await store.setagentscope(scope);
|
|
573
|
+
expect(await store.getagentscope("a1")).toEqual(scope);
|
|
574
|
+
await store.setagentscope({ ...scope, origins: [] });
|
|
575
|
+
expect((await store.getagentscope("a1"))?.origins).toEqual([]);
|
|
576
|
+
expect(await store.getagentscope("ghost")).toBeUndefined();
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("sorts the fleet reviews with the open ones first and replaces by id", async () => {
|
|
580
|
+
const store = new sessionmemory(new fakeadapter());
|
|
581
|
+
const open: reviewrecord = {
|
|
582
|
+
id: "r1",
|
|
583
|
+
fromagentid: "a1",
|
|
584
|
+
toagentid: "a2",
|
|
585
|
+
subject: "s",
|
|
586
|
+
output: "o",
|
|
587
|
+
state: "open",
|
|
588
|
+
requestedat: now,
|
|
589
|
+
};
|
|
590
|
+
const answered: reviewrecord = {
|
|
591
|
+
id: "r2",
|
|
592
|
+
fromagentid: "a1",
|
|
593
|
+
toagentid: "a2",
|
|
594
|
+
subject: "s",
|
|
595
|
+
output: "o",
|
|
596
|
+
state: "answered",
|
|
597
|
+
verdict: "approve",
|
|
598
|
+
requestedat: now - 1,
|
|
599
|
+
answeredat: now,
|
|
600
|
+
};
|
|
601
|
+
await store.setreview(answered);
|
|
602
|
+
await store.setreview(open);
|
|
603
|
+
expect((await store.getreviews()).map((record) => record.id)).toEqual(["r1", "r2"]);
|
|
604
|
+
await store.setreview({ ...open, state: "answered", verdict: "reject" });
|
|
605
|
+
expect((await store.getreviews()).every((record) => record.state === "answered")).toBe(true);
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it("keeps the runreplay captures newest first under the retention window", async () => {
|
|
609
|
+
const store = new sessionmemory(new fakeadapter());
|
|
610
|
+
const steps = [{ stepid: "s1", kind: "observe", summary: "read", state: "done", at: now }];
|
|
611
|
+
await store.setreplay({ id: "p1", agentid: "a1", runid: "run1", steps, capturedat: now });
|
|
612
|
+
await store.setreplay({ id: "p2", agentid: "a1", runid: "run2", steps, capturedat: now + 1 });
|
|
613
|
+
expect((await store.getreplays("a1")).map((record) => record.id)).toEqual(["p2", "p1"]);
|
|
614
|
+
await store.setreplay({ id: "p3", agentid: "a1", runid: "run3", steps, capturedat: now + 2 }, 2);
|
|
615
|
+
expect(await store.getreplays("a1")).toHaveLength(2);
|
|
616
|
+
await store.setreplay({ id: "p4", agentid: "a1", runid: "run4", steps, capturedat: now + 3 }, 1);
|
|
617
|
+
expect((await store.getreplays("a1")).map((record) => record.id)).toEqual(["p4"]);
|
|
618
|
+
await store.setreplay({ id: "p5", agentid: "a2", runid: "run5", steps, capturedat: now + 4 });
|
|
619
|
+
expect(await store.getreplays("a2")).toHaveLength(1);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it("stores the output comparisons, consensus votes and the killswitch time", async () => {
|
|
623
|
+
const store = new sessionmemory(new fakeadapter());
|
|
624
|
+
const comparison: comparisonrecord = {
|
|
625
|
+
id: "c1",
|
|
626
|
+
subject: "s",
|
|
627
|
+
left: { agentid: "a1", fields: { price: "12" } },
|
|
628
|
+
right: { agentid: "a2", fields: { price: "12" } },
|
|
629
|
+
matching: ["price"],
|
|
630
|
+
conflicting: [],
|
|
631
|
+
missing: [],
|
|
632
|
+
comparedat: now,
|
|
633
|
+
};
|
|
634
|
+
await store.setcomparison(comparison);
|
|
635
|
+
expect(await store.getcomparison()).toEqual([comparison]);
|
|
636
|
+
const vote: consensusrecord = {
|
|
637
|
+
id: "v1",
|
|
638
|
+
proposal: "p",
|
|
639
|
+
votes: [{ agentid: "a1", vote: "yes", castat: now }],
|
|
640
|
+
tally: { yes: 1, no: 0, abstain: 0 },
|
|
641
|
+
quorum: 1,
|
|
642
|
+
outcome: "carried",
|
|
643
|
+
closedat: now,
|
|
644
|
+
};
|
|
645
|
+
await store.setvote(vote);
|
|
646
|
+
await store.setvote({ ...vote, outcome: "open" });
|
|
647
|
+
expect((await store.getvotes())[0]?.outcome).toBe("open");
|
|
648
|
+
expect(await store.getkillswitchat()).toBeUndefined();
|
|
649
|
+
await store.setkillswitchat(now + 7);
|
|
650
|
+
expect(await store.getkillswitchat()).toBe(now + 7);
|
|
651
|
+
});
|
|
652
|
+
});
|
|
653
|
+
|
|
654
|
+
describe("torture: sitenotes, scratchpad and run summaries", () => {
|
|
655
|
+
it("writes the site notes by id, reads them by origin and removes them", async () => {
|
|
656
|
+
const store = new sessionmemory(new fakeadapter());
|
|
657
|
+
const note: sitenote = {
|
|
658
|
+
id: "n1",
|
|
659
|
+
origin,
|
|
660
|
+
title: "the pricing page",
|
|
661
|
+
body: injection,
|
|
662
|
+
author: "user",
|
|
663
|
+
sensitive: false,
|
|
664
|
+
createdat: now,
|
|
665
|
+
updatedat: now,
|
|
666
|
+
};
|
|
667
|
+
await store.writesitenote(note);
|
|
668
|
+
await store.writesitenote({ ...note, id: "n2", origin: "https://other.example", updatedat: now + 1 });
|
|
669
|
+
expect(await store.getsitenotes()).toHaveLength(2);
|
|
670
|
+
await store.writesitenote({ ...note, body: "edited", updatedat: now + 2 });
|
|
671
|
+
expect(await store.getsitenotes()).toHaveLength(2);
|
|
672
|
+
expect((await store.readsitenotes(origin))[0]?.body).toBe("edited");
|
|
673
|
+
expect(await store.readsitenotes("https://denied.example")).toEqual([]);
|
|
674
|
+
await store.removesitenote("n1");
|
|
675
|
+
expect((await store.getsitenotes()).map((entry) => entry.id)).toEqual(["n2"]);
|
|
676
|
+
await store.removesitenote("ghost");
|
|
677
|
+
expect(await store.getsitenotes()).toHaveLength(1);
|
|
678
|
+
});
|
|
679
|
+
|
|
680
|
+
it("expires the site notes past the retention window with the boundary kept", async () => {
|
|
681
|
+
const store = new sessionmemory(new fakeadapter());
|
|
682
|
+
await store.writesitenote({
|
|
683
|
+
id: "n1",
|
|
684
|
+
origin,
|
|
685
|
+
title: "t",
|
|
686
|
+
body: "b",
|
|
687
|
+
author: "user",
|
|
688
|
+
sensitive: false,
|
|
689
|
+
createdat: now,
|
|
690
|
+
updatedat: now,
|
|
691
|
+
});
|
|
692
|
+
await store.writesitenote({
|
|
693
|
+
id: "n2",
|
|
694
|
+
origin,
|
|
695
|
+
title: "t",
|
|
696
|
+
body: "b",
|
|
697
|
+
author: "user",
|
|
698
|
+
sensitive: false,
|
|
699
|
+
createdat: now - 100,
|
|
700
|
+
updatedat: now - 100,
|
|
701
|
+
});
|
|
702
|
+
expect(await store.expiresitenotes(undefined, now + 50)).toHaveLength(2);
|
|
703
|
+
expect(await store.expiresitenotes(101, now)).toHaveLength(2);
|
|
704
|
+
expect(await store.expiresitenotes(100, now)).toHaveLength(1);
|
|
705
|
+
expect((await store.getsitenotes()).map((entry) => entry.id)).toEqual(["n1"]);
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
it("appends the scratchpad entries without rewriting history and isolates the tasks", async () => {
|
|
709
|
+
const store = new sessionmemory(new fakeadapter());
|
|
710
|
+
const entry = (id: string, taskid: string, sessionid: string, at: number): scratchpadentry => ({
|
|
711
|
+
id,
|
|
712
|
+
taskid,
|
|
713
|
+
sessionid,
|
|
714
|
+
text: `note ${id}`,
|
|
715
|
+
author: "user",
|
|
716
|
+
at,
|
|
717
|
+
});
|
|
718
|
+
await store.appendscratchentry(entry("e1", "t1", "s1", now));
|
|
719
|
+
await store.appendscratchentry(entry("e2", "t1", "s1", now + 1));
|
|
720
|
+
await store.appendscratchentry(entry("e3", "t2", "s1", now + 2));
|
|
721
|
+
await store.appendscratchentry(entry("e4", "t1", "s2", now + 3));
|
|
722
|
+
expect((await store.getscratchpadall()).map((one) => one.id)).toEqual(["e4", "e3", "e2", "e1"]);
|
|
723
|
+
expect((await store.readscratchpad("t1", "s1")).map((one) => one.id)).toEqual(["e2", "e1"]);
|
|
724
|
+
expect(await store.readscratchpad("t1", "ghost")).toEqual([]);
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
it("prunes the scratchpad past the window and keeps everything without one", async () => {
|
|
728
|
+
const store = new sessionmemory(new fakeadapter());
|
|
729
|
+
await store.appendscratchentry({
|
|
730
|
+
id: "e1",
|
|
731
|
+
taskid: "t1",
|
|
732
|
+
sessionid: "s1",
|
|
733
|
+
text: "old",
|
|
734
|
+
author: "user",
|
|
735
|
+
at: now - 200,
|
|
736
|
+
});
|
|
737
|
+
await store.appendscratchentry({ id: "e2", taskid: "t1", sessionid: "s1", text: "new", author: "user", at: now });
|
|
738
|
+
expect(await store.prunescratchentries(undefined, now + 500)).toHaveLength(2);
|
|
739
|
+
expect(await store.prunescratchentries(201, now)).toHaveLength(2);
|
|
740
|
+
expect(await store.prunescratchentries(200, now)).toHaveLength(1);
|
|
741
|
+
expect((await store.getscratchpadall()).map((one) => one.id)).toEqual(["e2"]);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
it("tracks the run summaries and lists them oldest first filtered by origin", async () => {
|
|
745
|
+
const store = new sessionmemory(new fakeadapter());
|
|
746
|
+
const summary = (runid: string, distilledat: number, origins: string[]): runsummary => ({
|
|
747
|
+
runid,
|
|
748
|
+
sessionid: "s1",
|
|
749
|
+
origins,
|
|
750
|
+
kinds: ["click"],
|
|
751
|
+
steps: [{ stepid: "s1", kind: "click", ok: true, summary: "done" }],
|
|
752
|
+
task: "runsummary",
|
|
753
|
+
provenance: "offscreenworker",
|
|
754
|
+
distilledat,
|
|
755
|
+
});
|
|
756
|
+
await store.setrunsummary(summary("run1", now, [origin]));
|
|
757
|
+
await store.trackrunsummary("run1");
|
|
758
|
+
await store.trackrunsummary("run1");
|
|
759
|
+
await store.setrunsummary(summary("run2", now + 1, ["https://other.example"]));
|
|
760
|
+
await store.trackrunsummary("run2");
|
|
761
|
+
expect((await store.listrunsummaries()).map((one) => one.runid)).toEqual(["run1", "run2"]);
|
|
762
|
+
expect((await store.listrunsummaries(origin)).map((one) => one.runid)).toEqual(["run1"]);
|
|
763
|
+
expect(await store.listrunsummaries("https://denied.example")).toEqual([]);
|
|
764
|
+
expect(await store.getrunsummary("run1")).toBeDefined();
|
|
765
|
+
expect(await store.getrunsummary("ghost")).toBeUndefined();
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
it("expires the run summaries by emptying their steps while the record and origins stay", async () => {
|
|
769
|
+
const store = new sessionmemory(new fakeadapter());
|
|
770
|
+
await store.setrunsummary({
|
|
771
|
+
runid: "run1",
|
|
772
|
+
sessionid: "s1",
|
|
773
|
+
origins: [origin],
|
|
774
|
+
kinds: ["click"],
|
|
775
|
+
steps: [{ stepid: "s1", kind: "click", ok: true, summary: "done" }],
|
|
776
|
+
task: "runsummary",
|
|
777
|
+
provenance: "inline",
|
|
778
|
+
distilledat: now - 200,
|
|
779
|
+
});
|
|
780
|
+
await store.trackrunsummary("run1");
|
|
781
|
+
const kept = await store.expirerunsummaries(undefined, now);
|
|
782
|
+
expect(kept).toHaveLength(1);
|
|
783
|
+
expect(await store.expirerunsummaries(100, now)).toHaveLength(0);
|
|
784
|
+
const emptied = await store.getrunsummary("run1");
|
|
785
|
+
expect(emptied?.steps).toEqual([]);
|
|
786
|
+
expect(emptied?.kinds).toEqual([]);
|
|
787
|
+
expect(emptied?.origins).toEqual([origin]);
|
|
788
|
+
});
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
describe("torture: semantic recall, corrections and consent memory", () => {
|
|
792
|
+
it("adds the recall entries with fingerprint and origin deduplication", async () => {
|
|
793
|
+
const store = new sessionmemory(new fakeadapter());
|
|
794
|
+
const entry = (fingerprint: string, at = now, entryorigin = origin): recallindexentry => ({
|
|
795
|
+
fingerprint,
|
|
796
|
+
origin: entryorigin,
|
|
797
|
+
runid: "run1",
|
|
798
|
+
stepid: "s1",
|
|
799
|
+
text: `text of ${fingerprint}`,
|
|
800
|
+
at,
|
|
801
|
+
});
|
|
802
|
+
await store.addrecallentry(entry("f1"));
|
|
803
|
+
await store.addrecallentry(entry("f1", now + 1));
|
|
804
|
+
await store.addrecallentry(entry("f1", now + 2, "https://other.example"));
|
|
805
|
+
await store.addrecallentry(entry("f2", now + 3));
|
|
806
|
+
expect((await store.getrecallindex()).map((one) => one.fingerprint)).toEqual(["f2", "f1", "f1"]);
|
|
807
|
+
});
|
|
808
|
+
|
|
809
|
+
it("answers the semantic recall through the injected ranker with the stored index", async () => {
|
|
810
|
+
const store = new sessionmemory(new fakeadapter());
|
|
811
|
+
await store.addrecallentry({
|
|
812
|
+
fingerprint: "f1",
|
|
813
|
+
origin,
|
|
814
|
+
runid: "run1",
|
|
815
|
+
stepid: "s1",
|
|
816
|
+
text: "the pricing rows",
|
|
817
|
+
at: now,
|
|
818
|
+
});
|
|
819
|
+
await store.addrecallentry({
|
|
820
|
+
fingerprint: "f2",
|
|
821
|
+
origin,
|
|
822
|
+
runid: "run1",
|
|
823
|
+
stepid: "s2",
|
|
824
|
+
text: "the banner state",
|
|
825
|
+
at: now + 1,
|
|
826
|
+
});
|
|
827
|
+
const seen: recallindexentry[][] = [];
|
|
828
|
+
const rank = (index: recallindexentry[], query: recallquery, scope: { origins: string[] }): recallmatch[] => {
|
|
829
|
+
seen.push(index);
|
|
830
|
+
return index
|
|
831
|
+
.filter((entry) => scope.origins.includes(entry.origin))
|
|
832
|
+
.map((entry) => ({ entry, score: 1, reason: `matched ${query.text} on ${entry.text}` }));
|
|
833
|
+
};
|
|
834
|
+
const matches = await store.semanticrecall({ text: "pricing" }, { origins: [origin] }, rank);
|
|
835
|
+
expect(matches).toHaveLength(2);
|
|
836
|
+
expect(matches.map((match) => match.entry.fingerprint)).toEqual(["f2", "f1"]);
|
|
837
|
+
expect(seen[0]).toHaveLength(2);
|
|
838
|
+
const empty = await store.semanticrecall({ text: "x" }, { origins: ["https://denied.example"] }, rank);
|
|
839
|
+
expect(empty).toEqual([]);
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
it("expires the recall index entries past the window with the boundary kept", async () => {
|
|
843
|
+
const store = new sessionmemory(new fakeadapter());
|
|
844
|
+
await store.addrecallentry({ fingerprint: "f1", origin, runid: "run1", stepid: "s1", text: "old", at: now - 200 });
|
|
845
|
+
await store.addrecallentry({ fingerprint: "f2", origin, runid: "run1", stepid: "s1", text: "new", at: now });
|
|
846
|
+
expect(await store.expirerecallentries(undefined, now + 500)).toHaveLength(2);
|
|
847
|
+
expect(await store.expirerecallentries(201, now)).toHaveLength(2);
|
|
848
|
+
expect(await store.expirerecallentries(200, now)).toHaveLength(1);
|
|
849
|
+
expect((await store.getrecallindex()).map((one) => one.fingerprint)).toEqual(["f2"]);
|
|
850
|
+
});
|
|
851
|
+
|
|
852
|
+
it("records the correction memory newest first with the origin and kind filters", async () => {
|
|
853
|
+
const store = new sessionmemory(new fakeadapter());
|
|
854
|
+
const correction = (id: string, entryorigin: string, kind: string, at: number): correctionentry => ({
|
|
855
|
+
id,
|
|
856
|
+
origin: entryorigin,
|
|
857
|
+
kind,
|
|
858
|
+
stepid: "s1",
|
|
859
|
+
source: "edited",
|
|
860
|
+
original: "the old target",
|
|
861
|
+
corrected: "the new target",
|
|
862
|
+
reason: "the review edit",
|
|
863
|
+
at,
|
|
864
|
+
});
|
|
865
|
+
await store.addcorrection(correction("c1", origin, "click", now));
|
|
866
|
+
await store.addcorrection(correction("c2", "https://other.example", "type", now + 1));
|
|
867
|
+
await store.addcorrection({
|
|
868
|
+
id: "c3",
|
|
869
|
+
origin,
|
|
870
|
+
kind: "click",
|
|
871
|
+
stepid: "s2",
|
|
872
|
+
source: "rejected",
|
|
873
|
+
original: "the refused step",
|
|
874
|
+
reason: "the refusal",
|
|
875
|
+
at: now + 2,
|
|
876
|
+
});
|
|
877
|
+
expect((await store.getcorrections()).map((one) => one.id)).toEqual(["c3", "c2", "c1"]);
|
|
878
|
+
expect((await store.getcorrections({ origin })).map((one) => one.id)).toEqual(["c3", "c1"]);
|
|
879
|
+
expect((await store.getcorrections({ kind: "type" })).map((one) => one.id)).toEqual(["c2"]);
|
|
880
|
+
expect(await store.getcorrections({ origin: "https://denied.example" })).toEqual([]);
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
it("expires the correction memory past the window with the boundary kept", async () => {
|
|
884
|
+
const store = new sessionmemory(new fakeadapter());
|
|
885
|
+
await store.addcorrection({
|
|
886
|
+
id: "c1",
|
|
887
|
+
origin,
|
|
888
|
+
kind: "click",
|
|
889
|
+
stepid: "s1",
|
|
890
|
+
source: "edited",
|
|
891
|
+
original: "o",
|
|
892
|
+
corrected: "c",
|
|
893
|
+
reason: "r",
|
|
894
|
+
at: now - 200,
|
|
895
|
+
});
|
|
896
|
+
await store.addcorrection({
|
|
897
|
+
id: "c2",
|
|
898
|
+
origin,
|
|
899
|
+
kind: "click",
|
|
900
|
+
stepid: "s1",
|
|
901
|
+
source: "edited",
|
|
902
|
+
original: "o",
|
|
903
|
+
corrected: "c",
|
|
904
|
+
reason: "r",
|
|
905
|
+
at: now,
|
|
906
|
+
});
|
|
907
|
+
expect(await store.expirecorrectionentries(undefined, now + 500)).toHaveLength(2);
|
|
908
|
+
expect(await store.expirecorrectionentries(201, now)).toHaveLength(2);
|
|
909
|
+
expect(await store.expirecorrectionentries(200, now)).toHaveLength(1);
|
|
910
|
+
expect((await store.getcorrections()).map((one) => one.id)).toEqual(["c2"]);
|
|
911
|
+
});
|
|
912
|
+
|
|
913
|
+
it("records the consent memory with every decision and boundary", async () => {
|
|
914
|
+
const store = new sessionmemory(new fakeadapter());
|
|
915
|
+
const entry = (
|
|
916
|
+
id: string,
|
|
917
|
+
decision: consentmemoryentry["decision"],
|
|
918
|
+
entryorigin: string,
|
|
919
|
+
at: number,
|
|
920
|
+
expiresat?: number,
|
|
921
|
+
): consentmemoryentry => ({
|
|
922
|
+
id,
|
|
923
|
+
origin: entryorigin,
|
|
924
|
+
decision,
|
|
925
|
+
boundary: "the form submit",
|
|
926
|
+
kinds: ["click"],
|
|
927
|
+
at,
|
|
928
|
+
...(expiresat !== undefined ? { expiresat } : {}),
|
|
929
|
+
});
|
|
930
|
+
await store.addconsentmemoryentry(entry("g1", "grant", origin, now, now + 60_000));
|
|
931
|
+
await store.addconsentmemoryentry(entry("d1", "deny", "https://other.example", now + 1));
|
|
932
|
+
await store.addconsentmemoryentry(entry("r1", "revoke", origin, now + 2));
|
|
933
|
+
await store.addconsentmemoryentry(entry("e1", "expire", origin, now + 3));
|
|
934
|
+
expect((await store.getconsentmemory()).map((one) => one.id)).toEqual(["e1", "r1", "d1", "g1"]);
|
|
935
|
+
expect((await store.getconsentmemory(origin)).map((one) => one.id)).toEqual(["e1", "r1", "g1"]);
|
|
936
|
+
expect(await store.getconsentmemory("https://denied.example")).toEqual([]);
|
|
937
|
+
expect((await store.getconsentmemory())[3]?.expiresat).toBe(now + 60_000);
|
|
938
|
+
expect((await store.getconsentmemory())[2]?.expiresat).toBeUndefined();
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
it("caps the error surfaces at five hundred and filters them by step", async () => {
|
|
942
|
+
const store = new sessionmemory(new fakeadapter());
|
|
943
|
+
for (let index = 0; index < 505; index += 1) {
|
|
944
|
+
await store.adderrorsurface({
|
|
945
|
+
stepid: `s${index % 3}`,
|
|
946
|
+
runid: "run1",
|
|
947
|
+
cause: "page",
|
|
948
|
+
message: `failure ${index}`,
|
|
949
|
+
retry: { allowed: true, reason: "retry" },
|
|
950
|
+
context: { index: String(index) },
|
|
951
|
+
at: now + index,
|
|
952
|
+
});
|
|
953
|
+
}
|
|
954
|
+
const surfaces = await store.geterrorsurfaces();
|
|
955
|
+
expect(surfaces).toHaveLength(500);
|
|
956
|
+
expect(surfaces[0]?.message).toBe("failure 504");
|
|
957
|
+
expect((await store.geterrorsurfaces("s1"))[0]?.stepid).toBe("s1");
|
|
958
|
+
expect(await store.geterrorsurfaces("ghost")).toEqual([]);
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
it("indexes the history corpus incrementally and answers through the injected searcher", async () => {
|
|
962
|
+
const store = new sessionmemory(new fakeadapter());
|
|
963
|
+
await store.addhistoryentry({
|
|
964
|
+
source: "note",
|
|
965
|
+
id: "n1",
|
|
966
|
+
origin,
|
|
967
|
+
title: "pricing",
|
|
968
|
+
text: "the pricing rows",
|
|
969
|
+
at: now,
|
|
970
|
+
});
|
|
971
|
+
await store.addhistoryentry({
|
|
972
|
+
source: "note",
|
|
973
|
+
id: "n1",
|
|
974
|
+
origin,
|
|
975
|
+
title: "pricing v2",
|
|
976
|
+
text: "the edited pricing rows",
|
|
977
|
+
at: now + 1,
|
|
978
|
+
});
|
|
979
|
+
await store.addhistoryentry({
|
|
980
|
+
source: "summary",
|
|
981
|
+
id: "run1",
|
|
982
|
+
origin,
|
|
983
|
+
title: "the run",
|
|
984
|
+
text: "the run summary",
|
|
985
|
+
outcome: "completed",
|
|
986
|
+
at: now + 2,
|
|
987
|
+
});
|
|
988
|
+
const corpus = await store.gethistoryindex();
|
|
989
|
+
expect(corpus).toHaveLength(2);
|
|
990
|
+
expect(corpus.find((entry) => entry.id === "n1")?.title).toBe("pricing v2");
|
|
991
|
+
const search = (entries: historyindexentry[], query: historysearchquery): historysearchhit[] =>
|
|
992
|
+
entries
|
|
993
|
+
.filter((entry) => entry.text.includes(query.text))
|
|
994
|
+
.map((entry) => ({
|
|
995
|
+
source: entry.source,
|
|
996
|
+
id: entry.id,
|
|
997
|
+
title: entry.title,
|
|
998
|
+
excerpt: entry.text,
|
|
999
|
+
highlights: [query.text],
|
|
1000
|
+
...(entry.origin !== undefined ? { origin: entry.origin } : {}),
|
|
1001
|
+
...(entry.outcome !== undefined ? { outcome: entry.outcome } : {}),
|
|
1002
|
+
at: entry.at,
|
|
1003
|
+
}));
|
|
1004
|
+
const hits = await store.historysearch({ text: "pricing" }, search);
|
|
1005
|
+
expect(hits).toHaveLength(1);
|
|
1006
|
+
expect(hits[0]?.id).toBe("n1");
|
|
1007
|
+
});
|
|
1008
|
+
|
|
1009
|
+
it("isolates the per tab session references", async () => {
|
|
1010
|
+
const store = new sessionmemory(new fakeadapter());
|
|
1011
|
+
const ref = (tabid: number): tabsessionref => ({ tabid, sessionid: `s${tabid}`, origin, updatedat: now });
|
|
1012
|
+
await store.settabsession(ref(1));
|
|
1013
|
+
await store.settabsession(ref(2));
|
|
1014
|
+
await store.tracktabsession(1);
|
|
1015
|
+
await store.tracktabsession(2);
|
|
1016
|
+
await store.tracktabsession(2);
|
|
1017
|
+
expect((await store.listtabsessions()).map((entry) => entry.tabid)).toEqual([1, 2]);
|
|
1018
|
+
expect(await store.gettabsession(1)).toMatchObject({ sessionid: "s1" });
|
|
1019
|
+
expect(await store.gettabsession(9)).toBeUndefined();
|
|
1020
|
+
await store.settabsession({ tabid: 1, sessionid: "rebound", origin, updatedat: now + 1 });
|
|
1021
|
+
expect(await store.gettabsession(1)).toMatchObject({ sessionid: "rebound" });
|
|
1022
|
+
});
|
|
1023
|
+
|
|
1024
|
+
it("exports the session bundle with notes, summaries and corrections", async () => {
|
|
1025
|
+
const store = new sessionmemory(new fakeadapter());
|
|
1026
|
+
await store.writesitenote({
|
|
1027
|
+
id: "n1",
|
|
1028
|
+
origin,
|
|
1029
|
+
title: "t",
|
|
1030
|
+
body: "b",
|
|
1031
|
+
author: "user",
|
|
1032
|
+
sensitive: false,
|
|
1033
|
+
createdat: now,
|
|
1034
|
+
updatedat: now,
|
|
1035
|
+
});
|
|
1036
|
+
await store.addcorrection({
|
|
1037
|
+
id: "c1",
|
|
1038
|
+
origin,
|
|
1039
|
+
kind: "click",
|
|
1040
|
+
stepid: "s1",
|
|
1041
|
+
source: "edited",
|
|
1042
|
+
original: "o",
|
|
1043
|
+
corrected: "c",
|
|
1044
|
+
reason: "r",
|
|
1045
|
+
at: now,
|
|
1046
|
+
});
|
|
1047
|
+
const bundle = await store.exportsessionbundle(now + 1);
|
|
1048
|
+
expect(bundle).toEqual({
|
|
1049
|
+
kind: "sessionbundle",
|
|
1050
|
+
notes: await store.getsitenotes(),
|
|
1051
|
+
summaries: [],
|
|
1052
|
+
corrections: await store.getcorrections(),
|
|
1053
|
+
exportedat: now + 1,
|
|
1054
|
+
});
|
|
1055
|
+
expect(bundle.notes).toHaveLength(1);
|
|
1056
|
+
expect(bundle.corrections).toHaveLength(1);
|
|
1057
|
+
});
|
|
1058
|
+
|
|
1059
|
+
it("keeps the audit trail ordered with the retention window applied exactly", async () => {
|
|
1060
|
+
const store = new sessionmemory(new fakeadapter());
|
|
1061
|
+
await store.addaudi({ id: "e1", kind: "observe", at: now, summary: "first" });
|
|
1062
|
+
await store.addaudi({ id: "e2", kind: "stop", at: now + 1, summary: "second" });
|
|
1063
|
+
expect((await store.getaudit()).map((event) => event.id)).toEqual(["e2", "e1"]);
|
|
1064
|
+
await store.setsettings({ auditretention: 1 });
|
|
1065
|
+
await store.addaudi({ id: "e3", kind: "observe", at: now + 2, summary: "third" });
|
|
1066
|
+
expect((await store.getaudit()).map((event) => event.id)).toEqual(["e3"]);
|
|
1067
|
+
await store.setsettings({ auditretention: 0 });
|
|
1068
|
+
await store.addaudi({ id: "e4", kind: "observe", at: now + 3, summary: "fourth" });
|
|
1069
|
+
expect(await store.getaudit()).toEqual([]);
|
|
1070
|
+
});
|
|
1071
|
+
|
|
1072
|
+
it("keeps the step outcomes with the retention window applied exactly", async () => {
|
|
1073
|
+
const store = new sessionmemory(new fakeadapter());
|
|
1074
|
+
await store.addoutcome({ stepid: "s1", ok: true, summary: "Done.", at: now });
|
|
1075
|
+
await store.addoutcome({ stepid: "s2", ok: false, summary: "Failed.", at: now + 1 });
|
|
1076
|
+
expect((await store.getoutcomes()).map((outcome) => outcome.stepid)).toEqual(["s2", "s1"]);
|
|
1077
|
+
await store.setsettings({ outcomeretention: 1 });
|
|
1078
|
+
await store.addoutcome({ stepid: "s3", ok: true, summary: "Done.", at: now + 2 });
|
|
1079
|
+
expect((await store.getoutcomes()).map((outcome) => outcome.stepid)).toEqual(["s3"]);
|
|
1080
|
+
await store.setsettings({ outcomeretention: 0 });
|
|
1081
|
+
await store.addoutcome({ stepid: "s4", ok: true, summary: "Done.", at: now + 3 });
|
|
1082
|
+
expect(await store.getoutcomes()).toEqual([]);
|
|
1083
|
+
});
|
|
1084
|
+
});
|