From aca20fd22ec2157fb5386c55e9ca13e44d9fbbc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20Sol=C3=A1r?= Date: Thu, 10 Sep 2026 14:58:12 +0200 Subject: [PATCH] test: fix two local-only test failures caused by leftover state MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `python_support` left `test/tmp/my-python-actor` behind (`remove: false`), so the next run detected the stale `.venv` as the Python runtime, cached that interpreter path, then deleted it — making the test alternate pass/fail on every other local run. `detectAiAgent` cleared the agent env vars in `afterEach` only, so the first test saw whatever the shell exported and failed inside any agent CLI. Co-Authored-By: Claude Opus 5 --- test/lib/hooks/telemetry/detectEnvironment.test.ts | 9 +++++++-- test/local/__fixtures__/python_support.test.ts | 12 ++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/lib/hooks/telemetry/detectEnvironment.test.ts b/test/lib/hooks/telemetry/detectEnvironment.test.ts index ac0ddb408..b7c88de0a 100644 --- a/test/lib/hooks/telemetry/detectEnvironment.test.ts +++ b/test/lib/hooks/telemetry/detectEnvironment.test.ts @@ -17,12 +17,17 @@ describe('detectAiAgent', () => { 'OPENCLAW_SHELL', ]; - afterEach(() => { + beforeEach(() => { + // The suite itself may run inside one of these agents, so clear the vars before each test for (const key of agentEnvVars) { - delete process.env[key]; + vi.stubEnv(key, undefined); } }); + afterEach(() => { + vi.unstubAllEnvs(); + }); + test('returns undefined when no agent env vars are set', () => { expect(detectAiAgent()).toBeUndefined(); }); diff --git a/test/local/__fixtures__/python_support.test.ts b/test/local/__fixtures__/python_support.test.ts index beb80f2f5..f127e5ced 100644 --- a/test/local/__fixtures__/python_support.test.ts +++ b/test/local/__fixtures__/python_support.test.ts @@ -12,7 +12,7 @@ const actorName = 'my-python-actor'; const PYTHON_START_TEMPLATE_ID = 'python-start'; const { beforeAllCalls, afterAllCalls, joinPath, tmpPath, toggleCwdBetweenFullAndParentPath } = useTempPath(actorName, { create: true, - remove: false, + remove: true, cwd: true, cwdParent: true, }); @@ -34,6 +34,11 @@ describe('[python] Python support', () => { }); it('should work', { timeout: TEST_TIMEOUT }, async () => { + if (existsSync(tmpPath)) { + // Remove the tmp path before detecting the runtime, so a leftover .venv is not picked up + await rm(tmpPath, { recursive: true, force: true }); + } + const runtime = await usePythonRuntime({ cwd: tmpPath, force: true }); const pythonVersion = runtime.map((r) => r.version).unwrapOr(undefined); @@ -44,11 +49,6 @@ describe('[python] Python support', () => { return; } - if (existsSync(tmpPath)) { - // Remove the tmp path if it exists - await rm(tmpPath, { recursive: true, force: true }); - } - await testRunCommand(CreateCommand, { args_actorName: actorName, flags_template: PYTHON_START_TEMPLATE_ID,