mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 11:30:43 +00:00
test: narrow hotspot mocks
This commit is contained in:
@@ -21,27 +21,30 @@ printf '%s\n' '${escapedOutput}'
|
||||
return { root, cliPath };
|
||||
}
|
||||
|
||||
function resolveVersionFromInstaller(cliPath: string): string {
|
||||
function resolveVersionsFromInstaller(cliPaths: string[]): string[] {
|
||||
const installerPath = path.join(process.cwd(), "scripts", "install.sh");
|
||||
const output = execFileSync(
|
||||
"bash",
|
||||
[
|
||||
"-lc",
|
||||
`source "${installerPath}" >/dev/null 2>&1
|
||||
OPENCLAW_BIN="$FAKE_OPENCLAW_BIN"
|
||||
resolve_openclaw_version`,
|
||||
for openclaw_bin in "$@"; do
|
||||
OPENCLAW_BIN="$openclaw_bin"
|
||||
resolve_openclaw_version
|
||||
done`,
|
||||
"openclaw-version-test",
|
||||
...cliPaths,
|
||||
],
|
||||
{
|
||||
cwd: process.cwd(),
|
||||
encoding: "utf-8",
|
||||
env: {
|
||||
...process.env,
|
||||
FAKE_OPENCLAW_BIN: cliPath,
|
||||
OPENCLAW_INSTALL_SH_NO_RUN: "1",
|
||||
},
|
||||
},
|
||||
);
|
||||
return output.trim();
|
||||
return output.trimEnd().split("\n");
|
||||
}
|
||||
|
||||
function resolveVersionFromInstallerViaStdin(cliPath: string, cwd: string): string {
|
||||
@@ -68,23 +71,15 @@ describe("install.sh version resolution", () => {
|
||||
cleanupTempDirs(tempRoots);
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")(
|
||||
"extracts the semantic version from decorated CLI output",
|
||||
() => {
|
||||
const fixture = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
|
||||
it.runIf(process.platform !== "win32")("parses decorated and raw CLI versions", () => {
|
||||
const decorated = withFakeCli("OpenClaw 2026.3.10 (abcdef0)");
|
||||
const raw = withFakeCli("OpenClaw dev's build");
|
||||
|
||||
expect(resolveVersionFromInstaller(fixture.cliPath)).toBe("2026.3.10");
|
||||
},
|
||||
);
|
||||
|
||||
it.runIf(process.platform !== "win32")(
|
||||
"falls back to raw output when no semantic version is present",
|
||||
() => {
|
||||
const fixture = withFakeCli("OpenClaw dev's build");
|
||||
|
||||
expect(resolveVersionFromInstaller(fixture.cliPath)).toBe("OpenClaw dev's build");
|
||||
},
|
||||
);
|
||||
expect(resolveVersionsFromInstaller([decorated.cliPath, raw.cliPath])).toEqual([
|
||||
"2026.3.10",
|
||||
"OpenClaw dev's build",
|
||||
]);
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")(
|
||||
"does not source version helpers from cwd when installer runs via stdin",
|
||||
|
||||
@@ -38,18 +38,23 @@ const mocks = vi.hoisted(() => ({
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("./batch-embedding-common.js", async () => {
|
||||
const actual = await vi.importActual<typeof import("./batch-embedding-common.js")>(
|
||||
"./batch-embedding-common.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
uploadBatchJsonlFile: mocks.uploadBatchJsonlFile,
|
||||
postJsonWithRetry: mocks.postJsonWithRetry,
|
||||
resolveCompletedBatchResult: mocks.resolveCompletedBatchResult,
|
||||
withRemoteHttpResponse: mocks.withRemoteHttpResponse,
|
||||
};
|
||||
});
|
||||
vi.mock("./batch-upload.js", () => ({
|
||||
uploadBatchJsonlFile: mocks.uploadBatchJsonlFile,
|
||||
}));
|
||||
|
||||
vi.mock("./batch-http.js", () => ({
|
||||
postJsonWithRetry: mocks.postJsonWithRetry,
|
||||
}));
|
||||
|
||||
vi.mock("./batch-status.js", () => ({
|
||||
resolveBatchCompletionFromStatus: vi.fn(),
|
||||
resolveCompletedBatchResult: mocks.resolveCompletedBatchResult,
|
||||
throwIfBatchTerminalFailure: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./remote-http.js", () => ({
|
||||
withRemoteHttpResponse: mocks.withRemoteHttpResponse,
|
||||
}));
|
||||
|
||||
describe("runOpenAiEmbeddingBatches", () => {
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -35,6 +35,21 @@ vi.mock("../../agents/model-auth.js", () => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../../agents/api-key-rotation.js", () => ({
|
||||
collectProviderApiKeysForExecution: (params: { primaryApiKey?: string }) =>
|
||||
params.primaryApiKey ? [params.primaryApiKey] : [],
|
||||
executeWithApiKeyRotation: async <T>(params: {
|
||||
apiKeys: string[];
|
||||
execute: (apiKey: string) => Promise<T>;
|
||||
}) => {
|
||||
const apiKey = params.apiKeys[0];
|
||||
if (!apiKey) {
|
||||
throw new Error('No API keys configured for provider "google".');
|
||||
}
|
||||
return await params.execute(apiKey);
|
||||
},
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useRealTimers();
|
||||
vi.doUnmock("undici");
|
||||
|
||||
Reference in New Issue
Block a user