Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ set -a
. /tmp/images-runtime-startup.env
set +a
OPENCLAW_ENTERPRISE_CI_STATE=/tmp/images-runtime-startup.json \
node --test tests/integration/runtime-image-startup.test.mjs \
node --test tests/integration/runtime-image-startup.test.ts \
tests/integration/runtime-image-gateway-workspace.test.ts \
tests/integration/runtime-image-state-migration.test.mjs \
tests/integration/runtime-image-managed-files.test.ts \
Expand Down
2 changes: 1 addition & 1 deletion docs/testing/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ docker pull "$CONTROLLER_IMAGE"
docker pull "$RUNTIME_IMAGE"
OCC_TEST_PRODUCTION_IMAGE="$CONTROLLER_IMAGE" OCC_TEST_RUNTIME_IMAGE="$RUNTIME_IMAGE" \
node --test --test-concurrency=1 tests/integration/production-image-startup.test.mjs \
tests/integration/runtime-image-startup.test.mjs \
tests/integration/runtime-image-startup.test.ts \
tests/integration/runtime-image-gateway-workspace.test.ts \
tests/integration/runtime-image-public-github-read.test.mjs \
tests/integration/runtime-image-startup-probe.test.mjs \
Expand Down
2 changes: 1 addition & 1 deletion packages/occ/src/native-worker-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { SandboxDriver, SandboxFacet } from "@openclaw-enterprise/contracts
* the complete dedicated native OpenClaw flow: required worker placement
* (`cloudWorkers.requiredProfile`), node enrollment, workspace access, and native
* model execution from canonical `models.providers` configuration. No test derives
* this value: tests/integration/runtime-image-startup.test.mjs only checks that the
* this value: tests/integration/runtime-image-startup.test.ts only checks that the
* image accepts the configuration native OpenClaw renders, and schema acceptance does
* not qualify the flow. Flip it by hand, together with the assertion in
* tests/conformance/configuration-occ-sandbox-cases.ts and the native worker notes in
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/container-release/native-smoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { inspectDigest, skopeo } from "./registry.ts";
export const runtimeImageSmokeTests = Object.freeze([
"tests/helpers/workspace-gateway-relay-container.test.ts",
"tests/integration/codex-plugin-stdio-real.test.ts",
"tests/integration/runtime-image-startup.test.mjs",
"tests/integration/runtime-image-startup.test.ts",
"tests/integration/runtime-image-gateway-workspace.test.ts",
"tests/integration/runtime-image-public-github-read.test.mjs",
"tests/integration/runtime-image-state-migration.test.mjs",
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/staging-qualification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const workflow = ".github/workflows/staging-qualification.yml";
const maxReceiptBytes = 64 * 1024;
const startupFiles = [
["images-packaging", "tests/integration/production-image-startup.test.mjs"],
["images-runtime-startup", "tests/integration/runtime-image-startup.test.mjs"],
["images-runtime-startup", "tests/integration/runtime-image-startup.test.ts"],
] as const;

function decimal(value: unknown): string {
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/test-suites/images-runtime-startup.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"fileConcurrency": 3,
"parallelFiles": [
"tests/integration/runtime-image-gateway-retained-state.test.ts",
"tests/integration/runtime-image-startup.test.mjs",
"tests/integration/runtime-image-startup.test.ts",
"tests/integration/runtime-image-gateway-workspace.test.ts",
"tests/integration/runtime-image-public-github-read.test.mjs",
"tests/integration/runtime-image-managed-files.test.ts",
Expand All @@ -37,7 +37,7 @@
]
},
{
"path": "tests/integration/runtime-image-startup.test.mjs",
"path": "tests/integration/runtime-image-startup.test.ts",
"expectedTests": [
"runtime image applies the repository profile to a native thread shell turn",
"runtime image shares the reviewed Codex version between the plugin and Dedicated command",
Expand Down
19 changes: 19 additions & 0 deletions tests/fixtures/runtime-image-startup/broker-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { bundledExport, loadCodexConfig } from "./bundled-codex.ts";
import type { parseJson, record } from "./wire.ts";

export async function probeBrokerConfig(
load: typeof bundledExport,
loadConfig: typeof loadCodexConfig,
parse: typeof parseJson,
read: typeof record,
) {
const { readFileSync } = await import("node:fs");
const runtime = read(parse(readFileSync(0, "utf8")));
const resolve = await loadConfig(load, read, false);
const { networkProxy } = resolve({ pluginConfig: runtime.brokerCodexConfiguration });
const allowPatch = read(networkProxy).configPatch;
if (allowPatch === undefined) {
throw new Error("Codex network proxy config patch was not generated.");
}
process.stdout.write(JSON.stringify({ allowPatch }));
}
86 changes: 86 additions & 0 deletions tests/fixtures/runtime-image-startup/bundled-codex.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import type { record } from "./wire.ts";

type OpenClawOptions = Record<string, unknown>;
type CodexNotification = (notification: unknown) => void;

type CodexClient = {
request(
method: string,
params: OpenClawOptions,
options?: { timeoutMs: number },
): Promise<unknown>;
initialize(): Promise<unknown>;
close(): void;
closeAndWait(options: { exitTimeoutMs: number; forceKillDelayMs: number }): Promise<unknown>;
getServerVersion(): unknown;
addNotificationHandler(handler: CodexNotification): void;
};

export async function bundledExport(prefix: string, symbol: string, matchSource = true) {
const { readFileSync, readdirSync } = await import("node:fs");
const { join } = await import("node:path");
const { pathToFileURL } = await import("node:url");
const dist = "/app/node_modules/openclaw/dist";
const chunk = readdirSync(dist).find(
(name) =>
name.startsWith(prefix + "-") &&
name.endsWith(".mjs") &&
(!matchSource || readFileSync(join(dist, name), "utf8").includes(" " + symbol)),
);
if (chunk === undefined) {
throw new Error("Missing packaged chunk for " + symbol);
}
const exports: Record<string, unknown> = await import(pathToFileURL(join(dist, chunk)).href);
const result = Object.values(exports).find(
(value): value is (...args: unknown[]) => unknown =>
typeof value === "function" && value.name === symbol,
);
if (result === undefined) {
throw new Error("Missing packaged export " + symbol);
}
return result;
}

export async function loadCodexConfig(
load: typeof bundledExport,
read: typeof record,
matchSource = true,
) {
const createConfig = await load("config-options", "createCodexAppServerConfig", matchSource);
const aliasPath = "openclaw/plugin-sdk/provider-auth-aliases";
const aliases: Record<string, unknown> = await import(aliasPath);
const resolveProviderIdForAuth = aliases.resolveProviderIdForAuth;
if (typeof resolveProviderIdForAuth !== "function") {
throw new Error("Missing packaged provider-auth resolver.");
}
const config = read(createConfig({ resolveProviderIdForAuth }));
const resolve = config.resolveCodexAppServerRuntimeOptions;
if (typeof resolve !== "function") {
throw new Error("Missing packaged Codex runtime resolver.");
}
const resolveOptions = resolve as (input: OpenClawOptions) => unknown;
return (options: OpenClawOptions) => read(resolveOptions(options));
}

export async function loadCodexClient(load: typeof bundledExport, read: typeof record) {
const clientClass = await load("client", "CodexAppServerClient");
if (!("start" in clientClass) || typeof clientClass.start !== "function") {
throw new Error("Missing packaged Codex client starter.");
}
const start = clientClass.start as (this: typeof clientClass, input: OpenClawOptions) => unknown;
return async (options: OpenClawOptions): Promise<CodexClient> => {
const client: unknown = await start.call(clientClass, options);
const candidate = read(client);
if (
typeof candidate.request !== "function" ||
typeof candidate.initialize !== "function" ||
typeof candidate.close !== "function" ||
typeof candidate.closeAndWait !== "function" ||
typeof candidate.getServerVersion !== "function" ||
typeof candidate.addNotificationHandler !== "function"
) {
throw new Error("Invalid packaged Codex client.");
}
return candidate as CodexClient;
};
}
157 changes: 157 additions & 0 deletions tests/fixtures/runtime-image-startup/dedicated-command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import type { ChildProcessWithoutNullStreams, SpawnOptions } from "node:child_process";
import type { commandResult, codexRpc, parseJson, record, text } from "./wire.ts";

export async function probeDedicatedCommand(
tokenHash: string,
historicalCodex: boolean,
createRpc: typeof codexRpc,
parse: typeof parseJson,
read: typeof record,
asText: typeof text,
observeCommand: typeof commandResult,
) {
const assert: typeof import("node:assert/strict") =
process.getBuiltinModule("node:assert/strict");
const cp = process.getBuiltinModule("node:child_process");
const vm = process.getBuiltinModule("node:vm");
const fs = process.getBuiltinModule("node:fs");
const { createInterface } = process.getBuiltinModule("node:readline");
const requireModule: (name: string) => unknown = process
.getBuiltinModule("node:module")
.createRequire(process.cwd() + "/[eval]");
const environment: NodeJS.ProcessEnv = {
PATH: "/opt/oce/repository-credentials/bin:" + process.env.PATH,
HOME: "/home/node",
CODEX_HOME: "/home/node/.codex",
CODEX_LOGIN_MODE: "api_key",
OPENAI_API_KEY: "synthetic-offline-key",
OPENCLAW_HARNESS_MODEL: "codex/gpt-5",
APP_TOKEN_SHA: tokenHash,
APP_SERVER_PORT: "4500",
// The workspace node supervisor points hooks at a CA copy the sandbox cannot read.
NODE_EXTRA_CA_CERTS: "/home/node/.oce-native-hooks/gateway-ca.pem",
OPENCLAW_SHELL_NODE_EXTRA_CA_CERTS: "/run/oce/repository-credentials/ca-bundle.pem",
};
const launched: { native?: ChildProcessWithoutNullStreams } = {};
// The entrypoint arrives on stdin: inlined, it can exceed the per-argument limit.
vm.runInNewContext(fs.readFileSync(0, "utf8"), {
URL,
console,
setTimeout,
setInterval,
// The wrapper forwards filtered app-server stderr; the probe reads native.stderr itself.
process: {
env: environment,
stderr: {
write() {
return true;
},
},
on() {},
exit() {},
},
require(name: string) {
if (name !== "node:child_process") {
return requireModule(name);
}
return {
spawnSync(_command: string, args: string[]) {
return args.includes("login")
? { status: 0 }
: {
status: 0,
stdout: [
{ type: "turn.started" },
{ type: "item.completed", item: { type: "agent_message", text: "READY" } },
{ type: "turn.completed" },
]
.map((message) => JSON.stringify(message))
.join("\n"),
};
},
spawn(command: string, args: string[], options: SpawnOptions) {
const appServer = args.indexOf("app-server");
assert.ok(appServer > 0);
const appServerEnvironment = options.env ?? environment;
assert.equal(Object.hasOwn(appServerEnvironment, "APP_SERVER_TOKEN"), false);
assert.equal(Object.hasOwn(appServerEnvironment, "APP_TOKEN_SHA"), false);
assert.equal(
Object.hasOwn(appServerEnvironment, "OPENCLAW_SHELL_NODE_EXTRA_CA_CERTS"),
false,
);
assert.equal(appServerEnvironment.NODE_EXTRA_CA_CERTS, environment.NODE_EXTRA_CA_CERTS);
launched.native = cp.spawn(
command,
[...args.slice(0, appServer + 1), "--listen", "stdio://"],
{
...options,
env: appServerEnvironment,
stdio: ["pipe", "pipe", "pipe"],
},
);
return launched.native;
},
};
},
});
const { native } = launched;
assert.ok(native);
const lines = createInterface({ input: native.stdout });
const rpc = createRpc(native, lines, parse, read).request;
native.stderr.resume();
const timeout = setTimeout(() => {
native.kill("SIGKILL");
process.exitCode = 1;
}, 20000);
try {
await rpc("initialize", {
clientInfo: { name: "repository-runtime-smoke", version: "1.0.0" },
capabilities: { experimentalApi: true },
});
native.stdin.write(JSON.stringify({ method: "initialized" }) + "\n");
const config = read(read(await rpc("config/read", {})).config);
const shellEnvironment = read(read(config.shell_environment_policy).set);
// Native metrics have a separate upstream exporter default from logs.
if (!historicalCodex) {
assert.equal(read(config.otel).metrics_exporter, "none");
}
assert.equal(config.allow_login_shell, false);
assert.equal(shellEnvironment.PATH, environment.PATH);
assert.equal(
shellEnvironment.NODE_EXTRA_CA_CERTS,
environment.OPENCLAW_SHELL_NODE_EXTRA_CA_CERTS,
);
const result = observeCommand(
await rpc("command/exec", {
command: [
"/bin/bash",
"-c",
'test -z "$APP_SERVER_TOKEN" || exit 1; test -z "$APP_TOKEN_SHA" || exit 1; command -v gh; command -v git; git config --system --get-all include.path; echo "$NODE_EXTRA_CA_CERTS"',
],
sandboxPolicy: { type: "externalSandbox", networkAccess: "restricted" },
timeoutMs: 5000,
}),
read,
asText,
);
assert.equal(result.exitCode, 0);
assert.deepEqual(result.stdout.trim().split("\n"), [
"/opt/oce/repository-credentials/bin/gh",
"/usr/bin/git",
"/run/oce/repository-credentials/gitconfig",
environment.OPENCLAW_SHELL_NODE_EXTRA_CA_CERTS,
]);
fs.accessSync(
"/opt/oce/repository-credentials/dist/drivers/repo/github/access/client/router.js",
);
process.stdout.write("native-repository-shell-ready\n");
// The proof is complete. The Codex binary, a grandchild that holds this
// probe's pipes, takes about 5 s to exit after SIGTERM or EOF. This node is
// the container's PID 1, so its exit stops Codex at once.
process.exit();
} finally {
clearTimeout(timeout);
lines.close();
native.kill("SIGTERM");
}
}
Loading
Loading