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

Open
opened 2026-08-09 03:45:27 +02:00 by clawbot · 2 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
Author
Collaborator

Implementer brief (branch next2)

bin/quak.ts is now 502 lines, with 8 process.exit calls. test/cli/ already tests the output helpers and the backup, metadata-backup and read paths (backup.test.ts, metadata-backup.test.ts, output.test.ts, read.test.ts). Build on those; do not duplicate them. Session loading and saving, and the missing-versus-corrupt session report from #10, are now in bin/quak.ts. Keep them as they are and cover them.

Definition of done: as in the issue body, with these points made precise:

  • Commands become plain functions that take their options, an output stream and a session directory, and return an exit code or throw. One small wrapper maps that result to process.exitCode. Nothing below the wrapper calls process.exit.
  • Output for every command stays byte-identical. This is the rule written at the top of src/cli-output.ts.
  • Use a fake API client. Tests make no network calls and never touch the real session directory.
  • If the suite goes past the 30-second cap, stop and say so on the issue. Do not raise the cap.

Model: opus-5-5

## Implementer brief (branch `next2`) `bin/quak.ts` is now 502 lines, with 8 `process.exit` calls. `test/cli/` already tests the output helpers and the backup, metadata-backup and read paths (`backup.test.ts`, `metadata-backup.test.ts`, `output.test.ts`, `read.test.ts`). Build on those; do not duplicate them. Session loading and saving, and the missing-versus-corrupt session report from https://git.eeqj.de/sneak/quak/issues/10, are now in `bin/quak.ts`. Keep them as they are and cover them. Definition of done: as in the issue body, with these points made precise: - Commands become plain functions that take their options, an output stream and a session directory, and return an exit code or throw. One small wrapper maps that result to `process.exitCode`. Nothing below the wrapper calls `process.exit`. - Output for every command stays byte-identical. This is the rule written at the top of `src/cli-output.ts`. - Use a fake API client. Tests make no network calls and never touch the real session directory. - If the suite goes past the 30-second cap, stop and say so on the issue. Do not raise the cap. Model: opus-5-5
Author
Collaborator

Implemented in #86. The commands are now plain functions in src/cli-commands.ts, tested in test/cli/commands.test.ts with a fake client. Not covered: login, and the --exif/--all options on backup-metadata.

Model: opus-5-5

Implemented in https://git.eeqj.de/sneak/quak/pulls/86. The commands are now plain functions in `src/cli-commands.ts`, tested in `test/cli/commands.test.ts` with a fake client. Not covered: `login`, and the `--exif`/`--all` options on `backup-metadata`. Model: opus-5-5
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/quak#12