@niwa-labs/harness-mcode 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 +17 -4
- package/src/index.ts +13 -0
- package/src/mcode/control.ts +1840 -0
- package/src/mcode/durable.ts +445 -0
- package/src/mcode/fixtures.ts +93 -0
- package/src/mcode/format.ts +177 -0
- package/src/mcode/index.ts +50 -0
- package/src/mcode/kind.ts +147 -0
- package/src/mcode/ledger.ts +199 -0
- package/src/mcode/paths.ts +80 -0
- package/src/mcode/protocol.ts +91 -0
- package/src/mcode/reading.ts +1153 -0
- package/src/mcode/reverse.ts +201 -0
- package/src/mcode/skills.ts +6 -0
- package/src/mcode/titles.ts +51 -0
- package/src/mcode/tools.ts +56 -0
- package/src/mcode/transport.ts +31 -0
- package/src/ncode/index.ts +34 -0
- package/src/ncode/launcher.ts +33 -0
- package/src/ncode/protocol.ts +146 -0
- package/src/ncode/skills.ts +6 -0
- package/test/live/ncode-permission.test.ts +82 -0
- package/test/mcode-conformance.test.ts +52 -0
- package/test/mcode-control.test.ts +1616 -0
- package/test/mcode-durable.test.ts +722 -0
- package/test/mcode-ledger.test.ts +357 -0
- package/test/mcode-reading.test.ts +286 -0
- package/test/mcode-transport.test.ts +48 -0
- package/test/profile.test.ts +89 -0
- package/tsconfig.json +6 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// The profile of an mcode installation, and the proof of it.
|
|
2
|
+
//
|
|
3
|
+
// Offline: the profile is the program, the runtime it runs on and the home of its profile. Live
|
|
4
|
+
// (NIWA_LIVE=1, nono and an mcode on this machine): a session runs one turn in a nono box closed to
|
|
5
|
+
// reading, with nothing but that profile. MCODE_BIN selects the upstream executable. For the fork,
|
|
6
|
+
// NIWA_MCODE_LINEAGE=fork selects ncode, NCODE_BIN overrides its launcher and NCODE_PROFILE
|
|
7
|
+
// selects the account (default astrum). MCODE_MODEL and MCODE_NET select the model and hosts.
|
|
8
|
+
|
|
9
|
+
import { expect, test } from "bun:test";
|
|
10
|
+
import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { homedir, tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
|
|
14
|
+
import { profileConformance } from "@niwa-labs/harness";
|
|
15
|
+
import { nono, resolveProfile } from "@niwa-labs/sandbox";
|
|
16
|
+
import { live } from "@niwa-labs/testing";
|
|
17
|
+
|
|
18
|
+
import { mcodeKind, ncodeKind } from "../src/index.ts";
|
|
19
|
+
|
|
20
|
+
test("an installation's profile is its program, the runtime it runs on, and the home of its profile", () => {
|
|
21
|
+
const binding = mcodeKind.bind({ id: "mcode-a", home: "/srv/minimax", control: { binary: "/bin/sh" }, net: ["agent.example.com"] });
|
|
22
|
+
const profile = resolveProfile(binding.profile ?? {}, "mcode-a", { home: "/home/u", env: { PATH: "/nowhere" } });
|
|
23
|
+
expect(profile.read).toEqual(["/bin/sh"]);
|
|
24
|
+
expect(profile.write).toEqual(["/srv/minimax"]);
|
|
25
|
+
expect(profile.net).toEqual(["agent.example.com"]);
|
|
26
|
+
expect(mcodeKind.profile.status).toBe("admitted");
|
|
27
|
+
expect(ncodeKind.profile.status).toBe("verified");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test("a versioned ncode launcher reads only its current package and pinned Node", () => {
|
|
31
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), "ncode-install-")));
|
|
32
|
+
try {
|
|
33
|
+
const prefix = join(root, "store");
|
|
34
|
+
const alias = join(root, "active");
|
|
35
|
+
const revision = "a".repeat(40);
|
|
36
|
+
const relative = join("installs", "ncode", revision, "lib", "node_modules", "@niwa-labs", "ncode");
|
|
37
|
+
const pkg = join(alias, relative);
|
|
38
|
+
const node = join(root, "runtime", "bin", "node");
|
|
39
|
+
const launcher = join(alias, "bin", "ncode");
|
|
40
|
+
mkdirSync(join(prefix, "bin"), { recursive: true });
|
|
41
|
+
symlinkSync(prefix, alias);
|
|
42
|
+
mkdirSync(pkg, { recursive: true });
|
|
43
|
+
mkdirSync(join(root, "runtime", "bin"), { recursive: true });
|
|
44
|
+
mkdirSync(join(root, "runtime", "include", "node"), { recursive: true });
|
|
45
|
+
writeFileSync(join(root, "runtime", "include", "node", "node_version.h"), "");
|
|
46
|
+
writeFileSync(node, "#!/bin/sh\n", { mode: 0o755 });
|
|
47
|
+
writeFileSync(join(pkg, "package.json"), JSON.stringify({ name: "@niwa-labs/ncode" }));
|
|
48
|
+
writeFileSync(join(pkg, "release.json"), JSON.stringify({ revision }));
|
|
49
|
+
writeFileSync(join(pkg, "cli.js"), "");
|
|
50
|
+
writeFileSync(launcher, `#!/bin/sh\nMCODE_BUILD_ID=${revision}\nexec ${node} ${pkg}/cli.js "$@"\n`, { mode: 0o755 });
|
|
51
|
+
const instance = ncodeKind.bind({ id: "ncode-flash", profile: "astrum", control: { binary: launcher } });
|
|
52
|
+
const resolved = () => resolveProfile(instance.profile!, "ncode-flash", { home: root, env: { PATH: "/absent" } });
|
|
53
|
+
expect(new Set(resolved().read)).toEqual(new Set([launcher, realpathSync(launcher), pkg, realpathSync(pkg), node]));
|
|
54
|
+
expect(resolved().write).toEqual([join(homedir(), ".minimax-astrum")]);
|
|
55
|
+
writeFileSync(join(pkg, "package.json"), JSON.stringify({ name: "unrelated" }));
|
|
56
|
+
expect(resolved().read).toEqual([launcher, realpathSync(launcher)]);
|
|
57
|
+
} finally {
|
|
58
|
+
rmSync(root, { recursive: true, force: true });
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const fork = process.env["NIWA_MCODE_LINEAGE"] === "fork";
|
|
63
|
+
const binary = (fork ? process.env["NCODE_BIN"] ?? process.env["MCODE_BIN"] : process.env["MCODE_BIN"]) ?? (fork ? "ncode" : "mcode");
|
|
64
|
+
const present = live && Bun.which(binary) !== null && (await nono().available());
|
|
65
|
+
|
|
66
|
+
test.skipIf(!present)(
|
|
67
|
+
`a ${fork ? "ncode" : "mcode"} session runs a turn in a nono box with nothing but its installation's profile`,
|
|
68
|
+
async () => {
|
|
69
|
+
const cwd = realpathSync(mkdtempSync(join(tmpdir(), "mcode-profile-")));
|
|
70
|
+
try {
|
|
71
|
+
const kind = fork ? ncodeKind : mcodeKind;
|
|
72
|
+
const id = fork ? "ncode-flash" : "mcode-flash";
|
|
73
|
+
const binding = kind.bind({
|
|
74
|
+
id,
|
|
75
|
+
...(fork ? { profile: process.env["NCODE_PROFILE"] ?? "astrum" } : { home: join(homedir(), ".minimax") }),
|
|
76
|
+
model: process.env["MCODE_MODEL"] ?? "minimax/MiniMax-M3.1-Flash",
|
|
77
|
+
net: (process.env["MCODE_NET"] ?? "agent.minimax.io").split(","),
|
|
78
|
+
control: { binary },
|
|
79
|
+
});
|
|
80
|
+
const result = await profileConformance(binding, { cwd });
|
|
81
|
+
expect(result.ended).toBe(true);
|
|
82
|
+
expect(result.answered).toBe(true);
|
|
83
|
+
expect(result.box.paths.every((need) => need.from === `harness:${id}` || need.from === "temp")).toBe(true);
|
|
84
|
+
} finally {
|
|
85
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
240_000,
|
|
89
|
+
);
|