Skip to content

fix(opencode): update stats command to filter messages by creation time#21934

Open
kmampent wants to merge 2 commits intoanomalyco:devfrom
kmampent:fix/stats-day-filter
Open

fix(opencode): update stats command to filter messages by creation time#21934
kmampent wants to merge 2 commits intoanomalyco:devfrom
kmampent:fix/stats-day-filter

Conversation

@kmampent
Copy link
Copy Markdown

Issue for this PR

Closes #21920

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

This PR updates the stats.ts file so that messages outside the time window defined by the value passed for the --days parameter are not considered when reporting usage statistics.

We also add a unit test file for stats.ts with basic unit tests covering the logic addressed in this PR.

How did you verify your code works?

  1. Unit tests that cover the scenarios considered in this PR
  2. bun run test test/cli/cmd/stats.test.ts succeeds
  3. bun run test a the top most folder succeeds as well with the following outcome:
11 tests skipped:
» unicode filenames modification and restore
» file fsmonitor > status does not start fsmonitor for readonly git checks
» file fsmonitor > read does not start fsmonitor for git diffs
» defaults Ctrl+Z to input undo on Windows
» keeps explicit input undo overrides on Windows
» ignores terminal suspend bindings on Windows
» Worktree.remove > stops fsmonitor before removing a worktree
» StructuredOutput Integration > produces structured output with simple schema
» StructuredOutput Integration > produces structured output with nested objects
» StructuredOutput Integration > works with text outputFormat (default)
» StructuredOutput Integration > stores outputFormat on user message


1 tests todo:
✎ Instruction.resolve > fetches remote instructions from config URLs via HttpClient

 1886 pass
 11 skip
 1 todo
 0 fail
 5487 expect() calls
Ran 1898 tests across 153 files. [186.52s]
  1. Built the package and then verified with OPENCODE_DB=/.../opencode.db bun dev stats --days=0 that the output looks as expected. I compared the output reported with the output reported when directly examining the data stored in opencode's database via opencode db.

Screenshots / recordings

I have verified that other than the numbers reported, the graphical output of OPENCODE_DB=/.../opencode.db bun dev stats --days=0 matches that of opencode stats --days=0.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

Both PRs are targeting the same issue and implementing the same fix. You should verify which one should be used or if they need to be consolidated.

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.

Bug: opencode stats --days=X command incorrectly considers messages outside the time window defined by X

1 participant