test(parallels): batch POSIX provider config

This commit is contained in:
Peter Steinberger
2026-05-01 17:21:13 +01:00
parent d647ba1c6f
commit 4ad29d2d8e
5 changed files with 60 additions and 67 deletions

View File

@@ -12,9 +12,7 @@ import {
parseBoolEnv, parseBoolEnv,
parseMode, parseMode,
parseProvider, parseProvider,
modelTransportConfigJson, modelProviderConfigBatchJson,
providerIdFromModelId,
providerTimeoutConfigJson,
repoRoot, repoRoot,
resolveHostIp, resolveHostIp,
resolveHostPort, resolveHostPort,
@@ -690,22 +688,14 @@ rm -rf /root/.openclaw/test-bad-plugin`);
private verifyLocalTurn(): void { private verifyLocalTurn(): void {
this.guestExec(["openclaw", "models", "set", this.auth.modelId]); this.guestExec(["openclaw", "models", "set", this.auth.modelId]);
const providerId = providerIdFromModelId(this.auth.modelId) || this.options.provider; const modelProviderConfigBatch = modelProviderConfigBatchJson(this.auth.modelId, "linux");
const providerTimeoutConfig = providerTimeoutConfigJson(this.auth.modelId, "linux"); if (modelProviderConfigBatch) {
if (providerTimeoutConfig) { this.guestBash(`provider_config_batch="$(mktemp)"
this.guestBash( cat >"$provider_config_batch" <<'JSON'
`openclaw config set ${shellQuote(`models.providers.${providerId}`)} ${shellQuote( ${modelProviderConfigBatch}
providerTimeoutConfig, JSON
)} --strict-json`, openclaw config set --batch-file "$provider_config_batch" --strict-json
); rm -f "$provider_config_batch"`);
}
const modelTransportConfig = modelTransportConfigJson(this.auth.modelId);
if (modelTransportConfig) {
this.guestBash(
`openclaw config set ${shellQuote(
`agents.defaults.models.${this.auth.modelId}`,
)} ${shellQuote(modelTransportConfig)} --strict-json`,
);
} }
this.guestExec([ this.guestExec([
"openclaw", "openclaw",

View File

@@ -11,9 +11,7 @@ import {
packOpenClaw, packOpenClaw,
parseMode, parseMode,
parseProvider, parseProvider,
modelTransportConfigJson, modelProviderConfigBatchJson,
providerIdFromModelId,
providerTimeoutConfigJson,
resolveHostIp, resolveHostIp,
resolveHostPort, resolveHostPort,
resolveLatestVersion, resolveLatestVersion,
@@ -974,22 +972,16 @@ exit 1`);
private verifyTurn(): void { private verifyTurn(): void {
this.guestExec([guestNode, guestOpenClawEntry, "models", "set", this.auth.modelId]); this.guestExec([guestNode, guestOpenClawEntry, "models", "set", this.auth.modelId]);
const providerId = providerIdFromModelId(this.auth.modelId) || this.options.provider; const modelProviderConfigBatch = modelProviderConfigBatchJson(this.auth.modelId, "macos");
const providerTimeoutConfig = providerTimeoutConfigJson(this.auth.modelId, "macos"); if (modelProviderConfigBatch) {
if (providerTimeoutConfig) { this.guestSh(`provider_config_batch="$(mktemp)"
this.guestSh( cat >"$provider_config_batch" <<'JSON'
`${shellQuote(guestNode)} ${shellQuote(guestOpenClawEntry)} config set ${shellQuote( ${modelProviderConfigBatch}
`models.providers.${providerId}`, JSON
)} ${shellQuote(providerTimeoutConfig)} --strict-json`, ${shellQuote(guestNode)} ${shellQuote(
); guestOpenClawEntry,
} )} config set --batch-file "$provider_config_batch" --strict-json
const modelTransportConfig = modelTransportConfigJson(this.auth.modelId); rm -f "$provider_config_batch"`);
if (modelTransportConfig) {
this.guestSh(
`${shellQuote(guestNode)} ${shellQuote(guestOpenClawEntry)} config set ${shellQuote(
`agents.defaults.models.${this.auth.modelId}`,
)} ${shellQuote(modelTransportConfig)} --strict-json`,
);
} }
this.guestExec([ this.guestExec([
guestNode, guestNode,

View File

@@ -5,11 +5,7 @@ import {
windowsModelProviderTimeoutScript, windowsModelProviderTimeoutScript,
windowsOpenClawResolver, windowsOpenClawResolver,
} from "./powershell.ts"; } from "./powershell.ts";
import { import { modelProviderConfigBatchJson } from "./provider-auth.ts";
modelTransportConfigJson,
providerIdFromModelId,
providerTimeoutConfigJson,
} from "./provider-auth.ts";
import type { Platform, ProviderAuth } from "./types.ts"; import type { Platform, ProviderAuth } from "./types.ts";
export interface NpmUpdateScriptInput { export interface NpmUpdateScriptInput {
@@ -23,25 +19,20 @@ function posixModelProviderConfigCommands(
modelId: string, modelId: string,
platform: Platform, platform: Platform,
): string { ): string {
const commands: string[] = []; const batchJson = modelProviderConfigBatchJson(modelId, platform);
const providerId = providerIdFromModelId(modelId); if (!batchJson) {
const configJson = providerTimeoutConfigJson(modelId, platform); return "";
if (providerId && configJson) {
commands.push(
`${command} config set ${shellQuote(`models.providers.${providerId}`)} ${shellQuote(
configJson,
)} --strict-json`,
);
} }
const transportJson = modelTransportConfigJson(modelId); return `provider_config_batch="$(mktemp)"
if (transportJson) { cat >"$provider_config_batch" <<'JSON'
commands.push( ${batchJson}
`${command} config set ${shellQuote(`agents.defaults.models.${modelId}`)} ${shellQuote( JSON
transportJson, set +e
)} --strict-json`, ${command} config set --batch-file "$provider_config_batch" --strict-json
); provider_config_exit=$?
} set -e
return commands.join("\n"); rm -f "$provider_config_batch"
if [ "$provider_config_exit" -ne 0 ]; then exit "$provider_config_exit"; fi`;
} }
function posixAssertAgentOkScript(command: string, input: NpmUpdateScriptInput, sessionId: string) { function posixAssertAgentOkScript(command: string, input: NpmUpdateScriptInput, sessionId: string) {

View File

@@ -122,6 +122,26 @@ export function modelTransportConfigJson(modelId: string): string {
}); });
} }
export function modelProviderConfigBatchJson(modelId: string, platform: Platform): string {
const commands: Array<{ path: string; value: unknown }> = [];
const providerId = providerIdFromModelId(modelId);
const providerConfig = providerTimeoutConfigJson(modelId, platform);
if (providerId && providerConfig) {
commands.push({
path: `models.providers.${providerId}`,
value: JSON.parse(providerConfig) as unknown,
});
}
const modelTransportConfig = modelTransportConfigJson(modelId);
if (modelTransportConfig) {
commands.push({
path: `agents.defaults.models.${modelId}`,
value: JSON.parse(modelTransportConfig) as unknown,
});
}
return commands.length === 0 ? "" : JSON.stringify(commands);
}
export function parseProvider(value: string): Provider { export function parseProvider(value: string): Provider {
if (value === "openai" || value === "anthropic" || value === "minimax") { if (value === "openai" || value === "anthropic" || value === "minimax") {
return value; return value;

View File

@@ -321,10 +321,10 @@ console.log(JSON.stringify(result));
expect(script, scriptPath).toContain("minimal"); expect(script, scriptPath).toContain("minimal");
expect(script, scriptPath).toContain("finalAssistant(Raw|Visible)Text"); expect(script, scriptPath).toContain("finalAssistant(Raw|Visible)Text");
} }
expect(readFileSync(TS_PATHS.macos, "utf8")).toContain("providerTimeoutConfigJson"); expect(readFileSync(TS_PATHS.macos, "utf8")).toContain("modelProviderConfigBatchJson");
expect(readFileSync(TS_PATHS.macos, "utf8")).toContain("modelTransportConfigJson"); expect(readFileSync(TS_PATHS.macos, "utf8")).toContain("config set --batch-file");
expect(readFileSync(TS_PATHS.linux, "utf8")).toContain("providerTimeoutConfigJson"); expect(readFileSync(TS_PATHS.linux, "utf8")).toContain("modelProviderConfigBatchJson");
expect(readFileSync(TS_PATHS.linux, "utf8")).toContain("modelTransportConfigJson"); expect(readFileSync(TS_PATHS.linux, "utf8")).toContain("config set --batch-file");
expect(readFileSync(TS_PATHS.windows, "utf8")).toContain("windowsModelProviderTimeoutScript"); expect(readFileSync(TS_PATHS.windows, "utf8")).toContain("windowsModelProviderTimeoutScript");
expect(readFileSync(TS_PATHS.powershell, "utf8")).toContain("config set --batch-file"); expect(readFileSync(TS_PATHS.powershell, "utf8")).toContain("config set --batch-file");
@@ -336,8 +336,8 @@ console.log(JSON.stringify(result));
expect(npmUpdateScripts).toContain("finalAssistant(Raw|Visible)Text"); expect(npmUpdateScripts).toContain("finalAssistant(Raw|Visible)Text");
expect(npmUpdateScripts).toContain("posixAssertAgentOkScript"); expect(npmUpdateScripts).toContain("posixAssertAgentOkScript");
expect(npmUpdateScripts).toContain("windowsModelProviderTimeoutScript"); expect(npmUpdateScripts).toContain("windowsModelProviderTimeoutScript");
expect(npmUpdateScripts).toContain("modelTransportConfigJson"); expect(npmUpdateScripts).toContain("modelProviderConfigBatchJson");
expect(npmUpdateScripts).toContain("agents.defaults.models.${modelId}"); expect(npmUpdateScripts).toContain("config set --batch-file");
}); });
it("clears phase timers and applies phase deadlines to guest commands", () => { it("clears phase timers and applies phase deadlines to guest commands", () => {