Skip to content

Resolve spec/audit.py's Hub Name Lazily So Importing Scripts Parse Arguments Before Any Read #2829

Closed

Description

@ptr727

Defect

CODESTYLE.md General "Command-Line Arguments", which arrives with #2285, says a command-line script refuses an unrecognized argument with a non-zero exit before any read or write. spec/audit.py resolves its hub name when imported, at module level (HUB_NAME, HUB_NAME_FROM_REMOTE = hub_name()), and hub_name() runs git config --get remote.origin.url. So a script importing spec/audit.py at the top runs that read before argparse ever sees its arguments, --help and an unknown flag included.

The #2285 gate showed this when git was briefly added to its recording stubs. canonical_review.py, spec/audit.py, spec/fidelity_honesty.py, and spec/workflow_reuse.py were the scripts it named. Other scripts also import the module, so the fix should check them all rather than only those four.

Repro

Put a recording git stub first on PATH and run python3 spec/audit.py --bogus-flag from a hub checkout. The stub records a config --get remote.origin.url call before the usage error prints.

Proposed fix

Resolve the hub name lazily, for example with a cached accessor that runs on first use, and replace the module constant's uses with it. Then add git to the commands that tests/test_cli_usage.py records in RECORDED. It is left out today because this read would fail the gate, and adding it means the gate holds every entry point to "before any read" as well.

Context

Found while gating #2285 on feature/auto-2285. The maintainer chose to track it here rather than fix it in that pull request, because the constant has many uses and the change is wider than that pull request's scope.

Activity

  1. added
    bug
    introduced
    script
    on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugintroducedscript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions