Skip to content

chore: remediate code-review findings (6 issues)#29

Merged
anajuliabit merged 2 commits intomainfrom
chore/code-review-remediation
May 7, 2026
Merged

chore: remediate code-review findings (6 issues)#29
anajuliabit merged 2 commits intomainfrom
chore/code-review-remediation

Conversation

@anajuliabit
Copy link
Copy Markdown
Collaborator

Summary

Remediates 6 findings from a full-repo TypeScript code review.

# Severity File Fix
1 HIGH `query/emissions-due.ts` `parseWei()` helper guards `BigInt()` against JS numbers / scientific notation
2 MEDIUM `query/emissions-due.ts` Per-pod `{ok:true
3 MEDIUM `state/db.ts` `upsertIdempotent` defensive nil-check on legacy `argsFingerprint`
4 LOW `state/{db,idempotency}.ts`, `chain/addresses.ts` Replace `Object.assign(new Error, {code})` with canonical `cliError()`
5 LOW `chain/clients.ts` Remove dead `withTxLock` export
6 LOW `config/load.ts`, `commands/_base.ts` Bare `Error` → `cliError('INVALID_PRIVATE_KEY'

Also bumped vitest `testTimeout` to 20s — `npx tsx` cold-start was exceeding the 5s default in `command-error-paths.test.ts`, causing flake unrelated to these changes (verified by running tests on pristine main).

Test plan

  • `npm run lint` clean
  • `npm run typecheck` clean
  • `npm test` — 99 passing (96 baseline + 3 new tests pinning legacy-fingerprint defensiveness, `INVALID_NETWORK` code, `INVALID_PRIVATE_KEY` code)

🤖 Generated with Claude Code

Six findings from a TypeScript code review:

HIGH — query/emissions-due: BigInt() on a platform-API value that
arrives as a JS number or scientific-notation string (e.g. 1e18) throws
SyntaxError, surfacing as opaque INTERNAL_ERROR. Replace with a guarded
parseWei() helper that falls back to 0n on anything unparseable.

MEDIUM — query/emissions-due: a single pod's /emissions failure
aborted the whole batch via Promise.all. Per-pod outcomes now carry
either ok:true breakdowns or ok:false structured errors so one bad pod
doesn't black-hole the others.

MEDIUM — state/db: upsertIdempotent.argsFingerprint.slice() crashed
on legacy entries (pre-v0.2 cache files). Render a "(legacy)"
placeholder so the IDEMPOTENCY_ARGS_MISMATCH error stays clean even
when called directly bypassing peekIdempotent's earlier legacy guard.

LOW — replace Object.assign(new Error, {code, hint}) with cliError()
in state/db, state/idempotency, chain/addresses (CLAUDE.md canonical
rule).

LOW — config/load + commands/_base: bare `throw new Error(...)` for
user-facing config errors (bad private key, bad network) surfaced as
INTERNAL_ERROR. Replace with cliError('INVALID_PRIVATE_KEY' /
'INVALID_NETWORK') so agents can match programmatically.

LOW — chain/clients: removed dead withTxLock export. Single-process
CLI doesn't need an in-process tx mutex; nextNonce(blockTag:'pending')
is sufficient. Updated module comment.

Also bumped vitest testTimeout to 20s — `npx tsx` cold-start can
exceed the 5s default in command-error-paths.test.ts, causing flake
unrelated to these changes.

Tests: 99 passing (96 baseline + 3 new pinning legacy-fingerprint
defensiveness, INVALID_NETWORK and INVALID_PRIVATE_KEY codes).
Iter-2 reviewer found that parseWei's regex /^-?\d+$/ accepted
negative strings like '-500' as valid bigints. Since claimable
emissions are always non-negative, an adversarial or buggy platform
API response could drag totalDueREPPO below zero. Tighten the regex
to /^\d+$/ and pin the behavior with a unit test.
@anajuliabit anajuliabit merged commit 28a32b3 into main May 7, 2026
4 checks passed
@anajuliabit anajuliabit deleted the chore/code-review-remediation branch May 7, 2026 20:34
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.

1 participant