tests.test_cli module

Conformance of the repomatic.cli package: its lazy table and shared plumbing.

The group imports a command module only when a run needs one of its commands, so the table in repomatic.cli.main is the one place every command is declared. These tests hold that table to the commands it names, and the help sections to the rules that file each command.

tests.test_cli.SECTION_TITLES = ('Project setup', 'Linting & checks', 'Sync', 'Release & versioning', 'GitHub issues & PRs', 'CI & runners', 'Site & docs', 'Forge sampling', 'Tools')

The help sections, in the order the help screen lists them.

tests.test_cli.LOADING_PROBE = 'import importlib\nimport json\nimport sys\n\nfrom repomatic.cli.main import COMMANDS\n\nloaded = sorted(name for name in sys.modules if name.startswith("repomatic.cli."))\nnames = {}\nfor key, spec in COMMANDS.items():\n    module, _, attribute = spec.import_path.rpartition(".")\n    names[key] = getattr(importlib.import_module(module), attribute).name\nprint(json.dumps({"loaded": loaded, "names": names}))\n'

Read the lazy table from a fresh interpreter.

Loading a command through the group renames it after its table key, so only an interpreter that has not loaded any command yet still sees the name Click derived from the callback.

tests.test_cli.test_lazy_table_resolves_from_a_fresh_interpreter()[source]

Each import path names a command whose own name is its table key.

Importing the group loads no command module: a run imports the one module that holds the command it invokes, and the help screen alone imports them all.

tests.test_cli.test_command_module_imports_no_sibling(module)[source]

A command module imports main alone among the CLI modules.

Importing a sibling would load its commands, and all their dependencies, on every run of this module’s commands.

tests.test_cli.test_every_command_is_filed_in_a_section()[source]

No command of the table lands in the catch-all “Other commands” section.

The group itself registers only the help command click-extra adds to every group: click-extra files that one in the default section.

tests.test_cli.test_sync_prefix_decides_the_sync_section(name)[source]

A sync-* command is filed under Sync, and Sync holds nothing else.

tests.test_cli.test_help_lists_the_sections_in_declared_order()[source]

The help screen lists every section, in the order the table declares.

tests.test_cli.test_commands_carry_no_root_option()[source]

A command takes the root options from the group, never declares its own.

The command decorator of click-extra adds them to every command it builds, so a command declared without subcommand shows them all.

tests.test_cli.test_every_output_option_accepts_stdout()[source]

Each --output takes - to print to stdout instead of writing a file.

tests.test_cli.FEATURE_GATE_RE = re.compile('exit_if_disabled\\(ctx, "(?P<key>[\\w.-]+)"\\)')

A command gating itself on a [tool.repomatic] flag, named as a literal.

tests.test_cli.FEATURE_GATES = [('ci.py', 'sync-runner-images.sync'), ('deps.py', 'dependency-graph.update'), ('deps.py', 'vulnerable-deps.sync'), ('github.py', 'labels.sync'), ('github.py', 'setup-guide'), ('release.py', 'binaries.sync'), ('release.py', 'bumpversion.sync'), ('release.py', 'dev-release.sync'), ('release.py', 'github-releases.sync'), ('repo.py', 'gitignore.sync'), ('repo.py', 'mailmap.sync'), ('repo.py', 'metrics.sync')]

Every (module, key) pair the commands gate on.

tests.test_cli.test_feature_gates_are_found()[source]

The scan sees the gates, so the check over them proves something.

tests.test_cli.test_feature_gate_names_a_real_key(module, key)[source]

Every key a command gates on is a [tool.repomatic] setting.

exit_if_disabled reads the flag through Config.is_enabled, which raises on a key it does not know: a typo would break the command on its first run.

tests.test_cli.test_feature_gate_exits_cleanly_when_off(tmp_path, monkeypatch)[source]

A flag switched off in pyproject.toml ends the command with success.

tests.test_cli.test_feature_gate_precedes_repository_detection()[source]

No gated command looks for its repository while Click parses options.

A parameter callback runs before the command body. A --repo that detects the repository of the checkout would refuse to run without one, before the guard could exit 0 on a disabled flag.

tests.test_cli.test_disabled_sync_needs_no_repository(tmp_path, monkeypatch, command, key)[source]

A disabled sync exits 0 with no repository to act on.

