mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:02:42 +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 fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { setTimeout as delay } from "node:timers/promises";
|
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 { makeTempWorkspace } from "../test-helpers/workspace.js";
|
||||||
import { withEnvAsync } from "../test-utils/env.js";
|
import { withEnvAsync } from "../test-utils/env.js";
|
||||||
import { MINIMAX_API_BASE_URL, MINIMAX_CN_API_BASE_URL } from "./onboard-auth.js";
|
import { MINIMAX_API_BASE_URL, MINIMAX_CN_API_BASE_URL } from "./onboard-auth.js";
|
||||||
@@ -17,6 +17,17 @@ type OnboardEnv = {
|
|||||||
configPath: string;
|
configPath: string;
|
||||||
runtime: NonInteractiveRuntime;
|
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 ensureAuthProfileStore: typeof import("../agents/auth-profiles.js").ensureAuthProfileStore;
|
||||||
let upsertAuthProfile: typeof import("../agents/auth-profiles.js").upsertAuthProfile;
|
let upsertAuthProfile: typeof import("../agents/auth-profiles.js").upsertAuthProfile;
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,14 @@ function isDynamicTemplateSegment(node: ts.Expression): boolean {
|
|||||||
return ts.isTemplateExpression(node);
|
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 {
|
function hasDynamicTmpdirJoin(source: string, filePath = "fixture.ts"): boolean {
|
||||||
|
if (!mightContainDynamicTmpdirJoin(source)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const sourceFile = ts.createSourceFile(
|
const sourceFile = ts.createSourceFile(
|
||||||
filePath,
|
filePath,
|
||||||
source,
|
source,
|
||||||
@@ -138,7 +145,7 @@ describe("temp path guard", () => {
|
|||||||
if (shouldSkip(relativePath)) {
|
if (shouldSkip(relativePath)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const source = await fs.readFile(file, "utf-8");
|
const source = await fs.readFile(file, "utf8");
|
||||||
if (hasDynamicTmpdirJoin(source, relativePath)) {
|
if (hasDynamicTmpdirJoin(source, relativePath)) {
|
||||||
offenders.push(relativePath);
|
offenders.push(relativePath);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user