Skip to content

Harden AutoCTO: input validation, gh error handling, deterministic scan (fixes #1) - #2

Merged
zaidwhy merged 2 commits into
mainfrom
fix/scan-missing-path
Jul 4, 2026
Merged

zaidwhy merged 2 commits into
mainfrom
fix/scan-missing-path

Conversation

@zaidwhy

@zaidwhy zaidwhy commented Jul 4, 2026 •

Copy link
Copy Markdown
Owner

Hardening pass over AutoCTO so it has no soft spots. No new features - every change closes a real crash path or nondeterminism. Test count went 13 -> 32, all offline.

What was fragile

  • Any gh failure crashed with a raw traceback - a nonexistent repo, not being authenticated, no access, a rate limit, or a network blip all raised an uncaught CalledProcessError; TimeoutExpired and malformed JSON were unhandled too. Only GhNotAvailable was caught.
  • report/plan crashed when the Personal LLM core was not installed - the import personal_llm in _llm() was outside any guard, so a fresh clone that skipped the core install got a traceback instead of the documented graceful degradation.
  • primary_language was nondeterministic on ties - max() over a filesystem-ordered dict, so the same repo could report a different primary language across machines.
  • The scan walked into ignored dirs (.git, node_modules, venv) and could abort on a PermissionError in a locked subtree.

Changes

  • github.py: a GhError base (with GhNotAvailable as a subclass) surfaces every failure - bad owner/name, non-positive limit, non-zero exit (with stderr), timeout, spawn failure, unparseable / non-array output - as a readable error.
  • cli.py: _llm() degrades to a stub that reports the reason and never raises; all gh-backed commands catch the broad GhError; report --repo downgrades a fetch failure to a warning and still writes the local report. Also fixes analyze/report silently reports a missing path as an empty repo #1 (missing/non-directory path now errors cleanly with exit 1).
  • repo.py: deterministic primary_language (alphabetical tie-break); os.walk that prunes ignored dirs in place (never descends into them, faster on big repos) and skips unreadable subtrees via onerror.

Tests

  • New test_cli.py: Typer CliRunner asserts exit codes and that no raw traceback leaks on any error path.
  • test_github.py: full failure matrix (missing gh, bad repo, non-zero exit, timeout, bad/non-array JSON, empty output, happy path).
  • test_repo.py: missing path, non-directory, nested-ignore prune, deterministic tie, empty repo.
  • pytest tests/ -q -> 32 passed.

Live-verified

triage on a missing repo and a malformed repo string, report --repo on a missing repo (warns, still writes), and analyze . (venv/.git pruned) - all clean, correct exit codes, no tracebacks.

Fixes #1

zaidwhy and others added 2 commits July 4, 2026 22:52
analyze/report previously printed a normal-looking empty report when given a
path that does not exist, so a typo was indistinguishable from a real but empty
repository. scan_repo now raises FileNotFoundError / NotADirectoryError, and the
analyze, report, and plan commands catch it and exit with a clean one-line error
and a non-zero code. Updated the repo test to assert the new behavior.

Fixes #1

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Staff-engineer audit + repair across every module. No new features; each change
closes a crash path or nondeterminism. Test count 13 -> 32.

github.py: wrap every gh failure (bad repo, auth, network, timeout, unparseable
output) in a readable GhError hierarchy instead of leaking CalledProcessError /
TimeoutExpired / JSONDecodeError; validate owner/name and limit up front.

cli.py: _llm() no longer crashes when the Personal LLM core is absent - it
degrades to a stub that reports why. All gh-backed commands catch the broad
GhError; report --repo downgrades a fetch failure to a warning and still writes
the local report.

repo.py: deterministic primary_language on ties (alphabetical); os.walk that
prunes ignored dirs in place (never descends into .git/node_modules/venv) and
skips unreadable subtrees via onerror instead of aborting.

Tests: new test_cli.py (CliRunner exit codes, no leaked tracebacks), full
gh-failure matrix, determinism + nested-prune cases. 32/32 pass offline.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@zaidwhy
zaidwhy merged commit b893c63 into main Jul 4, 2026
@zaidwhy zaidwhy changed the title Raise on a missing or non-directory path in scan_repo Harden AutoCTO: input validation, gh error handling, deterministic scan (fixes #1) Jul 4, 2026
zaidwhy added a commit that referenced this pull request Sep 28, 2026
Raise on a missing or non-directory path in scan_repo
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.

analyze/report silently reports a missing path as an empty repo

1 participant