diff --git a/README.md b/README.md index d586d75fbb..7c51572839 100644 --- a/README.md +++ b/README.md @@ -383,7 +383,7 @@ and excessive permissions fail it, and every other finding is shown. | | | `devops roadmap plan-check [OPTIONS] ` | Check a plan pull request: the stage gates without a model, the title, the body, the `Semantic PR title` check and a base spec that moved since the plan. Details: docs/roadmap/plan-check.md. | | | `devops roadmap plan-recheck [OPTIONS]` | Check each change folder on the default branch again. Each folder gets one result: ok, rewrite, new-plan, delivered or cleanup. The command reads GitHub and git, calls no model and writes nothing. Details: docs/roadmap/plan-recheck.md. | | | `devops roadmap explain [OPTIONS] ` | Say, for one issue, whether the refine job, the stage job and the implement job take it. For each job the answer is yes, or no with the reason of the first rule that fails: the issue is closed or is no item, the filter, the rules of the job (the Status, the owner, the stop on record, the plan and the branch, and the setting roadmap.stage.planned_limit), and the limit of a run. For refine the reason is the wait of the item, such as a question for a person. The reasons are the texts of the 'Left out' list of stage --plan and implement --plan. The command reads GitHub and git, calls no model and writes nothing. It uses the filter and the limit that the Service uses for each job. A group over the step budget shows only when an earlier run recorded it. | -| | `devops roadmap inbox [OPTIONS]` | List what waits for a person, each line with its number, its age and the one command or action that clears it, and a line when the count of Planned items is at the setting roadmap.stage.planned_limit. It reads GitHub, calls no model and writes nothing. Details: docs/roadmap/inbox.md. | +| | `devops roadmap inbox [OPTIONS]` | List what waits for a person in each repository of service.repos, or in the one that --repo names. Each line has its number, its age and the step that clears it, and an old wait is marked. It reads GitHub, calls no model and writes nothing; details: docs/roadmap/inbox.md. | | | `devops roadmap repair [OPTIONS]` | Find the items that a placeholder reply of a model stalled. A returned item goes back to Ready. A stub refine item loses its stub section and its refine block. An item that a person set or answered stays as it is. This command reads GitHub and calls no model. It writes only with --confirm. Details: docs/roadmap/repair.md. | | | `devops roadmap return [OPTIONS] ` | Return an item to New with an evidence comment, handing it back to refinement when it cannot be built as specified or needs a refactor beyond its scope. The item gets the label status/new in place of its other status/* label. | | | `devops roadmap claim [OPTIONS] ` | Claim an item for an agent or a person with the label owner/agent or owner/human. An item has one owner. A person can take an item from the Service. The jobs stage and implement take no item that an agent or a person claimed. | diff --git a/docs/CLI_REFERENCE.md b/docs/CLI_REFERENCE.md index fcb3781d06..f850e15779 100644 --- a/docs/CLI_REFERENCE.md +++ b/docs/CLI_REFERENCE.md @@ -6754,7 +6754,7 @@ devops roadmap explain [OPTIONS] ### `devops roadmap inbox` -**List what waits for a person, each line with its number, its age and the one command or action that clears it, and a line when the count of Planned items is at the setting roadmap.stage.planned_limit. It reads GitHub, calls no model and writes nothing. Details: docs/roadmap/inbox.md.** +**List what waits for a person in each repository of service.repos, or in the one that --repo names. Each line has its number, its age and the step that clears it, and an old wait is marked. It reads GitHub, calls no model and writes nothing; details: docs/roadmap/inbox.md.** ```bash devops roadmap inbox [OPTIONS] @@ -6765,6 +6765,7 @@ devops roadmap inbox [OPTIONS] | Option / Flag | Type | Default | Description | |---|---|---|---| | `--repo`, `-R` | `string` | - | Repository as owner/name (default: this checkout's origin). | +| `--kind` | `choice (plan|implement|release|blocked|refine|split|alternatives|draft|claim|labels|queue|person)` | - | List only the lines of one class, such as refine, split, alternatives or draft. The counts of every class stay complete. | | `--dry-run` | `boolean` | - | Make no request: print the reads that a run makes, in order, with placeholders. | ### `devops roadmap repair` diff --git a/docs/CONFIGURATION.md b/docs/CONFIGURATION.md index 502a3b5362..c1b7971add 100644 --- a/docs/CONFIGURATION.md +++ b/docs/CONFIGURATION.md @@ -271,6 +271,7 @@ roadmap configuration settings. | `alternatives` | `AlternativesConfig` | `limit=5 first_pass_limit=20 recheck_days=30 retry_days=3` | - | - | | `stage` | `RoadmapStageConfig` | `filter=['status=ready'] limit=3 planned_limit=20 step_tokens=64000 retry_hours=6 toolset='extended'` | - | - | | `implement` | `RoadmapImplementConfig` | `in_runner=False repair_rounds=3 step_token_budget=8000000 item_token_budget=20000000 step_time_limit_seconds=5400 item_time_limit_seconds=12600 digest_clears_per_class=1 digest_clears_per_item=3 ladder={'plan': ['devops-coder'], 'edit': ['devops-coder'], 'repair': ['devops-coder'], 'review': ['devops-coder']} request_timeout_seconds=1200 command_timeout_seconds=1800 monitor_timeout_seconds=3600 deadline_stall_seconds=4200 deadline_extension_seconds=5400 deadline_ceiling_seconds=14400` | - | - | +| `inbox` | `RoadmapInboxConfig` | `draft_days=7 wait_days=7` | - | - | ## Firecrawl Configuration (`firecrawl`) diff --git a/docs/commands/roadmap.md b/docs/commands/roadmap.md index f012f3bc21..67fd50f20b 100644 --- a/docs/commands/roadmap.md +++ b/docs/commands/roadmap.md @@ -236,7 +236,7 @@ devops roadmap explain [OPTIONS] ## `devops roadmap inbox` -**List what waits for a person, each line with its number, its age and the one command or action that clears it, and a line when the count of Planned items is at the setting roadmap.stage.planned_limit. It reads GitHub, calls no model and writes nothing. Details: docs/roadmap/inbox.md.** +**List what waits for a person in each repository of service.repos, or in the one that --repo names. Each line has its number, its age and the step that clears it, and an old wait is marked. It reads GitHub, calls no model and writes nothing; details: docs/roadmap/inbox.md.** ```bash devops roadmap inbox [OPTIONS] @@ -247,6 +247,7 @@ devops roadmap inbox [OPTIONS] | Option / Flag | Type | Default | Description | |---|---|---|---| | `--repo`, `-R` | `string` | - | Repository as owner/name (default: this checkout's origin). | +| `--kind` | `choice (plan|implement|release|blocked|refine|split|alternatives|draft|claim|labels|queue|person)` | - | List only the lines of one class, such as refine, split, alternatives or draft. The counts of every class stay complete. | | `--dry-run` | `boolean` | - | Make no request: print the reads that a run makes, in order, with placeholders. | --- diff --git a/docs/roadmap/inbox.md b/docs/roadmap/inbox.md index b665a80c2b..8b1ce7b0e3 100644 --- a/docs/roadmap/inbox.md +++ b/docs/roadmap/inbox.md @@ -2,30 +2,48 @@ `devops roadmap inbox` lists what waits for a person. It shows the three gates of [the roadmap workflow](../ROADMAP_WORKFLOW.md) and the state that needs a person. The command help gives a summary only. This page gives the rest. The rules that a test checks are in the spec named at the end of this page. +## Which repositories it reads + +Without `--repo`, the inbox reads each repository of the setting `service.repos`, in its order, and lists the lines of each. With `--repo`, it reads that repository only. When `service.repos` is empty and `--repo` is not given, the command fails and names the setting. An entry that is not `owner/name` makes the command fail before it reads any repository, and the error names the entry. + ## What the inbox lists -Each line has its number, its age and the one command or action that clears it. The age is the time since the last update. The first list has these kinds of line, in this order: +Each line has its number, its age and the one command or action that clears it. The age is the time since the last update. A line whose age is over `roadmap.inbox.wait_days` ends with the mark `(over N days)`. After its title, the output starts with the count of the lines of each class, for example `Counts by class: refine 2, split 1.` -1. Ready plan pull requests of the jobs (G1). -2. Ready implementation pull requests of the jobs (G2). -3. The open release pull request (G3). -4. Items in `status/blocked`, with their cause. -5. New items that wait on a person in refine, one line for each. The line comes from the job record: the last refine round left a question for a person, or the stage job returned the item twice on the same body. A reply shows in the list until the next refine round. `devops roadmap explain ` gives the cause. -6. Claims with no activity for 7 days. -7. Labels of `.github/labels.yml` that the repository lacks. -8. The state of the Planned queue, when the count of Planned items is at `roadmap.stage.planned_limit`. The stage job then plans no new item. The line has no number and no age. +The lines come in this order of classes: -A second list holds the other open pull requests, those of people and agents. It marks the drafts. +1. Ready plan pull requests of the jobs (G1), class `plan`. +2. Ready implementation pull requests of the jobs (G2), class `implement`. +3. The open release pull request (G3), class `release`. +4. Items in `status/blocked`, with their cause, class `blocked`. +5. New items that wait on a person in refine, one line for each, class `refine`. The line comes from the job record: the last refine round left a question for a person, or the stage job returned the item twice on the same body. A reply shows in the list until the next refine round. `devops roadmap explain ` gives the cause. +6. New items with a split that no person has applied, one line for each, class `split`. Refine proposed the split in a comment. +7. New items whose refine round put a covering tool to a person, one line for each, class `alternatives`. The line names the tool. +8. Drafts of jobs, class `draft`. A draft of a job is listed when its head commit has a failed check run, or when it is older than `roadmap.inbox.draft_days`. A newer draft with no failed check is not listed. A pull request that a runner Job holds is not listed either. +9. Claims with no activity for 7 days, class `claim`. +10. Labels of `.github/labels.yml` that the repository lacks, class `labels`. +11. The state of the Planned queue, when the count of Planned items is at `roadmap.stage.planned_limit`, class `queue`. The stage job then plans no new item. The line has no number and no age. -A draft of a job is not listed. A pull request that a runner Job holds is not listed either. +A second list holds the other open pull requests, those of people and agents, class `person`. It marks the drafts. The inbox leaves out an image digest that is not rolled yet. To read it, run `devops argo cd apps status devops`. +## How to filter and count the lines + +The option `--kind ` keeps the lines of one class, for example `--kind split`. The counts at the top stay complete. An unknown class is a usage error that names the classes. + +## Settings + +| Setting | Default | Meaning | +| :--- | :--- | :--- | +| `roadmap.inbox.draft_days` | 7 | The age in days from which a draft of a job is listed, when no check run of its head commit failed. | +| `roadmap.inbox.wait_days` | 7 | The age in days from which a line is marked as old. | + ## What the inbox reads -The command reads the open issues, the open pull requests, the labels of the repository, and the labels file. It reads the newest commit of the labels file only when the labels differ. It reads no closed issue. It calls no model and writes nothing. +The command reads, for each repository it lists, the open issues, the open pull requests, the labels of the repository, and the labels file. It reads the newest commit of the labels file only when the labels differ. It reads the check runs of the head commit of each open draft of a job, one read for each draft. It reads no closed issue. It calls no model and writes nothing. -A run sends these requests: +A run sends these requests for each repository: | Read | Requests | | :--- | :--- | @@ -34,9 +52,10 @@ A run sends these requests: | The labels of the repository | One for each 100 | | `.github/labels.yml` on the default branch | One | | The newest commit that changed `.github/labels.yml` | One, only when the labels differ | +| The check runs of the head commit of each open draft of a job | One for each draft | -`--dry-run` makes no request and lists these reads. +`--dry-run` makes no request and lists these reads for each repository. ## Where the rules are -[roadmap-inbox](../../openspec/specs/roadmap-inbox/spec.md) holds the order of the lines, the line format, the age of a claim, the second list, and the bound on the reads. +[roadmap-inbox](../../openspec/specs/roadmap-inbox/spec.md) holds the order of the lines, the line format, the age of a claim, the second list, the drafts, the splits, the alternatives, the marks, the counts, the class filter and the bound on the reads. diff --git a/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/.openspec.yaml b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/.openspec.yaml new file mode 100644 index 0000000000..1491b921e2 --- /dev/null +++ b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-05 diff --git a/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/design.md b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/design.md new file mode 100644 index 0000000000..2ba5a7d605 --- /dev/null +++ b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/design.md @@ -0,0 +1,55 @@ +# Design + +## Context + +`read_inbox` in `src/devops_cli/roadmap/inbox.py` reads one repository and returns the lines of the jobs and the people. Its line builders are pure functions over the open items and the open pull requests of a store. The store protocol is `RoadmapStore` in `src/devops_cli/roadmap/store.py`. The command `inbox_cmd` in `src/devops_cli/commands/roadmap.py` opens one store from `--repo` or from the origin of the checkout. + +## Decisions + +### One read per repository in `service.repos` + +`inbox_cmd` loops over the repositories of `service.repos` when `--repo` is not given, and calls `read_inbox` for each one. `read_inbox` keeps its shape, so each repository has its own reads, its own counts and its own sections. + +Rejected: reading the origin of the checkout when `service.repos` is empty. The checkout hides the repositories that the Service runs. The project rule for unconfigured service URLs says to fail and name the setting. The command therefore raises `ConfigurationError` that names `service.repos`. + +### Three new classes, in the order of the issue + +`InboxKind` gets `SPLIT`, `ALTERNATIVES` and `DRAFT`, after `REFINE`. The person wait and the returned item stay in `REFINE`, because the rule of `refine_wait_on_person` already covers them. The rule for a returned item is kept, since no new record key replaces it. + +- `SPLIT`: an open New item whose `refine.next_step` is `split`. The item stays open until a person splits it. A reply shows after the next refine round, as it does for `REFINE`. +- `ALTERNATIVES`: an open New item whose `refine.alternatives_asked` is set. The key is set when the check verdict is `covers` (`refine.py:2079`). The key is read, not the next step, because the covers question joins the open questions only after a reply (`refine.py:560-564`). +- `DRAFT`: a draft of a job, which is a draft pull request that a job record names and that no runner Job holds. It is listed when its age is over `roadmap.inbox.draft_days` or when a check run of its head commit failed. + +An item may have more than one line, one for each wait. A `REFINE` line and an `ALTERNATIVES` line of one item both show. + +### Check runs by head commit + +`OpenPull` gets `head_sha`, read from `head.sha` of the pull request listing. `RoadmapStore.failed_checks(head_sha)` returns whether a check run of the commit failed. The GitHub store calls `read_check_runs` and returns `fail_count > 0`. When GitHub gives no check run list (`unread_reason` is set), the store raises `GitHubUnreadError`, so the inbox does not show a draft as passing. The in-memory store answers from the failures that a test seeds. + +The inbox reads the check runs only for job drafts, so a run makes one read for each job draft and no read for a person's draft. + +Rejected: reading the check runs of every open pull request. It costs one request for each person's draft, and the rule needs only the job drafts. + +### Two settings with a default of seven days + +`roadmap.inbox.draft_days` and `roadmap.inbox.wait_days` are integers of at least 1. Both default to 7 (`DEFAULT_ROADMAP_INBOX_DRAFT_DAYS` and `DEFAULT_ROADMAP_INBOX_WAIT_DAYS` in `config/defaults.py`). `CONST_ROADMAP_INBOX_CLAIM_DAYS` stays a constant, because the spec rule of claims names its 7 days. + +Rejected: one setting for both thresholds. The issue names a setting for drafts and a setting for the mark, and the two thresholds can differ. + +### Marks, counts and the class filter + +`InboxLine` gets a field `old`, which `read_inbox` sets when the age of the line is over `wait_days`. `render_inbox` prints the mark after the subject of an old line. + +`render_inbox` prints the counts of all lines by class under the title, before any filter. `render_inbox` takes an optional set of classes, and the command option `--kind` passes one class. The counts stay complete when a filter applies. + +Rejected: the option name `--class`. `class` is a Python keyword and the code names the type `InboxKind`, so the option is `--kind`. + +### Dry run + +`inbox_requests(repo)` lists the reads of one repository. It adds the check-run read of each open job draft, under the condition `open job draft`, so a dry run lists the reads that a run may make and makes none. + +## Rejected alternatives with their evidence + +- Reading the origin of the checkout when `service.repos` is empty: rejected for the reason above (the project rule on unconfigured service URLs). +- A record key for the returned item: rejected, because the rule `RETURNED_BODY_HASH == BODY_HASH` already gives the line, and the issue allows keeping the rule. +- Reading the check runs of every pull request: rejected because it costs a request for each person's draft. diff --git a/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/proposal.md b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/proposal.md new file mode 100644 index 0000000000..ade73bab49 --- /dev/null +++ b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/proposal.md @@ -0,0 +1,63 @@ +# Proposal + +## Why + +Issue #3494: `devops roadmap inbox` omits most of the waits that a person must clear. It lists one repository. It shows no unapplied split and no alternatives question. It hides every draft of a job, even a draft whose checks failed or that is old. A person who reads the inbox does not see the questions that wait for an answer. This change makes the inbox list each wait, for each repository of `service.repos`, with counts by class, a filter by class and a mark on each old wait. + +## What Changes + +- `devops roadmap inbox` reads each repository of `service.repos` when `--repo` is not given. With `--repo`, it reads that repository only. When `service.repos` is empty and `--repo` is not given, the command fails and names the setting (`src/devops_cli/commands/roadmap.py`). +- `InboxKind` gets three classes, in this order after `REFINE`: `SPLIT` (an open New item whose refine next step is `split`), `ALTERNATIVES` (an open New item whose `refine.alternatives_asked` is set) and `DRAFT` (a draft of a job that is older than `roadmap.inbox.draft_days`, or whose head commit has a failed check run). The draft rule that hid every draft of a job is removed (`src/devops_cli/roadmap/inbox.py`). +- `OpenPull` gets the field `head_sha`, read from the pull request listing. `RoadmapStore` gets `failed_checks(head_sha)`, implemented by the GitHub store with `read_check_runs` and by the in-memory store. An unread check run raises `GitHubUnreadError`. +- A new setting group `roadmap.inbox` holds `draft_days` and `wait_days`, both 7 by default (`src/devops_cli/config/settings.py`, `src/devops_cli/config/defaults.py`). +- A line whose wait is older than `roadmap.inbox.wait_days` shows a mark. +- After its title, the output starts with the count of lines in each class. The option `--kind` keeps the lines of one class. +- `--dry-run` lists the reads of each repository, and the check-run reads of each open job draft, under the condition that the draft exists. It makes no request. +- The spec delta `openspec/changes/3494-inbox-lists-all-person-waits/specs/roadmap-inbox/spec.md` changes the requirements about the gates, the draft rule and the bounded reads, and adds the requirements of this change. `docs/roadmap/inbox.md` and the help text of the command state the classes and the options. +- The change fits one pull request. It has a spec delta because a command, an option, a message and a setting are observable (`openspec/config.yaml`). + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `roadmap-inbox`: the gates of the jobs, the bounded reads of each repository, the draft rule and the marks, counts and filter of the lines are changed or added. + +## Impact + +- Code: `src/devops_cli/roadmap/inbox.py`, `src/devops_cli/roadmap/store.py`, `src/devops_cli/roadmap/github_store.py`, `src/devops_cli/roadmap/memory_store.py`, `src/devops_cli/roadmap/request_plan.py`, `src/devops_cli/commands/roadmap.py`, `src/devops_cli/config/settings.py`, `src/devops_cli/config/defaults.py`, `src/devops_cli/lang/en/messages.py`, `src/devops_cli/lang/en/help.py`. +- Tests: `tests/roadmap/test_roadmap_inbox.py`, `tests/roadmap/test_roadmap_inbox_command.py`, `tests/roadmap/test_roadmap_inbox_requests.py`, `tests/roadmap/test_roadmap_store_contract.py`. +- Documents: `docs/roadmap/inbox.md`, the help of the command in `README.md` when `devops docs generate --sync-readme` changes it. +- Unchanged on purpose: the record keys of `src/devops_cli/roadmap/store.py` (no new key is written), the claim threshold `CONST_ROADMAP_INBOX_CLAIM_DAYS` (a constant of the rule of the spec), and the people's list (`InboxKind.PERSON`). + +## Dependencies + +- #3483 is in `main` (closed by ce689f43). It gives the first line for a refine person wait, which this change keeps. +- #3478 (filler replies) is not confirmed closed. The line that the inbox shows for a returned item is not quoted as an action until #3478 is repaired. This change quotes no evidence text. +- #2968 and #3077 come after this change: #2968 counts these classes and #3077 adds its class to the inbox. +- #3497 (repeated reads) may need its fix first. Each open job draft adds one check-run read. The number of drafts is small, so this change does not wait for it. + +## Feasibility + +Checked on `origin/main` d254410c, the base of this branch. Each premise was read from the code at that commit. + +- The draft rule of the inbox. `git show origin/main:src/devops_cli/roadmap/inbox.py | sed -n 129p` prints `return None if pull.draft else kind`. A draft of a job is dropped there, so the premise holds. +- The person wait is in the tree. `inbox.py` lines 184 to 215 hold `refine_wait_on_person` and `_refine_lines`. That is the first line for a refine person wait of #3483. +- The unapplied split has no reader. `refine.py:1196` returns `NextStep.SPLIT`. `git grep -n SPLIT origin/main -- src/devops_cli/roadmap/inbox.py` prints nothing, so the inbox never lists a split. +- The alternatives question is recorded. `store.py:154` names `RefineRecordKey.ALTERNATIVES_ASKED`. `refine.py:2079` sets it to the tool when the check verdict is `covers`. `inbox.py` reads no such key. The issue asks to confirm that an alternatives wait holds next step `person`. Not confirmed: `refine.py:560-564` says that the covers question joins the open questions only after a reply, so this change reads the key `alternatives_asked` and not the next step. +- The head commit of a pull request is not read. `OpenPull` (`store.py:414-424`) has no head commit field. `_PullPayload` (`github_store.py:206-222`) reads `head.ref` and no `head.sha`. This change adds both. +- The check runs can be read by commit. `read_check_runs(owner, repo_name, head_sha, *, session)` (`github/check_verdict.py:374`) returns `CheckVerdictSummary`. Its `unread_reason` names a failed read and its `fail_count` (`check_verdict.py:87`) counts the failed runs. The REST path is `/repos/{owner}/{repo}/commits/{sha}/check-runs` (`check_verdict.py:315`). +- The command reads one repository. `_target` (`commands/roadmap.py:87-93`) resolves `--repo` or the origin of the checkout. `inbox_cmd` (`commands/roadmap.py:891-917`) calls `read_inbox` once. `ServiceConfig.repos` is at `settings.py:1069`. The issue gives line 1002, which is stale. +- The live counts of the issue (84 person waits, 35 returned items, 12 splits, 3 alternatives, the drafts of vibes, dreamscaper and dotfiles) are not checked here. This session cannot read the live Service store. The change does not depend on these numbers. +- Not verified: how GitHub answers the check-run request for a draft whose checks never ran. The contract test uses the recorded GitHub fake, which holds the same answer shape. + +## Existing Tool Considered + +No external tool covers an inbox of the roadmap waits. The existing `devops roadmap inbox` covers the need, and the change extends it. It reuses `read_inbox`, the record keys of `store.py`, `service.repos` and `read_check_runs`. No open tool reads the job records of this repository. + +Cost of this build, as an estimate: about 350,000 tokens to build, about 60,000 tokens to keep the classes in step with the refine record keys, and about 10,000 tokens for each new class that refine adds. Elapsed time is about 3 hours, with the CI waits. + +The change deletes the draft rule at `inbox.py:129` and its test `test_a_draft_of_a_job_is_not_listed_and_is_not_a_persons_pull_request`. The spec scenario "A draft of a job" is replaced by the requirement on the draft class in the delta. diff --git a/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/specs/roadmap-inbox/spec.md b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/specs/roadmap-inbox/spec.md new file mode 100644 index 0000000000..be8e658e86 --- /dev/null +++ b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/specs/roadmap-inbox/spec.md @@ -0,0 +1,111 @@ +## MODIFIED Requirements + +### Requirement: The inbox lists the gates of the jobs in order +`devops roadmap inbox` SHALL list, in this order: ready plan pull requests of the jobs, ready implementation pull requests of the jobs, the open release pull request, items in `status/blocked` with their cause, New items that wait on a person in refine, New items with an unapplied split, New items with an alternatives question, drafts of jobs that are old or have a failed check, old claims, and labels that the repository lacks. A pull request is a job's when the job record of an open item names it in `implement.pr` or `stage.pr`; `implement.pr` wins. A draft of a job SHALL be listed only as a draft line of the draft class. + +#### Scenario: Each category +- **WHEN** the repository holds a ready plan pull request, a ready implementation pull request, a release pull request, a blocked item, a New item that waits on a person in refine, a New item with an unapplied split, a New item with an alternatives question, an old draft of a job, an old claim and a missing label +- **THEN** the output lists one line for each, in the order above + +#### Scenario: A draft of a job +- **WHEN** the record of an item names a draft pull request in `stage.pr`, and the draft is newer than `roadmap.inbox.draft_days` and has no failed check +- **THEN** the output does not list it + +#### Scenario: A staged branch that became an implementation +- **WHEN** one pull request is named by `stage.pr` and by `implement.pr` of an item +- **THEN** it is listed once, as an implementation pull request + +#### Scenario: A pull request that a Job holds +- **WHEN** the record of an item names a ready pull request and a runner Job that no round reported +- **THEN** the output does not list the pull request + +### Requirement: The inbox reads a bounded number of requests and writes none +The inbox SHALL read, for each repository it lists, the open issues, the open pull requests, the repository labels and `.github/labels.yml` once, and the newest commit of that file only when the labels differ. It SHALL read the check runs of the head commit of each open draft of a job, once for each draft. It SHALL NOT call a model, and it SHALL write nothing to GitHub or git. Its dry-run class SHALL be `request-plan`: `--dry-run` SHALL make no request and SHALL list the reads. + +#### Scenario: No write +- **WHEN** the inbox runs on a store that records writes +- **THEN** the store records no write + +#### Scenario: The reads +- **WHEN** the inbox runs against a store that counts reads of open issues, open pull requests and labels +- **THEN** each is read once for each repository, and no read of every issue happens + +#### Scenario: A dry run +- **WHEN** `inbox --dry-run` runs with processes and sockets refused +- **THEN** the exit status is 0, the output says that no request was made, and it lists the reads and no write + +### Requirement: A listing takes one request for each 100 rows +The inbox SHALL read each of its three listings, the open issues, the open pull requests and the repository labels, with one request for each 100 rows. A run for one repository SHALL send one request for each 100 open issues and pull requests, one for each 100 open pull requests, one for each 100 labels, one for `.github/labels.yml`, and one for the newest commit of that file when the labels differ. It SHALL send one request for the check runs of each open draft of a job. + +#### Scenario: The requests of a run +- **WHEN** the plan of the inbox is read for one repository +- **THEN** it holds three listings that repeat for each page, one read of the labels file, one read of the newest commit of that file that only differing labels make, and one check-run read for each open draft of a job + +## ADDED Requirements + +### Requirement: The inbox reads each repository of service.repos by default +Without `--repo`, `devops roadmap inbox` SHALL read each repository of the setting `service.repos`, in its order, and list the lines of each. With `--repo`, it SHALL read that repository only. When `service.repos` is empty and `--repo` is not given, the command SHALL fail with an error that names `service.repos`, and SHALL read no repository. + +#### Scenario: No repository option +- **WHEN** `service.repos` names two repositories and `--repo` is not given +- **THEN** the command reads both repositories and lists the lines of each + +#### Scenario: One repository option +- **WHEN** `--repo` names a repository +- **THEN** the command reads that repository only + +#### Scenario: No repository configured +- **WHEN** `service.repos` is empty and `--repo` is not given +- **THEN** the command exits with status 1 and its error names `service.repos` + +### Requirement: The inbox refuses a service.repos entry that is not owner/name +An entry of `service.repos` that is not `owner/name` SHALL fail `devops roadmap inbox` before any repository is read. The error SHALL name the entry and `service.repos`. + +#### Scenario: An entry that is not owner/name +- **WHEN** `service.repos` holds an entry without `/`, such as `no-owner` +- **THEN** the command exits with status 1, its error names the entry and `service.repos`, and it reads no repository + +### Requirement: The inbox lists each unapplied split and each alternatives question +`devops roadmap inbox` SHALL list one line for each open New item whose `refine.next_step` is `split`, and one line for each open New item whose `refine.alternatives_asked` is set. The split line SHALL show the step that clears it, which is to split the item as the refine comment proposes. The alternatives line SHALL name the covering tool that refine put to a person. An item MAY have one line of each class. + +#### Scenario: An unapplied split +- **WHEN** an open New item records `refine.next_step` as `split` +- **THEN** the output lists one line for it, in the section of the split class, with the step that clears it + +#### Scenario: An alternatives question +- **WHEN** an open New item records `refine.alternatives_asked` as the URL of a covering tool +- **THEN** the output lists one line for it that names the URL of the tool + +#### Scenario: A closed item with a split +- **WHEN** a closed item records `refine.next_step` as `split` +- **THEN** the output lists no split line for it + +### Requirement: The inbox lists a draft of a job that is old or has a failed check +`devops roadmap inbox` SHALL list one line, in the draft class, for each draft of a job that is older than `roadmap.inbox.draft_days` or whose head commit has a failed check run. A draft of a job that no runner Job holds is a draft of a job. A draft that is newer than the setting and has no failed check SHALL have no line. + +#### Scenario: An old draft +- **WHEN** a draft of a job is older than `roadmap.inbox.draft_days` +- **THEN** the output lists one line for it, in the draft class + +#### Scenario: A draft with a failed check +- **WHEN** a draft of a job that is newer than the setting has a failed check run on its head commit +- **THEN** the output lists one line for it, in the draft class, with the step that clears the failed check + +#### Scenario: A draft that waits for its checks +- **WHEN** a draft of a job is newer than `roadmap.inbox.draft_days` and no check run failed +- **THEN** the output lists no line for it + +### Requirement: The inbox states the age of each wait and the classes it holds +Each line whose age is over the setting `roadmap.inbox.wait_days` SHALL show a mark that the wait is over that number of days. After its title, the output SHALL start with the count of the lines of each class, before any line. The option `--kind` SHALL keep only the lines of the class it names, and the counts SHALL stay complete. + +#### Scenario: An old wait +- **WHEN** a line is older than `roadmap.inbox.wait_days` +- **THEN** its line shows the mark with the number of days of the setting + +#### Scenario: Counts by class +- **WHEN** the inbox lists lines of two classes +- **THEN** the output starts, after its title, with the count of each of the two classes + +#### Scenario: The class filter +- **WHEN** `--kind` names one class +- **THEN** the output lists the lines of that class only, and the counts of all classes diff --git a/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/tasks.md b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/tasks.md new file mode 100644 index 0000000000..18b43e0ee0 --- /dev/null +++ b/openspec/changes/archive/2026-11-05-3494-inbox-lists-all-person-waits/tasks.md @@ -0,0 +1,67 @@ +# Tasks + +## 1. Read each repository of service.repos by default + +Kind: behavior. Reads: `src/devops_cli/commands/roadmap.py` (lines 73, 87 to 93, 891 to 917), `src/devops_cli/roadmap/request_plan.py` (lines 854 to 868), `src/devops_cli/config/settings.py` (lines 1066 to 1100). Changes: `src/devops_cli/commands/roadmap.py`, `src/devops_cli/roadmap/request_plan.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/test_roadmap_inbox_command.py`, `tests/roadmap/test_roadmap_inbox_requests.py`. + +- [x] 1.1 Write the failing tests first. In `tests/roadmap/test_roadmap_inbox_command.py`, add `test_without_repo_the_inbox_reads_each_service_repo` (the `config` fixture sets `service.repos` to two repositories, and the `roadmap_store_repos` fixture lists the repositories that the store opens), `test_with_repo_the_inbox_reads_that_repo_only`, and `test_without_repo_and_no_service_repos_the_inbox_fails_naming_the_setting`. In `tests/roadmap/test_roadmap_inbox_requests.py`, add `test_the_dry_run_lists_reads_for_each_service_repo_and_no_write`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox_command.py tests/roadmap/test_roadmap_inbox_requests.py` fails on the base, because the command reads the origin of the checkout only. +- [x] 1.2 In `inbox_cmd` of `src/devops_cli/commands/roadmap.py`, read the repository of `--repo`, or each repository of `service.repos` in order. Raise `ConfigurationError` that names `service.repos` when the list is empty and `--repo` is not given. In `inbox_requests` of `src/devops_cli/roadmap/request_plan.py`, take the repository as a parameter that the command calls once for each repository. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox_command.py tests/roadmap/test_roadmap_inbox_requests.py` passes. +- [x] 1.3 Write the failing test first. In `tests/roadmap/test_roadmap_inbox_command.py`, add `test_a_service_repo_that_is_not_owner_name_fails_before_any_read`, with the one entry `no-owner` in `service.repos`. The test fails until task 1.4 is done. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox_command.py -k not_owner_name` exits 1 and fails the assertion that the output names `service.repos`. +- [x] 1.4 In `_inbox_repos` of `src/devops_cli/commands/roadmap.py`, raise `ConfigurationError` that names the entry and `service.repos` when an entry of `service.repos` is not `owner/name`, before any store opens. Add the message to `src/devops_cli/lang/en/messages.py`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox_command.py` passes. + +## 2. List the unapplied splits and the alternatives questions + +Kind: behavior. Reads: `src/devops_cli/roadmap/inbox.py` (lines 63 to 75, 184 to 215), `src/devops_cli/roadmap/refine.py` (lines 263 to 277, 1196), `src/devops_cli/roadmap/store.py` (lines 134 to 160). Changes: `src/devops_cli/roadmap/inbox.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/test_roadmap_inbox.py`. + +- [x] 2.1 Write the failing tests first. In `tests/roadmap/test_roadmap_inbox.py`, add `test_an_unapplied_split_has_one_line_with_its_step` and `test_an_alternatives_question_has_one_line_naming_the_tool`, and extend the order test `test_every_category_is_listed_once_in_the_order_of_the_gates` with one line of each new class. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox.py` fails on the base, because the inbox has no line for either wait. +- [x] 2.2 In `src/devops_cli/roadmap/inbox.py`, add `InboxKind.SPLIT` and `InboxKind.ALTERNATIVES` after `REFINE`, with `_split_lines` and `_alternatives_lines` that `read_inbox` adds. Add the headings, subjects and clearing steps to `src/devops_cli/lang/en/messages.py`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox.py` passes. + +## 3. List a draft of a job that is old or whose checks failed + +Kind: behavior. Reads: `src/devops_cli/roadmap/store.py` (lines 414 to 424, 730 to 771), `src/devops_cli/roadmap/github_store.py` (lines 206 to 222, 641 to 644), `src/devops_cli/roadmap/memory_store.py` (lines 214 to 230, 518 to 535), `src/devops_cli/github/check_verdict.py` (lines 87 to 88, 374 to 390), `src/devops_cli/roadmap/inbox.py` (lines 120 to 130), `src/devops_cli/roadmap/request_plan.py` (lines 166 to 200). Changes: `src/devops_cli/roadmap/store.py`, `src/devops_cli/roadmap/github_store.py`, `src/devops_cli/roadmap/memory_store.py`, `src/devops_cli/roadmap/inbox.py`, `src/devops_cli/roadmap/request_plan.py`, `src/devops_cli/config/settings.py`, `src/devops_cli/config/defaults.py`, `tests/roadmap/test_roadmap_inbox.py`, `tests/roadmap/test_roadmap_inbox_requests.py`, `tests/roadmap/test_roadmap_store_contract.py`. + +- [x] 3.1 Write the failing tests first. In `tests/roadmap/test_roadmap_inbox.py`, replace `test_a_draft_of_a_job_is_not_listed_and_is_not_a_persons_pull_request` with `test_a_job_draft_that_waits_for_checks_and_is_newer_has_no_line`, and add `test_a_job_draft_older_than_the_setting_has_one_line` and `test_a_job_draft_with_a_failed_check_has_one_line`. In `tests/roadmap/test_roadmap_inbox_requests.py`, add `test_check_reads_are_listed_only_for_open_job_drafts`. In `tests/roadmap/test_roadmap_store_contract.py`, add `test_open_pulls_carry_the_head_sha_and_their_check_runs_read_by_sha`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox.py tests/roadmap/test_roadmap_inbox_requests.py tests/roadmap/test_roadmap_store_contract.py` fails on the base. +- [x] 3.2 Add `head_sha` to `OpenPull` in `src/devops_cli/roadmap/store.py`, with the default `""`. Add `failed_checks(head_sha)` to `RoadmapStore`. Read `head.sha` in `_PullPayload` and implement `failed_checks` in `src/devops_cli/roadmap/github_store.py` with `read_check_runs`, raising `GitHubUnreadError` on an unread summary. Implement both in `src/devops_cli/roadmap/memory_store.py`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_store_contract.py` passes. +- [x] 3.3 Add `RoadmapInboxConfig` with `draft_days` and `wait_days` to `src/devops_cli/config/settings.py` as `roadmap.inbox`, with the defaults `DEFAULT_ROADMAP_INBOX_DRAFT_DAYS` and `DEFAULT_ROADMAP_INBOX_WAIT_DAYS` in `src/devops_cli/config/defaults.py`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox.py` passes once task 3.4 is done. +- [x] 3.4 In `src/devops_cli/roadmap/inbox.py`, read the check runs of each job draft in `read_inbox`, and list a job draft as `InboxKind.DRAFT` when it is older than `draft_days` or its check runs failed. Add `StoreRequests.check_runs` and the condition `job_drafts` to `src/devops_cli/roadmap/request_plan.py`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox.py tests/roadmap/test_roadmap_inbox_requests.py` passes. + +## 4. Mark the old waits, count the classes and filter by class + +Kind: behavior. Reads: `src/devops_cli/roadmap/inbox.py` (lines 77 to 88, 286 to 339), `src/devops_cli/commands/roadmap.py` (lines 891 to 917), `src/devops_cli/lang/en/messages.py` (lines 3542 to 3600). Changes: `src/devops_cli/roadmap/inbox.py`, `src/devops_cli/commands/roadmap.py`, `src/devops_cli/lang/en/messages.py`, `tests/roadmap/test_roadmap_inbox.py`, `tests/roadmap/test_roadmap_inbox_command.py`. + +- [x] 4.1 Write the failing tests first. In `tests/roadmap/test_roadmap_inbox.py`, add `test_a_wait_older_than_the_setting_is_marked`, `test_counts_by_class_lead_the_inbox` and `test_the_class_filter_keeps_one_kind`. In `tests/roadmap/test_roadmap_inbox_command.py`, add `test_the_kind_option_keeps_the_lines_of_one_class`. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox.py tests/roadmap/test_roadmap_inbox_command.py` fails on the base. +- [x] 4.2 Add `old_days` to `InboxLine` and set it in `read_inbox` from `wait_days`. Add a `kinds` parameter to `render_inbox` and print the counts of all lines under the title. Add the option `--kind` to `inbox_cmd` with the type `InboxKind`, so that Typer refuses a value that is no class. + - Verification: `uv run devops ci test tests/roadmap/test_roadmap_inbox.py tests/roadmap/test_roadmap_inbox_command.py` passes. + +## 5. Document the classes, the repositories and the settings + +Kind: other. Reads: `docs/roadmap/inbox.md`, `src/devops_cli/lang/en/help.py` (lines 1569 to 1578). Changes: `docs/roadmap/inbox.md`, `src/devops_cli/lang/en/help.py`, `README.md` when the generator changes it. + +- [x] 5.1 In `src/devops_cli/lang/en/help.py`, state the classes, the default repositories, the option `--kind` and the marks of the command help. Run `uv run devops docs generate --sync-readme`. + - Verification: `uv run devops roadmap inbox --help` names `--kind`, and `uv run devops ci docs` passes. +- [x] 5.2 Rewrite `docs/roadmap/inbox.md` for the classes in their order, the repositories that the command reads, the two settings, the counts and the filter. + - Verification: `uv run devops ci docs` passes. + +## Criteria + +- Each new class has a test: group 2 and group 3. +- A draft of a job that waits for its checks and is newer than the setting has no line: group 3. +- The rule for a returned item is kept and tested: group 2. +- Without `--repo`, the inbox reads each repository of `service.repos`: group 1. +- Counts by class lead the inbox, and the filter keeps one class: group 4. +- `uv run devops ci` passes: the full gate, run before the archive. + +## Workflow follow-up + +- Pending a person: review the diff in tuicr (tuicr -r ..HEAD). diff --git a/openspec/specs/roadmap-inbox/spec.md b/openspec/specs/roadmap-inbox/spec.md index e0354313c7..84ca3e5898 100644 --- a/openspec/specs/roadmap-inbox/spec.md +++ b/openspec/specs/roadmap-inbox/spec.md @@ -6,14 +6,16 @@ How `devops roadmap inbox` lists what waits for a person on the roadmap: the pul ## Requirements ### Requirement: The inbox lists the gates of the jobs in order -`devops roadmap inbox` SHALL list, in this order: ready plan pull requests of the jobs, ready implementation pull requests of the jobs, the open release pull request, items in `status/blocked` with their cause, New items that wait on a person in refine, old claims, and labels that the repository lacks. A pull request is a job's when the job record of an open item names it in `implement.pr` or `stage.pr`; `implement.pr` wins. A draft pull request of a job SHALL NOT be listed. - +`devops roadmap inbox` SHALL list, in this order: ready plan pull requests of the jobs, ready implementation pull requests of the jobs, the open release pull request, items in `status/blocked` with their cause, New items that wait on a person in refine, New items with an unapplied split, New items with an alternatives question, drafts of jobs that are old or have a failed check, old claims, and labels that the repository lacks. #### Scenario: Each category -- **WHEN** the repository holds a ready plan pull request, a ready implementation pull request, a release pull request, a blocked item, a New item that waits on a person in refine, an old claim and a missing label +- **WHEN** the repository holds a ready plan pull request, a ready implementation pull request, a release pull request, a blocked item, a New item that waits on a person in refine, a New item with an unapplied split, a New item with an alternatives question, an old draft of a job, an old claim and a missing label - **THEN** the output lists one line for each, in the order above +### Requirement: The inbox lists each job pull request once +A pull request is a job's when the job record of an open item names it in `implement.pr` or `stage.pr`; `implement.pr` wins. A draft of a job SHALL be listed only as a draft line of the draft class. + #### Scenario: A draft of a job -- **WHEN** the record of an item names a draft pull request in `stage.pr` +- **WHEN** the record of an item names a draft pull request in `stage.pr`, and the draft is newer than `roadmap.inbox.draft_days` and has no failed check - **THEN** the output does not list it #### Scenario: A staged branch that became an implementation @@ -54,7 +56,7 @@ Every open pull request that no job record names and that is not the release pul - **THEN** the first list holds the plan pull request only, and the second list holds the two pull requests of the person, the draft marked as a draft ### Requirement: The inbox reads a bounded number of requests and writes none -The inbox SHALL read the open issues, the open pull requests, the repository labels and `.github/labels.yml` once, and the newest commit of that file only when the labels differ. It SHALL NOT call a model, and it SHALL write nothing to GitHub or git. Its dry-run class SHALL be `request-plan`: `--dry-run` SHALL make no request and SHALL list the reads. +The inbox SHALL read, for each repository it lists, the open issues, the open pull requests, the repository labels and `.github/labels.yml` once, and the newest commit of that file only when the labels differ. It SHALL read the check runs of the head commit of each open draft of a job, once for each draft. It SHALL NOT call a model, and it SHALL write nothing to GitHub or git. Its dry-run class SHALL be `request-plan`: `--dry-run` SHALL make no request and SHALL list the reads. #### Scenario: No write - **WHEN** the inbox runs on a store that records writes @@ -62,18 +64,18 @@ The inbox SHALL read the open issues, the open pull requests, the repository lab #### Scenario: The reads - **WHEN** the inbox runs against a store that counts reads of open issues, open pull requests and labels -- **THEN** each is read once, and no read of every issue happens +- **THEN** each is read once for each repository, and no read of every issue happens #### Scenario: A dry run - **WHEN** `inbox --dry-run` runs with processes and sockets refused - **THEN** the exit status is 0, the output says that no request was made, and it lists the reads and no write ### Requirement: A listing takes one request for each 100 rows -The inbox SHALL read each of its three listings, the open issues, the open pull requests and the repository labels, with one request for each 100 rows. A run SHALL send one request for each 100 open issues and pull requests, one for each 100 open pull requests, one for each 100 labels, one for `.github/labels.yml`, and one for the newest commit of that file when the labels differ. +The inbox SHALL read each of its three listings, the open issues, the open pull requests and the repository labels, with one request for each 100 rows. A run for one repository SHALL send one request for each 100 open issues and pull requests, one for each 100 open pull requests, one for each 100 labels, one for `.github/labels.yml`, and one for the newest commit of that file when the labels differ. It SHALL send one request for the check runs of each open draft of a job. #### Scenario: The requests of a run -- **WHEN** the plan of the inbox is read -- **THEN** it holds three listings that repeat for each page, one read of the labels file, and one read of the newest commit of that file that only differing labels make +- **WHEN** the plan of the inbox is read for one repository +- **THEN** it holds three listings that repeat for each page, one read of the labels file, one read of the newest commit of that file that only differing labels make, and one check-run read for each open draft of a job ### Requirement: The inbox lists each New item that waits on a person in refine `devops roadmap inbox` SHALL list one line for each open New item whose `refine.next_step` is `person`, and for each one whose `refine.returned_body_hash` equals its `refine.body_hash`. The line SHALL show the number, the age, the cause and the step that clears it. The read SHALL use the job record of the open issues only. @@ -100,3 +102,70 @@ The inbox SHALL read each of its three listings, the open issues, the open pull #### Scenario: Under the limit - **WHEN** 1 open item is Planned and the setting is 2 - **THEN** the output lists no such line + +### Requirement: The inbox reads each repository of service.repos by default +Without `--repo`, `devops roadmap inbox` SHALL read each repository of the setting `service.repos`, in its order, and list the lines of each. With `--repo`, it SHALL read that repository only. When `service.repos` is empty and `--repo` is not given, the command SHALL fail with an error that names `service.repos`, and SHALL read no repository. + +#### Scenario: No repository option +- **WHEN** `service.repos` names two repositories and `--repo` is not given +- **THEN** the command reads both repositories and lists the lines of each + +#### Scenario: One repository option +- **WHEN** `--repo` names a repository +- **THEN** the command reads that repository only + +#### Scenario: No repository configured +- **WHEN** `service.repos` is empty and `--repo` is not given +- **THEN** the command exits with status 1 and its error names `service.repos` + +### Requirement: The inbox refuses a service.repos entry that is not owner/name +An entry of `service.repos` that is not `owner/name` SHALL fail `devops roadmap inbox` before any repository is read. The error SHALL name the entry and `service.repos`. + +#### Scenario: An entry that is not owner/name +- **WHEN** `service.repos` holds an entry without `/`, such as `no-owner` +- **THEN** the command exits with status 1, its error names the entry and `service.repos`, and it reads no repository + +### Requirement: The inbox lists each unapplied split and each alternatives question +`devops roadmap inbox` SHALL list one line for each open New item whose `refine.next_step` is `split`, and one line for each open New item whose `refine.alternatives_asked` is set. The split line SHALL show the step that clears it, which is to split the item as the refine comment proposes. The alternatives line SHALL name the covering tool that refine put to a person. An item MAY have one line of each class. + +#### Scenario: An unapplied split +- **WHEN** an open New item records `refine.next_step` as `split` +- **THEN** the output lists one line for it, in the section of the split class, with the step that clears it + +#### Scenario: An alternatives question +- **WHEN** an open New item records `refine.alternatives_asked` as the URL of a covering tool +- **THEN** the output lists one line for it that names the URL of the tool + +#### Scenario: A closed item with a split +- **WHEN** a closed item records `refine.next_step` as `split` +- **THEN** the output lists no split line for it + +### Requirement: The inbox lists a draft of a job that is old or has a failed check +`devops roadmap inbox` SHALL list one line, in the draft class, for each draft of a job that is older than `roadmap.inbox.draft_days` or whose head commit has a failed check run. A draft of a job that no runner Job holds is a draft of a job. A draft that is newer than the setting and has no failed check SHALL have no line. + +#### Scenario: An old draft +- **WHEN** a draft of a job is older than `roadmap.inbox.draft_days` +- **THEN** the output lists one line for it, in the draft class + +#### Scenario: A draft with a failed check +- **WHEN** a draft of a job that is newer than the setting has a failed check run on its head commit +- **THEN** the output lists one line for it, in the draft class, with the step that clears the failed check + +#### Scenario: A draft that waits for its checks +- **WHEN** a draft of a job is newer than `roadmap.inbox.draft_days` and no check run failed +- **THEN** the output lists no line for it + +### Requirement: The inbox states the age of each wait and the classes it holds +Each line whose age is over the setting `roadmap.inbox.wait_days` SHALL show a mark that the wait is over that number of days. After its title, the output SHALL start with the count of the lines of each class, before any line. The option `--kind` SHALL keep only the lines of the class it names, and the counts SHALL stay complete. + +#### Scenario: An old wait +- **WHEN** a line is older than `roadmap.inbox.wait_days` +- **THEN** its line shows the mark with the number of days of the setting + +#### Scenario: Counts by class +- **WHEN** the inbox lists lines of two classes +- **THEN** the output starts, after its title, with the count of each of the two classes + +#### Scenario: The class filter +- **WHEN** `--kind` names one class +- **THEN** the output lists the lines of that class only, and the counts of all classes diff --git a/src/devops_cli/commands/roadmap.py b/src/devops_cli/commands/roadmap.py index dd89dfa482..2c907189cf 100644 --- a/src/devops_cli/commands/roadmap.py +++ b/src/devops_cli/commands/roadmap.py @@ -41,6 +41,7 @@ from devops_cli.core.repo import find_repo_root, get_repo_origin_name from devops_cli.dry_run import PlannedRequest, dry_run_class, is_dry_run from devops_cli.exceptions import DevOpsCLIError, RoadmapRunError +from devops_cli.exceptions.config import ConfigurationError from devops_cli.lang import HELP, MESSAGES from devops_cli.output import print_error, print_info, print_success, write_stdout from devops_cli.roadmap import store as roadmap_store @@ -51,6 +52,7 @@ plan_claim, render_claim_plan, ) +from devops_cli.roadmap.inbox_kind import InboxKind from devops_cli.roadmap.intake import ( Filer, NewCandidate, @@ -892,29 +894,54 @@ def explain_cmd( @dry_run_class("request-plan") def inbox_cmd( repo: RepoOption = None, + kind: Annotated[InboxKind | None, typer.Option("--kind", help=HELP.roadmap.inbox_kind)] = None, dry_run: Annotated[bool, typer.Option("--dry-run", help=HELP.roadmap.inbox_dry_run)] = False, ) -> None: - """List what waits for a person, each line with its age and the step that clears it.""" + """List what waits for a person in each repository, each line with its age and the step + that clears it. Without --repo, the repositories are those of service.repos.""" from datetime import UTC, datetime from devops_cli.config.settings import load_settings from devops_cli.roadmap.inbox import read_inbox, render_inbox from devops_cli.roadmap.request_plan import inbox_requests - target = _target(repo) + kinds = None if kind is None else frozenset({kind}) + settings = load_settings() + targets = _inbox_repos(repo, settings.service.repos) if dry_run or is_dry_run(): - reads, writes = inbox_requests(target) - render_dry_run("inbox", target, reads, writes) + for target in targets: + reads, writes = inbox_requests(target) + render_dry_run("inbox", target, reads, writes) return - with _exit_on_failure("Could not read the inbox"): - _, store = _open_store(target) - inbox = read_inbox( - store, - repo=target, - now=datetime.now(UTC), - planned_limit=load_settings().roadmap.stage.planned_limit, - ) - write_stdout(render_inbox(inbox, repo=target) + "\n") + for target in targets: + with _exit_on_failure("Could not read the inbox"): + _, store = _open_store(target) + inbox = read_inbox( + store, + repo=target, + now=datetime.now(UTC), + planned_limit=settings.roadmap.stage.planned_limit, + draft_days=settings.roadmap.inbox.draft_days, + wait_days=settings.roadmap.inbox.wait_days, + ) + write_stdout(render_inbox(inbox, repo=target, kinds=kinds) + "\n") + + +def _inbox_repos(repo: str | None, configured: Sequence[str]) -> list[str]: + """The repositories the inbox reads: `--repo` alone when it is given, else each entry of + `service.repos`. An empty list fails and names the setting, and so does an entry that is not + `owner/name`, before any store opens (#3494).""" + if repo is not None: + return [_target(repo)] + if not configured: + raise ConfigurationError(MESSAGES.roadmap.inbox_no_repos, key="service.repos") + for entry in configured: + owner, _, name = entry.partition("/") + if not owner or not name or "/" in name: + raise ConfigurationError( + MESSAGES.roadmap.inbox_bad_repo.format(entry=entry), key="service.repos" + ) + return list(configured) @app.command("repair", help=HELP.roadmap.repair) diff --git a/src/devops_cli/config/defaults.py b/src/devops_cli/config/defaults.py index a9dfef1fbc..7b44b0d4cb 100644 --- a/src/devops_cli/config/defaults.py +++ b/src/devops_cli/config/defaults.py @@ -720,6 +720,8 @@ # The minutes between two runs of a row are prime numbers (#2965): no two rows keep the same # poll tick for long, and no row lands on a multiple of 5 minutes. DEFAULT_ROADMAP_INTAKE_INTERVAL_MINUTES: int = 29 +DEFAULT_ROADMAP_INBOX_DRAFT_DAYS: int = 7 +DEFAULT_ROADMAP_INBOX_WAIT_DAYS: int = 7 # How often refine is due on its own, besides its cross-job trigger (#1515). DEFAULT_ROADMAP_REFINE_INTERVAL_MINUTES: int = 31 DEFAULT_ROADMAP_METRICS_INTERVAL_MINUTES: int = 13 diff --git a/src/devops_cli/config/settings.py b/src/devops_cli/config/settings.py index cc2b2fb5c1..19c00b034a 100644 --- a/src/devops_cli/config/settings.py +++ b/src/devops_cli/config/settings.py @@ -109,6 +109,8 @@ DEFAULT_ROADMAP_IMPLEMENT_REQUEST_TIMEOUT_SECONDS, DEFAULT_ROADMAP_IMPLEMENT_STEP_TIME_LIMIT_SECONDS, DEFAULT_ROADMAP_IMPLEMENT_STEP_TOKEN_BUDGET, + DEFAULT_ROADMAP_INBOX_DRAFT_DAYS, + DEFAULT_ROADMAP_INBOX_WAIT_DAYS, DEFAULT_ROADMAP_STAGE_FILTER, DEFAULT_ROADMAP_STAGE_LIMIT, DEFAULT_ROADMAP_STAGE_PLANNED_LIMIT, @@ -1153,12 +1155,30 @@ class AlternativesConfig(BaseModel): ) +class RoadmapInboxConfig(BaseModel): + """The two ages of `devops roadmap inbox` (#3494).""" + + model_config = ConfigDict(extra="ignore", validate_assignment=True, hide_input_in_errors=True) + + draft_days: int = Field( + default=DEFAULT_ROADMAP_INBOX_DRAFT_DAYS, + ge=1, + description="The age in days at which the inbox lists a draft of a job with no failed check. A newer draft with no failed check is not listed.", + ) + wait_days: int = Field( + default=DEFAULT_ROADMAP_INBOX_WAIT_DAYS, + ge=1, + description="The age in days at which the inbox marks a line as old.", + ) + + class RoadmapConfig(BaseModel): model_config = ConfigDict(extra="ignore", validate_assignment=True, hide_input_in_errors=True) alternatives: AlternativesConfig = Field(default_factory=AlternativesConfig) stage: RoadmapStageConfig = Field(default_factory=RoadmapStageConfig) implement: RoadmapImplementConfig = Field(default_factory=RoadmapImplementConfig) + inbox: RoadmapInboxConfig = Field(default_factory=RoadmapInboxConfig) class DataConfig(BaseModel): diff --git a/src/devops_cli/github/check_verdict.py b/src/devops_cli/github/check_verdict.py index 7b2d419b4d..38df91d684 100644 --- a/src/devops_cli/github/check_verdict.py +++ b/src/devops_cli/github/check_verdict.py @@ -4,9 +4,10 @@ import json import logging +from collections.abc import Iterator from enum import StrEnum from pathlib import Path -from typing import Any, Final +from typing import Any, Final, Protocol from pydantic import BaseModel, Field @@ -305,8 +306,14 @@ def _parse_rest_commit_statuses_payload( return status_items, combined_item +class PaginatingSession(Protocol): + """A session that reads a REST listing page by page, such as `GitHubSession` (#3494).""" + + def paginate(self, path: str, *, iterable_key: str | None = None) -> Iterator[Any]: ... + + def _fetch_check_runs_from_rest( - owner: str, repo_name: str, head_sha: str, session: GitHubSession | None + owner: str, repo_name: str, head_sha: str, session: PaginatingSession | None ) -> tuple[list[PRCheckItem], str]: """Read every page of a commit's check runs through the GitHub session, the process's own unless `session` is given, returning (items, unread_reason). A page that can't be read, or @@ -376,7 +383,7 @@ def read_check_runs( repo_name: str, head_sha: str, *, - session: GitHubSession | None = None, + session: PaginatingSession | None = None, ) -> CheckVerdictSummary: """Read and classify the check runs of a commit, failing closed, with no commit status. diff --git a/src/devops_cli/lang/en/help.py b/src/devops_cli/lang/en/help.py index 01d197b429..dc37c1c71a 100644 --- a/src/devops_cli/lang/en/help.py +++ b/src/devops_cli/lang/en/help.py @@ -1567,10 +1567,14 @@ class RoadmapCommandHelp: "that run commands." ) inbox: str = ( - "List what waits for a person, each line with its number, its age and the one command or " - "action that clears it, and a line when the count of Planned items is at the setting " - "roadmap.stage.planned_limit. It reads GitHub, calls no model and writes nothing. " - "Details: docs/roadmap/inbox.md." + "List what waits for a person in each repository of service.repos, or in the one that " + "--repo names. Each line has its number, its age and the step that clears it, and an old " + "wait is marked. It reads GitHub, calls no model and writes nothing; details: " + "docs/roadmap/inbox.md." + ) + inbox_kind: str = ( + "List only the lines of one class, such as refine, split, alternatives or draft. The " + "counts of every class stay complete." ) inbox_dry_run: str = ( "Make no request: print the reads that a run makes, in order, with placeholders." diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 698fcde7f0..eb8ec790c7 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -3542,6 +3542,10 @@ class RoadmapMessages: # `devops roadmap inbox` (#2915). inbox_title: str = "Waiting for a person in {repo}. The age is the time since the last update." inbox_empty: str = "Nothing waits for a person in {repo}." + inbox_no_repos: str = ( + "The inbox has no repository to read. Set service.repos, or pass --repo owner/name." + ) + inbox_bad_repo: str = "The service.repos entry {entry} is not owner/name." inbox_footer: str = ( "Not listed: an image digest that is not rolled yet. " "Run `devops argo cd apps status devops` to read it." @@ -3553,6 +3557,9 @@ class RoadmapMessages: "release": "The release pull request (G3)", "blocked": "Items in status/blocked", "refine": "New items that wait on a person in refine", + "split": "New items with a split that no person has applied", + "alternatives": "New items with a covering tool that refine put to a person", + "draft": "Drafts of jobs that are old or have a failed check", "claim": "Claims with no activity for {days} days", "labels": "Repository state that a person owns", "queue": "The stage job waits for deliveries", @@ -3561,6 +3568,9 @@ class RoadmapMessages: ) inbox_line: str = " {number} {age} {subject}" inbox_clear: str = " Clear it: {clear}" + inbox_counts: str = "Counts by class: {counts}." + inbox_count: str = "{kind} {count}" + inbox_old: str = "(over {days} days)" inbox_no_number: str = "-" inbox_no_age: str = "-" inbox_subjects: dict[str, str] = field( @@ -3572,7 +3582,11 @@ class RoadmapMessages: "no_cause": "{title}: no cause is recorded", "refine": "{title}: refine waits on a person", "refine_returned": "{title}: the stage job returned it twice on the same body", + "split": "{title}: refine proposed a split, not applied", + "alternatives": "{title}: refine put a covering tool to a person: {tool}", "claim": "{title} (claimed by {owner})", + "draft_old": "{title} (draft, no update for more than {days} days)", + "draft_failed": "{title} (draft, a check failed)", "labels": "{count} label(s) of {path} are missing or changed on GitHub: {names}", "more_labels": "{names}, and {more} more", "queue": ( @@ -3591,6 +3605,17 @@ class RoadmapMessages: "Wait for the checks with `devops pr monitor {number} --repo {repo}`, " "then run `devops pr ready {number} --repo {repo}`." ), + "draft_old": ("Finish the draft, then run `devops pr monitor {number} --repo {repo}`."), + "draft_failed": ( + "Fix the failed check, then run `devops pr monitor {number} --repo {repo}`." + ), + "split": ( + "Split it as refine proposed in a comment on #{number}, or edit its body to fit " + "one pull request." + ), + "alternatives": ( + "Answer in a comment on #{number}. Refine reads the answer in its next round." + ), "stopped": "Fix the cause, then comment `{retry}` on #{number}.", "blocked": ( "Fix the cause, then set the status by hand: `devops gh issues edit {number} " @@ -3609,9 +3634,11 @@ class RoadmapMessages: } ) plan_repeat_page: str = "per page, while GitHub links a next one" + plan_repeat_draft: str = "for each open draft of a job" plan_placeholders: dict[str, str] = field( default_factory=lambda: { "number": "", + "head_sha": "", "deferred_part": "", "milestone": "", "labels": "", @@ -3643,6 +3670,7 @@ class RoadmapMessages: default_factory=lambda: { "file": "{path} at {ref}", "milestones": "every milestone", + "check_runs": "the check runs of the head commit of an open draft of a job", "issues": "the issues ({query})", "comments": "the comments on {subject}", "issue": "{subject}", @@ -3688,6 +3716,7 @@ class RoadmapMessages: plan_conditions: dict[str, str] = field( default_factory=lambda: { "posted": "the change posts a comment", + "job_drafts": "the pull request is an open draft of a job", "check_on": "the repository is public and a Firecrawl key is set", "issues_unread": "the run has not read every issue yet", "labels_differ": "the labels of the repository differ from .github/labels.yml", diff --git a/src/devops_cli/roadmap/github_store.py b/src/devops_cli/roadmap/github_store.py index ebc420a465..aaa0b03aa9 100644 --- a/src/devops_cli/roadmap/github_store.py +++ b/src/devops_cli/roadmap/github_store.py @@ -47,7 +47,12 @@ CONST_GH_RAW_CONTENT_ACCEPT, ) from devops_cli.config.defaults import DEFAULT_GH_ISSUE_TIMELINE_LIMIT, DEFAULT_GH_REST_PER_PAGE -from devops_cli.exceptions.git import GitHubFileNotFoundError, GitHubOperationError +from devops_cli.exceptions.git import ( + GitHubFileNotFoundError, + GitHubOperationError, + GitHubUnreadError, +) +from devops_cli.github.check_verdict import read_check_runs from devops_cli.github.error_classifier import classify_gh_failure, gh_http_status from devops_cli.github.rate_limiter import run_gh from devops_cli.github.session import get_github_session @@ -209,6 +214,7 @@ class _PullPayload(BaseModel): html_url: str draft: bool = False head_ref: str = Field(validation_alias=AliasPath("head", "ref")) + head_sha: str = Field(default="", validation_alias=AliasPath("head", "sha")) updated_at: datetime def pull(self) -> OpenPull: @@ -217,6 +223,7 @@ def pull(self) -> OpenPull: title=self.title, url=self.html_url, head_ref=self.head_ref, + head_sha=self.head_sha, draft=self.draft, updated_at=self.updated_at, ) @@ -643,6 +650,15 @@ def open_pulls(self) -> list[OpenPull]: listing = self._listing(pulls_endpoint(self._repo), _PULL, "pull requests") return [pull.pull() for pull in listing] + def failed_checks(self, head_sha: str) -> bool: + """Whether a check run of the commit `head_sha` failed, read through the listing session. + A read that GitHub does not answer raises, so no draft shows as passing (#3494).""" + owner, _, name = self._repo.partition("/") + summary = read_check_runs(owner, name, head_sha, session=self._listing_session()) + if summary.unread_reason: + raise GitHubUnreadError(summary.unread_reason, operation="check_runs") + return summary.fail_count > 0 + def repository_labels(self) -> list[RepositoryLabel]: """The labels of the repository, one page for each 100.""" listing = self._listing(labels_endpoint(self._repo), _LABEL, "labels") diff --git a/src/devops_cli/roadmap/inbox.py b/src/devops_cli/roadmap/inbox.py index 2345f2d03a..c6f864616a 100644 --- a/src/devops_cli/roadmap/inbox.py +++ b/src/devops_cli/roadmap/inbox.py @@ -9,13 +9,15 @@ **The jobs' lines**, in the order of the gates (docs/ROADMAP_WORKFLOW.md): ready plan pull requests (G1), ready implementation pull requests (G2), the release pull request (G3), items in `status/blocked` with their cause, New items that wait on a person in refine (one line for each, -from the job record alone, #3483), old claims, labels that the repository lacks, and the Planned -queue when it is at the limit of the stage job (#3487). A pull request is a job's when the job -record of an open item names it: `implement.pr` makes it an implementation, `stage.pr` a plan, and -`implement.pr` wins because a staged branch keeps one pull request through both jobs. A draft of a -job waits for its checks, so it is not listed, and a pull request that a runner Job holds is not -listed: the Job pushes to it. The release pull request is -the open one whose head branch starts with the prefix of release-please. +from the job record alone, #3483), New items with an unapplied split, New items with an +alternatives question (#3494), drafts of jobs, old claims, labels that the repository lacks, and +the Planned queue when it is at the limit of the stage job (#3487). A pull request is a job's when +the job record of an open item names it: `implement.pr` makes it an implementation, `stage.pr` a +plan, and `implement.pr` wins because a staged branch keeps one pull request through both jobs. A +draft of a job is listed when it is older than `roadmap.inbox.draft_days`, or when a check run of +its head commit failed. A pull request that a runner Job holds is not listed: the Job pushes to it. +The release pull request is the open one whose head branch starts with the prefix of +release-please. **The people's lines** are every other open pull request, so a person's own pull requests are apart from the jobs'. A draft is marked as a draft. @@ -28,9 +30,8 @@ from __future__ import annotations from collections.abc import Iterable, Mapping, Sequence -from dataclasses import dataclass +from dataclasses import dataclass, replace from datetime import datetime, timedelta -from enum import StrEnum from devops_cli.config.constants import ( CONST_ROADMAP_IMPLEMENT_RETRY_COMMENT, @@ -45,6 +46,7 @@ from devops_cli.github.labels import diff_labels from devops_cli.lang import MESSAGES from devops_cli.output import format_duration +from devops_cli.roadmap.inbox_kind import InboxKind from devops_cli.roadmap.planned import planned_count from devops_cli.roadmap.pull_labels import declared_specs from devops_cli.roadmap.refine import NextStep @@ -60,20 +62,6 @@ ) -class InboxKind(StrEnum): - """What a line of the inbox is. The members are in the order the inbox lists them.""" - - PLAN = "plan" - IMPLEMENT = "implement" - RELEASE = "release" - BLOCKED = "blocked" - REFINE = "refine" - CLAIM = "claim" - LABELS = "labels" - QUEUE = "queue" - PERSON = "person" - - @dataclass(frozen=True) class InboxLine: """One thing that waits for a person: what it is, the number of its issue or pull request @@ -85,6 +73,7 @@ class InboxLine: age: timedelta | None subject: str clear: str + old_days: int | None = None @dataclass(frozen=True) @@ -118,15 +107,37 @@ def _named_pulls(items: Iterable[Item]) -> dict[int, InboxKind | None]: def _pull_kind(pull: OpenPull, named: Mapping[int, InboxKind | None]) -> InboxKind | None: - """The kind of the line of `pull`, or None when no person must act on it now: a draft of a - job or the release, or a pull request that a runner Job holds.""" + """The kind of the line of `pull`, or None when no line shows it: a draft of the release, or + a pull request that a runner Job holds. A draft of a job is `InboxKind.DRAFT` (#3494).""" if pull.head_ref.startswith(CONST_ROADMAP_RELEASE_BRANCH_PREFIX): - kind: InboxKind | None = InboxKind.RELEASE - elif pull.number in named: - kind = named[pull.number] - else: + return None if pull.draft else InboxKind.RELEASE + if pull.number not in named: return InboxKind.PERSON - return None if pull.draft else kind + kind = named[pull.number] + if kind is None: + return None + return InboxKind.DRAFT if pull.draft else kind + + +def _failing_drafts( + store: RoadmapStore, pulls: Sequence[OpenPull], named: Mapping[int, InboxKind | None] +) -> frozenset[int]: + """The numbers of the drafts of jobs whose head commit has a failed check run. Only the + drafts of jobs are read, one check-run read for each (#3494).""" + return frozenset( + pull.number + for pull in pulls + if _pull_kind(pull, named) is InboxKind.DRAFT and store.failed_checks(pull.head_sha) + ) + + +def _draft_line(pull: OpenPull, repo: str, now: datetime, *, failed: bool, days: int) -> InboxLine: + """The line of a draft of a job: its failed check when one failed, else its age (#3494).""" + texts = MESSAGES.roadmap + key = "draft_failed" if failed else "draft_old" + subject = texts.inbox_subjects[key].format(title=pull.title, days=days) + clear = texts.inbox_clears[key].format(number=pull.number, repo=repo) + return InboxLine(InboxKind.DRAFT, pull.number, _age(now, pull.updated_at), subject, clear) def _age(now: datetime, moment: datetime | None) -> timedelta | None: @@ -144,13 +155,26 @@ def _pull_line(pull: OpenPull, kind: InboxKind, repo: str, now: datetime) -> Inb def _pull_lines( - pulls: Iterable[OpenPull], named: Mapping[int, InboxKind | None], repo: str, now: datetime + pulls: Iterable[OpenPull], + named: Mapping[int, InboxKind | None], + failing: frozenset[int], + repo: str, + now: datetime, + draft_days: int, ) -> list[InboxLine]: + """The lines of the pull requests. A draft of a job has a line when a check run of its head + commit failed, or when it is older than `draft_days` (#3494).""" lines: list[InboxLine] = [] for pull in pulls: kind = _pull_kind(pull, named) - if kind is not None: + if kind is None: + continue + if kind is not InboxKind.DRAFT: lines.append(_pull_line(pull, kind, repo, now)) + elif pull.number in failing or now - pull.updated_at > timedelta(days=draft_days): + lines.append( + _draft_line(pull, repo, now, failed=pull.number in failing, days=draft_days) + ) return lines @@ -215,6 +239,47 @@ def _refine_lines(items: Iterable[Item], repo: str, now: datetime) -> list[Inbox return lines +def _open_new(item: Item) -> bool: + return item.state is GitHubState.OPEN and item.status == CONST_ROADMAP_STATUS_NEW + + +def _split_lines(items: Iterable[Item], now: datetime) -> list[InboxLine]: + """One line for each open New item whose refine next step is a split, which no person has + applied yet (#3494).""" + texts = MESSAGES.roadmap + return [ + InboxLine( + InboxKind.SPLIT, + item.number, + _age(now, item.updated_at), + texts.inbox_subjects["split"].format(title=item.title), + texts.inbox_clears["split"].format(number=item.number), + ) + for item in items + if _open_new(item) + and item.job_record.get(RefineRecordKey.NEXT_STEP) == NextStep.SPLIT.value + ] + + +def _alternatives_lines(items: Iterable[Item], now: datetime) -> list[InboxLine]: + """One line for each open New item whose refine round put a covering tool to a person + (#3494). The line names the tool that the round recorded.""" + texts = MESSAGES.roadmap + lines: list[InboxLine] = [] + for item in items: + tool = item.job_record.get(RefineRecordKey.ALTERNATIVES_ASKED) + if not _open_new(item) or not tool: + continue + subject = texts.inbox_subjects["alternatives"].format(title=item.title, tool=tool) + clear = texts.inbox_clears["alternatives"].format(number=item.number) + lines.append( + InboxLine( + InboxKind.ALTERNATIVES, item.number, _age(now, item.updated_at), subject, clear + ) + ) + return lines + + def _activity(item: Item, pulls: Sequence[OpenPull]) -> datetime | None: """The newest update of the issue of `item` and of each open pull request on a branch that names the issue.""" @@ -277,13 +342,29 @@ def _queue_lines(items: Iterable[Item], repo: str, planned_limit: int) -> list[I return [InboxLine(InboxKind.QUEUE, None, None, subject, clear)] +def _marked(line: InboxLine, wait_days: int) -> InboxLine: + """The line with its mark when its wait is over `wait_days` (#3494). A line with no age is + never marked.""" + if line.age is None or line.age <= timedelta(days=wait_days): + return line + return replace(line, old_days=wait_days) + + def _order(line: InboxLine) -> tuple[int, bool, float]: """Kind order, then the oldest first, a line with no age last.""" seconds = line.age.total_seconds() if line.age is not None else 0.0 return (list(InboxKind).index(line.kind), line.age is None, -seconds) -def read_inbox(store: RoadmapStore, *, repo: str, now: datetime, planned_limit: int) -> Inbox: +def read_inbox( + store: RoadmapStore, + *, + repo: str, + now: datetime, + planned_limit: int, + draft_days: int, + wait_days: int, +) -> Inbox: """What waits for a person in `repo` at `now`. It reads the open items, the open pull requests, the labels and the labels file, and the newest commit of that file when the labels differ, and writes nothing. A line states when the count of Planned items is at @@ -291,15 +372,18 @@ def read_inbox(store: RoadmapStore, *, repo: str, now: datetime, planned_limit: labels file of a repository that has none fails the read.""" items = store.open_items() pulls = store.open_pulls() + named = _named_pulls(items) lines = [ - *_pull_lines(pulls, _named_pulls(items), repo, now), + *_pull_lines(pulls, named, _failing_drafts(store, pulls, named), repo, now, draft_days), *_blocked_lines(items, repo, now), *_refine_lines(items, repo, now), + *_split_lines(items, now), + *_alternatives_lines(items, now), *_claim_lines(items, pulls, repo, now), *_label_lines(store, repo, now), *_queue_lines(items, repo, planned_limit), ] - ordered = sorted(lines, key=_order) + ordered = sorted((_marked(line, wait_days) for line in lines), key=_order) return Inbox( jobs=tuple(line for line in ordered if line.kind is not InboxKind.PERSON), people=tuple(line for line in ordered if line.kind is InboxKind.PERSON), @@ -310,7 +394,10 @@ def _render_line(line: InboxLine) -> str: texts = MESSAGES.roadmap number = texts.inbox_no_number if line.number is None else f"#{line.number}" age = texts.inbox_no_age if line.age is None else format_duration(line.age.total_seconds()) - head = texts.inbox_line.format(number=number, age=age, subject=line.subject) + subject = line.subject + if line.old_days is not None: + subject = f"{subject} {texts.inbox_old.format(days=line.old_days)}" + head = texts.inbox_line.format(number=number, age=age, subject=subject) return f"{head}\n{texts.inbox_clear.format(clear=line.clear)}" @@ -321,19 +408,35 @@ def _render_section(kind: InboxKind, lines: Sequence[InboxLine]) -> str: return "\n".join([heading, *(_render_line(line) for line in lines)]) -def render_inbox(inbox: Inbox, *, repo: str) -> str: - """The inbox as the report of the command: a section for each kind that has a line, the - jobs' sections first, then the people's, and the note on what the inbox leaves out.""" +def _counts(lines: Sequence[InboxLine]) -> str: + """The count of the lines of each class that has one, in the order of the classes (#3494).""" texts = MESSAGES.roadmap - lines = (*inbox.jobs, *inbox.people) - if not lines: + parts = [ + texts.inbox_count.format(kind=kind.value, count=count) + for kind in InboxKind + if (count := sum(1 for line in lines if line.kind is kind)) + ] + return texts.inbox_counts.format(counts=", ".join(parts)) + + +def render_inbox(inbox: Inbox, *, repo: str, kinds: frozenset[InboxKind] | None = None) -> str: + """The inbox as the report of the command: the title, the count of the lines of each class, + a section for each kind that has a line, the jobs' sections first, then the people's, and the + note on what the inbox leaves out. `kinds` keeps the lines of those classes only, and the + counts stay complete (#3494).""" + texts = MESSAGES.roadmap + every = (*inbox.jobs, *inbox.people) + if not every: return f"{texts.inbox_empty.format(repo=repo)}\n\n{texts.inbox_footer}" + lines = [line for line in every if kinds is None or line.kind in kinds] sections = [ _render_section(kind, [line for line in lines if line.kind is kind]) for kind in InboxKind if any(line.kind is kind for line in lines) ] - return "\n\n".join([texts.inbox_title.format(repo=repo), *sections, texts.inbox_footer]) + return "\n\n".join( + [texts.inbox_title.format(repo=repo), _counts(every), *sections, texts.inbox_footer] + ) __all__ = ["Inbox", "InboxKind", "InboxLine", "read_inbox", "render_inbox"] diff --git a/src/devops_cli/roadmap/inbox_kind.py b/src/devops_cli/roadmap/inbox_kind.py new file mode 100644 index 0000000000..745152c2c4 --- /dev/null +++ b/src/devops_cli/roadmap/inbox_kind.py @@ -0,0 +1,25 @@ +"""The kinds of the lines of the inbox, in the order the inbox lists them (#3494). + +The command module builds the `--kind` option from this enum. It lives apart from `inbox.py`, +which imports the refine module and so the agent framework, and `devops roadmap --help` must not +load that framework (`tests/gate/startup_imports.py`). +""" + +from enum import StrEnum + + +class InboxKind(StrEnum): + """What a line of the inbox is. The members are in the order the inbox lists them.""" + + PLAN = "plan" + IMPLEMENT = "implement" + RELEASE = "release" + BLOCKED = "blocked" + REFINE = "refine" + SPLIT = "split" + ALTERNATIVES = "alternatives" + DRAFT = "draft" + CLAIM = "claim" + LABELS = "labels" + QUEUE = "queue" + PERSON = "person" diff --git a/src/devops_cli/roadmap/memory_store.py b/src/devops_cli/roadmap/memory_store.py index d06af96fc1..9bcf1d4b9f 100644 --- a/src/devops_cli/roadmap/memory_store.py +++ b/src/devops_cli/roadmap/memory_store.py @@ -109,6 +109,8 @@ class _Roadmap: repositories: dict[str, RepositoryFacts] = field(default_factory=dict) # The head branch and draft state of each pull request `seed_pull` made, by number. pulls: dict[int, tuple[str, bool]] = field(default_factory=dict) + heads: dict[int, str] = field(default_factory=dict) + failing: set[str] = field(default_factory=set) labels: list[RepositoryLabel] = field(default_factory=list) @@ -219,11 +221,17 @@ def seed_pull( draft: bool = False, state: GitHubState = GitHubState.OPEN, updated_at: datetime | None = None, + head_sha: str = "", + checks_failed: bool = False, ) -> int: """Open a pull request on the branch `head_ref`, a draft when `draft`, returning its - number. It is an issue that is a pull request, so it shares the numbers of the issues.""" + number. It is an issue that is a pull request, so it shares the numbers of the issues. + Its head commit is `head_sha`, and `checks_failed` makes a check run of that commit fail.""" number = self.seed_issue(title, state=state, pull_request=True, updated_at=updated_at) self._roadmap.pulls[number] = (head_ref, draft) + self._roadmap.heads[number] = head_sha + if checks_failed: + self._roadmap.failing.add(head_sha) return number def seed_label(self, name: str, color: str, description: str = "") -> None: @@ -527,6 +535,7 @@ def open_pulls(self) -> list[OpenPull]: title=issue.title, url=issue.url, head_ref=head_ref, + head_sha=self._roadmap.heads.get(issue.number, ""), draft=draft, updated_at=issue.updated_at or self._roadmap.clock(), ) @@ -534,6 +543,10 @@ def open_pulls(self) -> list[OpenPull]: if issue.state is GitHubState.OPEN ] + def failed_checks(self, head_sha: str) -> bool: + """Whether a check run of the commit `head_sha` failed, as the seeded pulls say.""" + return head_sha in self._roadmap.failing + def repository_labels(self) -> list[RepositoryLabel]: """The labels that `seed_label` made.""" return list(self._roadmap.labels) diff --git a/src/devops_cli/roadmap/request_plan.py b/src/devops_cli/roadmap/request_plan.py index 4758e9b366..0a90c0c5f0 100644 --- a/src/devops_cli/roadmap/request_plan.py +++ b/src/devops_cli/roadmap/request_plan.py @@ -171,6 +171,15 @@ def open_pulls(self) -> Requests: """The listing of the open pull requests (#2915).""" return self.listing(gh.pulls_endpoint(self.repo), "open_pulls") + def check_runs(self) -> Requests: + """The check runs of the head commit of each open draft of a job, one read for each + draft (#3494). The commit is a placeholder, since the run learns it from the listing.""" + path = f"/repos/{self.repo}/commits/{_p('head_sha')}/check-runs?per_page=100" + request = planned_session_read( + path, self._target("check_runs"), repeat=MESSAGES.roadmap.plan_repeat_draft + ) + return within([request], MESSAGES.roadmap.plan_conditions["job_drafts"]) + def repository_labels(self) -> Requests: """The listing of the labels of the repository (#2915).""" return self.listing(gh.labels_endpoint(self.repo), "repository_labels") @@ -856,8 +865,9 @@ def inbox_requests( ) -> tuple[tuple[PlannedRequest, ...], tuple[PlannedRequest, ...]]: """What `devops roadmap inbox` reads, in order (#2915). It reads the open issues, the open pull requests, the labels of the repository and `.github/labels.yml` on the default branch, - and the newest commit that changed that file only when the labels differ. It reads the - listing of every issue never, makes no write and calls no model.""" + and the newest commit that changed that file only when the labels differ. It reads the check + runs of the head commit of each open draft of a job, one read for each draft (#3494). It + reads the listing of every issue never, makes no write and calls no model.""" store = StoreRequests(repo) differ = MESSAGES.roadmap.plan_conditions["labels_differ"] reads = [ @@ -866,6 +876,7 @@ def inbox_requests( *store.repository_labels(), *store.file(CONST_ROADMAP_LABELS_PATH, None), *within(store.path_change(CONST_ROADMAP_LABELS_PATH), differ), + *store.check_runs(), ] return tuple(reads), () diff --git a/src/devops_cli/roadmap/store.py b/src/devops_cli/roadmap/store.py index ff9d8635dc..cc56701641 100644 --- a/src/devops_cli/roadmap/store.py +++ b/src/devops_cli/roadmap/store.py @@ -423,6 +423,7 @@ class OpenPull(BaseModel): url: str head_ref: str draft: bool = False + head_sha: str = "" updated_at: datetime @@ -767,6 +768,10 @@ def open_items(self) -> list[Item]: def open_pulls(self) -> list[OpenPull]: """The open pull requests, with their branches and draft state (#2915).""" + def failed_checks(self, head_sha: str) -> bool: + """Whether a check run of the commit `head_sha` failed. A read that GitHub does not + answer raises (#3494).""" + def repository_labels(self) -> list[RepositoryLabel]: """The labels the repository holds on GitHub (#2915).""" diff --git a/tests/roadmap/test_roadmap_inbox.py b/tests/roadmap/test_roadmap_inbox.py index 420dee767c..62ff25e22b 100644 --- a/tests/roadmap/test_roadmap_inbox.py +++ b/tests/roadmap/test_roadmap_inbox.py @@ -65,8 +65,10 @@ def _lines(inbox: Inbox, kind: InboxKind) -> list[InboxLine]: return [line for line in (*inbox.jobs, *inbox.people) if line.kind is kind] -def _read(store: InMemoryRoadmapStore, *, planned_limit: int = 20) -> Inbox: - return read_inbox(store, repo=REPO, now=NOW, planned_limit=planned_limit) +def _read(store: InMemoryRoadmapStore, *, planned_limit: int = 20, draft_days: int = 7) -> Inbox: + return read_inbox( + store, repo=REPO, now=NOW, planned_limit=planned_limit, draft_days=draft_days, wait_days=7 + ) def test_every_category_is_listed_once_in_the_order_of_the_gates( @@ -84,6 +86,22 @@ def test_every_category_is_listed_once_in_the_order_of_the_gates( blocked = _item( store, fields={ItemField.STATUS: "Blocked"}, marks={ImplementRecordKey.STOPPED: "group 2"} ) + split = _item( + store, + "big", + fields={ItemField.STATUS: "New"}, + marks={RefineRecordKey.NEXT_STEP: "split"}, + ) + asked = _item( + store, + "asked", + fields={ItemField.STATUS: "New"}, + marks={RefineRecordKey.ALTERNATIVES_ASKED: "https://example.com/tool"}, + ) + draft = store.seed_pull( + "draft", head_ref="feat/99-draft", draft=True, head_sha="a9", updated_at=_ago(days=8) + ) + _item(store, marks={StageRecordKey.PR: str(draft)}) claimed = _item(store, fields={ItemField.OWNER: "Agent"}, updated_at=_ago(days=9)) store.seed_file(CONST_ROADMAP_LABELS_PATH, LABELS + "- name: scope/ci\n color: 0E8A16\n") @@ -94,21 +112,61 @@ def test_every_category_is_listed_once_in_the_order_of_the_gates( (InboxKind.IMPLEMENT, work), (InboxKind.RELEASE, release), (InboxKind.BLOCKED, blocked), + (InboxKind.SPLIT, split), + (InboxKind.ALTERNATIVES, asked), + (InboxKind.DRAFT, draft), (InboxKind.CLAIM, claimed), (InboxKind.LABELS, None), ] assert inbox.people == () -def test_a_draft_of_a_job_is_not_listed_and_is_not_a_persons_pull_request( +def test_a_job_draft_that_waits_for_checks_and_is_newer_has_no_line( store: InMemoryRoadmapStore, ) -> None: - draft = store.seed_pull("plan", head_ref="feat/1-plan", draft=True) + draft = store.seed_pull("plan", head_ref="feat/1-plan", draft=True, head_sha="a1") _item(store, marks={StageRecordKey.PR: str(draft)}) - inbox = _read(store) + inbox = _read(store, draft_days=7) assert (inbox.jobs, inbox.people) == ((), ()) +def test_a_job_draft_older_than_the_setting_has_one_line(store: InMemoryRoadmapStore) -> None: + draft = store.seed_pull( + "plan", head_ref="feat/1-plan", draft=True, head_sha="a1", updated_at=_ago(days=8) + ) + _item(store, marks={StageRecordKey.PR: str(draft)}) + + lines = _lines(_read(store, draft_days=7), InboxKind.DRAFT) + + assert [(line.number, line.subject) for line in lines] == [ + (draft, "plan (draft, no update for more than 7 days)") + ] + assert ( + lines[0].clear == f"Finish the draft, then run `devops pr monitor {draft} --repo {REPO}`." + ) + + +def test_a_job_draft_with_a_failed_check_has_one_line(store: InMemoryRoadmapStore) -> None: + draft = store.seed_pull( + "plan", + head_ref="feat/1-plan", + draft=True, + head_sha="a1", + updated_at=_ago(days=1), + checks_failed=True, + ) + _item(store, marks={StageRecordKey.PR: str(draft)}) + + lines = _lines(_read(store, draft_days=7), InboxKind.DRAFT) + + assert [(line.number, line.subject) for line in lines] == [ + (draft, "plan (draft, a check failed)") + ] + assert lines[0].clear == ( + f"Fix the failed check, then run `devops pr monitor {draft} --repo {REPO}`." + ) + + def test_one_pull_request_of_the_stage_and_the_implement_job_is_an_implementation( store: InMemoryRoadmapStore, ) -> None: @@ -411,3 +469,99 @@ def test_the_inbox_says_nothing_of_the_planned_limit_under_it(store: InMemoryRoa _item(store, fields={ItemField.STATUS: "Ready"}) assert _lines(_read(store, planned_limit=2), InboxKind.QUEUE) == [] + + +def test_an_unapplied_split_has_one_line_with_its_step(store: InMemoryRoadmapStore) -> None: + split = _item( + store, + "big", + fields={ItemField.STATUS: "New"}, + marks={RefineRecordKey.NEXT_STEP: "split"}, + updated_at=_ago(days=2), + ) + + lines = _lines(_read(store), InboxKind.SPLIT) + + assert [(line.number, line.subject) for line in lines] == [ + (split, "big: refine proposed a split, not applied") + ] + assert lines[0].clear == ( + f"Split it as refine proposed in a comment on #{split}, or edit its body to fit one " + "pull request." + ) + + +def test_an_alternatives_question_has_one_line_naming_the_tool( + store: InMemoryRoadmapStore, +) -> None: + tool = "https://example.com/covering-tool" + asked = _item( + store, + "asked tool", + fields={ItemField.STATUS: "New"}, + marks={RefineRecordKey.ALTERNATIVES_ASKED: tool}, + updated_at=_ago(days=4), + ) + + lines = _lines(_read(store), InboxKind.ALTERNATIVES) + + assert [(line.number, line.subject) for line in lines] == [ + (asked, f"asked tool: refine put a covering tool to a person: {tool}") + ] + assert lines[0].clear == ( + f"Answer in a comment on #{asked}. Refine reads the answer in its next round." + ) + + +def test_the_split_and_alternatives_classes_follow_the_refine_class() -> None: + kinds = list(InboxKind) + refine = kinds.index(InboxKind.REFINE) + assert kinds[refine + 1 : refine + 3] == [InboxKind.SPLIT, InboxKind.ALTERNATIVES] + + +def test_a_wait_older_than_the_setting_is_marked(store: InMemoryRoadmapStore) -> None: + old = _item( + store, + "old", + fields={ItemField.STATUS: "New"}, + marks={RefineRecordKey.NEXT_STEP: "person"}, + updated_at=_ago(days=10), + ) + young = _item( + store, + "young", + fields={ItemField.STATUS: "New"}, + marks={RefineRecordKey.NEXT_STEP: "person"}, + updated_at=_ago(days=2), + ) + + inbox = read_inbox(store, repo=REPO, now=NOW, planned_limit=20, draft_days=7, wait_days=7) + rendered = render_inbox(inbox, repo=REPO).splitlines() + + old_head = next(text for text in rendered if text.startswith(f" #{old} ")) + young_head = next(text for text in rendered if text.startswith(f" #{young} ")) + assert old_head.endswith("(over 7 days)") + assert not young_head.endswith("(over 7 days)") + + +def test_counts_by_class_lead_the_inbox(store: InMemoryRoadmapStore) -> None: + _item(store, "a", fields={ItemField.STATUS: "New"}, marks={RefineRecordKey.NEXT_STEP: "person"}) + _item(store, "b", fields={ItemField.STATUS: "New"}, marks={RefineRecordKey.NEXT_STEP: "person"}) + _item(store, "c", fields={ItemField.STATUS: "New"}, marks={RefineRecordKey.NEXT_STEP: "split"}) + + blocks = render_inbox(_read(store), repo=REPO).split("\n\n") + + assert blocks[1] == "Counts by class: refine 2, split 1." + + +def test_the_class_filter_keeps_one_kind(store: InMemoryRoadmapStore) -> None: + _item(store, "a", fields={ItemField.STATUS: "New"}, marks={RefineRecordKey.NEXT_STEP: "person"}) + split = _item( + store, "c", fields={ItemField.STATUS: "New"}, marks={RefineRecordKey.NEXT_STEP: "split"} + ) + + rendered = render_inbox(_read(store), repo=REPO, kinds=frozenset({InboxKind.SPLIT})) + + assert f" #{split} " in rendered + assert "New items that wait on a person in refine" not in rendered + assert "Counts by class: refine 1, split 1." in rendered diff --git a/tests/roadmap/test_roadmap_inbox_command.py b/tests/roadmap/test_roadmap_inbox_command.py index 7592db1b9f..6fb1cd7624 100644 --- a/tests/roadmap/test_roadmap_inbox_command.py +++ b/tests/roadmap/test_roadmap_inbox_command.py @@ -10,7 +10,13 @@ from devops_cli.config.constants import CONST_ROADMAP_LABELS_PATH from devops_cli.roadmap.github_store import listing_path, pulls_endpoint from devops_cli.roadmap.memory_store import InMemoryRoadmapStore -from devops_cli.roadmap.store import ItemField, StageRecordKey, encode_job_record, with_record +from devops_cli.roadmap.store import ( + ItemField, + RefineRecordKey, + StageRecordKey, + encode_job_record, + with_record, +) from tests.support.fakes.github import API REPO = "example/roadmap" @@ -64,3 +70,88 @@ def test_the_dry_run_opens_no_store_and_lists_the_reads_and_no_write( @pytest.mark.parametrize("flag", ["--confirm", "--plan"]) def test_the_inbox_takes_no_write_option(cli: Callable[..., Any], flag: str) -> None: assert cli("roadmap", "inbox", "--repo", REPO, flag).exit_code == 2 + + +def _seed_labels(store: InMemoryRoadmapStore) -> None: + store.seed_file(CONST_ROADMAP_LABELS_PATH, "- name: type/bug\n color: D73A4A\n") + store.seed_label("type/bug", "D73A4A") + + +def test_without_repo_the_inbox_reads_each_service_repo( + cli: Callable[..., Any], + config: Callable[..., Any], + roadmap_store: InMemoryRoadmapStore, + roadmap_store_repos: list[str], +) -> None: + config(service={"repos": ["example/app", "example/roadmap"]}) + _seed_labels(roadmap_store) + + result = cli("roadmap", "inbox") + + assert result.exit_code == 0, result.output + assert roadmap_store_repos == ["example/app", "example/roadmap"] + assert "Nothing waits for a person in example/app." in result.stdout + assert "Nothing waits for a person in example/roadmap." in result.stdout + + +def test_with_repo_the_inbox_reads_that_repo_only( + cli: Callable[..., Any], + config: Callable[..., Any], + roadmap_store: InMemoryRoadmapStore, + roadmap_store_repos: list[str], +) -> None: + config(service={"repos": ["example/app", "example/roadmap"]}) + _seed_labels(roadmap_store) + + result = cli("roadmap", "inbox", "--repo", REPO) + + assert result.exit_code == 0, result.output + assert roadmap_store_repos == [REPO] + + +def test_without_repo_and_no_service_repos_the_inbox_fails_naming_the_setting( + cli: Callable[..., Any], + config: Callable[..., Any], + roadmap_store_repos: list[str], +) -> None: + config(service={"repos": []}) + + result = cli("roadmap", "inbox") + + assert (result.exit_code, "service.repos" in result.output) == (1, True) + assert roadmap_store_repos == [] + + +def test_a_service_repo_that_is_not_owner_name_fails_before_any_read( + cli: Callable[..., Any], + config: Callable[..., Any], + roadmap_store_repos: list[str], +) -> None: + config(service={"repos": ["no-owner"]}) + + result = cli("roadmap", "inbox") + + assert (result.exit_code, "service.repos" in result.output) == (1, True) + assert roadmap_store_repos == [] + + +def test_the_kind_option_keeps_the_lines_of_one_class( + cli: Callable[..., Any], roadmap_store: InMemoryRoadmapStore +) -> None: + _seed_labels(roadmap_store) + split = roadmap_store.seed_issue( + "big", + body=with_record("", encode_job_record({}, {RefineRecordKey.NEXT_STEP: "split"})), + fields={ItemField.STATUS: "New", ItemField.PRIORITY: "P2-Medium"}, + ) + + result = cli("roadmap", "inbox", "--repo", REPO, "--kind", "split") + + assert result.exit_code == 0, result.output + assert f"#{split}" in result.stdout + assert "Counts by class: split 1." in result.stdout + + +def test_an_unknown_kind_is_a_usage_error(cli: Callable[..., Any]) -> None: + result = cli("roadmap", "inbox", "--repo", REPO, "--kind", "nope") + assert (result.exit_code, "Invalid value for '--kind'" in result.output) == (2, True) diff --git a/tests/roadmap/test_roadmap_inbox_requests.py b/tests/roadmap/test_roadmap_inbox_requests.py index b0bc780124..e72251de63 100644 --- a/tests/roadmap/test_roadmap_inbox_requests.py +++ b/tests/roadmap/test_roadmap_inbox_requests.py @@ -6,6 +6,9 @@ from __future__ import annotations +from collections.abc import Callable +from typing import Any + from devops_cli.config.constants import CONST_ROADMAP_LABELS_PATH from devops_cli.lang import MESSAGES from devops_cli.roadmap.github_store import ( @@ -62,7 +65,8 @@ def test_the_commit_of_the_labels_file_is_read_only_when_the_labels_differ() -> def test_a_run_reads_three_listings_a_file_and_a_commit_that_differing_labels_make() -> None: """The page `docs/roadmap/inbox.md` states these reads: three listings that repeat for each - page, one read of the labels file, and one commit read that only differing labels make.""" + page, one read of the labels file, one commit read that only differing labels make, and one + check-run read for each open draft of a job.""" reads, _ = inbox_requests(REPO) page = MESSAGES.roadmap.plan_repeat_page differ = MESSAGES.roadmap.plan_conditions["labels_differ"] @@ -73,4 +77,30 @@ def test_a_run_reads_three_listings_a_file_and_a_commit_that_differing_labels_ma (page, ""), ("", ""), ("", differ), + (MESSAGES.roadmap.plan_repeat_draft, MESSAGES.roadmap.plan_conditions["job_drafts"]), + ] + + +def test_the_dry_run_lists_reads_for_each_service_repo_and_no_write( + cli: Callable[..., Any], + config: Callable[..., Any], + roadmap_store_repos: list[str], +) -> None: + config(service={"repos": ["example/app", "example/roadmap"]}) + + result = cli("roadmap", "inbox", "--dry-run") + + assert result.exit_code == 0, result.output + assert roadmap_store_repos == [] + for repo in ("example/app", "example/roadmap"): + assert f"{API}{listing_path(pulls_endpoint(repo))}" in result.output + assert "PATCH" not in result.output + + +def test_check_reads_are_listed_only_for_open_job_drafts() -> None: + reads, writes = inbox_requests(REPO) + checks = [request for request in reads if "check-runs" in request.argv[1]] + assert writes == () + assert [request.condition for request in checks] == [ + MESSAGES.roadmap.plan_conditions["job_drafts"] ] diff --git a/tests/roadmap/test_roadmap_limit_classes.py b/tests/roadmap/test_roadmap_limit_classes.py index dc47fd7717..774debc04b 100644 --- a/tests/roadmap/test_roadmap_limit_classes.py +++ b/tests/roadmap/test_roadmap_limit_classes.py @@ -397,6 +397,14 @@ "DEFAULT_ROADMAP_INTAKE_REASON_CHARS": ("kept", "the reason of a decision in a comment"), "DEFAULT_ROADMAP_INTAKE_LIMIT": ("kept", "candidates of one round"), "DEFAULT_ROADMAP_REFINE_LIMIT": ("kept", "items of one round"), + "DEFAULT_ROADMAP_INBOX_DRAFT_DAYS": ( + "setting", + "the age from which the inbox lists a draft of a job; roadmap.inbox.draft_days", + ), + "DEFAULT_ROADMAP_INBOX_WAIT_DAYS": ( + "setting", + "the age from which the inbox marks a wait; roadmap.inbox.wait_days", + ), "DEFAULT_ROADMAP_INTAKE_INTERVAL_MINUTES": ("other", "a schedule"), "DEFAULT_ROADMAP_REFINE_INTERVAL_MINUTES": ("other", "a schedule"), "DEFAULT_ROADMAP_METRICS_INTERVAL_MINUTES": ("other", "a schedule"), diff --git a/tests/roadmap/test_roadmap_retitle.py b/tests/roadmap/test_roadmap_retitle.py index 4cdd48537f..895a23e234 100644 --- a/tests/roadmap/test_roadmap_retitle.py +++ b/tests/roadmap/test_roadmap_retitle.py @@ -270,7 +270,14 @@ def test_the_inbox_lists_a_blocked_item_whose_title_summary_is_over_the_limit( store.seed_label("type/bug", "D73A4A") number = _item(store, status="Blocked") - inbox = read_inbox(store, repo=REPO, now=datetime(2026, 11, 5, tzinfo=UTC), planned_limit=20) + inbox = read_inbox( + store, + repo=REPO, + now=datetime(2026, 11, 5, tzinfo=UTC), + planned_limit=20, + draft_days=7, + wait_days=7, + ) assert [line.number for line in inbox.jobs if line.kind is InboxKind.BLOCKED] == [number] diff --git a/tests/roadmap/test_roadmap_store_contract.py b/tests/roadmap/test_roadmap_store_contract.py index 0f94627270..2d1fb92d32 100644 --- a/tests/roadmap/test_roadmap_store_contract.py +++ b/tests/roadmap/test_roadmap_store_contract.py @@ -20,7 +20,11 @@ import pytest -from devops_cli.exceptions.git import GitHubFileNotFoundError, GitHubOperationError +from devops_cli.exceptions.git import ( + GitHubFileNotFoundError, + GitHubOperationError, + GitHubUnreadError, +) from devops_cli.exceptions.roadmap import RoadmapItemChangedError from devops_cli.github.session import get_github_session from devops_cli.roadmap.github_store import GitHubRoadmapStore @@ -72,6 +76,8 @@ def seed_pull( draft: bool = False, state: GitHubState = GitHubState.OPEN, updated_at: datetime | None = None, + head_sha: str = "0" * 40, + checks_failed: bool = False, ) -> int: ... def seed_label(self, name: str, color: str, description: str | None = None) -> None: ... @@ -121,9 +127,17 @@ def seed_pull( draft: bool = False, state: GitHubState = GitHubState.OPEN, updated_at: datetime | None = None, + head_sha: str = "0" * 40, + checks_failed: bool = False, ) -> int: return self._roadmap.seed_pull( - title, head_ref=head_ref, draft=draft, state=state, updated_at=updated_at + title, + head_ref=head_ref, + draft=draft, + state=state, + updated_at=updated_at, + head_sha=head_sha, + checks_failed=checks_failed, ) def seed_label(self, name: str, color: str, description: str | None = None) -> None: @@ -183,11 +197,21 @@ def seed_pull( draft: bool = False, state: GitHubState = GitHubState.OPEN, updated_at: datetime | None = None, + head_sha: str = "0" * 40, + checks_failed: bool = False, ) -> int: number = len(self.github.issues) + 1 self.github.seed_pull( - number, title, head_ref=head_ref, draft=draft, state=state.value, updated_at=updated_at + number, + title, + head_ref=head_ref, + draft=draft, + state=state.value, + updated_at=updated_at, + head_sha=head_sha, ) + if checks_failed: + self.github.seed_check_run(head_sha, "ci", conclusion="failure") return number def seed_label(self, name: str, color: str, description: str | None = None) -> None: @@ -1085,3 +1109,26 @@ def test_the_github_store_reads_open_issues_and_never_the_listing_of_every_issue world.store.open_items() read = [call[0] for call in world.github.calls if call[0].startswith(API)] assert [path.split("/issues?", 1)[1].split("&")[0] for path in read] == ["state=open"] + + +def test_open_pulls_carry_the_head_sha_and_their_check_runs_read_by_sha(world: World) -> None: + sha, other = "a" * 40, "b" * 40 + failing = world.seed_pull( + "draft", head_ref="feat/1-x", draft=True, head_sha=sha, checks_failed=True + ) + passing = world.seed_pull("ready", head_ref="feat/2-y", head_sha=other) + + heads = {pull.number: pull.head_sha for pull in world.store.open_pulls()} + + assert heads == {failing: sha, passing: other} + assert (world.store.failed_checks(sha), world.store.failed_checks(other)) == (True, False) + + +def test_the_github_store_raises_when_a_draft_check_cannot_be_read() -> None: + """A check read that GitHub does not answer raises, so no draft shows as passing (#3494).""" + world = GitHubWorld() + + with pytest.raises(GitHubUnreadError, match="head commit SHA is missing") as raised: + world.store.failed_checks("") + + assert raised.value.error_code == GitHubUnreadError.error_code diff --git a/tests/roadmap_github_fake.py b/tests/roadmap_github_fake.py index 8b38bf1ede..13c87449d3 100644 --- a/tests/roadmap_github_fake.py +++ b/tests/roadmap_github_fake.py @@ -64,6 +64,7 @@ def __init__( self.files = dict(files or {}) self.events = list(events) self.commits = set(commits) + self.check_runs: dict[str, list[dict[str, str]]] = {} self.issues: dict[int, dict[str, Any]] = {} self.pulls: dict[int, dict[str, Any]] = {} self.label_catalog: list[dict[str, Any]] = [] @@ -123,6 +124,12 @@ def seed_issue( "html_url": f"https://github.com/{self.repo}/pull/{number}", } + def seed_check_run(self, sha: str, name: str, *, conclusion: str) -> None: + """A completed check run of the commit `sha` that ended with `conclusion`.""" + self.check_runs.setdefault(sha, []).append( + {"name": name, "status": "completed", "conclusion": conclusion} + ) + def seed_pull( self, number: int, @@ -132,6 +139,7 @@ def seed_pull( draft: bool = False, state: str = "open", updated_at: datetime | None = None, + head_sha: str = "0" * 40, ) -> None: """Pull request `number` on branch `head_ref`: its issue, and its entry in the pull request listing.""" @@ -142,7 +150,7 @@ def seed_pull( "html_url": f"https://github.com/{self.repo}/pull/{number}", "state": state, "draft": draft, - "head": {"ref": head_ref, "sha": "0" * 40}, + "head": {"ref": head_ref, "sha": head_sha}, "updated_at": self.issues[number]["updated_at"], } @@ -329,6 +337,13 @@ def _paginate_rest( page += 1 return "".join(json.dumps(p) for p in pages) + def _commit_route(self, parts: list[str]) -> Any: + """The check runs of a commit, or the commit itself when the fake holds it.""" + if parts[-1:] == ["check-runs"]: + runs = self.check_runs.get(parts[1], []) + return {"total_count": len(runs), "check_runs": runs} + return {"sha": parts[1]} if parts[1] in self.commits else (1, "HTTP 422") + def _route( self, method: str, @@ -343,7 +358,7 @@ def _route( name = unquote("/".join(parts[1:])) return self.files[name] if name in self.files else (1, "gh: Not Found (HTTP 404)") if parts[0] == "commits": - return {"sha": parts[1]} if parts[1] in self.commits else (1, "HTTP 422") + return self._commit_route(parts) if "/".join(parts) == "issues/events": size = int(query.get("per_page", "100")) return self.events[(page - 1) * size : page * size]