Skip to content

Commit f72782d

Browse files
authored
refactor(test): restore auth persistence integrity (#125699)
* test: restore auth persistence integrity Restore the SQLite-backed auth wizard assertions traced to 43ea501 and consolidate duplicated message-action and temp-directory fixtures. * test: support npm 12 pack results
1 parent f32da28 commit f72782d

43 files changed

Lines changed: 361 additions & 1013 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎extensions/browser/test-support.ts‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,12 @@
11
/**
22
* Browser test-support re-exports from shared plugin-sdk test fixtures.
33
*/
4-
import fs from "node:fs";
5-
import path from "node:path";
6-
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
7-
84
export {
95
createCliRuntimeCapture,
106
expectGeneratedTokenPersistedToGatewayAuth,
117
type CliRuntimeCapture,
128
} from "openclaw/plugin-sdk/test-fixtures";
13-
export { createTempHomeEnv } from "openclaw/plugin-sdk/test-env";
9+
export { createTempHomeEnv, useAutoCleanupTempDirTracker } from "openclaw/plugin-sdk/test-env";
1410
export type { TempHomeEnv } from "openclaw/plugin-sdk/test-env";
1511
export { isLiveTestEnabled } from "openclaw/plugin-sdk/test-live";
1612
export type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
17-
18-
export function useAutoCleanupTempDirTracker(registerCleanup: (cleanup: () => void) => unknown) {
19-
const dirs = new Set<string>();
20-
registerCleanup(() => {
21-
for (const dir of dirs) {
22-
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
23-
}
24-
dirs.clear();
25-
});
26-
return {
27-
make(prefix: string): string {
28-
const dir = fs.mkdtempSync(path.join(resolvePreferredOpenClawTmpDir(), prefix));
29-
dirs.add(dir);
30-
return dir;
31-
},
32-
};
33-
}

‎extensions/codex/src/app-server/test-support.ts‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
* transports.
44
*/
55
import { EventEmitter } from "node:events";
6-
import fs from "node:fs";
7-
import path from "node:path";
86
import { PassThrough, Writable } from "node:stream";
97
import type { EmbeddedRunAttemptParamsV2 as EmbeddedRunAttemptParams } from "openclaw/plugin-sdk/agent-harness-runtime";
108
import type { Model } from "openclaw/plugin-sdk/llm";
11-
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
129
import { vi } from "vitest";
1310
import { CodexAppServerClient } from "./client.js";
1411
import type { CodexAppServerClientFactory, CodexAppServerClientOptions } from "./shared-client.js";
@@ -78,24 +75,7 @@ export function createCodexTestToolTerminalObserver(): NonNullable<
7875
};
7976
}
8077

81-
/** Creates temp directories that are removed by the supplied test cleanup hook. */
82-
export function useAutoCleanupTempDirTracker(registerCleanup: (cleanup: () => void) => unknown) {
83-
const dirs = new Set<string>();
84-
registerCleanup(() => {
85-
for (const dir of dirs) {
86-
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
87-
}
88-
dirs.clear();
89-
});
90-
return {
91-
dirs,
92-
make(prefix: string): string {
93-
const dir = fs.mkdtempSync(path.join(resolvePreferredOpenClawTmpDir(), prefix));
94-
dirs.add(dir);
95-
return dir;
96-
},
97-
};
98-
}
78+
export { useAutoCleanupTempDirTracker } from "openclaw/plugin-sdk/test-env";
9979

10080
/** Positional naked-client injection contract confined to tests. */
10181
export type CodexTestAppServerClientFactory = (

‎extensions/matrix/test-support.ts‎

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,2 @@
1-
// Matrix test support owns plugin-local fixture cleanup.
2-
import fs from "node:fs";
3-
import path from "node:path";
4-
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
5-
6-
type RegisterTempDirCleanup = (cleanup: () => void) => unknown;
7-
8-
export function useAutoCleanupTempDirTracker(registerCleanup: RegisterTempDirCleanup) {
9-
const dirs = new Set<string>();
10-
registerCleanup(() => {
11-
for (const dir of dirs) {
12-
fs.rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 20 });
13-
}
14-
dirs.clear();
15-
});
16-
return {
17-
make(prefix: string): string {
18-
// openclaw-temp-dir: allow extension-local test support cannot import the core-only tracker.
19-
const dir = fs.mkdtempSync(path.join(resolvePreferredOpenClawTmpDir(), prefix));
20-
dirs.add(dir);
21-
return dir;
22-
},
23-
};
24-
}
1+
// Matrix test support keeps plugin tests on the public SDK fixture boundary.
2+
export { useAutoCleanupTempDirTracker } from "openclaw/plugin-sdk/test-env";
Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1 @@
1-
import fs from "node:fs";
2-
import path from "node:path";
3-
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/file-access-runtime";
4-
5-
export function useReefTempDirs(registerCleanup: (cleanup: () => void) => unknown): {
6-
make(prefix: string): string;
7-
} {
8-
const directories = new Set<string>();
9-
registerCleanup(() => {
10-
for (const directory of directories) {
11-
fs.rmSync(directory, { force: true, maxRetries: 5, recursive: true, retryDelay: 20 });
12-
}
13-
directories.clear();
14-
});
15-
return {
16-
make(prefix: string): string {
17-
const directory = fs.mkdtempSync(path.join(resolvePreferredOpenClawTmpDir(), prefix));
18-
directories.add(directory);
19-
return directory;
20-
},
21-
};
22-
}
1+
export { useAutoCleanupTempDirTracker as useReefTempDirs } from "openclaw/plugin-sdk/test-env";

