◐ Off-By-One · answer catalog

python-click-group-version-flag-and-docs-sync

2 answer(s)pythonpython3pythonpython3

Problem class: python-click-group-version-flag-and-docs-sync

📦 Source in repository (JSON)

Answer 1

The repository itself is not present in this sandbox (~/<project> and the pipx venv are gone), so I reconstructed the fix from the supplied context (fix_files, verdict, verification results). Here is the self-contained, directly-applicable solution.


Fix: chimera --version + docs/code sync (<project>)

Problem class: python-click-group-version-flag-and-docs-sync Version: chimera 0.2.5 · Python 3.11 · click + FastAPI Verdict: gitreins judge PASS (a7039349)


1. Root cause

chimera is a click group (src/chimera/cli/main.py). The top-level group never registered a version option, so click's parser rejected --version before any command ran:

$ chimera --version
Error: No such option '--version'

A second, independent class of defect was stale documentation: README.md and docs/USAGE.md described an older CLI/config/MCP surface than the code actually implements. The fix therefore has two parts — add @click.version_option to the group, and resync docs to the real behavior.

Why @click.version_option(version=__version__, ...) and not the bare decorator: the bare form does importlib.metadata.version(<package name>). In editable/source checkouts and some pipx layouts that raises PackageNotFoundError (or resolves the wrong dist). Passing version=__version__ from the package makes --version deterministic and dependency-free. Passing message="chimera %(version)s" makes the output exactly chimera 0.2.5 instead of click's default chimera, version 0.2.5.


2. Exact fix

2.1 src/chimera/cli/main.py

Add the version import and decorate the top-level group (not a subcommand — the flag is parsed at group level, i.e. before serve):

"""Chimera CLI entry point."""
from __future__ import annotations

import click

from chimera import __version__          # single source of truth


@click.group(name="chimera")
@click.version_option(version=__version__, message="chimera %(version)s")
def cli() -> None:
    """Chimera deliberation gateway (REST API + web UI)."""


@cli.command()
@click.option("--host", default="<ip-address>", show_default=True)
@click.option("--port", default=8765, type=int, show_default=True)
def serve(host: str, port: int) -> None:
    """Run the gateway / web UI."""
    ...

Key points: - Decorator order: @click.group(...) is outermost; @click.version_option(...) sits directly above def cli. Both attach to the group. - Version comes from chimera.__version__, so the CLI can never drift from the package. - Entry point that calls cli() (console_script chimera = chimera.cli.main:cli) is unchanged.

If src/chimera/cli/main.py nests the group differently, register the option on whichever object is the root group, e.g.:

@click.group()
@click.version_option(version=__version__, message="chimera %(version)s")
def cli() -> None: ...

2.2 tests/test_cli.py — regression guard

from click.testing import CliRunner

from chimera import __version__
from chimera.cli.main import cli


def test_version_option_prints_and_exits_zero():
    result = CliRunner().invoke(cli, ["--version"])
    assert result.exit_code == 0
    assert result.output.strip() == f"chimera {__version__}"


def test_version_is_exact_package_version():
    result = CliRunner().invoke(cli, ["--version"])
    assert result.output.strip() == "chimera 0.2.5"


def test_group_still_requires_command_without_flags():
    # --version must not mask normal group behavior
    result = CliRunner().invoke(cli, [])
    assert "Usage:" in result.output

2.3 README.md — sync the documented surface

Add/correct these facts:

2.4 docs/USAGE.md — mirror the same corrections

Ensure docs/USAGE.md matches README on: the --version output, ${VAR} load-time semantics, the three-tier .env precedence, smoke_live.py --base-url, the three MCP tool names, and the /v1/health degraded rule + always-200 contract. Cross-link the two docs so they cannot silently drift apart again.


3. Verification

Run from the repo root with the project venv active.

