refactor(agent): dedupe harness and command workflows

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:09 +00:00
parent 04892ee230
commit f717a13039
204 changed files with 7366 additions and 11540 deletions

View File

@@ -18,6 +18,12 @@ type OnboardEnv = {
runtime: RuntimeMock;
};
type ProviderAuthConfigSnapshot = {
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
agents?: { defaults?: { model?: { primary?: string } } };
models?: { providers?: Record<string, { baseUrl?: string }> };
};
async function removeDirWithRetry(dir: string): Promise<void> {
for (let attempt = 0; attempt < 5; attempt += 1) {
try {
@@ -93,10 +99,86 @@ async function runNonInteractive(
await runNonInteractiveOnboarding(options, runtime);
}
async function runNonInteractiveWithDefaults(
runtime: RuntimeMock,
options: Record<string, unknown>,
): Promise<void> {
await runNonInteractive(
{
nonInteractive: true,
skipHealth: true,
skipChannels: true,
json: true,
...options,
},
runtime,
);
}
async function readJsonFile<T>(filePath: string): Promise<T> {
return JSON.parse(await fs.readFile(filePath, "utf8")) as T;
}
async function runApiKeyOnboardingAndReadConfig(
env: OnboardEnv,
options: Record<string, unknown>,
): Promise<ProviderAuthConfigSnapshot> {
await runNonInteractiveWithDefaults(env.runtime, {
skipSkills: true,
...options,
});
return readJsonFile<ProviderAuthConfigSnapshot>(env.configPath);
}
async function runInferredApiKeyOnboardingAndReadConfig(
env: OnboardEnv,
options: Record<string, unknown>,
): Promise<ProviderAuthConfigSnapshot> {
await runNonInteractive(
{
nonInteractive: true,
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
...options,
},
env.runtime,
);
return readJsonFile<ProviderAuthConfigSnapshot>(env.configPath);
}
const CUSTOM_LOCAL_BASE_URL = "https://models.custom.local/v1";
const CUSTOM_LOCAL_MODEL_ID = "local-large";
const CUSTOM_LOCAL_PROVIDER_ID = "custom-models-custom-local";
async function runCustomLocalNonInteractive(
runtime: RuntimeMock,
overrides: Record<string, unknown> = {},
): Promise<void> {
await runNonInteractiveWithDefaults(runtime, {
authChoice: "custom-api-key",
customBaseUrl: CUSTOM_LOCAL_BASE_URL,
customModelId: CUSTOM_LOCAL_MODEL_ID,
skipSkills: true,
...overrides,
});
}
async function readCustomLocalProviderApiKey(configPath: string): Promise<string | undefined> {
const cfg = await readJsonFile<{
models?: {
providers?: Record<
string,
{
apiKey?: string;
}
>;
};
}>(configPath);
return cfg.models?.providers?.[CUSTOM_LOCAL_PROVIDER_ID]?.apiKey;
}
async function expectApiKeyProfile(params: {
profileId: string;
provider: string;
@@ -118,25 +200,11 @@ async function expectApiKeyProfile(params: {
describe("onboard (non-interactive): provider auth", () => {
it("stores MiniMax API key and uses global baseUrl by default", async () => {
await withOnboardEnv("openclaw-onboard-minimax-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
authChoice: "minimax-api",
minimaxApiKey: "sk-minimax-test",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
agents?: { defaults?: { model?: { primary?: string } } };
models?: { providers?: Record<string, { baseUrl?: string }> };
}>(configPath);
await withOnboardEnv("openclaw-onboard-minimax-", async (env) => {
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
authChoice: "minimax-api",
minimaxApiKey: "sk-minimax-test",
});
expect(cfg.auth?.profiles?.["minimax:default"]?.provider).toBe("minimax");
expect(cfg.auth?.profiles?.["minimax:default"]?.mode).toBe("api_key");
@@ -151,25 +219,11 @@ describe("onboard (non-interactive): provider auth", () => {
}, 60_000);
it("supports MiniMax CN API endpoint auth choice", async () => {
await withOnboardEnv("openclaw-onboard-minimax-cn-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
authChoice: "minimax-api-key-cn",
minimaxApiKey: "sk-minimax-test",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
agents?: { defaults?: { model?: { primary?: string } } };
models?: { providers?: Record<string, { baseUrl?: string }> };
}>(configPath);
await withOnboardEnv("openclaw-onboard-minimax-cn-", async (env) => {
const cfg = await runApiKeyOnboardingAndReadConfig(env, {
authChoice: "minimax-api-key-cn",
minimaxApiKey: "sk-minimax-test",
});
expect(cfg.auth?.profiles?.["minimax-cn:default"]?.provider).toBe("minimax-cn");
expect(cfg.auth?.profiles?.["minimax-cn:default"]?.mode).toBe("api_key");
@@ -185,18 +239,11 @@ describe("onboard (non-interactive): provider auth", () => {
it("stores Z.AI API key and uses global baseUrl by default", async () => {
await withOnboardEnv("openclaw-onboard-zai-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
authChoice: "zai-api-key",
zaiApiKey: "zai-test-key",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
await runNonInteractiveWithDefaults(runtime, {
authChoice: "zai-api-key",
zaiApiKey: "zai-test-key",
skipSkills: true,
});
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
@@ -214,18 +261,11 @@ describe("onboard (non-interactive): provider auth", () => {
it("supports Z.AI CN coding endpoint auth choice", async () => {
await withOnboardEnv("openclaw-onboard-zai-cn-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
authChoice: "zai-coding-cn",
zaiApiKey: "zai-test-key",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
await runNonInteractiveWithDefaults(runtime, {
authChoice: "zai-coding-cn",
zaiApiKey: "zai-test-key",
skipSkills: true,
});
const cfg = await readJsonFile<{
models?: { providers?: Record<string, { baseUrl?: string }> };
@@ -240,18 +280,11 @@ describe("onboard (non-interactive): provider auth", () => {
it("stores xAI API key and sets default model", async () => {
await withOnboardEnv("openclaw-onboard-xai-", async ({ configPath, runtime }) => {
const rawKey = "xai-test-\r\nkey";
await runNonInteractive(
{
nonInteractive: true,
authChoice: "xai-api-key",
xaiApiKey: rawKey,
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
await runNonInteractiveWithDefaults(runtime, {
authChoice: "xai-api-key",
xaiApiKey: rawKey,
skipSkills: true,
});
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
@@ -267,18 +300,11 @@ describe("onboard (non-interactive): provider auth", () => {
it("stores Vercel AI Gateway API key and sets default model", async () => {
await withOnboardEnv("openclaw-onboard-ai-gateway-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
authChoice: "ai-gateway-api-key",
aiGatewayApiKey: "gateway-test-key",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
await runNonInteractiveWithDefaults(runtime, {
authChoice: "ai-gateway-api-key",
aiGatewayApiKey: "gateway-test-key",
skipSkills: true,
});
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
@@ -303,19 +329,12 @@ describe("onboard (non-interactive): provider auth", () => {
const cleanToken = `sk-ant-oat01-${"a".repeat(80)}`;
const token = `${cleanToken.slice(0, 30)}\r${cleanToken.slice(30)}`;
await runNonInteractive(
{
nonInteractive: true,
authChoice: "token",
tokenProvider: "anthropic",
token,
tokenProfileId: "anthropic:default",
skipHealth: true,
skipChannels: true,
json: true,
},
runtime,
);
await runNonInteractiveWithDefaults(runtime, {
authChoice: "token",
tokenProvider: "anthropic",
token,
tokenProfileId: "anthropic:default",
});
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
@@ -337,18 +356,11 @@ describe("onboard (non-interactive): provider auth", () => {
it("stores OpenAI API key and sets OpenAI default model", async () => {
await withOnboardEnv("openclaw-onboard-openai-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
authChoice: "openai-api-key",
openaiApiKey: "sk-openai-test",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
await runNonInteractiveWithDefaults(runtime, {
authChoice: "openai-api-key",
openaiApiKey: "sk-openai-test",
skipSkills: true,
});
const cfg = await readJsonFile<{
agents?: { defaults?: { model?: { primary?: string } } };
@@ -361,35 +373,21 @@ describe("onboard (non-interactive): provider auth", () => {
it("rejects vLLM auth choice in non-interactive mode", async () => {
await withOnboardEnv("openclaw-onboard-vllm-non-interactive-", async ({ runtime }) => {
await expect(
runNonInteractive(
{
nonInteractive: true,
authChoice: "vllm",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
),
runNonInteractiveWithDefaults(runtime, {
authChoice: "vllm",
skipSkills: true,
}),
).rejects.toThrow('Auth choice "vllm" requires interactive mode.');
});
}, 60_000);
it("stores LiteLLM API key and sets default model", async () => {
await withOnboardEnv("openclaw-onboard-litellm-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
authChoice: "litellm-api-key",
litellmApiKey: "litellm-test-key",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
await runNonInteractiveWithDefaults(runtime, {
authChoice: "litellm-api-key",
litellmApiKey: "litellm-test-key",
skipSkills: true,
});
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
@@ -463,23 +461,10 @@ describe("onboard (non-interactive): provider auth", () => {
);
it("infers Together auth choice from --together-api-key and sets default model", async () => {
await withOnboardEnv("openclaw-onboard-together-infer-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
togetherApiKey: "together-test-key",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
agents?: { defaults?: { model?: { primary?: string } } };
}>(configPath);
await withOnboardEnv("openclaw-onboard-together-infer-", async (env) => {
const cfg = await runInferredApiKeyOnboardingAndReadConfig(env, {
togetherApiKey: "together-test-key",
});
expect(cfg.auth?.profiles?.["together:default"]?.provider).toBe("together");
expect(cfg.auth?.profiles?.["together:default"]?.mode).toBe("api_key");
@@ -493,23 +478,10 @@ describe("onboard (non-interactive): provider auth", () => {
}, 60_000);
it("infers QIANFAN auth choice from --qianfan-api-key and sets default model", async () => {
await withOnboardEnv("openclaw-onboard-qianfan-infer-", async ({ configPath, runtime }) => {
await runNonInteractive(
{
nonInteractive: true,
qianfanApiKey: "qianfan-test-key",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
const cfg = await readJsonFile<{
auth?: { profiles?: Record<string, { provider?: string; mode?: string }> };
agents?: { defaults?: { model?: { primary?: string } } };
}>(configPath);
await withOnboardEnv("openclaw-onboard-qianfan-infer-", async (env) => {
const cfg = await runInferredApiKeyOnboardingAndReadConfig(env, {
qianfanApiKey: "qianfan-test-key",
});
expect(cfg.auth?.profiles?.["qianfan:default"]?.provider).toBe("qianfan");
expect(cfg.auth?.profiles?.["qianfan:default"]?.mode).toBe("api_key");
@@ -611,35 +583,8 @@ describe("onboard (non-interactive): provider auth", () => {
"openclaw-onboard-custom-provider-env-fallback-",
async ({ configPath, runtime }) => {
process.env.CUSTOM_API_KEY = "custom-env-key";
await runNonInteractive(
{
nonInteractive: true,
authChoice: "custom-api-key",
customBaseUrl: "https://models.custom.local/v1",
customModelId: "local-large",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
const cfg = await readJsonFile<{
models?: {
providers?: Record<
string,
{
apiKey?: string;
}
>;
};
}>(configPath);
expect(cfg.models?.providers?.["custom-models-custom-local"]?.apiKey).toBe(
"custom-env-key",
);
await runCustomLocalNonInteractive(runtime);
expect(await readCustomLocalProviderApiKey(configPath)).toBe("custom-env-key");
},
);
}, 60_000);
@@ -650,42 +595,15 @@ describe("onboard (non-interactive): provider auth", () => {
async ({ configPath, runtime }) => {
const { upsertAuthProfile } = await import("../agents/auth-profiles.js");
upsertAuthProfile({
profileId: "custom-models-custom-local:default",
profileId: `${CUSTOM_LOCAL_PROVIDER_ID}:default`,
credential: {
type: "api_key",
provider: "custom-models-custom-local",
provider: CUSTOM_LOCAL_PROVIDER_ID,
key: "custom-profile-key",
},
});
await runNonInteractive(
{
nonInteractive: true,
authChoice: "custom-api-key",
customBaseUrl: "https://models.custom.local/v1",
customModelId: "local-large",
skipHealth: true,
skipChannels: true,
skipSkills: true,
json: true,
},
runtime,
);
const cfg = await readJsonFile<{
models?: {
providers?: Record<
string,
{
apiKey?: string;
}
>;
};
}>(configPath);
expect(cfg.models?.providers?.["custom-models-custom-local"]?.apiKey).toBe(
"custom-profile-key",
);
await runCustomLocalNonInteractive(runtime);
expect(await readCustomLocalProviderApiKey(configPath)).toBe("custom-profile-key");
},
);
}, 60_000);