mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-25 23:47:20 +00:00
test: speed up onboarding provider auth and temp-path guard scans
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { setTimeout as delay } from "node:timers/promises";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { beforeAll, describe, expect, it, vi } from "vitest";
|
||||
import { makeTempWorkspace } from "../test-helpers/workspace.js";
|
||||
import { withEnvAsync } from "../test-utils/env.js";
|
||||
import { MINIMAX_API_BASE_URL, MINIMAX_CN_API_BASE_URL } from "./onboard-auth.js";
|
||||
@@ -17,6 +17,17 @@ type OnboardEnv = {
|
||||
configPath: string;
|
||||
runtime: NonInteractiveRuntime;
|
||||
};
|
||||
|
||||
const ensureWorkspaceAndSessionsMock = vi.fn(async (..._args: unknown[]) => {});
|
||||
|
||||
vi.mock("./onboard-helpers.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./onboard-helpers.js")>();
|
||||
return {
|
||||
...actual,
|
||||
ensureWorkspaceAndSessions: ensureWorkspaceAndSessionsMock,
|
||||
};
|
||||
});
|
||||
|
||||
let ensureAuthProfileStore: typeof import("../agents/auth-profiles.js").ensureAuthProfileStore;
|
||||
let upsertAuthProfile: typeof import("../agents/auth-profiles.js").upsertAuthProfile;
|
||||
|
||||
|
||||
@@ -44,7 +44,14 @@ function isDynamicTemplateSegment(node: ts.Expression): boolean {
|
||||
return ts.isTemplateExpression(node);
|
||||
}
|
||||
|
||||
function mightContainDynamicTmpdirJoin(source: string): boolean {
|
||||
return source.includes("path.join") && source.includes("os.tmpdir") && source.includes("`");
|
||||
}
|
||||
|
||||
function hasDynamicTmpdirJoin(source: string, filePath = "fixture.ts"): boolean {
|
||||
if (!mightContainDynamicTmpdirJoin(source)) {
|
||||
return false;
|
||||
}
|
||||
const sourceFile = ts.createSourceFile(
|
||||
filePath,
|
||||
source,
|
||||
@@ -138,7 +145,7 @@ describe("temp path guard", () => {
|
||||
if (shouldSkip(relativePath)) {
|
||||
continue;
|
||||
}
|
||||
const source = await fs.readFile(file, "utf-8");
|
||||
const source = await fs.readFile(file, "utf8");
|
||||
if (hasDynamicTmpdirJoin(source, relativePath)) {
|
||||
offenders.push(relativePath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user