Skip to content

Remove process-global cwd mutation from base_cli.testing.invoke #1201

Description

@codeforester

Problem

Validated from Claude third-pass finding [87].

lib/python/base_cli/testing.py::invoke() changes process-global working directory with os.chdir(cwd_path), calls CliRunner.invoke(...), and then changes back in a finally block. This works for serial tests, but os.chdir() is process-global and can race when helper invocations run concurrently in the same Python process, such as with pytest-xdist style patterns or future threaded test harnesses.

Desired outcome

Make base_cli.testing.invoke() avoid process-global cwd mutation while preserving its current test ergonomics.

Scope

  • Prefer a Click-supported isolated cwd mechanism or another local-only strategy.
  • Preserve support for writing a base_manifest.yaml fixture when manifest= is supplied.
  • Keep stdout/stderr separation behavior intact.
  • Add a regression test for cwd isolation.

Acceptance criteria

  • invoke(..., cwd=...) no longer calls os.chdir() around the invocation, or the remaining use is isolated and safe for concurrent calls.
  • Existing base_cli testing helpers continue to work.
  • Tests cover cwd behavior without relying on global process state.

Classification

Review finding taxonomy: test helper robustness.

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions