Answer product-owner round 1: 1 🔴, 1 🟡 (1 misread); DM through the checkout of a held-up issue's repo and show the DM in the window
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from loop_effects.effects import Effects, say
|
||||
|
||||
|
||||
def tell(text: str, effects: Effects) -> None:
|
||||
"""DMs text to the human. Where the DM fails, it says why on stderr and goes on: the DM only copies what the terminal shows, so its failure never stops the loop."""
|
||||
if failed := effects.dm(text):
|
||||
def tell(text: str, effects: Effects, directory: str | None = None) -> bool:
|
||||
"""DMs text to the human through the notifier of the project whose checkout holds directory, else the current directory, and returns whether it went out. Where the DM fails, it says why on stderr and goes on: the DM only copies what the terminal shows, so its failure never stops the loop."""
|
||||
if failed := effects.dm(text, directory):
|
||||
say(f"could not DM you: {failed.reason}", effects)
|
||||
return not failed
|
||||
|
||||
@@ -109,6 +109,8 @@ class FakeEffects:
|
||||
self.owner = owner
|
||||
# Each direct message sent. They stay out of self.calls, so a test that lists every call doesn't list them. Without a script, each is sent.
|
||||
self.dms = []
|
||||
# The directory each DM named, in the order of self.dms; None where it named none.
|
||||
self.dm_directories = []
|
||||
self.dm_failures = list(dm_failures)
|
||||
self.scripts = {"claude": list(claude), "claude_on_terminal": list(on_terminal_claude), "git": list(git), "input": list(inputs), "python": list(python), "stream_claude": list(streams)}
|
||||
# Without a script, every read finds all memory available.
|
||||
@@ -144,8 +146,9 @@ class FakeEffects:
|
||||
return subprocess.CompletedProcess(args, 1 if self.windows is None else 0, self.windows or "", "no server")
|
||||
return subprocess.CompletedProcess(args, 0, {"-V": self.tmux_version + "\n", "show-options": self.owner + "\n"}.get(args[0], "@9\n"), "")
|
||||
|
||||
def dm(self, text):
|
||||
def dm(self, text, directory):
|
||||
self.dms.append(text)
|
||||
self.dm_directories.append(directory)
|
||||
return self.dm_failures.pop(0) if self.dm_failures else None
|
||||
|
||||
def memory(self):
|
||||
@@ -832,7 +835,7 @@ class Interrupts(unittest.TestCase):
|
||||
def test_drops_the_keys_typed_before_the_question_ahead_of_the_dm_so_an_answer_typed_while_it_sends_counts(self):
|
||||
fake = FakeEffects(inputs=["Use B."])
|
||||
seen = []
|
||||
effects = dataclasses.replace(fake.effects(), dm=lambda text: seen.append(list(fake.calls)))
|
||||
effects = dataclasses.replace(fake.effects(), dm=lambda text, directory: seen.append(list(fake.calls)))
|
||||
self.assertEqual(self.put(fake, effects=effects)[0], "Use B.")
|
||||
self.assertEqual(seen, [[("discard_typed", None)]])
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ class Effects:
|
||||
claude_on_terminal: typing.Callable[[list[str], str, dict[str, str]], int]
|
||||
# Drops what was typed on the terminal and not yet read.
|
||||
discard_typed: typing.Callable[[], None]
|
||||
# Sends the human a direct message through the notifier the project's config names, as `notify` does, for the project whose checkout holds the current directory; a Failure where it could not.
|
||||
dm: typing.Callable[[str], Failure | None]
|
||||
# Sends the human a direct message through the notifier the project's config names, as `notify` does, for the project whose checkout holds the given directory, else the current directory; a Failure where it could not.
|
||||
dm: typing.Callable[[str, str | None], Failure | None]
|
||||
execv: typing.Callable[[str, list[str]], None]
|
||||
git: git_repo.Git
|
||||
input: typing.Callable[[str], str]
|
||||
@@ -75,7 +75,7 @@ def system_effects(backends: typing.Mapping[Notifier, Backend[typing.Any]] = BAC
|
||||
claude=lambda args, cwd, stdin: subprocess.run(["claude", *args], capture_output=True, cwd=cwd, input=stdin, text=True),
|
||||
claude_on_terminal=claude_on_terminal,
|
||||
discard_typed=lambda: termios.tcflush(sys.stdin, termios.TCIFLUSH),
|
||||
dm=lambda text: notify(text, None, pathlib.Path.home(), backends),
|
||||
dm=lambda text, directory: notify(text, directory, pathlib.Path.home(), backends),
|
||||
execv=os.execv,
|
||||
git=git_repo.git,
|
||||
input=input,
|
||||
|
||||
@@ -73,7 +73,14 @@ class Notify(Project):
|
||||
self.name_notifier("slack", SLACK_KEYS)
|
||||
slack = Slack({"ok": True})
|
||||
with contextlib.chdir(self.checkout):
|
||||
self.assertIsNone(system_effects(through("slack", slack)).dm("Which one?"))
|
||||
self.assertIsNone(system_effects(through("slack", slack)).dm("Which one?", None))
|
||||
self.assertEqual(slack.requests, [SLACK_POST])
|
||||
|
||||
def test_a_dm_that_names_a_directory_goes_through_the_notifier_for_the_project_holding_it_from_any_current_directory(self):
|
||||
self.name_notifier("slack", SLACK_KEYS)
|
||||
slack = Slack({"ok": True})
|
||||
with contextlib.chdir(self.home):
|
||||
self.assertIsNone(system_effects(through("slack", slack)).dm("Which one?", str(self.checkout)))
|
||||
self.assertEqual(slack.requests, [SLACK_POST])
|
||||
|
||||
def test_skips_the_notice_for_a_project_that_names_no_notifier_even_where_its_env_file_holds_the_keys(self):
|
||||
|
||||
Reference in New Issue
Block a user