mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 06:41:22 +00:00
refactor(test): dedupe copilot env restores
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
|
import { captureEnv } from "../test-utils/env.js";
|
||||||
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
import { resolveOpenClawAgentDir } from "./agent-paths.js";
|
||||||
import {
|
import {
|
||||||
installModelsConfigTestHooks,
|
installModelsConfigTestHooks,
|
||||||
@@ -13,9 +14,7 @@ installModelsConfigTestHooks({ restoreFetch: true });
|
|||||||
describe("models-config", () => {
|
describe("models-config", () => {
|
||||||
it("uses the first github-copilot profile when env tokens are missing", async () => {
|
it("uses the first github-copilot profile when env tokens are missing", async () => {
|
||||||
await withTempHome(async (home) => {
|
await withTempHome(async (home) => {
|
||||||
const previous = process.env.COPILOT_GITHUB_TOKEN;
|
const envSnapshot = captureEnv(["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"]);
|
||||||
const previousGh = process.env.GH_TOKEN;
|
|
||||||
const previousGithub = process.env.GITHUB_TOKEN;
|
|
||||||
delete process.env.COPILOT_GITHUB_TOKEN;
|
delete process.env.COPILOT_GITHUB_TOKEN;
|
||||||
delete process.env.GH_TOKEN;
|
delete process.env.GH_TOKEN;
|
||||||
delete process.env.GITHUB_TOKEN;
|
delete process.env.GITHUB_TOKEN;
|
||||||
@@ -61,28 +60,14 @@ describe("models-config", () => {
|
|||||||
const [, opts] = fetchMock.mock.calls[0] as [string, { headers?: Record<string, string> }];
|
const [, opts] = fetchMock.mock.calls[0] as [string, { headers?: Record<string, string> }];
|
||||||
expect(opts?.headers?.Authorization).toBe("Bearer alpha-token");
|
expect(opts?.headers?.Authorization).toBe("Bearer alpha-token");
|
||||||
} finally {
|
} finally {
|
||||||
if (previous === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.COPILOT_GITHUB_TOKEN;
|
|
||||||
} else {
|
|
||||||
process.env.COPILOT_GITHUB_TOKEN = previous;
|
|
||||||
}
|
|
||||||
if (previousGh === undefined) {
|
|
||||||
delete process.env.GH_TOKEN;
|
|
||||||
} else {
|
|
||||||
process.env.GH_TOKEN = previousGh;
|
|
||||||
}
|
|
||||||
if (previousGithub === undefined) {
|
|
||||||
delete process.env.GITHUB_TOKEN;
|
|
||||||
} else {
|
|
||||||
process.env.GITHUB_TOKEN = previousGithub;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not override explicit github-copilot provider config", async () => {
|
it("does not override explicit github-copilot provider config", async () => {
|
||||||
await withTempHome(async () => {
|
await withTempHome(async () => {
|
||||||
const previous = process.env.COPILOT_GITHUB_TOKEN;
|
const envSnapshot = captureEnv(["COPILOT_GITHUB_TOKEN"]);
|
||||||
process.env.COPILOT_GITHUB_TOKEN = "gh-token";
|
process.env.COPILOT_GITHUB_TOKEN = "gh-token";
|
||||||
const fetchMock = vi.fn().mockResolvedValue({
|
const fetchMock = vi.fn().mockResolvedValue({
|
||||||
ok: true,
|
ok: true,
|
||||||
@@ -115,11 +100,7 @@ describe("models-config", () => {
|
|||||||
|
|
||||||
expect(parsed.providers["github-copilot"]?.baseUrl).toBe("https://copilot.local");
|
expect(parsed.providers["github-copilot"]?.baseUrl).toBe("https://copilot.local");
|
||||||
} finally {
|
} finally {
|
||||||
if (previous === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.COPILOT_GITHUB_TOKEN;
|
|
||||||
} else {
|
|
||||||
process.env.COPILOT_GITHUB_TOKEN = previous;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user