Refuse a Read, Grep or Bash call that reads ~/.claude/.env or a config's env-file #524

Merged
lilleman merged 8 commits from item-369 into main 2026-11-13 21:28:59 +01:00
2 changed files with 14 additions and 5 deletions
Showing only changes of commit bc066943f6 - Show all commits
+10 -1
View File
@@ -9,7 +9,7 @@ import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from failure import Failure
from project_config.settings import held, load, OUTSIDE, ProjectConfig, SETTINGS
from project_config.settings import env_files, held, load, OUTSIDE, ProjectConfig, SETTINGS
from test_env import isolated_env
TOOL = pathlib.Path(__file__).resolve().parents[1] / "project-config"
@@ -238,6 +238,15 @@ class HeldTest(ConfigCase):
self.assertIsInstance(held(target, self.home), ProjectConfig, "git names the folder by its resolved path")
class EnvFilesTest(ConfigCase):
def test_lists_each_readable_configs_env_file_even_one_load_refuses(self) -> None:
self.write("acme", CLIENT + 'env-file = "~/acme.env"\n')
self.write("misplaced", 'checkout = "~/code/other"\nenv-file = "/srv/other.env"\n')
self.write("broken", "checkout = ")
self.write("none", CLIENT)
self.assertEqual(env_files(self.home), [self.home / "acme.env", pathlib.Path("/srv/other.env")])
class ToolTest(ConfigCase):
def run_tool(self, *args: str, cwd: pathlib.Path | None = None) -> subprocess.CompletedProcess[str]:
return subprocess.run([sys.executable, str(TOOL), *args], cwd=cwd or self.checkout, env={**isolated_env(), "HOME": str(self.home)}, capture_output=True, text=True)
+4 -4
View File
@@ -7,12 +7,12 @@ import os
import pathlib
import re
from failure import Failure
from rule_hook.call import Call, text
from rule_hook.git import guarded_git
from rule_hook.rules import Breach
from command_lines.shell_command import resolved, simple_commands
from rule_hook.call import Call, text
from project_config.settings import env_files
from failure import Failure
from rule_hook.git import guarded_git
from command_lines.shell_command import resolved, simple_commands
def env_file_breaches(call: Call, home: str) -> list[Breach]: