Skip to content

Test the --chat contacts fallback and receipt wait; fix empty-listing hint - #19

Merged
Skeyelab merged 2 commits into
mainfrom
test/coverage-gaps
Nov 13, 2026
Merged

Skeyelab merged 2 commits into
mainfrom
test/coverage-gaps

Conversation

@Skeyelab

Copy link
Copy Markdown
Member

Summary

Tests for two untested behaviors, plus one hint fix.

--chat read, contacts.toml broken or $IMSG_AGENT_CONTACTS missing
  -> still reads; group senders masked            (guard)
--contact read, contacts.toml broken
  -> error: not valid TOML                         (guard)
send(), receipt arrives 0.1s later
  -> waits, reports delivered                      (guard)
send(), receipt never arrives
  -> waits the full timeout, "no delivery receipt" (guard)
 imsg-agent --contacts   # with no contacts in the file in force
-no contacts configured -- create ~/.config/imsg-agent/contacts.toml
+no contacts configured -- add contacts to <--contacts-file or $IMSG_AGENT_CONTACTS path>

Evidence

  • Guards: passed on arrival (the behavior already worked). Each was checked by breaking the code: removing the --chat fallback in _open_book failed 2 tests; making confirm_delivery check once without waiting failed 2 tests. Code restored after each.
  • Hint fix: test_an_empty_listing_names_the_contacts_file_given and ..._env_var_file red -> green.
  • Coverage of imsgread.py: 87% -> 89% (lines + branches). 127 passed.

Merge Danger

Door: two-way

Blast Radius: none

Tests plus one error message's wording.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCgWWsJbTMzsnA2WJkmsjC

…pty-listing hint

Guards for two behaviors nothing tested: a raw --chat read works with a
broken or missing contacts file, and send() waits for a receipt that
arrives late (and gives up after the timeout). Both were checked by
breaking the code and watching the tests fail.

The "no contacts configured" hint named ~/.config/imsg-agent even when
--contacts-file or $IMSG_AGENT_CONTACTS was in force; it now names the
file the run actually reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCgWWsJbTMzsnA2WJkmsjC
@claude

claude Bot commented Nov 13, 2026

Copy link
Copy Markdown

Blocking: .coverage is committed. This PR adds a binary .coverage SQLite file, and it isn't in .gitignore. It embeds absolute local paths, e.g. /Users/<real-username>/Documents/GitHub/imsg-agent/imsgread.py. That is a real identifier in a tracked file, which the privacy rules forbid. Please remove it from the PR and add .coverage (and htmlcov/) to .gitignore. Because the path is already in this PR's history, squash it out before merge rather than only deleting it in a later commit.

Checked, no problems found:

  • The new --contacts empty-listing hint only changes the error text. It doesn't touch read or send scoping, --robot handling, or the read-only chat.db open.
  • Contacts lookup order is consistent. --contacts-file wins, then a set $IMSG_AGENT_CONTACTS (even if the file doesn't exist yet), then the config dir, then the bundled file. The hint now names the file actually in force.
  • The new tests use only placeholders (+15555550123, friend).
  • _open_book already tolerates a broken contacts file for a raw --chat, so the new tests match existing behavior. --contact still raises. The scope is unchanged: it is still one chat.

Minor:

  • test_an_empty_listing_names_the_contacts_file_given asserts create X or add contacts to X, which is loose. The file exists, so it should assert add contacts to exactly.
  • The two receipt-wait tests use real sleeps and a thread, so they could be flaky on slow CI. Consider injecting a clock or sleep function.
  • The typedstream decoder and README install steps aren't touched by this diff, so I didn't re-review them. I also couldn't run the test suite here, since pytest isn't installed in this environment.

.coverage was committed by accident and embeds absolute local paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCgWWsJbTMzsnA2WJkmsjC
@claude

claude Bot commented Nov 13, 2026

Copy link
Copy Markdown

Review against the privacy and scoping invariants. I found no blockers. I couldn't run the tests here because pytest isn't installed in the runner, so none of this has been executed.

Invariants

  • Identifiers: the new tests only use +15555550123, friend and masked handles. I saw no real identifiers in the diff.
  • Chat scoping: the diff doesn't touch read or send scoping. The new --chat chat9001 test still reads a single chat.
  • --robot: the send and marker paths are unchanged, so the refusal of an unstated marker choice is unaffected. The receipt-wait tests call send(..., robot=False) explicitly, so they don't rely on a default.
  • chat.db: the diff doesn't touch how the DB is opened. The new sqlite3.connect(send_db) write is on the test fixture DB, not a real chat.db, and that's fine.
  • Not reviewed: the typedstream decoder, the contacts.toml lookup order, and the README install steps. The diff doesn't change them. The new hint logic follows contacts_path() precedence (the --contacts-file flag, then $IMSG_AGENT_CONTACTS, then the search), which matches contacts_candidates().

Nits

  1. imsgread.py (the empty --contacts hint): args.contacts_file is printed and checked with .exists() as given. If ContactBook.open calls expanduser() on it, a ~/x.toml value would be reported as missing or shown unexpanded even though the file is the one in force. Expanding it once up front would fix that.
  2. test_a_receipt_that_arrives_late_is_waited_for: the writer thread is never joined. Joining it, or making it a daemon thread, avoids a leaked sqlite3 connection if the assertion fails. The fixed 0.1s sleep against a 5s timeout is fine.
  3. test_a_receipt_that_never_arrives_waits_out_the_timeout uses a real 0.2s wall-clock wait. That's acceptable, but it's the sort of test that flakes on a loaded CI runner if the bound ever tightens.

Otherwise this looks good to merge.

@Skeyelab
Skeyelab merged commit 0baa306 into main Nov 13, 2026
6 checks passed
@Skeyelab
Skeyelab deleted the test/coverage-gaps branch November 13, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant