oliver-zehentleitner / maity
clean-up: forge and outbound: test-fake compatibility path, secret_key_missing helper, header scanning, narrow excepts, leftovers, replicas.md
tsk-1mkd2n9x3phr Open
From the clean-up audit tsk-hgnbapyw7hnh, Area 3 (Forge and outbound calls), read at 80647565. Line numbers are at 80647565; check each one against current main before changing it. Finding numbers are the audit's (A3-n).
Small, low-risk debt around the forge modules. The structural forge items (one transport, one visibility cache) are on the sibling card filed at the same time.
1. A compatibility path in the Forge read API that exists only for test fakes (A3-6, debt)
forge._raw(forge.py:344-347) says it is there so that "the reads of JSON call exactly as they did before raw reads existed".Forge._get(forge.py:401-407) has four branches for the same reason.- Fakes with the old signatures:
test_forge_access.py:69andtest_instance_namespaces.py:48(lambda self, path, query=None);test_contract_text.py:62,test_merged_closes.py:35andtest_overview.py:300(lambda _self, path). - Proposal: the fakes take
**_, the code always passesraw_cap=raw_cap,_rawgoes, and_getbecomes two branches. - Effort: S. Risk: low (test-only churn).
2. The secret_key_missing 409 is raised in three places (A3-7, duplication)
forge_tokens.py:92-95(require_key),forge_webhook.py:308-309(inline inrotate),auth/second_factor.py:335. Same status, code and message.- Proposal: one helper (e.g.
forge_tokens.require_keymoved toerrors.pyorsecretbox.py) used by all three. - Effort: S. Risk: low.
3. ASGI request headers are scanned by hand four times (A3-8, duplication)
net.py:34-41(_values);forge_webhook.py:67-85(_headers,_header,_declared);middleware.py:514-521(_content_length);join_host.py:48-53(requested_host).- Two of them parse Content-Length by different rules:
forge_webhook._declaredrefuses a repeated or non-digit value;middleware._content_lengthtakes the first value throughint(), which also accepts a sign or surrounding spaces. - Proposal: one
net.header_values(scope, name)and one Content-Length parser, used by all four. The webhook's strict rule must stay, and should become the rule for both. - Effort: S to M. Risk: low.
4. Small leftovers in forge_access.py and forge_webhook.py (A3-13, debt)
ForgeAccess._bound(forge_access.py:265-281) andForgeAccess._refusing(forge_access.py:283-284) take abase: forge.Forgeparameter neither uses.forge_webhook.py:148has# type: ignore[union-attr]onPATH.match(...).group(1).matches()(forge_webhook.py:63-64, called frommiddleware.py:180) has already run the same regex.- Proposal: drop
basefrom both methods. Havematches()return the slug (or None) and pass it tohandle, so the ignore goes. - Effort: S. Risk: low.
5. Broad except Exception around the shared budget and probe_via writes (A3-14, debt)
shared_budget.py:48,shared_budget.py:99andforge_access.py:132catchExceptionand log a warning. The decision never to fail a forge read over the shared row is recorded inhub/context/replicas.md:454-458and the shared_budget docstring; that intent only needs database errors caught. Today a programming error in the upsert (a wrong column, a type error) is swallowed as a warning and budget sharing silently stops.- Proposal: narrow to
sqlalchemy.exc.SQLAlchemyError(plusOSErrorif needed for connect failures). - Effort: S. Risk: low. A missed exception class would surface as a failed forge read, so add one test with the database down.
6. The Source line in hub/context/replicas.md:435 cites stale lines and a function that does not exist (A3-12, docs drift)
forge.py:125-126(_budgets) is now 129-130;forge.py:246-250(_visible,_public) is 288 and 292;forge_access.py:62(_chosen) is 94;forge_access.py:258-277(_last_via,probe_via) is 318-357;views.py:185is 226;releases.py:190is 192.forge_links.forget_tokendoes not exist; the function isgithub_app.forget_token(github_app.py:186).- Proposal: cite symbols, not line numbers, and fix the function name.
- Effort: S. Risk: none.
Order
- Item 2:
auth/second_factor.pyis being changed by tsk-8mgb85ne0nrq; touch it after that lands. - Item 3:
middleware.pyis also edited by tsk-j967n09yz6ps (items 7 and 9); rebase rather than conflict. - Item 1 touches forge.py like the sibling card; do it first or in the same PR as the sibling's item 1.
- Item 6 last, after the sibling card has moved the lines it cites.
Covered elsewhere
- None of these six. Searched:
secret_key_missing,shared_budget,content-length,forge_webhook,replicas.md,_raw.
Effort sum: 6S (item 3 may grow to M).