Add tests for the CLI (bin/quak.ts) #12

Open
opened 2026-08-09 03:45:27 +02:00 by clawbot · 0 comments
Collaborator

Problem

bin/quak.ts is 436 lines — the single largest file in the repo — and has zero tests. No
test file imports it. The repo's own README says tests are the canonical documentation and
that main is only green when the suite covers what ships, and the README documents a CLI
contract (exit codes, --json output, session file permissions) that nothing verifies.

Untested behaviour includes:

  • session load and save, including the 0600 file mode and 0700 directory mode;
  • the "not logged in" exit path;
  • every command's argument parsing and exit code;
  • the get / get-thumb search-all-collections loops used when --collection is omitted;
  • the --exif / --all option handling on backup-metadata;
  • the non-zero exit code on partial backup failure that the README's Backup layout section
    documents.

Definition of done

  1. bin/quak.ts is testable without spawning a subprocess and without calling process.exit
    from inside async handlers — refactor the command bodies into functions that return or
    throw, with a thin top-level wrapper that maps results to exit codes. The externally
    visible CLI behaviour does not change.
  2. Tests cover, at minimum: whoami, logout, collections, files, get, get-thumb,
    backup, and helper list-missing-thumbnails, each in both human and --json output
    modes where the command supports --json.
  3. Tests assert the documented exit codes, including the non-zero exit when a backup has
    per-file failures.
  4. Tests assert the session file is created with mode 0600 in a directory with mode 0700,
    and that logout removes it.
  5. Tests assert get/get-thumb find a file by ID across collections when --collection is
    not supplied, and report a clear error when the ID is not found anywhere.
  6. Tests use mkdtempSync for temporary directories and inject a fake session directory
    rather than touching the real one. No test writes to the developer's home directory.
  7. The suite still completes within the 30-second cap enforced by script/test. If it does
    not, say so on this issue rather than raising the cap.
  8. make check green.
  9. TODO.md updated in the same commit.

Note

process.exit() is currently called from nine places inside async handlers, which can
truncate pending stdout writes when output is piped. Item 1 fixes that as a side effect; call
it out explicitly in the PR body.

## Problem `bin/quak.ts` is 436 lines — the single largest file in the repo — and has **zero tests**. No test file imports it. The repo's own README says tests are the canonical documentation and that `main` is only green when the suite covers what ships, and the README documents a CLI contract (exit codes, `--json` output, session file permissions) that nothing verifies. Untested behaviour includes: - session load and save, including the `0600` file mode and `0700` directory mode; - the "not logged in" exit path; - every command's argument parsing and exit code; - the `get` / `get-thumb` search-all-collections loops used when `--collection` is omitted; - the `--exif` / `--all` option handling on `backup-metadata`; - the non-zero exit code on partial backup failure that the README's Backup layout section documents. ## Definition of done 1. `bin/quak.ts` is testable without spawning a subprocess and without calling `process.exit` from inside async handlers — refactor the command bodies into functions that return or throw, with a thin top-level wrapper that maps results to exit codes. The externally visible CLI behaviour does not change. 2. Tests cover, at minimum: `whoami`, `logout`, `collections`, `files`, `get`, `get-thumb`, `backup`, and `helper list-missing-thumbnails`, each in both human and `--json` output modes where the command supports `--json`. 3. Tests assert the documented exit codes, including the non-zero exit when a backup has per-file failures. 4. Tests assert the session file is created with mode `0600` in a directory with mode `0700`, and that `logout` removes it. 5. Tests assert `get`/`get-thumb` find a file by ID across collections when `--collection` is not supplied, and report a clear error when the ID is not found anywhere. 6. Tests use `mkdtempSync` for temporary directories and inject a fake session directory rather than touching the real one. No test writes to the developer's home directory. 7. The suite still completes within the 30-second cap enforced by `script/test`. If it does not, say so on this issue rather than raising the cap. 8. `make check` green. 9. `TODO.md` updated in the same commit. ## Note `process.exit()` is currently called from nine places inside async handlers, which can truncate pending stdout writes when output is piped. Item 1 fixes that as a side effect; call it out explicitly in the PR body.
clawbot added this to the 1.0.0 milestone 2026-08-09 03:45:27 +02:00
clawbot self-assigned this 2026-08-09 03:45:27 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/quak#12