tests.test_cli.EXIT_CATCHING_EXCEPTIONS = frozenset({'BaseException', 'Exception', 'RuntimeError'})

Handlers that catch the exceptions ctx.exit() and ctx.abort() raise.

Click’s Exit and Abort subclass RuntimeError. A handler catching one of these takes the exit for a failure: the usual raise ClickException(str(error)) turns ctx.exit(0) into Error: 0 and an exit code of 1.

tests.test_cli.test_caught_exit_scan_finds_the_pattern()[source]

The scan sees a caught exit, so the check over the package proves something.

tests.test_cli.test_no_handler_catches_a_click_exit()[source]

No ctx.exit() or ctx.abort() sits in a try whose handler catches it.

tests.test_cli.OFFLINE_RUN_EXEMPT = {'sync-tool-versions': 'rewrites the tooling/registry.py of the installed package', 'update-checksums': 'rewrites the tooling/registry.py of the installed package'}

Commands the offline run leaves out, each with the reason.

Each one writes to the source of the installed package, which no temporary working directory isolates: under an editable install, the run would rewrite the checkout.

tests.test_cli.LEAF_COMMANDS = (('apply-labels', <Command apply-labels>), ('audit', <Command audit>), ('broken-links', <Command broken-links>), ('bump-version', <Command bump-version>), ('cache clean', <Command clean>), ('cache help', <HelpCommand help>), ('cache path', <Command path>), ('cache show', <Command show>), ('cancel-runs', <Command cancel-runs>), ('changelog', <Command changelog>), ('ci-status', <Command ci-status>), ('cloudflare-pages', <Command cloudflare-pages>), ('cloudflare-r2', <Command cloudflare-r2>), ('create-release', <Command create-release>), ('fix-awesome-toc', <Command fix-awesome-toc>), ('format-images', <Command format-images>), ('git-tag', <Command git-tag>), ('help', <HelpCommand help>), ('init', <Command init>), ('issue', <Command issue>), ('job-timings', <Command job-timings>), ('lint-changelog', <Command lint-changelog>), ('lint-coverage', <Command lint-coverage>), ('lint-deps', <Command lint-deps>), ('lint-repo', <Command lint-repo>), ('list-skills', <Command list-skills>), ('lock-threads', <Command lock-threads>), ('pack-attestation', <Command pack-attestation>), ('pack-binaries', <Command pack-binaries>), ('pack-manpages', <Command pack-manpages>), ('pack-plugin', <Command pack-plugin>), ('pr-body', <Command pr-body>), ('pr-sync', <Command pr-sync>), ('prepare-release', <Command prepare-release>), ('prune-caches', <Command prune-caches>), ('run', <Command run>), ('sample-metrics', <Command sample-metrics>), ('scan-virustotal', <Command scan-virustotal>), ('setup-guide', <Command setup-guide>), ('show-config', <Command show-config>), ('show-metadata', <Command show-metadata>), ('show-test-matrix', <Command show-test-matrix>), ('sponsor-label', <Command sponsor-label>), ('squashed-release', <Command squashed-release>), ('sync-action-pins', <Command sync-action-pins>), ('sync-binaries', <Command sync-binaries>), ('sync-bumpversion', <Command sync-bumpversion>), ('sync-dep-sources', <Command sync-dep-sources>), ('sync-deps', <Command sync-deps>), ('sync-dev-release', <Command sync-dev-release>), ('sync-github-releases', <Command sync-github-releases>), ('sync-gitignore', <Command sync-gitignore>), ('sync-labels', <Command sync-labels>), ('sync-mailmap', <Command sync-mailmap>), ('sync-runner-images', <Command sync-runner-images>), ('sync-tool-versions', <Command sync-tool-versions>), ('sync-uv-lock', <Command sync-uv-lock>), ('sync-workflow-pins', <Command sync-workflow-pins>), ('unsubscribe-threads', <Command unsubscribe-threads>), ('update-checksums', <Command update-checksums>), ('update-dep-graph', <Command update-dep-graph>), ('update-docs', <Command update-docs>), ('verify-binary', <Command verify-binary>), ('wait-pypi', <Command wait-pypi>))

Every command a user can run, with its path.

tests.test_cli.test_offline_run_exempts_only_real_commands()[source]

Each exemption names a command that still exists.

