Python
fix(permissions): protect more files that run later; more plain git settings (OPE-231)
Devika Verma9e4a526354d0
diff --git a/coworker/permissions.py b/coworker/permissions.pyindex cac4d4cd..53ff0734 100644--- a/coworker/permissions.py+++ b/coworker/permissions.py@@ -154,6 +154,7 @@ def protected_paths() -> list[Path]:_PROTECTED_IN_PROJECT = (".git/hooks/",".github/workflows/",+ ".github/actions/", # actions the workflows call; they run with the workflow".gitlab-ci.yml",".vscode/tasks.json",".coworker/", # workspace policy + skills the agent would otherwise self-grant@@ -178,8 +179,18 @@ _PROTECTED_IN_PROJECT = (".git/config",".git/info/attributes",".git/modules/",+ ".git/worktrees/", # each linked worktree's own settings, same role as `modules/`".git","conftest.py", # pytest imports it on every test run, from any folder it collects+ "pytest.ini", # its options can load a plugin on every test run, like `tox.ini`+ # Python imports these on every start of the interpreter that can see them.+ "sitecustomize.py",+ "usercustomize.py",+ # mise loads these on entering the folder, as direnv does `.envrc`.+ ".mise.toml",+ "mise.toml",+ ".mise.local.toml",+ "mise.local.toml",# CI services run these on push."azure-pipelines.yml",".travis.yml",@@ -187,11 +198,18 @@ _PROTECTED_IN_PROJECT = ("bitbucket-pipelines.yml",".buildkite/",".vscode/launch.json", # what the editor runs when the user starts or debugs the program+ # Editor settings can name programs the editor starts on its own: the terminal+ # shell, the interpreter, formatters and linters.+ ".vscode/settings.json",# Package managers read these on every run, and a setting can name a program to run# in place of (or alongside) the package manager itself.".npmrc",".yarnrc",".yarnrc.yml",+ ".pnpmfile.cjs", # code pnpm runs on every install+ # cargo's settings can name the program that runs, links or wraps every build.+ ".cargo/config.toml",+ ".cargo/config",)@@ -285,6 +303,8 @@ _GIT_CONFIG_VALUE_FLAGS = {"-f", "--file", "--blob", "-t", "--type", "--default"# file to load, or where git fetches from. Setting one keeps its normal handling._GIT_CONFIG_PLAIN_KEYS = {"user.name", "user.email", "init.defaultbranch", "core.autocrlf", "pull.rebase", "color.ui",+ "core.longpaths", "push.default", "push.autosetupremote", "fetch.prune", "rebase.autostash",+ "merge.conflictstyle",}_GIT_CONFIG_WHOLE_FILE = {"--edit", "-e", "edit", "--rename-section", "rename-section","--remove-section", "remove-section"}diff --git a/tests/test_protected_paths.py b/tests/test_protected_paths.pyindex b8a6e431..93fed350 100644--- a/tests/test_protected_paths.py+++ b/tests/test_protected_paths.py@@ -160,21 +160,36 @@ _NEW_MARKER_TARGETS = [".git/modules/vendor/lib/hooks/post-checkout",".git/modules/vendor/lib/config","vendor/lib/.git", # a `.git` file says which folder git takes settings and hooks from+ ".git/worktrees/feature/config.worktree", # a linked worktree's own settings# pytest imports these on every test run, at any depth"conftest.py","tests/unit/conftest.py",+ "pytest.ini", # its options can load a plugin on every test run+ # Python imports these on every start of an interpreter that can see them+ "sitecustomize.py",+ ".venv/Lib/site-packages/usercustomize.py",+ # mise loads these on entering the folder+ ".mise.toml",+ "mise.toml",+ "mise.local.toml",# CI services run these on push"azure-pipelines.yml",".travis.yml","Jenkinsfile","bitbucket-pipelines.yml",".buildkite/pipeline.yml",+ ".github/actions/setup/action.yml", # actions the workflows call# the editor runs this when the user starts the program or the debugger".vscode/launch.json",+ ".vscode/settings.json", # can name the terminal shell, interpreter and formatters# package managers read these on every run, and they can name programs to run".npmrc",".yarnrc",".yarnrc.yml",+ ".pnpmfile.cjs",+ # cargo's settings can name the program that runs, links or wraps every build+ ".cargo/config.toml",+ ".cargo/config",]@@ -191,8 +206,13 @@ def test_new_protected_targets_are_human_only(tmp_path, target):".git/index.lock",".git/COMMIT_EDITMSG",".git/info/exclude",- ".vscode/settings.json",".vscode/extensions.json",+ ".github/ISSUE_TEMPLATE/bug.md",+ "docs/pytest.ini.md",+ "src/sitecustomize_helpers.py",+ "notes/mise.toml.example",+ ".cargo/credentials.toml",+ "src/cargo/config.rs","src/conftest.py.bak","tests/my_conftest.py","docs/Jenkinsfile.md",@@ -303,6 +323,12 @@ def test_a_sequence_of_reads_is_still_a_read(tmp_path, command):"git config user.email [email protected]","git config --global user.name 'A B'","git config set --local init.defaultBranch main",+ "git config --global core.longpaths true",+ "git config push.autoSetupRemote true",+ "git config --global push.default simple",+ "git config fetch.prune true",+ "git config rebase.autoStash true",+ "git config merge.conflictStyle zdiff3","cd .git && cat config",],)@@ -318,6 +344,7 @@ def test_other_shell_commands_are_unaffected(tmp_path, case_insensitive, command"git config --local core.fsmonitor ./watch.sh","git -C sub config alias.st '!sh x'","git config set core.pager less",+ "git config --global core.editor vim","git config --unset core.hooksPath","git config -e","git config --system --add safe.directory /deps/repo",