Repository navigation
fix(insight): reject a non-positive --hours instead of reporting all-time cost - #295
Merged
Merged
Conversation
…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
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.
Requested by Antonio · project thread
Summary
Por quê: em
pr-insight cost --hours N, o CLI faziaNumber(values.hours)sem validar einsight/cost.tstrata 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:--hoursprecisa ser número finito > 0; senão imprime--hours must be a positive numbere sai com código 2 (o mesmo que o CLI já usa nos outros erros de uso).cost.tsfica intacto.ts/tests/insight.test.ts: roda o CLI comabc,0e-5(espera exit 2 e a mensagem) e com24(exit 0).Quality Checklist
Verification
Como foi verificado
Antes da correção (com o teste novo):
Depois:
Generated by Claude Code