Repository navigation
Fix require_account fallback and send the resolved account to the daemon - #55
Merged
Merged
Conversation
With require_account on (TLGR_REQUIRE_ACCOUNT or [defaults] require_account), resolve_account still fell back to [accounts] default and the active alias and only refused when nothing resolved. It now counts only the explicit sources (the positional, -a/--account, and TLGR_ACCOUNT, the documented environment form of -a) and refuses everything else locally with ACCOUNT_REQUIRED, exit 2, before anything is dispatched. With it off, run_op resolved the fallback account into a local variable while the daemon dispatcher read state.account, so the request carried account "" and the daemon answered ACCOUNT_REQUIRED. run_op now stores the resolved alias on state, so the documented fallback works end to end. Tests pin both modes: resolve_account directly, the CLI with a recording dispatcher (including live streams), and a real daemon on a temp socket.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
README and AGENT.md say
require_account = truemeans every command must name its account, with no default-account fallback, and that a violation exits 2. Two things in the CLI did not match:resolve_account(tlgr/cli/globals.py) tried[accounts] defaultand then the active alias, and only refused when nothing resolved at all. So the rail passed on exactly the state it is meant to distrust: a script that forgot-aran as whichever account happened to be the default.run_op(tlgr/cli/gen.py) resolved the account into a local variable, but the daemon dispatcher readsstate.account. A command without-atherefore sentaccount: ""and the daemon (which never picks one, COR-02) answeredACCOUNT_REQUIRED, so the documented fallback order only worked on paper.run_livealready assigned tostate.account;run_opdid not.Behaviour chosen (from the docs)
require_accounton (TLGR_REQUIRE_ACCOUNT=1, or[defaults] require_account = true;TLGR_REQUIRE_ACCOUNT=0still overrides the config):-a/--account, andTLGR_ACCOUNT.[accounts] defaultand the active alias are never consulted.ACCOUNT_REQUIRED, exit 2 (the code and exit status the daemon uses and AGENT.md documents). Previously the rare path that did refuse raised a plain ClickUSAGEerror instead.TLGR_ACCOUNTcounts as explicit because AGENT.md lists it as the environment form of-a, and the root-aoption already takes its default from it, so the CLI cannot tell the two apart at that layer anyway. If we want strict mode to reject the env var too, that needs the root option to report its parameter source and is a separate change.require_accountoff: positional,-a,TLGR_ACCOUNT,[accounts] default, then the active alias, and the alias that wins is now the one the request carries to the daemon. When nothing resolves the CLI still sends""and lets the daemon refuse, as before; refusing locally there would also refuse--dry-run, whichrun_opanswers without an account (the registry contract tests pin that).Local operations are untouched (
needs_account=Falsefor every local op, soresolve_accountis never called for them).Tests
tests/test_require_account.py(23 tests):resolve_accountdirectly: the full fallback order, strict mode refusing the active alias and the config default, the config switch alone turning it on, the env override, explicit-a/ positional /TLGR_ACCOUNTpassing.ACCOUNT_REQUIREDenvelope, exit 2, and dispatches nothing; live streams are guarded too.tlgr --json profile getwith no-anow succeeds as the active account (it answeredACCOUNT_REQUIREDbefore), and with strict mode on it is refused without any Telegram call, while-a workgoes through.Against
origin/mainthe new file has 11 failures; with this change it passes.make check(lint, typecheck, test, docs, parity) is green locally: 13569 passed.Related
#52 (
tlgr.Client) and #53 (tlgr batch) each enforce the strict rule themselves. They may touchtlgr/cli/gen.pytoo, so one of them may need a rebase; the diff here is limited to account resolution. With this merged, #53's own per-line check becomes redundant but stays harmless.Not changed here: account-management ops (
account info,account sync, ...) are local and resolve throughops/_auth.resolve_alias, which still falls back to the active alias even withrequire_accounton. Whether strict mode should cover those is worth a separate look.