Skip to content

chore(usage): decompose services/usage.ts into per-provider usage/* leaves (999 → 253) - #8545

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.49from
MumuTW:chore/decomp-usage-service
Jul 26, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.49from
MumuTW:chore/decomp-usage-service

Conversation

@MumuTW

@MumuTW MumuTW commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Phase 1 god-file decomposition, 1 of 3. Independent of the sibling PRs — disjoint file sets, mergeable in any order.

What

open-sse/services/usage.ts 999 → 253 lines. Ten per-provider usage fetchers move into usage/* leaves (crof, nanogpt, qoder, opencode, deepseek, bailian, vertex, xiaomi-mimo, xai, github). usage.ts becomes a thin provider→fetcher dispatcher.

Behavior-preserving move. The public import surface is unchanged — usage.ts re-exports the symbols that existing tests import from services/usage (buildKiroUsageResult, discoverKiroProfileArn, parseQoderUserStatusUsage, glmMonthlyRemainingPercentage).

Faithfulness

Mechanically verified rather than eyeballed — every moved function body was extracted from both revisions and compared after normalizing comments/whitespace:

  • 15 of 15 moved functions are byte-identical to their pre-move bodies
  • no function lost (nothing present in the old file is absent from leaves + host)
  • no function duplicated (nothing left behind in the host that also lives in a leaf)

Verification

Check Result
typecheck:core clean
check:cycles no cycles
check-file-size new leaves ≤ cap 800 (largest 230)
Pre-existing suites touching services/usage 452/452 pass
New split tests pass

The new *-split.test.ts files are characterization tests — they lock the export surface and a couple of edge assertions, and say so in their header comments. They are not the regression guard; the 452 pre-existing tests are, and they are green.

Inherited base-red (not from this PR)

release/v3.8.49 is currently red on two gates that this branch does not touch:

Both were verified present on the base at branch point.

@MumuTW
MumuTW requested a review from diegosouzapw as a code owner July 25, 2026 08:25
@diegosouzapw

Copy link
Copy Markdown
Owner

Verified independently: diff against the merge-base matches your stated +1648/-840 across 22 files exactly, every new *-split.test.ts is additions-only (no existing test line removed), typecheck:core and check:cycles are clean, and all 364 tests across the usage-related suite pass on your branch. Confirmed the two inherited base-red gates (file-size on providers/page.tsx + tokenHealthCheck.ts, db-rules on compressionDetailNormalizers.ts) are untouched by this diff — pre-existing, not caused by this PR. Real production consumers (quotaCache.ts, providerLimits.ts, saturationSignals.ts) only ever import getUsageForProvider, which the dispatcher still exports unchanged, so nothing external breaks. This looks merge-ready — nice clean decomposition, thanks for doing the byte-level faithfulness check up front.

MumuTW added 2 commits July 25, 2026 22:33
…an, vertex, xiaomi-mimo, xai, github usage fetchers into usage/* leaves

Decompose services/usage.ts (god-file phase 1): move the remaining per-provider
usage fetcher/parser logic into co-located leaves under open-sse/services/usage/
so usage.ts becomes a thin dispatcher (imports + USAGE_FETCHER_PROVIDERS +
getUsageForProvider switch + __testing re-exports).

New leaves (each a pure data transform or independent fetcher, no orchestration):
  - usage/github.ts    getGitHubUsage, formatGitHubQuotaSnapshot, inferGitHubPlanName, shouldDisplayGitHubQuota
  - usage/crof.ts      getCrofUsage
  - usage/nanogpt.ts   getNanoGptUsage
  - usage/qoder.ts     getQoderUsage, parseQoderUserStatusUsage
  - usage/opencode.ts  getOpencodeUsage
  - usage/deepseek.ts  getDeepseekUsage
  - usage/bailian.ts   getBailianCodingPlanUsage
  - usage/vertex.ts    getVertexUsage
  - usage/xiaomi-mimo.ts getXiaomiMimoUsage
  - usage/xai.ts       getXaiUsage

usage.ts re-exports parseQoderUserStatusUsage (named) and threads every helper
the existing __testing contract exposes (usage-utils / usage-service-hardening /
qoder-usage-quota / xiaomi-mimo-selftrack / xai-usage / vertex-spend suites read
them from services/usage). External importers unchanged.

open-sse/services/usage.ts: 1065 -> 256 lines (cap 800).
npm run check:file-size: OK. typecheck:core: OK. eslint: clean. check:cycles: OK.

Added characterization tests (tests/unit/usage-<provider>-split.test.ts) that
import each leaf directly and pin its export surface + key edges, mirroring the
existing usage-quota-core-split / usage-scalars-split pattern.
@MumuTW
MumuTW force-pushed the chore/decomp-usage-service branch from f1f6a43 to 05dc3f5 Compare July 25, 2026 14:36
@MumuTW

MumuTW commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the current release tip (4053e2314). The four inherited base-red gates you confirmed are now actually fixed upstream — #8544 (ESLint suppressions, merged), #8534 (check:db-rules), #8539 (backoff assertions), #8561 (check:file-size rebaseline) — so this PR's CI should come back green on its own merits rather than needing the base-red carve-out.

Re-verified on the rebased head: the 10 usage-*-split.test.ts files pass 36/36, and check:file-size is OK (182 frozen files, no violations). Pure rebase, no content changes.

@MumuTW

MumuTW commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Correction to my comment above: Fast Quality Gates will still be red after the rebase, and it isn't this PR. #8561 fixed check:file-size and thereby unmasked a fifth base-red gate behind it in the same job — check:complexity-ratchets (complexity 2169 > baseline 2130, cognitiveComplexity 956 > 951).

I measured it on pristine detached checkouts with an empty working tree: 4053e2314 (current tip) and 30709255c (the base you reviewed against) both report 2169 / 956 — identical to this PR's head, so it predates #8561 and is not caused by anything here. It was hidden because check:file-size ran earlier in the same bash -e job and short-circuited it. Full measurement table in my comment on #8546.

The gate is in quality.yml's fast-gates job, so it's red for every PR against release/v3.8.49 regardless of content. Everything else on this PR is green and verified locally.

@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @MumuTW — merged into release/v3.8.49 via the local merge-train (validated as one combined tree: full test:unit + test:vitest 274/274 on the 32-core box, tip d4b9ce6016). Your commit keeps its authorship. 🚀

HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
…eaves (999 → 253) (diegosouzapw#8545)

* chore(usage): extract crof, nanogpt, qoder, opencode, deepseek, bailian, vertex, xiaomi-mimo, xai, github usage fetchers into usage/* leaves

Decompose services/usage.ts (god-file phase 1): move the remaining per-provider
usage fetcher/parser logic into co-located leaves under open-sse/services/usage/
so usage.ts becomes a thin dispatcher (imports + USAGE_FETCHER_PROVIDERS +
getUsageForProvider switch + __testing re-exports).

New leaves (each a pure data transform or independent fetcher, no orchestration):
  - usage/github.ts    getGitHubUsage, formatGitHubQuotaSnapshot, inferGitHubPlanName, shouldDisplayGitHubQuota
  - usage/crof.ts      getCrofUsage
  - usage/nanogpt.ts   getNanoGptUsage
  - usage/qoder.ts     getQoderUsage, parseQoderUserStatusUsage
  - usage/opencode.ts  getOpencodeUsage
  - usage/deepseek.ts  getDeepseekUsage
  - usage/bailian.ts   getBailianCodingPlanUsage
  - usage/vertex.ts    getVertexUsage
  - usage/xiaomi-mimo.ts getXiaomiMimoUsage
  - usage/xai.ts       getXaiUsage

usage.ts re-exports parseQoderUserStatusUsage (named) and threads every helper
the existing __testing contract exposes (usage-utils / usage-service-hardening /
qoder-usage-quota / xiaomi-mimo-selftrack / xai-usage / vertex-spend suites read
them from services/usage). External importers unchanged.

open-sse/services/usage.ts: 1065 -> 256 lines (cap 800).
npm run check:file-size: OK. typecheck:core: OK. eslint: clean. check:cycles: OK.

Added characterization tests (tests/unit/usage-<provider>-split.test.ts) that
import each leaf directly and pin its export surface + key edges, mirroring the
existing usage-quota-core-split / usage-scalars-split pattern.

* docs(changelog): add fragment for this PR
@MumuTW
MumuTW deleted the chore/decomp-usage-service branch September 5, 2026 10:18
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…eaves (999 → 253) (diegosouzapw#8545)

* chore(usage): extract crof, nanogpt, qoder, opencode, deepseek, bailian, vertex, xiaomi-mimo, xai, github usage fetchers into usage/* leaves

Decompose services/usage.ts (god-file phase 1): move the remaining per-provider
usage fetcher/parser logic into co-located leaves under open-sse/services/usage/
so usage.ts becomes a thin dispatcher (imports + USAGE_FETCHER_PROVIDERS +
getUsageForProvider switch + __testing re-exports).

New leaves (each a pure data transform or independent fetcher, no orchestration):
  - usage/github.ts    getGitHubUsage, formatGitHubQuotaSnapshot, inferGitHubPlanName, shouldDisplayGitHubQuota
  - usage/crof.ts      getCrofUsage
  - usage/nanogpt.ts   getNanoGptUsage
  - usage/qoder.ts     getQoderUsage, parseQoderUserStatusUsage
  - usage/opencode.ts  getOpencodeUsage
  - usage/deepseek.ts  getDeepseekUsage
  - usage/bailian.ts   getBailianCodingPlanUsage
  - usage/vertex.ts    getVertexUsage
  - usage/xiaomi-mimo.ts getXiaomiMimoUsage
  - usage/xai.ts       getXaiUsage

usage.ts re-exports parseQoderUserStatusUsage (named) and threads every helper
the existing __testing contract exposes (usage-utils / usage-service-hardening /
qoder-usage-quota / xiaomi-mimo-selftrack / xai-usage / vertex-spend suites read
them from services/usage). External importers unchanged.

open-sse/services/usage.ts: 1065 -> 256 lines (cap 800).
npm run check:file-size: OK. typecheck:core: OK. eslint: clean. check:cycles: OK.

Added characterization tests (tests/unit/usage-<provider>-split.test.ts) that
import each leaf directly and pin its export surface + key edges, mirroring the
existing usage-quota-core-split / usage-scalars-split pattern.

* docs(changelog): add fragment for this PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants