Answer prose round 1: 0 🔴, 9 🟡 (0 misread); say DM throughout, untangle the notifier's help, error and README lines, and sort the new README bullets

This commit is contained in:
2026-11-14 23:36:30 +01:00
parent a8d0a9011c
commit ad70ec6dad
8 changed files with 20 additions and 19 deletions
+4 -4
View File
@@ -1,4 +1,4 @@
"""Sends a notice through the notifier that a project's config names."""
"""Sends a DM through the notifier that a project's config names."""
import dataclasses
import pathlib
import typing
@@ -16,7 +16,7 @@ Sender = typing.Callable[[str], Failure | None]
@dataclasses.dataclass(frozen=True)
class Backend:
"""A notifier's three parts. `read_config` returns whatever `send` takes as its config."""
"""What one notifier needs: `read_config` reads its credentials from an env file, and returns whatever `send` takes as its config; `send` posts a message with them through `http`; `keys` are the env file's keys."""
read_config: typing.Callable[[pathlib.Path], typing.Any]
send: typing.Callable[[typing.Any, str, Http], Failure | None]
http: Http
@@ -33,7 +33,7 @@ assert tuple(BACKENDS) == NOTIFIERS
def sender_of(project: ProjectConfig, http: Http | None = None) -> Sender | Failure:
"""A sender through the project's notifier, with the credentials in its env file read; http replaces the backend's own. A Failure where the project names no notifier or its env file cannot be used."""
if project.notifier is None or project.env_file is None:
return Failure(f"{project.folder / 'config.toml'} sets no `{NOTIFIER}`; set it to one of {', '.join(NOTIFIERS)}, and `env-file` to the file that holds its keys: mattermost needs {', '.join(BACKENDS['mattermost'].keys)}, slack needs {', '.join(BACKENDS['slack'].keys)}")
return Failure(f"{project.folder / 'config.toml'} sets no `{NOTIFIER}`; set `notifier` to {' or '.join(NOTIFIERS)}, and `env-file` to the file that holds that service's keys ({'; '.join(f'{name}: {', '.join(backend.keys)}' for name, backend in BACKENDS.items())})")
backend = BACKENDS[project.notifier]
config = backend.read_config(project.env_file)
if isinstance(config, Failure):
@@ -44,7 +44,7 @@ def sender_of(project: ProjectConfig, http: Http | None = None) -> Sender | Fail
def notify(text: str, directory: str | None, home: pathlib.Path, http: Http | None = None) -> Failure | None:
"""Sends text through the notifier of the project whose checkout holds directory.
It is skipped where the config names no notifier, since the project hasn't asked for notices. It is skipped too where no config can be read: loop-claude has stopped with that reason, and without a config there is no notifier to ask."""
The DM is skipped where the config names no notifier, since the project hasn't asked for DMs. It is skipped too where no config can be read: loop-claude has stopped with that reason, and without a config there is no notifier to ask."""
project = located(directory, home)
if isinstance(project, Failure) or project.notifier is None:
return None
+1 -1
View File
@@ -99,7 +99,7 @@ class Notify(Project):
def test_sender_in_names_the_settings_to_add_where_the_config_names_no_notifier(self):
failed = notify.sender_in(str(self.checkout), self.home)
assert isinstance(failed, Failure), failed
self.assertEqual(failed.reason, f"{self.folder / 'config.toml'} sets no `notifier`; set it to one of mattermost, slack, and `env-file` to the file that holds its keys: mattermost needs MATTERMOST_URL, MATTERMOST_TOKEN, MATTERMOST_RECIPIENT, slack needs SLACK_TOKEN, SLACK_RECIPIENT")
self.assertEqual(failed.reason, f"{self.folder / 'config.toml'} sets no `notifier`; set `notifier` to mattermost or slack, and `env-file` to the file that holds that service's keys (mattermost: MATTERMOST_URL, MATTERMOST_TOKEN, MATTERMOST_RECIPIENT; slack: SLACK_TOKEN, SLACK_RECIPIENT)")
class Main(Project):