test: isolate OS managed config writes - #400
Open
Edwinhe03 wants to merge 1 commit into
Open
Conversation
Redirect the managed-resolution coverage to a temporary machine-wide config and make the test suite fail closed before any unmocked privileged managed-file write can reach sudo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
managed-settings.jsonRoot cause
TestStateFileIsNotRewrittenuses a fake workspace together with a managed manifest that enablesuse_as_global_settings. Its fixture redirectedstate.jsonand the user-level Claude settings file, but not Claude Code's OS-managed settings path or privileged writer.Calling
claude.write_tool_configtherefore reached the real/etc/claude-code/managed-settings.json. On a developer machine where sudo was available, running the test suite could merge the fake workspace routing and auth configuration into the real machine-wide file.Fix
managed_files._sudo_replacein the suite-wide isolation fixture to fail any test that reaches an unmocked privileged writeProduction behavior is unchanged: ucode can still write the actual OS-managed config when an administrator explicitly enables global settings.
Validation
uv run pytest tests/test_managed_resolve.py tests/test_managed_files.py tests/test_agent_claude.py::TestWriteToolConfigManagedSettings tests/test_agent_codex.py::TestCodexManagedConfig— 86 passeduv run ruff check tests/conftest.py tests/test_managed_resolve.pygit diff --check/etc/claude-code/managed-settings.jsonchecksum and mtime remain unchanged during the focused suiteFull-suite verification
uv run pytest— 1988 passed, 39 skipped, 1 environment-specific failureTestCliWiring.test_successful_apply_exits_zero, where the bootstrap installer refuses to overwrite this host's existing/usr/local/bin/databricks; it does not exercise managed config writes/etc/claude-code/managed-settings.jsonremained byte-for-byte identical before and after the suite (sha256: 7544dc52fb73317e3699b30724e81b46f82de8bac4a360e88cfcbda0b79d253a), with unchanged mtime, ownership, mode, size, and file attributes