@@ -7,7 +7,13 @@ import type { OpenClawConfig } from "../config/config.js";
|
7 | 7 | import type { PluginInstallRecord } from "../config/types.plugins.js"; |
8 | 8 | import { writePersistedInstalledPluginIndex } from "../plugins/installed-plugin-index-store.js"; |
9 | 9 | import type { InstalledPluginIndex } from "../plugins/installed-plugin-index.js"; |
10 | | -import { createPathResolutionEnv, withEnvAsync } from "../test-utils/env.js"; |
| 10 | +import { |
| 11 | +captureEnv, |
| 12 | +createPathResolutionEnv, |
| 13 | +deleteTestEnvValue, |
| 14 | +setTestEnvValue, |
| 15 | +withEnvAsync, |
| 16 | +} from "../test-utils/env.js"; |
11 | 17 | |
12 | 18 | type CollectPluginsTrustFindings = |
13 | 19 | typeof import("./audit-plugins-trust.js").collectPluginsTrustFindings; |
@@ -489,8 +495,7 @@ describe("security audit extension tool reachability findings", () => {
|
489 | 495 | "OPENCLAW_STATE_DIR", |
490 | 496 | "OPENCLAW_BUNDLED_PLUGINS_DIR", |
491 | 497 | ] as const; |
492 | | -const previousPathResolutionEnv: Partial<Record<(typeof pathResolutionEnvKeys)[number], string>> = |
493 | | -{}; |
| 498 | +let pathResolutionEnvSnapshot: ReturnType<typeof captureEnv> | undefined; |
494 | 499 | |
495 | 500 | const runSharedExtensionsAudit = async (config: OpenClawConfig) => { |
496 | 501 | return await collectPluginsTrustFindingsForTest({ |
@@ -505,13 +510,13 @@ describe("security audit extension tool reachability findings", () => {
|
505 | 510 | fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-security-extensions-")); |
506 | 511 | isolatedHome = path.join(fixtureRoot, "home"); |
507 | 512 | const isolatedEnv = createPathResolutionEnv(isolatedHome, { OPENCLAW_HOME: isolatedHome }); |
| 513 | +pathResolutionEnvSnapshot = captureEnv([...pathResolutionEnvKeys]); |
508 | 514 | for (const key of pathResolutionEnvKeys) { |
509 | | -previousPathResolutionEnv[key] = process.env[key]; |
510 | 515 | const value = isolatedEnv[key]; |
511 | 516 | if (value === undefined) { |
512 | | -delete process.env[key]; |
| 517 | +deleteTestEnvValue(key); |
513 | 518 | } else { |
514 | | -process.env[key] = value; |
| 519 | +setTestEnvValue(key, value); |
515 | 520 | } |
516 | 521 | } |
517 | 522 | homedirSpy = vitestModule.vi |
@@ -527,14 +532,7 @@ describe("security audit extension tool reachability findings", () => {
|
527 | 532 | |
528 | 533 | afterAll(async () => { |
529 | 534 | homedirSpy?.mockRestore(); |
530 | | -for (const key of pathResolutionEnvKeys) { |
531 | | -const value = previousPathResolutionEnv[key]; |
532 | | -if (value === undefined) { |
533 | | -delete process.env[key]; |
534 | | -} else { |
535 | | -process.env[key] = value; |
536 | | -} |
537 | | -} |
| 535 | +pathResolutionEnvSnapshot?.restore(); |
538 | 536 | if (fixtureRoot) { |
539 | 537 | await fs.rm(fixtureRoot, { recursive: true, force: true }).catch(() => undefined); |
540 | 538 | } |
|