tests.test_cli.test_every_command_ends_cleanly_offline(path, command, tmp_path, monkeypatch, hermetic_git, cache_env)[source]

A command with nothing to act on ends on an error message, not a traceback.

The run starts in an empty directory, with no network, no token and no CI environment, so a command finds no project, no changelog and no answer from any host. Each of those is an expected failure, and a traceback means one of them escaped unhandled.

tests.test_cli.test_write_output_closes_the_file_it_opens(tmp_path, monkeypatch)[source]

The stream opened for an --output path is closed once written.

tests.test_cli.test_write_output_leaves_a_captured_stdout_open(monkeypatch)[source]

The live stdout prep_path hands back for - stays open for later writes.

tests.test_cli.REPO_PROBES = (((<Command repo-probe>,), (), 'parse'), ((<Command deferred-repo-probe>,), (), 'deferred'))

A command resolving --repo while Click parses it, and one in its body.

tests.test_cli.test_repo_option_falls_back_in_order(monkeypatch, probe, args, env, detected, expected)[source]

--repo, then $GITHUB_REPOSITORY, then the repository of the checkout.

tests.test_cli.test_repo_option_refuses_to_run_without_a_repository(monkeypatch, probe)[source]
tests.test_cli.test_upload_without_a_repository_names_the_flag(tmp_path, monkeypatch)[source]

--upload-to with no repository fails before it packs anything.

tests.test_cli.test_upload_refused_by_gh_ends_on_its_error(tmp_path, monkeypatch)[source]

An upload gh refuses ends the command on the error gh gave.

tests.test_cli.test_pack_commands_print_the_archive_they_write(tmp_path, monkeypatch)[source]

--output - prints the bytes each packer writes to a file.

tests.test_cli.test_refused_bump_names_the_pull_requests_it_closed(monkeypatch, closed, reported)[source]

A bump the version already moved past reports each stale PR it closed.

tests.test_cli.test_allowed_bump_reports_the_step_that_ended_it(monkeypatch, seam, outcome, exit_code, message)[source]

Each step of an allowed bump ends the run on its own error.

A branch left as it was names no pull request.

tests.test_cli.test_show_metadata_warns_only_over_content(tmp_path, content, warned)[source]
tests.test_cli.test_show_metadata_keeps_a_file_holding_content(tmp_path)[source]

--no-overwrite refuses a target that already holds content.

tests.test_cli.test_show_metadata_messages_on_a_stdout_run(args, exit_code, message)[source]

A stdout run lists the keys, refuses an unknown one, or drops --overwrite.

tests.test_cli.test_show_metadata_in_ci_warns_off_the_step_output(tmp_path, monkeypatch, github_output, warned)[source]

In CI, a target other than $GITHUB_OUTPUT earns a warning.

tests.test_cli.test_init_completes_components_then_their_files(incomplete, expected)[source]

Shell completion offers component names, then the files of the one typed.

tests.test_cli.test_init_rejects_an_unknown_selector(tmp_path, monkeypatch)[source]

A selector naming no component fails the parse, before any file is written.

tests.test_cli.test_group_publishes_the_config_it_resolved(tmp_path, monkeypatch)[source]

Library helpers see the config --config names, not ./pyproject.toml.

The group callback publishes the resolved config for the duration of the command, then clears the slot.

tests.test_cli.RELEASED_CHANGELOG = '# Changelog\n\n## [`1.0.0` (2026-03-04)](https://github.com/kiwi/orchard/compare/v0.9.0...v1.0.0)\n\n- Plant the first row of apple trees.\n'

A changelog whose newest section is released, so changelog opens the next.

tests.test_cli.relocated_changelog(tmp_path, monkeypatch)[source]

A project keeping its changelog away from the default changelog.md.

tests.test_cli.test_changelog_writes_in_place_at_the_configured_location(relocated_changelog)[source]

The new section lands in changelog.location, not in ./changelog.md.

tests.test_cli.test_changelog_in_place_is_idempotent(relocated_changelog)[source]
tests.test_cli.test_changelog_prints_on_dash_and_leaves_the_file(relocated_changelog)[source]
tests.test_cli.test_create_release_reports_what_the_draft_hit(tmp_path, monkeypatch, version, args, gh, exit_code, message)[source]

An existing release, a version with no notes and a gh failure each say so.