@sixb/core 0.2.5 → 0.2.7
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/dist/actions/index.js +36 -35
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/validation.d.ts.map +1 -1
- package/dist/agents/errors.d.ts +1 -1
- package/dist/agents/errors.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +17 -2
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/index.d.ts +3 -3
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +53 -45
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-routing.d.ts +16 -2
- package/dist/agents/model-routing.d.ts.map +1 -1
- package/dist/agents/request.d.ts +45 -4
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-events.d.ts +4 -0
- package/dist/agents/run-events.d.ts.map +1 -1
- package/dist/agents/run-session-children.d.ts.map +1 -1
- package/dist/agents/run-token.d.ts +6 -0
- package/dist/agents/run-token.d.ts.map +1 -1
- package/dist/agents/run-turn.d.ts +9 -1
- package/dist/agents/run-turn.d.ts.map +1 -1
- package/dist/agents/streams/index.d.ts +1 -1
- package/dist/agents/streams/index.d.ts.map +1 -1
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.d.ts +2 -1
- package/dist/agents/streams/internal.d.ts.map +1 -1
- package/dist/agents/streams/internal.js +22 -2
- package/dist/agents/streams/internal.js.map +1 -1
- package/dist/agents/streams/protocol.d.ts +37 -0
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/streams/steps.d.ts +24 -0
- package/dist/agents/streams/steps.d.ts.map +1 -0
- package/dist/agents/thread-access.d.ts +44 -2
- package/dist/agents/thread-access.d.ts.map +1 -1
- package/dist/artifacts/live/server.js +19 -18
- package/dist/artifacts/live/server.js.map +1 -1
- package/dist/artifacts/publish/index.js +18 -17
- package/dist/artifacts/publish/index.js.map +1 -1
- package/dist/artifacts/publish/merge.d.ts +2 -1
- package/dist/artifacts/publish/merge.d.ts.map +1 -1
- package/dist/artifacts/run-query.d.ts.map +1 -1
- package/dist/auth/index.js +6 -6
- package/dist/authorization/index.js +2 -2
- package/dist/bootstrap/discovery.d.ts +6 -0
- package/dist/bootstrap/discovery.d.ts.map +1 -1
- package/dist/bootstrap/index.js +40 -38
- package/dist/bootstrap/index.js.map +2 -2
- package/dist/calendar.d.ts +55 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +19 -0
- package/dist/calendar.js.map +9 -0
- package/dist/chunk-04r2fdsd.js +386 -0
- package/dist/chunk-04r2fdsd.js.map +14 -0
- package/dist/{chunk-gjhrz66x.js → chunk-06kpaqg4.js} +248 -21
- package/dist/{chunk-gjhrz66x.js.map → chunk-06kpaqg4.js.map} +6 -6
- package/dist/{chunk-5a4a52tq.js → chunk-0pmpwn3g.js} +18 -2
- package/dist/chunk-0pmpwn3g.js.map +10 -0
- package/dist/{chunk-nxysqbt0.js → chunk-389ybvw9.js} +6 -2
- package/dist/chunk-389ybvw9.js.map +10 -0
- package/dist/{chunk-xcrnrpfh.js → chunk-394zjzjs.js} +20 -10
- package/dist/{chunk-xcrnrpfh.js.map → chunk-394zjzjs.js.map} +5 -5
- package/dist/{chunk-stmxh0hv.js → chunk-3neam1y5.js} +2 -2
- package/dist/{chunk-zeykm8my.js → chunk-3qtk0070.js} +16 -42
- package/dist/chunk-3qtk0070.js.map +14 -0
- package/dist/{chunk-0hkdtwqk.js → chunk-44hrfmbk.js} +5 -5
- package/dist/{chunk-ey1p8w68.js → chunk-5pz3htbe.js} +86 -5
- package/dist/chunk-5pz3htbe.js.map +13 -0
- package/dist/{chunk-s5pj68fa.js → chunk-5sswe5ej.js} +2 -2
- package/dist/{chunk-k3jh8gsg.js → chunk-5xkqasvn.js} +21 -4
- package/dist/chunk-5xkqasvn.js.map +10 -0
- package/dist/{chunk-5t9gm5tt.js → chunk-6md802cc.js} +38 -14
- package/dist/chunk-6md802cc.js.map +22 -0
- package/dist/{chunk-3zagkr6w.js → chunk-7mhbs9yy.js} +4 -4
- package/dist/{chunk-3zagkr6w.js.map → chunk-7mhbs9yy.js.map} +1 -1
- package/dist/{chunk-ewqn51gr.js → chunk-88xeh6zx.js} +6 -4
- package/dist/{chunk-ewqn51gr.js.map → chunk-88xeh6zx.js.map} +4 -4
- package/dist/{chunk-z1njfqqs.js → chunk-8qmp9fpa.js} +783 -171
- package/dist/{chunk-z1njfqqs.js.map → chunk-8qmp9fpa.js.map} +13 -13
- package/dist/{chunk-r2psmn42.js → chunk-95ps0k5q.js} +3 -3
- package/dist/{chunk-r2psmn42.js.map → chunk-95ps0k5q.js.map} +3 -3
- package/dist/{chunk-fpf57gca.js → chunk-9cyq87qa.js} +276 -68
- package/dist/{chunk-fpf57gca.js.map → chunk-9cyq87qa.js.map} +6 -6
- package/dist/{chunk-q9nkpr8k.js → chunk-9tpmfh3n.js} +1 -1
- package/dist/chunk-9wr3yajk.js.map +2 -2
- package/dist/{chunk-naxjka9v.js → chunk-brhp9d97.js} +2 -2
- package/dist/{chunk-8a8k38tz.js → chunk-brybqw5k.js} +1 -1
- package/dist/{chunk-vehcr9eb.js → chunk-cg7cygfj.js} +1 -1
- package/dist/{chunk-b4escq4c.js → chunk-cpy282b8.js} +6 -6
- package/dist/chunk-dq3t5sr3.js +114 -0
- package/dist/chunk-dq3t5sr3.js.map +11 -0
- package/dist/{chunk-68hm50qh.js → chunk-fdk0ks9p.js} +16 -46
- package/dist/chunk-fdk0ks9p.js.map +12 -0
- package/dist/{chunk-fzae1jpq.js → chunk-fycac8e9.js} +50 -16
- package/dist/{chunk-fzae1jpq.js.map → chunk-fycac8e9.js.map} +3 -3
- package/dist/{chunk-zft9bzbc.js → chunk-hkbks1xm.js} +2 -1
- package/dist/{chunk-zft9bzbc.js.map → chunk-hkbks1xm.js.map} +3 -3
- package/dist/{chunk-m3qx2pns.js → chunk-hvq8xs66.js} +28 -12
- package/dist/{chunk-m3qx2pns.js.map → chunk-hvq8xs66.js.map} +5 -5
- package/dist/{chunk-bc3y6gff.js → chunk-jka26v8c.js} +1 -1
- package/dist/{chunk-s1mqyqmm.js → chunk-js9e6487.js} +12 -8
- package/dist/chunk-js9e6487.js.map +18 -0
- package/dist/{chunk-zxhym8tr.js → chunk-k29rdc3h.js} +1 -1
- package/dist/{chunk-rg725hry.js → chunk-m1cwncee.js} +86 -34
- package/dist/{chunk-rg725hry.js.map → chunk-m1cwncee.js.map} +8 -8
- package/dist/{chunk-1yh6jgtz.js → chunk-mrs7jy17.js} +2 -2
- package/dist/{chunk-qavwr628.js → chunk-n1hbwc6y.js} +5 -6
- package/dist/chunk-n1hbwc6y.js.map +12 -0
- package/dist/{chunk-pqvvqc65.js → chunk-pfdq1ga6.js} +3 -3
- package/dist/{chunk-k29n4176.js → chunk-phs5fbff.js} +6 -6
- package/dist/{chunk-wqe9shx2.js → chunk-qbd282aa.js} +2 -2
- package/dist/{chunk-e91fmg6t.js → chunk-qsa7nw6f.js} +2 -1
- package/dist/{chunk-e91fmg6t.js.map → chunk-qsa7nw6f.js.map} +3 -3
- package/dist/chunk-r588h4ev.js +98 -0
- package/dist/chunk-r588h4ev.js.map +10 -0
- package/dist/{chunk-rtdrm592.js → chunk-t58sktr5.js} +12 -4
- package/dist/{chunk-rtdrm592.js.map → chunk-t58sktr5.js.map} +3 -3
- package/dist/{chunk-paxabbqd.js → chunk-tapdssb5.js} +1 -1
- package/dist/{chunk-dhkc9b23.js → chunk-v8a1qjzp.js} +1 -1
- package/dist/{chunk-q8d9p0tb.js → chunk-wzcjhv54.js} +8 -1
- package/dist/{chunk-q8d9p0tb.js.map → chunk-wzcjhv54.js.map} +3 -3
- package/dist/{chunk-pc7kra3k.js → chunk-xavet0qs.js} +1 -1
- package/dist/{chunk-m9ketb51.js → chunk-ygvay56w.js} +1 -1
- package/dist/{chunk-0mvjpgvm.js → chunk-yyj009tv.js} +4 -4
- package/dist/connectors/connections/capability.d.ts +11 -0
- package/dist/connectors/connections/capability.d.ts.map +1 -1
- package/dist/connectors/connections/internal.d.ts +2 -1
- package/dist/connectors/connections/internal.d.ts.map +1 -1
- package/dist/connectors/connections/internal.js +8 -4
- package/dist/connectors/connections/internal.js.map +1 -1
- package/dist/connectors/connections/service.d.ts +9 -1
- package/dist/connectors/connections/service.d.ts.map +1 -1
- package/dist/connectors/execution.d.ts +7 -1
- package/dist/connectors/execution.d.ts.map +1 -1
- package/dist/connectors/service.d.ts +5 -1
- package/dist/connectors/service.d.ts.map +1 -1
- package/dist/deploy/index.d.ts +1 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/internal.js +2 -2
- package/dist/deploy/internal.js.map +2 -2
- package/dist/deploy/types.d.ts +12 -59
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/env/index.d.ts +10 -3
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +2 -2
- package/dist/events/execution.d.ts +8 -1
- package/dist/events/execution.d.ts.map +1 -1
- package/dist/events/types/syncs.d.ts +4 -0
- package/dist/events/types/syncs.d.ts.map +1 -1
- package/dist/execution/agent.js +37 -36
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorized-object-reader.d.ts +4 -0
- package/dist/execution/authorized-object-reader.d.ts.map +1 -1
- package/dist/execution/object-reader-ontology.d.ts +3 -0
- package/dist/execution/object-reader-ontology.d.ts.map +1 -1
- package/dist/execution/primitive.js +36 -35
- package/dist/execution/primitive.js.map +1 -1
- package/dist/execution/request.d.ts +1 -1
- package/dist/execution/request.d.ts.map +1 -1
- package/dist/execution/request.js +33 -32
- package/dist/execution/request.js.map +3 -3
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -59
- package/dist/index.js.map +1 -1
- package/dist/maintenance/index.js +1 -1
- package/dist/materializer/index.js +22 -21
- package/dist/materializer/index.js.map +1 -1
- package/dist/models/audio/runtime.d.ts.map +1 -1
- package/dist/models/audio/types.d.ts +19 -0
- package/dist/models/audio/types.d.ts.map +1 -1
- package/dist/models/execution/index.js +20 -19
- package/dist/models/execution/index.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/objects/index.js +36 -35
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/query/executor.d.ts +3 -1
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/explain.d.ts +3 -1
- package/dist/objects/query/explain.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +1 -1
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +19 -18
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/link-query-clearance.d.ts +3 -0
- package/dist/objects/query/link-query-clearance.d.ts.map +1 -1
- package/dist/objects/query/links.d.ts +1 -1
- package/dist/objects/query/links.d.ts.map +1 -1
- package/dist/objects/query/validate.d.ts +17 -0
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
- package/dist/ontology/index.js +3 -3
- package/dist/ontology/internal.js +3 -3
- package/dist/pipelines/index.js +21 -20
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/internal.js +20 -19
- package/dist/projections/internal.js.map +1 -1
- package/dist/queues/in-memory.d.ts +1 -1
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +14 -0
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +3 -1
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/internal.js +24 -23
- package/dist/runtime/internal.js.map +2 -2
- package/dist/runtime/locale.d.ts +0 -2
- package/dist/runtime/locale.d.ts.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +2 -1
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/sandboxes/auth.d.ts +26 -4
- package/dist/sandboxes/auth.d.ts.map +1 -1
- package/dist/sandboxes/errors.d.ts +19 -0
- package/dist/sandboxes/errors.d.ts.map +1 -1
- package/dist/sandboxes/exec.d.ts +2 -0
- package/dist/sandboxes/exec.d.ts.map +1 -1
- package/dist/sandboxes/index.d.ts +4 -2
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +13 -7
- package/dist/sandboxes/index.js.map +1 -1
- package/dist/sandboxes/sandbox.d.ts +15 -1
- package/dist/sandboxes/sandbox.d.ts.map +1 -1
- package/dist/security/view-conditions.d.ts.map +1 -1
- package/dist/shares/internal.js +16 -15
- package/dist/shares/internal.js.map +2 -2
- package/dist/storage/agents/in-memory.d.ts +18 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +1 -1
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +43 -9
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +19 -3
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +150 -4
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/analytics.d.ts +3 -2
- package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +4 -3
- package/dist/storage/ai-cost/provider.js.map +1 -1
- package/dist/storage/ai-cost/types.d.ts +5 -1
- package/dist/storage/ai-cost/types.d.ts.map +1 -1
- package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
- package/dist/storage/artifacts/record.d.ts +3 -1
- package/dist/storage/artifacts/record.d.ts.map +1 -1
- package/dist/storage/artifacts/types.d.ts +7 -0
- package/dist/storage/artifacts/types.d.ts.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +7 -7
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +23 -22
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.js +8 -8
- package/dist/storage/operation-scope.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +1 -1
- package/dist/storage/sync-runs/idempotency.d.ts.map +1 -1
- package/dist/storage/sync-runs/in-memory.d.ts +2 -1
- package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/sync-runs/index.d.ts +1 -1
- package/dist/storage/sync-runs/index.d.ts.map +1 -1
- package/dist/storage/sync-runs/types.d.ts +27 -2
- package/dist/storage/sync-runs/types.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +7 -7
- package/dist/syncs/accounts.d.ts +36 -0
- package/dist/syncs/accounts.d.ts.map +1 -0
- package/dist/syncs/builders.d.ts.map +1 -1
- package/dist/syncs/connections.d.ts +36 -0
- package/dist/syncs/connections.d.ts.map +1 -0
- package/dist/syncs/execution.d.ts +14 -4
- package/dist/syncs/execution.d.ts.map +1 -1
- package/dist/syncs/index.d.ts +2 -1
- package/dist/syncs/index.d.ts.map +1 -1
- package/dist/syncs/index.js +22 -21
- package/dist/syncs/index.js.map +1 -1
- package/dist/syncs/request.d.ts +16 -2
- package/dist/syncs/request.d.ts.map +1 -1
- package/dist/syncs/run-dispatch.d.ts +14 -2
- package/dist/syncs/run-dispatch.d.ts.map +1 -1
- package/dist/testing/agent-approval-storage-contract.d.ts.map +1 -1
- package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -1
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
- package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.js +1157 -100
- package/dist/testing/index.js.map +9 -9
- package/dist/testing/run-claim-storage-contract.d.ts.map +1 -1
- package/dist/testing/sandboxes-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +17 -16
- package/dist/webhooks/internal.js.map +2 -2
- package/dist/workers/index.js +66 -13
- package/dist/workers/index.js.map +4 -4
- package/dist/workers/queue-worker.d.ts +5 -0
- package/dist/workers/queue-worker.d.ts.map +1 -1
- package/dist/workers/worker.d.ts +8 -0
- package/dist/workers/worker.d.ts.map +1 -1
- package/dist/workflows/index.js +42 -40
- package/dist/workflows/index.js.map +1 -1
- package/package.json +7 -1
- package/src/actions/validation.ts +3 -1
- package/src/agents/children.ts +6 -0
- package/src/agents/errors.ts +3 -0
- package/src/agents/execution.ts +170 -20
- package/src/agents/index.ts +5 -0
- package/src/agents/model-routing.ts +116 -34
- package/src/agents/request.ts +783 -38
- package/src/agents/run-events.ts +235 -38
- package/src/agents/run-session-children.ts +13 -2
- package/src/agents/run-token.ts +7 -0
- package/src/agents/run-turn.ts +140 -23
- package/src/agents/streams/index.ts +2 -0
- package/src/agents/streams/internal.ts +12 -0
- package/src/agents/streams/protocol.ts +69 -1
- package/src/agents/streams/steps.ts +131 -0
- package/src/agents/thread-access.ts +57 -2
- package/src/artifacts/publish/merge.ts +14 -3
- package/src/artifacts/run-query.ts +5 -2
- package/src/bootstrap/discovery.ts +61 -11
- package/src/calendar.ts +195 -0
- package/src/connectors/connections/capability.ts +40 -0
- package/src/connectors/connections/internal.ts +3 -0
- package/src/connectors/connections/service.ts +74 -5
- package/src/connectors/execution.ts +5 -6
- package/src/connectors/service.ts +23 -0
- package/src/deploy/index.ts +0 -5
- package/src/deploy/types.ts +12 -64
- package/src/deploy/validation.ts +1 -1
- package/src/env/index.ts +10 -4
- package/src/events/execution.ts +42 -2
- package/src/events/types/syncs.ts +4 -0
- package/src/execution/authorized-object-reader.ts +33 -5
- package/src/execution/object-reader-ontology.ts +6 -0
- package/src/execution/request.ts +1 -0
- package/src/http/api-routes.ts +8 -0
- package/src/index.ts +21 -2
- package/src/models/audio/runtime.ts +57 -14
- package/src/models/audio/types.ts +20 -0
- package/src/models/index.ts +1 -0
- package/src/objects/query/executor.ts +4 -0
- package/src/objects/query/explain.ts +5 -0
- package/src/objects/query/index.ts +1 -0
- package/src/objects/query/link-query-clearance.ts +4 -1
- package/src/objects/query/links.ts +5 -1
- package/src/objects/query/validate.ts +33 -1
- package/src/objects/sdk/runtime-query-executor.ts +7 -3
- package/src/runtime/create.ts +1 -0
- package/src/runtime/definitions.ts +25 -0
- package/src/runtime/host.ts +16 -8
- package/src/runtime/index.ts +6 -1
- package/src/runtime/locale.ts +0 -10
- package/src/runtime/resolve-definitions.ts +7 -1
- package/src/runtime/sixb.ts +12 -2
- package/src/sandboxes/README.md +12 -1
- package/src/sandboxes/auth.ts +32 -4
- package/src/sandboxes/errors.ts +27 -0
- package/src/sandboxes/exec.ts +3 -1
- package/src/sandboxes/index.ts +18 -1
- package/src/sandboxes/sandbox.ts +15 -1
- package/src/security/view-conditions.ts +2 -1
- package/src/storage/agents/in-memory.ts +271 -6
- package/src/storage/agents/index.ts +10 -0
- package/src/storage/agents/provider.ts +178 -13
- package/src/storage/agents/types.ts +166 -4
- package/src/storage/ai-cost/analytics.ts +22 -43
- package/src/storage/ai-cost/types.ts +5 -1
- package/src/storage/artifacts/in-memory.ts +20 -5
- package/src/storage/artifacts/record.ts +8 -2
- package/src/storage/artifacts/types.ts +7 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/operation-scope.ts +1 -0
- package/src/storage/sync-runs/idempotency.ts +1 -0
- package/src/storage/sync-runs/in-memory.ts +43 -1
- package/src/storage/sync-runs/index.ts +1 -0
- package/src/storage/sync-runs/types.ts +30 -1
- package/src/syncs/accounts.ts +85 -0
- package/src/syncs/builders.ts +18 -1
- package/src/syncs/connections.ts +123 -0
- package/src/syncs/execution.ts +64 -22
- package/src/syncs/index.ts +3 -0
- package/src/syncs/request.ts +81 -23
- package/src/syncs/run-dispatch.ts +69 -7
- package/src/testing/agent-approval-storage-contract.ts +123 -0
- package/src/testing/agent-inbox-storage-contract.ts +59 -0
- package/src/testing/agent-storage-contract.ts +794 -8
- package/src/testing/ai-cost-storage-contract.ts +80 -0
- package/src/testing/artifact-storage-contract.ts +139 -0
- package/src/testing/run-claim-storage-contract.ts +116 -0
- package/src/testing/sandboxes-contract.ts +50 -0
- package/src/workers/README.md +4 -1
- package/src/workers/lost-runs.ts +1 -0
- package/src/workers/queue-worker.ts +16 -5
- package/src/workers/worker.ts +67 -7
- package/dist/chunk-5a4a52tq.js.map +0 -10
- package/dist/chunk-5t9gm5tt.js.map +0 -22
- package/dist/chunk-68hm50qh.js.map +0 -13
- package/dist/chunk-aw1z0gre.js +0 -234
- package/dist/chunk-aw1z0gre.js.map +0 -12
- package/dist/chunk-ey1p8w68.js.map +0 -13
- package/dist/chunk-k3jh8gsg.js.map +0 -10
- package/dist/chunk-nxysqbt0.js.map +0 -10
- package/dist/chunk-qavwr628.js.map +0 -12
- package/dist/chunk-s1mqyqmm.js.map +0 -18
- package/dist/chunk-zeykm8my.js.map +0 -14
- /package/dist/{chunk-stmxh0hv.js.map → chunk-3neam1y5.js.map} +0 -0
- /package/dist/{chunk-0hkdtwqk.js.map → chunk-44hrfmbk.js.map} +0 -0
- /package/dist/{chunk-s5pj68fa.js.map → chunk-5sswe5ej.js.map} +0 -0
- /package/dist/{chunk-q9nkpr8k.js.map → chunk-9tpmfh3n.js.map} +0 -0
- /package/dist/{chunk-naxjka9v.js.map → chunk-brhp9d97.js.map} +0 -0
- /package/dist/{chunk-8a8k38tz.js.map → chunk-brybqw5k.js.map} +0 -0
- /package/dist/{chunk-vehcr9eb.js.map → chunk-cg7cygfj.js.map} +0 -0
- /package/dist/{chunk-b4escq4c.js.map → chunk-cpy282b8.js.map} +0 -0
- /package/dist/{chunk-bc3y6gff.js.map → chunk-jka26v8c.js.map} +0 -0
- /package/dist/{chunk-zxhym8tr.js.map → chunk-k29rdc3h.js.map} +0 -0
- /package/dist/{chunk-1yh6jgtz.js.map → chunk-mrs7jy17.js.map} +0 -0
- /package/dist/{chunk-pqvvqc65.js.map → chunk-pfdq1ga6.js.map} +0 -0
- /package/dist/{chunk-k29n4176.js.map → chunk-phs5fbff.js.map} +0 -0
- /package/dist/{chunk-wqe9shx2.js.map → chunk-qbd282aa.js.map} +0 -0
- /package/dist/{chunk-paxabbqd.js.map → chunk-tapdssb5.js.map} +0 -0
- /package/dist/{chunk-dhkc9b23.js.map → chunk-v8a1qjzp.js.map} +0 -0
- /package/dist/{chunk-pc7kra3k.js.map → chunk-xavet0qs.js.map} +0 -0
- /package/dist/{chunk-m9ketb51.js.map → chunk-ygvay56w.js.map} +0 -0
- /package/dist/{chunk-0mvjpgvm.js.map → chunk-yyj009tv.js.map} +0 -0
package/dist/testing/index.js
CHANGED
|
@@ -10,13 +10,13 @@ import {
|
|
|
10
10
|
AuthStorageError2,
|
|
11
11
|
toUserProfile,
|
|
12
12
|
SYSTEM_PRINCIPAL2
|
|
13
|
-
} from "../chunk-
|
|
13
|
+
} from "../chunk-394zjzjs.js";
|
|
14
14
|
import"../chunk-d7v97qxq.js";
|
|
15
15
|
import {
|
|
16
16
|
agentServiceAccountId2,
|
|
17
17
|
MAX_OBJECT_READ_FACETS2,
|
|
18
18
|
defineProjection2
|
|
19
|
-
} from "../chunk-
|
|
19
|
+
} from "../chunk-tapdssb5.js";
|
|
20
20
|
import"../chunk-7j4yydm2.js";
|
|
21
21
|
import {
|
|
22
22
|
compileSelectedObjectReadScope2,
|
|
@@ -28,11 +28,11 @@ import {
|
|
|
28
28
|
} from "../chunk-wkv3h3q7.js";
|
|
29
29
|
import {
|
|
30
30
|
UNIQUE_VALUE_KEY_VERSION
|
|
31
|
-
} from "../chunk-
|
|
31
|
+
} from "../chunk-7mhbs9yy.js";
|
|
32
32
|
import"../chunk-frsz8wxd.js";
|
|
33
33
|
import {
|
|
34
34
|
ref2
|
|
35
|
-
} from "../chunk-
|
|
35
|
+
} from "../chunk-brybqw5k.js";
|
|
36
36
|
import {
|
|
37
37
|
OntologyRegistry2,
|
|
38
38
|
defineObjectType2,
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
link2,
|
|
42
42
|
valueTypeRef2,
|
|
43
43
|
stringEnum2
|
|
44
|
-
} from "../chunk-
|
|
44
|
+
} from "../chunk-v8a1qjzp.js";
|
|
45
45
|
import {
|
|
46
46
|
createEventId2
|
|
47
47
|
} from "../chunk-zrvhsq7f.js";
|
|
@@ -50,8 +50,9 @@ import"../chunk-az95tsh3.js";
|
|
|
50
50
|
import"../chunk-qttqe1ah.js";
|
|
51
51
|
import {
|
|
52
52
|
AgentStorageError2
|
|
53
|
-
} from "../chunk-
|
|
54
|
-
import"../chunk-
|
|
53
|
+
} from "../chunk-5pz3htbe.js";
|
|
54
|
+
import"../chunk-dq3t5sr3.js";
|
|
55
|
+
import"../chunk-3qtk0070.js";
|
|
55
56
|
import {
|
|
56
57
|
aiLimitCalendarMonth2
|
|
57
58
|
} from "../chunk-c4nrycdy.js";
|
|
@@ -61,10 +62,10 @@ import {
|
|
|
61
62
|
import {
|
|
62
63
|
DEFAULT_FILE_UPLOAD_TERMINAL_SESSION_TTL_MS2
|
|
63
64
|
} from "../chunk-h89wz928.js";
|
|
64
|
-
import"../chunk-
|
|
65
|
+
import"../chunk-cg7cygfj.js";
|
|
65
66
|
import {
|
|
66
67
|
ArtifactStorageError
|
|
67
|
-
} from "../chunk-
|
|
68
|
+
} from "../chunk-88xeh6zx.js";
|
|
68
69
|
import {
|
|
69
70
|
ARTIFACT_STATE_LIMITS2,
|
|
70
71
|
ARTIFACT_RESTORE_POINTS2,
|
|
@@ -90,9 +91,9 @@ import {
|
|
|
90
91
|
WorkflowInterventionError2,
|
|
91
92
|
InMemoryStorage2,
|
|
92
93
|
migrateStorage2
|
|
93
|
-
} from "../chunk-
|
|
94
|
+
} from "../chunk-06kpaqg4.js";
|
|
94
95
|
import"../chunk-61zptves.js";
|
|
95
|
-
import"../chunk-
|
|
96
|
+
import"../chunk-hkbks1xm.js";
|
|
96
97
|
import {
|
|
97
98
|
ORPHANED_RUN_AFTER_MS2,
|
|
98
99
|
planRunClaim2
|
|
@@ -105,7 +106,7 @@ import {
|
|
|
105
106
|
import"../chunk-jmfet9r4.js";
|
|
106
107
|
import"../chunk-qf954wje.js";
|
|
107
108
|
import"../chunk-x0v3jd47.js";
|
|
108
|
-
import"../chunk-
|
|
109
|
+
import"../chunk-5sswe5ej.js";
|
|
109
110
|
import {
|
|
110
111
|
planObjectQuery2,
|
|
111
112
|
executeObjectQuery2,
|
|
@@ -113,25 +114,25 @@ import {
|
|
|
113
114
|
existsObjects2,
|
|
114
115
|
facetObjects2,
|
|
115
116
|
executeObjectQueryLinks2
|
|
116
|
-
} from "../chunk-
|
|
117
|
-
import"../chunk-
|
|
117
|
+
} from "../chunk-js9e6487.js";
|
|
118
|
+
import"../chunk-6md802cc.js";
|
|
118
119
|
import"../chunk-vs2s3p8n.js";
|
|
119
120
|
import"../chunk-bz5bnjjt.js";
|
|
120
121
|
import"../chunk-bqr703h4.js";
|
|
121
|
-
import"../chunk-
|
|
122
|
+
import"../chunk-hvq8xs66.js";
|
|
122
123
|
import"../chunk-60662fyv.js";
|
|
123
124
|
import {
|
|
124
125
|
bindModelExecutionAttempt,
|
|
125
126
|
isBoundSixb
|
|
126
|
-
} from "../chunk-
|
|
127
|
+
} from "../chunk-8qmp9fpa.js";
|
|
127
128
|
import"../chunk-czct88ht.js";
|
|
128
|
-
import"../chunk-
|
|
129
|
-
import"../chunk-
|
|
129
|
+
import"../chunk-phs5fbff.js";
|
|
130
|
+
import"../chunk-5xkqasvn.js";
|
|
130
131
|
import"../chunk-5qqmndhm.js";
|
|
131
132
|
import"../chunk-sgx82nnt.js";
|
|
132
133
|
import"../chunk-8ncg20rd.js";
|
|
133
|
-
import"../chunk-
|
|
134
|
-
import"../chunk-
|
|
134
|
+
import"../chunk-0pmpwn3g.js";
|
|
135
|
+
import"../chunk-n1hbwc6y.js";
|
|
135
136
|
import {
|
|
136
137
|
col2,
|
|
137
138
|
defineDataset2,
|
|
@@ -141,13 +142,14 @@ import {
|
|
|
141
142
|
writeDataset2
|
|
142
143
|
} from "../chunk-ppxf7gw2.js";
|
|
143
144
|
import"../chunk-191jz8a6.js";
|
|
144
|
-
import"../chunk-
|
|
145
|
-
import"../chunk-
|
|
145
|
+
import"../chunk-mrs7jy17.js";
|
|
146
|
+
import"../chunk-9tpmfh3n.js";
|
|
146
147
|
import {
|
|
147
148
|
ProjectionRegistry2,
|
|
148
149
|
createLinkScopeFingerprint2,
|
|
149
150
|
createOntologyMaterializer2
|
|
150
|
-
} from "../chunk-
|
|
151
|
+
} from "../chunk-cpy282b8.js";
|
|
152
|
+
import"../chunk-04r2fdsd.js";
|
|
151
153
|
import"../chunk-1vg43g9q.js";
|
|
152
154
|
import"../chunk-m427qgq0.js";
|
|
153
155
|
import {
|
|
@@ -163,50 +165,49 @@ import {
|
|
|
163
165
|
QueueError2,
|
|
164
166
|
InMemoryQueues2
|
|
165
167
|
} from "../chunk-8tv3qd65.js";
|
|
166
|
-
import"../chunk-
|
|
167
|
-
import"../chunk-
|
|
168
|
+
import"../chunk-95ps0k5q.js";
|
|
169
|
+
import"../chunk-fdk0ks9p.js";
|
|
168
170
|
import"../chunk-92wrka15.js";
|
|
169
171
|
import {
|
|
170
172
|
projectAgentThreadModelContext2
|
|
171
|
-
} from "../chunk-
|
|
172
|
-
import"../chunk-
|
|
173
|
+
} from "../chunk-9cyq87qa.js";
|
|
174
|
+
import"../chunk-k29rdc3h.js";
|
|
173
175
|
import"../chunk-de5sfbc3.js";
|
|
174
|
-
import"../chunk-
|
|
175
|
-
import"../chunk-
|
|
176
|
+
import"../chunk-jka26v8c.js";
|
|
177
|
+
import"../chunk-wzcjhv54.js";
|
|
176
178
|
import {
|
|
177
179
|
workflowAgentStepActorId2
|
|
178
|
-
} from "../chunk-
|
|
180
|
+
} from "../chunk-yyj009tv.js";
|
|
179
181
|
import"../chunk-c69nj7se.js";
|
|
180
182
|
import"../chunk-whbwf3np.js";
|
|
181
|
-
import"../chunk-
|
|
183
|
+
import"../chunk-fycac8e9.js";
|
|
182
184
|
import {
|
|
183
185
|
SixbHost2
|
|
184
|
-
} from "../chunk-
|
|
186
|
+
} from "../chunk-m1cwncee.js";
|
|
185
187
|
import {
|
|
186
188
|
findDatasetIngestRuntime2,
|
|
187
189
|
getDatasetIngestRuntime2
|
|
188
|
-
} from "../chunk-
|
|
189
|
-
import"../chunk-
|
|
190
|
+
} from "../chunk-44hrfmbk.js";
|
|
191
|
+
import"../chunk-brhp9d97.js";
|
|
190
192
|
import"../chunk-3ba89vm7.js";
|
|
191
193
|
import {
|
|
192
194
|
createTestingScope
|
|
193
|
-
} from "../chunk-
|
|
195
|
+
} from "../chunk-ygvay56w.js";
|
|
194
196
|
import {
|
|
195
197
|
datasetSequenceChange2,
|
|
196
198
|
DatasetSequenceConflictError2
|
|
197
199
|
} from "../chunk-dmnd9ea6.js";
|
|
198
200
|
import"../chunk-7qe46788.js";
|
|
199
|
-
import"../chunk-
|
|
200
|
-
import"../chunk-
|
|
201
|
+
import"../chunk-qbd282aa.js";
|
|
202
|
+
import"../chunk-pfdq1ga6.js";
|
|
203
|
+
import"../chunk-y8fwm3z2.js";
|
|
201
204
|
import {
|
|
202
205
|
SandboxNotRunningError2
|
|
203
|
-
} from "../chunk-
|
|
204
|
-
import"../chunk-3723kgba.js";
|
|
205
|
-
import"../chunk-pqvvqc65.js";
|
|
206
|
-
import"../chunk-y8fwm3z2.js";
|
|
206
|
+
} from "../chunk-t58sktr5.js";
|
|
207
207
|
import {
|
|
208
208
|
restoreTrustedPrimitiveExecutionScope
|
|
209
|
-
} from "../chunk-
|
|
209
|
+
} from "../chunk-xavet0qs.js";
|
|
210
|
+
import"../chunk-3723kgba.js";
|
|
210
211
|
import"../chunk-d9xbwh3h.js";
|
|
211
212
|
import"../chunk-w3t94hm6.js";
|
|
212
213
|
import {
|
|
@@ -222,16 +223,17 @@ import {
|
|
|
222
223
|
import {
|
|
223
224
|
ObjectQueryPlanningError2
|
|
224
225
|
} from "../chunk-0k1h5hmr.js";
|
|
225
|
-
import"../chunk-
|
|
226
|
+
import"../chunk-3neam1y5.js";
|
|
226
227
|
import {
|
|
227
228
|
MaterializationValidationError2,
|
|
228
229
|
UniqueValueViolationError2,
|
|
229
230
|
MaterializationConflictError2
|
|
230
231
|
} from "../chunk-y7dbmaqh.js";
|
|
232
|
+
import"../chunk-r588h4ev.js";
|
|
231
233
|
import {
|
|
232
234
|
AGENT_TOKEN_RATE_SAMPLES2,
|
|
233
235
|
AGENT_THREAD_INBOX_MAX_ITEMS2
|
|
234
|
-
} from "../chunk-
|
|
236
|
+
} from "../chunk-389ybvw9.js";
|
|
235
237
|
import"../chunk-a3faa34j.js";
|
|
236
238
|
|
|
237
239
|
// src/testing/action-execution.ts
|
|
@@ -1993,6 +1995,117 @@ function runAgentApprovalStorageContractSuite(label, options) {
|
|
|
1993
1995
|
expect3(stored?.kind === "conversation" ? stored.spec?.approvalMode : null).toBe("accept-edits");
|
|
1994
1996
|
});
|
|
1995
1997
|
});
|
|
1998
|
+
test3("rewinds approvals of truncated turns, unmarks earlier ones, and filters rewound subagents", async () => {
|
|
1999
|
+
await withStorage(async (storage) => {
|
|
2000
|
+
const t1 = new Date(t0.getTime() + 1000);
|
|
2001
|
+
await startTurn(storage);
|
|
2002
|
+
await storage.agents.messages.append({
|
|
2003
|
+
id: "msg_1",
|
|
2004
|
+
projectId: projectId3,
|
|
2005
|
+
threadId: "thr_1",
|
|
2006
|
+
runId: null,
|
|
2007
|
+
role: "user",
|
|
2008
|
+
parts: [{ type: "text", text: "Turn 1" }],
|
|
2009
|
+
createdAt: t0
|
|
2010
|
+
});
|
|
2011
|
+
await storage.agents.approvals.request(approvalInput({ id: "apr_early" }));
|
|
2012
|
+
await storage.agents.approvals.decide({ ...decision("denied"), id: "apr_early" });
|
|
2013
|
+
await finishTurn(storage, "cancelled");
|
|
2014
|
+
await storage.agents.messages.append({
|
|
2015
|
+
id: "msg_2",
|
|
2016
|
+
projectId: projectId3,
|
|
2017
|
+
threadId: "thr_1",
|
|
2018
|
+
runId: null,
|
|
2019
|
+
role: "user",
|
|
2020
|
+
parts: [{ type: "text", text: "Turn 2" }],
|
|
2021
|
+
createdAt: t1
|
|
2022
|
+
});
|
|
2023
|
+
await storage.agents.approvals.markReported({
|
|
2024
|
+
projectId: projectId3,
|
|
2025
|
+
threadId: "thr_1",
|
|
2026
|
+
ids: ["apr_early"],
|
|
2027
|
+
messageId: "msg_2"
|
|
2028
|
+
});
|
|
2029
|
+
const laterExec = await createTestAgentExecution(storage, { projectId: projectId3, runId: "run_later" });
|
|
2030
|
+
await storage.agents.runs.create({
|
|
2031
|
+
...runInput("run_later"),
|
|
2032
|
+
executionId: laterExec,
|
|
2033
|
+
triggerMessageId: "msg_2",
|
|
2034
|
+
createdAt: t1
|
|
2035
|
+
});
|
|
2036
|
+
await storage.agents.runs.start({
|
|
2037
|
+
projectId: projectId3,
|
|
2038
|
+
id: "run_later",
|
|
2039
|
+
execution: { token: "tok_later", queueLeaseExpiresAt: new Date(t1.getTime() + 60000) },
|
|
2040
|
+
startedAt: t1
|
|
2041
|
+
});
|
|
2042
|
+
await storage.agents.approvals.request(approvalInput({
|
|
2043
|
+
id: "apr_rewound",
|
|
2044
|
+
runId: "run_later",
|
|
2045
|
+
callerRunId: "run_later",
|
|
2046
|
+
executionToken: "tok_later",
|
|
2047
|
+
call: sendReminders
|
|
2048
|
+
}));
|
|
2049
|
+
const childExec = await createTestAgentExecution(storage, {
|
|
2050
|
+
projectId: projectId3,
|
|
2051
|
+
runId: "child_rewound",
|
|
2052
|
+
sourceExecutionId: laterExec
|
|
2053
|
+
});
|
|
2054
|
+
await storage.agents.runs.createSubagent({
|
|
2055
|
+
id: "child_rewound",
|
|
2056
|
+
projectId: projectId3,
|
|
2057
|
+
executionId: childExec,
|
|
2058
|
+
parentRunId: "run_later",
|
|
2059
|
+
parentExecutionToken: "tok_later",
|
|
2060
|
+
spawnKey: "west",
|
|
2061
|
+
spec: { model: { provider: "test", modelId: "fast" }, task: "Ask west.", toolNames: [] },
|
|
2062
|
+
thread: { id: "thr_child_rewound", create: true },
|
|
2063
|
+
trigger: { id: "msg_child_rewound", parts: [{ type: "text", text: "Ask west." }] },
|
|
2064
|
+
maxActiveChildren: 4,
|
|
2065
|
+
createdAt: t1
|
|
2066
|
+
});
|
|
2067
|
+
await storage.agents.runs.start({
|
|
2068
|
+
projectId: projectId3,
|
|
2069
|
+
id: "child_rewound",
|
|
2070
|
+
execution: { token: "tok_c", queueLeaseExpiresAt: new Date(t1.getTime() + 60000) },
|
|
2071
|
+
startedAt: t1
|
|
2072
|
+
});
|
|
2073
|
+
await storage.agents.runs.finish({
|
|
2074
|
+
projectId: projectId3,
|
|
2075
|
+
id: "child_rewound",
|
|
2076
|
+
executionToken: "tok_c",
|
|
2077
|
+
status: "succeeded",
|
|
2078
|
+
finishReason: "awaiting_answer",
|
|
2079
|
+
result: { text: "" }
|
|
2080
|
+
});
|
|
2081
|
+
await storage.agents.runs.finish({
|
|
2082
|
+
projectId: projectId3,
|
|
2083
|
+
id: "run_later",
|
|
2084
|
+
executionToken: "tok_later",
|
|
2085
|
+
status: "succeeded",
|
|
2086
|
+
finishReason: "awaiting_approval"
|
|
2087
|
+
});
|
|
2088
|
+
const rewound = await storage.agents.approvals.rewind({
|
|
2089
|
+
projectId: projectId3,
|
|
2090
|
+
threadId: "thr_1",
|
|
2091
|
+
runIds: ["run_later"],
|
|
2092
|
+
clearedMessageIds: ["msg_2"]
|
|
2093
|
+
});
|
|
2094
|
+
await storage.agents.messages.deleteFromSeq({ projectId: projectId3, threadId: "thr_1", fromSeq: 2 });
|
|
2095
|
+
expect3(rewound).toEqual({
|
|
2096
|
+
cancelled: [expect3.objectContaining({ id: "apr_rewound", status: "cancelled" })],
|
|
2097
|
+
deleted: 1
|
|
2098
|
+
});
|
|
2099
|
+
expect3(await storage.agents.approvals.getById({ projectId: projectId3, id: "apr_rewound" })).toBeNull();
|
|
2100
|
+
const earlyAfter = await storage.agents.approvals.getById({ projectId: projectId3, id: "apr_early" });
|
|
2101
|
+
expect3(earlyAfter?.reportedInMessageId).toBeUndefined();
|
|
2102
|
+
expect3(await storage.agents.runs.listThreadSubagents({
|
|
2103
|
+
projectId: projectId3,
|
|
2104
|
+
threadId: "thr_1",
|
|
2105
|
+
retainedTurnsOnly: true
|
|
2106
|
+
})).toEqual([]);
|
|
2107
|
+
});
|
|
2108
|
+
});
|
|
1996
2109
|
});
|
|
1997
2110
|
}
|
|
1998
2111
|
function approvalInput(overrides = {}) {
|
|
@@ -2603,6 +2716,56 @@ function runAgentInboxStorageContractSuite(label, options) {
|
|
|
2603
2716
|
]);
|
|
2604
2717
|
});
|
|
2605
2718
|
});
|
|
2719
|
+
test4("an edit waiting for its turn keeps the message it replaces, and stays a message sent now", async () => {
|
|
2720
|
+
await withStorage(async (storage) => {
|
|
2721
|
+
await storage.agents.threads.create({
|
|
2722
|
+
id: "thr_edit",
|
|
2723
|
+
projectId: projectId4,
|
|
2724
|
+
ownerPrincipal: alice,
|
|
2725
|
+
createdAt: t02
|
|
2726
|
+
});
|
|
2727
|
+
await startConversationRun(storage, "thr_edit", "run_stopping", "tok_stopping");
|
|
2728
|
+
const edit = {
|
|
2729
|
+
id: "inb_edit",
|
|
2730
|
+
projectId: projectId4,
|
|
2731
|
+
threadId: "thr_edit",
|
|
2732
|
+
messageId: "msg_edited",
|
|
2733
|
+
authorPrincipal: alice,
|
|
2734
|
+
mode: "queue",
|
|
2735
|
+
immediate: true,
|
|
2736
|
+
replacesMessageId: "msg_original",
|
|
2737
|
+
parts: [{ type: "text", text: "Only the breaking changes" }]
|
|
2738
|
+
};
|
|
2739
|
+
for (const invalid of [
|
|
2740
|
+
{ ...edit, mode: "steer" },
|
|
2741
|
+
{ ...edit, immediate: false }
|
|
2742
|
+
]) {
|
|
2743
|
+
const error = await storage.agents.inbox.enqueue(invalid).catch((caught) => caught);
|
|
2744
|
+
expect4(error).toBeInstanceOf(AgentStorageError2);
|
|
2745
|
+
expect4(error.code).toBe("invalid_input");
|
|
2746
|
+
}
|
|
2747
|
+
const { item } = await storage.agents.inbox.enqueue(edit);
|
|
2748
|
+
expect4(item.replacesMessageId).toBe("msg_original");
|
|
2749
|
+
const [listed] = await storage.agents.inbox.list({ projectId: projectId4, threadId: "thr_edit" });
|
|
2750
|
+
expect4(listed?.replacesMessageId).toBe("msg_original");
|
|
2751
|
+
const demoted = await storage.agents.inbox.update({ projectId: projectId4, threadId: "thr_edit", id: "inb_edit", immediate: false }).catch((caught) => caught);
|
|
2752
|
+
expect4(demoted).toBeInstanceOf(AgentStorageError2);
|
|
2753
|
+
expect4(demoted.code).toBe("invalid_state");
|
|
2754
|
+
await storage.agents.runs.finish({
|
|
2755
|
+
projectId: projectId4,
|
|
2756
|
+
id: "run_stopping",
|
|
2757
|
+
executionToken: "tok_stopping",
|
|
2758
|
+
status: "cancelled"
|
|
2759
|
+
});
|
|
2760
|
+
const popped = await storage.agents.inbox.takeNextQueued({
|
|
2761
|
+
projectId: projectId4,
|
|
2762
|
+
threadId: "thr_edit",
|
|
2763
|
+
onlyImmediate: true
|
|
2764
|
+
});
|
|
2765
|
+
expect4(popped?.id).toBe("inb_edit");
|
|
2766
|
+
expect4(popped?.replacesMessageId).toBe("msg_original");
|
|
2767
|
+
});
|
|
2768
|
+
});
|
|
2606
2769
|
test4("takeNextQueued waits for idle and orders immediate, steer, then queue", async () => {
|
|
2607
2770
|
await withStorage(async (storage) => {
|
|
2608
2771
|
await storage.agents.threads.create({
|
|
@@ -3106,6 +3269,9 @@ function participant(userId, addedAt) {
|
|
|
3106
3269
|
addedBy: owner
|
|
3107
3270
|
};
|
|
3108
3271
|
}
|
|
3272
|
+
function user(id) {
|
|
3273
|
+
return { type: "user", id };
|
|
3274
|
+
}
|
|
3109
3275
|
function execution(token, queueLeaseExpiresAt = at2("2026-06-23T10:05:00.000Z")) {
|
|
3110
3276
|
return { token, queueLeaseExpiresAt };
|
|
3111
3277
|
}
|
|
@@ -3720,10 +3886,10 @@ function runAgentStorageContractSuite(label, options) {
|
|
|
3720
3886
|
})), "invalid_input");
|
|
3721
3887
|
});
|
|
3722
3888
|
});
|
|
3723
|
-
test6("moves a
|
|
3724
|
-
await withStorage(async (storage) => {
|
|
3889
|
+
test6("moves a thread between the cloud, computers and folders back and forth", async () => {
|
|
3890
|
+
await withStorage(async (storage, fixture) => {
|
|
3725
3891
|
await storage.threads.create(threadInput({ runsOn: "computer", computer: laptop }));
|
|
3726
|
-
await storage.threads.create(threadInput({ id: "thr_cloud" }));
|
|
3892
|
+
await storage.threads.create(threadInput({ id: "thr_cloud", sandboxParams: { repo: "app" } }));
|
|
3727
3893
|
const thread = { projectId: projectId6, id: "thr_1" };
|
|
3728
3894
|
const renamed = await storage.threads.assignComputer({
|
|
3729
3895
|
...thread,
|
|
@@ -3739,13 +3905,167 @@ function runAgentStorageContractSuite(label, options) {
|
|
|
3739
3905
|
movedAt: at2("2026-06-23T12:00:00.000Z")
|
|
3740
3906
|
});
|
|
3741
3907
|
await expect6(storage.threads.getById(thread)).resolves.toMatchObject({
|
|
3908
|
+
runsOn: "computer",
|
|
3742
3909
|
computer: elsewhere,
|
|
3743
3910
|
movedAt: at2("2026-06-23T12:00:00.000Z")
|
|
3744
3911
|
});
|
|
3745
|
-
await
|
|
3912
|
+
await createRun(storage, fixture, runInput2({
|
|
3913
|
+
id: "run_cloud",
|
|
3914
|
+
threadId: "thr_cloud",
|
|
3915
|
+
spec: { model: { provider: "test", modelId: "large" } },
|
|
3916
|
+
execution: execution("cloud")
|
|
3917
|
+
}));
|
|
3918
|
+
await expectAgentError2(storage.threads.assignComputer({ projectId: projectId6, id: "thr_cloud", computer: laptop }), "active_run_exists");
|
|
3919
|
+
await storage.runs.start({ projectId: projectId6, id: "run_cloud", execution: execution("cloud") });
|
|
3920
|
+
await expectAgentError2(storage.threads.assignComputer({ projectId: projectId6, id: "thr_cloud", computer: laptop }), "active_run_exists");
|
|
3921
|
+
await storage.runs.finish({
|
|
3922
|
+
projectId: projectId6,
|
|
3923
|
+
id: "run_cloud",
|
|
3924
|
+
executionToken: "cloud",
|
|
3925
|
+
status: "cancelled"
|
|
3926
|
+
});
|
|
3927
|
+
const toLaptop = await storage.threads.assignComputer({
|
|
3928
|
+
projectId: projectId6,
|
|
3929
|
+
id: "thr_cloud",
|
|
3930
|
+
computer: laptop,
|
|
3931
|
+
movedAt: at2("2026-06-23T13:00:00.000Z")
|
|
3932
|
+
});
|
|
3933
|
+
expect6(toLaptop).toMatchObject({
|
|
3934
|
+
runsOn: "computer",
|
|
3935
|
+
computer: laptop,
|
|
3936
|
+
sandboxParams: { repo: "app" },
|
|
3937
|
+
movedAt: at2("2026-06-23T13:00:00.000Z")
|
|
3938
|
+
});
|
|
3939
|
+
const backToCloud = await storage.threads.moveToCloud({
|
|
3940
|
+
projectId: projectId6,
|
|
3941
|
+
id: "thr_cloud",
|
|
3942
|
+
movedAt: at2("2026-06-23T14:00:00.000Z")
|
|
3943
|
+
});
|
|
3944
|
+
expect6(backToCloud.thread).not.toHaveProperty("runsOn");
|
|
3945
|
+
expect6(backToCloud.thread).not.toHaveProperty("computer");
|
|
3946
|
+
expect6(backToCloud.thread).toMatchObject({
|
|
3947
|
+
sandboxParams: { repo: "app" },
|
|
3948
|
+
movedAt: at2("2026-06-23T14:00:00.000Z")
|
|
3949
|
+
});
|
|
3950
|
+
const backToElsewhere = await storage.threads.assignComputer({
|
|
3951
|
+
projectId: projectId6,
|
|
3952
|
+
id: "thr_cloud",
|
|
3953
|
+
computer: elsewhere,
|
|
3954
|
+
movedAt: at2("2026-06-23T15:00:00.000Z")
|
|
3955
|
+
});
|
|
3956
|
+
expect6(backToElsewhere).toMatchObject({
|
|
3957
|
+
runsOn: "computer",
|
|
3958
|
+
computer: elsewhere,
|
|
3959
|
+
movedAt: at2("2026-06-23T15:00:00.000Z")
|
|
3960
|
+
});
|
|
3961
|
+
await createRun(storage, fixture, runInput2({
|
|
3962
|
+
id: "run_with_place",
|
|
3963
|
+
threadId: "thr_cloud",
|
|
3964
|
+
spec: {
|
|
3965
|
+
model: { provider: "test", modelId: "large" },
|
|
3966
|
+
runsOn: "computer",
|
|
3967
|
+
computer: { id: elsewhere.id, folder: elsewhere.folder }
|
|
3968
|
+
},
|
|
3969
|
+
execution: execution("with_place")
|
|
3970
|
+
}));
|
|
3971
|
+
await storage.threads.assignComputer({
|
|
3972
|
+
projectId: projectId6,
|
|
3973
|
+
id: "thr_cloud",
|
|
3974
|
+
computer: laptop,
|
|
3975
|
+
movedAt: at2("2026-06-23T16:00:00.000Z")
|
|
3976
|
+
});
|
|
3977
|
+
expect6((await storage.runs.getById({ projectId: projectId6, id: "run_with_place" }))?.spec).toEqual({
|
|
3978
|
+
model: { provider: "test", modelId: "large" },
|
|
3979
|
+
runsOn: "computer",
|
|
3980
|
+
computer: { id: laptop.id, folder: laptop.folder }
|
|
3981
|
+
});
|
|
3982
|
+
const cloudAgain = await storage.threads.moveToCloud({
|
|
3983
|
+
projectId: projectId6,
|
|
3984
|
+
id: "thr_cloud",
|
|
3985
|
+
movedAt: at2("2026-06-23T17:00:00.000Z")
|
|
3986
|
+
});
|
|
3987
|
+
expect6(cloudAgain.queued?.spec).toEqual({ model: { provider: "test", modelId: "large" } });
|
|
3746
3988
|
await expectAgentError2(storage.threads.assignComputer({ projectId: projectId6, id: "thr_none", computer: laptop }), "thread_not_found");
|
|
3747
3989
|
await expectAgentError2(storage.threads.assignComputer({ ...thread, computer: { ...laptop, id: " " } }), "invalid_input");
|
|
3748
|
-
|
|
3990
|
+
});
|
|
3991
|
+
});
|
|
3992
|
+
test6("retires a paused child's cloud workspace when its conversation moves to a computer", async () => {
|
|
3993
|
+
await withStorage(async (storage, fixture) => {
|
|
3994
|
+
await storage.threads.create(threadInput({ id: "thr_neighbour", sandboxParams: {} }));
|
|
3995
|
+
await createAndStartRun(storage, fixture, runInput2({
|
|
3996
|
+
id: "run_neighbour",
|
|
3997
|
+
threadId: "thr_neighbour",
|
|
3998
|
+
execution: execution("neighbour_token", new Date("2099-01-01"))
|
|
3999
|
+
}));
|
|
4000
|
+
const acquireNeighbour = {
|
|
4001
|
+
projectId: projectId6,
|
|
4002
|
+
id: "thr_neighbour",
|
|
4003
|
+
action: "acquire",
|
|
4004
|
+
runId: "run_neighbour",
|
|
4005
|
+
executionToken: "neighbour_token",
|
|
4006
|
+
name: "neighbour-workspace",
|
|
4007
|
+
sourceFingerprint: "c".repeat(64)
|
|
4008
|
+
};
|
|
4009
|
+
await storage.threads.transitionSandbox(acquireNeighbour);
|
|
4010
|
+
await storage.threads.transitionSandbox({
|
|
4011
|
+
...acquireNeighbour,
|
|
4012
|
+
action: "settle",
|
|
4013
|
+
status: "ready",
|
|
4014
|
+
initialized: true
|
|
4015
|
+
});
|
|
4016
|
+
await storage.runs.finish({
|
|
4017
|
+
projectId: projectId6,
|
|
4018
|
+
id: "run_neighbour",
|
|
4019
|
+
executionToken: "neighbour_token",
|
|
4020
|
+
status: "succeeded"
|
|
4021
|
+
});
|
|
4022
|
+
await createRunningParent(storage, fixture);
|
|
4023
|
+
await createSubagent(storage, fixture);
|
|
4024
|
+
await storage.runs.start({
|
|
4025
|
+
projectId: projectId6,
|
|
4026
|
+
id: "child_1",
|
|
4027
|
+
execution: execution("child_token", new Date("2099-01-01"))
|
|
4028
|
+
});
|
|
4029
|
+
const acquire = {
|
|
4030
|
+
projectId: projectId6,
|
|
4031
|
+
id: "thread_child_1",
|
|
4032
|
+
action: "acquire",
|
|
4033
|
+
runId: "child_1",
|
|
4034
|
+
executionToken: "child_token",
|
|
4035
|
+
name: "child-workspace",
|
|
4036
|
+
sourceFingerprint: "b".repeat(64)
|
|
4037
|
+
};
|
|
4038
|
+
await storage.threads.transitionSandbox(acquire);
|
|
4039
|
+
await storage.threads.transitionSandbox({
|
|
4040
|
+
...acquire,
|
|
4041
|
+
action: "settle",
|
|
4042
|
+
status: "ready",
|
|
4043
|
+
initialized: true
|
|
4044
|
+
});
|
|
4045
|
+
await storage.runs.finish({
|
|
4046
|
+
projectId: projectId6,
|
|
4047
|
+
id: "child_1",
|
|
4048
|
+
executionToken: "child_token",
|
|
4049
|
+
status: "succeeded",
|
|
4050
|
+
result: { text: "Looked west." }
|
|
4051
|
+
});
|
|
4052
|
+
await storage.runs.finish({
|
|
4053
|
+
projectId: projectId6,
|
|
4054
|
+
id: "parent_1",
|
|
4055
|
+
executionToken: "parent_token",
|
|
4056
|
+
status: "succeeded"
|
|
4057
|
+
});
|
|
4058
|
+
await storage.threads.assignComputer({
|
|
4059
|
+
projectId: projectId6,
|
|
4060
|
+
id: "parent_thread",
|
|
4061
|
+
computer: laptop
|
|
4062
|
+
});
|
|
4063
|
+
await expect6(storage.threads.getById({ projectId: projectId6, id: "thread_child_1" })).resolves.toMatchObject({
|
|
4064
|
+
sandboxState: { name: "child-workspace", status: "unavailable" }
|
|
4065
|
+
});
|
|
4066
|
+
await expect6(storage.threads.getById({ projectId: projectId6, id: "thr_neighbour" })).resolves.toMatchObject({
|
|
4067
|
+
sandboxState: { name: "neighbour-workspace", status: "ready" }
|
|
4068
|
+
});
|
|
3749
4069
|
});
|
|
3750
4070
|
});
|
|
3751
4071
|
test6("moves a computer's thread to the cloud with its queued turn, never while one runs", async () => {
|
|
@@ -4097,59 +4417,346 @@ function runAgentStorageContractSuite(label, options) {
|
|
|
4097
4417
|
...participantsInput(["usr_bob", "usr_cleo"]),
|
|
4098
4418
|
maxParticipants: 2
|
|
4099
4419
|
});
|
|
4100
|
-
expect6(kept.map((record) => record.principal.id)).toEqual(["usr_bob", "usr_cleo"]);
|
|
4420
|
+
expect6(kept.map((record) => record.principal.id)).toEqual(["usr_bob", "usr_cleo"]);
|
|
4421
|
+
});
|
|
4422
|
+
});
|
|
4423
|
+
test6("removes a participant and lists the threads shared with a user", async () => {
|
|
4424
|
+
await withStorage(async (storage) => {
|
|
4425
|
+
await storage.threads.create(threadInput({ id: "thr_a", createdAt: at2("2026-06-23T10:00:00.000Z") }));
|
|
4426
|
+
await storage.threads.create(threadInput({ id: "thr_b", createdAt: at2("2026-06-23T10:01:00.000Z") }));
|
|
4427
|
+
await storage.threads.create(threadInput({ id: "thr_c", createdAt: at2("2026-06-23T10:02:00.000Z") }));
|
|
4428
|
+
await storage.threads.create(threadInput({ id: "thr_a", projectId: otherProjectId3 }));
|
|
4429
|
+
for (const threadId of ["thr_a", "thr_c"]) {
|
|
4430
|
+
await storage.threads.addParticipants({ ...participantsInput(["usr_bob"]), threadId });
|
|
4431
|
+
}
|
|
4432
|
+
await storage.threads.addParticipants({
|
|
4433
|
+
...participantsInput(["usr_bob"]),
|
|
4434
|
+
projectId: otherProjectId3,
|
|
4435
|
+
threadId: "thr_a"
|
|
4436
|
+
});
|
|
4437
|
+
const bob = { type: "user", id: "usr_bob" };
|
|
4438
|
+
const shared = await storage.threads.list({
|
|
4439
|
+
projectId: projectId6,
|
|
4440
|
+
participantPrincipal: bob,
|
|
4441
|
+
order: "asc"
|
|
4442
|
+
});
|
|
4443
|
+
expect6(shared.threads.map((thread) => thread.id)).toEqual(["thr_a", "thr_c"]);
|
|
4444
|
+
expect6(shared.total).toBe(2);
|
|
4445
|
+
const page = await storage.threads.list({
|
|
4446
|
+
projectId: projectId6,
|
|
4447
|
+
participantPrincipal: bob,
|
|
4448
|
+
order: "desc",
|
|
4449
|
+
limit: 1
|
|
4450
|
+
});
|
|
4451
|
+
expect6(page.threads.map((thread) => thread.id)).toEqual(["thr_c"]);
|
|
4452
|
+
expect6(page.hasMore).toBe(true);
|
|
4453
|
+
expect6(await storage.threads.removeParticipant({ projectId: projectId6, threadId: "thr_a", principal: bob })).toBe(true);
|
|
4454
|
+
expect6(await storage.threads.removeParticipant({ projectId: projectId6, threadId: "thr_a", principal: bob })).toBe(false);
|
|
4455
|
+
expect6(await storage.threads.removeParticipant({ projectId: projectId6, threadId: "nope", principal: bob })).toBe(false);
|
|
4456
|
+
const after = await storage.threads.list({ projectId: projectId6, participantPrincipal: bob });
|
|
4457
|
+
expect6(after.threads.map((thread) => thread.id)).toEqual(["thr_c"]);
|
|
4458
|
+
expect6(await storage.threads.listParticipants({ projectId: projectId6, threadIds: ["thr_a", "thr_b"] })).toEqual([]);
|
|
4459
|
+
expect6(await storage.threads.listParticipants({
|
|
4460
|
+
projectId: otherProjectId3,
|
|
4461
|
+
threadIds: ["thr_a"]
|
|
4462
|
+
})).toHaveLength(1);
|
|
4463
|
+
});
|
|
4464
|
+
});
|
|
4465
|
+
test6("rolls participants back with their transaction", async () => {
|
|
4466
|
+
await withStorage(async (storage, fixture) => {
|
|
4467
|
+
await storage.threads.create(threadInput());
|
|
4468
|
+
await expect6(fixture.transaction(async (tx) => {
|
|
4469
|
+
await tx.agents?.threads.addParticipants(participantsInput(["usr_bob"]));
|
|
4470
|
+
throw new Error("rollback");
|
|
4471
|
+
})).rejects.toThrow("rollback");
|
|
4472
|
+
expect6(await storage.threads.listParticipants({ projectId: projectId6, threadIds: ["thr_1"] })).toEqual([]);
|
|
4473
|
+
});
|
|
4474
|
+
});
|
|
4475
|
+
test6("marks how far one person has read, never backwards, by message", async () => {
|
|
4476
|
+
await withStorage(async (storage) => {
|
|
4477
|
+
await storage.threads.create(threadInput());
|
|
4478
|
+
for (const id of ["m1", "m2", "m3"]) {
|
|
4479
|
+
await storage.messages.append({
|
|
4480
|
+
id,
|
|
4481
|
+
projectId: projectId6,
|
|
4482
|
+
threadId: "thr_1",
|
|
4483
|
+
runId: null,
|
|
4484
|
+
role: "user",
|
|
4485
|
+
authorPrincipal: user("usr_bob"),
|
|
4486
|
+
parts: [{ type: "text", text: id }],
|
|
4487
|
+
createdAt: at2("2026-06-23T10:00:00.000Z")
|
|
4488
|
+
});
|
|
4489
|
+
}
|
|
4490
|
+
const mark = (input) => storage.reads.mark({
|
|
4491
|
+
projectId: projectId6,
|
|
4492
|
+
threadId: "thr_1",
|
|
4493
|
+
principal: input.principal ?? user("usr_1"),
|
|
4494
|
+
...input.throughMessageId === undefined ? {} : { throughMessageId: input.throughMessageId },
|
|
4495
|
+
...input.readAt === undefined ? {} : { readAt: input.readAt }
|
|
4496
|
+
});
|
|
4497
|
+
expect6(await mark({ throughMessageId: "m2", readAt: at2("2026-06-23T11:00:00.000Z") })).toEqual({
|
|
4498
|
+
threadId: "thr_1",
|
|
4499
|
+
throughSeq: 2,
|
|
4500
|
+
headSeq: 3,
|
|
4501
|
+
unread: 1,
|
|
4502
|
+
readAt: at2("2026-06-23T11:00:00.000Z")
|
|
4503
|
+
});
|
|
4504
|
+
const back = await mark({ throughMessageId: "m1", readAt: at2("2026-06-23T12:00:00.000Z") });
|
|
4505
|
+
expect6(back.throughSeq).toBe(2);
|
|
4506
|
+
expect6(back.readAt?.toISOString()).toBe("2026-06-23T12:00:00.000Z");
|
|
4507
|
+
const earlier = await mark({
|
|
4508
|
+
throughMessageId: "m2",
|
|
4509
|
+
readAt: at2("2026-06-23T09:00:00.000Z")
|
|
4510
|
+
});
|
|
4511
|
+
expect6(earlier.readAt?.toISOString()).toBe("2026-06-23T12:00:00.000Z");
|
|
4512
|
+
expect6(await mark({})).toMatchObject({ throughSeq: 3, headSeq: 3, unread: 0 });
|
|
4513
|
+
const other = await mark({ principal: user("usr_2"), throughMessageId: "m_gone" });
|
|
4514
|
+
expect6(other).toEqual({ threadId: "thr_1", throughSeq: 0, headSeq: 3, unread: 3 });
|
|
4515
|
+
expect6(await storage.reads.list({
|
|
4516
|
+
projectId: projectId6,
|
|
4517
|
+
threadIds: ["thr_1", "thr_1", "thr_missing"],
|
|
4518
|
+
principal: user("usr_2")
|
|
4519
|
+
})).toEqual([{ threadId: "thr_1", throughSeq: 0, headSeq: 3, unread: 3 }]);
|
|
4520
|
+
await expectAgentError2(storage.reads.mark({ projectId: projectId6, threadId: "thr_missing", principal: user("usr_1") }), "thread_not_found");
|
|
4521
|
+
});
|
|
4522
|
+
});
|
|
4523
|
+
test6("counts as unread what someone else wrote", async () => {
|
|
4524
|
+
await withStorage(async (storage) => {
|
|
4525
|
+
const alice = user("usr_1");
|
|
4526
|
+
const bob = user("usr_bob");
|
|
4527
|
+
await storage.threads.create(threadInput());
|
|
4528
|
+
const message = (id, role, author, parts) => storage.messages.append({
|
|
4529
|
+
id,
|
|
4530
|
+
projectId: projectId6,
|
|
4531
|
+
threadId: "thr_1",
|
|
4532
|
+
runId: null,
|
|
4533
|
+
role,
|
|
4534
|
+
authorPrincipal: author,
|
|
4535
|
+
parts
|
|
4536
|
+
});
|
|
4537
|
+
await message("m1", "user", alice, [{ type: "text", text: "question" }]);
|
|
4538
|
+
await message("m2", "assistant", alice, [{ type: "text", text: "answer" }]);
|
|
4539
|
+
await message("m3", "user", alice, [
|
|
4540
|
+
{
|
|
4541
|
+
type: "approval-outcome",
|
|
4542
|
+
approvalId: "apr_1",
|
|
4543
|
+
status: "approved",
|
|
4544
|
+
call: {
|
|
4545
|
+
kind: "action",
|
|
4546
|
+
actionId: "mark-paid",
|
|
4547
|
+
subject: { kind: "object", objectTypeId: "invoice", primaryId: "INV-2041" }
|
|
4548
|
+
}
|
|
4549
|
+
}
|
|
4550
|
+
]);
|
|
4551
|
+
await message("m4", "user", bob, [{ type: "text", text: "hello" }]);
|
|
4552
|
+
const place = (principal) => storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal });
|
|
4553
|
+
expect6(await place(alice)).toEqual([
|
|
4554
|
+
{ threadId: "thr_1", throughSeq: 0, headSeq: 4, unread: 2 }
|
|
4555
|
+
]);
|
|
4556
|
+
expect6(await place(bob)).toMatchObject([{ unread: 2 }]);
|
|
4557
|
+
await storage.reads.mark({
|
|
4558
|
+
projectId: projectId6,
|
|
4559
|
+
threadId: "thr_1",
|
|
4560
|
+
principal: alice,
|
|
4561
|
+
throughMessageId: "m2"
|
|
4562
|
+
});
|
|
4563
|
+
expect6(await place(alice)).toMatchObject([{ throughSeq: 2, unread: 1 }]);
|
|
4564
|
+
});
|
|
4565
|
+
});
|
|
4566
|
+
test6("a retried turn's new answer is unread to whoever read the failed one", async () => {
|
|
4567
|
+
await withStorage(async (storage, fixture) => {
|
|
4568
|
+
const bob = user("usr_bob");
|
|
4569
|
+
await storage.threads.create(threadInput());
|
|
4570
|
+
await storage.messages.append({
|
|
4571
|
+
id: "m1",
|
|
4572
|
+
projectId: projectId6,
|
|
4573
|
+
threadId: "thr_1",
|
|
4574
|
+
runId: null,
|
|
4575
|
+
role: "user",
|
|
4576
|
+
authorPrincipal: owner,
|
|
4577
|
+
parts: [{ type: "text", text: "first" }]
|
|
4578
|
+
});
|
|
4579
|
+
await createAndStartRun(storage, fixture, runInput2({ triggerMessageId: "m1" }));
|
|
4580
|
+
await storage.messages.append({
|
|
4581
|
+
id: "m2",
|
|
4582
|
+
projectId: projectId6,
|
|
4583
|
+
threadId: "thr_1",
|
|
4584
|
+
runId: "run_1",
|
|
4585
|
+
role: "assistant",
|
|
4586
|
+
authorPrincipal: owner,
|
|
4587
|
+
parts: [{ type: "text", text: "failed answer" }]
|
|
4588
|
+
});
|
|
4589
|
+
await storage.threads.addParticipants(participantsInput(["usr_bob"]));
|
|
4590
|
+
await storage.runs.finish({
|
|
4591
|
+
id: "run_1",
|
|
4592
|
+
projectId: projectId6,
|
|
4593
|
+
executionToken: "exec_1",
|
|
4594
|
+
status: "failed"
|
|
4595
|
+
});
|
|
4596
|
+
await storage.messages.deleteByRunId({ projectId: projectId6, threadId: "thr_1", runId: "run_1" });
|
|
4597
|
+
const retried = await storage.messages.append({
|
|
4598
|
+
id: "m3",
|
|
4599
|
+
projectId: projectId6,
|
|
4600
|
+
threadId: "thr_1",
|
|
4601
|
+
runId: null,
|
|
4602
|
+
role: "assistant",
|
|
4603
|
+
authorPrincipal: owner,
|
|
4604
|
+
parts: [{ type: "text", text: "retried answer" }]
|
|
4605
|
+
});
|
|
4606
|
+
expect6(retried.seq).toBe(2);
|
|
4607
|
+
expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 1, headSeq: 2, unread: 1 }]);
|
|
4608
|
+
await storage.reads.mark({
|
|
4609
|
+
projectId: projectId6,
|
|
4610
|
+
threadId: "thr_1",
|
|
4611
|
+
principal: bob,
|
|
4612
|
+
throughMessageId: "m2"
|
|
4613
|
+
});
|
|
4614
|
+
expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 1, unread: 1 }]);
|
|
4615
|
+
});
|
|
4616
|
+
});
|
|
4617
|
+
test6("retrying an older turn leaves what came after it read", async () => {
|
|
4618
|
+
await withStorage(async (storage, fixture) => {
|
|
4619
|
+
const bob = user("usr_bob");
|
|
4620
|
+
await storage.threads.create(threadInput());
|
|
4621
|
+
const message = (id, role, runId) => storage.messages.append({
|
|
4622
|
+
id,
|
|
4623
|
+
projectId: projectId6,
|
|
4624
|
+
threadId: "thr_1",
|
|
4625
|
+
runId,
|
|
4626
|
+
role,
|
|
4627
|
+
authorPrincipal: owner,
|
|
4628
|
+
parts: [{ type: "text", text: id }]
|
|
4629
|
+
});
|
|
4630
|
+
await message("m1", "user", null);
|
|
4631
|
+
await createAndStartRun(storage, fixture, runInput2({ triggerMessageId: "m1" }));
|
|
4632
|
+
await message("m2", "assistant", "run_1");
|
|
4633
|
+
await storage.runs.finish({
|
|
4634
|
+
id: "run_1",
|
|
4635
|
+
projectId: projectId6,
|
|
4636
|
+
executionToken: "exec_1",
|
|
4637
|
+
status: "failed"
|
|
4638
|
+
});
|
|
4639
|
+
await message("m3", "user", null);
|
|
4640
|
+
await message("m4", "assistant", null);
|
|
4641
|
+
await storage.threads.addParticipants(participantsInput(["usr_bob"]));
|
|
4642
|
+
await storage.messages.deleteByRunId({ projectId: projectId6, threadId: "thr_1", runId: "run_1" });
|
|
4643
|
+
expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 4, headSeq: 4, unread: 0 }]);
|
|
4644
|
+
});
|
|
4645
|
+
});
|
|
4646
|
+
test6("an edited message is unread to whoever read past it", async () => {
|
|
4647
|
+
await withStorage(async (storage) => {
|
|
4648
|
+
const bob = user("usr_bob");
|
|
4649
|
+
await storage.threads.create(threadInput());
|
|
4650
|
+
for (const id of ["m1", "m2", "m3"]) {
|
|
4651
|
+
await storage.messages.append({
|
|
4652
|
+
id,
|
|
4653
|
+
projectId: projectId6,
|
|
4654
|
+
threadId: "thr_1",
|
|
4655
|
+
runId: null,
|
|
4656
|
+
role: "user",
|
|
4657
|
+
authorPrincipal: owner,
|
|
4658
|
+
parts: [{ type: "text", text: id }]
|
|
4659
|
+
});
|
|
4660
|
+
}
|
|
4661
|
+
await storage.threads.addParticipants(participantsInput(["usr_bob"]));
|
|
4662
|
+
await storage.reads.mark({ projectId: projectId6, threadId: "thr_1", principal: user("usr_1") });
|
|
4663
|
+
await storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_1", fromSeq: 2 });
|
|
4664
|
+
await storage.messages.append({
|
|
4665
|
+
id: "m2_edited",
|
|
4666
|
+
projectId: projectId6,
|
|
4667
|
+
threadId: "thr_1",
|
|
4668
|
+
runId: null,
|
|
4669
|
+
role: "user",
|
|
4670
|
+
authorPrincipal: owner,
|
|
4671
|
+
parts: [{ type: "text", text: "edited" }]
|
|
4672
|
+
});
|
|
4673
|
+
expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: bob })).toMatchObject([{ throughSeq: 1, headSeq: 2, unread: 1 }]);
|
|
4674
|
+
expect6(await storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: user("usr_1") })).toMatchObject([{ throughSeq: 1, unread: 0 }]);
|
|
4101
4675
|
});
|
|
4102
4676
|
});
|
|
4103
|
-
test6("
|
|
4677
|
+
test6("starts a participant caught up and drops their row when they leave", async () => {
|
|
4104
4678
|
await withStorage(async (storage) => {
|
|
4105
|
-
await storage.threads.create(threadInput(
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4679
|
+
await storage.threads.create(threadInput());
|
|
4680
|
+
for (const id of ["m1", "m2"]) {
|
|
4681
|
+
await storage.messages.append({
|
|
4682
|
+
id,
|
|
4683
|
+
projectId: projectId6,
|
|
4684
|
+
threadId: "thr_1",
|
|
4685
|
+
runId: null,
|
|
4686
|
+
role: "user",
|
|
4687
|
+
authorPrincipal: owner,
|
|
4688
|
+
parts: [{ type: "text", text: id }],
|
|
4689
|
+
createdAt: at2("2026-06-23T10:00:00.000Z")
|
|
4690
|
+
});
|
|
4111
4691
|
}
|
|
4112
|
-
await storage.threads.addParticipants(
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4692
|
+
await storage.threads.addParticipants(participantsInput(["usr_bob"], at2("2026-06-23T11:00:00.000Z")));
|
|
4693
|
+
const bobsPlace = () => storage.reads.list({ projectId: projectId6, threadIds: ["thr_1"], principal: user("usr_bob") });
|
|
4694
|
+
expect6(await bobsPlace()).toEqual([
|
|
4695
|
+
{
|
|
4696
|
+
threadId: "thr_1",
|
|
4697
|
+
throughSeq: 2,
|
|
4698
|
+
headSeq: 2,
|
|
4699
|
+
unread: 0,
|
|
4700
|
+
readAt: at2("2026-06-23T11:00:00.000Z")
|
|
4701
|
+
}
|
|
4702
|
+
]);
|
|
4703
|
+
await storage.threads.removeParticipant({
|
|
4704
|
+
projectId: projectId6,
|
|
4705
|
+
threadId: "thr_1",
|
|
4706
|
+
principal: user("usr_bob")
|
|
4116
4707
|
});
|
|
4117
|
-
|
|
4118
|
-
|
|
4708
|
+
expect6(await bobsPlace()).toEqual([
|
|
4709
|
+
{ threadId: "thr_1", throughSeq: 0, headSeq: 2, unread: 2 }
|
|
4710
|
+
]);
|
|
4711
|
+
await storage.reads.mark({
|
|
4119
4712
|
projectId: projectId6,
|
|
4120
|
-
|
|
4121
|
-
|
|
4713
|
+
threadId: "thr_1",
|
|
4714
|
+
principal: user("usr_bob"),
|
|
4715
|
+
throughMessageId: "m1"
|
|
4122
4716
|
});
|
|
4123
|
-
|
|
4124
|
-
expect6(
|
|
4125
|
-
|
|
4717
|
+
await storage.threads.addParticipants(participantsInput(["usr_bob"], at2("2026-06-23T12:00:00.000Z")));
|
|
4718
|
+
expect6(await bobsPlace()).toMatchObject([{ throughSeq: 2, unread: 0 }]);
|
|
4719
|
+
});
|
|
4720
|
+
});
|
|
4721
|
+
test6("a fork keeps its owner's place, clamped to what it copied", async () => {
|
|
4722
|
+
await withStorage(async (storage, fixture) => {
|
|
4723
|
+
await prepareForkSource(storage, fixture);
|
|
4724
|
+
await storage.reads.mark({
|
|
4126
4725
|
projectId: projectId6,
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4726
|
+
threadId: "thr_1",
|
|
4727
|
+
principal: user("usr_2"),
|
|
4728
|
+
throughMessageId: "m4"
|
|
4130
4729
|
});
|
|
4131
|
-
|
|
4132
|
-
expect6(
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
expect6(after.threads.map((thread) => thread.id)).toEqual(["thr_c"]);
|
|
4138
|
-
expect6(await storage.threads.listParticipants({ projectId: projectId6, threadIds: ["thr_a", "thr_b"] })).toEqual([]);
|
|
4139
|
-
expect6(await storage.threads.listParticipants({
|
|
4140
|
-
projectId: otherProjectId3,
|
|
4141
|
-
threadIds: ["thr_a"]
|
|
4142
|
-
})).toHaveLength(1);
|
|
4730
|
+
await storage.threads.fork(forkInput());
|
|
4731
|
+
expect6(await storage.reads.list({
|
|
4732
|
+
projectId: projectId6,
|
|
4733
|
+
threadIds: ["thr_fork"],
|
|
4734
|
+
principal: user("usr_2")
|
|
4735
|
+
})).toMatchObject([{ throughSeq: 4 }]);
|
|
4143
4736
|
});
|
|
4144
4737
|
});
|
|
4145
|
-
test6("
|
|
4738
|
+
test6("reads each thread's newest run, by creation then id", async () => {
|
|
4146
4739
|
await withStorage(async (storage, fixture) => {
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4740
|
+
for (const id of ["thr_1", "thr_2", "thr_3"]) {
|
|
4741
|
+
await storage.threads.create(threadInput({ id }));
|
|
4742
|
+
}
|
|
4743
|
+
const run = async (id, threadId, createdAt, status) => {
|
|
4744
|
+
await createAndStartRun(storage, fixture, runInput2({ id, threadId, createdAt: at2(createdAt), execution: execution(`exec_${id}`) }));
|
|
4745
|
+
await storage.runs.finish({ id, projectId: projectId6, executionToken: `exec_${id}`, status });
|
|
4746
|
+
};
|
|
4747
|
+
await run("run_1", "thr_1", "2026-06-23T10:00:10.000Z", "failed");
|
|
4748
|
+
await run("run_2", "thr_1", "2026-06-23T10:00:20.000Z", "succeeded");
|
|
4749
|
+
await run("run_b", "thr_2", "2026-06-23T10:00:30.000Z", "failed");
|
|
4750
|
+
await run("run_c", "thr_2", "2026-06-23T10:00:30.000Z", "succeeded");
|
|
4751
|
+
const latest = await storage.runs.latestByThread({
|
|
4752
|
+
projectId: projectId6,
|
|
4753
|
+
threadIds: ["thr_1", "thr_2", "thr_3", "thr_missing"]
|
|
4754
|
+
});
|
|
4755
|
+
expect6(latest.map((entry) => [entry.threadId, entry.id, entry.status]).sort()).toEqual([
|
|
4756
|
+
["thr_1", "run_2", "succeeded"],
|
|
4757
|
+
["thr_2", "run_c", "succeeded"]
|
|
4758
|
+
]);
|
|
4759
|
+
expect6(await storage.runs.latestByThread({ projectId: projectId6, threadIds: [] })).toEqual([]);
|
|
4153
4760
|
});
|
|
4154
4761
|
});
|
|
4155
4762
|
test6("creates a queued run before execution and claims the thread", async () => {
|
|
@@ -4594,6 +5201,26 @@ function runAgentStorageContractSuite(label, options) {
|
|
|
4594
5201
|
}
|
|
4595
5202
|
});
|
|
4596
5203
|
});
|
|
5204
|
+
test6("keeps a child's read-only and workspace flags, and rejects one that is not true", async () => {
|
|
5205
|
+
await withStorage(async (storage, fixture) => {
|
|
5206
|
+
await createRunningParent(storage, fixture);
|
|
5207
|
+
const spec = {
|
|
5208
|
+
...subagentInput("parent_token").spec,
|
|
5209
|
+
readOnly: true,
|
|
5210
|
+
inParentWorkspace: true
|
|
5211
|
+
};
|
|
5212
|
+
await createSubagent(storage, fixture, { spec });
|
|
5213
|
+
expect6((await storage.runs.getById({ projectId: projectId6, id: "child_1" }))?.spec).toEqual(spec);
|
|
5214
|
+
for (const flag of ["readOnly", "inParentWorkspace"]) {
|
|
5215
|
+
await expectAgentError2(createSubagent(storage, fixture, {
|
|
5216
|
+
id: "child_2",
|
|
5217
|
+
executionId: "test_agent_execution:child_2",
|
|
5218
|
+
spawnKey: `invalid-${flag}`,
|
|
5219
|
+
spec: { ...spec, [flag]: false }
|
|
5220
|
+
}), "invalid_input");
|
|
5221
|
+
}
|
|
5222
|
+
});
|
|
5223
|
+
});
|
|
4597
5224
|
test6("enforces the active-child limit atomically", async () => {
|
|
4598
5225
|
await withStorage(async (storage, fixture) => {
|
|
4599
5226
|
await createRunningParent(storage, fixture);
|
|
@@ -5656,6 +6283,142 @@ function runAgentStorageContractSuite(label, options) {
|
|
|
5656
6283
|
expect6(await storage.checkpoints.getLatest({ projectId: projectId6, threadId: "thr_fork" })).toBeNull();
|
|
5657
6284
|
});
|
|
5658
6285
|
});
|
|
6286
|
+
test6("deletes messages from a sequence onward, repairs thread stats, and reuses the sequence", async () => {
|
|
6287
|
+
await withStorage(async (storage) => {
|
|
6288
|
+
await storage.threads.create(threadInput({ id: "thr_rewind" }));
|
|
6289
|
+
const t1 = at2("2026-06-23T10:00:00.000Z");
|
|
6290
|
+
const t2 = at2("2026-06-23T10:01:00.000Z");
|
|
6291
|
+
const t3 = at2("2026-06-23T10:02:00.000Z");
|
|
6292
|
+
await storage.messages.append({
|
|
6293
|
+
id: "m1",
|
|
6294
|
+
projectId: projectId6,
|
|
6295
|
+
threadId: "thr_rewind",
|
|
6296
|
+
runId: null,
|
|
6297
|
+
role: "user",
|
|
6298
|
+
parts: [{ type: "text", text: "First" }],
|
|
6299
|
+
createdAt: t1
|
|
6300
|
+
});
|
|
6301
|
+
await storage.messages.append({
|
|
6302
|
+
id: "m2",
|
|
6303
|
+
projectId: projectId6,
|
|
6304
|
+
threadId: "thr_rewind",
|
|
6305
|
+
runId: null,
|
|
6306
|
+
role: "user",
|
|
6307
|
+
parts: [
|
|
6308
|
+
{
|
|
6309
|
+
type: "approval-outcome",
|
|
6310
|
+
approvalId: "apr_1",
|
|
6311
|
+
status: "denied",
|
|
6312
|
+
call: { kind: "workflow", workflowId: "wf_1" }
|
|
6313
|
+
}
|
|
6314
|
+
],
|
|
6315
|
+
createdAt: t2
|
|
6316
|
+
});
|
|
6317
|
+
await storage.messages.append({
|
|
6318
|
+
id: "m3",
|
|
6319
|
+
projectId: projectId6,
|
|
6320
|
+
threadId: "thr_rewind",
|
|
6321
|
+
runId: null,
|
|
6322
|
+
role: "user",
|
|
6323
|
+
parts: [{ type: "text", text: "Second" }],
|
|
6324
|
+
createdAt: t3
|
|
6325
|
+
});
|
|
6326
|
+
expect6(await storage.threads.getById({ projectId: projectId6, id: "thr_rewind" })).toMatchObject({
|
|
6327
|
+
messageCount: 2,
|
|
6328
|
+
lastMessageAt: t3
|
|
6329
|
+
});
|
|
6330
|
+
await expectAgentError2(storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_rewind", fromSeq: 0 }), "invalid_input");
|
|
6331
|
+
await expectAgentError2(storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "missing", fromSeq: 1 }), "thread_not_found");
|
|
6332
|
+
expect6(await storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_rewind", fromSeq: 2 })).toBe(2);
|
|
6333
|
+
expect6(await storage.threads.getById({ projectId: projectId6, id: "thr_rewind" })).toMatchObject({
|
|
6334
|
+
messageCount: 1,
|
|
6335
|
+
lastMessageAt: t1
|
|
6336
|
+
});
|
|
6337
|
+
const replacement = await storage.messages.append({
|
|
6338
|
+
id: "m2_next",
|
|
6339
|
+
projectId: projectId6,
|
|
6340
|
+
threadId: "thr_rewind",
|
|
6341
|
+
runId: null,
|
|
6342
|
+
role: "user",
|
|
6343
|
+
parts: [{ type: "text", text: "Edited second" }],
|
|
6344
|
+
createdAt: at2("2026-06-23T10:05:00.000Z")
|
|
6345
|
+
});
|
|
6346
|
+
expect6(replacement.seq).toBe(2);
|
|
6347
|
+
expect6(await storage.messages.deleteFromSeq({ projectId: projectId6, threadId: "thr_rewind", fromSeq: 1 })).toBe(2);
|
|
6348
|
+
expect6(await storage.threads.getById({ projectId: projectId6, id: "thr_rewind" })).toMatchObject({
|
|
6349
|
+
messageCount: 0,
|
|
6350
|
+
lastMessageAt: undefined
|
|
6351
|
+
});
|
|
6352
|
+
});
|
|
6353
|
+
});
|
|
6354
|
+
test6("deletes chained checkpoints past a retained sequence without violating chain foreign keys", async () => {
|
|
6355
|
+
await withStorage(async (storage, fixture) => {
|
|
6356
|
+
await storage.threads.create(threadInput({ id: "thr_cp" }));
|
|
6357
|
+
for (let i = 1;i <= 3; i += 1) {
|
|
6358
|
+
await storage.messages.append({
|
|
6359
|
+
id: `u_${i}`,
|
|
6360
|
+
projectId: projectId6,
|
|
6361
|
+
threadId: "thr_cp",
|
|
6362
|
+
runId: null,
|
|
6363
|
+
role: "user",
|
|
6364
|
+
parts: [{ type: "text", text: `Prompt ${i}` }]
|
|
6365
|
+
});
|
|
6366
|
+
const runId = `run_cp_${i}`;
|
|
6367
|
+
await createAndStartRun(storage, fixture, runInput2({
|
|
6368
|
+
id: runId,
|
|
6369
|
+
threadId: "thr_cp",
|
|
6370
|
+
triggerMessageId: `u_${i}`,
|
|
6371
|
+
execution: execution(`tok_${i}`)
|
|
6372
|
+
}));
|
|
6373
|
+
if (i >= 2) {
|
|
6374
|
+
const headSeq = (i - 1) * 2 + 1;
|
|
6375
|
+
await storage.checkpoints.create({
|
|
6376
|
+
id: `cp_${i - 1}`,
|
|
6377
|
+
projectId: projectId6,
|
|
6378
|
+
threadId: "thr_cp",
|
|
6379
|
+
createdByRunId: runId,
|
|
6380
|
+
expectedPreviousCheckpointId: i === 2 ? null : `cp_${i - 2}`,
|
|
6381
|
+
expectedHeadSeq: headSeq,
|
|
6382
|
+
executionToken: `tok_${i}`,
|
|
6383
|
+
reason: "threshold",
|
|
6384
|
+
summary: `Summary through turn ${i - 1}`,
|
|
6385
|
+
summaryFormatVersion: 1,
|
|
6386
|
+
summarizedThroughSeq: headSeq - 1,
|
|
6387
|
+
observedHeadSeq: headSeq,
|
|
6388
|
+
estimatedInputTokensBefore: 1000,
|
|
6389
|
+
estimatedInputTokensAfter: 300,
|
|
6390
|
+
summaryModelId: "test-model"
|
|
6391
|
+
});
|
|
6392
|
+
}
|
|
6393
|
+
await storage.messages.append({
|
|
6394
|
+
id: `a_${i}`,
|
|
6395
|
+
projectId: projectId6,
|
|
6396
|
+
threadId: "thr_cp",
|
|
6397
|
+
runId,
|
|
6398
|
+
role: "assistant",
|
|
6399
|
+
parts: [{ type: "text", text: `Reply ${i}` }]
|
|
6400
|
+
});
|
|
6401
|
+
await storage.runs.finish({
|
|
6402
|
+
projectId: projectId6,
|
|
6403
|
+
id: runId,
|
|
6404
|
+
executionToken: `tok_${i}`,
|
|
6405
|
+
status: "succeeded"
|
|
6406
|
+
});
|
|
6407
|
+
}
|
|
6408
|
+
expect6(await storage.checkpoints.deleteAfterSeq({
|
|
6409
|
+
projectId: projectId6,
|
|
6410
|
+
threadId: "thr_cp",
|
|
6411
|
+
afterSeq: 4
|
|
6412
|
+
})).toBe(1);
|
|
6413
|
+
expect6((await storage.checkpoints.getLatest({ projectId: projectId6, threadId: "thr_cp" }))?.id).toBe("cp_1");
|
|
6414
|
+
expect6(await storage.checkpoints.deleteAfterSeq({
|
|
6415
|
+
projectId: projectId6,
|
|
6416
|
+
threadId: "thr_cp",
|
|
6417
|
+
afterSeq: 0
|
|
6418
|
+
})).toBe(1);
|
|
6419
|
+
expect6(await storage.checkpoints.getLatest({ projectId: projectId6, threadId: "thr_cp" })).toBeNull();
|
|
6420
|
+
});
|
|
6421
|
+
});
|
|
5659
6422
|
});
|
|
5660
6423
|
}
|
|
5661
6424
|
// src/testing/agent-token-rate-storage-contract.ts
|
|
@@ -6121,6 +6884,45 @@ function runAiCostStorageContractSuite(name, options) {
|
|
|
6121
6884
|
await options.cleanup?.(storage);
|
|
6122
6885
|
}
|
|
6123
6886
|
});
|
|
6887
|
+
test8("buckets a series on the calendar of the query's time zone", async () => {
|
|
6888
|
+
const storage = await fixture();
|
|
6889
|
+
try {
|
|
6890
|
+
const august = {
|
|
6891
|
+
from: new Date("2026-08-03T00:00:00.000Z"),
|
|
6892
|
+
to: new Date("2026-08-05T00:00:00.000Z")
|
|
6893
|
+
};
|
|
6894
|
+
const callsIn = async (query) => (await storage.queryProjectOverview({ projectId: projectId8, ...august, bucket: "day", ...query })).series.map((period) => period.modelCallCount);
|
|
6895
|
+
expect8(await callsIn({})).toEqual([1, 0]);
|
|
6896
|
+
expect8(await callsIn({ timeZone: "Pacific/Kiritimati" })).toEqual([0, 1, 0]);
|
|
6897
|
+
const november = await storage.queryProjectOverview({
|
|
6898
|
+
projectId: projectId8,
|
|
6899
|
+
from: new Date("2026-11-01T04:00:00.000Z"),
|
|
6900
|
+
to: new Date("2026-11-03T05:00:00.000Z"),
|
|
6901
|
+
bucket: "day",
|
|
6902
|
+
timeZone: "America/New_York"
|
|
6903
|
+
});
|
|
6904
|
+
expect8(november.series.map((period) => [period.start.toISOString(), period.modelCallCount])).toEqual([
|
|
6905
|
+
["2026-11-01T04:00:00.000Z", 1],
|
|
6906
|
+
["2026-11-02T05:00:00.000Z", 1]
|
|
6907
|
+
]);
|
|
6908
|
+
const santiago = await storage.queryProjectOverview({
|
|
6909
|
+
projectId: projectId8,
|
|
6910
|
+
from: new Date("2026-09-05T04:00:00.000Z"),
|
|
6911
|
+
to: new Date("2026-11-03T03:00:00.000Z"),
|
|
6912
|
+
bucket: "day",
|
|
6913
|
+
timeZone: "America/Santiago",
|
|
6914
|
+
providerId: "gateway",
|
|
6915
|
+
modelId: "clock/model"
|
|
6916
|
+
});
|
|
6917
|
+
expect8(santiago.series).toHaveLength(59);
|
|
6918
|
+
expect8(santiago.series.filter((period) => period.modelCallCount > 0).map((period) => [period.start.toISOString(), period.modelCallCount])).toEqual([
|
|
6919
|
+
["2026-11-01T03:00:00.000Z", 1],
|
|
6920
|
+
["2026-11-02T03:00:00.000Z", 1]
|
|
6921
|
+
]);
|
|
6922
|
+
} finally {
|
|
6923
|
+
await options.cleanup?.(storage);
|
|
6924
|
+
}
|
|
6925
|
+
});
|
|
6124
6926
|
test8("rejects missing usage and mismatched billed quantities", async () => {
|
|
6125
6927
|
const storage = await fixture();
|
|
6126
6928
|
try {
|
|
@@ -6232,6 +7034,25 @@ async function seedAiCostStorageContractUsage(executions, usage) {
|
|
|
6232
7034
|
occurredAt: new Date("2026-08-03T12:00:00.000Z"),
|
|
6233
7035
|
recordedAt: new Date("2026-08-03T12:00:00.100Z")
|
|
6234
7036
|
});
|
|
7037
|
+
for (const [index, occurredAt] of [
|
|
7038
|
+
"2026-11-01T12:00:00.000Z",
|
|
7039
|
+
"2026-11-02T12:00:00.000Z"
|
|
7040
|
+
].entries()) {
|
|
7041
|
+
await usage.recordModelCall({
|
|
7042
|
+
id: `clock_${index}`,
|
|
7043
|
+
projectId: projectId8,
|
|
7044
|
+
executionId: otherExecutionId,
|
|
7045
|
+
attempt: 1,
|
|
7046
|
+
callId: `clock_${index}`,
|
|
7047
|
+
responseId: `response_clock_${index}`,
|
|
7048
|
+
requesterGroupIds: [],
|
|
7049
|
+
providerId: "gateway",
|
|
7050
|
+
requestedModelId: "clock/model",
|
|
7051
|
+
usage: { inputTokens: 1, outputTokens: 1 },
|
|
7052
|
+
occurredAt: new Date(occurredAt),
|
|
7053
|
+
recordedAt: new Date(occurredAt)
|
|
7054
|
+
});
|
|
7055
|
+
}
|
|
6235
7056
|
for (const [day, calls, complete, tokens] of [
|
|
6236
7057
|
[16, 87, 84, 4013782],
|
|
6237
7058
|
[18, 29, 28, 334815]
|
|
@@ -6279,7 +7100,7 @@ var projectId9 = "ai-limit-contract";
|
|
|
6279
7100
|
var executionId2 = "exec_ai_limit_1";
|
|
6280
7101
|
var project = { type: "project" };
|
|
6281
7102
|
var support = { type: "group", id: "support" };
|
|
6282
|
-
var
|
|
7103
|
+
var user2 = { type: "user", id: "user-1" };
|
|
6283
7104
|
function at4(value) {
|
|
6284
7105
|
return new Date(value);
|
|
6285
7106
|
}
|
|
@@ -6289,7 +7110,7 @@ function reservation(callId, tokens, overrides = {}) {
|
|
|
6289
7110
|
executionId: executionId2,
|
|
6290
7111
|
attempt: 1,
|
|
6291
7112
|
callId,
|
|
6292
|
-
subjects: [support,
|
|
7113
|
+
subjects: [support, user2],
|
|
6293
7114
|
estimates: [{ meter: "tokens.total", amount: tokens }],
|
|
6294
7115
|
reservedAt: at4("2026-08-15T12:00:00.000Z"),
|
|
6295
7116
|
...overrides
|
|
@@ -6367,7 +7188,7 @@ function runAiLimitStorageContractSuite(label, options) {
|
|
|
6367
7188
|
for (const [id, subject, amount] of [
|
|
6368
7189
|
["project", project, 10],
|
|
6369
7190
|
["support", support, 8],
|
|
6370
|
-
["user",
|
|
7191
|
+
["user", user2, 100]
|
|
6371
7192
|
]) {
|
|
6372
7193
|
await aiLimits.createPolicy({
|
|
6373
7194
|
id,
|
|
@@ -6510,7 +7331,7 @@ function runAiLimitStorageContractSuite(label, options) {
|
|
|
6510
7331
|
await aiLimits.createPolicy({
|
|
6511
7332
|
id: "user-cost",
|
|
6512
7333
|
projectId: projectId9,
|
|
6513
|
-
subject:
|
|
7334
|
+
subject: user2,
|
|
6514
7335
|
limit: {
|
|
6515
7336
|
meter: "cost.catalogEstimated",
|
|
6516
7337
|
amount: { currency: "USD", amountNanos: "100" }
|
|
@@ -6531,7 +7352,7 @@ function runAiLimitStorageContractSuite(label, options) {
|
|
|
6531
7352
|
buckets: [
|
|
6532
7353
|
{ subject: project, estimate: { meter: "tokens.total", amount: 5 } },
|
|
6533
7354
|
{
|
|
6534
|
-
subject:
|
|
7355
|
+
subject: user2,
|
|
6535
7356
|
estimate: {
|
|
6536
7357
|
meter: "cost.catalogEstimated",
|
|
6537
7358
|
amount: { currency: "USD", amountNanos: "7" }
|
|
@@ -6909,7 +7730,7 @@ function runAiLimitStorageContractSuite(label, options) {
|
|
|
6909
7730
|
["project-subject", project],
|
|
6910
7731
|
["support-subject", support],
|
|
6911
7732
|
["engineering-subject", engineering],
|
|
6912
|
-
["user-subject",
|
|
7733
|
+
["user-subject", user2],
|
|
6913
7734
|
["service-account-subject", serviceAccount]
|
|
6914
7735
|
]) {
|
|
6915
7736
|
await storage.aiLimits.createPolicy({
|
|
@@ -7155,9 +7976,9 @@ function runAiLimitStorageContractSuite(label, options) {
|
|
|
7155
7976
|
});
|
|
7156
7977
|
}
|
|
7157
7978
|
async function seedAiLimitStorageContractExecution(auth, executions) {
|
|
7158
|
-
if (!await auth.users.getById({ projectId: projectId9, id:
|
|
7979
|
+
if (!await auth.users.getById({ projectId: projectId9, id: user2.id })) {
|
|
7159
7980
|
await auth.users.create({
|
|
7160
|
-
id:
|
|
7981
|
+
id: user2.id,
|
|
7161
7982
|
projectId: projectId9,
|
|
7162
7983
|
email: "ai-limit-user@example.test",
|
|
7163
7984
|
createdAt: at4("2026-08-01T00:00:00.000Z"),
|
|
@@ -7170,7 +7991,7 @@ async function seedAiLimitStorageContractExecution(auth, executions) {
|
|
|
7170
7991
|
await executions.create({
|
|
7171
7992
|
id: executionId2,
|
|
7172
7993
|
projectId: projectId9,
|
|
7173
|
-
requestedBy:
|
|
7994
|
+
requestedBy: user2,
|
|
7174
7995
|
executor: { type: "primitive", kind: primitive.kind, runId: primitive.runId },
|
|
7175
7996
|
source: { type: "event", eventId: `test_event:${executionId2}` },
|
|
7176
7997
|
correlationId: `test_correlation:${executionId2}`,
|
|
@@ -9872,6 +10693,103 @@ function runArtifactStorageContractSuite(label, options) {
|
|
|
9872
10693
|
expect13((await artifacts.listComments({ projectId: projectId12, id: "art_reviewed" })).map(({ id }) => id)).toEqual(["cmt_other"]);
|
|
9873
10694
|
});
|
|
9874
10695
|
});
|
|
10696
|
+
test13("undoes later turns with a turn, back to before the first, as an edit takes them back", async () => {
|
|
10697
|
+
await withStorage(async (artifacts) => {
|
|
10698
|
+
const turnA = { threadId: "thr_a", runId: "run_a" };
|
|
10699
|
+
const turnB = { threadId: "thr_b", runId: "run_b" };
|
|
10700
|
+
const write = (artifactId, turn, updatedAt) => artifacts.publish({
|
|
10701
|
+
...publishInput({ title: `Turn ${turn.runId}`, origin: turn, updatedAt }, artifactId),
|
|
10702
|
+
turnRunId: turn.runId
|
|
10703
|
+
});
|
|
10704
|
+
await artifacts.create(createInput({ id: "art_plan" }));
|
|
10705
|
+
await write("art_plan", turnA, at6(1));
|
|
10706
|
+
await write("art_plan", turnB, at6(2));
|
|
10707
|
+
await artifacts.create({
|
|
10708
|
+
...createInput({ id: "art_draft", version: versionInput({ origin: turnA }) }),
|
|
10709
|
+
turnRunId: "run_a"
|
|
10710
|
+
});
|
|
10711
|
+
await write("art_draft", turnB, at6(2));
|
|
10712
|
+
await artifacts.createComment({
|
|
10713
|
+
projectId: projectId12,
|
|
10714
|
+
artifactId: "art_draft",
|
|
10715
|
+
id: "cmt_turn_b",
|
|
10716
|
+
anchor: { revision: 2 },
|
|
10717
|
+
body: "Turn B's note",
|
|
10718
|
+
author: otherOwner,
|
|
10719
|
+
origin: turnB,
|
|
10720
|
+
createdAt: at6(3)
|
|
10721
|
+
});
|
|
10722
|
+
const undone = await artifacts.undoTurnWrites({
|
|
10723
|
+
projectId: projectId12,
|
|
10724
|
+
turnRunId: "run_a",
|
|
10725
|
+
laterTurnRunIds: ["run_b"],
|
|
10726
|
+
requester: owner2
|
|
10727
|
+
});
|
|
10728
|
+
expect13(undone.deleted).toEqual(["art_draft"]);
|
|
10729
|
+
expect13(undone.restored.map(({ artifact }) => artifact.id)).toEqual(["art_plan"]);
|
|
10730
|
+
expect13(await artifacts.get({ projectId: projectId12, id: "art_draft" })).toBeNull();
|
|
10731
|
+
expect13(await artifacts.get({ projectId: projectId12, id: "art_plan" })).toMatchObject({
|
|
10732
|
+
title: "Q3 report",
|
|
10733
|
+
revision: 4,
|
|
10734
|
+
updatedAt: t05
|
|
10735
|
+
});
|
|
10736
|
+
expect13(await artifacts.listRestorePoints({ projectId: projectId12, id: "art_plan" })).toEqual([]);
|
|
10737
|
+
expect13(await artifacts.listTurnWrites({ projectId: projectId12, turnRunId: "run_b" })).toEqual([]);
|
|
10738
|
+
expect13(await artifacts.listThreadIds({ projectId: projectId12, id: "art_plan" })).toEqual(["thr_1"]);
|
|
10739
|
+
expect13(await artifacts.undoTurnWrites({ projectId: projectId12, turnRunId: "run_b" })).toEqual({
|
|
10740
|
+
restored: [],
|
|
10741
|
+
deleted: []
|
|
10742
|
+
});
|
|
10743
|
+
});
|
|
10744
|
+
});
|
|
10745
|
+
test13("keeps what anyone wrote between turns undone together, and the later turn's own undo", async () => {
|
|
10746
|
+
await withStorage(async (artifacts) => {
|
|
10747
|
+
const write = (artifactId, runId, updatedAt) => artifacts.publish({
|
|
10748
|
+
...publishInput({ title: `Turn ${runId}`, origin: { threadId: "thr_turn", runId }, updatedAt }, artifactId),
|
|
10749
|
+
turnRunId: runId
|
|
10750
|
+
});
|
|
10751
|
+
const person = (artifactId) => artifacts.publish(publishInput({ title: "Person's", origin: undefined, updatedAt: at6(2) }, artifactId));
|
|
10752
|
+
await artifacts.create(createInput({ id: "art_plan" }));
|
|
10753
|
+
await write("art_plan", "run_a", at6(1));
|
|
10754
|
+
await person("art_plan");
|
|
10755
|
+
await write("art_plan", "run_b", at6(3));
|
|
10756
|
+
await artifacts.create({
|
|
10757
|
+
...createInput({
|
|
10758
|
+
id: "art_draft",
|
|
10759
|
+
version: versionInput({ origin: { threadId: "thr_turn", runId: "run_a" } })
|
|
10760
|
+
}),
|
|
10761
|
+
turnRunId: "run_a"
|
|
10762
|
+
});
|
|
10763
|
+
await person("art_draft");
|
|
10764
|
+
await write("art_draft", "run_b", at6(3));
|
|
10765
|
+
expect13(await artifacts.undoTurnWrites({
|
|
10766
|
+
projectId: projectId12,
|
|
10767
|
+
turnRunId: "run_a",
|
|
10768
|
+
laterTurnRunIds: ["run_b"]
|
|
10769
|
+
})).toEqual({ restored: [], deleted: [] });
|
|
10770
|
+
expect13(await artifacts.get({ projectId: projectId12, id: "art_plan" })).toMatchObject({
|
|
10771
|
+
title: "Turn run_b",
|
|
10772
|
+
revision: 4
|
|
10773
|
+
});
|
|
10774
|
+
expect13(await artifacts.get({ projectId: projectId12, id: "art_draft" })).toMatchObject({
|
|
10775
|
+
title: "Turn run_b",
|
|
10776
|
+
revision: 3
|
|
10777
|
+
});
|
|
10778
|
+
const undone = await artifacts.undoTurnWrites({ projectId: projectId12, turnRunId: "run_b" });
|
|
10779
|
+
expect13(undone.restored.map(({ artifact }) => artifact.id).sort()).toEqual([
|
|
10780
|
+
"art_draft",
|
|
10781
|
+
"art_plan"
|
|
10782
|
+
]);
|
|
10783
|
+
expect13(await artifacts.get({ projectId: projectId12, id: "art_plan" })).toMatchObject({
|
|
10784
|
+
title: "Person's",
|
|
10785
|
+
revision: 5
|
|
10786
|
+
});
|
|
10787
|
+
expect13(await artifacts.get({ projectId: projectId12, id: "art_draft" })).toMatchObject({
|
|
10788
|
+
title: "Person's",
|
|
10789
|
+
revision: 4
|
|
10790
|
+
});
|
|
10791
|
+
});
|
|
10792
|
+
});
|
|
9875
10793
|
test13("keeps comments and their replies, oldest first, and resolves and deletes them", async () => {
|
|
9876
10794
|
await withStorage(async (artifacts) => {
|
|
9877
10795
|
await artifacts.create(createInput());
|
|
@@ -10202,6 +11120,11 @@ function runArtifactStorageContractSuite(label, options) {
|
|
|
10202
11120
|
expect13(await artifacts.listBoardPreviews({ projectId: otherProjectId4, renderKeys: [welcome] })).toEqual([]);
|
|
10203
11121
|
});
|
|
10204
11122
|
});
|
|
11123
|
+
test13("reads one board's pictures first", async () => {
|
|
11124
|
+
await withStorage(async (artifacts) => {
|
|
11125
|
+
expect13(await artifacts.listBoardPreviews({ projectId: projectId12, renderKeys: ["a".repeat(64)] })).toEqual([]);
|
|
11126
|
+
});
|
|
11127
|
+
});
|
|
10205
11128
|
test13("keeps a PDF by render key, the first one kept staying", async () => {
|
|
10206
11129
|
await withStorage(async (artifacts) => {
|
|
10207
11130
|
const renderKey = "c".repeat(64);
|
|
@@ -26103,6 +27026,101 @@ function runRunClaimStorageContractSuite(label, options) {
|
|
|
26103
27026
|
await expect38(runs.startOrReclaim({ projectId: projectId27, id: "second", execution: held("second"), claimedAt })).resolves.toMatchObject({ outcome: "started" });
|
|
26104
27027
|
});
|
|
26105
27028
|
});
|
|
27029
|
+
test38("Sync: runs of every connection of one Sync run one at a time", async () => {
|
|
27030
|
+
await withStorage(async (storage) => {
|
|
27031
|
+
const runs = requireRuns(storage.syncRuns);
|
|
27032
|
+
const queue = (id, connectionId) => queueTestSyncRun(storage, {
|
|
27033
|
+
id,
|
|
27034
|
+
projectId: projectId27,
|
|
27035
|
+
syncId: "inbox",
|
|
27036
|
+
...connectionId === undefined ? {} : { connectionId },
|
|
27037
|
+
datasetId: "inbox",
|
|
27038
|
+
mode: "merge"
|
|
27039
|
+
});
|
|
27040
|
+
await queue("ada-1", "conn_ada");
|
|
27041
|
+
await queue("grace-1", "conn_grace");
|
|
27042
|
+
await queue("whole-1");
|
|
27043
|
+
await expect38(runs.startOrReclaim({ projectId: projectId27, id: "ada-1", execution: held("ada-1"), claimedAt })).resolves.toMatchObject({ outcome: "started", run: { connectionId: "conn_ada" } });
|
|
27044
|
+
await expect38(runs.startOrReclaim({ projectId: projectId27, id: "grace-1", execution: held("grace-1"), claimedAt })).resolves.toMatchObject({ outcome: "waiting", sibling: { id: "ada-1" } });
|
|
27045
|
+
const ada = await runs.list({ projectId: projectId27, syncId: "inbox", connectionId: "conn_ada" });
|
|
27046
|
+
expect38(ada.runs.map((run) => run.id)).toEqual(["ada-1"]);
|
|
27047
|
+
const whole = await runs.list({ projectId: projectId27, syncId: "inbox", connectionId: null });
|
|
27048
|
+
expect38(whole.runs.map((run) => run.id)).toEqual(["whole-1"]);
|
|
27049
|
+
expect38(whole.runs[0]?.connectionId).toBeUndefined();
|
|
27050
|
+
});
|
|
27051
|
+
});
|
|
27052
|
+
test38("Sync: lists the latest run of each sync and connection", async () => {
|
|
27053
|
+
await withStorage(async (storage) => {
|
|
27054
|
+
const runs = requireRuns(storage.syncRuns);
|
|
27055
|
+
const queue = (id, syncId, minute, connectionId) => queueTestSyncRun(storage, {
|
|
27056
|
+
id,
|
|
27057
|
+
projectId: projectId27,
|
|
27058
|
+
syncId,
|
|
27059
|
+
...connectionId === undefined ? {} : { connectionId },
|
|
27060
|
+
datasetId: syncId,
|
|
27061
|
+
mode: "merge",
|
|
27062
|
+
queuedAt: new Date(`2100-06-01T12:0${minute}:00.000Z`)
|
|
27063
|
+
});
|
|
27064
|
+
await queue("inbox-ada-old", "inbox", 1, "conn_ada");
|
|
27065
|
+
await queue("inbox-ada-new", "inbox", 2, "conn_ada");
|
|
27066
|
+
await queue("inbox-grace", "inbox", 1, "conn_grace");
|
|
27067
|
+
await queue("calendar-ada", "calendar", 3, "conn_ada");
|
|
27068
|
+
await queue("inbox-whole", "inbox", 4);
|
|
27069
|
+
await queue("other-ada", "other", 5, "conn_ada");
|
|
27070
|
+
const ids = async (input) => (await runs.listLatestByConnection(input)).runs.map((run) => run.id).sort();
|
|
27071
|
+
expect38(await ids({ projectId: projectId27, syncIds: ["inbox", "calendar"] })).toEqual([
|
|
27072
|
+
"calendar-ada",
|
|
27073
|
+
"inbox-ada-new",
|
|
27074
|
+
"inbox-grace"
|
|
27075
|
+
]);
|
|
27076
|
+
expect38(await ids({ projectId: projectId27, syncIds: ["inbox", "calendar"], connectionIds: ["conn_ada"] })).toEqual(["calendar-ada", "inbox-ada-new"]);
|
|
27077
|
+
expect38(await ids({ projectId: projectId27, syncIds: [] })).toEqual([]);
|
|
27078
|
+
});
|
|
27079
|
+
});
|
|
27080
|
+
test38("Sync: lists only the runs of visible connections, and every run that reads none", async () => {
|
|
27081
|
+
await withStorage(async (storage) => {
|
|
27082
|
+
const runs = requireRuns(storage.syncRuns);
|
|
27083
|
+
const queue = (id, minute, connectionId) => queueTestSyncRun(storage, {
|
|
27084
|
+
id,
|
|
27085
|
+
projectId: projectId27,
|
|
27086
|
+
syncId: "inbox",
|
|
27087
|
+
...connectionId === undefined ? {} : { connectionId },
|
|
27088
|
+
datasetId: "inbox",
|
|
27089
|
+
mode: "merge",
|
|
27090
|
+
queuedAt: new Date(`2100-06-01T12:0${minute}:00.000Z`)
|
|
27091
|
+
});
|
|
27092
|
+
await queue("whole", 1);
|
|
27093
|
+
await queue("project", 2, "conn_project");
|
|
27094
|
+
await queue("ada", 3, "conn_ada");
|
|
27095
|
+
await queue("grace", 4, "conn_grace");
|
|
27096
|
+
const listed = async (visibleConnectionIds) => {
|
|
27097
|
+
const page = await runs.list({
|
|
27098
|
+
projectId: projectId27,
|
|
27099
|
+
syncId: "inbox",
|
|
27100
|
+
visibleConnectionIds,
|
|
27101
|
+
limit: 2
|
|
27102
|
+
});
|
|
27103
|
+
return { ids: page.runs.map((run) => run.id), total: page.total, hasMore: page.hasMore };
|
|
27104
|
+
};
|
|
27105
|
+
const latest = async (visibleConnectionIds) => {
|
|
27106
|
+
const { runs: found } = await runs.listLatestBySyncIds({
|
|
27107
|
+
projectId: projectId27,
|
|
27108
|
+
syncIds: ["inbox"],
|
|
27109
|
+
...visibleConnectionIds === undefined ? {} : { visibleConnectionIds }
|
|
27110
|
+
});
|
|
27111
|
+
return found.map((run) => run.id);
|
|
27112
|
+
};
|
|
27113
|
+
expect38(await listed(["conn_project", "conn_ada"])).toEqual({
|
|
27114
|
+
ids: ["ada", "project"],
|
|
27115
|
+
total: 3,
|
|
27116
|
+
hasMore: true
|
|
27117
|
+
});
|
|
27118
|
+
expect38(await listed([])).toEqual({ ids: ["whole"], total: 1, hasMore: false });
|
|
27119
|
+
expect38(await latest(["conn_project", "conn_ada"])).toEqual(["ada"]);
|
|
27120
|
+
expect38(await latest([])).toEqual(["whole"]);
|
|
27121
|
+
expect38(await latest()).toEqual(["grace"]);
|
|
27122
|
+
});
|
|
27123
|
+
});
|
|
26106
27124
|
test38("Sync: a run of an older version holds no later run back", async () => {
|
|
26107
27125
|
await withStorage(async (storage) => {
|
|
26108
27126
|
const runs = requireRuns(storage.syncRuns);
|
|
@@ -26961,6 +27979,20 @@ function runSandboxesContractSuite(label, options) {
|
|
|
26961
27979
|
await sandbox.destroy();
|
|
26962
27980
|
}
|
|
26963
27981
|
});
|
|
27982
|
+
test41("declares its longest command timeout, and runs a command asked for longer", async () => {
|
|
27983
|
+
const sandbox = await factory.create();
|
|
27984
|
+
try {
|
|
27985
|
+
expect41(sandbox.maxCommandTimeout).toBeGreaterThan(0);
|
|
27986
|
+
const result = await sandbox.runCommand("sh", ["-c", "sleep 0.2; echo ran"], {
|
|
27987
|
+
timeout: Number.MAX_SAFE_INTEGER
|
|
27988
|
+
});
|
|
27989
|
+
expect41(result).toMatchObject({ exitCode: 0, stdout: `ran
|
|
27990
|
+
` });
|
|
27991
|
+
expect41(result.timedOut).toBeUndefined();
|
|
27992
|
+
} finally {
|
|
27993
|
+
await sandbox.destroy();
|
|
27994
|
+
}
|
|
27995
|
+
});
|
|
26964
27996
|
test41("abort signal aborts an in-flight command", async () => {
|
|
26965
27997
|
const sandbox = await factory.create();
|
|
26966
27998
|
try {
|
|
@@ -27043,6 +28075,31 @@ echo ran
|
|
|
27043
28075
|
await sandbox.destroy();
|
|
27044
28076
|
}
|
|
27045
28077
|
});
|
|
28078
|
+
test41("writeFiles writes a large file and many files in one call", async () => {
|
|
28079
|
+
const sandbox = await factory.create();
|
|
28080
|
+
try {
|
|
28081
|
+
const large = Uint8Array.from({ length: 2 * 1024 * 1024 }, (_, index) => index % 251);
|
|
28082
|
+
const many = Array.from({ length: 200 }, (_, index) => ({
|
|
28083
|
+
path: `many/${String(index).padStart(3, "0")}.txt`,
|
|
28084
|
+
contents: `${index}
|
|
28085
|
+
`
|
|
28086
|
+
}));
|
|
28087
|
+
await sandbox.writeFiles([{ path: "large.bin", contents: large }, ...many]);
|
|
28088
|
+
const size = await sandbox.runCommand("wc", ["-c", "large.bin"]);
|
|
28089
|
+
expect41(size.exitCode).toBe(0);
|
|
28090
|
+
expect41(size.stdout.trim().split(/\s+/)[0]).toBe(String(large.length));
|
|
28091
|
+
const tail = await sandbox.runCommand("/bin/sh", [
|
|
28092
|
+
"-c",
|
|
28093
|
+
"tail -c 4 large.bin | od -An -tu1"
|
|
28094
|
+
]);
|
|
28095
|
+
expect41(tail.stdout.trim().split(/\s+/)).toEqual([...large.subarray(-4)].map((byte) => String(byte)));
|
|
28096
|
+
const listed = await sandbox.runCommand("/bin/sh", ["-c", "cat many/*.txt"]);
|
|
28097
|
+
expect41(listed.exitCode).toBe(0);
|
|
28098
|
+
expect41(listed.stdout).toBe(many.map((file) => file.contents).join(""));
|
|
28099
|
+
} finally {
|
|
28100
|
+
await sandbox.destroy();
|
|
28101
|
+
}
|
|
28102
|
+
});
|
|
27046
28103
|
test41("writeFiles after stop rejects", async () => {
|
|
27047
28104
|
const sandbox = await factory.create();
|
|
27048
28105
|
await sandbox.stop();
|
|
@@ -28785,4 +29842,4 @@ export {
|
|
|
28785
29842
|
testRunExecution
|
|
28786
29843
|
};
|
|
28787
29844
|
|
|
28788
|
-
//# debugId=
|
|
29845
|
+
//# debugId=B62758356E9E18EF64756E2164756E21
|