@niwa-labs/testing 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 +2 -2
- package/package.json +25 -4
- package/src/cli.ts +4 -0
- package/src/client.ts +93 -0
- package/src/fake-harness.ts +118 -0
- package/src/harness-claude.ts +213 -0
- package/src/harness-zcode.ts +194 -0
- package/src/helpers.ts +38 -0
- package/src/index.ts +521 -0
- package/src/messages.ts +25 -0
- package/src/niwa.ts +7 -0
- package/src/preload.ts +7 -0
- package/src/requests.ts +6 -0
- package/src/schema-reads.ts +94 -0
- package/src/sessions.ts +39 -0
- package/src/stack.ts +46 -0
- package/src/tasks.ts +4 -0
- package/src/web.ts +4 -0
- package/src/workflow.ts +93 -0
- package/test/fixtures/temp-dirs-child.ts +17 -0
- package/test/fixtures/temp-dirs-leaky.ts +12 -0
- package/test/schema-reads.test.ts +52 -0
- package/test/temp-dirs.test.ts +75 -0
- package/test/testing-stack.test.ts +52 -0
- package/tsconfig.json +6 -0
package/src/sessions.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// What the tests of the sessions package need besides the shared helpers: the factory of the
|
|
2
|
+
// requests module, which a plugin may reach only through its records, and the function that makes
|
|
3
|
+
// a token of its text, which belongs to a client.
|
|
4
|
+
|
|
5
|
+
import { sandbox } from "@niwa-labs/sandbox";
|
|
6
|
+
import type { LaunchedBox, Sandbox, SandboxHost } from "@niwa-labs/sandbox";
|
|
7
|
+
|
|
8
|
+
export { token } from "@niwa-labs/client";
|
|
9
|
+
export { requests } from "@niwa-labs/requests";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A sandbox that confines nothing: the box is planned, admitted and recorded as it would be, and its
|
|
13
|
+
* process runs as a plain child. For a test whose fake harness is not what it is about.
|
|
14
|
+
*/
|
|
15
|
+
export function unconfined(name: "srt" | "nono" = "srt"): Sandbox {
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
class: "process",
|
|
19
|
+
available: async () => true,
|
|
20
|
+
// It says what it applies as a sandbox does, though nothing holds the process to it.
|
|
21
|
+
manifest: (spec) => ({ sandbox: name, cwd: spec.cwd, env: spec.env, policy: { write: [...spec.write], devices: [], read: { except: [...spec.closed] }, net: [...spec.net] } }),
|
|
22
|
+
async launch(spec, argv, options): Promise<LaunchedBox> {
|
|
23
|
+
const child = Bun.spawn([...argv], {
|
|
24
|
+
cwd: spec.cwd,
|
|
25
|
+
env: { ...spec.env },
|
|
26
|
+
stdin: "pipe",
|
|
27
|
+
stdout: "pipe",
|
|
28
|
+
stderr: "pipe",
|
|
29
|
+
detached: options?.detached ?? false,
|
|
30
|
+
});
|
|
31
|
+
return { pid: child.pid, stdin: child.stdin, stdout: child.stdout, stderr: child.stderr, exited: child.exited, kill: (signal) => child.kill(signal) };
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A host's sandbox whose boxes confine nothing: `sessions({ sandbox: openBoxes() })`. */
|
|
37
|
+
export function openBoxes(): SandboxHost {
|
|
38
|
+
return sandbox({ adapter: unconfined() });
|
|
39
|
+
}
|
package/src/stack.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The base stack: the plugins nearly every check needs, in the order a host takes them.
|
|
3
|
+
*
|
|
4
|
+
* messages, requests, tasks, timers and sessions over a fake harness. Every factory is called
|
|
5
|
+
* with its defaults, so a check that wants another option builds that plugin itself and uses the
|
|
6
|
+
* rest of the stack by name.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { Plugin } from "@niwa-labs/plugin";
|
|
10
|
+
import { messages } from "@niwa-labs/messages";
|
|
11
|
+
import { requests } from "@niwa-labs/requests";
|
|
12
|
+
import { sessions } from "@niwa-labs/sessions";
|
|
13
|
+
import type { HarnessBinding } from "@niwa-labs/harness";
|
|
14
|
+
import { tasks } from "@niwa-labs/tasks";
|
|
15
|
+
import { timers } from "@niwa-labs/timer";
|
|
16
|
+
|
|
17
|
+
import { fakeHarness } from "./fake-harness.ts";
|
|
18
|
+
import type { FakeHarness } from "./fake-harness.ts";
|
|
19
|
+
|
|
20
|
+
/** What the stack is made with. */
|
|
21
|
+
export interface BaseStackOptions {
|
|
22
|
+
/** The harnesses the sessions module serves; by default one fake harness. */
|
|
23
|
+
readonly harnesses?: readonly HarnessBinding[];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The base stack, and the fake harness it serves when no harnesses were given. */
|
|
27
|
+
export interface BaseStack {
|
|
28
|
+
readonly plugins: readonly Plugin[];
|
|
29
|
+
/** The fake harness of the default stack; undefined when the check gave its own harnesses. */
|
|
30
|
+
readonly fake: FakeHarness | undefined;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The plugins of the base stack: `host.use(...stack.plugins)`.
|
|
35
|
+
*
|
|
36
|
+
* A host with no plugin has no actions but the core's; this is the smallest host that can take
|
|
37
|
+
* a message, a request or a task, run a timer and start a session.
|
|
38
|
+
*/
|
|
39
|
+
export function baseStack(options: BaseStackOptions = {}): BaseStack {
|
|
40
|
+
const fake = options.harnesses === undefined ? fakeHarness() : undefined;
|
|
41
|
+
const harnesses = options.harnesses ?? (fake === undefined ? [] : [fake.binding]);
|
|
42
|
+
return {
|
|
43
|
+
plugins: [messages(), requests(), tasks(), timers([]), sessions({ harnesses })],
|
|
44
|
+
fake,
|
|
45
|
+
};
|
|
46
|
+
}
|
package/src/tasks.ts
ADDED
package/src/web.ts
ADDED
package/src/workflow.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// What the tests of the workflow package need besides the shared helpers: the stub plugin the
|
|
2
|
+
// script bridge is checked against, the id a request born in a record of a given name has, the
|
|
3
|
+
// factories of the plugins a workflow reads, which a plugin may reach only through their records,
|
|
4
|
+
// and the reference of `history.read` that a stub of it is held to.
|
|
5
|
+
|
|
6
|
+
import { action, issueId, record, recordId } from "@niwa-labs/core";
|
|
7
|
+
import { plugin } from "@niwa-labs/plugin";
|
|
8
|
+
import type { Plugin } from "@niwa-labs/plugin";
|
|
9
|
+
import type { RequestId } from "@niwa-labs/requests/records";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
|
|
12
|
+
import { counter, gate } from "./index.ts";
|
|
13
|
+
|
|
14
|
+
export { describe } from "@niwa-labs/host";
|
|
15
|
+
export { CLEANUP_TIMER, WorktreeRefusal, git, registeredWorktree } from "@niwa-labs/git";
|
|
16
|
+
export { historyRead } from "@niwa-labs/history/records";
|
|
17
|
+
export { messages } from "@niwa-labs/messages";
|
|
18
|
+
export { TaskDone, tasks } from "@niwa-labs/tasks";
|
|
19
|
+
export { timer, timerList, timers } from "@niwa-labs/timer";
|
|
20
|
+
export { workflow } from "@niwa-labs/workflow";
|
|
21
|
+
|
|
22
|
+
/** A record a script waits for. */
|
|
23
|
+
export const StubFinished = record("stub.finished", z.object({ id: z.string() }));
|
|
24
|
+
|
|
25
|
+
/** A record a script may emit: the types of a script are `wf.<name>.*`. */
|
|
26
|
+
export const WfNote = record("wf.demo.note", z.object({ text: z.string() }));
|
|
27
|
+
|
|
28
|
+
/** The stub plugin: `stub.bump`, `stub.create`, `stub.finish` and `stub.hold`. Counters and gates live in the home, so they survive a restart of the host. */
|
|
29
|
+
export function stub(home: string): Plugin {
|
|
30
|
+
return plugin("stub", (api) => {
|
|
31
|
+
api.declare(StubFinished);
|
|
32
|
+
const bumped = api.state("count", z.number(), 0);
|
|
33
|
+
api.action(
|
|
34
|
+
action("stub.bump", {
|
|
35
|
+
description: "Counts up the state of the plugin.",
|
|
36
|
+
input: z.object({}),
|
|
37
|
+
output: z.object({ count: z.number() }),
|
|
38
|
+
recovery: "repeat",
|
|
39
|
+
effect: "record",
|
|
40
|
+
world: "niwa",
|
|
41
|
+
run: () => ({ count: bumped.update((count) => count + 1) }),
|
|
42
|
+
}),
|
|
43
|
+
);
|
|
44
|
+
api.action(
|
|
45
|
+
action("stub.create", {
|
|
46
|
+
description: "Makes a thing; counts the calls.",
|
|
47
|
+
input: z.object({ name: z.string() }),
|
|
48
|
+
output: z.object({ id: z.string() }),
|
|
49
|
+
recovery: "do-not-repeat",
|
|
50
|
+
effect: "write",
|
|
51
|
+
world: "local",
|
|
52
|
+
run: ({ name }) => {
|
|
53
|
+
counter(home, "w1.create").hit();
|
|
54
|
+
return { id: `t-${name}` };
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
api.action(
|
|
59
|
+
action("stub.finish", {
|
|
60
|
+
description: "Finishes a thing: writes the record a script waits for.",
|
|
61
|
+
input: z.object({ id: z.string() }),
|
|
62
|
+
output: z.object({ id: z.string() }),
|
|
63
|
+
recovery: "repeat",
|
|
64
|
+
effect: "record",
|
|
65
|
+
world: "niwa",
|
|
66
|
+
run: async ({ id }, ctx) => {
|
|
67
|
+
await ctx.emit(StubFinished, { id });
|
|
68
|
+
return { id };
|
|
69
|
+
},
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
api.action(
|
|
73
|
+
action("stub.hold", {
|
|
74
|
+
description: "Answers when the test opens the gate of its name; counts the calls.",
|
|
75
|
+
input: z.object({ name: z.string() }),
|
|
76
|
+
output: z.object({ name: z.string() }),
|
|
77
|
+
recovery: "repeat",
|
|
78
|
+
effect: "read",
|
|
79
|
+
world: "niwa",
|
|
80
|
+
run: async ({ name }) => {
|
|
81
|
+
counter(home, `w1.hold.${name}`).hit();
|
|
82
|
+
await gate(home, `w1.hold.${name}`).wait();
|
|
83
|
+
return { name };
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The id niwa would issue to a request born in a record named `name`; a test that writes `request.created` by hand gets the same id for the same name. */
|
|
91
|
+
export function requestIdOf(name: string): RequestId {
|
|
92
|
+
return issueId("request", recordId(`test:${name}`), []);
|
|
93
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// A process that makes temporary directories the way a test does and then ends in the way argv[2] says.
|
|
2
|
+
// It prints the directories it made, one per line, before it ends.
|
|
3
|
+
|
|
4
|
+
import { tempDir, tempDirSync, tempHome } from "@niwa-labs/testing";
|
|
5
|
+
|
|
6
|
+
const how = process.argv[2];
|
|
7
|
+
|
|
8
|
+
const home = await tempHome();
|
|
9
|
+
const paths = [home.path, await tempDir("async"), tempDirSync("sync")];
|
|
10
|
+
console.log(paths.join("\n"));
|
|
11
|
+
|
|
12
|
+
if (how === "throw") throw new Error("the test failed before its cleanup");
|
|
13
|
+
if (how === "kill") process.kill(process.pid, "SIGKILL");
|
|
14
|
+
if (how === "term") process.kill(process.pid, "SIGTERM");
|
|
15
|
+
if (how === "int") process.kill(process.pid, "SIGINT");
|
|
16
|
+
if (how === "cleaned") await home.cleanup();
|
|
17
|
+
if (how === "term" || how === "int") await new Promise(() => {});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// A test file that leaves its temporary directories behind: the failing test never reaches its cleanup.
|
|
2
|
+
// It is run by `bun test` from temp-dirs.test.ts, not by the suite.
|
|
3
|
+
|
|
4
|
+
import { expect, test } from "bun:test";
|
|
5
|
+
|
|
6
|
+
import { tempDir, tempHome } from "@niwa-labs/testing";
|
|
7
|
+
|
|
8
|
+
test("fails before its cleanup", async () => {
|
|
9
|
+
const home = await tempHome();
|
|
10
|
+
await tempDir("leaky");
|
|
11
|
+
expect(home.path).toBe("never");
|
|
12
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { unreadable, unsendable } from "../src/index.ts";
|
|
5
|
+
|
|
6
|
+
describe("what a narrower schema can read of another", () => {
|
|
7
|
+
const written = z.object({ id: z.string(), state: z.enum(["a", "b"]), when: z.number().int(), tags: z.array(z.object({ name: z.string(), extra: z.boolean() })), note: z.string().optional() });
|
|
8
|
+
|
|
9
|
+
test("a reader of some of the fields reads it", () => {
|
|
10
|
+
const reader = z.object({ id: z.string(), state: z.enum(["a", "b", "c"]), when: z.number(), tags: z.array(z.object({ name: z.string() })), note: z.string().optional() });
|
|
11
|
+
expect(unreadable(reader, written)).toEqual([]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("a field the writer has not, or may leave out, is not read", () => {
|
|
15
|
+
expect(unreadable(z.object({ gone: z.string() }), written)).toEqual(["$.gone: the writer has no such field"]);
|
|
16
|
+
expect(unreadable(z.object({ note: z.string() }), written)).toEqual(["$.note: the reader needs it, the writer may leave it out"]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("a type that changed, and a value an enum gained, are not read", () => {
|
|
20
|
+
expect(unreadable(z.object({ id: z.number() }), written)[0]).toContain("$.id: the type string is not read as number");
|
|
21
|
+
expect(unreadable(z.object({ state: z.enum(["a"]) }), written)).toEqual(['$.state: the values ["b"] are not read']);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("a union is read when each of its variants is", () => {
|
|
25
|
+
const union = z.discriminatedUnion("kind", [z.object({ kind: z.literal("x"), n: z.number() }), z.object({ kind: z.literal("y") })]);
|
|
26
|
+
expect(unreadable(z.object({ kind: z.string() }), union)).toEqual([]);
|
|
27
|
+
expect(unreadable(z.discriminatedUnion("kind", [z.object({ kind: z.literal("x"), n: z.number() })]), union)).not.toEqual([]);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("an input is sendable when its fields are the action's, and the action's required ones are sent", () => {
|
|
31
|
+
const real = z.object({ run: z.string(), limit: z.number().optional() });
|
|
32
|
+
expect(unsendable(z.object({ run: z.string() }), real)).toEqual([]);
|
|
33
|
+
expect(unsendable(z.object({ run: z.string(), more: z.string() }), real)).toEqual(["$.more: the action takes no such field"]);
|
|
34
|
+
expect(unsendable(z.object({}), real)).toEqual(["$.run: the action needs it and the module never sends it"]);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("a field of a union", () => {
|
|
39
|
+
const addresses = z.discriminatedUnion("kind", [z.object({ kind: z.literal("owner") }), z.object({ kind: z.literal("session"), id: z.string() })]);
|
|
40
|
+
|
|
41
|
+
test("an optional field some variant lacks is read as absent there", () => {
|
|
42
|
+
expect(unreadable(z.object({ kind: z.string(), id: z.string().optional() }), addresses)).toEqual([]);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test("a field no variant has is not read", () => {
|
|
46
|
+
expect(unreadable(z.object({ kind: z.string(), harness: z.string().optional() }), addresses)).toEqual(["$.harness: no variant of the writer has such a field"]);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("a field a variant may leave out, that the reader needs, is not read", () => {
|
|
50
|
+
expect(unreadable(z.object({ id: z.string() }), addresses)).not.toEqual([]);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// The directories a test makes are removed when the process ends, however the test ended, and only
|
|
2
|
+
// the ones of this run: a run that is still alive keeps its own.
|
|
3
|
+
|
|
4
|
+
import { afterAll, beforeAll, expect, test } from "bun:test";
|
|
5
|
+
import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync } from "node:fs";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
|
|
9
|
+
const CHILD = join(import.meta.dir, "./fixtures/temp-dirs-child.ts");
|
|
10
|
+
|
|
11
|
+
// The children get a temporary directory of their own, so the count of what they leave is exact.
|
|
12
|
+
let scratch: string;
|
|
13
|
+
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
scratch = mkdtempSync(join(tmpdir(), "niwa-temp-dirs-scratch-"));
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterAll(() => {
|
|
19
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
async function runChild(how: string): Promise<{ made: string[]; code: number | null }> {
|
|
23
|
+
const child = Bun.spawn(["bun", CHILD, how], {
|
|
24
|
+
env: { ...process.env, TMPDIR: scratch },
|
|
25
|
+
stdout: "pipe",
|
|
26
|
+
stderr: "ignore",
|
|
27
|
+
});
|
|
28
|
+
const out = await new Response(child.stdout).text();
|
|
29
|
+
const code = await child.exited;
|
|
30
|
+
return { made: out.split("\n").filter((line) => line !== ""), code };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const left = (): string[] => readdirSync(scratch).filter((name) => name.startsWith("niwa-test-"));
|
|
34
|
+
|
|
35
|
+
for (const how of ["exit", "cleaned", "throw", "term", "int"]) {
|
|
36
|
+
test(`a process that ends by "${how}" leaves none of its directories`, async () => {
|
|
37
|
+
const { made } = await runChild(how);
|
|
38
|
+
expect(made).toHaveLength(3);
|
|
39
|
+
expect(made.every((path) => path.startsWith(scratch))).toBe(true);
|
|
40
|
+
expect(left()).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
test("a killed process leaves its directories until the next run starts, which removes them", async () => {
|
|
45
|
+
const { made } = await runChild("kill");
|
|
46
|
+
expect(made.every((path) => existsSync(path))).toBe(true);
|
|
47
|
+
|
|
48
|
+
// The directory of a run that is alive (this one) and a directory nobody owns are not touched.
|
|
49
|
+
const alive = join(scratch, `niwa-test-${String(process.pid)}-alive-x`);
|
|
50
|
+
const foreign = join(scratch, "niwa-test-notapid-x");
|
|
51
|
+
mkdirSync(alive);
|
|
52
|
+
mkdirSync(foreign);
|
|
53
|
+
|
|
54
|
+
await runChild("exit");
|
|
55
|
+
|
|
56
|
+
expect(made.some((path) => existsSync(path))).toBe(false);
|
|
57
|
+
expect(existsSync(alive)).toBe(true);
|
|
58
|
+
expect(existsSync(foreign)).toBe(true);
|
|
59
|
+
rmSync(alive, { recursive: true });
|
|
60
|
+
rmSync(foreign, { recursive: true });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test("`bun test` removes the directories of a test that failed before its cleanup", async () => {
|
|
64
|
+
const leaky = join(import.meta.dir, "./fixtures/temp-dirs-leaky.ts");
|
|
65
|
+
const run = Bun.spawn(["bun", "test", leaky], {
|
|
66
|
+
cwd: join(import.meta.dir, "../../.."),
|
|
67
|
+
env: { ...process.env, TMPDIR: scratch },
|
|
68
|
+
stdout: "ignore",
|
|
69
|
+
stderr: "pipe",
|
|
70
|
+
});
|
|
71
|
+
const report = await new Response(run.stderr).text();
|
|
72
|
+
expect(await run.exited).not.toBe(0);
|
|
73
|
+
expect(report).toContain("1 fail"); // It ran, and failed where it was meant to.
|
|
74
|
+
expect(left()).toEqual([]);
|
|
75
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// The testing package: the base stack over a fake harness, and the re-exports that a test needs to
|
|
2
|
+
// run a host and speak to it without importing the core.
|
|
3
|
+
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
import { expect, test } from "bun:test";
|
|
8
|
+
|
|
9
|
+
import { actionName } from "@niwa-labs/core";
|
|
10
|
+
import { connect as coreConnect } from "@niwa-labs/client";
|
|
11
|
+
import { createNiwa as coreCreateNiwa } from "@niwa-labs/host";
|
|
12
|
+
import { FAKE_HARNESS, baseStack, connect, connectAsOwner, createNiwa, fakeHarness, tempHome } from "../src/index.ts";
|
|
13
|
+
|
|
14
|
+
test("testing re-exports the host and the client of the core", () => {
|
|
15
|
+
expect(createNiwa).toBe(coreCreateNiwa);
|
|
16
|
+
expect(connect).toBe(coreConnect);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("the base stack runs a session over the fake harness, for the owner", async () => {
|
|
20
|
+
const home = await tempHome();
|
|
21
|
+
const stack = baseStack();
|
|
22
|
+
const niwa = createNiwa({ home: home.path });
|
|
23
|
+
niwa.use(...stack.plugins);
|
|
24
|
+
await niwa.serve();
|
|
25
|
+
const api = await connectAsOwner(home.path);
|
|
26
|
+
try {
|
|
27
|
+
const started = (await api.call(actionName("session.start"), { harness: FAKE_HARNESS, prompt: "move the parser" })) as {
|
|
28
|
+
session: string;
|
|
29
|
+
};
|
|
30
|
+
expect(started.session.length).toBeGreaterThan(0);
|
|
31
|
+
expect(stack.fake?.control.started).toEqual(["move the parser"]);
|
|
32
|
+
const listed = (await api.call(actionName("session.list"), { managedOnly: true })) as { sessions?: unknown[] };
|
|
33
|
+
expect(listed.sessions).toHaveLength(1);
|
|
34
|
+
} finally {
|
|
35
|
+
await api.close();
|
|
36
|
+
await niwa.close();
|
|
37
|
+
await home.cleanup();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("the base stack serves the harnesses a test gives, and no fake of its own", () => {
|
|
42
|
+
const own = fakeHarness({ id: "mine", answer: { result: "ok" } });
|
|
43
|
+
const stack = baseStack({ harnesses: [own.binding] });
|
|
44
|
+
expect(stack.fake).toBeUndefined();
|
|
45
|
+
expect(own.instance.id).toBe(own.binding.instance.id);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("the pure helpers import only the contracts of the core, so they need no host", () => {
|
|
49
|
+
const text = readFileSync(join(import.meta.dir, "../src/helpers.ts"), "utf8");
|
|
50
|
+
const specifiers = [...text.matchAll(/from "([^"]+)"/g)].map((match) => match[1]);
|
|
51
|
+
expect(specifiers.sort()).toEqual(["@niwa-labs/core", "@niwa-labs/core"]);
|
|
52
|
+
});
|