Repository navigation
feat: add repo-map schema models + validation envelope - #222
Merged
Merged
Conversation
First implementation slice under the QA-native repo-understanding epic. Locks the .sumo-qa/ repo-map artifact contract so downstream slices (generator, diff-impact, MCP/CLI, report) have a stable, schema-validated shape to build against — without committing to a generator yet. Adds: - sumo_qa.repo_map_models: Pydantic models for project / nodes / edges / commands / warnings, with schema_version pinned to "1.0" and a small Literal vocabulary for node, edge, command, and warning kinds. extra fields rejected via ConfigDict(extra="forbid"). - sumo_qa.repo_map_validation: load_repo_map(dict | Path | str) returning a validated RepoMap. RepoMapValidationError carries a stable `kind` (malformed_json | schema_version_mismatch | missing_field | unknown_field | type_error | io_error) plus the failing JSON path, so consumers can branch on the category rather than parsing free-form messages. schema_version_mismatch fires before Pydantic so a stale artifact is surfaced as stale, not as a generic literal-type error. - tests/fixtures/repo_map/repo-map.example.json: round-trip-tested example artifact covering every first-slice node kind. - docs/REPO-MAP.md: schema reference + commit-vs-cache guidance. 54 new tests; both new modules at 100% coverage. Full suite (1042 passed) remains at 100%. Refs #154.
Schema-contract tightening surfaced by adversarial review. All slice-1 contract; locking now is cheaper than expanding the kind taxonomy or schema-version-bumping later. - Drop `command_runs` from the EdgeType Literal: commands have no stable id field yet, so edges addressing them would invent endpoint conventions. Returns once the generator slice defines command ids. - Require `project.generated_at` to be timezone-aware (custom validator). Naive datetimes silently break age_days / stale-after-N freshness math. - Require `nodes[].fingerprint`, when present, to match `sha256:<64 lowercase hex>`. Slice 1 commits to SHA-256 only; other algorithms are a schema-version bump. - Reject duplicate `nodes[].id` via a RepoMap model_validator. Downstream consumers (#156 diff-impact, #157 report) build id-keyed structures. - Add `vocab_error` to RepoMapValidationError.kind so callers can distinguish a typo'd Literal (a node type out of catalogue) from a wrong-type-entirely mismatch. Maps Pydantic's `literal_error`. - Restrict the schema_version pre-check to string values so numeric `1.0` falls through to Pydantic with a clearer error rather than masquerading as version drift. - Docs (docs/REPO-MAP.md): honest determinism note (structural fields stable; generated_at churns), explicit deferral of edge-membership validation to slice 2, JSON-pointer escape limitation noted in module docstring. 17 new tests added; full suite stays at 100% coverage.
Second round of codex-driven contract tightening. - `RepoMap.schema_version` no longer has a default; a versioned artifact must carry its version stamp explicitly. Producers that forgot to stamp the field now fail validation instead of being silently treated as the current version. - Use `re.fullmatch` for the fingerprint pattern so a trailing newline doesn't sneak past the `$` anchor. - Sync the example fingerprint in docs/REPO-MAP.md to a real 64-hex value and add `vocab_error` to the documented kind list.
Codex round-3 caught a remaining hole in the timezone-aware guard: a tzinfo subclass whose `utcoffset()` returns None still counts as naive in Python, even though `tzinfo is not None`. The validator now checks both surfaces.
Codex round-4 caught a remaining theoretical edge: a tzinfo subclass whose utcoffset() raises (e.g. TypeError from returning a non-timedelta) would surface a raw exception to the caller instead of a Pydantic ValidationError. Wrap the call in try/except so the failure stays inside the validation envelope.
This was referenced May 28, 2026
sumithr
added a commit
that referenced
this pull request
May 28, 2026
🤖 I have created a release *beep* *boop* --- ## [0.17.0](v0.16.1...v0.17.0) (2026-05-28) ### Features * add repo-map schema models + validation envelope ([#222](#222)) ([6ad5964](6ad5964)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: release-please[bot] <release-please[bot]@users.noreply.github.com>
sumithr
added a commit
that referenced
this pull request
May 29, 2026
**Stacked on #222** (slice 1). When that lands on main, this PR's base auto-rebases. Second implementation slice under #154's QA-native repo-understanding epic. Adds the local walker that populates the `.sumo-qa/repo-map.json` artifact defined by slice 1. Refs #155 · Closes when slice 1 (PR #222) is also merged. ## What landed **`sumo_qa.repo_map_scanner.scan_repo(root, *, generator_version) -> RepoMap`** - Prefers `git ls-files` (respects `.gitignore`, only tracked files); falls back to an `rglob` walk that skips `.git`, `node_modules`, `__pycache__`, `.venv`, `dist`, `build`, `.tox`, `mutants`, `.sumo-qa` when not in a git repo. - Cross-checks `git rev-parse --show-toplevel` against `root` so a parent process's `GIT_DIR` / `GIT_WORK_TREE` (notably pre-commit's stash on `git push`) can't leak an ancestor repo's tracked files into a sub-directory scan. Env vars are also scrubbed (`_git_env()` strips `GIT_*` before every `git` subprocess). - Classifies into the full first-slice vocabulary: `source_file`, `test_file`, `manifest`, `ci_workflow`, `docs`, `config`, `fixture`, `migration_schema`, `infrastructure`. Language detected from extension. Files outside the language map → `unsupported_language` warning; binary-extension files → `skipped_file` warning. - SHA-256 content fingerprints (slice 1 schema requires `sha256:<64 hex>`). - Edges of type `likely_tests` only, inferred by name convention: `tests/test_X.py` → `*/X.py`. `confidence` is `high` for a unique source match, `medium` when multiple sources share the stem. `imports`, `configured_by` deferred — they need #156's diff-impact context to be worth computing. - Commands extracted from `pyproject.toml` `[project.scripts]` and `package.json` `scripts`. `package.json` kinds (`test`/`lint`/`format`/`build`/`other`) guessed from script name; `pyproject.toml` defaults to `other`. - Deterministic by construction: nodes sorted by path; edges by `(source, target)`; commands by `(source, name)`. Only `project.generated_at` churns. ## Evidence | Gate | Result | |---|---| | `uv run pytest -q` | 1113 passed, 1 xfailed, 100% coverage on `src/sumo_qa` | | `uv run mypy src/sumo_qa/repo_map_scanner.py` | Clean | | `uv run ruff check` + `ruff format --check` | Clean | | End-to-end on this actual repo | 240 nodes (8 CI workflows, 46 source, 101 tests, 48 docs, 29 configs, 5 fixtures, 1 infra, 2 manifests), 20 `likely_tests` edges (all high-confidence), 9 commands (pyproject + package.json), 12 warnings — 83KB JSON round-trips cleanly through slice 1's `load_repo_map`. | ## Deferred to follow-up slices - MCP/CLI surfaces — slice 3 / #160 - `imports`, `configured_by`, `command_runs` edges — slice 4 / #156 - Diff-impact extension — #156 ## Notes - `tomli>=2,<3; python_version < '3.11'` added to runtime deps for the scanner's `pyproject.toml` parsing under the 3.10 floor; unconditional in dev deps so mypy's 3.10-pinned check resolves on every dev host. - `.sumo-qa/repo-map.json` added to `.gitignore` — local cache per slice 1's docs guidance. - Codex adversarial review is **pending until usage limit resets** — I'll re-run it before merge and surface any findings in a follow-up commit. --------- Co-authored-by: t <t@t>
sumithr
added a commit
that referenced
this pull request
May 29, 2026
**Stacked on #229** (slice 2) which is stacked on **#222** (slice 1). When upstream PRs land on main, this PR's base auto-rebases. Third implementation slice under #154's QA-native repo-understanding epic. Wraps the slice-2 deterministic scanner in a host-callable MCP tool so any host (Claude Code, IntelliJ AI Assistant, VS Code + Copilot) can map an arbitrary repo from the slash menu. Refs #155. ## Tool signature ```python sumo_qa_scan_repo( root: str, generator_version: str | None = None, write_to: str | None = None, ) -> RepoMapScanOutput | ErrorEnvelope ``` ## Design choices - **Compact-by-default response.** Returns per-type node counts, per-type + per-confidence edge counts, command counts by kind, warning counts by kind. **NO node/edge arrays** — a real scan of this repo produces 242 nodes / 84KB of JSON; the host budget can't carry that on every call. Callers who need the full artifact pass `write_to=<path>` and read it from disk. - `generator_version` defaults to the installed sumo-qa version via `importlib.metadata.version("sumo-qa")` so freshness metadata accurately identifies the producer. - Read-only annotation, `openWorldHint=False` — reads the local filesystem only, no network calls. - Failures (missing directory, file-as-root, scanner exceptions) come back through the standard `{"isError": True, "error": {...}}` envelope with an actionable hint. ## Live demo (against this actual repo) ``` Server has 31 tools registered. New tool present: sumo_qa_scan_repo: YES Compact summary returned to the host: node_count : 242 nodes_by_type : {config: 29, docs: 48, source_file: 47, ci_workflow: 8, infrastructure: 1, manifest: 2, test_file: 102, fixture: 5} edge_count : 21 (all likely_tests, all high confidence) command_count : 9 (extracted from pyproject.toml + package.json) warning_count : 12 (11 unsupported_language + 1 skipped_file) artifact_path : /tmp/sumo-qa-slice3-demo-repo-map.json artifact_bytes : 84425 ``` Full artifact round-trips cleanly through slice 1's `load_repo_map`. ## Evidence | Gate | Result | |---|---| | `uv run pytest -q` | 1123 passed, 1 xfailed, 100% coverage on `src/sumo_qa` | | `uv run mypy src/sumo_qa/server.py src/sumo_qa/server_schemas.py` | Clean | | `uv run ruff check` + `ruff format --check` | Clean | | MCP tool surface | 31 tools (was 30); `REQUIRED_TOOL_NAMES` bumped 16 → 17 | | `tests/fixtures/mcp_tools_list_snapshot.json` | Regenerated via `scripts/regen_tools_list_snapshot.py` | ## What landed - `src/sumo_qa/server_schemas.py` — new `RepoMapScanOutput` model (under existing `_StrictBase`) - `src/sumo_qa/server.py` — `@mcp.tool` registration, `_package_version()` helper, `_build_scan_summary()` aggregator, `_HINT_SCAN_REPO` - `src/sumo_qa/installer.py` — `sumo_qa_scan_repo` added to `REQUIRED_TOOL_NAMES`; doctor/verify handshake fails if a host install drops it - `tests/test_server_repo_map_tool.py` — 10 new tests (registration, annotation shape, declarative description, compact summary, optional write_to + slice-1 round-trip, default vs explicit generator_version, both error-envelope arms) - `tests/test_server.py`, `tests/test_installer_verify.py`, `tests/test_skill_tool_crossref.py` — updated for the new tool name - `tests/fixtures/mcp_tools_list_snapshot.json` — regenerated ## Notes - A `repo-walk` SKILL.md update referencing `sumo_qa_scan_repo` is a small follow-up (the skill-tool-crossref test currently whitelists the tool as a standalone utility). - Codex adversarial review on slices 2 + 3 is still pending — I'll re-run it before merge once usage resets and surface findings in a follow-up commit. --------- Co-authored-by: t <t@t>
sumithr
added a commit
that referenced
this pull request
May 29, 2026
…#233) ## What First consumer of the repo-map: `sumo_qa_analyze_diff_impact`. Given a set of changed files it uses the persisted `.sumo-qa/repo-map.json` (live-scan fallback) to answer the QA-native question — **which tests exercise these changes, and which changed sources have no mapped coverage (the risk surface)?** This is the first cut of **issue #156** ("Add repo-map query and diff-impact analysis tools"), branched off slice 3 so the diff shows only the slice-4 delta. Scope is deliberately the **diff-impact tool only**; `sumo_qa_query_repo_map` and the skill-wiring (`reviewing-before-merge` / `preparing-for-work` / `strategising`) are follow-up slices. ## How Mirrors the slice-2 (pure service) + slice-3 (thin MCP wrapper) split: - **`src/sumo_qa/repo_map_impact.py`** (new) — pure `analyze_diff_impact(repo_map, changed_files) -> DiffImpact` (no I/O); plus `changed_files_from_git(root, base_ref)` which diffs the working tree against `merge-base(base_ref, HEAD)` using `git diff --name-only -z` (clean GIT_* env + toplevel cross-check, same hygiene as the scanner). - **`repo_map_models.py`** — `ImpactNode` + `DiffImpact` models. - **`server_schemas.py`** — compact `DiffImpactOutput` (bounded by the changeset, no full node/edge arrays). - **`server.py`** — the `sumo_qa_analyze_diff_impact` MCP tool: loads the artifact (ignores a foreign-root artifact, falls back to a live scan), resolves changed files from an explicit list or `base_ref`, detects staleness vs HEAD, and optionally writes a `.sumo-qa/diff-impact.json` overlay. Registered `_writer_local` from the start (carries forward the PR #230 read-only-hint lesson). ## Output (per changeset) `changed_nodes`, `affected_nodes` (one-hop), `related_tests`, `unmapped_files`, **`risk_surface`** (changed sources with no mapped test), `suggested_inspections`, plus `is_stale` / `used_live_scan` flags and warning counts. ## Tests / verification - New: `tests/test_repo_map_impact.py` (core + git helper), `tests/test_server_diff_impact_tool.py` (wrapper). Contract/registration tests + tools-list snapshot updated (31 → 32 tools; installer required-tool count 17 → 18). - Full suite: **1147 passed, 1 xfailed, 100% coverage**; ruff + ruff-format + mypy(py3.10) clean. - Live demo on this repo: changed sources mapped to their tests, risk surface empty (both covered). ## Review Codex reviewed the diff (two rounds): round 1 → diff against merge-base not base-tip, `-z` for non-ASCII paths, foreign-artifact guard; round 2 → suppress a redundant live-scan warning, tighten the foreign-artifact test, sync the docstring. All applied and re-verified green. The GitHub Codex bot will also review on open. Stacked on #230 (slice 3). Merge order: #222 → #229 → #230 → this. --------- Co-authored-by: t <t@t>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First implementation slice under the QA-native repo-understanding epic (#154). Locks the
.sumo-qa/repo-map artifact contract so downstream slices (generator, diff-impact, MCP/CLI, report) have a stable, schema-validated shape to build against — without committing to a generator yet.Closes #155.
Scope (slice 1 of 4 per the issue's iteration plan)
extra="forbid"and Literal vocabularykindtaxonomyWhat landed
sumo_qa.repo_map_models— Pydantic models for the slice-1 schema:RepoMap(top-level): requiredschema_version(Literal["1.0"], no default — explicit version stamp required),project,nodes,edges,commands,warnings.model_validatorrejects duplicatenodes[].id.RepoMapProject: freshness metadata;generated_atmust be timezone-aware (rejects naive datetimes AND tzinfos whoseutcoffset()returnsNoneor raises).RepoMapNode: fingerprint, when present, must match^sha256:[0-9a-f]{64}$(usingfullmatchso a trailing newline can't sneak past).RepoMapEdge: first-slice edge vocabularylikely_tests | imports | configured_by.command_runsdeliberately deferred to slice 2 — commands have no stable id yet.sumo_qa.repo_map_validation—load_repo_map(dict | Path | str)returning a validatedRepoMap:RepoMapValidationError.kind:malformed_json | schema_version_mismatch | missing_field | unknown_field | vocab_error | type_error | io_error. Stable taxonomy so consumers can branch on category rather than parsing free-form messages.schema_version_mismatchfires before Pydantic (only for string values, so numeric1.0falls through cleanly as a type error rather than masquerading as version drift).vocab_errordistinguishes out-of-catalogue Literal values (a node type typo) from a wrong-type-entirely mistake./; strict RFC 6901 escaping deferred (today's field names can't contain~or/givenextra="forbid").tests/fixtures/repo_map/repo-map.example.json— golden fixture exercising every first-slice node kind.docs/REPO-MAP.md— schema reference, first-slice vocabulary table, commit-vs-cache guidance (honest aboutgenerated_atchurn breaking byte-for-byte determinism even when the structural fields are stable).Evidence
uv run pytest -q(full suite)src/sumo_qatests/test_repo_map_models.py/tests/test_repo_map_validation.pyuv run mypy src/sumo_qa/repo_map_models.py src/sumo_qa/repo_map_validation.pyuv run ruff check+ruff format --checkReview trail
Five commits on the branch — the first lands the slice, the next four apply codex-driven schema-contract tightening (drop
command_runs, require timezone-awaregenerated_at, enforce sha256 fingerprint pattern, reject duplicate node ids, addvocab_errorkind, require explicitschema_version, fullmatch the fingerprint regex, guard malformed tzinfo). The final codex pass returned effectively GREEN LIGHT — the one remaining MINOR (narrow vs broad exception catching onutcoffset()) is a judgment call against Python's tzinfo contract, accepted intentionally.Deferred to follow-up slices
exc.path— slice 2+.source/targetmembership validation againstnodes[].id— slice 2 (generator decides id conventions for external refs).