Skip to content

[codex] Centralize usage-store scan helpers#213

Open
pq198363-ops wants to merge 1 commit into
Agentpay-Org:mainfrom
pq198363-ops:bounty-151-usage-scan-helpers
Open

[codex] Centralize usage-store scan helpers#213
pq198363-ops wants to merge 1 commit into
Agentpay-Org:mainfrom
pq198363-ops:bounty-151-usage-scan-helpers

Conversation

@pq198363-ops

Copy link
Copy Markdown

Summary

Closes #151.

  • Add a shared usageScan helper module with parseUsageKey, scanUsageStore, scanByAgent, and scanByService.
  • Route usage exports, aggregate billing, agent rollups, service rollups, and stats through the shared parser/scanners.
  • Preserve existing response shapes and values while removing duplicated usageStore.entries() parsing loops.
  • Add focused tests for helper parsing/scanning plus endpoint parity across exports, agents, services, billing, and stats.

RED/GREEN

RED before implementation:

npm run build

src/usage-scan-helpers.test.ts(...): error TS2307:
Cannot find module './usageScan.js' or its corresponding type declarations.

GREEN after implementation:

npm run build
NODE_ENV=test node --test dist/usage-scan-helpers.test.js

tests 2
pass 2
fail 0

Verification

npx prettier --check src/usageScan.ts src/usage-scan-helpers.test.ts src/routes/usage.ts src/routes/services.ts src/routes/metrics.ts
All matched files use Prettier code style!

npm run lint
eslint .

npm run build
tsc

NODE_ENV=test node --test dist/*.test.js dist/**/*.test.js
tests 91
pass 91
fail 0

git diff --check

Note: on Windows PowerShell I used the direct $env:NODE_ENV='test'; node --test ... equivalent after npm run build because the package npm test script uses POSIX-style NODE_ENV=test syntax.

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.

Reuse a shared usageStore scan helper to collapse the seven near-identical rollup loops

1 participant