diff --git a/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/.openspec.yaml b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/.openspec.yaml new file mode 100644 index 0000000000..4bfa67093b --- /dev/null +++ b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-10-30 diff --git a/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/design.md b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/design.md new file mode 100644 index 0000000000..ed8889c244 --- /dev/null +++ b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/design.md @@ -0,0 +1,13 @@ +# Design + +## Decisions + +- **Store protocol defines `add_sub_issue(parent: int, child: int) -> None`**: Both arguments are issue numbers. In `GitHubRoadmapStore`, the child's REST ID is retrieved from the stored payload or fetched if not present. +- **Link sub-issue immediately after filing**: Linking happens in `_apply_placement` right after `_placement_target` files the new issue. +- **Support both full issue URLs and issue numbers in `--source`**: Extract the issue number whether `--source` is a URL to the same repository or an issue number. External URLs return None and do not link. +- **Include sub-issue write in dry-run plan**: In `intake_requests.py`, when a new candidate specifies a `--source` that names an issue in the repository, add the sub-issue write to `planned_requests`. + +## Rejected Alternatives + +- **Pass child REST ID in `RoadmapStore.add_sub_issue`**: Rejected because `MemoryRoadmapStore` and the CLI operate on issue numbers. The store handles REST ID translation internally. +- **Link sub-issues in a separate CLI command**: Rejected because intake already knows the parent from `--source` when filing. Manual linking is error-prone. diff --git a/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/proposal.md b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/proposal.md new file mode 100644 index 0000000000..3c3ce308de --- /dev/null +++ b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/proposal.md @@ -0,0 +1,38 @@ +# Proposal + +## Why + +Issue #2035: `devops roadmap intake --source ` does not link the candidate it files as a sub-issue. + +When an agent splits an issue into parts, it files each part with `devops roadmap intake --source `. The new issue has no sub-issue link to its parent on GitHub. A person or an agent links each part by hand. On 2026-10-23, an agent linked 14 split parts as sub-issues one at a time. This change links the filed issue to its parent automatically at file time. + +## What Changes + +- Add `add_sub_issue(parent, child)` to `RoadmapStore`, `GitHubRoadmapStore`, and `MemoryRoadmapStore`. +- `GitHubRoadmapStore` implements `add_sub_issue` with `POST /repos/{owner}/{repo}/issues/{parent}/sub_issues` and the REST database ID of the child. +- `MemoryRoadmapStore` records the sub-issue relationship and updates parent and child records. +- When intake files a candidate whose `--source` links an issue of the same repository, intake adds the candidate as a sub-issue of that issue. +- The dry-run plan lists the sub-issue write as a planned write. +- Update the docstring rule in `intake.py` to name the sub-issue link write as an allowed extra write. + +## Capabilities + +### Modified Capabilities + +- `roadmap-intake-duplicates`: adds requirement to link candidates filed from `--source` as sub-issues. + +## Impact + +- Code: `src/devops_cli/roadmap/store.py`, `src/devops_cli/roadmap/github_store.py`, `src/devops_cli/roadmap/memory_store.py`, `src/devops_cli/roadmap/intake.py`, `src/devops_cli/roadmap/intake_requests.py`, `src/devops_cli/roadmap/request_plan.py`, `src/devops_cli/lang/en/messages.py`. +- Tests: `tests/test_roadmap_store_contract.py`, `tests/test_roadmap_intake.py`, `tests/roadmap_github_fake.py`. +- Documentation: `docs/commands/roadmap.md` and `README.md` if options change. + +## Feasibility + +- GitHub REST API supports `POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues` with body `{"sub_issue_id": }`. +- `POST /repos/{owner}/{repo}/issues` returns the issue with its REST ID (`id`). +- Verified against GitHub documentation and API schema on 2026-10-30. + +## Existing Tool Considered + +GitHub REST API provides the sub-issues endpoint `POST /repos/{owner}/{repo}/issues/{issue_number}/sub_issues`. It uses the existing GitHub REST API transport in `GitHubRoadmapStore`. No new library or external tool is needed. diff --git a/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/specs/roadmap-intake-duplicates/spec.md b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/specs/roadmap-intake-duplicates/spec.md new file mode 100644 index 0000000000..98f2357db0 --- /dev/null +++ b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/specs/roadmap-intake-duplicates/spec.md @@ -0,0 +1,10 @@ +# Spec Delta + +## ADDED Requirements + +### Requirement: Intake links a candidate filed from --source as a sub-issue +When intake files a candidate whose `--source` links an issue of the same repository, intake SHALL add the filed issue as a sub-issue of that issue. + +#### Scenario: Candidate filed with --source linking an issue in the same repository +- **WHEN** intake files a candidate whose `--source` links an issue in the same repository +- **THEN** intake adds the filed issue as a sub-issue of that issue, and lists the write in the dry-run plan diff --git a/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/tasks.md b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/tasks.md new file mode 100644 index 0000000000..278b067e06 --- /dev/null +++ b/openspec/changes/archive/2026-10-30-2035-intake-sub-issue/tasks.md @@ -0,0 +1,18 @@ +# Tasks + +## 1. Store protocol and implementations + +- [x] 1.1 Add `add_sub_issue` method to `RoadmapStore` protocol and write failing contract test in `tests/test_roadmap_store_contract.py` +- [x] 1.2 Implement `add_sub_issue` in `MemoryRoadmapStore` and `GitHubRoadmapStore` +- [x] 1.3 Add sub-issues route to `tests/roadmap_github_fake.py` + +## 2. Intake sub-issue linking and dry-run plan + +- [x] 2.1 Add failing tests in `tests/test_roadmap_intake.py` for intake with `--source` linking sub-issues and appearing in dry-run plan +- [x] 2.2 Update `IntakeDecision`, `_apply_placement`, `plan_intake`, and `dry_run_intake` to link sub-issues and list the write in the dry-run plan +- [x] 2.3 Update module docstring in `src/devops_cli/roadmap/intake.py` + +## 3. Verification and checks + +- [x] 3.1 Verify OpenSpec check passes +- [x] 3.2 Verify full test suite passes diff --git a/openspec/specs/roadmap-intake-duplicates/spec.md b/openspec/specs/roadmap-intake-duplicates/spec.md index 803db8f554..5c7e535e1a 100644 --- a/openspec/specs/roadmap-intake-duplicates/spec.md +++ b/openspec/specs/roadmap-intake-duplicates/spec.md @@ -98,3 +98,10 @@ When a case's model call fails, `devops roadmap intake-eval` SHALL show that cas #### Scenario: The dry run of the set - **WHEN** `devops roadmap intake-eval --dry-run` runs - **THEN** it lists the 16 cases and 16 `analysis` calls, and the model gets no call + +### Requirement: Intake links a candidate filed from --source as a sub-issue +When intake files a candidate whose `--source` links an issue of the same repository, intake SHALL add the filed issue as a sub-issue of that issue. + +#### Scenario: Candidate filed with --source linking an issue in the same repository +- **WHEN** intake files a candidate whose `--source` links an issue in the same repository +- **THEN** intake adds the filed issue as a sub-issue of that issue, and lists the write in the dry-run plan diff --git a/src/devops_cli/lang/en/messages.py b/src/devops_cli/lang/en/messages.py index 6d431dc69a..cc39097ad4 100644 --- a/src/devops_cli/lang/en/messages.py +++ b/src/devops_cli/lang/en/messages.py @@ -2482,6 +2482,7 @@ class RoadmapMessages: "title": "", "body": "<body>", "label": "<label>", + "sub_issue_id": "<the child's REST id>", "node_id": "<node id>", "original_id": "<original node id>", "evidence": "<evidence>", @@ -2526,6 +2527,7 @@ class RoadmapMessages: "body": "the body of {subject}, its job record kept", "comment": "comment on {subject}", "label": "label {subject}", + "add_sub_issue": "add {subject} as a sub-issue of {parent}", "create_issue": "open an issue for {subject}", "close": "close {subject} with the reason {reason}", } @@ -2592,6 +2594,7 @@ class RoadmapMessages: intake_writes: str = " - writes: {writes}" intake_note: str = " - note: {note}" intake_write_file: str = "file the issue with {labels}" + intake_write_sub_issue: str = "sub-issue of #{parent}" intake_no_labels: str = "no labels" intake_write_label: str = "label {label}" intake_write_field: str = "{field} {value}" @@ -2727,6 +2730,7 @@ class RoadmapMessages: "evidence": "the evidence the model cites for {subject}", "comments": "the comments on {subject}, for intake's marker", "file": "file {subject}, with source/agent when an agent files it", + "sub_issue": "link {subject} as a sub-issue of {parent}", "label": "label {subject} with its type/* label when it has none", "field": ( "set {field} on {subject}: read the issue, then write its labels and its job " @@ -2746,6 +2750,7 @@ class RoadmapMessages: "evidence": "the model cites any", "comments": "{subject} is placed", "file": "no open issue with no Priority holds its title and body", + "sub_issue": "the candidate's source is an issue of the repository", "placed": "intake places {subject}", "field": "it has none", "comment": "intake's is not there", diff --git a/src/devops_cli/roadmap/github_store.py b/src/devops_cli/roadmap/github_store.py index e9b7a5055a..e26576c62c 100644 --- a/src/devops_cli/roadmap/github_store.py +++ b/src/devops_cli/roadmap/github_store.py @@ -142,6 +142,7 @@ def milestone(self) -> Milestone: class _IssuePayload(BaseModel): + id: int = 0 number: int title: str html_url: str @@ -180,6 +181,7 @@ def split(self) -> tuple[str, dict[str, Any]]: def record(self) -> IssueRecord: body, held = self.split() return IssueRecord( + id=self.id, number=self.number, title=self.title, url=self.html_url, @@ -427,6 +429,17 @@ def create_issue_args(repo: str, title: str, body: str, labels: Sequence[str] = return ["api", "-X", "POST", f"repos/{repo}/issues", *flags] +def add_sub_issue_args(repo: str, parent: Number, child_id: Number) -> list[str]: + return [ + "api", + "-X", + "POST", + f"repos/{repo}/issues/{parent}/sub_issues", + "-F", + f"sub_issue_id={child_id}", + ] + + def comment_args(repo: str, number: Number, body: str) -> list[str]: return ["api", "-X", "POST", comments_endpoint(repo, number), "-f", f"body={body}"] @@ -622,6 +635,28 @@ def create_issue(self, title: str, body: str, *, labels: Sequence[str] = ()) -> ) return self._kept(self._validate(written, _ISSUE, "issue after it was opened")) + def add_sub_issue(self, parent: int, child: int) -> None: + """Add issue `child` as a sub-issue of issue `parent`.""" + if self._all is None or parent not in self._all: + self._require_issue(parent, "roadmap.add_sub_issue") + child_id = None + if self._all is not None and child in self._all and self._all[child].id: + child_id = self._all[child].id + if child_id is None: + child_payload = self._require_issue(child, "roadmap.add_sub_issue") + child_id = child_payload.id + self._write( + add_sub_issue_args(self._repo, parent, child_id), + f"link #{child} as a sub-issue of #{parent}", + ) + if self._all is not None: + if parent in self._all: + p = self._all[parent] + self._all[parent] = p.model_copy(update={"sub_issues": p.sub_issues + 1}) + if child in self._all: + c = self._all[child] + self._all[child] = c.model_copy(update={"parent": parent}) + def read_issue_body(self, number: int) -> str: """The body of issue `number`, with no record block, raising if it is not an issue of this repository.""" @@ -932,6 +967,7 @@ def _failure( "GhRunner", "GitHubRoadmapStore", "ListingSession", + "add_sub_issue_args", "advisory_args", "closures_args", "comment_args", diff --git a/src/devops_cli/roadmap/intake.py b/src/devops_cli/roadmap/intake.py index b9924ea9a7..ef1a1d2f59 100644 --- a/src/devops_cli/roadmap/intake.py +++ b/src/devops_cli/roadmap/intake.py @@ -57,16 +57,17 @@ plans the milestones. A milestone the issue already has stands. **Writes**, in order, with Priority last, which makes the candidate an item: file the issue (a -new candidate only), add a `type/*` label when it has none, set each of Status (New), Value and -Effort that the issue holds no label for, leave one reason comment carrying -`CONST_ROADMAP_INTAKE_REASON_MARKER` unless one is there, then set Priority. Each field write -replaces the labels of its family and records the value in the issue's job record -(`RoadmapStore.set_field`). A label a person set stays, and the job record never claims it (ADR -0002); a person's change between the plan and the write stops that write. +new candidate only), link it as a sub-issue when `--source` is an issue of the repository, add a +`type/*` label when it has none, set each of Status (New), Value and Effort that the issue holds +no label for, leave one reason comment carrying `CONST_ROADMAP_INTAKE_REASON_MARKER` unless one +is there, then set Priority. Each field write replaces the labels of its family and records the +value in the issue's job record (`RoadmapStore.set_field`). A label a person set stays, and the +job record never claims it (ADR 0002); a person's change between the plan and the write stops +that write. A run that stops part-way leaves an open issue with no Priority, a candidate, and the next run decides it again: it writes only the fields the issue holds no label for, and no second reason -comment. Intake writes to no issue but the candidate, and closes none. +comment. Intake writes to no issue but the candidate and its parent sub-issue link, and closes none. **Dry run, plan, confirm** (the dry-run rule of #412). `dry_run_intake` makes no request, to GitHub or a model: it returns an `IntakePlan` marked `dry_run`, with no decision, that holds @@ -317,6 +318,7 @@ class IntakeDecision: shown: tuple[str, str, str, str] = ("", "", "", "") notes: tuple[str, ...] = () reasons: tuple[tuple[str, str, str], ...] = () + parent: int | None = None @property def has_writes(self) -> bool: @@ -327,6 +329,8 @@ def writes(self) -> list[str]: texts = MESSAGES.roadmap filing = ", ".join(self.filing_labels) or texts.intake_no_labels planned = [texts.intake_write_file.format(labels=filing)] + if self.parent is not None: + planned.append(texts.intake_write_sub_issue.format(parent=self.parent)) planned = planned if self.subject.number is None else [] planned += [texts.intake_write_label.format(label=label) for label in self.labels] planned += [texts.intake_write_field.format(field=f.value, value=v) for f, v in self.fields] @@ -685,15 +689,35 @@ def _comparison(run: _Run, *, agent_candidates: bool) -> list[_Entry]: ] +def source_parent_number(repo: str, source: str | None) -> int | None: + """The issue number of `repo` that `source` names, or None when it names another + repository or is not an issue link.""" + if not source: + return None + trimmed = source.strip() + if trimmed.lstrip("#").isdigit(): + return int(trimmed.lstrip("#")) + parsed = urlsplit(trimmed) + if parsed.netloc and parsed.netloc != "github.com": + return None + path = parsed.path if parsed.path.startswith("/") else f"/{parsed.path}" + prefix = f"/{repo.strip('/')}/issues/" + if path.startswith(prefix): + tail = path.removeprefix(prefix) + if tail.isdigit(): + return int(tail) + return None + + def _source_issue(run: _Run, subject: Subject) -> int | None: """The issue of the repository that a new candidate's source links, such as the issue it splits: the issue whose GitHub link is the source with no query or fragment, so a link to one of its comments names it too (#1985).""" source = subject.new.source if subject.new is not None else None - if not source: + parent = source_parent_number(run.repo, source) + if parent is None: return None - link = urlsplit(source.strip())._replace(query="", fragment="").geturl() - return next((issue.number for issue in run.issues if issue.url == link), None) + return next((issue.number for issue in run.issues if issue.number == parent), None) def _apart(run: _Run, subject: Subject) -> set[int]: @@ -1119,6 +1143,7 @@ def _place(self, subject: Subject, proposal: Proposal, judgement: _Judgement) -> if _has_comment(self.run.store, subject, CONST_ROADMAP_INTAKE_REASON_MARKER) else _comment(placement, lines) ) + parent = _source_issue(self.run, subject) if subject.number is None else None return IntakeDecision( subject, Outcome.PLACE, @@ -1135,6 +1160,7 @@ def _place(self, subject: Subject, proposal: Proposal, judgement: _Judgement) -> duplicate_reason=judgement.reason if judgement.possible_duplicate is not None else "", related=judgement.related, related_reason=judgement.reason if judgement.related is not None else "", + parent=parent, ) @@ -1200,8 +1226,15 @@ def dry_run_intake( subjects = [f"#{number}" for number in sorted(set(issues))] else: subjects = [MESSAGES.roadmap.intake_placeholder_each] + source_parent = source_parent_number(repo, new.source) if new is not None else None reads, writes = planned_requests( - subjects, repo=repo, ref=ref, new=new is not None, each=each, limit=limit + subjects, + repo=repo, + ref=ref, + new=new is not None, + each=each, + limit=limit, + parent=source_parent, ) return IntakePlan(decisions=(), limit=limit, dry_run=True, requests=reads, writes=writes) @@ -1235,6 +1268,8 @@ def _apply_placement(store: RoadmapStore, decision: IntakeDecision) -> int: if priority is None: raise _lacks(decision, "Priority") number, item = _placement_target(store, decision) + if decision.parent is not None: + store.add_sub_issue(decision.parent, number) for label in decision.labels: store.label_issue(number, label) for item_field, value in decision.fields: diff --git a/src/devops_cli/roadmap/intake_requests.py b/src/devops_cli/roadmap/intake_requests.py index 201f9fa4e8..90fd5544b1 100644 --- a/src/devops_cli/roadmap/intake_requests.py +++ b/src/devops_cli/roadmap/intake_requests.py @@ -111,7 +111,14 @@ def decisions(self, subjects: Sequence[str], *, new: bool, repeat: str) -> list[ ) return planned - def writes(self, subjects: Sequence[str], *, new: bool, repeat: str) -> list[PlannedRequest]: + def writes( + self, + subjects: Sequence[str], + *, + new: bool, + repeat: str, + parent: int | None = None, + ) -> list[PlannedRequest]: """The writes `--confirm` makes for each candidate it places.""" texts = MESSAGES.roadmap planned: list[PlannedRequest] = [] @@ -119,6 +126,17 @@ def writes(self, subjects: Sequence[str], *, new: bool, repeat: str) -> list[Pla if new: filing = self.store.create_issue(subject, (texts.plan_placeholders["label"],)) planned += self.step("file", filing, subject=subject, repeat=repeat) + if parent is not None: + sub_issue = self.store.add_sub_issue( + f"#{parent}", texts.intake_placeholder_filed + ) + planned += self.step( + "sub_issue", + sub_issue, + parent=f"#{parent}", + subject=texts.intake_placeholder_filed, + repeat=repeat, + ) planned += self._placement(texts.intake_placeholder_filed if new else subject, repeat) return planned @@ -154,6 +172,7 @@ def planned_requests( new: bool, each: bool = False, limit: int | None = None, + parent: int | None = None, ) -> tuple[tuple[PlannedRequest, ...], tuple[PlannedRequest, ...]]: """The requests a run over `subjects` makes, as reads and model calls, then the writes `--confirm` adds after them; `new` when the one subject is a candidate that is not an issue @@ -164,7 +183,7 @@ def planned_requests( limited = texts.intake_repeat_limited.format(limit=limit) if limit is not None else "" repeat = (limited or texts.intake_repeat_candidate) if each else "" reads = steps.reads() + steps.decisions(subjects, new=new, repeat=repeat) - return tuple(reads), tuple(steps.writes(subjects, new=new, repeat=repeat)) + return tuple(reads), tuple(steps.writes(subjects, new=new, repeat=repeat, parent=parent)) # ── What a run spends ───────────────────────────────────────────────────────── diff --git a/src/devops_cli/roadmap/memory_store.py b/src/devops_cli/roadmap/memory_store.py index 1700e4978a..7a271b8f3c 100644 --- a/src/devops_cli/roadmap/memory_store.py +++ b/src/devops_cli/roadmap/memory_store.py @@ -182,6 +182,7 @@ def seed_issue( now = self._roadmap.clock() given = (*labels, *(field_label(f, value) for f, value in (fields or {}).items())) self._roadmap.issues[number] = IssueRecord( + id=number, number=number, title=title, url=f"https://github.com/{self._roadmap.repo}/{kind}/{number}", @@ -328,6 +329,14 @@ def create_issue(self, title: str, body: str, *, labels: Sequence[str] = ()) -> self._log("create_issue", number, value=title) return self._read(self._roadmap.issues[number]) + def add_sub_issue(self, parent: int, child: int) -> None: + """Add issue `child` as a sub-issue of issue `parent`.""" + parent_issue = self._require_issue(parent, "roadmap.add_sub_issue") + child_issue = self._require_issue(child, "roadmap.add_sub_issue") + self._update_issue(parent_issue, sub_issues=parent_issue.sub_issues + 1) + self._update_issue(child_issue, parent=parent) + self._log("add_sub_issue", parent, value=str(child)) + def closures(self, number: int) -> list[Closure]: """Every close and reopen of issue `number`, oldest first.""" return list(self._roadmap.closures.get(number, [])) diff --git a/src/devops_cli/roadmap/request_plan.py b/src/devops_cli/roadmap/request_plan.py index 3933dfb434..40e05bbacb 100644 --- a/src/devops_cli/roadmap/request_plan.py +++ b/src/devops_cli/roadmap/request_plan.py @@ -235,6 +235,10 @@ def create_issue(self, subject: str, labels: Sequence[str] = ()) -> Requests: args = gh.create_issue_args(self.repo, _p("title"), _p("body"), labels) return [self.gh(args, "create_issue", subject=subject)] + def add_sub_issue(self, parent: str, subject: str) -> Requests: + args = gh.add_sub_issue_args(self.repo, _number(parent), _p("sub_issue_id")) + return [self.gh(args, "add_sub_issue", subject=subject, parent=parent)] + def write_issue_body(self, subject: str) -> Requests: """The issue now, for the job record it holds, then its new body with that record.""" edit = self._edit(subject, "body", gh.issue_edit(body=_p("body"))) diff --git a/src/devops_cli/roadmap/store.py b/src/devops_cli/roadmap/store.py index 53266f5372..6edf7bf6f2 100644 --- a/src/devops_cli/roadmap/store.py +++ b/src/devops_cli/roadmap/store.py @@ -295,6 +295,7 @@ class IssueRecord(BaseModel): model_config = ConfigDict(frozen=True) + id: int = 0 number: int title: str url: str @@ -725,6 +726,9 @@ def issues(self) -> list[IssueRecord]: def create_issue(self, title: str, body: str, *, labels: Sequence[str] = ()) -> IssueRecord: """Open an issue with `title`, `body` and `labels`, returning it.""" + def add_sub_issue(self, parent: int, child: int) -> None: + """Add issue `child` as a sub-issue of issue `parent`.""" + def read_issue_body(self, number: int) -> str: """The body of issue `number`, with no record block, raising if it is not an issue of this repository.""" diff --git a/tests/roadmap_github_fake.py b/tests/roadmap_github_fake.py index 60a615eae4..0685c23d41 100644 --- a/tests/roadmap_github_fake.py +++ b/tests/roadmap_github_fake.py @@ -92,6 +92,7 @@ def seed_issue( gives in each issue's `parent_issue_url`. Its author has `author_association` with the repository.""" self.issues[number] = { + "id": number, "number": number, "title": title or f"Issue {number}", "html_url": f"https://github.com/{self.repo}/issues/{number}", @@ -338,6 +339,17 @@ def _issue_route( if rest == ["comments"] and method == "POST": self.comments.setdefault(number, []).append(fields["body"]) return {} + if rest == ["sub_issues"] and method == "POST": + sub_id = int(fields["sub_issue_id"]) + child = next( + (i for i in self.issues.values() if i.get("id") == sub_id or i["number"] == sub_id), + None, + ) + if child is None: + return (1, "gh: Not Found (HTTP 404)") + issue["sub_issues_summary"]["total"] += 1 + child["parent_issue_url"] = f"https://api.github.com/repos/{self.repo}/issues/{number}" + return child if rest == ["comments"]: bodies = self.comments.get(number, []) if page == 1 else [] return [{"body": body, "created_at": "2026-10-01T00:00:00Z"} for body in bodies] diff --git a/tests/test_roadmap_intake.py b/tests/test_roadmap_intake.py index 1c88d93149..f5491c9d34 100644 --- a/tests/test_roadmap_intake.py +++ b/tests/test_roadmap_intake.py @@ -668,6 +668,86 @@ def _split( return outcome.decision.outcome, outcome.decision.possible_duplicate, outcome.number, sent +def test_a_candidate_filed_from_source_is_linked_as_a_sub_issue_of_that_issue( + roadmap: Roadmap, model_fake: ModelFake +) -> None: + """When a new candidate's source is an issue of the same repository, intake links the filed + issue as a sub-issue of that source issue (#2035).""" + parent = roadmap.finished(PARENT_TITLE, body=PARENT_BODY) + source = _link(parent) + outcome, _, filed, _ = _split(roadmap, model_fake, {}, source=source) + assert outcome is Outcome.PLACE + assert filed is not None + parent_record = next(i for i in roadmap.store.issues() if i.number == parent) + filed_record = next(i for i in roadmap.store.issues() if i.number == filed) + writes = [w.operation for w in roadmap.store.job_writes() if w.number == parent] + assert (parent_record.sub_issues, filed_record.parent, "add_sub_issue" in writes) == ( + 1, + parent, + True, + ) + + +def test_a_candidate_from_another_repository_source_is_not_linked_as_sub_issue( + roadmap: Roadmap, model_fake: ModelFake +) -> None: + """When a candidate's source links an issue of another repository, intake links no sub-issue (#2035).""" + outcome, _, filed, _ = _split( + roadmap, model_fake, {}, source="https://github.com/other-org/other-repo/issues/99" + ) + assert outcome is Outcome.PLACE + assert filed is not None + filed_record = next(i for i in roadmap.store.issues() if i.number == filed) + writes = [w.operation for w in roadmap.store.job_writes()] + assert (filed_record.parent, "add_sub_issue" in writes) == (None, False) + + +def test_intake_plan_lists_sub_issue_write(roadmap: Roadmap) -> None: + """The plan of a candidate with source in the same repo lists the sub-issue write (#2035).""" + parent = roadmap.finished(PARENT_TITLE, body=PARENT_BODY) + source = _link(parent) + model = FakeModel(proposals={STEP_B.title: REGRESSION}) + candidate = replace(STEP_B, source=source) + plan = plan_intake(roadmap.store, repo=REPO, model=model, new=candidate) + assert f"sub-issue of #{parent}" in plan.decisions[0].writes() + rendered = render_intake(plan, repo=REPO) + assert f"sub-issue of #{parent}" in rendered + + +def test_a_dry_run_lists_the_sub_issue_write_when_source_is_an_issue(tmp_path: Path) -> None: + """A dry run with --source naming an issue of the repository lists the sub-issue write (#2035).""" + body_file = tmp_path / "body.md" + body_file.write_text("body text", encoding="utf-8") + output = _intake( + "--title", + "feat: split task", + "--body-file", + str(body_file), + "--source", + f"https://github.com/{REPO}/issues/42", + "--dry-run", + ) + assert f"POST repos/{REPO}/issues/42/sub_issues" in output + + +def test_intake_docstring_names_sub_issue_write_rule() -> None: + """The docstring of intake.py names the sub-issue write as an allowed extra write (#2035).""" + from devops_cli.roadmap import intake + + doc = intake.__doc__ or "" + assert "Intake writes to no issue but the candidate" in doc + assert "sub-issue" in doc + + +def test_source_parent_number_parses_hashes_and_numbers() -> None: + """source_parent_number parses hash numbers, bare numbers, and returns None for non-numbers (#2035).""" + from devops_cli.roadmap.intake import source_parent_number + + assert source_parent_number(REPO, "#42") == 42 + assert source_parent_number(REPO, "42") == 42 + assert source_parent_number(REPO, "not-a-number") is None + + @pytest.mark.parametrize("anchor", ["", "#issuecomment-1"], ids=["issue", "comment-on-issue"]) def test_a_part_is_never_a_duplicate_of_the_issue_its_source_names( roadmap: Roadmap, model_fake: ModelFake, anchor: str diff --git a/tests/test_roadmap_store_contract.py b/tests/test_roadmap_store_contract.py index 542dc9a0ff..77243c60b4 100644 --- a/tests/test_roadmap_store_contract.py +++ b/tests/test_roadmap_store_contract.py @@ -944,3 +944,24 @@ def test_repository_facts_are_those_seeded_for_the_repository(store: InMemoryRoa facts, None, ) + + +def test_add_sub_issue_links_child_to_parent(world: World) -> None: + parent = world.seed("parent") + child = world.seed("child") + world.store.add_sub_issue(parent, child) + parent_record = next(i for i in world.store.issues() if i.number == parent) + child_record = next(i for i in world.store.issues() if i.number == child) + assert (parent_record.sub_issues, child_record.parent) == (1, parent) + with pytest.raises(GitHubOperationError, match="not an issue"): + world.store.add_sub_issue(999, child) + + +def test_add_sub_issue_links_child_to_parent_with_cached_issues(world: World) -> None: + parent = world.seed("parent") + child = world.seed("child") + _ = list(world.store.issues()) + world.store.add_sub_issue(parent, child) + parent_record = next(i for i in world.store.issues() if i.number == parent) + child_record = next(i for i in world.store.issues() if i.number == child) + assert (parent_record.sub_issues, child_record.parent) == (1, parent)