mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:38:25 +00:00
test(models): dedupe auth-sync command assertions
This commit is contained in:
@@ -68,6 +68,17 @@ function getProviderRow(payloadText: string, providerPrefix: string) {
|
|||||||
return payload.models?.find((model) => String(model.key ?? "").startsWith(providerPrefix));
|
return payload.models?.find((model) => String(model.key ?? "").startsWith(providerPrefix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function runModelsListAndGetProvider(providerPrefix: string) {
|
||||||
|
const runtime = createRuntime();
|
||||||
|
await modelsListCommand({ all: true, json: true }, runtime as never);
|
||||||
|
|
||||||
|
expect(runtime.error).not.toHaveBeenCalled();
|
||||||
|
expect(runtime.log).toHaveBeenCalledTimes(1);
|
||||||
|
const provider = getProviderRow(String(runtime.log.mock.calls[0]?.[0]), providerPrefix);
|
||||||
|
expect(provider).toBeDefined();
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
describe("models list auth-profile sync", () => {
|
describe("models list auth-profile sync", () => {
|
||||||
it("marks models available when auth exists only in auth-profiles.json", async () => {
|
it("marks models available when auth exists only in auth-profiles.json", async () => {
|
||||||
await withAuthSyncFixture(async ({ agentDir, authPath }) => {
|
await withAuthSyncFixture(async ({ agentDir, authPath }) => {
|
||||||
@@ -87,13 +98,7 @@ describe("models list auth-profile sync", () => {
|
|||||||
|
|
||||||
expect(await pathExists(authPath)).toBe(false);
|
expect(await pathExists(authPath)).toBe(false);
|
||||||
|
|
||||||
const runtime = createRuntime();
|
const openrouter = await runModelsListAndGetProvider("openrouter/");
|
||||||
await modelsListCommand({ all: true, json: true }, runtime as never);
|
|
||||||
|
|
||||||
expect(runtime.error).not.toHaveBeenCalled();
|
|
||||||
expect(runtime.log).toHaveBeenCalledTimes(1);
|
|
||||||
const openrouter = getProviderRow(String(runtime.log.mock.calls[0]?.[0]), "openrouter/");
|
|
||||||
expect(openrouter).toBeDefined();
|
|
||||||
expect(openrouter?.available).toBe(true);
|
expect(openrouter?.available).toBe(true);
|
||||||
expect(await pathExists(authPath)).toBe(true);
|
expect(await pathExists(authPath)).toBe(true);
|
||||||
});
|
});
|
||||||
@@ -115,11 +120,7 @@ describe("models list auth-profile sync", () => {
|
|||||||
agentDir,
|
agentDir,
|
||||||
);
|
);
|
||||||
|
|
||||||
const runtime = createRuntime();
|
await runModelsListAndGetProvider("openrouter/");
|
||||||
await modelsListCommand({ all: true, json: true }, runtime as never);
|
|
||||||
|
|
||||||
expect(runtime.error).not.toHaveBeenCalled();
|
|
||||||
expect(runtime.log).toHaveBeenCalledTimes(1);
|
|
||||||
if (await pathExists(authPath)) {
|
if (await pathExists(authPath)) {
|
||||||
const parsed = JSON.parse(await fs.readFile(authPath, "utf8")) as Record<
|
const parsed = JSON.parse(await fs.readFile(authPath, "utf8")) as Record<
|
||||||
string,
|
string,
|
||||||
|
|||||||
Reference in New Issue
Block a user