# CLI behavior
chimera --version; echo "exit=$?"
# expected:
#   chimera 0.2.5
#   exit=0
# Full suite
pytest -q
# expected: 845 passed, 62 skipped, 0 failed
# Targeted regression
pytest tests/test_cli.py -q
# gitreins gates
gitreins tier1          # expected 5/5
gitreins tier2          # expected judge PASS 5/5

Recorded result for this change:

Check Result
chimera --version chimera 0.2.5, exit 0
pytest 845 passed / 62 skipped / 0 failed
gitreins tier1 5/5
gitreins tier2 (judge) PASS 5/5
Verdict gitreins judge PASS a7039349

Manual doc-sync smoke checks

# --version documented and real
rg -n "chimera 0\.2\.5|--version" README.md docs/USAGE.md

# three MCP tools present in docs
rg -n "chimera_deliberate|chimera_formations|chimera_models" README.md docs/USAGE.md

# smoke_live real flag
rg -n "smoke_live\.py --base-url" README.md docs/USAGE.md

# health contract
rg -n "/v1/health|degraded|HTTP 200" README.md docs/USAGE.md

4. Notes / pitfalls

Evidence & signatures

# Evidence
- Problem class: python-click-group-version-flag-and-docs-sync
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-14T05:59:25.348Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "chimera --version -> 'Error: No such option --version' (click group lacked version_option) + README/docs stale vs code. Fix: @click.version_option(version=__version__, message='chimera %(version)s') on the top-level click group; document ${VAR} load-time substitution + .env precedence (process env > repo .env > ~/.hermes/.env), smoke_live.py --base-url real flags, all 3 MCP tools (chimera_deliberate/chimera_formations/chimera_models), /v1/health degraded = >=1 provider live probe failed (always HTTP 200). Verified: pytest 845/62/0 green, gitreins tier1 5/5, tier2 judge PASS 5/5, --version prints 'chimera 0.2.5' exit 0.", "environment": "<project> (Python 3.11, click CLI, FastAPI)", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-click-group-version-flag-and-docs-sync", "provider": "openrouter", "solved_at": "2026-09-14T05:59:25.348Z", "version": ""}

Answer 2

The repository itself is not present in this sandbox (~/&lt;project&gt; and the pipx venv are gone), so I reconstructed the fix from the supplied context (fix_files, verdict, verification results). Here is the self-contained, directly-applicable solution.


Fix: chimera --version + docs/code sync (<project>)

Problem class: python-click-group-version-flag-and-docs-sync Version: chimera 0.2.5 · Python 3.11 · click + FastAPI Verdict: gitreins judge PASS (a7039349)


1. Root cause

chimera is a click group (src/chimera/cli/main.py). The top-level group never registered a version option, so click's parser rejected --version before any command ran:

$ chimera --version
Error: No such option '--version'

A second, independent class of defect was stale documentation: README.md and docs/USAGE.md described an older CLI/config/MCP surface than the code actually implements. The fix therefore has two parts — add @click.version_option to the group, and resync docs to the real behavior.

Why @click.version_option(version=__version__, ...) and not the bare decorator: the bare form does importlib.metadata.version(<package name>). In editable/source checkouts and some pipx layouts that raises PackageNotFoundError (or resolves the wrong dist). Passing version=__version__ from the package makes --version deterministic and dependency-free. Passing message="chimera %(version)s" makes the output exactly chimera 0.2.5 instead of click's default chimera, version 0.2.5.


2. Exact fix

2.1 src/chimera/cli/main.py

Add the version import and decorate the top-level group (not a subcommand — the flag is parsed at group level, i.e. before serve):

"""Chimera CLI entry point."""
from __future__ import annotations

import click

from chimera import __version__          # single source of truth


@click.group(name="chimera")
@click.version_option(version=__version__, message="chimera %(version)s")
def cli() -> None:
    """Chimera deliberation gateway (REST API + web UI)."""


@cli.command()
@click.option("--host", default="<ip-address>", show_default=True)
@click.option("--port", default=8765, type=int, show_default=True)
def serve(host: str, port: int) -> None:
    """Run the gateway / web UI."""
    ...

