test: track ClickClack temporary directories

This commit is contained in:
Shakker
2026-07-15 07:20:17 +01:00
committed by Shakker
parent d54eb4b74d
commit beece7f527
2 changed files with 40 additions and 44 deletions
+19 -21
View File
@@ -1,8 +1,8 @@
// Clickclack tests cover accounts plugin behavior.
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
import {
listClickClackAccountIds,
resolveClickClackAccount,
@@ -10,6 +10,8 @@ import {
} from "./accounts.js";
import type { CoreConfig } from "./types.js";
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
describe("ClickClack account resolution", () => {
afterEach(() => {
vi.unstubAllEnvs();
@@ -149,32 +151,28 @@ describe("ClickClack account resolution", () => {
});
it("reads tokenFile credentials without overriding a named account token", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "clickclack-token-"));
const tempDir = tempDirs.make("clickclack-token-");
const tokenFile = path.join(tempDir, "token");
fs.writeFileSync(tokenFile, " file-token \n", "utf8");
try {
const cfg = {
channels: {
clickclack: {
enabled: true,
baseUrl: "https://app.clickclack.chat",
workspace: "wsp_1",
tokenFile,
accounts: {
work: {
token: "work-token",
},
const cfg = {
channels: {
clickclack: {
enabled: true,
baseUrl: "https://app.clickclack.chat",
workspace: "wsp_1",
tokenFile,
accounts: {
work: {
token: "work-token",
},
},
},
} satisfies CoreConfig;
},
} satisfies CoreConfig;
expect(listClickClackAccountIds(cfg)).toEqual(["default", "work"]);
expect(resolveClickClackAccount({ cfg }).token).toBe("file-token");
expect(resolveClickClackAccount({ cfg, accountId: "work" }).token).toBe("work-token");
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
}
expect(listClickClackAccountIds(cfg)).toEqual(["default", "work"]);
expect(resolveClickClackAccount({ cfg }).token).toBe("file-token");
expect(resolveClickClackAccount({ cfg, accountId: "work" }).token).toBe("work-token");
});
it("resolves model-mode bot account policy", () => {
+21 -23
View File
@@ -1,6 +1,5 @@
// ClickClack tests cover guided setup prompts and nonfatal live validation.
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import {
createPluginSetupWizardConfigure,
@@ -10,6 +9,7 @@ import {
runSetupWizardFinalize,
} from "openclaw/plugin-sdk/plugin-test-runtime";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
const mocks = vi.hoisted(() => ({
me: vi.fn(),
@@ -32,6 +32,8 @@ import { clickClackSetupPlugin } from "./channel.setup.js";
import { clickClackSetupWizard } from "./setup-surface.js";
import type { CoreConfig } from "./types.js";
const tempDirs = useAutoCleanupTempDirTracker(afterEach);
const configuredAccount = {
channels: {
clickclack: {
@@ -103,31 +105,27 @@ describe("ClickClack setup wizard", () => {
envValue: "ccb_env",
});
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "clickclack-setup-token-"));
const tempDir = tempDirs.make("clickclack-setup-token-");
const tokenFile = path.join(tempDir, "token");
fs.writeFileSync(tokenFile, "ccb_file\n", "utf8");
try {
expect(
credential.inspect({
cfg: {
channels: {
clickclack: {
baseUrl: "https://clickclack.example",
tokenFile,
workspace: "default",
},
expect(
credential.inspect({
cfg: {
channels: {
clickclack: {
baseUrl: "https://clickclack.example",
tokenFile,
workspace: "default",
},
} as CoreConfig,
accountId: "default",
}),
).toMatchObject({
accountConfigured: true,
hasConfiguredValue: true,
resolvedValue: "ccb_file",
});
} finally {
fs.rmSync(tempDir, { recursive: true, force: true });
}
},
} as CoreConfig,
accountId: "default",
}),
).toMatchObject({
accountConfigured: true,
hasConfiguredValue: true,
resolvedValue: "ccb_file",
});
});
it("switches the default account to env auth before URL and workspace prompts", async () => {