Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/SELF_IMPROVEMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -742,13 +742,14 @@ project enforces, the inputs the project trusts, or house rules for its document
A change is reviewed under the conventions it started from, so it cannot loosen its own review
(#946). `devops review branch` reads conventions with git at the merge base of the branch and its
base (at `HEAD` for uncommitted changes), not from the working tree, and `devops review pr` reads
them from the pull request's base. A base with no local branch, as in a CI checkout of a feature,
is `origin/<base>`, and the checked-out branch is never its own base: with no base at all the diff
fails. The lookup also stops at a defect corpus's root, which its manifest marks, read at the same
revision. It reads only regular files: a conventions file that is a link is skipped, on disk and
at a revision, so a reviewed tree cannot bring a file
from outside it into the prompts. Each review's `profile.json` records `conventions_digest`, a digest of the conventions
its prompts carried, empty when they carried none.
them at the merge base of the pull request's head commit and the tip of its base branch, the base of
the diff that the squash merge applies (#5346). A base with no local branch, as in a CI checkout of
a feature, is `origin/<base>`, and the checked-out branch is never its own base: with no base at all
the diff fails. The lookup also stops at a defect corpus's root, which its manifest marks, read at
the same revision. It reads only regular files: a conventions file that is a link is skipped, on
disk and at a revision, so a reviewed tree cannot bring a file from outside it into the prompts.
Each review's `profile.json` records `conventions_digest`, a digest of the conventions its prompts
carried, empty when they carried none.

### Synthetic Defect Corpora

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-13
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Design

## Decisions

- **Read the file list from the compare of the base branch name and the head commit sha.**: GitHub compares from the merge base of the two, so this is the diff that the squash merge applies. For pull request 2509, `compare/main...344adba9` gave the 11 files of the squash commit. Readiness reads the same compare (#2530), and the head is a commit sha for a fork too.
- **Read the diff from the compare of the merge base and the head commit.**: The merge base comes from the file read, so the diff and the file list come from one commit, also when the base branch moves between the two requests. The compare of a merge base and its descendant is the diff of the two.
- **Read the base text, the conventions and the base worktree at the merge base of the compare.**: The tip of the base branch can be ahead of the merge base, and symbols added on the base since would read as removed. The fetch of `refs/pull/<n>/head` brings every ancestor of the head, the merge base too, so the local worktree can be made there. The payload's `base.sha` can be absent from the local repository.
- **Return the merge base from `get_compare_files` and delete `get_merge_base`.**: The review needs the files and the merge base of one compare, and one request gives both. The design of #2530 kept the two reads apart so that a malformed file entry did not break the merge base read of the review. The review now needs the files, so that reason is gone.
- **Give the merge base to the review worktrees through `BaseRevision.revision`.**: The branch review gives its base worktree the same field. `_run_pr_review_workflow` then needs no pull request.
- **End `devops review pr` when the compare lists 300 files.**: The compare diff holds every file, but the head files, the symbol deltas and the filter of deleted files read the file list. A review of a partial list would give wrong deltas with no sign. The message names `devops review branch`, which reads the diff with git and has no such limit.
- **Warn and continue in `devops ai analyze pr` when the compare lists 300 files.**: The analysis gives one record for each file, so a partial list gives fewer records and no wrong record. The warning names the limit.
- **List the files of the comment from the base revision of the review.**: The base revision holds the compare that the review read, so the comment names the same files and needs no second request.
- **Delete `get_pull_files`.**: No code in `src/` calls it after this change. Its tests move to the compare read, which parses the same `PullRequestFile` model.

## Rejected alternatives

- **Compare from the payload's `base.sha`.**: For pull request 2509, `compare/0137f231...344adba9` gave merge base 0137f231 and the same 184 files as the pulls files endpoint.
- **Keep the diff of the pulls endpoint and filter it by the compare file list.**: The pulls diff of pull request 2509 held 184 files against 11 in the compare, and a page of a file that both changed would show the changes of `main` too.
- **Read the diff from `compare/<base-ref>...<head-sha>`.**: It is the same diff while the merge base stays, but a push that moves the merge base between the two requests, such as a merge of the head into the base branch, could give a diff from another merge base than the file list.
- **Fall back to the pulls files endpoint when the compare lists 300 files.**: That list keeps the stale base, so the review would read the changes of `main` again.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Proposal: #5346

## Why

The issue #5346 reports that `devops review pr` and `devops ai analyze pr` read a stale change set. The review read the files of a pull request from the pulls files endpoint and its diff from the pulls endpoint, and it read the base text at the merge base of the payload's `base.sha` and the head commit. It also gave `base.sha` to the review worktrees as the base revision. GitHub does not move `base.sha` when a merge commit moves the merge base of a pull request, and the pulls files and diff endpoints keep that stale base too. Thus, after a person merges `main` into a pull request branch, the review reads the changes of `main` as changes of the pull request. `devops ai analyze pr` read the pulls files endpoint and has the same defect. The issue #2530 fixed the same cause in `devops pr check-readiness`.

## What Changes

- `devops review pr` reads the files of a pull request from the compare of the tip of its base branch and its head commit (`compare/<base-ref>...<head-sha>`), in the base repository. This is the diff that the squash merge applies.
- The review reads the diff from the compare of that merge base and the head commit (`compare/<merge-base>...<head-sha>`, diff media type), so the files and the diff come from one merge base.
- The review reads the base text of each changed file and the base conventions at that merge base. No request of the review names the payload's `base.sha`.
- The base worktree of the review is at that merge base. The fetch of the pull request head brings the merge base to the local repository.
- A compare at GitHub's limit of 300 files ends `devops review pr` with status 1 and a message that names the limit and `devops review branch`. The compare diff has no such limit, but the review needs every changed file for the head files, the symbol deltas and the filter of deleted files.
- When the diff names no reviewable file, the comment of `devops review pr --post` lists the files of the compare that the review read. The command does not read the file list a second time.
- `devops ai analyze pr` reads the files of a pull request from the compare of the tip of its base branch and its head commit. A compare at the limit gives an analysis of the listed files and a warning that names the limit.
- `GitHubClient.get_compare_files` also returns the merge base of the compare, and the new `GitHubClient.get_compare_diff` reads the diff of two commits. `GitHubClient.get_pull_files` and `GitHubClient.get_merge_base` have no caller after this change, so the change deletes them.
- The change alters the output of two commands, so it carries a spec delta. It fits one pull request.

## Capabilities

### New Capabilities

- `pr-squash-diff`: A PR review reads the diff that the squash merge applies, A PR review refuses a compare at the file limit, The PR analysis reads the files of the compare of its base branch

### Modified Capabilities

None.

## Impact

- Code: `src/devops_cli/github/client.py`, `src/devops_cli/ai/review/runner.py`, `src/devops_cli/commands/review.py`, `src/devops_cli/commands/analyze.py`, `src/devops_cli/lang/en/messages.py`, `src/devops_cli/ai/analyze/symbols.py` (the docstring of `BaseRevision.revision`), `src/devops_cli/config/constants.py` (the comment of `CONST_GITHUB_DIFF_MEDIA_TYPE`)
- Docs: `docs/SELF_IMPROVEMENT.md`, `src/devops_cli/ai/knowledge_base/devops_cli/python_packages.md`
- Tests: `tests/github/test_github_client.py`, `tests/commands/test_review_scope.py`, `tests/commands/test_review_pr_post.py`, `tests/commands/test_analyze.py`, `tests/ai/review/test_review_runner.py`, `tests/ai/review/test_review_path_routing.py`, `tests/ai/client/test_batch_2_review_defects.py`, `tests/git/test_review_worktree_regression.py`, `tests/git/test_ai_task_metadata.py`, `tests/roadmap/test_roadmap_draft_readiness.py`, `tests/support/fakes/github.py`, `tests/fixtures/github/hello_world_pull_request.json`

## Feasibility

- A live probe on 2026-11-13 confirmed the premise. `devops gh api repos/dan-petty/devops-cli/pulls/2509` gave state closed, merged true, `base.sha` 0137f231, `base.ref` main, head 344adba9 and 184 changed files.
- `compare/0137f231...344adba9?per_page=1` gave merge base 0137f231 and 184 files, and `compare/main...344adba9?per_page=1` gave merge base 5c4d24ee and 11 files, the files of the squash commit.
- The diff of the pulls endpoint (`pulls/2509` with `Accept: application/vnd.github.diff`) held 184 `diff --git` headers, and the diff of `compare/main...344adba9` held 11. So the diff that the review read was stale too, not only its file list.
- `compare/v0.100.0...v0.127.0?per_page=1` listed 300 files, the limit, and its diff media type held 3394 `diff --git` headers. So the compare diff has no 300-file limit, and the file list is the read that can be partial.
- `compare/master...ec18ca7b` of octocat/Hello-World pull request 158 gave merge base 7fd1a60b and its 2 files. The change records that answer in `tests/fixtures/github/hello_world_pull_request.json`.
- The source of `origin/main` showed the stale reads: `src/devops_cli/ai/review/runner.py:952` read `get_pr_diff`, line 957 read `get_pull_files`, line 988 read `get_merge_base(base_repo, pull.base.sha, pull.head.sha)`, line 1015 read the conventions at `pull.base.sha`, and line 278 read `get_pull_files` for the comment. `src/devops_cli/commands/review.py:731` gave `pull.base.sha` to the worktrees, and `src/devops_cli/commands/analyze.py:537` read `get_pull_files`.
- `git grep` for `get_pull_files` and `get_merge_base` in `src/` showed no caller other than these reads.

## Existing Tool Considered

- The GitHub REST compare endpoint covers the need: it compares from the merge base of the base branch and the head, and it serves the diff in the diff media type. The change uses `GitHubClient.get_compare_files`, which #2530 added for readiness, and adds no second copy of that read.
- The change deletes `GitHubClient.get_pull_files`, `GitHubClient.get_merge_base`, the model `_Comparison`, the test route `route_merge_base`, the `pull` parameter of `_run_pr_review_workflow`, and the second file read of the PR comment.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Purpose

Which changes of a pull request `devops review pr` and `devops ai analyze pr` read: the files and the diff that the squash merge applies, which is the compare of the tip of the base branch and the head commit, and not the stale base of the pull request payload.

## ADDED Requirements

### Requirement: A PR review reads the diff that the squash merge applies
The command `devops review pr` SHALL read the files and the diff of a pull request from the compare of the tip of its base branch and its head commit, and SHALL read the base text and the base conventions at the merge base of that compare. It MUST NOT read the pulls files endpoint or the diff of the pulls endpoint, and MUST NOT read a file at the `base.sha` of the pull request payload.

#### Scenario: A moved merge base
- **WHEN** a merge of the base branch into the pull request moved its merge base, the payload's `base.sha` and the pulls files and diff endpoints still name the old base, and the compare of the base branch and the head commit names another merge base
- **THEN** the review pages hold only the files of the compare, the base text and the conventions are read at the merge base of the compare, and no request names `base.sha` or the pulls files path

#### Scenario: The base worktree
- **WHEN** the fetch of the pull request head into the local checkout succeeds
- **THEN** the base worktree of the review is at the merge base of the compare

#### Scenario: A diff that names no reviewable file
- **WHEN** the diff names no reviewable file and the review posts its comment
- **THEN** the comment lists the files of the compare that the review read, less the deleted files, and the command reads the file list only one time

### Requirement: A PR review refuses a compare at the file limit
The command `devops review pr` SHALL end with status 1 when the compare of the base branch and the head commit lists GitHub's limit of files for one comparison, with a message that names the limit and `devops review branch`, and SHALL read no diff.

#### Scenario: The compare lists 300 files
- **WHEN** the compare of the base branch and the head commit lists 300 files
- **THEN** the command exits 1, its message names 300 files and `devops review branch`, and it makes no diff request

### Requirement: The PR analysis reads the files of the compare of its base branch
The command `devops ai analyze pr` SHALL read the files of a pull request from the compare of the tip of its base branch and its head commit, and MUST NOT read the pulls files endpoint. A compare that lists GitHub's limit of files SHALL give an analysis of the listed files and a warning that names the limit.

#### Scenario: A moved merge base
- **WHEN** the pulls files endpoint lists a file that the compare of the base branch and the head commit does not list
- **THEN** the analysis holds only the files of the compare, and the command reads only the pull request and the compare

#### Scenario: The compare lists 300 files
- **WHEN** the compare of the base branch and the head commit lists 300 files
- **THEN** the command exits 0, the analysis holds the 300 files, and a warning names the limit of 300 files
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Tasks

## 1. Read the merge base and the diff of a compare in the GitHub client

Kind: behavior. Changes: `src/devops_cli/github/client.py`, `tests/github/test_github_client.py`, `tests/fixtures/github/hello_world_pull_request.json`, `tests/roadmap/test_roadmap_draft_readiness.py`.

- [x] 1.1 `tests/github/test_github_client.py::test_the_files_of_a_comparison_come_with_its_merge_base` and `test_the_compare_diff_is_read_as_text` fail: the recorded compare of the base branch and the head commit of octocat/Hello-World pull request 158 gives its files and its merge base, and the client has no merge base in `CompareFiles` and no `get_compare_diff`
- Verification: `$ uv run devops ci test tests/github/test_github_client.py` fails on the base
- [x] 1.2 Add `merge_base` to `_CompareFiles` and `CompareFiles`, and add `get_compare_diff`, which shares `_read_diff` with `get_pr_diff`. Delete `get_pull_files`, `get_merge_base` and `_Comparison`, and move their tests to the compare read. Replace the recorded pages of the pulls files endpoint with the recorded compare in the fixture
- Verification: `$ uv run devops ci test tests/github/test_github_client.py tests/roadmap/test_roadmap_draft_readiness.py` passes

## 2. Review a pull request at the merge base of its base branch

Kind: behavior. Changes: `src/devops_cli/ai/review/runner.py`, `src/devops_cli/commands/review.py`, `src/devops_cli/lang/en/messages.py`, `tests/support/fakes/github.py`, `tests/commands/test_review_scope.py`, `tests/commands/test_review_pr_post.py`, `tests/ai/review/test_review_runner.py`, `tests/ai/review/test_review_path_routing.py`, `tests/ai/client/test_batch_2_review_defects.py`, `tests/git/test_review_worktree_regression.py`.

- [x] 2.1 `tests/commands/test_review_scope.py::test_a_pr_review_reads_the_changes_at_the_merge_base_of_its_base_branch` fails: the payload's `base.sha` is not the merge base, the pulls endpoints still list the stale file `main_only.py`, and the review pages hold that file. `test_a_pr_review_refuses_a_comparison_at_the_file_limit` and `tests/git/test_review_worktree_regression.py::test_run_pr_review_workflow_with_worktree` fail too
- Verification: `$ uv run devops ci test tests/commands/test_review_scope.py tests/git/test_review_worktree_regression.py` fails on the base
- [x] 2.2 In `_prepare_pr_content`, read the compare of `pull.base.ref` and `pull.head.sha` in the base repository, end the command with `MESSAGES.review.pr_compare_at_file_limit` at the file limit, and read the diff with `get_compare_diff` from the merge base. Give the compare to `_materialize_pr_head` and `_pr_base_revision`, read the conventions and the base text at the merge base, and set `BaseRevision.revision` to it. Give the base worktree that revision, and drop the `pull` parameter of `_run_pr_review_workflow`. List the comment files from the base revision in `resolve_pr_files`. Add `route_compare_diff` and `route_pull_request_changes` to the GitHub fake, and delete `route_merge_base`. Run `uv run devops docs generate`
- Verification: `$ uv run devops ci test tests/commands/test_review_scope.py tests/commands/test_review_pr_post.py tests/ai/review/test_review_runner.py tests/ai/review/test_review_path_routing.py tests/ai/client/test_batch_2_review_defects.py tests/git/test_review_worktree_regression.py` passes

## 3. Analyze the files of the compare of the base branch

Kind: behavior. Changes: `src/devops_cli/commands/analyze.py`, `src/devops_cli/lang/en/messages.py`, `tests/commands/test_analyze.py`, `tests/git/test_ai_task_metadata.py`.

- [x] 3.1 `tests/commands/test_analyze.py::test_analyze_pr_reads_the_files_at_the_merge_base_of_its_base_branch` and `test_analyze_pr_warns_that_a_comparison_at_the_file_limit_can_miss_files` fail: the analysis reads the pulls files endpoint, which lists the stale file `main_only.py`
- Verification: `$ uv run devops ci test tests/commands/test_analyze.py` fails on the base
- [x] 3.2 In `devops ai analyze pr`, read the files with `get_compare_files` of `pull.base.ref` and `pull.head.sha` in the base repository, and warn with `MESSAGES.analyze.pr_compare_at_file_limit` at the file limit. Run `uv run devops docs generate`
- Verification: `$ uv run devops ci test tests/commands/test_analyze.py tests/git/test_ai_task_metadata.py` passes

## 4. Documents

Kind: documents. Changes: `docs/SELF_IMPROVEMENT.md`, `src/devops_cli/ai/knowledge_base/devops_cli/python_packages.md`.

- [x] 4.1 Say in `docs/SELF_IMPROVEMENT.md` that `devops review pr` reads the conventions at the merge base of the head commit and the tip of the base branch, and name the compare reads of `devops_cli.github.client` in the knowledge base
- Verification: `$ uv run devops ci docs`

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r origin/main..HEAD).
Loading