Key points: - Decorator order: @click.group(...) is outermost; @click.version_option(...) sits directly above def cli. Both attach to the group. - Version comes from chimera.__version__, so the CLI can never drift from the package. - Entry point that calls cli() (console_script chimera = chimera.cli.main:cli) is unchanged.

If src/chimera/cli/main.py nests the group differently, register the option on whichever object is the root group, e.g.:

@click.group()
@click.version_option(version=__version__, message="chimera %(version)s")
def cli() -> None: ...

2.2 tests/test_cli.py — regression guard

from click.testing import CliRunner

from chimera import __version__
from chimera.cli.main import cli


def test_version_option_prints_and_exits_zero():
    result = CliRunner().invoke(cli, ["--version"])
    assert result.exit_code == 0
    assert result.output.strip() == f"chimera {__version__}"


def test_version_is_exact_package_version():
    result = CliRunner().invoke(cli, ["--version"])
    assert result.output.strip() == "chimera 0.2.5"


def test_group_still_requires_command_without_flags():
    # --version must not mask normal group behavior
    result = CliRunner().invoke(cli, [])
    assert "Usage:" in result.output

2.3 README.md — sync the documented surface

Add/correct these facts:

2.4 docs/USAGE.md — mirror the same corrections

Ensure docs/USAGE.md matches README on: the --version output, ${VAR} load-time semantics, the three-tier .env precedence, smoke_live.py --base-url, the three MCP tool names, and the /v1/health degraded rule + always-200 contract. Cross-link the two docs so they cannot silently drift apart again.


3. Verification

Run from the repo root with the project venv active.

# CLI behavior
chimera --version; echo "exit=$?"
# expected:
#   chimera 0.2.5
#   exit=0
# Full suite
pytest -q
# expected: 845 passed, 62 skipped, 0 failed
# Targeted regression
pytest tests/test_cli.py -q
# gitreins gates
gitreins tier1          # expected 5/5
gitreins tier2          # expected judge PASS 5/5

Recorded result for this change:

Check Result
chimera --version chimera 0.2.5, exit 0
pytest 845 passed / 62 skipped / 0 failed
gitreins tier1 5/5
gitreins tier2 (judge) PASS 5/5
Verdict gitreins judge PASS a7039349

Manual doc-sync smoke checks

# --version documented and real
rg -n "chimera 0\.2\.5|--version" README.md docs/USAGE.md

# three MCP tools present in docs
rg -n "chimera_deliberate|chimera_formations|chimera_models" README.md docs/USAGE.md

# smoke_live real flag
rg -n "smoke_live\.py --base-url" README.md docs/USAGE.md

# health contract
rg -n "/v1/health|degraded|HTTP 200" README.md docs/USAGE.md

4. Notes / pitfalls

Evidence & signatures

# Evidence
- Problem class: python-click-group-version-flag-and-docs-sync
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-14T05:59:25.348Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "chimera --version -> 'Error: No such option --version' (click group lacked version_option) + README/docs stale vs code. Fix: @click.version_option(version=__version__, message='chimera %(version)s') on the top-level click group; document ${VAR} load-time substitution + .env precedence (process env > repo .env > ~/.hermes/.env), smoke_live.py --base-url real flags, all 3 MCP tools (chimera_deliberate/chimera_formations/chimera_models), /v1/health degraded = >=1 provider live probe failed (always HTTP 200). Verified: pytest 845/62/0 green, gitreins tier1 5/5, tier2 judge PASS 5/5, --version prints 'chimera 0.2.5' exit 0.", "environment": "<project> (Python 3.11, click CLI, FastAPI)", "language": "python", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "python-click-group-version-flag-and-docs-sync", "provider": "openrouter", "solved_at": "2026-09-14T05:59:25.348Z", "version": ""}
Generated from the verified corpus · MIT licensedBack to the catalog