Skip to content

fix: act on the checked target, refuse undeclared flags, keep done calls done - #220

Merged
neoromantic merged 3 commits into
mainfrom
fix/217-write-commands
Nov 19, 2026
Merged

neoromantic merged 3 commits into
mainfrom
fix/217-write-commands

Conversation

@neoromantic

Copy link
Copy Markdown
Owner

What and why

Three of the four defects in #217, in shared code used by every write command:

  1. Target resolved twice. The access guard resolved the account and the chat, then the command resolved both again. Now the guard pins args.account to the account it checked and hands its resolved chat to tg send and tg messages read (checkedChat). A switch of the active account or a cache change in between no longer moves the command.
  2. Ignored flags. citty reads an undeclared --acount 2 as true and drops the 2, and --silent false as --silent. The guard now refuses both with INVALID_ARGS (exit 3) before the command runs. tg api and tg sql pass their flags on, so they are not checked.
  3. Local log turned a done write into a failure. A failed api_activity insert after a successful call threw from trackApiCall, so a retry repeated the write. The log write is now outside the call's try and never changes the call's outcome. A failed write shows only in --verbose.

The stale @username part (item 2 of #217) is in a separate PR. It adds a contacts.resolveUsername call for writes and needs a live run first.

Refs #217

How I checked it

  • Each new test fails on main and passes here: the guard test switches the account and moves @testuser to another user between the check and the run; undeclaredArg unit tests; the e2e refusal of --acount 2 and --silent false without credentials; trackApiCall with the api_activity table dropped.

  • bun run check, bun run test (1200 pass), bun run test:e2e (339 pass), bun run build; dist/tg send --to me -m hi --silent false exits 3 before connecting.

  • No new Telegram calls, so no live run. The test session is logged out, and the smoke suite fails the same way on main.

  • Tests pass locally and use made-up data only

  • README, docs and affected demos follow the product content standard

  • Title follows the repo's commit style

🤖 Generated with Claude Code

neoromantic and others added 3 commits November 19, 2026 17:32
The guard resolved the account and the chat, then the command resolved
both again. An account switch or a cache change in between could make a
command act on a chat that was never checked. The check now pins
args.account and hands its resolved chat to tg send and tg messages read.

Refs #217

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…drop

citty reads an unknown --acount 2 as true and drops the value, so the
command ran on the active account; --silent false ran as --silent. The
guard now refuses both with INVALID_ARGS before the command runs. tg api
and tg sql pass their flags on and are not checked.

Refs #217

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…itten

The success log ran inside the try, so a failed local insert turned a
completed write into an error and invited a retry that repeated it.

Refs #217

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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