oliver-zehentleitner / maity
clean-up: web api.js: request layer apart from the fixture hub, no test hooks on M.api
tsk-1ms2pg7257pb Open
From the web clean-up audit, area 17 (tsk-hgnbapyw7hnh), read at 80647565 (findings sent to lotse, seq 125537). Line numbers are from 80647565, so re-check them on current main.
#63 api.js: the request layer and a 5800-line fixture hub in one file that every production page parses (design).
- api.js is 6183 lines, about 418 KB. Lines about 28-5888 are the fixture hub, and the request layer is about 5890-6183.
- index.html:35 loads js/api.js on every http(s) page.
- context/fixtures.md (beba53ac) says an http origin never loads fixture code. That holds only for the data bundle fixtures.js, which loadFixtures loads lazily (api.js:127-144). The simulator logic is downloaded and parsed by every real user.
- The file mixes two unrelated jobs, which makes review hard.
- Proposal:
- js/api.js keeps ApiError, projectPath, request/requestOnce, prime, getAll and M.api (about 400 lines).
- js/fixture-hub.js is loaded by loadFixtures next to fixtures.js, and by web/tools/fixture_answers.js:22.
- Later, split it by domain if wanted.
- Move the STEP_UP_ROUTES target in check.py (1680-1681) with it.
- Effort M-L. Risk medium: load order on file://, fixture_answers.js, smoke hooks.
- Open question for the lead: the performance umbrella tsk-a5pxwgkgr73e covers bundling the scripts. Decide whether this split goes there or here.
#64 api.js: test-only hooks on the production M.api, and a misplaced comment (debt).
- api.js:6132-6146 and 6181 export fixtureManages, fixtureMailTestTo, fixturesLive, fixtureAsked and isPublicPath. Their only callers are in web/tools/smoke.js (3066, 17056, 11252/13621/17476, 13659/13679/15743, 13025/14999). Nothing in web/js uses them.
- The attachmentUrl comment (6153-6154) sits above projectPath (6155-6157), not above attachmentUrl (6161).
- Proposal: after #63, put the hooks on a fixture-only object (for example M.fixtureHub), keep M.api to what the views use, and move the comment back.
- Effort S. Risk low.
Order: do this before the fixture-hub clean-up card (permission checks, word lists, paging), or after it. Not both at once: both rewrite the same 5800 lines.