Skip to content

Commit 3042a19

Browse files
committed
fix(tests): align plugin temp-dir and registry tests with current contracts
1 parent e7365d4 commit 3042a19

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

src/plugins/git-install.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { redactSensitiveUrlLikeString } from "@openclaw/net-policy/redact-sensit
77
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
88
import { useAutoCleanupTempDirTracker } from "../../test/helpers/temp-dir.js";
99
import type { DiagnosticSecurityEvent } from "../infra/diagnostic-events.js";
10+
import { resolvePreferredOpenClawTmpDir } from "../infra/tmp-openclaw-dir.js";
1011

1112
const runCommandWithTimeoutMock = vi.fn();
1213
const installPluginFromInstalledPackageDirMock = vi.fn();
@@ -531,7 +532,7 @@ describe("installPluginFromGitSpec", () => {
531532
}
532533
});
533534

534-
it("falls back to OS temp when target workspace creation fails", async () => {
535+
it("falls back to the OpenClaw temp root when target workspace creation fails", async () => {
535536
const gitDir = trackedTempDirs.make("openclaw-git-install-stage-fallback-");
536537
runCommandWithTimeoutMock
537538
.mockResolvedValueOnce({ code: 0, stdout: "", stderr: "" })
@@ -568,7 +569,12 @@ describe("installPluginFromGitSpec", () => {
568569
normalizedSpec: "git:https://github.com/acme/demo.git",
569570
});
570571
expect(path.dirname(targetPrefix)).toBe(await fs.realpath(path.dirname(persistentRepoDir)));
571-
expect(path.dirname(fallbackPrefix)).toBe(await fs.realpath(os.tmpdir()));
572+
// withTempDir roots fallback staging at resolvePreferredOpenClawTmpDir(), which
573+
// prefers /tmp/openclaw and only degrades to a uid-scoped os.tmpdir path when
574+
// that is unsafe. Recompute it here so the assertion holds on every host.
575+
expect(path.dirname(fallbackPrefix)).toBe(
576+
await fs.realpath(resolvePreferredOpenClawTmpDir()),
577+
);
572578
expect(runCommandWithTimeoutMock).toHaveBeenCalledTimes(3);
573579
} finally {
574580
mkdtempSpy.mockRestore();

src/plugins/manifest-model-id-normalization.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,14 @@ describe("manifest model id normalization", () => {
338338

339339
const readFileSyncSpy = vi.spyOn(fs, "readFileSync");
340340

341-
expect(listOpenClawPluginManifestMetadata(process.env)).toHaveLength(1);
342-
expect(listOpenClawPluginManifestMetadata(process.env)).toHaveLength(1);
341+
// The scan also lists source-checkout extensions/ manifests when tests run
342+
// from a repo checkout, so only pin the record for the plugin under test.
343+
const listNormalizerRecords = () =>
344+
listOpenClawPluginManifestMetadata(process.env).filter(
345+
(record) => record.pluginDir === pluginDir,
346+
);
347+
expect(listNormalizerRecords()).toHaveLength(1);
348+
expect(listNormalizerRecords()).toHaveLength(1);
343349

344350
const manifestReads = readFileSyncSpy.mock.calls.filter(
345351
([filePath]) => String(filePath) === manifestPath,

src/plugins/tools.optional.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { DEFAULT_PLUGIN_TOOLS_ALLOWLIST_ENTRY } from "../agents/tool-policy.js";
44
import { resetLogger, setLoggerOverride } from "../logging/logger.js";
55
import { loggingState } from "../logging/state.js";
66
import { resolveInstalledPluginIndexPolicyHash } from "./installed-plugin-index-policy.js";
7+
import { createEmptyPluginRegistry } from "./registry-empty.js";
78

89
type MockRegistryToolEntry = {
910
pluginId: string;
@@ -2861,15 +2862,9 @@ describe("resolvePluginTools optional tools", () => {
28612862
});
28622863

28632864
it("reloads when gateway binding would otherwise reuse a default-mode active registry", () => {
2864-
setActivePluginRegistry(
2865-
{
2866-
plugins: [],
2867-
tools: [],
2868-
diagnostics: [],
2869-
} as never,
2870-
"default-registry",
2871-
"default",
2872-
);
2865+
// Retiring an active registry walks all cleanup collections, so the
2866+
// default-mode stand-in must be a fully initialized registry shape.
2867+
setActivePluginRegistry(createEmptyPluginRegistry(), "default-registry", "default");
28732868
setOptionalDemoRegistry();
28742869

28752870
resolvePluginTools({

0 commit comments

Comments
 (0)