Skip to content

test(admin): add unit test suite for buzz-admin CLI - #2608

Open
SeanGearin wants to merge 1 commit into
block:mainfrom
SeanGearin:test-buzz-admin-coverage
Open

test(admin): add unit test suite for buzz-admin CLI#2608
SeanGearin wants to merge 1 commit into
block:mainfrom
SeanGearin:test-buzz-admin-coverage

Conversation

@SeanGearin

Copy link
Copy Markdown
Contributor

Problem

crates/buzz-admin (the operator CLI: membership management, migrations,
channel reconciliation) had zero tests. Its pure logic — role validation,
pubkey parsing/normalization, the NIP-43 same-second-domination timestamp
bump, and the clap argument surface — was only exercised manually against a
live deployment.

Fix

Adds a #[cfg(test)] unit test module (no Postgres, no Redis, no network)
covering:

  • clap definitionCli::command().debug_assert() (same pattern as
    buzz-cli's cli_definition_is_valid), plus parse tests for every
    subcommand's argument surface: add-member role default + required
    --pubkey, remove-member optional role filter, product-feedback list
    limit default (100) and 1..=1000 range enforcement, reconcile-channels
    optional --relay-key, unknown-subcommand rejection.
  • validate_role — accepts member/admin; rejects owner with the
    RELAY_OWNER_PUBKEY hint; rejects unknown/case-mismatched roles with the
    offending role named in the error.
  • parse_pubkey_hex — hex round-trip, npub decoding, uppercase-hex
    normalization to lowercase, garbage and truncated-hex rejection (error
    echoes the input). Fixtures are derived from a fixed secret key at test
    time, so no hard-coded pubkey constants can drift.
  • bumped_created_at — the kind:13534 same-second domination guard
    documented in the module header. The max(now, newest_existing + 1s)
    expression is extracted from publish_membership_list_with_bump into a
    named pure function (byte-identical behavior, same call site) so the four
    cases are testable: no existing list, older existing, same-second
    collision, and backwards clock skew.

The only production-code change is that six-line extraction; no behavior
changes.

The suite is wired into just test-unit (both the cargo-nextest branch and
the scripts/run-tests.sh fallback), so it gates CI's unit job and the
lefthook pre-push hook rather than running only on a manual
cargo test -p buzz-admin. Happy to drop those two lines and leave the
wiring to a follow-up if you'd rather keep this PR test-only.

Test evidence

cargo fmt -p buzz-admin -- --check          # clean
cargo clippy -p buzz-admin --all-targets -- -D warnings   # clean
cargo test -p buzz-admin                    # 21 passed; 0 failed
just test-unit                              # fallback path; "buzz-admin unit
                                            # tests" step runs the 21 tests

(cargo-nextest is not installed in this environment, so just test-unit
exercised the run-tests.sh fallback branch end-to-end; the nextest line
mirrors the existing per-package invocations.)

@SeanGearin
SeanGearin requested a review from a team as a code owner July 23, 2026 20:13
Signed-off-by: Sean Gearin <sgearin@gmail.com>
@SeanGearin
SeanGearin force-pushed the test-buzz-admin-coverage branch from 58a4c01 to 8ce7e94 Compare July 23, 2026 20:20
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