Skip to content

Add meili get stats - #34

Merged
curquiza merged 1 commit into
mainfrom
get-stats-command
Oct 28, 2026
Merged

curquiza merged 1 commit into
mainfrom
get-stats-command

Conversation

@curquiza

@curquiza curquiza commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

What

Add meili get stats, the two routes GET /stats and GET /indexes/{index_uid}/stats.

Contract

  • The command name and flags derive from its routes by the naming rules of docs/contract/commands.md, and each route is reachable by a distinct set of flags, or the exception is recorded with its reason (or this pull request changes the contract and nothing else)
  • Output goes through src/lib/output.ts, errors through src/lib/errors.ts
  • The command never waits for a human: no prompt, no question, no $EDITOR; a delete command spreads BaseCommand.confirmFlags and its examples carry --yes
  • The command never speaks HTTP itself: the SDK or the generated client only, no fetch outside src/lib/clients/

Tests

  • --help snapshot added or updated on purpose
  • JSON output snapshot for one success case per route and one error case
  • Integration test added (Meilisearch API commands only)
  • pnpm lint, pnpm typecheck, pnpm test pass locally

Simplicity

  • Nothing in the diff exists for a case the API cannot produce, a caller that does not exist, or a generality nobody asked for (rule 16)
  • Anything shared lives in src/lib/, is used by this command, and is named below

Docs

  • docs/contract/ updated for every name, flag, variable or code this change adds or renames, or nothing to update
  • The ADRs that touch this change were read; what they decide still holds, or a new ADR says what changed
  • No accepted ADR was edited. A new ADR was added if a decision changed.

Housekeeping

  • oclif.manifest.json regenerated
  • Changeset added, or the change is invisible to users of the package (docs of this repository, tests, CI)
  • New dependency justified below, or none added

Notes for the reviewer

One shared piece and one contract test changed. Both are below, read them first.

  1. fetchStats in src/lib/clients/meilisearch.ts, next to fetchDocuments. getStats() of meilisearch-js sends no query parameter, so neither showInternalDatabaseSizes nor sizeFormat can reach the API through it, and rule 6 asks for a flag per query parameter. ADR 0003 covers exactly this: the fix goes to the SDK first, and the CLI uses client.httpRequest meanwhile. That is what fetchDocuments already does for the fetch route, three lines above. The helper returns the body untyped on purpose: with sizeFormat=human the sizes are strings where Stats and IndexStats declare numbers, so a cast would claim something false. Happy to open the meilisearch-js issue and link it here if you want the pointer in the comment.

  2. --index is optional, so the contract test had to stop requiring every parent path flag. test/contract/api.test.ts asked that a parent path parameter be required, which would have made --index mandatory and GET /stats unreachable, while the routes table of commands.md has documented meili get stats [--index <index>] since the first version. The contract file wins, so the test now applies to a parent flag the rule it already applied to --id: required only when every route of the command takes it. Rule 4 of commands.md says it in words now, and the two lines of .claude/skills/add-command/SKILL.md that described the old behaviour follow. No other command changes: --index stays required on every command whose routes all take it, and the test still fails if one of them drops it.

  3. The two query parameters are sent only when given. --size-format is the closed list the document declares, raw or human, so oclif refuses anything else with cli_usage before the call; --show-internal-database-sizes is a bare boolean. The unit test pins the query string of both routes, /stats with nothing and /indexes/movies/stats?showInternalDatabaseSizes=true&sizeFormat=human, and the integration test checks that human really turns indexSize into a string.

  4. Four paths left PLANNED_PATHS of test/contract/docs.test.ts. The skill has always used get stats as its worked example, so its four paths were listed as planned; the test fails when a planned path appears, which is how it asked to be updated here. That is the whole of the diff in that file.

Ran the simplify skill on the diff. Reuse, simplification and efficiency found nothing. Altitude found two things in the relaxed test, both applied: generalising the check had dropped the guard that a parent flag exists at all, since flags[flag]?.required === true is false for a flag that is optional and for one that is not declared, so the loop now asserts toBeDefined() first, as the --id block below it does; and the snippet of the skill still spelled Flags.string({ required: true, ... }) next to the sentence that had just stopped saying always, so it now reads required: true only when every route takes it.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added meili get stats to view statistics for a Meilisearch instance or a specific index.
    • Choose human-readable or raw size output, and optionally include internal database sizes when retrieving statistics.
  • Documentation

    • Clarified when parent-resource flags are required or optional in command documentation.

