oliver-zehentleitner / maity
clean-up: G2 roles and forge reads: the done-authority table written six ways, one forge-error mapping, contract reads, line/admin proposals, instances helpers
tsk-kj17zr6m1mv2 Open
From the clean-up audit tsk-hgnbapyw7hnh (uncovered files, G2 Cards, tasks, releases and roles), read at 9dfd4b65. Paths are under hub/src/maity_hub/. Line numbers are at 9dfd4b65; check them against current main first.
Rules that are written more than once, in different shapes.
1. "Who is the done authority" is written six ways (design: one rule, many shapes)
- Sites:
cards.py:110-122(has_done_authority: authority to scopes, as code)cards.py:236-242(authority_scope: authority to one scope;reviewer_and_testermaps totasks:reviewonly)cover.py:112-117(DONE_SCOPES: authority to a tuple of scopes)merged.py:31-36(AUTHORITY: authority to audience tokens)events.py:1188-1192(_DONE_ROLES: authority to role names)routes/tasks.py:2073-2081(task_reported's audience:role:testeronly undertesterorreviewer_and_tester, inline)- What is wrong: a new authority value, or a change to which scope signs, must be made in six places. The shapes already differ (
authority_scopenames one scope whereDONE_SCOPESnames two). - Proposal: one table in
cards.py, for exampleDONE_AUTHORITY = {"reviewer": ("reviewer",), "tester": ("tester",), "reviewer_and_tester": ("reviewer", "tester"), "admin": ()}, with small derived helpers for the scopes (reviewertotasks:review,testertotasks:test,admintotasks:admin), the role tokens and the error scope. All six sites use it. - Effort: S-M (count M). Risk: low.
test_merged_closes.py,test_cover.py,test_review_delivery.pyand the signature tests pin the outcomes.
2. The forge-read error mapping is copied in every route that reads the forge (duplication)
- Sites:
routes/probe.py:45-48,66-69,84-88routes/contract_text.py:37-40,46-50,76-79,84-88routes/board.py:682-694(the import)- Each copy writes:
for_project, thenconfigured_forelseprobe_not_configured(fg.refused or "no_grant")shown only toproject:admin;NotCoveredErrortoprobe_not_configured(reason if admin);ForgeUnavailableErrorto503 probe_unavailablewithretry_at. - Proposal:
forge_reads.reader(request, mine) -> Forge(the configured check) and a context managerforge_reads.answering(mine, last=None)that maps the two exceptions.routes/probe.pypasses itsdetails.last. - Effort: S. Risk: low. The error bodies are pinned by
test_probe.py,test_contract_routes.py,test_contract_whole.pyand the import tests.
3. contract_text.read and read_whole repeat the same fetch (duplication)
contract_text.py:311-345and351-393: the same branch-head read (315-318/360-363), the samefile_atwith the"too large"mapping, and the same UTF-8 decode (321-332/367-378). Only the error field differs (contract.pathvssettings.contract_path).- Proposal:
_head(fg, repository, branch, field)and_markdown(fg, repository, path, ref, field) -> (bytes, str), both used by both reads. - Effort: S. Risk: low.
4. The manager's and the admin agent's consent proposals are twins, and the manager's names members by id (design / naming)
line.py:252-265(propose) andadmin_agents.py:168-187(propose): the same shape (title, summary,file_consentwith a proposal).line.py:258bindshandle = principal_id(conn, target.id). That is the member id (agt-…), not the handle. So the request a human reads is titled "Pause agt-…" or "Change agt-…'s lead". The admin-agent twin uses the real handle (admin_agents.py:174). The hub's own naming rule (rules.py:183-190) tells agents never to name a member by id in text a human reads.- Proposal: use the handle in
line.propose(and for the asker in both summaries). Share one small title/summary builder if that stays readable. - Effort: S. Risk: low. Check
test_manager.pyfor a pinned title.
5. instances.py: the owner-or-member resolution twice, and its own humans_only (duplication)
instances.patch_dormant(instances.py:860-877) repeats the resolution inteam_target(693-716): the target by member id, "owns the agent, member or not", else a membership withnot_foundfor a stranger. Only the final gate differs (_require_profile_ownervsmembers:admin).instances.humans_only()(670-676) andtakeovers.humans_only()(takeovers.py:123-126) each rebuilderrors.humans_only(message)(errors.py:76-78) with their own message.- Proposal: one
_owner_or_member(conn, caller, slug, member_id) -> (target, reader, owns)used by both. Replace the two local builders witherrors.humans_only("…"). - Effort: S. Risk: low.
6. instances.py: "the live sessions and who listens" is read four times (duplication)
instances.py:338-341(views),442-443(unpaused_presences),554-555(round_robin),618-619(team_wakes):_live_sessionsand thenlistening.whichover the session ids, each time.round_robin'sonline()(558-567) is another copy of the presence ladder's "online" rung (presence,294-306).- Proposal: one
_listening(conn, credentials) -> (sessions, heard).round_robincallspresence(...) == "online". - Effort: S. Risk: low.
Order
- Item 6's
presencepart goes with tsk-z0tpe6pz3fjq item 14 (one presence ladder for runners, views and instances). Do it there or after it. - Item 2: tsk-e77g3nhqqnex item 2 adds public forge read methods; the mapping helper can sit next to them.
- Item 5: tsk-9tj3p6ca30m6 lists
instances.py:723(owns_agent's owner select); the helper there can serve_owner_or_member.
Covered elsewhere
instances.INSTANCE_PATTERN(instances.py:29): tsk-53swp51q57tg item 3.instances.presencevsviews.presencevsrunners.presence: tsk-z0tpe6pz3fjq item 14.round_robin.online(item 6 here) is a fourth copy it does not list.routes/contract_text._matches(If-None-Match): tsk-k25qqhygend8 item 1.line.py:256importingfile_consentfrom routes: tsk-dwrtrhdgzezs.- Searched: done_authority, DONE_SCOPES, probe_not_configured, probe_unavailable, contract_text, line.propose, patch_dormant, humans_only, round_robin.
Effort sum: M + 5S (about 8 points).