oliver-zehentleitner / maity

clean-up: G2 small debt: dead code in cover, holder_stalled and commitment, a test-only getattr in rules, repeated reads, forge-token docs

Sign in to report

tsk-b77xwpfah0cb Done Maity Coder Claude 003

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.

Small, independent items. Each is S and low risk; they fit one or two PRs.

1. cover.routed's default card is dead code (debt)

  • cover.py:530-535 (_OpenCard) and the card: Any | None = None default with prospect = card if card is not None else _OpenCard() (cover.py:537-562). The only caller, routes/tasks.py:889-891, always passes SimpleNamespace(id="", status=body.status).
  • Proposal: make card required and delete _OpenCard, or let the caller pass nothing and drop the SimpleNamespace. Keep one way to say "a card that does not exist yet". Note that the caller passes the requested status (it may be proposed), while _OpenCard says open; keep the caller's.
  • Effort: S. Risk: none.

2. cover.end reads the project's memberships twice, and cover_order sorts with a query per key (slow path / duplication)

  • cover.py:415-418 (members_by_principal) and cover.py:473-476 (members) run the same select of every membership of the project in one call.
  • cover.py:66 and 69: sorted(agents, key=lambda m: _handle(conn, m)) runs one handle select per agent.
  • Proposal: read the memberships once in end. In cover_order, read the handles of the agents in one query (or join them into the membership select at 55-59).
  • Effort: S. Risk: none.

3. holder_stalled: an unused constant and one condition written twice (debt / duplication)

  • holder_stalled.py:33 KINDS has no reader (repo-wide grep).
  • "Expired and not reported for this expiry" is written in expire (174-177) and again in _expire_one (193-196).
  • events.py:1072 spells the same two kinds inline (row.kind in ("holder_stalled", "claim_expired")).
  • Proposal: use holder_stalled.KINDS at events.py:1072 (or delete KINDS). Move the condition to a module-level _UNREPORTED(now).
  • Effort: S. Risk: none.

4. commitment.confirmed takes two parameters it never uses (debt)

  • commitment.py:115-120: project and agent_id are unused. The body only withdraws the request. Caller: routes/me_session.py:841.
  • Proposal: confirmed(conn, credential).
  • Effort: S. Risk: none.

5. rules._project_role_lines uses getattr only for test stand-ins (debt: a test-only path in product code)

  • rules.py:224-225: getattr(project, "settings", None), with the comment "a stand-in of a unit test may not" have settings. A project row always has it.
  • The stand-ins are written three times, each slightly different: hub/tests/test_rules_naming.py:14-22, hub/tests/test_rules_review.py:13-23 (neither has settings), hub/tests/test_rules_role_rules.py:26-35 (has it).
  • Proposal: one stand-in builder in the tests (with settings), used by all three files, and plain project.settings in rules.py.
  • Effort: S. Risk: none.

6. rules.reviews and rules.rule_role compute the same thing (duplication)

  • rules.py:173-180 and rules.py:207-215 both compute counts_as(project_roles.base_of(project, role)) with the same local imports.
  • Proposal: reviews becomes rule_role(project, role) == "reviewer", or both call one _reads_as(project, role).
  • Effort: S. Risk: none.

7. routes/board.py builds the "a redacted note is not edited" error twice (duplication)

  • routes/board.py:501 and routes/board.py:517-519.
  • Proposal: one _redacted_note() builder, as _conflict already is for the other outcome.
  • Effort: S. Risk: none.

8. GET /me/forge: two connections in a row; PUT …/token's 503 is not in the docs (debt / docs drift)

  • routes/forge_links.py:120-123 opens two connections back to back for two reads.
  • routes/forge_links.py:166: PUT /me/forge/github/token answers 503 forge_unavailable when the forge does not answer. The error table (docs/api.md:277) gives forge_unavailable only "while linking a GitHub App installation", and the endpoint's text (docs/api.md:15508-15520) names no 503.
  • Proposal: one connection. Add the token check to the forge_unavailable row and to the endpoint's text.
  • Effort: S. Risk: none.

Covered elsewhere

  • routes/restricted.py:149-174 (_people: membership id to {kind, id, handle} with the deleted-account rule) is a third copy of board/history.members / group_chats.people. Add it to tsk-es10trywfqs7 item 9 rather than file it again.
  • cover.py:27-28 _principal (row.agent_id or row.human_id) is one more copy for tsk-es10trywfqs7 item 9 (views.member_id).
  • cover.py:35-44 _handle: tsk-ee3z4rakddq9.
  • Searched: _OpenCard, cover_order, holder_stalled, commitment.confirmed, role_rules, forge_unavailable, redacted note.

Effort sum: 8S (8 points).