fix(usage): declare the Adobe Firefly usage fetcher the dispatcher already calls - #12321
Merged
diegosouzapw merged 1 commit intoSep 1, 2026
Conversation
maxmad64bis
force-pushed
the
fix/usage-fetcher-registration
branch
from
September 1, 2026 14:20
54ccbd1 to
f2c31f3
Compare
7 tasks done
muhamadgalihsaputra
pushed a commit
to niyatna/NiyatnaRoute
that referenced
this pull request
Sep 27, 2026
…ready calls (diegosouzapw#12321) usage/fetcherProviders.ts exists, in its own words, "so the registration list can't drift from the dispatcher's switch statement". It drifted: diegosouzapw#8006 added adobe-firefly and firefly to the dispatcher and to USAGE_SUPPORTED_PROVIDERS but not to this list, so the connection UI advertised usage support while the provider-plugin manifest, genericQuotaFetcher and the free-access quota cache all reported no fetcher — for two ids getUsageForProvider would happily serve. Declaring them is what makes the balance actually get fetched (registerGenericQuotaFetchers wires a generic fetcher per declared id, and resolveFreeAccessState stops returning early), which the PR states plainly rather than burying as a side effect. The test turns the docstring's prose invariant into enforcement: it reads the dispatcher's cases from source and compares both directions, and records each accepted difference against USAGE_SUPPORTED_PROVIDERS with a reason plus a staleness check, so the next drift can't hide among them. xiaomi-mimo-token-plan is left flagged as a real gap rather than widening the PR. Verified in a combined batch worktree: 174/174 focused tests across all 11 PRs of this batch, typecheck:core clean, complexity 2706/3218, cognitive-complexity 1221/1437, check:cycles and check:docs-counts green. Thanks @maxmad64bis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
usage/fetcherProviders.tssays of itself that it exists "so the registration list can't drift from the dispatcher's switch statement", and asks whoever adds a case to remember to add it here too.It drifted. #8006 added
adobe-fireflyandfireflyto the dispatcher and toUSAGE_SUPPORTED_PROVIDERS, but not to this list. So the connection UI says usage is supported while the provider-plugin manifest,genericQuotaFetcherand the free-access quota cache all report no usage fetcher — whengetUsageForProviderwill happily callgetAdobeFireflyUsagefor either id.Nothing suggests this was deliberate.
git log -S adobe-fireflyon both files turns up exactly one commit, the one that added the feature. No guard, no comment, no test excludes them.Declaring them is what makes the balance actually get fetched:
registerGenericQuotaFetcherswires a generic fetcher for every declared id, andresolveFreeAccessStatestops returning early. That's the intended effect, not a side effect — worth stating plainly since two more providers now take part in quota refreshes.The test is the enforcement the docstring asked for in prose. It reads the dispatcher's cases from the source and compares both directions, so a case without a declaration fails, and so does a declaration the dispatcher would never reach.
It also records the differences between this list and
USAGE_SUPPORTED_PROVIDERS, each with a reason. Those sets aren't meant to converge — aggregators likeopenrouterhave a fetcher without being surfaced as a usage-reporting account — but an unexplained difference now fails, so the next drift can't hide among the accepted ones.xiaomi-mimo-token-planis in there as a real gap: declared supported, no fetcher. Left alone rather than widen this PR.Related Issues
Validation
npm run lintRed before green: 2 of 4 cases failed on the unmodified list — the undeclared pair, and the unexplained difference between the two sets. After adding the two ids, 4/4. Measured on the base: the dispatcher handles 49 ids, the list declared 47,
USAGE_SUPPORTED_PROVIDERSlists 46.npm run lintexits 2 here and on an untouched checkout of the base alike (suppressions left that do not occur anymore, zero reported errors).Tests Added Or Updated
tests/unit/usage-fetcher-registration-coverage.test.ts(new, 4 cases)Coverage Notes
The production change is two strings in a
constarray. The test covers the invariant that array exists to hold, in both directions, plus the recorded divergences and a staleness check so they can't outlive the difference they explain.Reviewer Notes
usage.tsas text rather than importing it: pulling in the dispatcher drags its whole fetcher graph — DB, sockets,child_process— which is exactly the weightfetcherProviders.tswas extracted to avoid.switch (provider) {and stops at that switch's closing brace. Anchoring on the firstswitchwould land in a doc comment twenty lines above, and running to end-of-file would let a future switch contribute cases to an invariant that isn't about it.