Files
openclaw/test/scripts/ci-node-test-plan.test.ts
Peter Steinberger bb46b79d3c refactor: internalize OpenClaw agent runtime (#85341)
* refactor: extract agent core package

Introduce packages/agent-core as the OpenClaw-owned home for reusable agent loop, harness, session, prompt, and runtime dependency contracts.

* refactor: extract shared llm runtime

Move provider model registries, stream wrappers, OAuth helpers, and LLM utilities into src/llm with plugin-sdk barrels instead of depending on the old embedded runtime layout.

* refactor: remove pi runtime internals

Rename remaining Pi-shaped agent surfaces to OpenClaw agent runtime names, delete obsolete Pi docs and package graph checks, and add the third-party notice for incorporated code.

* refactor: tighten agent session runtime

Make agent-core/runtime dependencies explicit, consolidate compaction and session transcript helpers, and move model/session helpers behind OpenClaw-owned contracts.

* refactor: remove static model and pi auth paths

Drop static model catalogs and Pi auth bridges, move model/provider facts to manifest-owned runtime contracts, and harden internal embedded-agent utilities.

* refactor: remove legacy provider compat paths

* docs: remove agent parity notes

* fix: skip provider wildcard metadata parsing

* refactor: share session extension sdk loading

* refactor: inline acpx proxy error formatter

* refactor: fold edit recovery into edit tool

* fix: accept extension batch separator

* test: align startup provider plugin expectations

* fix: restore provider-scoped release discovery

* test: align static asset packaging expectations

* fix: run static provider catalogs during scoped discovery

* fix: add provider entry catalogs for scoped live discovery

* fix: load lightweight provider catalog entries

* fix: refresh provider-scoped plugin metadata

* fix: keep provider catalog entries on release live path

* fix: keep static manifest models in release live checks

* fix: harden release model discovery

* fix: reduce OpenAI live cache probe reasoning

* fix: disable OpenAI cache probe reasoning

* ci: extend OpenAI gateway live timeout

* fix: extend live gateway model budget

* fix: stabilize release validation regressions

* fix: honor provider aliases in model rows

* fix: stabilize release validation lanes

* fix: stabilize release memory qa

* ci: stabilize release validation lanes

* ci: prefer ipv4 for live docker node calls

* fix: restore shared tool-call stream wrapper

* ci: remove legacy pi test shard alias

* fix: clean up embedded agent test drift

* fix: stabilize runtime alias status

* fix: clean up embedded agent ci drift

* fix: restore release ci invariants

* fix: clean up post-rebase runtime drift

* fix: restore release ci checks

* fix: restore release ci after rebase

* fix: remove stale pi runtime path

* test: align compaction runtime expectations

* test: update plugin prerelease expectations

* fix: handle claude live tool approvals

* fix: stabilize release validation gates

* fix: finish agent runtime import

* test: finish post-rebase agent runtime mocks

* fix: keep codex compaction native

* fix: stabilize codex app-server hook tests

* test: isolate codex diagnostic active run

* test: remove codex diagnostic completion race

# Conflicts:
#	extensions/codex/src/app-server/run-attempt.test.ts

* ci: fix full release manifest performance run id

* refactor: narrow llm plugin sdk boundary

* chore: drop generated google boundary stamps

* fix: repair rebase fallout

* fix: clean up rebased runtime references

* fix: decode codex jwt payloads as base64url

* fix: preserve shipped pi runtime alias

* fix: add scoped sdk virtual modules

* fix: decode llm codex oauth jwt as base64url

* fix: avoid stale vertex adc negative cache

* fix: harden tool arg decoding and codeql path

* fix: keep vertex adc negative checks live

* refactor: consolidate codex jwt and edit helpers

* fix: await codex oauth node runtime imports

* fix: preserve sdk tool and notice contracts

* fix: preserve shipped compat config boundaries

* fix: align codex oauth callback host

* fix: terminate agent-core loop streams on failure

* fix: keep codex oauth callback alive during fallback

* ci: include session tools in critical codeql scans

* fix: keep Cloudflare Anthropic provider auth header

* docs: redirect legacy pi runtime pages

* fix: honor bundled web provider compat discovery

* fix: protect session output spill files

* fix: keep legacy agent dir env blocked

* fix: contain auto-discovered skill symlinks

* fix: harden agent core sdk proxy surfaces

* fix: restore approval reaction sdk compat

* fix: keep live docker runs bounded

* fix: keep codex oauth redirect host aligned

* fix: resolve post-rebase agent runtime drift

* fix: redact anthropic oauth parse failures

* fix: preserve responses strict tool shaping

* fix: repair agent runtime rebase cleanup

* docs: redirect retired parity pages

* fix: bound auto-discovered resources to roots

* fix: repair post-rebase agent test drift

* fix: preserve bundled provider allowlist migration

* fix: preserve manifest-owned provider aliases

* fix: declare photon image dependency

* fix: keep provider headers out of proxy body

* fix: preserve shipped env aliases

* fix: refresh control ui i18n generated state

* fix: quote read fallback paths

* fix: preview edits through configured backend

* test: satisfy core test typecheck

* fix: preserve ZAI usage auth fallback

* test: repair codex diagnostic test

* fix: repair agent runtime rebase drift

* test: finish embedded runner import rename

* fix: repair agent runtime rebase integrations

* test: align compaction oauth fallback expectations

* fix: allow sdk-auth session models

* fix: update doctor tool schema import

* fix: preserve bedrock plugin region

* fix: stream harmony-like prose immediately

* ci: include session runtime in codeql shards

* fix: repair latest rebase integrations

* fix: honor explicit codex websocket transport

* fix: keep openai-compatible credentials provider-scoped

* fix: refresh sdk api baseline after rebase

* fix: route cli runtime aliases through openclaw harness

* test: rename stale harness mock expectation

* test: rename embedded agent overflow calls

* test: clean embedded auth test wording

* test: use openclaw stream types in deepinfra cache test

* fix: refresh sdk api baseline on latest main

* fix: honor bundled discovery compat allowlists

* fix: refresh sdk api baseline after latest rebase

* fix: remove stale rebase imports

* test: rename stale model catalog mock

* test: mock renamed doctor runtime modules

* fix: map canonical kimi env auth

* fix: use internal model registry in bench script

* fix: migrate deepinfra provider catalog entry

* fix: enforce builtin tool suppression

* fix: route compaction auth and proxy payloads safely

* refactor: prune unused llm registry leftovers

* test: update codex hooks session import

* test: fix model picker ci coverage

* test: align model picker auth mock types
2026-05-27 19:24:04 +01:00

487 lines
17 KiB
TypeScript

import { existsSync, readdirSync } from "node:fs";
import { join, relative, resolve } from "node:path";
import fg from "fast-glob";
import { describe, expect, it } from "vitest";
import { createNodeTestShards } from "../../scripts/lib/ci-node-test-plan.mjs";
import { expectNoNodeFsScans } from "../../src/test-utils/fs-scan-assertions.js";
import { listGitTrackedFiles, sortRepoPaths, toRepoPath } from "../../src/test-utils/repo-files.js";
import { commandsLightTestFiles } from "../vitest/vitest.commands-light-paths.mjs";
import { createPluginsVitestConfig } from "../vitest/vitest.plugins.config.ts";
type VitestTestConfig = {
dir?: string;
exclude?: string[];
include?: string[];
};
type VitestConfig = {
test?: VitestTestConfig;
};
const PLUGIN_PRERELEASE_NPM_SPEC_TEST = "src/plugins/install.npm-spec.test.ts";
const PLUGIN_NPM_INSTALL_SECURITY_SCAN_TEST =
"src/plugins/npm-install-security-scan.release.test.ts";
const GATEWAY_SERVER_BACKED_HTTP_TESTS = new Set([
"src/gateway/embeddings-http.test.ts",
"src/gateway/models-http.test.ts",
"src/gateway/openai-http.test.ts",
"src/gateway/openresponses-http.test.ts",
"src/gateway/probe.auth.integration.test.ts",
]);
const GATEWAY_SERVER_EXCLUDED_TESTS = new Set([
"src/gateway/gateway.test.ts",
"src/gateway/server.startup-matrix-migration.integration.test.ts",
"src/gateway/sessions-history-http.test.ts",
]);
function listTestFiles(rootDir: string): string[] {
const gitFiles = listGitTrackedFiles({ pathspecs: rootDir });
expect(gitFiles).not.toBeNull();
if (gitFiles) {
return gitFiles.filter((line) => line.endsWith(".test.ts"));
}
if (!existsSync(rootDir)) {
return [];
}
const files: string[] = [];
const visit = (dir: string) => {
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const path = join(dir, entry.name);
if (entry.isDirectory()) {
visit(path);
} else if (entry.isFile() && entry.name.endsWith(".test.ts")) {
files.push(toRepoPath(path));
}
}
};
visit(rootDir);
return sortRepoPaths(files);
}
function listMatchedTestFiles(config: VitestConfig): string[] {
const testConfig = config.test ?? {};
const cwd = testConfig.dir ? resolve(testConfig.dir) : process.cwd();
return fg
.sync(testConfig.include ?? [], {
absolute: false,
cwd,
dot: false,
ignore: testConfig.exclude ?? [],
})
.map((file) => toRepoPath(relative(process.cwd(), resolve(cwd, file))))
.toSorted((a, b) => a.localeCompare(b));
}
function isGatewayServerTestFile(file: string): boolean {
return (
file.startsWith("src/gateway/") &&
!file.startsWith("src/gateway/server-methods/") &&
!GATEWAY_SERVER_EXCLUDED_TESTS.has(file) &&
(file.includes("server") || GATEWAY_SERVER_BACKED_HTTP_TESTS.has(file))
);
}
describe("scripts/lib/ci-node-test-plan.mjs", () => {
it("creates split shards without walking test roots", () => {
const payload = expectNoNodeFsScans<{
includePatterns: number;
shards: number;
}>(`
const { createNodeTestShards } = await import("./scripts/lib/ci-node-test-plan.mjs");
const shards = createNodeTestShards();
return {
includePatterns: shards.reduce(
(total, shard) => total + (shard.includePatterns?.length ?? 0),
0,
),
shards: shards.length,
};
`);
expect(payload.shards).toBeGreaterThan(0);
expect(payload.includePatterns).toBeGreaterThan(0);
});
it("splits the slow core unit shards while keeping paired source/security coverage", () => {
const coreUnitShards = createNodeTestShards()
.filter((shard) => shard.shardName.startsWith("core-unit-"))
.map((shard) => ({
configs: shard.configs,
requiresDist: shard.requiresDist,
shardName: shard.shardName,
}));
expect(coreUnitShards).toEqual([
{
configs: ["test/vitest/vitest.unit-fast.config.ts"],
requiresDist: false,
shardName: "core-unit-fast",
},
{
configs: [
"test/vitest/vitest.unit-src.config.ts",
"test/vitest/vitest.unit-security.config.ts",
],
requiresDist: false,
shardName: "core-unit-src-security",
},
{
configs: ["test/vitest/vitest.unit-ui.config.ts"],
requiresDist: false,
shardName: "core-unit-ui",
},
{
configs: ["test/vitest/vitest.unit-support.config.ts"],
requiresDist: false,
shardName: "core-unit-support",
},
]);
});
it("names the node shard checks as core test lanes", () => {
const shards = createNodeTestShards();
expect(shards).not.toHaveLength(0);
expect(shards.map((shard) => shard.checkName)).toEqual(
shards.map((shard) =>
shard.shardName.startsWith("core-unit-")
? `checks-node-core-${shard.shardName.slice("core-unit-".length)}`
: `checks-node-${shard.shardName}`,
),
);
});
it("keeps extension, bundled, contracts, and channels configs out of the core node lane", () => {
const configs = createNodeTestShards().flatMap((shard) => shard.configs);
expect(configs).not.toContain("test/vitest/vitest.channels.config.ts");
expect(configs).not.toContain("test/vitest/vitest.contracts.config.ts");
expect(configs).not.toContain("test/vitest/vitest.bundled.config.ts");
expect(configs).not.toContain("test/vitest/vitest.full-extensions.config.ts");
expect(configs).not.toContain("test/vitest/vitest.extension-telegram.config.ts");
});
it("marks only dist-dependent shards for built artifact restore", () => {
const requiresDistShardNames = createNodeTestShards()
.filter((shard) => shard.requiresDist)
.map((shard) => shard.shardName);
expect(requiresDistShardNames).toEqual(["core-support-boundary"]);
});
it("splits core runtime configs into smaller source-only shards", () => {
const runtimeShards = createNodeTestShards()
.filter((shard) => shard.shardName.startsWith("core-runtime-"))
.map((shard) => ({
configs: shard.configs,
requiresDist: shard.requiresDist,
runner: shard.runner,
shardName: shard.shardName,
}));
expect(runtimeShards).toEqual([
{
configs: [
"test/vitest/vitest.infra.config.ts",
"test/vitest/vitest.hooks.config.ts",
"test/vitest/vitest.secrets.config.ts",
],
requiresDist: false,
runner: "blacksmith-4vcpu-ubuntu-2404",
shardName: "core-runtime-infra-state",
},
{
configs: [
"test/vitest/vitest.logging.config.ts",
"test/vitest/vitest.process.config.ts",
"test/vitest/vitest.runtime-config.config.ts",
],
requiresDist: false,
runner: "blacksmith-4vcpu-ubuntu-2404",
shardName: "core-runtime-infra-process",
},
{
configs: [
"test/vitest/vitest.media.config.ts",
"test/vitest/vitest.media-understanding.config.ts",
"test/vitest/vitest.tui.config.ts",
"test/vitest/vitest.ui.config.ts",
"test/vitest/vitest.wizard.config.ts",
],
requiresDist: false,
runner: undefined,
shardName: "core-runtime-media-ui",
},
{
configs: [
"test/vitest/vitest.acp.config.ts",
"test/vitest/vitest.shared-core.config.ts",
"test/vitest/vitest.tasks.config.ts",
"test/vitest/vitest.utils.config.ts",
],
requiresDist: false,
runner: undefined,
shardName: "core-runtime-shared",
},
{
configs: ["test/vitest/vitest.cron.config.ts"],
requiresDist: false,
runner: undefined,
shardName: "core-runtime-cron-core",
},
{
configs: ["test/vitest/vitest.cron.config.ts"],
requiresDist: false,
runner: undefined,
shardName: "core-runtime-cron-isolated-agent",
},
{
configs: ["test/vitest/vitest.cron.config.ts"],
requiresDist: false,
runner: undefined,
shardName: "core-runtime-cron-service",
},
]);
});
it("covers every cron test exactly once across core runtime cron shards", () => {
const cronShards = createNodeTestShards().filter((shard) =>
shard.shardName.startsWith("core-runtime-cron-"),
);
const actual = cronShards
.flatMap((shard) => shard.includePatterns ?? [])
.toSorted((a, b) => a.localeCompare(b));
expect(cronShards.map((shard) => shard.shardName)).toEqual([
"core-runtime-cron-core",
"core-runtime-cron-isolated-agent",
"core-runtime-cron-service",
]);
expect(actual).toEqual(listTestFiles("src/cron"));
expect(new Set(actual).size).toBe(actual.length);
});
it("splits the agentic lane into control-plane, command, agent, gateway, SDK, and plugin shards", () => {
const shards = createNodeTestShards();
const controlPlaneShards = shards.filter((shard) =>
shard.shardName.startsWith("agentic-control-plane-"),
);
const cliShard = shards.find((shard) => shard.shardName === "agentic-cli");
const commandSupportShard = shards.find(
(shard) => shard.shardName === "agentic-command-support",
);
const commandShards = shards.filter((shard) => shard.shardName.startsWith("agentic-commands-"));
const agentShard = shards.find((shard) => shard.shardName === "agentic-agents");
const gatewayCoreShard = shards.find((shard) => shard.shardName === "agentic-gateway-core");
const gatewayMethodsShard = shards.find(
(shard) => shard.shardName === "agentic-gateway-methods",
);
const pluginSdkShard = shards.find((shard) => shard.shardName === "agentic-plugin-sdk");
const pluginsShard = shards.find((shard) => shard.shardName === "agentic-plugins");
expect(controlPlaneShards.map((shard) => shard.shardName)).toEqual([
"agentic-control-plane-agent-chat",
"agentic-control-plane-auth-node",
"agentic-control-plane-http-models",
"agentic-control-plane-http-plugin-ws",
"agentic-control-plane-runtime",
"agentic-control-plane-startup-runtime",
]);
expect(controlPlaneShards).toEqual(
controlPlaneShards.map((shard) => ({
checkName: `checks-node-${shard.shardName}`,
configs: ["test/vitest/vitest.gateway-server.config.ts"],
includePatterns: shard.includePatterns,
requiresDist: false,
runner: "blacksmith-4vcpu-ubuntu-2404",
shardName: shard.shardName,
})),
);
const controlPlaneShardFiles = controlPlaneShards
.flatMap((shard) => shard.includePatterns ?? [])
.toSorted((a, b) => a.localeCompare(b));
const expectedControlPlaneFiles = listTestFiles("src/gateway")
.filter(isGatewayServerTestFile)
.toSorted((a, b) => a.localeCompare(b));
expect(controlPlaneShardFiles).toEqual(expectedControlPlaneFiles);
expect(new Set(controlPlaneShardFiles).size).toBe(controlPlaneShardFiles.length);
expect(cliShard).toEqual({
checkName: "checks-node-agentic-cli",
shardName: "agentic-cli",
configs: ["test/vitest/vitest.cli.config.ts"],
requiresDist: false,
});
expect(commandSupportShard).toEqual({
checkName: "checks-node-agentic-command-support",
shardName: "agentic-command-support",
configs: [
"test/vitest/vitest.commands-light.config.ts",
"test/vitest/vitest.daemon.config.ts",
],
requiresDist: false,
});
expect(commandShards.map((shard) => shard.shardName)).toEqual([
"agentic-commands-agent-channel",
"agentic-commands-doctor",
"agentic-commands-doctor-shared",
"agentic-commands-models",
"agentic-commands-onboard-config",
"agentic-commands-status-tools",
]);
expect(commandShards).toEqual(
commandShards.map((shard) => ({
checkName: `checks-node-${shard.shardName}`,
configs: ["test/vitest/vitest.commands.config.ts"],
includePatterns: shard.includePatterns,
requiresDist: false,
shardName: shard.shardName,
})),
);
const commandShardFiles = commandShards
.flatMap((shard) => shard.includePatterns ?? [])
.toSorted((a, b) => a.localeCompare(b));
const expectedCommandFiles = listTestFiles("src/commands")
.filter((file) => !commandsLightTestFiles.includes(file))
.toSorted((a, b) => a.localeCompare(b));
expect(commandShardFiles).toEqual(expectedCommandFiles);
expect(new Set(commandShardFiles).size).toBe(commandShardFiles.length);
expect(agentShard).toEqual({
checkName: "checks-node-agentic-agents",
shardName: "agentic-agents",
configs: [
"test/vitest/vitest.agents-core.config.ts",
"test/vitest/vitest.agents-embedded-agent.config.ts",
"test/vitest/vitest.agents-support.config.ts",
"test/vitest/vitest.agents-tools.config.ts",
],
requiresDist: false,
});
expect(pluginSdkShard).toEqual({
checkName: "checks-node-agentic-plugin-sdk",
shardName: "agentic-plugin-sdk",
configs: [
"test/vitest/vitest.plugin-sdk-light.config.ts",
"test/vitest/vitest.plugin-sdk.config.ts",
],
requiresDist: false,
});
expect(gatewayCoreShard).toEqual({
checkName: "checks-node-agentic-gateway-core",
shardName: "agentic-gateway-core",
configs: [
"test/vitest/vitest.gateway-core.config.ts",
"test/vitest/vitest.gateway-client.config.ts",
],
requiresDist: false,
});
expect(gatewayMethodsShard).toEqual({
checkName: "checks-node-agentic-gateway-methods",
shardName: "agentic-gateway-methods",
configs: ["test/vitest/vitest.gateway-methods.config.ts"],
requiresDist: false,
});
expect(pluginsShard).toEqual({
checkName: "checks-node-agentic-plugins",
shardName: "agentic-plugins",
configs: ["test/vitest/vitest.plugins.config.ts"],
requiresDist: false,
});
});
it("keeps plugin prerelease npm install coverage on the release-only agentic plugin shard", () => {
const pluginsShard = createNodeTestShards().find(
(shard) => shard.shardName === "agentic-plugins",
);
expect(pluginsShard).toEqual({
checkName: "checks-node-agentic-plugins",
configs: ["test/vitest/vitest.plugins.config.ts"],
requiresDist: false,
shardName: "agentic-plugins",
});
expect(listMatchedTestFiles(createPluginsVitestConfig({}))).toContain(
PLUGIN_PRERELEASE_NPM_SPEC_TEST,
);
expect(listMatchedTestFiles(createPluginsVitestConfig({}))).toContain(
PLUGIN_NPM_INSTALL_SECURITY_SCAN_TEST,
);
});
it("keeps expensive plugin shards release-only when normal CI asks for the cheaper plan", () => {
const shards = createNodeTestShards({ includeReleaseOnlyPluginShards: false });
const shardNames = shards.map((shard) => shard.shardName);
expect(shardNames).not.toContain("agentic-plugins");
expect(shardNames).toContain("agentic-gateway-core");
expect(shardNames).toContain("agentic-gateway-methods");
expect(shardNames).toContain("agentic-plugin-sdk");
});
it("splits auto-reply into balanced core/top-level and reply subtree shards", () => {
const shards = createNodeTestShards();
const autoReplyShards = shards
.filter((shard) => shard.shardName.startsWith("auto-reply"))
.map((shard) => ({
checkName: shard.checkName,
configs: shard.configs,
requiresDist: shard.requiresDist,
shardName: shard.shardName,
}));
expect(autoReplyShards).toEqual([
{
checkName: "checks-node-auto-reply-core-top-level",
configs: [
"test/vitest/vitest.auto-reply-core.config.ts",
"test/vitest/vitest.auto-reply-top-level.config.ts",
],
requiresDist: false,
shardName: "auto-reply-core-top-level",
},
{
checkName: "checks-node-auto-reply-reply-agent-runner",
configs: ["test/vitest/vitest.auto-reply-reply.config.ts"],
requiresDist: false,
shardName: "auto-reply-reply-agent-runner",
},
{
checkName: "checks-node-auto-reply-reply-commands",
configs: ["test/vitest/vitest.auto-reply-reply.config.ts"],
requiresDist: false,
shardName: "auto-reply-reply-commands",
},
{
checkName: "checks-node-auto-reply-reply-dispatch",
configs: ["test/vitest/vitest.auto-reply-reply.config.ts"],
requiresDist: false,
shardName: "auto-reply-reply-dispatch",
},
{
checkName: "checks-node-auto-reply-reply-session",
configs: ["test/vitest/vitest.auto-reply-reply.config.ts"],
requiresDist: false,
shardName: "auto-reply-reply-session",
},
{
checkName: "checks-node-auto-reply-reply-state-routing",
configs: ["test/vitest/vitest.auto-reply-reply.config.ts"],
requiresDist: false,
shardName: "auto-reply-reply-state-routing",
},
]);
});
it("covers every auto-reply reply test exactly once across split shards", () => {
const actual = createNodeTestShards()
.filter((shard) => shard.shardName.startsWith("auto-reply-reply-"))
.flatMap((shard) => shard.includePatterns ?? [])
.toSorted((a, b) => a.localeCompare(b));
expect(actual).toEqual(listTestFiles("src/auto-reply/reply"));
expect(new Set(actual).size).toBe(actual.length);
});
});