feat(cli): add checks list/get commands with typed formatters#1233
feat(cli): add checks list/get commands with typed formatters#1233MichaelHogers merged 22 commits intomainfrom
Conversation
Add `checkly checks list` and `checkly checks get` commands with REST clients, formatters, and e2e tests. Formatters use typed field definitions (DetailField, ColumnDef) with generic renderDetailFields/renderTable primitives, defining fields once and rendering them for both terminal and markdown output formats.
- Extract appendErrors/appendAssets helpers in check-result-detail - Collapse duplicated formatBody try/catch branches - De-duplicate Tags column definition in checks table - Simplify formatCheckType to pass-through - Use stripAnsi/formatDate in get.ts instead of inline regex/formatting
78aeeb3 to
482d32e
Compare
…tive checks - Replace this.exit(1) with process.exitCode = 1 to avoid oclif's global handler printing the error a second time - Exclude inactive checks from --status filter results - Extract filterByStatus() and add unit tests
Add .catch() fallbacks for check-statuses and check-groups API calls so accounts with no checks don't crash with a 404.
Test checks list and get commands against an account with no checks to verify graceful handling of empty responses and 404 fallbacks.
…nfig - Add markdown output branch to showErrorGroupDetail (was rendering terminal/chalk output regardless of --output flag) - Switch empty account e2e tests to use node-config pattern with describe.skipIf for graceful skipping when creds aren't set - Add emptyApiKey/emptyAccountId to e2e config default.js - Document optional empty account test setup in e2e README
|
checking something with totals not adding up as expected, monitors causing some funniness in the counting |
Show per-type counts (e.g. BROWSER: 140 API: 77 ...) on a dim line below the status summary. Filters by activeCheckIds so the subcounts sum to the displayed total.
|
@sorccu could you give this an initial review please? 🙇 |
|
@sorccu what do you typically do with CLI releases? do we best first dogfood these type of changes? |
thebiglabasky
left a comment
There was a problem hiding this comment.
I think it's fine, though also believe there could be a case for already centralizing some elements that'll be common across most commands like pagination, command output parameter, or formatting.
The second point is regarding the contract, though I think we could go with this first and refactor later to move the definitions you have there into the contract package.
This made me wonder if by "contract" we wouldn't actually mean a TS SDK that we'd import both from the CLI and webapp and would act as the actual contract against the openapi spec from the BE API.
|
thanks @thebiglabasky going through the comments now (on the formatting side i didn't feel super strongly about the code, because it is bound to change and nothing depends directly on that for a while) |
@thebiglabasky the way i've done this before is:
*: we need to also build some tooling to check that older contracts still work against latest backend, this could be by validating the contracts directly or simply e2e suits between the range of versions of clients and latest backend, probably former is easiest |
I was thinking this but then wondered why we'd actually bother to separate all these things since it's all TypeScript in the end, so having all the openapi, types and even handy wrapping call methods in a single package suddenly looked appealing to me: so you don't even bother with the API endpoint and structure, it's all typed through the SDK. The openapi part becomes the elements used by the backend and for docs. |
|
Note for self: came back from the SDK idea, and now sold on sticking to only zod so we can generate the openapi spec, and get runtime validation all in a single place |
Replace client-side filtering that fetched all checks (5+ API calls for large accounts) with server-side query params on GET /v1/checks. The command now makes just 2 API calls regardless of filters applied. Remove --status flag (not supported server-side), client-side filter helpers (filterByStatus, buildActiveCheckIds), and their tests.
Extract shared outputFlag factory to flags.ts. Also improve e2e test assertions per PR review feedback.
oclif auto-discovers all files in the commands directory as commands, causing flags.ts to be registered as checks:flags. Move to src/flags/.
Move flags.ts back to commands/checks/ where it belongs and configure oclif to skip files named flags.* via globPatterns negation.
Revert oclif globPatterns config and move flags.ts to src/helpers/ where it won't interfere with oclif command discovery.
|
@thebiglabasky finished now with feedback and some improvements @sorccu could use some pointers on how to do the release now and in the future, sent slack msg as well |
The --status flag was removed in 372cbe2 when we moved to server-side filtering, but this test was left behind causing CI failures.
|
I noticed tests are failing — they were still using the --status flag which was removed in 372cbe2 when we moved to server-side filtering. I've cleaned up the failing test in 80ecd78. otherwise, in a separate agent session I'm looking into adding status filtering to the public API so we can re-enable --status in the CLI as a proper server-side filter, this should be a low complexity change. TLDR: we can merge this, but i am looking at adding a status filter to our public api endpoint in the meantime, it is quite useful to have @sorccu i still need some instructions on how we publish our CLI! 🙏 |
Summary
Add
checkly checks listandcheckly checks getCLI commands for viewing checks, results, and error groups from the terminal.DetailField<T>,ColumnDef<T>) — fields defined once, rendered for both terminal and markdownAlso adds a new e2e testing account with no checks, representing a new user, to cover any potential edge cases we may miss in our own e2e prod account.
Test plan
vitest --run src/formatters/__tests__/ src/commands/checks/__tests__/— 115 tests passchecks-list.spec.ts,checks-get.spec.ts(require prod env)