mirror of
https://github.com/Heretek-AI/openclaw.git
synced 2026-08-27 09:01:15 -04:00
fix: replace os.tmpdir() with resolvePreferredOpenClawTmpDir() fallback
Fix os.tmpdir() usage in 7 extension test files. Files: nostr-state-store.test.ts, remote-fs-bridge.test.ts, fs-bridge.test.ts, accounts.test.ts, replay-guard.test.ts, outbound.test.ts, config.test.ts (3 occurrences).
This commit is contained in:
@@ -3,6 +3,7 @@ import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { pathToFileURL } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../../../../src/infra/tmp-openclaw-dir.js";
|
||||
import {
|
||||
ACPX_BUNDLED_BIN,
|
||||
ACPX_PINNED_VERSION,
|
||||
@@ -13,7 +14,9 @@ import {
|
||||
|
||||
describe("acpx plugin config parsing", () => {
|
||||
it("resolves source-layout plugin root from a file under src", () => {
|
||||
const pluginRoot = fs.mkdtempSync(path.join(os.tmpdir(), "acpx-root-source-"));
|
||||
const pluginRoot = fs.mkdtempSync(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "acpx-root-source-"),
|
||||
);
|
||||
try {
|
||||
fs.mkdirSync(path.join(pluginRoot, "src"), { recursive: true });
|
||||
fs.writeFileSync(path.join(pluginRoot, "package.json"), "{}\n", "utf8");
|
||||
@@ -27,7 +30,9 @@ describe("acpx plugin config parsing", () => {
|
||||
});
|
||||
|
||||
it("resolves bundled-layout plugin root from the dist entry file", () => {
|
||||
const pluginRoot = fs.mkdtempSync(path.join(os.tmpdir(), "acpx-root-dist-"));
|
||||
const pluginRoot = fs.mkdtempSync(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "acpx-root-dist-"),
|
||||
);
|
||||
try {
|
||||
fs.writeFileSync(path.join(pluginRoot, "package.json"), "{}\n", "utf8");
|
||||
fs.writeFileSync(path.join(pluginRoot, "openclaw.plugin.json"), "{}\n", "utf8");
|
||||
@@ -40,7 +45,9 @@ describe("acpx plugin config parsing", () => {
|
||||
});
|
||||
|
||||
it("prefers the workspace plugin root for dist/extensions/acpx bundles", () => {
|
||||
const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), "acpx-root-workspace-"));
|
||||
const repoRoot = fs.mkdtempSync(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "acpx-root-workspace-"),
|
||||
);
|
||||
const workspacePluginRoot = path.join(repoRoot, "extensions", "acpx");
|
||||
const bundledPluginRoot = path.join(repoRoot, "dist", "extensions", "acpx");
|
||||
try {
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../../../../src/infra/tmp-openclaw-dir.js";
|
||||
|
||||
const sendMediaFeishuMock = vi.hoisted(() => vi.fn());
|
||||
const sendMessageFeishuMock = vi.hoisted(() => vi.fn());
|
||||
@@ -45,7 +46,9 @@ describe("feishuOutbound.sendText local-image auto-convert", () => {
|
||||
});
|
||||
|
||||
async function createTmpImage(ext = ".png"): Promise<{ dir: string; file: string }> {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-feishu-outbound-"));
|
||||
const dir = await fs.mkdtemp(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "openclaw-feishu-outbound-"),
|
||||
);
|
||||
const file = path.join(dir, `sample${ext}`);
|
||||
await fs.writeFile(file, "image-data");
|
||||
return { dir, file };
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../../../../src/infra/tmp-openclaw-dir.js";
|
||||
import { resolveNextcloudTalkAccount } from "./accounts.js";
|
||||
import type { CoreConfig } from "./types.js";
|
||||
|
||||
@@ -30,7 +31,9 @@ describe("resolveNextcloudTalkAccount", () => {
|
||||
});
|
||||
|
||||
it.runIf(process.platform !== "win32")("rejects symlinked botSecretFile paths", () => {
|
||||
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-nextcloud-talk-"));
|
||||
const dir = fs.mkdtempSync(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "openclaw-nextcloud-talk-"),
|
||||
);
|
||||
const secretFile = path.join(dir, "secret.txt");
|
||||
const secretLink = path.join(dir, "secret-link.txt");
|
||||
fs.writeFileSync(secretFile, "bot-secret\n", "utf8");
|
||||
|
||||
@@ -2,6 +2,7 @@ import { mkdtemp, rm } from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../../../../src/infra/tmp-openclaw-dir.js";
|
||||
import { createNextcloudTalkReplayGuard } from "./replay-guard.js";
|
||||
|
||||
const tempDirs: string[] = [];
|
||||
@@ -16,7 +17,9 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
async function makeTempDir(): Promise<string> {
|
||||
const dir = await mkdtemp(path.join(os.tmpdir(), "nextcloud-talk-replay-"));
|
||||
const dir = await mkdtemp(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "nextcloud-talk-replay-"),
|
||||
);
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../../../../src/infra/tmp-openclaw-dir.js";
|
||||
import type { PluginRuntime } from "../runtime-api.js";
|
||||
import {
|
||||
readNostrBusState,
|
||||
@@ -12,7 +13,9 @@ import { setNostrRuntime } from "./runtime.js";
|
||||
|
||||
async function withTempStateDir<T>(fn: (dir: string) => Promise<T>) {
|
||||
const previous = process.env.OPENCLAW_STATE_DIR;
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-nostr-"));
|
||||
const dir = await fs.mkdtemp(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "openclaw-nostr-"),
|
||||
);
|
||||
process.env.OPENCLAW_STATE_DIR = dir;
|
||||
setNostrRuntime({
|
||||
state: {
|
||||
|
||||
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../../../../src/infra/tmp-openclaw-dir.js";
|
||||
import { createSandboxTestContext } from "../../../src/agents/sandbox/test-fixtures.js";
|
||||
import type { OpenShellSandboxBackend } from "./backend.js";
|
||||
import { createOpenShellFsBridge } from "./fs-bridge.js";
|
||||
@@ -9,7 +10,9 @@ import { createOpenShellFsBridge } from "./fs-bridge.js";
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
async function makeTempDir() {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-openshell-fs-"));
|
||||
const dir = await fs.mkdtemp(
|
||||
path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), "openclaw-openshell-fs-"),
|
||||
);
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { resolvePreferredOpenClawTmpDir } from "../../../../src/infra/tmp-openclaw-dir.js";
|
||||
import { createSandboxTestContext } from "../../../src/agents/sandbox/test-fixtures.js";
|
||||
import type { OpenShellSandboxBackend } from "./backend.js";
|
||||
import { createOpenShellRemoteFsBridge } from "./remote-fs-bridge.js";
|
||||
@@ -10,7 +11,7 @@ import { createOpenShellRemoteFsBridge } from "./remote-fs-bridge.js";
|
||||
const tempDirs: string[] = [];
|
||||
|
||||
async function makeTempDir(prefix: string) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
||||
const dir = await fs.mkdtemp(path.join(resolvePreferredOpenClawTmpDir() ?? os.tmpdir(), prefix));
|
||||
tempDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user