perf(test): eliminate resetModules via injectable seams

This commit is contained in:
Peter Steinberger
2026-02-13 16:20:31 +00:00
parent a844fb161c
commit b272158fe4
21 changed files with 223 additions and 188 deletions

View File

@@ -82,6 +82,9 @@ export async function resolveCopilotApiToken(params: {
githubToken: string;
env?: NodeJS.ProcessEnv;
fetchImpl?: typeof fetch;
cachePath?: string;
loadJsonFileImpl?: (path: string) => unknown;
saveJsonFileImpl?: (path: string, value: CachedCopilotToken) => void;
}): Promise<{
token: string;
expiresAt: number;
@@ -89,8 +92,10 @@ export async function resolveCopilotApiToken(params: {
baseUrl: string;
}> {
const env = params.env ?? process.env;
const cachePath = resolveCopilotTokenCachePath(env);
const cached = loadJsonFile(cachePath) as CachedCopilotToken | undefined;
const cachePath = params.cachePath?.trim() || resolveCopilotTokenCachePath(env);
const loadJsonFileFn = params.loadJsonFileImpl ?? loadJsonFile;
const saveJsonFileFn = params.saveJsonFileImpl ?? saveJsonFile;
const cached = loadJsonFileFn(cachePath) as CachedCopilotToken | undefined;
if (cached && typeof cached.token === "string" && typeof cached.expiresAt === "number") {
if (isTokenUsable(cached)) {
return {
@@ -121,7 +126,7 @@ export async function resolveCopilotApiToken(params: {
expiresAt: json.expiresAt,
updatedAt: Date.now(),
};
saveJsonFile(cachePath, payload);
saveJsonFileFn(cachePath, payload);
return {
token: payload.token,