diff --git a/bin/loop_claude/loop/main.py b/bin/loop_claude/loop/main.py index 31dd7e92..9b6b566c 100644 --- a/bin/loop_claude/loop/main.py +++ b/bin/loop_claude/loop/main.py @@ -36,7 +36,7 @@ def main(argv: list[str], env: typing.Mapping[str, str], paths: Paths, launcher: raise if stop.reason: say(stop.reason, effects, stdout=not stop.code) - # Every stop but the human's own Ctrl-C and the help is DMed, so a loop left overnight never ends unseen. A loop given no task prints the help. + # Every stop but the human's own Ctrl-C and the help is DMed where the project's config can be read and sets `env-file`, so a loop left overnight never ends unseen. A loop given no task prints the help. if stop.code != 130 and stop.reason != HELP: tell(f"loop-claude in {cwd} stopped: {stop.reason}", effects) return stop.code diff --git a/bin/loop_effects/test_effects.py b/bin/loop_effects/test_effects.py index 1593e29c..bd3a7e54 100644 --- a/bin/loop_effects/test_effects.py +++ b/bin/loop_effects/test_effects.py @@ -13,7 +13,6 @@ import unittest.mock sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) -from mattermost_dm.dm import http_json from loop_effects.effects import run_python, say, system_effects NOW = 1790000000 @@ -59,14 +58,6 @@ class Said(unittest.TestCase): self.assertEqual(flushes, [f"{STAMP} hello\n"]) - -class Dm(unittest.TestCase): - def test_sends_the_text_for_the_project_holding_the_current_directory_with_the_real_http(self): - with unittest.mock.patch("loop_effects.effects.dm", return_value=None) as sent: - self.assertIsNone(system_effects().dm("Which one?")) - sent.assert_called_once_with("Which one?", None, pathlib.Path.home(), http_json) - - class LocalTime(unittest.TestCase): def test_renders_seconds_in_the_machines_zone(self): # A POSIX zone two hours ahead of UTC, so a time in UTC would read 14:13:20. Cleanups run last in, first out: the zone is restored before time.tzset makes the clock read it again. diff --git a/bin/mattermost_dm/test_mattermost_dm.py b/bin/mattermost_dm/test_mattermost_dm.py index de13ca2c..ffa5ca6e 100644 --- a/bin/mattermost_dm/test_mattermost_dm.py +++ b/bin/mattermost_dm/test_mattermost_dm.py @@ -1,3 +1,4 @@ +import contextlib import http.server import io import json @@ -16,6 +17,7 @@ from project_config.test_project_config import configured from mattermost_dm import dm, main from failure import Failure from test_env import isolated_env +from loop_effects.effects import system_effects TOOL = pathlib.Path(__file__).resolve().parents[1] / "mattermost-dm" CONFIG = dm.Config("https://chat.example", "secret-token", "lilleman") @@ -228,6 +230,13 @@ class Dm(Project): self.assertIsNone(dm.dm("Which one?", str(self.checkout), self.home, server)) self.assertEqual(server.requests[-1], ("POST", "https://chat.example/api/v4/posts", "secret-token", {"channel_id": "channel-id", "message": "Which one?"})) + def test_loop_claudes_dm_posts_the_text_for_the_project_holding_the_current_directory(self): + self.name_env_file("MATTERMOST_URL=https://chat.example\nMATTERMOST_TOKEN=secret-token\nMATTERMOST_RECIPIENT=lilleman\n") + server = mattermost() + with unittest.mock.patch("loop_effects.effects.http_json", server), contextlib.chdir(self.checkout): + self.assertIsNone(system_effects().dm("Which one?")) + self.assertEqual(server.requests[-1], ("POST", "https://chat.example/api/v4/posts", "secret-token", {"channel_id": "channel-id", "message": "Which one?"})) + def test_skips_the_dm_for_a_project_whose_config_names_no_env_file_even_where_the_old_shared_file_exists(self): (self.home / ".claude").mkdir() env_file(str(self.home / ".claude"), "MATTERMOST_URL=https://chat.example\nMATTERMOST_TOKEN=other-projects-token\nMATTERMOST_RECIPIENT=lilleman\n", name=".env")