‎src/channels/bundled-channel-catalog-read.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import fs from "node:fs";
33
import path from "node:path";
44
import { afterEach, describe, expect, it, vi } from "vitest";
5-
import { cleanupTempDirs, makeTempRepoRoot, writeJsonFile } from "../../test/helpers/temp-repo.js";
5+
import { cleanupTempDirs, makeTempDir as makeTempRepoRoot } from "../../test/helpers/temp-dir.js";
6+
import { writeJsonFile } from "../../test/helpers/temp-repo.js";
67
import type { PluginChannelCatalogEntry } from "../plugins/channel-catalog-registry.js";
78

89
// Delegate to the plugin-dir resolver for candidate-order policy; mock it here

‎src/channels/plugins/contracts/test-helpers/AGENTS.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ This file adds channel-specific rules on top of `src/channels/AGENTS.md`.
1010
imports into `extensions/**`.
1111
- When a helper needs a bundled plugin public/test surface, go through
1212
`src/test-utils/bundled-plugin-public-surface.ts`.
13-
- Prefer `loadBundledPluginTestApiSync(...)` for eager access to exported test
14-
helpers.
1513
- Prefer `resolveRelativeBundledPluginPublicModuleId(...)` when a test needs a
1614
module id for dynamic import or mocking.
1715
- If `vi.mock(...)` hoisting would evaluate the module id too early, use

‎src/commands/auth-choice.test.ts‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
// Auth choice tests cover auth choice application, provider config, and credential prompts.
2-
import fs from "node:fs/promises";
32
import path from "node:path";
43
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from "vitest";
4+
import {
5+
createAuthTestLifecycle,
6+
createExitThrowingRuntime,
7+
createWizardPrompter,
8+
setupAuthTestEnv,
9+
} from "../../test/helpers/auth-wizard.js";
510
import { resolveAgentDir } from "../agents/agent-scope.js";
611
import type { OpenClawConfig } from "../config/config.js";
712
import { resolveAgentModelPrimaryValue } from "../config/model-input.js";
@@ -10,12 +15,6 @@ import * as providerAuthChoices from "../plugins/provider-auth-choices.js";
1015
import type { ProviderAuthMethod, ProviderAuthResult, ProviderPlugin } from "../plugins/types.js";
1116
import type { WizardPrompter } from "../wizard/prompts.js";
1217
import { applyAuthChoice } from "./auth-choice.apply.js";
13-
import {
14-
createAuthTestLifecycle,
15-
createExitThrowingRuntime,
16-
createWizardPrompter,
17-
setupAuthTestEnv,
18-
} from "./test-wizard-helpers.js";
1918

2019
type DetectZaiEndpoint = (params: {
2120
apiKey: string;
@@ -605,6 +604,7 @@ describe("applyAuthChoice", () => {
605604
"SYNTHETIC_API_KEY",
606605
]);
607606
let authTestRoot: string | null = null;
607+
let authTestCleanup: (() => Promise<void>) | null = null;
608608
let authStateCounter = 0;
609609
async function setupTempState() {
610610
if (!authTestRoot) {
@@ -683,15 +683,15 @@ describe("applyAuthChoice", () => {
683683
let defaultProviderPlugins: ProviderPlugin[] = [];
684684

685685
beforeAll(async () => {
686-
authTestRoot = (await setupAuthTestEnv("openclaw-auth-")).stateDir;
686+
const authTestEnv = await setupAuthTestEnv("openclaw-auth-");
687+
authTestRoot = authTestEnv.stateDir;
688+
authTestCleanup = authTestEnv.cleanup;
687689
defaultProviderPlugins = await createDefaultProviderPlugins();
688690
resolvePluginProviders.mockReturnValue(defaultProviderPlugins);
689691
});
690692

691693
afterAll(async () => {
692-
if (authTestRoot) {
693-
await fs.rm(authTestRoot, { recursive: true, force: true });
694-
}
694+
await authTestCleanup?.();
695695
});
696696

697697
afterEach(async () => {

‎src/commands/doctor/channel-capabilities.packaged.test.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import path from "node:path";
33
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
44
import {
55
cleanupTempDirs,
6-
makeTempRepoRoot,
7-
writeJsonFile,
8-
} from "../../../test/helpers/temp-repo.js";
6+
makeTempDir as makeTempRepoRoot,
7+
} from "../../../test/helpers/temp-dir.js";
8+
import { writeJsonFile } from "../../../test/helpers/temp-repo.js";
99

1010
const packageRootMock = vi.hoisted(() => ({ value: "" }));
1111
const channelPluginMocks = vi.hoisted(() => ({

0 commit comments

Comments
 (0)