@desplega.ai/agent-swarm 2.8.0 → 2.8.2
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/{acp-adapter-t949vbbp.js → acp-adapter-fqzkxyra.js} +3 -3
- package/dist/{actions-7e9czc7s.js → actions-kxek041g.js} +18 -18
- package/dist/{amp-adapter-gv6cbb7d.js → amp-adapter-ce7jjke4.js} +1 -1
- package/dist/{app-b9fbkp9v.js → app-v6zz8yh0.js} +3 -3
- package/dist/{assistant-wjb7v4c7.js → assistant-m0sw9xx2.js} +19 -19
- package/dist/{boot-args-schema-2t37e0fe.js → boot-args-schema-66bk37wv.js} +1 -1
- package/dist/{boot-reembed-gka3zas7.js → boot-reembed-edjpwsc1.js} +1 -1
- package/dist/{boot-reembed-a35nkyr1.js → boot-reembed-y27n09tz.js} +1 -1
- package/dist/{boot-scrub-sweep-65sdnp6c.js → boot-scrub-sweep-1xc35965.js} +3 -3
- package/dist/{boot-seeds-x42tzytw.js → boot-seeds-7hjj91qj.js} +4 -4
- package/dist/{boxd-qbkxy6ap.js → boxd-ent8ch04.js} +1 -1
- package/dist/{claude-adapter-v221b2fd.js → claude-adapter-stw7jdcf.js} +3 -3
- package/dist/{claude-managed-adapter-29eq09wd.js → claude-managed-adapter-jh6c523j.js} +2 -2
- package/dist/{claude-managed-setup-9m6450zk.js → claude-managed-setup-y6z2perp.js} +5 -5
- package/dist/{claude-sdk-session-0q0ptaba.js → claude-sdk-session-vvya8wqk.js} +3 -3
- package/dist/{cli-wk18cm92.js → cli-0cq8y6m7.js} +1 -1
- package/dist/{cli-p1w18yhx.js → cli-1pz0330a.js} +1 -1
- package/dist/{cli-y97qxcfx.js → cli-1qkz151v.js} +3 -3
- package/dist/{cli-qwca7s44.js → cli-26ctbcdp.js} +18 -6
- package/dist/{cli-8fknbnhw.js → cli-2kvhc7x8.js} +7 -7
- package/dist/{cli-rfywm85n.js → cli-3e875j5p.js} +136 -49
- package/dist/{cli-6wxjceza.js → cli-3sy2xags.js} +10 -10
- package/dist/{cli-a7wvp2km.js → cli-3vmb0n58.js} +1 -1
- package/dist/{cli-p1bq50aa.js → cli-4vzgeta4.js} +13 -13
- package/dist/{cli-m28atx8q.js → cli-5y340nzn.js} +4 -4
- package/dist/{cli-7p1kvkck.js → cli-6rc5frdm.js} +1 -1
- package/dist/{cli-tph5wt3y.js → cli-6wj7p986.js} +1 -1
- package/dist/{cli-t73cas91.js → cli-7349va39.js} +8100 -7620
- package/dist/{cli-ee0b971j.js → cli-837vfs2x.js} +2 -2
- package/dist/{cli-abejgen1.js → cli-959kp5h2.js} +12 -11
- package/dist/{cli-8kzasymh.js → cli-97ae65rz.js} +4 -4
- package/dist/{cli-m4dqmnbp.js → cli-9mb2q6pb.js} +1 -1
- package/dist/{cli-p2gfst4m.js → cli-a0z912j7.js} +123 -35
- package/dist/{cli-4txa0ter.js → cli-b98a65ed.js} +3 -3
- package/dist/{cli-k0wwfqbg.js → cli-dns0y538.js} +4 -0
- package/dist/{cli-tk7cjj8h.js → cli-dzpc6en0.js} +1 -1
- package/dist/{cli-qa4wdgsy.js → cli-e1p3n5gq.js} +4 -4
- package/dist/{cli-gxkx0zzp.js → cli-f4e8r23x.js} +1 -1
- package/dist/{cli-qmqk2yc2.js → cli-f4r3g076.js} +1 -1
- package/dist/{cli-wcg8x116.js → cli-f6bahpn5.js} +1 -1
- package/dist/{cli-qsnnd04k.js → cli-fpjmegdb.js} +1 -1
- package/dist/{cli-j790gp2w.js → cli-fwy8kfd6.js} +271 -37
- package/dist/{cli-rmmpt0wm.js → cli-g5mtmf6t.js} +6 -6
- package/dist/{cli-rzsy6nc6.js → cli-gyt3zydq.js} +3 -3
- package/dist/{cli-pasjcnmj.js → cli-j24zbska.js} +3 -3
- package/dist/{cli-qfedvmcr.js → cli-jdknh18m.js} +10 -10
- package/dist/{cli-7b8sbmag.js → cli-kjtwrhea.js} +1 -1
- package/dist/{cli-gpwhbgx0.js → cli-m9s2qff2.js} +57 -25
- package/dist/{cli-2wnq8jkz.js → cli-mxn1qvbn.js} +3 -2
- package/dist/{cli-s7t6p9my.js → cli-n6vtrcht.js} +1 -1
- package/dist/{cli-2zp0et3v.js → cli-pchypa1s.js} +55 -19
- package/dist/{cli-yq3zak69.js → cli-pfs8adn4.js} +1 -1
- package/dist/{cli-c55z5chy.js → cli-q24n86d2.js} +2 -2
- package/dist/{cli-h38x262p.js → cli-rcecc3yq.js} +167 -43
- package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
- package/dist/{cli-sdtt3men.js → cli-rmzsadkf.js} +1 -1
- package/dist/{cli-f3vq58d2.js → cli-t2tma8gb.js} +1 -1
- package/dist/{cli-m23zjcy2.js → cli-tekytdq9.js} +2 -2
- package/dist/{cli-tqegb8eq.js → cli-vdektqgf.js} +1 -1
- package/dist/{cli-ffhtssbp.js → cli-vj75tyaw.js} +1 -1
- package/dist/{cli-deefvewm.js → cli-w401b9tq.js} +1 -1
- package/dist/{cli-n9ftpys4.js → cli-x6t50dmw.js} +7 -7
- package/dist/{cli-6t09sdhy.js → cli-xf3qw745.js} +3 -3
- package/dist/{cli-hxpyc9sn.js → cli-z1w943va.js} +2 -2
- package/dist/{cli-334z18y3.js → cli-zh9rsbqf.js} +3 -3
- package/dist/cli.js +17 -17
- package/dist/{codex-adapter-30j9bpzd.js → codex-adapter-zerf5qsp.js} +1 -1
- package/dist/{codex-hook-h3vk6xzr.js → codex-hook-30gyhzxe.js} +1 -1
- package/dist/{codex-session-runner-8vp57v8w.js → codex-session-runner-89s304py.js} +1 -1
- package/dist/{commands-bngnz9g7.js → commands-jeh1b51j.js} +3 -3
- package/dist/{controller-hxx8wwy1.js → controller-mctfbrse.js} +3 -3
- package/dist/{controllers-connect-e2b4gyxc.js → controllers-connect-nxa1ddwn.js} +19 -19
- package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-qj8vehv6.js} +1 -1
- package/dist/{db-bgm7vkc0.js → db-2dvay0es.js} +3 -3
- package/dist/{db-c6np41ca.js → db-b36qn6k3.js} +2 -2
- package/dist/{dispatcher-jnybck15.js → dispatcher-gndbta01.js} +17 -17
- package/dist/{dsh-adapter-nrhbrjz8.js → dsh-adapter-f75sz821.js} +1 -1
- package/dist/{e2b-jkwfhbcv.js → e2b-3gpc2n3w.js} +1 -1
- package/dist/{e2b-s16txnpx.js → e2b-jbm7mj93.js} +1 -1
- package/dist/{embedding-space-crsm2zp0.js → embedding-space-4p05vb2x.js} +6 -6
- package/dist/{embeddings-e7z3f27f.js → embeddings-m6768mgh.js} +1 -1
- package/dist/{external-channel-m77wf5z3.js → external-channel-gjv3jne3.js} +2 -2
- package/dist/{fx-adapter-b6w0kf56.js → fx-adapter-rpsgb1tw.js} +4 -4
- package/dist/{grok-adapter-4sqtebdk.js → grok-adapter-n2m3zjg1.js} +4 -4
- package/dist/handlers-nv8edn19.js +32 -0
- package/dist/{heartbeat-xgb036sx.js → heartbeat-a1tv60gt.js} +20 -20
- package/dist/{hook-xsk1jbha.js → hook-8h5dzcgq.js} +2 -2
- package/dist/{hook-5h02c9ga.js → hook-cyaps9ba.js} +4 -4
- package/dist/{http-txe7qhvn.js → http-t15mhbd9.js} +1733 -79
- package/dist/{index-0eny15vj.js → index-2skqtd76.js} +2 -2
- package/dist/{index-w7em4ktq.js → index-d6wkh8ar.js} +2 -2
- package/dist/{index-rvccek1w.js → index-gjwaqaq8.js} +5 -5
- package/dist/{index-e5pfbsys.js → index-hjhfk3ra.js} +3 -3
- package/dist/{index-1qw6f2dc.js → index-khe3gp0k.js} +4 -4
- package/dist/index-ksmyd6kc.js +37 -0
- package/dist/{index-vk63emp7.js → index-qav6455f.js} +14 -12
- package/dist/index-rjnrje98.js +32 -0
- package/dist/index-tv3413wy.js +33 -0
- package/dist/{index-ysvbhg5m.js → index-w1zqf680.js} +1 -1
- package/dist/{keepalive-4zsrce78.js → keepalive-91s7hzrb.js} +3 -3
- package/dist/lead-3hmddvrm.js +70 -0
- package/dist/{maintenance-86jvartk.js → maintenance-7pjmy5xy.js} +1 -1
- package/dist/{node-je82wjet.js → node-4c5jqxr3.js} +1 -1
- package/dist/{oauth-refresh-sweep-j52kg9pr.js → oauth-refresh-sweep-rzqfm94j.js} +2 -2
- package/dist/{onboard-c2aj5p8q.js → onboard-74st7pag.js} +3 -3
- package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-arn7gm8q.js} +2 -2
- package/dist/{otel-impl-yyy203z8.js → otel-impl-rnzey8cb.js} +1 -1
- package/dist/{pi-mono-adapter-546cd1cc.js → pi-mono-adapter-6mkwq64n.js} +3 -2
- package/dist/{pricing-refresh-1rgzqyzz.js → pricing-refresh-ha21jhk7.js} +2 -2
- package/dist/{rbac-roles-e70xfeyj.js → rbac-roles-59dxachk.js} +2 -2
- package/dist/{rbac-roles-q89qe8er.js → rbac-roles-wqhma4dr.js} +3 -3
- package/dist/{render-v2-k6tt107q.js → render-v2-14kpzx12.js} +3 -3
- package/dist/{resume-cnnrjfxa.js → resume-gsa5fb5f.js} +6 -6
- package/dist/{session-access-xkxkjw3n.js → session-access-skm7bnp6.js} +4 -4
- package/dist/{session-source-backfill-1d5pdwww.js → session-source-backfill-pbqzbncv.js} +2 -2
- package/dist/{setup-se8q7gkc.js → setup-5yermsem.js} +1 -1
- package/dist/{work-objects-1kxnbzy5.js → work-objects-xj0ck0w4.js} +20 -20
- package/dist/{worker-follow-up-zqm8apt4.js → worker-follow-up-911xc0b8.js} +19 -17
- package/dist/worker-qgg0m2gw.js +70 -0
- package/openapi.json +1741 -290
- package/package.json +3 -3
- package/src/apps/catalog.generated.json +120 -1
- package/src/apps/definition.ts +38 -11
- package/src/apps/page-validator.ts +88 -0
- package/src/be/db/model-profiles.ts +110 -11
- package/src/be/db/tasks/read.ts +20 -0
- package/src/be/db/workflow-run-definitions.ts +19 -8
- package/src/be/db-client.ts +43 -5
- package/src/be/db.ts +9 -3
- package/src/be/migrations/284_model_profile_fallbacks.sql +9 -0
- package/src/be/model-profile-check.ts +43 -18
- package/src/be/runtime-pools/routing.ts +1 -0
- package/src/be/savings/calibrate.ts +468 -0
- package/src/be/savings/compute.ts +182 -0
- package/src/be/savings/model.ts +406 -0
- package/src/be/scripts/typecheck.ts +5 -0
- package/src/be/seed/agent-fs-provision.ts +48 -11
- package/src/be/seed/workflows-seeder.ts +67 -23
- package/src/be/skill-parser.ts +19 -7
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/provider-error-class.ts +97 -0
- package/src/commands/runner.ts +99 -17
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/all-routes.ts +2 -0
- package/src/http/fs.ts +8 -2
- package/src/http/index.ts +4 -0
- package/src/http/model-profiles.ts +43 -10
- package/src/http/poll.ts +1 -0
- package/src/http/savings-calibration.ts +277 -0
- package/src/http/savings.ts +363 -0
- package/src/http/tasks.ts +46 -4
- package/src/http/trackers/authorize-gate.ts +41 -0
- package/src/http/trackers/jira.ts +26 -4
- package/src/http/trackers/linear.ts +26 -4
- package/src/integrations/chat-sdk/limits.ts +6 -1
- package/src/jira/oauth.ts +7 -1
- package/src/linear/README.md +2 -1
- package/src/linear/oauth.ts +7 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/codex-adapter.ts +3 -0
- package/src/providers/pi-mono-adapter.ts +6 -5
- package/src/providers/types.ts +7 -0
- package/src/scripts-runtime/eval-harness.ts +14 -1
- package/src/scripts-runtime/executors/types.ts +3 -0
- package/src/scripts-runtime/sdk-allowlist.ts +11 -1
- package/src/scripts-runtime/swarm-sdk.ts +6 -0
- package/src/scripts-runtime/types/stdlib.d.ts +9 -0
- package/src/scripts-runtime/types/swarm-extension.d.ts +34 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +9 -0
- package/src/tasks/worker-follow-up.ts +142 -3
- package/src/tests/agent-fs-provision-seeder.test.ts +81 -0
- package/src/tests/apps-chart-shell.test.ts +170 -0
- package/src/tests/apps-icon.test.ts +156 -2
- package/src/tests/chat-sdk-relay.test.ts +12 -0
- package/src/tests/codex-adapter.test.ts +11 -0
- package/src/tests/comb-default.test.ts +6 -0
- package/src/tests/core-auth.test.ts +7 -6
- package/src/tests/db-client-busy-retry.test.ts +58 -6
- package/src/tests/deploy-guard.test.ts +154 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/fixtures/app-shell-charts-definition.json.txt +180 -0
- package/src/tests/mcp-tools.test.ts +1 -1
- package/src/tests/model-profile-fallbacks.test.ts +482 -0
- package/src/tests/model-profiles-api.test.ts +1 -0
- package/src/tests/pi-mono-session-cost-on-abort.test.ts +115 -0
- package/src/tests/provider-error-class.test.ts +174 -0
- package/src/tests/runner-provider-fallback.test.ts +197 -0
- package/src/tests/savings-calibration-api.test.ts +264 -0
- package/src/tests/savings-calibration.test.ts +201 -0
- package/src/tests/savings-compute.test.ts +406 -0
- package/src/tests/savings-model.test.ts +287 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/script-native-unawaited-drain.test.ts +167 -0
- package/src/tests/sdk-allowlist.test.ts +40 -0
- package/src/tests/seed-workflows.test.ts +167 -11
- package/src/tests/skill-parser.test.ts +45 -0
- package/src/tests/tracker-oauth-authorize-auth.test.ts +262 -0
- package/src/tests/workflow-definition-pinning.test.ts +128 -3
- package/src/tests/workflow-script-principal.test.ts +94 -4
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/model-profiles/list-model-profiles.ts +4 -2
- package/src/tools/script-run.ts +1 -1
- package/src/tools/update-profile.ts +1 -1
- package/src/types.ts +115 -33
- package/src/utils/constants.ts +2 -0
- package/templates/skills/apps/SKILL.md +62 -3
- package/templates/skills/apps/content.md +62 -3
- package/templates/skills/swarm-docs/content.md +2 -0
- package/templates/skills/swarm-scripts/SKILL.md +1 -1
- package/templates/skills/swarm-scripts/content.md +1 -1
- package/dist/handlers-kdjcyzdj.js +0 -32
- package/dist/index-835xdgnm.js +0 -33
- package/dist/index-d469300x.js +0 -37
- package/dist/index-rzqwp11g.js +0 -32
- package/dist/lead-yqt47dkr.js +0 -70
- package/dist/worker-j6xxtq7p.js +0 -70
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { parseAppDefinition } from "../apps/definition";
|
|
3
|
+
|
|
4
|
+
const fixture = (name: string) =>
|
|
5
|
+
Bun.file(new URL(`./fixtures/${name}`, import.meta.url)).json() as Promise<Record<string, any>>;
|
|
6
|
+
|
|
7
|
+
const definition = await fixture("app-shell-charts-definition.json.txt");
|
|
8
|
+
|
|
9
|
+
type Elements = Record<string, { type: string; props: Record<string, unknown> }>;
|
|
10
|
+
|
|
11
|
+
function withProps(page: string, elementId: string, props: Record<string, unknown>) {
|
|
12
|
+
const copy = structuredClone(definition);
|
|
13
|
+
const elements = copy.pages[page].elements as Elements;
|
|
14
|
+
elements[elementId]!.props = { ...elements[elementId]!.props, ...props };
|
|
15
|
+
return copy;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function issuesFor(input: unknown) {
|
|
19
|
+
const parsed = await parseAppDefinition(input);
|
|
20
|
+
return parsed.success ? [] : parsed.issues;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function pathsFor(input: unknown) {
|
|
24
|
+
return (await issuesFor(input)).map((i) => i.path);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("Chart, Metric sparkline and the sidebar layout", () => {
|
|
28
|
+
test("the sample app using all three passes validation", async () => {
|
|
29
|
+
const parsed = await parseAppDefinition(definition);
|
|
30
|
+
if (!parsed.success) console.error(parsed.issues);
|
|
31
|
+
expect(parsed.success).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("Chart rejects unknown and malformed props", async () => {
|
|
35
|
+
const chart = "pages.overview.elements.deploysChart.props";
|
|
36
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { colour: "red" }))).toContain(
|
|
37
|
+
`${chart}.colour`,
|
|
38
|
+
);
|
|
39
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { kind: "pie" }))).toContain(
|
|
40
|
+
`${chart}.kind`,
|
|
41
|
+
);
|
|
42
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { xType: "log" }))).toContain(
|
|
43
|
+
`${chart}.xType`,
|
|
44
|
+
);
|
|
45
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { format: "bytes" }))).toContain(
|
|
46
|
+
`${chart}.format`,
|
|
47
|
+
);
|
|
48
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { series: [] }))).toContain(
|
|
49
|
+
`${chart}.series`,
|
|
50
|
+
);
|
|
51
|
+
const nine = Array.from({ length: 9 }, () => ({ key: "deploys" }));
|
|
52
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { series: nine }))).toContain(
|
|
53
|
+
`${chart}.series`,
|
|
54
|
+
);
|
|
55
|
+
expect(
|
|
56
|
+
await pathsFor(
|
|
57
|
+
withProps("overview", "deploysChart", { series: [{ key: "deploys", color: "pink" }] }),
|
|
58
|
+
),
|
|
59
|
+
).toContain(`${chart}.series.0.color`);
|
|
60
|
+
expect(
|
|
61
|
+
await pathsFor(
|
|
62
|
+
withProps("overview", "deploysChart", { series: [{ key: "deploys", stack: "a" }] }),
|
|
63
|
+
),
|
|
64
|
+
).toContain(`${chart}.series.0.stack`);
|
|
65
|
+
expect(
|
|
66
|
+
await pathsFor(
|
|
67
|
+
withProps("overview", "deploysChart", { series: [{ key: "deploys" }, { key: "deploys" }] }),
|
|
68
|
+
),
|
|
69
|
+
).toContain(`${chart}.series.1.key`);
|
|
70
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { currency: "usd" }))).toContain(
|
|
71
|
+
`${chart}.currency`,
|
|
72
|
+
);
|
|
73
|
+
expect(await pathsFor(withProps("overview", "deploysChart", { height: 40 }))).toContain(
|
|
74
|
+
`${chart}.height`,
|
|
75
|
+
);
|
|
76
|
+
const missingX = structuredClone(definition);
|
|
77
|
+
delete (missingX.pages.overview.elements as Elements).deploysChart!.props.x;
|
|
78
|
+
expect(await pathsFor(missingX)).toContain(`${chart}.x`);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("Chart x and series keys are cross-checked against the bound query's model", async () => {
|
|
82
|
+
expect(await issuesFor(withProps("overview", "deploysChart", { x: "day" }))).toContainEqual({
|
|
83
|
+
path: "pages.overview.elements.deploysChart.props.x",
|
|
84
|
+
message: 'unknown or hidden column "day" on model "day"',
|
|
85
|
+
});
|
|
86
|
+
expect(
|
|
87
|
+
await issuesFor(withProps("overview", "deploysChart", { series: [{ key: "deploy" }] })),
|
|
88
|
+
).toContainEqual({
|
|
89
|
+
path: "pages.overview.elements.deploysChart.props.series.0.key",
|
|
90
|
+
message: 'unknown or hidden column "deploy" on model "day"',
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("Metric sparkline rejects malformed values and unknown props", async () => {
|
|
95
|
+
const tile = "pages.overview.elements.failuresTile.props";
|
|
96
|
+
expect(await pathsFor(withProps("overview", "failuresTile", { sparkline: ["5"] }))).toContain(
|
|
97
|
+
`${tile}.sparkline.0`,
|
|
98
|
+
);
|
|
99
|
+
expect(await pathsFor(withProps("overview", "failuresTile", { sparkline: 5 }))).toContain(
|
|
100
|
+
`${tile}.sparkline`,
|
|
101
|
+
);
|
|
102
|
+
expect(await pathsFor(withProps("overview", "failuresTile", { sparklineKey: 3 }))).toContain(
|
|
103
|
+
`${tile}.sparklineKey`,
|
|
104
|
+
);
|
|
105
|
+
expect(await pathsFor(withProps("overview", "failuresTile", { sparkLine: [1, 2] }))).toContain(
|
|
106
|
+
`${tile}.sparkLine`,
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("layout and page shell fields are validated", async () => {
|
|
111
|
+
expect(await pathsFor({ ...definition, layout: "tabs" })).toContain("layout");
|
|
112
|
+
|
|
113
|
+
const badIcon = structuredClone(definition);
|
|
114
|
+
badIcon.pages.overview.icon = "chart-pie";
|
|
115
|
+
expect(await issuesFor(badIcon)).toContainEqual({
|
|
116
|
+
path: "pages.overview.icon",
|
|
117
|
+
message: 'unknown icon "chart-pie"',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const unknownPageKey = structuredClone(definition);
|
|
121
|
+
unknownPageKey.pages.overview.subtitle = "x";
|
|
122
|
+
expect((await pathsFor(unknownPageKey)).some((p) => p.startsWith("pages.overview"))).toBe(true);
|
|
123
|
+
|
|
124
|
+
const missingHeader = structuredClone(definition);
|
|
125
|
+
missingHeader.pages.overview.headerActions = "nope";
|
|
126
|
+
expect(await issuesFor(missingHeader)).toContainEqual({
|
|
127
|
+
path: "pages.overview.headerActions",
|
|
128
|
+
message: 'element "nope" not found',
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const doubled = structuredClone(definition);
|
|
132
|
+
doubled.pages.overview.elements.root.children.push("headerRefresh");
|
|
133
|
+
expect(await issuesFor(doubled)).toContainEqual({
|
|
134
|
+
path: "pages.overview.headerActions",
|
|
135
|
+
message: 'element "headerRefresh" is already rendered from root',
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// The header subtree counts as reachable only through `headerActions`.
|
|
139
|
+
const orphan = structuredClone(definition);
|
|
140
|
+
delete orphan.pages.overview.headerActions;
|
|
141
|
+
delete orphan.layout;
|
|
142
|
+
expect(await pathsFor(orphan)).toContain("pages.overview.elements.headerRefresh");
|
|
143
|
+
|
|
144
|
+
const noLayout = structuredClone(definition);
|
|
145
|
+
delete noLayout.layout;
|
|
146
|
+
const paths = await pathsFor(noLayout);
|
|
147
|
+
expect(paths).toContain("pages.overview.headerActions");
|
|
148
|
+
expect(paths).toContain("pages.settings.nav");
|
|
149
|
+
// Icons and descriptions are harmless without the layout.
|
|
150
|
+
expect(paths).not.toContain("pages.overview.icon");
|
|
151
|
+
expect(paths).not.toContain("pages.overview.description");
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test("existing definitions still validate and none opts into the sidebar layout", async () => {
|
|
155
|
+
for (const name of [
|
|
156
|
+
"bookmarks-definition.json.txt",
|
|
157
|
+
"catalog-feedback-definition.json.txt",
|
|
158
|
+
"catalog-inputs-definition.json.txt",
|
|
159
|
+
"catalog-table-definition.json.txt",
|
|
160
|
+
"kibo-blocks-definition.json.txt",
|
|
161
|
+
// prs-app-definition is left out: its script refs need a seeded DB.
|
|
162
|
+
]) {
|
|
163
|
+
const existing = await fixture(name);
|
|
164
|
+
const parsed = await parseAppDefinition(existing);
|
|
165
|
+
if (!parsed.success) console.error(name, parsed.issues);
|
|
166
|
+
expect(parsed.success).toBe(true);
|
|
167
|
+
expect(existing.layout).toBeUndefined();
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
2
2
|
import { unlink } from "node:fs/promises";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
type AppDefinition,
|
|
5
|
+
applyAppDefinitionPatch,
|
|
6
|
+
parseAppDefinition,
|
|
7
|
+
} from "../apps/definition";
|
|
4
8
|
import { createApp, getApp, listApps, updateApp } from "../apps/store";
|
|
5
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
closeDb,
|
|
11
|
+
createAgent,
|
|
12
|
+
getAgentById,
|
|
13
|
+
getDbClient,
|
|
14
|
+
initDb,
|
|
15
|
+
updateAgentProfile,
|
|
16
|
+
} from "../be/db";
|
|
17
|
+
import { AgentAvatarSchema, AgentSlackIconSchema, AppIconSchema } from "../types";
|
|
6
18
|
|
|
7
19
|
const TEST_DB_PATH = `/private/tmp/test-apps-icon-${process.pid}.sqlite`;
|
|
8
20
|
|
|
@@ -118,3 +130,145 @@ describe("app icon", () => {
|
|
|
118
130
|
expect(summary?.icon).toEqual(icon);
|
|
119
131
|
});
|
|
120
132
|
});
|
|
133
|
+
|
|
134
|
+
const URL_ICON = { type: "url", url: "https://example.com/icon.png" };
|
|
135
|
+
const AGENT_FS_ICON = { type: "agent-fs", path: "/apps/abc/icon-1.png" };
|
|
136
|
+
const AGENT_FS_ICON_WITH_DRIVE = {
|
|
137
|
+
type: "agent-fs",
|
|
138
|
+
path: "/apps/abc/icon-1.png",
|
|
139
|
+
orgId: "org-1",
|
|
140
|
+
driveId: "drive-1",
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
async function parseWithIcon(icon: unknown) {
|
|
144
|
+
return parseAppDefinition({ ...baseDefinition, icon }, { writerIsUser: true });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async function storedDefinition(icon: unknown): Promise<AppDefinition> {
|
|
148
|
+
const parsed = await parseWithIcon(icon);
|
|
149
|
+
if (!parsed.success) throw new Error(JSON.stringify(parsed.issues));
|
|
150
|
+
return parsed.definition;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
describe("app icon url variant", () => {
|
|
154
|
+
test("accepts an https link", async () => {
|
|
155
|
+
expect(AppIconSchema.safeParse(URL_ICON).success).toBe(true);
|
|
156
|
+
expect((await parseWithIcon(URL_ICON)).success).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test("rejects http, javascript:, credentials, and links over 2048 characters", async () => {
|
|
160
|
+
const bad = [
|
|
161
|
+
"http://example.com/icon.png",
|
|
162
|
+
"javascript:alert(1)",
|
|
163
|
+
"https://user:pass@example.com/icon.png",
|
|
164
|
+
`https://example.com/${"a".repeat(2048)}`,
|
|
165
|
+
];
|
|
166
|
+
for (const url of bad) {
|
|
167
|
+
expect(AppIconSchema.safeParse({ type: "url", url }).success).toBe(false);
|
|
168
|
+
expect((await parseWithIcon({ type: "url", url })).success).toBe(false);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("Slack icons share the same https link rules", () => {
|
|
173
|
+
expect(AgentSlackIconSchema.safeParse(URL_ICON).success).toBe(true);
|
|
174
|
+
expect(
|
|
175
|
+
AgentSlackIconSchema.safeParse({ type: "url", url: "http://example.com/i.png" }).success,
|
|
176
|
+
).toBe(false);
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
describe("app icon agent-fs variant", () => {
|
|
181
|
+
test("accepts a path alone or with both drive IDs", async () => {
|
|
182
|
+
for (const icon of [AGENT_FS_ICON, AGENT_FS_ICON_WITH_DRIVE]) {
|
|
183
|
+
expect(AppIconSchema.safeParse(icon).success).toBe(true);
|
|
184
|
+
expect((await parseWithIcon(icon)).success).toBe(true);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("rejects a relative path, a .. segment, and a single drive ID", async () => {
|
|
189
|
+
const bad = [
|
|
190
|
+
{ type: "agent-fs", path: "apps/abc/icon.png" },
|
|
191
|
+
{ type: "agent-fs", path: "/apps/../secrets/icon.png" },
|
|
192
|
+
{ type: "agent-fs", path: "/apps/abc/icon.png", orgId: "org-1" },
|
|
193
|
+
{ type: "agent-fs", path: "/apps/abc/icon.png", driveId: "drive-1" },
|
|
194
|
+
];
|
|
195
|
+
for (const icon of bad) {
|
|
196
|
+
expect(AppIconSchema.safeParse(icon).success).toBe(false);
|
|
197
|
+
expect((await parseWithIcon(icon)).success).toBe(false);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("app icon variants round trip", () => {
|
|
203
|
+
test("parseAppDefinition -> createApp -> listApps keeps each variant", async () => {
|
|
204
|
+
for (const icon of [URL_ICON, AGENT_FS_ICON, AGENT_FS_ICON_WITH_DRIVE]) {
|
|
205
|
+
const app = await createApp({
|
|
206
|
+
name: `Round trip ${icon.type}`,
|
|
207
|
+
definition: await storedDefinition(icon),
|
|
208
|
+
});
|
|
209
|
+
expect((await listApps()).find((summary) => summary.id === app.id)?.icon).toEqual(icon);
|
|
210
|
+
expect((await getApp(app.id))?.definition.icon).toEqual(icon);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("app icon merge patch", () => {
|
|
216
|
+
test("switching from lucide with color to url leaves no lucide keys", async () => {
|
|
217
|
+
const stored = await storedDefinition({ type: "lucide", icon: "star", color: "#f59e0b" });
|
|
218
|
+
const patched = applyAppDefinitionPatch(stored, { icon: URL_ICON });
|
|
219
|
+
expect(patched.success).toBe(true);
|
|
220
|
+
if (patched.success) {
|
|
221
|
+
expect((patched.definition as { icon: unknown }).icon).toEqual(URL_ICON);
|
|
222
|
+
const reparsed = await parseAppDefinition(patched.definition, { writerIsUser: true });
|
|
223
|
+
expect(reparsed.success).toBe(true);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("switching from agent-fs to lucide leaves no agent-fs keys", async () => {
|
|
228
|
+
const stored = await storedDefinition(AGENT_FS_ICON_WITH_DRIVE);
|
|
229
|
+
const lucide = { type: "lucide", icon: "star" };
|
|
230
|
+
const patched = applyAppDefinitionPatch(stored, { icon: lucide });
|
|
231
|
+
expect(patched.success).toBe(true);
|
|
232
|
+
if (patched.success) {
|
|
233
|
+
expect((patched.definition as { icon: unknown }).icon).toEqual(lucide);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test("a null icon removes it", async () => {
|
|
238
|
+
const stored = await storedDefinition(URL_ICON);
|
|
239
|
+
const patched = applyAppDefinitionPatch(stored, { icon: null });
|
|
240
|
+
expect(patched.success).toBe(true);
|
|
241
|
+
if (patched.success) expect("icon" in (patched.definition as object)).toBe(false);
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
describe("agent avatars take the same icons", () => {
|
|
246
|
+
test("AgentAvatarSchema accepts lucide, url and agent-fs icons", () => {
|
|
247
|
+
expect(AgentAvatarSchema.safeParse({ type: "lucide", icon: "bot" }).success).toBe(true);
|
|
248
|
+
expect(AgentAvatarSchema.safeParse(URL_ICON).success).toBe(true);
|
|
249
|
+
expect(AgentAvatarSchema.safeParse(AGENT_FS_ICON).success).toBe(true);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
test("AgentAvatarSchema rejects http links and a single drive ID", () => {
|
|
253
|
+
expect(
|
|
254
|
+
AgentAvatarSchema.safeParse({ type: "url", url: "http://example.com/x.png" }).success,
|
|
255
|
+
).toBe(false);
|
|
256
|
+
expect(
|
|
257
|
+
AgentAvatarSchema.safeParse({ type: "agent-fs", path: "/agents/a/avatar.png", orgId: "o" })
|
|
258
|
+
.success,
|
|
259
|
+
).toBe(false);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test("a url avatar round trips through the profile update, then an agent-fs one replaces it", async () => {
|
|
263
|
+
const agent = await createAgent({ name: "Avatar Agent", isLead: false, status: "idle" });
|
|
264
|
+
await updateAgentProfile(agent.id, { avatar: URL_ICON });
|
|
265
|
+
expect((await getAgentById(agent.id))?.avatar).toEqual(URL_ICON);
|
|
266
|
+
|
|
267
|
+
const fsAvatar = { type: "agent-fs" as const, path: `/agents/${agent.id}/avatar-1.png` };
|
|
268
|
+
await updateAgentProfile(agent.id, { avatar: fsAvatar });
|
|
269
|
+
expect((await getAgentById(agent.id))?.avatar).toEqual(fsAvatar);
|
|
270
|
+
|
|
271
|
+
await updateAgentProfile(agent.id, { avatar: null });
|
|
272
|
+
expect((await getAgentById(agent.id))?.avatar).toBeNull();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
@@ -180,6 +180,18 @@ describe("chat relay text", () => {
|
|
|
180
180
|
expect(chunks.join(" ")).toBe(words);
|
|
181
181
|
expect(splitChatMessage("short", 4096)).toEqual(["short"]);
|
|
182
182
|
});
|
|
183
|
+
|
|
184
|
+
test("splitChatMessage does not loop on a surrogate pair at a tiny limit", () => {
|
|
185
|
+
// A one-code-unit limit is smaller than an emoji: keep the pair whole.
|
|
186
|
+
expect(splitChatMessage("😀", 1)).toEqual(["😀"]);
|
|
187
|
+
// The cut still advances when text continues past the pair.
|
|
188
|
+
expect(splitChatMessage("a😀b", 1)).toEqual(["a", "😀", "b"]);
|
|
189
|
+
// A limit-wide window still never splits a pair.
|
|
190
|
+
const emojiChunks = splitChatMessage("😀😀😀", 2);
|
|
191
|
+
expect(emojiChunks).toEqual(["😀", "😀", "😀"]);
|
|
192
|
+
// A pair straddling the window edge moves the cut back, not to zero.
|
|
193
|
+
expect(splitChatMessage("ab😀cd", 3)).toEqual(["ab", "😀c", "d"]);
|
|
194
|
+
});
|
|
183
195
|
});
|
|
184
196
|
|
|
185
197
|
describe("chat relay watcher", () => {
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
} from "node:fs";
|
|
19
19
|
import { homedir, tmpdir } from "node:os";
|
|
20
20
|
import { join } from "node:path";
|
|
21
|
+
import { classifyProviderErrorOf } from "../commands/provider-error-class";
|
|
21
22
|
import { renderContextBoundNote } from "../prompts/context-bound-note";
|
|
22
23
|
import type {
|
|
23
24
|
AgentMessageItem,
|
|
@@ -2682,6 +2683,16 @@ describe("CodexSession — rate-limit error preservation", () => {
|
|
|
2682
2683
|
expect(result.isError).toBe(true);
|
|
2683
2684
|
expect(result.rateLimitResetAt).toBeUndefined();
|
|
2684
2685
|
});
|
|
2686
|
+
|
|
2687
|
+
test("an unexpected throw is a harness error: a 503 in its text never moves the task to a fallback profile", async () => {
|
|
2688
|
+
const { result } = await runSessionWithThrowingThread(
|
|
2689
|
+
[{ type: "thread.started", thread_id: "thread-mcp-503" }, { type: "turn.started" }],
|
|
2690
|
+
new Error("MCP error -32000: HTTP 503 Service Unavailable"),
|
|
2691
|
+
testConfig({ logFile: join(tmpLogDir, "mcp-503.log"), cwd: "" }),
|
|
2692
|
+
);
|
|
2693
|
+
expect(result.errorOrigin).toBe("harness");
|
|
2694
|
+
expect(classifyProviderErrorOf(result, result.failureReason, "gpt-6.1-sol")).toBeNull();
|
|
2695
|
+
});
|
|
2685
2696
|
});
|
|
2686
2697
|
|
|
2687
2698
|
describe("CodexSession context-bound note", () => {
|
|
@@ -75,12 +75,14 @@ describe("isBrowserReachableUrl", () => {
|
|
|
75
75
|
"http://172.31.255.255",
|
|
76
76
|
"http://192.168.1.10:7433",
|
|
77
77
|
"http://169.254.169.254",
|
|
78
|
+
"http://0.0.0.0:7433",
|
|
78
79
|
"http://[fd00::1]:7433",
|
|
79
80
|
"http://[fe80::1]:7433",
|
|
80
81
|
"http://[::ffff:10.0.0.5]:7433",
|
|
81
82
|
"http://[::ffff:192.168.1.10]:7433",
|
|
82
83
|
"http://[::ffff:172.16.0.1]:7433",
|
|
83
84
|
"http://[::ffff:169.254.169.254]",
|
|
85
|
+
"http://[::ffff:0.0.0.0]:7433",
|
|
84
86
|
"http://[::]:7433",
|
|
85
87
|
"http://[ff02::1]:7433",
|
|
86
88
|
"http://[ff00::1]:7433",
|
|
@@ -89,6 +91,10 @@ describe("isBrowserReachableUrl", () => {
|
|
|
89
91
|
}
|
|
90
92
|
});
|
|
91
93
|
|
|
94
|
+
test("treats 0.0.0.0 as unreachable", () => {
|
|
95
|
+
expect(isBrowserReachableUrl("http://0.0.0.0:7433")).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
|
|
92
98
|
test("an unparseable value is not reachable", () => {
|
|
93
99
|
expect(isBrowserReachableUrl("agent-fs:7433")).toBe(false);
|
|
94
100
|
expect(isBrowserReachableUrl("")).toBe(false);
|
|
@@ -98,18 +98,19 @@ describe("handleCore auth middleware (route() auth.apiKey=false is honored)", ()
|
|
|
98
98
|
expect(res.status).not.toBe(401);
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
test("Linear webhook/
|
|
102
|
-
for (const path of [
|
|
103
|
-
"/api/trackers/linear/authorize",
|
|
104
|
-
"/api/trackers/linear/callback",
|
|
105
|
-
"/api/trackers/linear/webhook",
|
|
106
|
-
]) {
|
|
101
|
+
test("Linear webhook/callback are still public", async () => {
|
|
102
|
+
for (const path of ["/api/trackers/linear/callback", "/api/trackers/linear/webhook"]) {
|
|
107
103
|
const method = path.endsWith("/webhook") ? "POST" : "GET";
|
|
108
104
|
const res = await fetch(`http://localhost:${port}${path}`, { method });
|
|
109
105
|
expect(res.status).not.toBe(401);
|
|
110
106
|
}
|
|
111
107
|
});
|
|
112
108
|
|
|
109
|
+
test("Linear authorize requires a Bearer (it starts an admin OAuth flow)", async () => {
|
|
110
|
+
const res = await fetch(`http://localhost:${port}/api/trackers/linear/authorize`);
|
|
111
|
+
expect(res.status).toBe(401);
|
|
112
|
+
});
|
|
113
|
+
|
|
113
114
|
test("Workflow webhook trigger is still public", async () => {
|
|
114
115
|
const res = await fetch(`http://localhost:${port}/api/webhooks/some-workflow-id`, {
|
|
115
116
|
method: "POST",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Database } from "bun:sqlite";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, spyOn, test } from "bun:test";
|
|
3
3
|
import { unlink } from "node:fs/promises";
|
|
4
|
-
import { createBunSqliteClient, type DbClient } from "../be/db-client";
|
|
4
|
+
import { createBunSqliteClient, type DbClient, DbTransactionDeadlineError } from "../be/db-client";
|
|
5
5
|
|
|
6
6
|
// Cross-process SQLITE_BUSY retry: a second connection on the same file plays
|
|
7
7
|
// the external lock holder (litestream checkpoint, CLI access). The client's
|
|
@@ -356,7 +356,6 @@ describe("db-client SQLITE_BUSY retry", () => {
|
|
|
356
356
|
}) as unknown as typeof main.query);
|
|
357
357
|
const released = holdWriteLock(1_500);
|
|
358
358
|
|
|
359
|
-
const startedAt = performance.now();
|
|
360
359
|
let results: PromiseSettledResult<unknown>[];
|
|
361
360
|
try {
|
|
362
361
|
results = await Promise.allSettled(
|
|
@@ -369,7 +368,6 @@ describe("db-client SQLITE_BUSY retry", () => {
|
|
|
369
368
|
execSpy.mockRestore();
|
|
370
369
|
querySpy.mockRestore();
|
|
371
370
|
}
|
|
372
|
-
const wallMs = performance.now() - startedAt;
|
|
373
371
|
const messages = warn.mock.calls.map((c) => String(c[0]));
|
|
374
372
|
warn.mockRestore();
|
|
375
373
|
|
|
@@ -393,13 +391,19 @@ describe("db-client SQLITE_BUSY retry", () => {
|
|
|
393
391
|
// attempt that waits any time (even 10ms x hundreds of attempts) shows up
|
|
394
392
|
// here as more spinning attempts than the gate reported probes.
|
|
395
393
|
expect(spinning).toBe(probes);
|
|
396
|
-
//
|
|
397
|
-
|
|
394
|
+
// No wall-clock bound on purpose. Idle, the crowd finishes in ~1.85s
|
|
395
|
+
// (1.5s hold plus the post-release backoff); a loaded CI runner stretched
|
|
396
|
+
// that past 3s twice although the gate held, so a time limit measured the
|
|
397
|
+
// runner. "Ungated the crowd spins for seconds" is already asserted above
|
|
398
|
+
// by counting spinning attempts, and the per-test timeout still fails a
|
|
399
|
+
// crowd that never drains.
|
|
398
400
|
const rows = await crowdClient.query<{ n: number }>(
|
|
399
401
|
"SELECT COUNT(*) AS n FROM items WHERE name LIKE 'crowd-%'",
|
|
400
402
|
);
|
|
401
403
|
expect(rows[0]?.n).toBe(writers);
|
|
402
|
-
|
|
404
|
+
// The test spends 1.5s in the hold alone, so the 5s default leaves a
|
|
405
|
+
// loaded runner under 3s of slack; 15s keeps a hung crowd a failure.
|
|
406
|
+
}, 15_000);
|
|
403
407
|
|
|
404
408
|
test("a held lock past the budget fails fast for the whole crowd", async () => {
|
|
405
409
|
const crowdClient = createBunSqliteClient(() => main, {
|
|
@@ -438,4 +442,52 @@ describe("db-client SQLITE_BUSY retry", () => {
|
|
|
438
442
|
);
|
|
439
443
|
expect(rows.map((r) => r.name)).toEqual(["after-hold", "after-second-hold"]);
|
|
440
444
|
});
|
|
445
|
+
describe("transaction deadlineAt", () => {
|
|
446
|
+
const names = async () =>
|
|
447
|
+
(await client.query<{ name: string }>("SELECT name FROM items ORDER BY id")).map(
|
|
448
|
+
(r) => r.name,
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
test("BEGIN stops retrying at the deadline instead of outwaiting the holder", async () => {
|
|
452
|
+
const released = holdWriteLock(600);
|
|
453
|
+
const startedAt = performance.now();
|
|
454
|
+
await expect(
|
|
455
|
+
client.transaction(
|
|
456
|
+
async (tx) => {
|
|
457
|
+
await tx.run("INSERT INTO items (name) VALUES ('late')");
|
|
458
|
+
},
|
|
459
|
+
{ deadlineAt: Date.now() + 150 },
|
|
460
|
+
),
|
|
461
|
+
).rejects.toBeInstanceOf(DbTransactionDeadlineError);
|
|
462
|
+
expect(performance.now() - startedAt).toBeLessThan(500);
|
|
463
|
+
await released;
|
|
464
|
+
expect(await names()).toEqual(["locker"]);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
test("a callback that outlives the deadline is rolled back, not committed", async () => {
|
|
468
|
+
await expect(
|
|
469
|
+
client.transaction(
|
|
470
|
+
async (tx) => {
|
|
471
|
+
await tx.run("INSERT INTO items (name) VALUES ('slow')");
|
|
472
|
+
await new Promise((r) => setTimeout(r, 120));
|
|
473
|
+
},
|
|
474
|
+
{ deadlineAt: Date.now() + 60 },
|
|
475
|
+
),
|
|
476
|
+
).rejects.toBeInstanceOf(DbTransactionDeadlineError);
|
|
477
|
+
expect(await names()).toEqual([]);
|
|
478
|
+
// The connection is not left inside the transaction.
|
|
479
|
+
await client.run("INSERT INTO items (name) VALUES ('after')");
|
|
480
|
+
expect(await names()).toEqual(["after"]);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
test("a transaction inside its deadline commits as before", async () => {
|
|
484
|
+
await client.transaction(
|
|
485
|
+
async (tx) => {
|
|
486
|
+
await tx.run("INSERT INTO items (name) VALUES ('ok')");
|
|
487
|
+
},
|
|
488
|
+
{ deadlineAt: Date.now() + 5_000 },
|
|
489
|
+
);
|
|
490
|
+
expect(await names()).toEqual(["ok"]);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
441
493
|
});
|