Skip to content

fix(insight): reject a non-positive --hours instead of reporting all-time cost - #295

Merged
juninmd merged 1 commit into
masterfrom
claude/insight-hours-validation
Nov 22, 2026
Merged

juninmd merged 1 commit into
masterfrom
claude/insight-hours-validation

Conversation

@juninmd

@juninmd juninmd commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Requested by Antonio · project thread

Summary

Por quê: em pr-insight cost --hours N, o CLI fazia Number(values.hours) sem validar e insight/cost.ts trata valor falso como "sem janela" (cutoff = sinceHours ? ... : 0). Resultado:

  • --hours abc → NaN → soma de todo o histórico, exibida como se fosse das últimas N horas;
  • --hours 0 → mesmo efeito;
  • --hours=-5 → corte no futuro → totais vazios, sem erro.

Quem lê o número para decidir gasto com LLM recebe um valor errado sem aviso.

O que mudou:

  • ts/src/cli/insight.ts: --hours precisa ser número finito > 0; senão imprime --hours must be a positive number e sai com código 2 (o mesmo que o CLI já usa nos outros erros de uso). cost.ts fica intacto.
  • ts/tests/insight.test.ts: roda o CLI com abc, 0 e -5 (espera exit 2 e a mensagem) e com 24 (exit 0).

Quality Checklist

  • User-facing behavior is described clearly.
  • Security impact was considered, including secrets, auth, and data exposure. (nenhum)
  • Performance impact was considered for startup, runtime, bundle size, or query cost. (nenhum)
  • Logs, errors, and operational visibility are useful enough to debug failures.
  • UI changes were checked for keyboard access, responsive layout, and readable states. (N/A)
  • Tests, smoke checks, or manual verification are listed below.

Verification

Como foi verificado

Antes da correção (com o teste novo):

$ cd ts && bun test tests/insight.test.ts
Expected: 2
Received: 0
 1 pass
 1 fail

Depois:

$ bun test tests/insight.test.ts
 2 pass
 0 fail
$ bun test
 293 pass
 0 fail
$ bun run typecheck   -> tsc --noEmit sem erros
$ bun src/cli/insight.ts cost --hours ""
--hours must be a positive number   (exit=2)

Generated by Claude Code

…time cost

`pr-insight cost --hours abc` turned into NaN, which cost.ts treats as
"no window", so all-time totals were printed as if they were the last N
hours; 0 behaved the same and negative values silently returned nothing.
The CLI now exits 2 with a usage message, like its other usage errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn6JQLtmA8NV75CtdV373W
@juninmd juninmd self-assigned this Nov 22, 2026
@juninmd
juninmd merged commit 976eb29 into master Nov 22, 2026
3 checks passed
@juninmd
juninmd deleted the claude/insight-hours-validation branch November 22, 2026 05:14
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