@niwa-labs/harness-codex 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 +16 -2
- package/package.json +20 -4
- package/scripts/gen-codex.ts +352 -0
- package/src/control.ts +1596 -0
- package/src/fixtures.ts +103 -0
- package/src/format.ts +196 -0
- package/src/incoming.ts +273 -0
- package/src/index.ts +128 -0
- package/src/paths.ts +42 -0
- package/src/protocol/generated/app-server.ts +2818 -0
- package/src/protocol/index.ts +106 -0
- package/src/reading.ts +940 -0
- package/src/refusals.ts +72 -0
- package/src/reverse.ts +243 -0
- package/src/skills.ts +6 -0
- package/src/tools.ts +69 -0
- package/test/codex-conformance.test.ts +29 -0
- package/test/codex-control-process.test.ts +1239 -0
- package/test/codex-control.test.ts +217 -0
- package/test/codex-elicitation.test.ts +71 -0
- package/test/codex-protocol.test.ts +245 -0
- package/test/codex-reading.test.ts +513 -0
- package/test/fixtures/codex-app-server/captured.jsonl +21 -0
- package/test/fixtures/codex-frames.ts +88 -0
- package/test/fixtures/zod-instance.ts +35 -0
- package/test/profile.test.ts +48 -0
- package/tsconfig.json +6 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The smallest value a zod schema takes: the required fields of an object only, and the first
|
|
3
|
+
* option of a union that takes it. A test that needs one message of every variant of a protocol,
|
|
4
|
+
* and has a real one for only some, makes the rest with this.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
|
|
9
|
+
export function minimalInstance(schema: z.core.$ZodType): unknown {
|
|
10
|
+
if (schema instanceof z.ZodObject) {
|
|
11
|
+
const made: Record<string, unknown> = {};
|
|
12
|
+
for (const [key, field] of Object.entries(schema.shape)) {
|
|
13
|
+
if (field instanceof z.ZodOptional || field instanceof z.ZodDefault) continue;
|
|
14
|
+
made[key] = minimalInstance(field);
|
|
15
|
+
}
|
|
16
|
+
return made;
|
|
17
|
+
}
|
|
18
|
+
if (schema instanceof z.ZodUnion) {
|
|
19
|
+
for (const option of schema.options) {
|
|
20
|
+
const value = minimalInstance(option);
|
|
21
|
+
if (z.safeParse(schema, value).success) return value;
|
|
22
|
+
}
|
|
23
|
+
throw new Error("no option of the union takes its smallest value");
|
|
24
|
+
}
|
|
25
|
+
if (schema instanceof z.ZodLiteral) return schema.value;
|
|
26
|
+
if (schema instanceof z.ZodEnum) return schema.options[0];
|
|
27
|
+
if (schema instanceof z.ZodString) return "x";
|
|
28
|
+
if (schema instanceof z.ZodNumber) return 1;
|
|
29
|
+
if (schema instanceof z.ZodBoolean) return false;
|
|
30
|
+
if (schema instanceof z.ZodNull) return null;
|
|
31
|
+
if (schema instanceof z.ZodArray) return [];
|
|
32
|
+
if (schema instanceof z.ZodRecord) return {};
|
|
33
|
+
if (schema instanceof z.ZodLazy) return minimalInstance(schema.unwrap());
|
|
34
|
+
throw new Error(`no smallest value is known for ${schema.constructor.name}`);
|
|
35
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// The profile of a Codex installation, and the proof of it.
|
|
2
|
+
//
|
|
3
|
+
// Offline: the profile is the installation's program, its home and the endpoints of its model and
|
|
4
|
+
// its sign-in. Live (NIWA_LIVE=1, nono and `codex` on this machine): a session of an installation
|
|
5
|
+
// runs one turn in a nono box closed to reading, with nothing but that profile; the kind's profile
|
|
6
|
+
// is declared verified on that proof. The model is the cheap one, `gpt-6-luna` unless CODEX_MODEL
|
|
7
|
+
// names another.
|
|
8
|
+
|
|
9
|
+
import { expect, test } from "bun:test";
|
|
10
|
+
import { mkdtempSync, realpathSync, rmSync } from "node:fs";
|
|
11
|
+
import { 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 { codexKind } from "../src/index.ts";
|
|
19
|
+
|
|
20
|
+
test("an installation's profile is its program, its home, and the endpoints of its model and sign-in", () => {
|
|
21
|
+
const binding = codexKind.bind({ id: "codex-a", home: "/srv/codex-a", control: { binary: "/bin/sh" } });
|
|
22
|
+
const profile = resolveProfile(binding.profile ?? {}, "codex-a", { home: "/home/u", env: {} });
|
|
23
|
+
expect(profile.write).toEqual(["/srv/codex-a"]);
|
|
24
|
+
expect(profile.read).toContain("/bin/sh");
|
|
25
|
+
expect(profile.programs).toContain("/bin/sh");
|
|
26
|
+
expect(profile.net).toEqual(["api.openai.com", "chatgpt.com"]);
|
|
27
|
+
expect(codexKind.profile.status).toBe("verified");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const present = live && Bun.which("codex") !== null && (await nono().available());
|
|
31
|
+
|
|
32
|
+
test.skipIf(!present)(
|
|
33
|
+
"a Codex session runs a turn in a nono box with nothing but its installation's profile",
|
|
34
|
+
async () => {
|
|
35
|
+
const cwd = realpathSync(mkdtempSync(join(tmpdir(), "codex-profile-")));
|
|
36
|
+
try {
|
|
37
|
+
const binding = codexKind.bind({ id: "codex-luna", model: process.env["CODEX_MODEL"] ?? "gpt-6-luna" });
|
|
38
|
+
const result = await profileConformance(binding, { cwd });
|
|
39
|
+
expect(result.ended).toBe(true);
|
|
40
|
+
expect(result.answered).toBe(true);
|
|
41
|
+
expect(result.box.sandbox).toBe("nono");
|
|
42
|
+
expect(result.box.paths.every((need) => need.from === "harness:codex-luna" || need.from === "temp")).toBe(true);
|
|
43
|
+
} finally {
|
|
44
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
240_000,
|
|
48
|
+
);
|