…one index

`--index` selects the route of one index, and its absence the one of the
whole instance, as rule 3 of the command contract says. The two query
parameters of the routes, `--show-internal-database-sizes` and
`--size-format`, travel through `fetchStats` in `src/lib/clients/`:
`getStats` of meilisearch-js sends none, and ADR 0003 allows
`client.httpRequest` until the SDK takes them, as `fetchDocuments` does.

The contract test asked that every parent path flag be required, which
would have made `--index` mandatory and `GET /stats` unreachable, while the
routes table has documented `meili get stats [--index <index>]` since the
first version. It now applies to a parent flag the rule it already applied
to `--id`: required only when every route of the command takes it. Rule 4
says it in words, and the skill follows.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: f9cf3999-4481-42b6-9939-b5369e0cc3a2
Commits

Reviewing files that changed from the base of the PR and between 39bc99b and 57e0532.

Files ignored due to path filters: 3
  • test/commands/get/__snapshots__/stats.test.ts.snap is excluded by !**/*.snap
  • test/contract/__snapshots__/commands.test.ts.snap is excluded by !**/*.snap
  • test/contract/__snapshots__/help.test.ts.snap is excluded by !**/*.snap
Files selected for processing: 11
  • .changeset/first-version.md
  • .claude/skills/add-command/SKILL.md
  • docs/contract/commands.md
  • oclif.manifest.json
  • src/commands/get/stats.ts
  • src/lib/clients/meilisearch.ts
  • test/commands/get/stats.test.ts
  • test/contract/api.test.ts
  • test/contract/docs.test.ts
  • test/helpers/meilisearch-handlers.ts
  • test/integration/meilisearch/get-stats.test.ts
Files with no reviewable changes: 1
  • test/contract/docs.test.ts

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour.

Walkthrough

The CLI adds meili get stats for instance-wide or index-specific statistics. The command supports optional index selection, internal database sizes, and raw or human-readable size formatting. The command contract and related documentation now describe when parent-resource flags are required.

Changes: Statistics command

Layer / File(s) Summary
Parent flag contract
.claude/skills/add-command/SKILL.md, docs/contract/commands.md, test/contract/api.test.ts
The guidance and contract test require a parent-resource flag only when every route in the command uses it.
Statistics retrieval
oclif.manifest.json, src/commands/get/stats.ts, src/lib/clients/meilisearch.ts, .changeset/first-version.md
The new command requests global or index statistics. It forwards optional size-format and internal-database-size options, and the release note documents the command.
Command and API tests
test/commands/get/stats.test.ts, test/helpers/meilisearch-handlers.ts, test/integration/meilisearch/get-stats.test.ts, test/contract/docs.test.ts
Tests cover command output, request parameters, API errors, and real-instance statistics. The docs contract test removes the new command paths from its planned-path list.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant GetStats
  participant fetchStats
  participant MeilisearchAPI
  CLI->>GetStats: Run with optional index and size flags
  GetStats->>fetchStats: Pass index and query options
  fetchStats->>MeilisearchAPI: GET /stats or /indexes/{index_uid}/stats
  MeilisearchAPI-->>fetchStats: Return statistics
  fetchStats-->>GetStats: Return statistics
  GetStats-->>CLI: Output statistics
Loading

Possibly related PRs

  • meilisearch/cli#30: Adds get settings with a required index flag, which the updated command contract uses as an example.
Merge Risk: Minimal · up to 57e05

The statistics command is ready to merge after normal checks; no blocking issue was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Add meili get stats" names the main change. The PR adds the meili get stats command, which calls GET /stats and GET /indexes/{index_uid}/stats, with the --index, `--show-internal-…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within survi…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Add meili get stats" names the main change. The PR adds the meili get stats command, which calls GET /stats and GET /indexes/{index_uid}/stats, with the --index, --show-internal-database-sizes, and --size-format options. The title is short, specific, and free of noise. It does not mention the contract-test or docs changes, which is acceptable because they are secondary to the main feature.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 6 files. (4 skipped: 4 unsupported.)

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@curquiza
curquiza merged commit 72b1094 into main Oct 28, 2026
3 checks passed
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