Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tests/python/test_findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,15 @@ def test_an_unanswered_question_is_refused(paths: tuple[Path, Path]) -> None:
assert not paths[0].exists()


@pytest.mark.parametrize("words", ["Change it", "No", "Yes, but say three delays"])
def test_a_click_on_the_recommended_yes_counts_as_agreement(paths: tuple[Path, Path]) -> None:
"""The question box records a click on the recommended option with this suffix."""
by_question(paths, asked(paths, f'May the ledger say: "{LINE}"?', "Yes (Recommended)"))
assert [e["text"] for e in entries(paths)] == [LINE]


@pytest.mark.parametrize(
"words", ["Change it", "No", "Yes, but say three delays", "No (Recommended)", "(Recommended)"]
)
def test_an_answer_other_than_agreement_is_refused(paths: tuple[Path, Path], words: str) -> None:
qid = asked(paths, f'May the ledger say: "{LINE}"?', words)
with pytest.raises(findings.RefusedError, match="agree"):
Expand Down
12 changes: 7 additions & 5 deletions tools/findings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
`add` and `replace` need Ola's agreement to the wording: `--ola`, words found in
this session's transcript as `brief.py --ola` finds them, or `--question <id>`, a
question `questions.py` stored whose text holds the line and whose answer is
one of `AGREE`. Each `search` appends its time and
words to `<git-common-dir>/findings-searches.jsonl`, untracked; `questions.py
add` and design or probe briefs (`brief.py`) refuse through `unsearched` until
a search ran in the last hour. Standard library only.
one of `AGREE`, alone or with the box's `RECOMMENDED` suffix. Each `search`
appends its time and words to `<git-common-dir>/findings-searches.jsonl`,
untracked; `questions.py add` and design or probe briefs (`brief.py`) refuse
through `unsearched` until a search ran in the last hour. Standard library only.
"""

from __future__ import annotations
Expand All @@ -41,6 +41,8 @@
WINDOW = timedelta(hours=1)
#: Chosen: whole answers that agree; anything else, "Yes, but ..." too, is refused.
AGREE = {"yes", "agree", "agreed", "ok", "approve", "approved"}
#: The question box's suffix on a click of the recommended option, as in "Yes (Recommended)".
RECOMMENDED = " (Recommended)"


class RefusedError(Exception):
Expand Down Expand Up @@ -84,7 +86,7 @@ def _answered(args: argparse.Namespace, store: Path) -> str:
raise RefusedError(f"there is no question {qid}")
if record["state"] != "answered":
raise RefusedError(f"question {qid} is not answered")
if record["words"].strip(" .!").casefold() not in AGREE:
if record["words"].removesuffix(RECOMMENDED).strip(" .!").casefold() not in AGREE:
raise RefusedError(f'Ola did not agree to question {qid}: "{record["words"]}"')
if " ".join(args.text.split()) not in " ".join(record["text"].split()):
raise RefusedError(f"question {qid} does not hold this line")
Expand Down
Loading