@niwa-labs/workflow 0.0.0-stage → 0.0.0
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/LICENSE +21 -0
- package/README.md +13 -2
- package/package.json +55 -4
- package/src/actions.ts +408 -0
- package/src/agent.ts +211 -0
- package/src/ask.ts +84 -0
- package/src/bridge.ts +710 -0
- package/src/catalogue.ts +74 -0
- package/src/check.ts +880 -0
- package/src/child.ts +1378 -0
- package/src/cockpit/actions.ts +128 -0
- package/src/cockpit/catalogue-actions.ts +97 -0
- package/src/cockpit/dashboard.tsx +134 -0
- package/src/cockpit/groups.ts +45 -0
- package/src/cockpit/index.tsx +50 -0
- package/src/cockpit/launch.tsx +136 -0
- package/src/cockpit/plan.ts +101 -0
- package/src/cockpit/run-commands.tsx +102 -0
- package/src/cockpit/run-page.tsx +140 -0
- package/src/cockpit/run-summary.ts +16 -0
- package/src/cockpit/runs.tsx +73 -0
- package/src/cockpit/statistics.tsx +176 -0
- package/src/cockpit/track.tsx +159 -0
- package/src/cockpit/workflows.tsx +383 -0
- package/src/describe-cache.ts +122 -0
- package/src/describe.ts +174 -0
- package/src/guide.ts +213 -0
- package/src/index.ts +2813 -0
- package/src/inspect.ts +235 -0
- package/src/installation.ts +90 -0
- package/src/language.ts +217 -0
- package/src/records-entry.ts +63 -0
- package/src/records.ts +574 -0
- package/src/registry.ts +250 -0
- package/src/revise.ts +89 -0
- package/src/runner.ts +339 -0
- package/src/script-types.ts +549 -0
- package/src/stats.ts +460 -0
- package/src/status.ts +512 -0
- package/src/store.ts +259 -0
- package/src/subscriptions.ts +102 -0
- package/src/waiting.ts +61 -0
- package/test/cockpit-actions.test.ts +20 -0
- package/test/cockpit-groups.test.ts +42 -0
- package/test/cockpit-plan.test.ts +118 -0
- package/test/fixtures/branches-host.ts +58 -0
- package/test/fixtures/branches-script.js +23 -0
- package/test/fixtures/bridge-host.ts +23 -0
- package/test/fixtures/bridge-keys-script.js +15 -0
- package/test/fixtures/bridge-wait-script.js +8 -0
- package/test/fixtures/cancel-host.ts +58 -0
- package/test/fixtures/cancel-script.js +12 -0
- package/test/fixtures/crash-host.ts +61 -0
- package/test/fixtures/crash-script.js +14 -0
- package/test/fixtures/ping-records.ts +20 -0
- package/test/fixtures/revision-host.ts +57 -0
- package/test/fixtures/revision-script.js +11 -0
- package/test/fixtures/running-host.ts +61 -0
- package/test/fixtures/running-script.js +12 -0
- package/test/fixtures/with-data/flow.ts +2 -0
- package/test/fixtures/with-data/table.json +1 -0
- package/test/git-repo.ts +45 -0
- package/test/git-worktree.test.ts +413 -0
- package/test/question-format.test.ts +279 -0
- package/test/workflow-agent-caps.test.ts +91 -0
- package/test/workflow-agent-lifetime.test.ts +93 -0
- package/test/workflow-agent-options.test.ts +216 -0
- package/test/workflow-agent-schema.test.ts +386 -0
- package/test/workflow-agent-typings.test.ts +241 -0
- package/test/workflow-ask-resume.test.ts +145 -0
- package/test/workflow-branch-keys.test.ts +133 -0
- package/test/workflow-bridge-inproc.test.ts +230 -0
- package/test/workflow-bridge.test.ts +141 -0
- package/test/workflow-builtin-candidate.test.ts +230 -0
- package/test/workflow-builtin.test.ts +197 -0
- package/test/workflow-cancel-agent.test.ts +144 -0
- package/test/workflow-cancel.test.ts +166 -0
- package/test/workflow-chain.test.ts +84 -0
- package/test/workflow-check-options.test.ts +144 -0
- package/test/workflow-check-uses.test.ts +148 -0
- package/test/workflow-check.test.ts +282 -0
- package/test/workflow-contract.test.ts +295 -0
- package/test/workflow-crash-resume.test.ts +141 -0
- package/test/workflow-deadline.test.ts +102 -0
- package/test/workflow-describe-cache.test.ts +240 -0
- package/test/workflow-directory.test.ts +73 -0
- package/test/workflow-emits.test.ts +261 -0
- package/test/workflow-group-keys.test.ts +72 -0
- package/test/workflow-harnesses.test.ts +262 -0
- package/test/workflow-inspect.test.ts +152 -0
- package/test/workflow-language-types.test.ts +148 -0
- package/test/workflow-manifest.test.ts +93 -0
- package/test/workflow-manual-pause.test.ts +116 -0
- package/test/workflow-owners.test.ts +154 -0
- package/test/workflow-pause.test.ts +200 -0
- package/test/workflow-phases.test.ts +445 -0
- package/test/workflow-plugin-entries.test.ts +59 -0
- package/test/workflow-record-refs.test.ts +310 -0
- package/test/workflow-replay.test.ts +206 -0
- package/test/workflow-resume-once.test.ts +188 -0
- package/test/workflow-revision.test.ts +216 -0
- package/test/workflow-scope.test.ts +505 -0
- package/test/workflow-script-defaults.test.ts +119 -0
- package/test/workflow-script-error.test.ts +228 -0
- package/test/workflow-script-libraries.test.ts +88 -0
- package/test/workflow-script-packages.test.ts +119 -0
- package/test/workflow-stdout.test.ts +89 -0
- package/test/workflow-stop.test.ts +299 -0
- package/test/workflow-store.test.ts +220 -0
- package/test/workflow-visible.test.ts +136 -0
- package/test/workflow-wait-version.test.ts +54 -0
- package/test/workflow-wait.test.ts +224 -0
- package/test/workflow-waiting-agent.test.ts +64 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// The typing of a script knows the options block of each harness by the kind the sessions module binds
|
|
2
|
+
// it to, from the schema that kind declares: a field the block does not have, a value of the wrong type,
|
|
3
|
+
// a field in a block that takes none and the block of another kind are errors of the checker, found by
|
|
4
|
+
// `workflow.check` with their place in the file. A kind is any package's: the blocks are the host's to say.
|
|
5
|
+
|
|
6
|
+
import { afterEach, expect, test } from "bun:test";
|
|
7
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
import { NoOptions, harnessId, kindOptions, machineId } from "@niwa-labs/harness";
|
|
13
|
+
import type { Harness, KindOptions } from "@niwa-labs/harness";
|
|
14
|
+
import { harnessGet, harnessList } from "@niwa-labs/sessions/records";
|
|
15
|
+
import { createNiwa, sessions, tempHome } from "@niwa-labs/testing";
|
|
16
|
+
import type { Host } from "@niwa-labs/testing";
|
|
17
|
+
import { workflow, workflowCheck } from "../src/index.ts";
|
|
18
|
+
|
|
19
|
+
const homes: Array<{ cleanup(): Promise<void> }> = [];
|
|
20
|
+
const hosts: Host[] = [];
|
|
21
|
+
|
|
22
|
+
afterEach(async () => {
|
|
23
|
+
for (const host of hosts.splice(0)) await host.close().catch(() => {});
|
|
24
|
+
for (const home of homes.splice(0)) await home.cleanup();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
/** An installation with no side: the check only needs to know what it is bound to. */
|
|
28
|
+
const installed = (id: string): Harness => ({ id: harnessId(id), kind: "test" as never, machine: machineId("machine-1"), home: "/tmp/fake-home", sides: {} });
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* One harness of each kind, named after its block (`claude-sonnet` a Claude Code, `codex-x` a Codex), and `bare` bound
|
|
32
|
+
* to no block. The workflow module is given the names alone: the kind is the sessions module's to know.
|
|
33
|
+
*/
|
|
34
|
+
const CLAUDE = kindOptions("claude", z.strictObject({ advisor: z.boolean().optional() }));
|
|
35
|
+
const CODEX = kindOptions("codex", NoOptions);
|
|
36
|
+
const BOUND: ReadonlyArray<readonly [string, KindOptions | undefined]> = [
|
|
37
|
+
["claude-sonnet", CLAUDE],
|
|
38
|
+
["codex-x", CODEX],
|
|
39
|
+
...(["mcode", "ncode", "pi", "zcode"] as const).map((kind) => [`${kind}-x`, kindOptions(kind, NoOptions)] as const),
|
|
40
|
+
["bare", undefined],
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
async function check(lines: readonly string[], bound: ReadonlyArray<readonly [string, KindOptions | undefined]> = BOUND) {
|
|
44
|
+
const home = await tempHome();
|
|
45
|
+
homes.push(home);
|
|
46
|
+
const host = createNiwa({ home: home.path });
|
|
47
|
+
host.use(sessions({ harnesses: bound.map(([id, options]) => ({ instance: installed(id), ...(options === undefined ? {} : { options }) })) }));
|
|
48
|
+
host.use(workflow({ harnesses: bound.map(([id]) => id) }));
|
|
49
|
+
await host.serve();
|
|
50
|
+
hosts.push(host);
|
|
51
|
+
const file = join(home.path, "script.ts");
|
|
52
|
+
await mkdir(home.path, { recursive: true });
|
|
53
|
+
await writeFile(file, lines.join("\n"));
|
|
54
|
+
return await host.call(workflowCheck, { file });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const script = (call: string, harness = "claude-sonnet"): string[] => [
|
|
58
|
+
"export default workflow({}, async () => {",
|
|
59
|
+
` await ask({ harness: ${JSON.stringify(harness)}, ${call} }, "go");`,
|
|
60
|
+
"});",
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
test("the block of a kind with its own option is typed by that option", async () => {
|
|
64
|
+
expect((await check(script("claude: { advisor: false }"))).ok).toBe(true);
|
|
65
|
+
const wrongType = await check(script('claude: { advisor: "no" }'));
|
|
66
|
+
expect(wrongType.ok).toBe(false);
|
|
67
|
+
expect(wrongType.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
68
|
+
expect(wrongType.errors[0]?.message).toContain("Type 'string' is not assignable to type 'boolean | undefined'");
|
|
69
|
+
const unknownField = await check(script("claude: { advisor: false, advisr: true }"));
|
|
70
|
+
expect(unknownField.ok).toBe(false);
|
|
71
|
+
expect(unknownField.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
72
|
+
expect(unknownField.errors[0]?.message).toContain("'advisr' does not exist");
|
|
73
|
+
}, 60_000);
|
|
74
|
+
|
|
75
|
+
test("the block of a kind with no option takes the empty block and nothing else, not a value that happens to be an object", async () => {
|
|
76
|
+
for (const kind of ["codex", "mcode", "ncode", "pi", "zcode"]) {
|
|
77
|
+
expect((await check(script(`${kind}: {}`, `${kind}-x`))).ok).toBe(true);
|
|
78
|
+
const field = await check(script(`${kind}: { speed: "fast" }`, `${kind}-x`));
|
|
79
|
+
expect(field.ok).toBe(false);
|
|
80
|
+
expect(field.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
81
|
+
expect(field.errors[0]?.message).toContain("Type 'string' is not assignable to type 'never'");
|
|
82
|
+
}
|
|
83
|
+
const scalar = await check(script("codex: 5", "codex-x"));
|
|
84
|
+
expect(scalar.ok).toBe(false);
|
|
85
|
+
expect(scalar.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
86
|
+
expect(scalar.errors[0]?.message).toContain("Type 'number' is not assignable to type 'NiwaOptionBlock$codex'");
|
|
87
|
+
}, 120_000);
|
|
88
|
+
|
|
89
|
+
test("the block of another kind is an error, and so is any block for a harness given without its kind's options or for no harness", async () => {
|
|
90
|
+
const foreign = await check(script("codex: {}"));
|
|
91
|
+
expect(foreign.ok).toBe(false);
|
|
92
|
+
expect(foreign.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
93
|
+
expect(foreign.errors[0]?.message).toContain("Type '{}' is not assignable to type 'undefined'");
|
|
94
|
+
const claudeOnCodex = await check(script("claude: { advisor: false }", "codex-x"));
|
|
95
|
+
expect(claudeOnCodex.ok).toBe(false);
|
|
96
|
+
expect(claudeOnCodex.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
97
|
+
expect((await check(script("claude: { advisor: false }", "bare"))).ok).toBe(false);
|
|
98
|
+
// The same name, bound by the sessions module to one kind and then to another: the block follows the binding.
|
|
99
|
+
expect((await check(script("claude: { advisor: false }", "same"), [["same", CLAUDE]])).ok).toBe(true);
|
|
100
|
+
const rebound = await check(script("claude: { advisor: false }", "same"), [["same", CODEX]]);
|
|
101
|
+
expect(rebound.ok).toBe(false);
|
|
102
|
+
expect(rebound.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
103
|
+
expect((await check(script("codex: {}", "same"), [["same", CODEX]])).ok).toBe(true);
|
|
104
|
+
const none = await check(["export default workflow({}, async () => {", ' await ask({ claude: { advisor: false } }, "go");', "});"]);
|
|
105
|
+
expect(none.ok).toBe(false);
|
|
106
|
+
expect(none.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
107
|
+
}, 60_000);
|
|
108
|
+
|
|
109
|
+
test("a block that no kind declares is not an option of ask()", async () => {
|
|
110
|
+
const report = await check(script("gemini: {}"));
|
|
111
|
+
expect(report.ok).toBe(false);
|
|
112
|
+
expect(report.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
113
|
+
expect(report.errors[0]?.message).toContain("'gemini' does not exist");
|
|
114
|
+
}, 60_000);
|
|
115
|
+
|
|
116
|
+
test("the block of a kind no package of niwa ships is typed by the schema its harness reports", async () => {
|
|
117
|
+
const acme = kindOptions("acme-code", z.strictObject({ speed: z.enum(["slow", "fast"]).optional() }));
|
|
118
|
+
const bound = [...BOUND, ["acme", acme] as const];
|
|
119
|
+
expect((await check(script('"acme-code": { speed: "fast" }', "acme"), bound)).ok).toBe(true);
|
|
120
|
+
const wrong = await check(script('"acme-code": { speed: "warp" }', "acme"), bound);
|
|
121
|
+
expect(wrong.ok).toBe(false);
|
|
122
|
+
expect(wrong.errors[0]).toMatchObject({ line: 2, code: "TS2769" });
|
|
123
|
+
// Its block is a block of another kind for every other harness of the host.
|
|
124
|
+
expect((await check(script('"acme-code": {}'), bound)).ok).toBe(false);
|
|
125
|
+
}, 60_000);
|
|
126
|
+
|
|
127
|
+
test("the sessions module serves each harness as an entity: harness.list names them, harness.get gives one with its block's schema", async () => {
|
|
128
|
+
const home = await tempHome();
|
|
129
|
+
homes.push(home);
|
|
130
|
+
const host = createNiwa({ home: home.path });
|
|
131
|
+
host.use(sessions({ harnesses: BOUND.map(([id, options]) => ({ instance: installed(id), ...(options === undefined ? {} : { options }) })) }));
|
|
132
|
+
await host.serve();
|
|
133
|
+
hosts.push(host);
|
|
134
|
+
const { items } = await host.call(harnessList, {});
|
|
135
|
+
expect(items.map((item): [string, string | undefined] => [item.name, item.block])).toEqual(BOUND.map(([id, options]) => [id, options?.block]));
|
|
136
|
+
expect(items[0]?.options).toMatchObject({ type: "object", properties: { advisor: { type: "boolean" } } });
|
|
137
|
+
const claude = await host.call(harnessGet, { name: "claude-sonnet" });
|
|
138
|
+
expect(claude).toMatchObject({ name: "claude-sonnet", kind: "test", block: "claude", machine: "machine-1" });
|
|
139
|
+
expect(claude.options).toMatchObject({ type: "object", properties: { advisor: { type: "boolean" } } });
|
|
140
|
+
const bare = await host.call(harnessGet, { name: "bare" });
|
|
141
|
+
expect(bare.block).toBeUndefined();
|
|
142
|
+
expect(bare.options).toBeUndefined();
|
|
143
|
+
await expect(host.call(harnessGet, { name: "nope" })).rejects.toThrow(/not known/);
|
|
144
|
+
}, 30_000);
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// An `ask()` call starts its session through `session.start.<harness>`, so a script that names a harness `uses` does
|
|
2
|
+
// not list would pause at its first call. The check finds it first: a harness written in the call, held by a constant or
|
|
3
|
+
// chosen between two is an error, and one known only when the script runs is a warning.
|
|
4
|
+
|
|
5
|
+
import { afterEach, expect, test } from "bun:test";
|
|
6
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
|
|
10
|
+
import { action } from "@niwa-labs/core";
|
|
11
|
+
import type { ActionDescription } from "@niwa-labs/core";
|
|
12
|
+
import { createNiwa, describe, tempHome } from "@niwa-labs/testing";
|
|
13
|
+
import type { Host } from "@niwa-labs/testing";
|
|
14
|
+
import { sessionAgent, workflow, workflowCheck } from "../src/index.ts";
|
|
15
|
+
|
|
16
|
+
import { scriptChecker, scriptUses } from "../src/check.ts";
|
|
17
|
+
|
|
18
|
+
const homes: Array<{ cleanup(): Promise<void> }> = [];
|
|
19
|
+
const hosts: Host[] = [];
|
|
20
|
+
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
for (const host of hosts.splice(0)) await host.close().catch(() => {});
|
|
23
|
+
for (const home of homes.splice(0)) await home.cleanup();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
/** An action as the host describes it, with the input given. */
|
|
27
|
+
function described(name: string, input: z.ZodType): ActionDescription {
|
|
28
|
+
const one = describe({
|
|
29
|
+
actions: [action(name, { description: `The action ${name}.`, input, output: z.object({}), recovery: "repeat", effect: "write", run: () => ({}) })],
|
|
30
|
+
types: [],
|
|
31
|
+
}).actions[0];
|
|
32
|
+
if (one === undefined) throw new Error("no description");
|
|
33
|
+
return one;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const actions = [
|
|
37
|
+
described("session.start.codex-luna", sessionAgent("codex-luna").input),
|
|
38
|
+
described("session.start.claude-work", sessionAgent("claude-work").input),
|
|
39
|
+
described("task.create", z.object({ title: z.string() })),
|
|
40
|
+
];
|
|
41
|
+
const callable = actions.map((entry) => entry.name);
|
|
42
|
+
|
|
43
|
+
/** The check of a script with the given `uses`, over a host that serves two harnesses. */
|
|
44
|
+
async function report(uses: string, lines: readonly string[], file = "uses-probe.ts") {
|
|
45
|
+
const text = [`export default workflow({ output: z.json(), uses: [${uses}] }, async () => {`, ...lines, " return null;", "});"].join("\n");
|
|
46
|
+
const checked = await scriptChecker()({ file: join(process.cwd(), file), text }, { actions, callable });
|
|
47
|
+
return { errors: checked.errors, warnings: checked.warnings };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
test("a harness written in the call that uses does not list is an error, and a listed one passes", async () => {
|
|
51
|
+
const missing = await report('"task.create"', [' await ask({ harness: "codex-luna" }, "go");']);
|
|
52
|
+
expect(missing.errors.map((error) => error.code)).toEqual(["TS2769", "uses"]);
|
|
53
|
+
expect(missing.errors[1]).toMatchObject({ line: 2 });
|
|
54
|
+
expect(missing.errors[1]?.message).toContain('add "session.start.codex-luna"');
|
|
55
|
+
expect(missing.warnings).toEqual([]);
|
|
56
|
+
expect((await report('"task.create", "session.start.codex-luna"', [' await ask({ harness: "codex-luna" }, "go");'])).errors).toEqual([]);
|
|
57
|
+
expect((await report('"session.start.*"', [' await ask({ harness: "codex-luna" }, "go");'])).errors).toEqual([]);
|
|
58
|
+
// Another harness than the one listed.
|
|
59
|
+
const other = await report('"session.start.claude-work"', [' await ask({ harness: "codex-luna" }, "go");']);
|
|
60
|
+
expect(other.errors.map((error) => error.code)).toEqual(["TS2769", "uses"]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("a harness held by a constant is found as the text is", async () => {
|
|
64
|
+
const errors = (await report('"task.create"', [' const harness = "codex-luna";', ' await ask({ harness }, "go");', ' const other = "claude-work";', ' await ask({ harness: other }, "go");'])).errors;
|
|
65
|
+
expect(errors.filter((error) => error.code === "uses").map((error) => error.line)).toEqual([3, 5]);
|
|
66
|
+
expect((await report('"session.start.codex-luna", "session.start.claude-work"', [' const harness = "codex-luna";', ' await ask({ harness }, "go");'])).errors).toEqual([]);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("a script that is not type checked is held to uses all the same, with an error that says what to add", async () => {
|
|
70
|
+
const lines = [' const harness = "codex-luna";', ' await ask({ harness }, "go");', ' await ask({ harness: "claude-work" }, "go");'];
|
|
71
|
+
const { errors, warnings } = await report('"task.create"', lines, "uses-probe.js");
|
|
72
|
+
expect(errors).toHaveLength(2);
|
|
73
|
+
expect(errors[0]).toMatchObject({ line: 3, code: "uses" });
|
|
74
|
+
expect(errors[0]?.message).toContain('add "session.start.codex-luna"');
|
|
75
|
+
expect(errors[1]).toMatchObject({ line: 4, code: "uses" });
|
|
76
|
+
expect(warnings).toEqual([]);
|
|
77
|
+
expect((await report('"session.start.codex-luna", "session.start.claude-work"', lines, "uses-probe.js")).errors).toEqual([]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test("a harness known only when the script runs is a warning that the call needs a matching uses entry", async () => {
|
|
81
|
+
const lines = [" const chosen: unknown = JSON.parse('{}');", ' await ask({ harness: chosen as any }, "go");'];
|
|
82
|
+
const missing = await report('"task.create"', lines);
|
|
83
|
+
expect(missing.errors).toEqual([]);
|
|
84
|
+
expect(missing.warnings).toHaveLength(1);
|
|
85
|
+
expect(missing.warnings[0]).toMatchObject({ line: 3, code: "uses" });
|
|
86
|
+
expect(missing.warnings[0]?.message).toContain("session.start.*");
|
|
87
|
+
// Every harness the host serves is listed: nothing is left that the call could name.
|
|
88
|
+
expect((await report('"session.start.*"', lines)).warnings).toEqual([]);
|
|
89
|
+
expect((await report('"session.start.codex-luna", "session.start.claude-work"', lines)).warnings).toEqual([]);
|
|
90
|
+
// A harness that is text of any kind is the same, in a script of any kind.
|
|
91
|
+
const text = await report('"session.start.codex-luna"', [" let harness = 'codex-luna';", ' await ask({ harness }, "go");'], "uses-probe.js");
|
|
92
|
+
expect(text.errors).toEqual([]);
|
|
93
|
+
expect(text.warnings).toHaveLength(1);
|
|
94
|
+
expect(text.warnings[0]).toMatchObject({ line: 3, code: "uses" });
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("a call that names no harness, or a host that serves none, has nothing to warn of", async () => {
|
|
98
|
+
expect(await report('"task.create"', [' await ask({}, "go");'])).toEqual({ errors: [], warnings: [] });
|
|
99
|
+
const none = await scriptChecker()({ file: join(process.cwd(), "uses-probe.ts"), text: 'export default workflow({ output: z.json() }, async () => { await ask({ harness: "x" as string }, "go"); return null; });' }, { actions: [], callable: [] });
|
|
100
|
+
expect(none.errors).toEqual([]);
|
|
101
|
+
expect(none.warnings).toEqual([]);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test("workflow.check on a live host says so in its report", async () => {
|
|
105
|
+
const home = await tempHome();
|
|
106
|
+
homes.push(home);
|
|
107
|
+
const host = createNiwa({ home: home.path });
|
|
108
|
+
host.use(workflow({ harnesses: ["codex-luna", "claude-work"] }));
|
|
109
|
+
await host.serve();
|
|
110
|
+
hosts.push(host);
|
|
111
|
+
await mkdir(home.path, { recursive: true });
|
|
112
|
+
const check = async (name: string, uses: string, call: string) => {
|
|
113
|
+
const path = join(home.path, name);
|
|
114
|
+
await writeFile(path, ["export default workflow({ output: z.json(), uses: [" + uses + "] }, async () => {", ` await ask(${call}, "a");`, " return null;", "});"].join("\n"));
|
|
115
|
+
return host.call(workflowCheck, { file: path });
|
|
116
|
+
};
|
|
117
|
+
const missing = await check("missing.ts", '"workflow.guide"', '{ harness: "codex-luna" }');
|
|
118
|
+
expect(missing.ok).toBe(false);
|
|
119
|
+
expect(missing.errors.find((error) => error.code === "uses")).toMatchObject({ line: 2 });
|
|
120
|
+
const listed = await check("listed.ts", '"session.start.codex-luna"', '{ harness: "codex-luna" }');
|
|
121
|
+
expect(listed.ok).toBe(true);
|
|
122
|
+
expect(listed.warnings).toBeUndefined();
|
|
123
|
+
const dynamic = await check("dynamic.ts", '"session.start.codex-luna"', '{ harness: (JSON.parse("{}") as { h: string }).h }');
|
|
124
|
+
expect(dynamic.errors.length).toBeGreaterThan(0);
|
|
125
|
+
expect(dynamic.warnings?.[0]).toMatchObject({ line: 2, code: "uses" });
|
|
126
|
+
}, 60_000);
|
|
127
|
+
|
|
128
|
+
test("uses that a spread, a computed key or an accessor may decide is an error, not a script with no uses", async () => {
|
|
129
|
+
const check = async (declaration: string) => {
|
|
130
|
+
const text = `const base = { uses: ["*"] };\nconst key = "uses";\nexport default workflow(${declaration}, async () => null);`;
|
|
131
|
+
const source = { file: join(process.cwd(), "uses-unsettled.ts"), text };
|
|
132
|
+
const checked = await scriptChecker()(source, { actions, callable });
|
|
133
|
+
return { codes: checked.errors.map((error) => error.code), uses: await scriptUses(source) };
|
|
134
|
+
};
|
|
135
|
+
for (const declaration of [
|
|
136
|
+
"{ output: z.json(), ...base }",
|
|
137
|
+
'{ output: z.json(), uses: ["task.create"], ...base }',
|
|
138
|
+
'{ output: z.json(), [key]: ["*"] }',
|
|
139
|
+
'{ output: z.json(), get uses() { return ["*"]; } }',
|
|
140
|
+
'{ output: z.json(), uses: ["task.create"], get uses() { return ["*"]; } }',
|
|
141
|
+
'{ output: z.json(), ...["*"] }',
|
|
142
|
+
]) {
|
|
143
|
+
const found = await check(declaration);
|
|
144
|
+
expect({ declaration, codes: found.codes, bad: "bad" in (found.uses ?? {}) }).toEqual({ declaration, codes: expect.arrayContaining(["uses"]), bad: true });
|
|
145
|
+
}
|
|
146
|
+
const written = await check('{ output: z.json(), uses: ["task.create"] }');
|
|
147
|
+
expect(written).toEqual({ codes: [], uses: { masks: [expect.objectContaining({ mask: "task.create" })] } });
|
|
148
|
+
});
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// A script is type-checked against the typing generated
|
|
2
|
+
// from what the host describes, a call outside `uses` is an error with a place in the file,
|
|
3
|
+
// `workflow.start` does not run a script that fails the check, and `workflow.guide` shows a caller
|
|
4
|
+
// only the actions it may call. The hash of the script is what tells a replay from a revision.
|
|
5
|
+
|
|
6
|
+
import { afterEach, expect, test } from "bun:test";
|
|
7
|
+
import { createHash } from "node:crypto";
|
|
8
|
+
import { existsSync } from "node:fs";
|
|
9
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
import { action, actionName, grant, principalOf, seq, owner } from "@niwa-labs/core";
|
|
14
|
+
import type { ActionDescription, StoredRecord } from "@niwa-labs/core";
|
|
15
|
+
import type { CallerBinding } from "@niwa-labs/plugin";
|
|
16
|
+
import { connect, createNiwa, describe, messages, requests, tasks, timers, eventually, tempDir, tempHome } from "@niwa-labs/testing";
|
|
17
|
+
import type { Host } from "@niwa-labs/testing";
|
|
18
|
+
import { workflow, workflowCheck, workflowGuide, workflowResume, workflowStart } from "../src/index.ts";
|
|
19
|
+
|
|
20
|
+
import { scriptChecker } from "../src/check.ts";
|
|
21
|
+
import { scriptTyping } from "../src/script-types.ts";
|
|
22
|
+
|
|
23
|
+
const homes: Array<{ cleanup(): Promise<void> }> = [];
|
|
24
|
+
const hosts: Host[] = [];
|
|
25
|
+
|
|
26
|
+
afterEach(async () => {
|
|
27
|
+
for (const host of hosts.splice(0)) await host.close().catch(() => {});
|
|
28
|
+
for (const home of homes.splice(0)) await home.cleanup();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const bind: CallerBinding = (caller) =>
|
|
32
|
+
caller.kind === "handler" && caller.handler.startsWith("workflow/") ? owner : undefined;
|
|
33
|
+
|
|
34
|
+
async function served(): Promise<{ host: Host; home: string }> {
|
|
35
|
+
const home = await tempHome();
|
|
36
|
+
homes.push(home);
|
|
37
|
+
const host = createNiwa({ home: home.path });
|
|
38
|
+
host.use(requests(), timers([]), messages({ bind }), tasks({ messages: { bind } }));
|
|
39
|
+
host.use(workflow({ harnesses: ["codex", "mcode-work"] }));
|
|
40
|
+
await host.serve();
|
|
41
|
+
hosts.push(host);
|
|
42
|
+
return { host, home: home.path };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function scriptIn(home: string, name: string, lines: readonly string[]): Promise<string> {
|
|
46
|
+
const file = join(home, name);
|
|
47
|
+
await mkdir(home, { recursive: true });
|
|
48
|
+
await writeFile(file, lines.join("\n"));
|
|
49
|
+
return file;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const ofType = (records: readonly StoredRecord[], type: string): StoredRecord[] => records.filter((row) => row.type === type);
|
|
53
|
+
const sha256 = (text: string): string => createHash("sha256").update(text).digest("hex");
|
|
54
|
+
|
|
55
|
+
test("the typing generated from the live host has no error of its own", async () => {
|
|
56
|
+
const { host, home } = await served();
|
|
57
|
+
const file = await scriptIn(home, "empty.ts", ["export default workflow({ output: z.number() }, async () => {", " return 1;", "});"]);
|
|
58
|
+
const report = await host.call(workflowCheck, { file });
|
|
59
|
+
expect(report).toEqual({ file, ok: true, errors: [], note: "described, the script was not run", output: { type: "number" }, contract: expect.any(String) });
|
|
60
|
+
}, 30_000);
|
|
61
|
+
|
|
62
|
+
test("a wrapper is typed by the schema of its action", async () => {
|
|
63
|
+
const { host, home } = await served();
|
|
64
|
+
const file = await scriptIn(home, "typed.ts", [
|
|
65
|
+
"export default workflow({}, async () => {",
|
|
66
|
+
' await niwa.task.create({ nonsense: 1 });',
|
|
67
|
+
"});",
|
|
68
|
+
]);
|
|
69
|
+
const report = await host.call(workflowCheck, { file });
|
|
70
|
+
expect(report.ok).toBe(false);
|
|
71
|
+
expect(report.errors[0]).toMatchObject({ file, line: 2, code: "TS2353" });
|
|
72
|
+
}, 30_000);
|
|
73
|
+
|
|
74
|
+
test("W2b: a call outside uses is an error with its place, and the script function is not run", async () => {
|
|
75
|
+
const { host, home } = await served();
|
|
76
|
+
const marker = join(home, "ran");
|
|
77
|
+
const file = await scriptIn(home, "outside.ts", [
|
|
78
|
+
'export default workflow({ uses: ["task.*"] }, async () => {',
|
|
79
|
+
` await Bun.write(${JSON.stringify(marker)}, "ran");`,
|
|
80
|
+
' await niwa.request.ask({ question: "x" });',
|
|
81
|
+
' await call("request.ask", {});',
|
|
82
|
+
'});',
|
|
83
|
+
]);
|
|
84
|
+
const report = await host.call(workflowCheck, { file });
|
|
85
|
+
expect(report.note).toBe("described, the script was not run");
|
|
86
|
+
expect(report.ok).toBe(false);
|
|
87
|
+
expect(report.errors.map((error) => [error.file, error.line, error.column, error.code])).toEqual([
|
|
88
|
+
[file, 3, 14, "TS2339"],
|
|
89
|
+
[file, 4, 14, "TS2345"],
|
|
90
|
+
]);
|
|
91
|
+
expect(existsSync(marker)).toBe(false);
|
|
92
|
+
}, 30_000);
|
|
93
|
+
|
|
94
|
+
test("a call inside uses passes, by name and as a wrapper", async () => {
|
|
95
|
+
const { host, home } = await served();
|
|
96
|
+
const file = await scriptIn(home, "inside.ts", [
|
|
97
|
+
'export default workflow({ uses: ["task.create", "request.*"] }, async () => {',
|
|
98
|
+
" await niwa.request.open({});",
|
|
99
|
+
' await call("request.open", {});',
|
|
100
|
+
'});',
|
|
101
|
+
]);
|
|
102
|
+
expect((await host.call(workflowCheck, { file })).errors).toEqual([]);
|
|
103
|
+
}, 30_000);
|
|
104
|
+
|
|
105
|
+
test("a mask that names no action is an error at its place", async () => {
|
|
106
|
+
const { host, home } = await served();
|
|
107
|
+
const file = await scriptIn(home, "mask.ts", [
|
|
108
|
+
'export default workflow({ uses: ["task.*", "nothing.*"] }, async () => {});',
|
|
109
|
+
]);
|
|
110
|
+
const report = await host.call(workflowCheck, { file });
|
|
111
|
+
expect(report.errors).toEqual([
|
|
112
|
+
{ file, line: 1, column: 44, code: "uses", message: 'uses "nothing.*" names no action the caller may call' },
|
|
113
|
+
]);
|
|
114
|
+
}, 30_000);
|
|
115
|
+
|
|
116
|
+
test("a script with no uses may call any action the caller may call; a JS script is read for its syntax", async () => {
|
|
117
|
+
const { host, home } = await served();
|
|
118
|
+
const open = await scriptIn(home, "open.ts", ["export default workflow({}, async () => {", ' await niwa.request.open({});', "});"]);
|
|
119
|
+
expect((await host.call(workflowCheck, { file: open })).ok).toBe(true);
|
|
120
|
+
const js = await scriptIn(home, "plain.js", ["export default workflow({ output: z.boolean() }, async () => {", " return await Bun.file('x').exists();", "});"]);
|
|
121
|
+
expect((await host.call(workflowCheck, { file: js })).ok).toBe(true);
|
|
122
|
+
const checked = await scriptIn(home, "checked.js", [
|
|
123
|
+
"// @ts-check",
|
|
124
|
+
"export default workflow({}, async () => {",
|
|
125
|
+
' await niwa.request.open({ nonsense: 1 });',
|
|
126
|
+
"});",
|
|
127
|
+
]);
|
|
128
|
+
expect((await host.call(workflowCheck, { file: checked })).errors[0]).toMatchObject({ line: 3, code: "TS2353" });
|
|
129
|
+
const broken = await scriptIn(home, "broken.js", ["export default workflow({}, async () => {"]);
|
|
130
|
+
expect((await host.call(workflowCheck, { file: broken })).ok).toBe(false);
|
|
131
|
+
}, 30_000);
|
|
132
|
+
|
|
133
|
+
test("W2b: workflow.start refuses a script that fails its check, with the errors, and writes no run", async () => {
|
|
134
|
+
const { host, home } = await served();
|
|
135
|
+
const bad = await scriptIn(home, "bad.ts", [
|
|
136
|
+
'export default workflow({ uses: ["task.*"] }, async () => {',
|
|
137
|
+
' await niwa.request.open({});',
|
|
138
|
+
'});',
|
|
139
|
+
]);
|
|
140
|
+
const refused = await host.call(workflowStart, { file: bad }).catch((error: unknown) => error);
|
|
141
|
+
expect(refused).toBeInstanceOf(Error);
|
|
142
|
+
expect((refused as Error).message).toContain(`${bad}:2:`);
|
|
143
|
+
expect((refused as Error).message).toContain("the script was not run");
|
|
144
|
+
expect(ofType(await host.records.read(), "workflow.run.requested")).toHaveLength(0);
|
|
145
|
+
|
|
146
|
+
const good = await scriptIn(home, "good.ts", ["export default workflow({ output: z.number() }, async () => {", " return 1;", "});"]);
|
|
147
|
+
await host.call(workflowStart, { file: good });
|
|
148
|
+
await eventually(async () => ofType(await host.records.read(), "workflow.run.finished").length === 1, 20_000);
|
|
149
|
+
}, 30_000);
|
|
150
|
+
|
|
151
|
+
test("the hash of the script is pinned at the start and decides what a resume is", async () => {
|
|
152
|
+
const { host, home } = await served();
|
|
153
|
+
const text = "export default workflow({ output: z.number() }, async () => {\n return 1;\n});\n";
|
|
154
|
+
const file = await scriptIn(home, "pinned.ts", [text.trimEnd()]);
|
|
155
|
+
await writeFile(file, text);
|
|
156
|
+
const { run } = await host.call(workflowStart, { file });
|
|
157
|
+
const finished = async (count: number): Promise<boolean> =>
|
|
158
|
+
ofType(await host.records.read(), "workflow.run.finished").length === count;
|
|
159
|
+
await eventually(() => finished(1), 20_000);
|
|
160
|
+
const records = await host.records.read();
|
|
161
|
+
expect(ofType(records, "workflow.run.requested")[0]?.data).toMatchObject({ hash: sha256(text) });
|
|
162
|
+
expect(ofType(records, "workflow.run.started")[0]?.data).toMatchObject({ hash: sha256(text) });
|
|
163
|
+
|
|
164
|
+
// The same bytes saved again: a replay, not a revision.
|
|
165
|
+
await writeFile(file, text);
|
|
166
|
+
const replay = await host.call(workflowResume, { run });
|
|
167
|
+
expect(replay).toEqual({ run, finished: false });
|
|
168
|
+
await eventually(async () => ofType(await host.records.read(), "workflow.run.started").length === 2, 20_000);
|
|
169
|
+
await eventually(() => finished(2), 20_000);
|
|
170
|
+
|
|
171
|
+
// One byte changed: a revision.
|
|
172
|
+
await writeFile(file, `${text}// edited\n`);
|
|
173
|
+
const revised = await host.call(workflowResume, { run });
|
|
174
|
+
expect(revised.revision).toBeDefined();
|
|
175
|
+
await eventually(async () => ofType(await host.records.read(), "workflow.run.started").length === 3, 20_000);
|
|
176
|
+
const starts = ofType(await host.records.read(), "workflow.run.started");
|
|
177
|
+
expect(starts[2]?.data).toMatchObject({ hash: sha256(`${text}// edited\n`) });
|
|
178
|
+
}, 30_000);
|
|
179
|
+
|
|
180
|
+
/** What the guide says its actions are, and what the declarations expose of them. */
|
|
181
|
+
const declared = (declarations: string): string[] =>
|
|
182
|
+
[...declarations.matchAll(/^ {2}"([^"]+)": \{ input: /gm)].map((match) => match[1] ?? "");
|
|
183
|
+
|
|
184
|
+
test("W2c: the guide lists the actions the caller may call, and the declarations match the list", async () => {
|
|
185
|
+
const { host, home } = await served();
|
|
186
|
+
const everything = await host.call(workflowGuide, {});
|
|
187
|
+
const names = everything.actions.map((entry) => entry.name);
|
|
188
|
+
expect(names).toContain("task.create");
|
|
189
|
+
expect(names).toContain("workflow.guide");
|
|
190
|
+
expect(declared(everything.declarations).sort()).toEqual([...names].sort());
|
|
191
|
+
expect(everything.guide).toContain("uses");
|
|
192
|
+
expect(everything.actions.find((entry) => entry.name === "task.create")?.description.length).toBeGreaterThan(0);
|
|
193
|
+
|
|
194
|
+
const session = await connect({
|
|
195
|
+
home,
|
|
196
|
+
id: "session:narrow",
|
|
197
|
+
token: host.issueToken(principalOf("session", "narrow"), {
|
|
198
|
+
grant: grant(["workflow.guide", "workflow.check", "task.create"]),
|
|
199
|
+
}),
|
|
200
|
+
});
|
|
201
|
+
try {
|
|
202
|
+
const narrow = await session.call(actionName("workflow.guide"), {});
|
|
203
|
+
const seen = (narrow as { actions: Array<{ name: string }>; declarations: string }).actions.map((entry) => entry.name);
|
|
204
|
+
expect(seen.sort()).toEqual(["task.create", "workflow.check", "workflow.guide"]);
|
|
205
|
+
expect(declared((narrow as { declarations: string }).declarations).sort()).toEqual(seen);
|
|
206
|
+
|
|
207
|
+
// A call of an action the caller may not call is a type error for it, even with no uses.
|
|
208
|
+
const file = await scriptIn(home, "narrow.ts", ["export default workflow({}, async () => {", ' await niwa.request.open({});', "});"]);
|
|
209
|
+
const report = (await session.call(actionName("workflow.check"), { file })) as { ok: boolean; errors: Array<{ line: number }> };
|
|
210
|
+
expect(report.ok).toBe(false);
|
|
211
|
+
expect(report.errors[0]?.line).toBe(2);
|
|
212
|
+
} finally {
|
|
213
|
+
await session.close();
|
|
214
|
+
}
|
|
215
|
+
}, 30_000);
|
|
216
|
+
|
|
217
|
+
test("the typing handles what the schemas of niwa hold: references, records, enums, a node that is an action and a group", async () => {
|
|
218
|
+
type Tree = { name: string; children: Tree[] };
|
|
219
|
+
const Tree: z.ZodType<Tree> = z.lazy(() => z.object({ name: z.string(), children: z.array(Tree) }));
|
|
220
|
+
const described = (name: string, input: z.ZodType, output: z.ZodType): ActionDescription => {
|
|
221
|
+
const [one] = describe({
|
|
222
|
+
actions: [action(name, { description: `The action ${name}.`, input, output, recovery: "repeat", effect: "write", run: () => ({}) })],
|
|
223
|
+
types: [],
|
|
224
|
+
}).actions;
|
|
225
|
+
if (one === undefined) throw new Error("no description");
|
|
226
|
+
return one;
|
|
227
|
+
};
|
|
228
|
+
const catalogue = [
|
|
229
|
+
described("tree.grow", z.object({ tree: Tree, kind: z.enum(["a", "b"]), tags: z.record(z.string(), z.number()), pair: z.tuple([z.string(), z.number()]) }), z.object({ id: z.string().nullable(), any: z.unknown() })),
|
|
230
|
+
described("session.start", z.object({ prompt: z.string() }), z.object({ session: z.string() })),
|
|
231
|
+
described("session.start.codex", z.object({ prompt: z.string(), model: z.string().optional() }), z.object({ session: z.string() })),
|
|
232
|
+
described("agent.search-old", z.object({}), z.object({})),
|
|
233
|
+
];
|
|
234
|
+
const names = catalogue.map((entry) => entry.name);
|
|
235
|
+
const check = scriptChecker();
|
|
236
|
+
const file = join(process.cwd(), "typing-probe.ts");
|
|
237
|
+
const ok = [
|
|
238
|
+
"export default workflow({ output: z.json() }, async () => {",
|
|
239
|
+
' const grown = await niwa.tree.grow({ tree: { name: "a", children: [{ name: "b", children: [] }] }, kind: "a", tags: { x: 1 }, pair: ["x", 1] });',
|
|
240
|
+
" const id: string | null = grown.id;",
|
|
241
|
+
' const one = await niwa.session.start({ prompt: "x" });',
|
|
242
|
+
' const two = await niwa.session.start.codex({ prompt: "x", model: "m" });',
|
|
243
|
+
' const three = await niwa.agent["search-old"]({});',
|
|
244
|
+
' await call("session.start.codex", { prompt: "x" });',
|
|
245
|
+
" return [id, one.session, two.session, three];",
|
|
246
|
+
"});",
|
|
247
|
+
].join("\n");
|
|
248
|
+
expect((await check({ file, text: ok }, { actions: catalogue, callable: names })).errors).toEqual([]);
|
|
249
|
+
const wrong = ok.replace('kind: "a"', 'kind: "c"');
|
|
250
|
+
const failed = await check({ file, text: wrong }, { actions: catalogue, callable: names });
|
|
251
|
+
expect(failed.errors).toHaveLength(1);
|
|
252
|
+
expect(failed.errors[0]).toMatchObject({ line: 2, code: "TS2322" });
|
|
253
|
+
// Without `session.start.codex` among the callable names the wrapper is gone, the group stays.
|
|
254
|
+
const narrowed = scriptTyping(catalogue, names.filter((name) => name !== "session.start.codex")).declarations;
|
|
255
|
+
// The block of the kind `codex` in the options of `ask()` is not that wrapper: it is `"codex"?`, not `"codex": {`.
|
|
256
|
+
expect(narrowed).not.toContain('"codex": {');
|
|
257
|
+
expect(narrowed).toContain('"session": {');
|
|
258
|
+
}, 30_000);
|
|
259
|
+
|
|
260
|
+
test("an answer kept for a script is not given to the same text in another file", async () => {
|
|
261
|
+
const check = scriptChecker();
|
|
262
|
+
const text = 'export default workflow({ output: z.json() }, async () => { return missing; });';
|
|
263
|
+
const dir = process.cwd();
|
|
264
|
+
const typed = await check({ file: join(dir, "same.ts"), text }, { actions: [], callable: [] });
|
|
265
|
+
const plain = await check({ file: join(dir, "same.js"), text }, { actions: [], callable: [] });
|
|
266
|
+
expect(typed.ok).toBe(false);
|
|
267
|
+
expect(plain.ok).toBe(true);
|
|
268
|
+
expect(plain.file).toBe(join(dir, "same.js"));
|
|
269
|
+
}, 30_000);
|
|
270
|
+
|
|
271
|
+
test("the packages the checker reads are parsed once, and the files of a script's own folder are read at every check", async () => {
|
|
272
|
+
const check = scriptChecker();
|
|
273
|
+
const dir = await tempDir("check-import");
|
|
274
|
+
const file = join(dir, "script.ts");
|
|
275
|
+
const text = 'import { value } from "./value.ts"; export default workflow({ output: z.number() }, async () => { return value; });';
|
|
276
|
+
await writeFile(join(dir, "value.ts"), "export const value: number = 1;");
|
|
277
|
+
expect((await check({ file, text }, { actions: [], callable: [] })).ok).toBe(true);
|
|
278
|
+
// The imported file is edited, the script is not: another checker keeps no answer, and it must read the new text of the file.
|
|
279
|
+
await writeFile(join(dir, "value.ts"), 'export const value: string = "one";');
|
|
280
|
+
const again = await scriptChecker()({ file, text }, { actions: [], callable: [] });
|
|
281
|
+
expect(again.ok).toBe(false);
|
|
282
|
+
}, 30_000);
|