diff --git a/.github/workflows/upstreaming-worker.lock.yml b/.github/workflows/upstreaming-worker.lock.yml index 43bdb1f4328..d6edac1a8db 100644 --- a/.github/workflows/upstreaming-worker.lock.yml +++ b/.github/workflows/upstreaming-worker.lock.yml @@ -1,4 +1,4 @@ -# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"30088af59ad86726a3c2b0b6b6076ec9463412481ddfd3a12da5d807b699c00a","body_hash":"a8abe13163eb37ad8a7dfcef0c8623d9063889694d364506d0b22cb59d14249a","compiler_version":"v1.2.2","strict":true,"agent_id":"pi","agent_model":"anthropic/claude-opus-5-5","engine_versions":{"pi":"1.5.0"}} +# gh-aw-metadata: {"schema_version":"v4","frontmatter_hash":"f59accebadca45d1eaf227c55b70d831463daaf6d3ce5e3f0780948bb30fe9dd","body_hash":"c2baea3582364d048cf2d83f3eaae073738dda88c35c483d78b99c7d2d6689b9","compiler_version":"v1.2.2","strict":true,"agent_id":"pi","agent_model":"anthropic/claude-opus-5-5","engine_versions":{"pi":"1.5.0"}} # gh-aw-manifest: {"version":1,"secrets":["ANTHROPIC_API_KEY","COPILOT_GITHUB_TOKEN","GH_AW_DEFAULT_OTLP_ENDPOINT","GH_AW_DEFAULT_OTLP_HEADERS","GH_AW_GITHUB_MCP_SERVER_TOKEN","GH_AW_GITHUB_TOKEN","GITHUB_TOKEN","RISEPROJECT_APP_PRIVATE_KEY","RISEPROJECT_UPSTREAMING_APP_PRIVATE_KEY"],"actions":[{"repo":"actions/checkout","sha":"3d3c42e5aac5ba805825da76410c181273ba90b1","version":"v7.0.1"},{"repo":"actions/create-github-app-token","sha":"64ab729a6294000f5aa4a4bc0b73d1f32bc45510","version":"v3.3.0"},{"repo":"actions/download-artifact","sha":"9000827ccba6bdab643e8b6fd33ac0654aef8333","version":"v8.0.2"},{"repo":"actions/github-script","sha":"3a2844b7e9c422d3c10d287c895573f7108da1b3","version":"v9.0.0"},{"repo":"actions/setup-node","sha":"949feb2413d6458794dcd2491c4babbbce0c15c1","version":"v7.1.0"},{"repo":"actions/upload-artifact","sha":"043fb46d1a93c77aae656e7c1c64a875d1fc6a0a","version":"v7.0.1"},{"repo":"actions/upload-artifact","sha":"cf430e030ddbb5b0abf93d22962f4752f3646cd9","version":"v7.0.2"},{"repo":"astral-sh/setup-uv","sha":"20cfd1bf945f4377ade1205e4dbc17946fc9a30d","version":"v10.0.1"},{"repo":"github/gh-aw-actions/setup","sha":"53d0749e19424a918acd82b4d140264ce48f2f14","version":"v1.2.2"}],"containers":[{"image":"ghcr.io/github/gh-aw-firewall/agent:0.29.11","digest":"sha256:8774a73c351395b41d2ad0af4ddb4689007c67de3cd08bd9f43bb8a0e300690e","pinned_image":"ghcr.io/github/gh-aw-firewall/agent:0.29.11@sha256:8774a73c351395b41d2ad0af4ddb4689007c67de3cd08bd9f43bb8a0e300690e"},{"image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.29.11","digest":"sha256:88d2d0e315a504d93fd4fb8847fd0f6b7f4469f41a6fc6047b3dc9654c56ab2c","pinned_image":"ghcr.io/github/gh-aw-firewall/api-proxy:0.29.11@sha256:88d2d0e315a504d93fd4fb8847fd0f6b7f4469f41a6fc6047b3dc9654c56ab2c"},{"image":"ghcr.io/github/gh-aw-firewall/squid:0.29.11","digest":"sha256:861739ecf924dd2db5e5fb652db2ad82aaafd1615623297ddabc8f41a36b2847","pinned_image":"ghcr.io/github/gh-aw-firewall/squid:0.29.11@sha256:861739ecf924dd2db5e5fb652db2ad82aaafd1615623297ddabc8f41a36b2847"},{"image":"ghcr.io/github/gh-aw-mcpg:v0.5.6","digest":"sha256:342cd624e1f179d91be2de7a146fc4f387092e62e6c8a47506d7932e113d2311","pinned_image":"ghcr.io/github/gh-aw-mcpg:v0.5.6@sha256:342cd624e1f179d91be2de7a146fc4f387092e62e6c8a47506d7932e113d2311"},{"image":"ghcr.io/github/gh-aw-node","digest":"sha256:8735428c2d4e602f90781ba0c571c400e8ff93c7ee1508a75d71f87e34e415cc","pinned_image":"ghcr.io/github/gh-aw-node@sha256:8735428c2d4e602f90781ba0c571c400e8ff93c7ee1508a75d71f87e34e415cc"},{"image":"ghcr.io/github/github-mcp-server:v2.1.0","digest":"sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a","pinned_image":"ghcr.io/github/github-mcp-server:v2.1.0@sha256:f6056fc10bfffcc8c81a6417a2e9ca12808647e8dd6049642a4feaadee0e0f8a"}],"mcp_servers":[{"name":"github","tools":["get_commit","get_file_contents","get_latest_release","get_me","get_pull_request","get_pull_request_comments","get_pull_request_diff","get_pull_request_files","get_pull_request_review_comments","get_pull_request_reviews","get_pull_request_status","get_release_by_tag","get_tag","issue_read","list_branches","list_commits","list_issue_types","list_issues","list_pull_requests","list_releases","list_starred_repositories","list_tags","pull_request_read","search_code","search_issues","search_pull_requests","search_repositories"]},{"name":"github-authenticated","tools":["actions_list","get_commit","get_file_contents","get_pull_request","get_pull_request_comments","get_pull_request_diff","get_pull_request_files","get_pull_request_review_comments","get_pull_request_reviews","get_pull_request_status","issue_read","list_commits","list_issues","list_pull_requests","pull_request_read","search_code","search_issues","search_pull_requests"]},{"name":"safeoutputs","tools":["noop","report_incomplete","report_missing_data","report_missing_tool","upload_artifact"]},{"name":"work-queue","tools":["work_queue_claim_finish","work_queue_dispatch_next","work_queue_explain","work_queue_read","work_queue_submit"]}],"threat_detection":{"mode":"enabled"},"admission":false,"work_queue":{"worker":true,"logical_contract":"056b332b022951fc3d1ae91c58cb202ea509dcef2a5d2c296a6cc0a9f8abc00a"},"agent_metadata":{}} # This file was automatically generated by gh-aw (v1.2.2). DO NOT EDIT. To debug this workflow, load the skill at https://github.com/github/gh-aw/blob/main/debug.md # @@ -2202,6 +2202,18 @@ jobs: env: UPSTREAMING_FORK_TOKEN: ${{ steps.fork-token.outputs.token }} working-directory: control + - name: Answer addressed review feedback and resolve inline threads + if: steps.publish.outputs.status == 'published' + run: | + uv run --no-project --with-requirements upstreaming/requirements.txt \ + python -m upstreaming.review_response \ + --record ../in/record.json --task ../in/task.json \ + --proposal ../in/proposal.json --outcome ../in/outcome.json \ + --out ../in/review-response.json + env: + UPSTREAMING_FORK_TOKEN: ${{ steps.fork-token.outputs.token }} + continue-on-error: true + working-directory: control - if: always() uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: @@ -2215,6 +2227,7 @@ jobs: in/outcome.json in/proposal.json in/dossier.json + in/review-response.json retention-days: ${{ vars.GH_AW_DEFAULT_ARTIFACT_RETENTION_DAYS || '30' }} safe_outputs: diff --git a/.github/workflows/upstreaming-worker.md b/.github/workflows/upstreaming-worker.md index f27214e327c..fd0be19ee71 100644 --- a/.github/workflows/upstreaming-worker.md +++ b/.github/workflows/upstreaming-worker.md @@ -218,6 +218,18 @@ jobs: # 1 rejected / 3 infrastructure are recorded outcomes, not job failures; # 2 (uncertain) fails the job so it is visible, and discovery resolves it. exit $(( rc == 1 || rc == 3 ? 0 : rc )) + - name: Answer addressed review feedback and resolve inline threads + if: steps.publish.outputs.status == 'published' + continue-on-error: true + working-directory: control + env: + UPSTREAMING_FORK_TOKEN: ${{ steps.fork-token.outputs.token }} + run: | + uv run --no-project --with-requirements upstreaming/requirements.txt \ + python -m upstreaming.review_response \ + --record ../in/record.json --task ../in/task.json \ + --proposal ../in/proposal.json --outcome ../in/outcome.json \ + --out ../in/review-response.json # Everything the controller needs to record the outcome and, for an # infrastructure failure, to retry this exact publication without a new # agent run: the task, the verified artifact identity and the outcome. @@ -233,6 +245,7 @@ jobs: in/outcome.json in/proposal.json in/dossier.json + in/review-response.json if-no-files-found: ignore retention-days: 30 continuation: @@ -296,7 +309,12 @@ call: `{"path": "upstreaming-out"}` (the native handler names the artifact revision task, `reason_ids` must include every task `reason_ids` entry. In `diagnosis`, include a checklist with one item per review or CI constraint, the exact change that addresses it, and how you verified that change. Never - claim `no_change` while required review feedback remains unresolved. + claim `no_change` while required review feedback remains unresolved. For + every item in human-relay `reviews`, `comments`, and `conversation_comments`, + add one `feedback_responses` entry with its numeric ID and a short factual + description of the implemented change. Trusted code posts these responses + only after publication and resolves inline review threads. Do not claim a + change was made unless it is present in the delivered series. `patch_digest` is the sha256 of `patches.mbox`, or null. - `patches.mbox`: for `append`, `git -C fork format-patch --stdout `; for `rewrite`, `git -C fork format-patch --stdout `. Omit it diff --git a/SESSIONLOG.md b/SESSIONLOG.md index afed41912a6..14520616ab3 100644 --- a/SESSIONLOG.md +++ b/SESSIONLOG.md @@ -25,3 +25,4 @@ - Fixed review and CI reconciliation so pending human feedback survives head changes, every repair carries and acknowledges all feedback evidence, `fix_needed` cannot be overwritten before dispatch, and any executed build or test failure returns handoff to automated development repair. - Replaced the rejected workflow-glob approach with complete dossier path coverage and natural-language review scope extension: human-relay-backed repairs may add exact changed paths, which trusted publication verifies and persists without requiring command syntax. - Added an exact-path repair compatibility flag for live contributions whose dossiers predate mandatory path coverage; new dossiers are marked coverage-complete and cannot use the legacy allowance. +- Added trusted post-publication review acknowledgements: every addressed feedback item gets a short App-authored response, inline review threads are resolved after replying, and marker/readback checks make retries idempotent. diff --git a/upstreaming/INTEGRATION.md b/upstreaming/INTEGRATION.md index db6cbfa2654..19cdf356352 100644 --- a/upstreaming/INTEGRATION.md +++ b/upstreaming/INTEGRATION.md @@ -200,7 +200,12 @@ paths actually changed by that repair, applies all existing content and workflow safety checks, and persists the verified paths into contribution scope. Live contributions whose dossiers predate mandatory path coverage receive the same exact-path compatibility only during repair; new dossiers are marked complete -and cannot use that legacy allowance. +and cannot use that legacy allowance. A human-relay-backed proposal also carries +one bounded response per review item. After exact-head publication, trusted code +posts each short response as the destination App and resolves its inline review +thread. PR conversation comments receive the response but are not falsely marked +resolved because GitHub does not expose thread resolution for them. Response +markers and thread-state readback make retries idempotent. Previously merged implementation: diff --git a/upstreaming/README.md b/upstreaming/README.md index c1bfb93dc73..9a3b9d4d12c 100644 --- a/upstreaming/README.md +++ b/upstreaming/README.md @@ -215,8 +215,11 @@ pilot details are kept in lifecycle state and diagnostic artifacts, not here. line and text in task context. Ordinary natural-language review feedback may require another file without any command syntax. A human-relay-backed repair may identify that exact path; trusted publication validates the actual diff - and persists the verified path into contribution scope. Passing means every - required riscv64 job and + and persists the verified path into contribution scope. After the patch is + published, trusted code posts the worker's short factual response to each + addressed review item as the destination App and resolves inline review + threads. Conversation comments are answered but cannot be marked resolved by + GitHub. Passing means every required riscv64 job and wheel artifact satisfy the project-specific frozen topology contract. 5. **Upstream handoff.** When the exact development head passes its frozen CI contract and has no debug commits, observation automatically records it as the diff --git a/upstreaming/fork_publish.py b/upstreaming/fork_publish.py index 09cdb5105f4..2444e98bdc1 100644 --- a/upstreaming/fork_publish.py +++ b/upstreaming/fork_publish.py @@ -130,6 +130,20 @@ def check_proposal(proposal: dict, record: dict, task: dict, *, allow_no_change: missing_reasons = set(task.get("reason_ids") or []) - set(proposal.get("reason_ids") or []) if missing_reasons: raise PublishRejected(f"repair proposal did not acknowledge required evidence: {sorted(missing_reasons)}") + required_feedback = { + int(item["id"]) + for evidence in (task.get("context") or {}).get("reason_evidence") or [] + if evidence.get("kind") == "human_relay" + for key in ("reviews", "comments", "conversation_comments") + for item in ((evidence.get("data") or {}).get(key) or []) + if item.get("id") + } + response_ids = [int(item["comment_id"]) for item in proposal.get("feedback_responses") or []] + if len(response_ids) != len(set(response_ids)): + raise PublishRejected("repair proposal contains duplicate feedback responses") + missing_feedback = required_feedback - set(response_ids) + if missing_feedback: + raise PublishRejected(f"repair proposal did not describe responses for feedback: {sorted(missing_feedback)}") fork = (record.get("fork") or {}).get("name") or "" if not fork.startswith(FORK_ORG + "/") or task["fork"] != fork: raise PublishRejected("task fork is not the recorded contribution fork") diff --git a/upstreaming/review_response.py b/upstreaming/review_response.py new file mode 100644 index 00000000000..2e9b4c2da04 --- /dev/null +++ b/upstreaming/review_response.py @@ -0,0 +1,166 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT +"""Answer addressed development-PR feedback and resolve inline threads. + +This runs only in the trusted post-publication job with a one-fork App token. +The worker supplies bounded response text but never receives the token. +""" + +from __future__ import annotations + +import argparse +import json +import os +import time +import urllib.error +import urllib.parse +import urllib.request +from dataclasses import dataclass +from pathlib import Path +from typing import Any + + +class ResponseError(RuntimeError): + pass + + +class Api: + def __init__(self, token: str, base: str = "https://api.github.com"): + self.token, self.base = token, base.rstrip("/") + + def call(self, method: str, path: str, data: dict | None = None) -> Any: + body = json.dumps(data).encode() if data is not None else None + req = urllib.request.Request(self.base + path, data=body, method=method, headers={ + "Authorization": f"Bearer {self.token}", "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28", "Content-Type": "application/json"}) + last: Exception | None = None + for attempt in range(5): + try: + with urllib.request.urlopen(req, timeout=60) as response: + raw = response.read() + return json.loads(raw) if raw else None + except urllib.error.HTTPError as exc: + last = exc + if exc.code not in (429, 500, 502, 503, 504): + raise ResponseError( + f"GitHub {method} {path}: HTTP {exc.code}: {exc.read()[-500:].decode(errors='replace')}") from exc + except urllib.error.URLError as exc: + last = exc + if attempt < 4: + time.sleep(2 ** attempt) + raise ResponseError(f"GitHub {method} {path} failed after retries: {last}") + + def graphql(self, query: str, variables: dict) -> dict: + result = self.call("POST", "/graphql", {"query": query, "variables": variables}) + if result.get("errors"): + raise ResponseError(f"GraphQL failed: {result['errors']}") + return result["data"] + + +@dataclass(frozen=True) +class Feedback: + id: int + kind: str + reviewer: str | None + + +def feedback_items(task: dict) -> dict[int, Feedback]: + found: dict[int, Feedback] = {} + for evidence in (task.get("context") or {}).get("reason_evidence") or []: + if evidence.get("kind") != "human_relay": + continue + data = evidence.get("data") or {} + for key, kind in (("reviews", "review"), ("comments", "inline"), + ("conversation_comments", "conversation")): + for item in data.get(key) or []: + if item.get("id"): + found[int(item["id"])] = Feedback(int(item["id"]), kind, item.get("reviewer")) + return found + + +def marker(comment_id: int, head: str) -> str: + return f"" + + +def response_body(item: Feedback, summary: str, head: str) -> str: + mention = f"@{item.reviewer} " if item.reviewer else "" + return f"{mention}{summary.strip()}\n\n{marker(item.id, head)}" + + +def review_threads(api: Api, owner: str, name: str, number: int) -> list[dict]: + query = """ + query($owner:String!,$name:String!,$number:Int!) { + repository(owner:$owner,name:$name) { + pullRequest(number:$number) { + reviewThreads(first:100) { + nodes { id isResolved comments(first:100) { nodes { databaseId body } } } + } + } + } + } + """ + data = api.graphql(query, {"owner": owner, "name": name, "number": number}) + return data["repository"]["pullRequest"]["reviewThreads"]["nodes"] + + +def apply(api: Api, *, record: dict, task: dict, proposal: dict, outcome: dict) -> list[dict]: + if outcome.get("status") != "published" or not outcome.get("candidate"): + return [] + fork = record.get("fork") or {} + repository = fork.get("name") + number = fork.get("pr_number") + if not repository or not number: + raise ResponseError("development PR identity is missing") + feedback = feedback_items(task) + responses = {int(item["comment_id"]): item["summary"] for item in proposal.get("feedback_responses") or []} + missing = set(feedback) - set(responses) + if missing: + raise ResponseError(f"missing feedback responses: {sorted(missing)}") + owner, name = repository.split("/", 1) + head = outcome["candidate"] + inline_comments = api.call("GET", f"/repos/{repository}/pulls/{number}/comments?per_page=100") + conversation = api.call("GET", f"/repos/{repository}/issues/{number}/comments?per_page=100") + existing_bodies = [item.get("body") or "" for item in inline_comments + conversation] + threads = review_threads(api, owner, name, int(number)) if any(x.kind == "inline" for x in feedback.values()) else [] + actions: list[dict] = [] + for comment_id in sorted(feedback): + item = feedback[comment_id] + tag = marker(comment_id, head) + body = response_body(item, responses[comment_id], head) + if not any(tag in existing for existing in existing_bodies): + if item.kind == "inline": + api.call("POST", f"/repos/{repository}/pulls/{number}/comments/{comment_id}/replies", {"body": body}) + else: + api.call("POST", f"/repos/{repository}/issues/{number}/comments", {"body": body}) + existing_bodies.append(body) + actions.append({"comment_id": comment_id, "action": "replied"}) + if item.kind == "inline": + thread = next((thread for thread in threads if any( + comment.get("databaseId") == comment_id for comment in thread["comments"]["nodes"])), None) + if thread is None: + raise ResponseError(f"review thread for comment {comment_id} was not found") + if not thread["isResolved"]: + mutation = "mutation($id:ID!){resolveReviewThread(input:{threadId:$id}){thread{id isResolved}}}" + api.graphql(mutation, {"id": thread["id"]}) + actions.append({"comment_id": comment_id, "action": "resolved"}) + return actions + + +def main(argv=None) -> int: + parser = argparse.ArgumentParser() + for name in ("record", "task", "proposal", "outcome"): + parser.add_argument(f"--{name}", required=True, type=Path) + parser.add_argument("--out", required=True, type=Path) + args = parser.parse_args(argv) + values = {name: json.loads(getattr(args, name).read_text()) for name in ("record", "task", "proposal", "outcome")} + token = os.environ.get("UPSTREAMING_FORK_TOKEN") + if not token: + raise ResponseError("UPSTREAMING_FORK_TOKEN is missing") + actions = apply(Api(token), **values) + args.out.parent.mkdir(parents=True, exist_ok=True) + args.out.write_text(json.dumps({"actions": actions}, indent=2) + "\n") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/upstreaming/schemas/proposal.schema.json b/upstreaming/schemas/proposal.schema.json index 4eca38ae9ae..3a19151af8f 100644 --- a/upstreaming/schemas/proposal.schema.json +++ b/upstreaming/schemas/proposal.schema.json @@ -52,6 +52,19 @@ "maxLength": 200 } }, + "feedback_responses": { + "type": "array", + "maxItems": 128, + "items": { + "type": "object", + "additionalProperties": false, + "required": ["comment_id", "summary"], + "properties": { + "comment_id": {"type": "integer", "minimum": 1}, + "summary": {"type": "string", "minLength": 1, "maxLength": 1000} + } + } + }, "patch_digest": { "type": [ "string", diff --git a/upstreaming/tests/test_fork_publish.py b/upstreaming/tests/test_fork_publish.py index 6a83086dd62..b1e9d330a45 100644 --- a/upstreaming/tests/test_fork_publish.py +++ b/upstreaming/tests/test_fork_publish.py @@ -67,6 +67,14 @@ def test_repair_must_acknowledge_every_reason_evidence_record(self): with self.assertRaisesRegex(fork_publish.PublishRejected, "did not acknowledge"): fork_publish.check_proposal(self.proposal(reason_ids=[]), self.record, self.task) fork_publish.check_proposal(self.proposal(reason_ids=["ci-1"]), self.record, self.task) + self.task["context"] = {"reason_evidence": [{"kind": "human_relay", "data": { + "comments": [{"id": 20}], "conversation_comments": [{"id": 30}]}}]} + with self.assertRaisesRegex(fork_publish.PublishRejected, "responses for feedback"): + fork_publish.check_proposal(self.proposal(reason_ids=["ci-1"]), self.record, self.task) + fork_publish.check_proposal(self.proposal( + reason_ids=["ci-1"], feedback_responses=[ + {"comment_id": 20, "summary": "Updated the matrix."}, + {"comment_id": 30, "summary": "Enabled the test workflow."}]), self.record, self.task) def fork_head(self): return git(self.fork_bare, "rev-parse", "refs/heads/riscv64") diff --git a/upstreaming/tests/test_review_response.py b/upstreaming/tests/test_review_response.py new file mode 100644 index 00000000000..7241fa6b65a --- /dev/null +++ b/upstreaming/tests/test_review_response.py @@ -0,0 +1,76 @@ +# SPDX-FileCopyrightText: 2026 The RISE Project +# SPDX-License-Identifier: MIT + +import unittest + +from upstreaming import review_response + + +class FakeApi: + def __init__(self, existing=None, resolved=False): + self.existing = existing or [] + self.resolved = resolved + self.calls = [] + + def call(self, method, path, data=None): + self.calls.append((method, path, data)) + if method == "GET" and "/pulls/1/comments" in path: + return list(self.existing) + if method == "GET" and "/issues/1/comments" in path: + return [] + return {} + + def graphql(self, query, variables): + self.calls.append(("GRAPHQL", query, variables)) + if "reviewThreads" in query: + return {"repository": {"pullRequest": {"reviewThreads": {"nodes": [{ + "id": "PRRT_1", "isResolved": self.resolved, + "comments": {"nodes": [{"databaseId": 20, "body": "change this"}]} + }]}}}} + self.resolved = True + return {"resolveReviewThread": {"thread": {"id": "PRRT_1", "isResolved": True}}} + + +class TestReviewResponse(unittest.TestCase): + def values(self): + task = {"context": {"reason_evidence": [{"kind": "human_relay", "data": { + "comments": [{"id": 20, "reviewer": "maintainer"}], + "conversation_comments": [{"id": 30, "reviewer": "maintainer"}], + "reviews": []}}]}} + proposal = {"feedback_responses": [ + {"comment_id": 20, "summary": "Added riscv64 to the existing test matrix."}, + {"comment_id": 30, "summary": "Enabled the Test workflow for the pull request."}]} + record = {"fork": {"name": "riseproject-upstreaming/proj", "pr_number": 1}} + outcome = {"status": "published", "candidate": "a" * 40} + return record, task, proposal, outcome + + def test_replies_then_resolves_inline_thread(self): + api = FakeApi() + actions = review_response.apply(api, record=self.values()[0], task=self.values()[1], + proposal=self.values()[2], outcome=self.values()[3]) + self.assertEqual(actions, [{"comment_id": 20, "action": "replied"}, + {"comment_id": 20, "action": "resolved"}, + {"comment_id": 30, "action": "replied"}]) + reply = next(call for call in api.calls if "/comments/20/replies" in call[1]) + self.assertIn("@maintainer Added riscv64", reply[2]["body"]) + self.assertTrue(any(call[0] == "GRAPHQL" and "resolveReviewThread" in call[1] for call in api.calls)) + + def test_marker_makes_reply_idempotent_but_unresolved_thread_is_retried(self): + record, task, proposal, outcome = self.values() + tag = review_response.marker(20, outcome["candidate"]) + api = FakeApi(existing=[{"body": tag}]) + actions = review_response.apply(api, record=record, task=task, proposal=proposal, outcome=outcome) + self.assertNotIn(("POST", "/repos/riseproject-upstreaming/proj/pulls/1/comments/20/replies"), + [(method, path) for method, path, _ in api.calls]) + self.assertIn({"comment_id": 20, "action": "resolved"}, actions) + + def test_non_published_outcome_has_no_effect(self): + record, task, proposal, outcome = self.values() + api = FakeApi() + self.assertEqual(review_response.apply(api, record=record, task=task, proposal=proposal, + outcome={"status": "uncertain"}), []) + self.assertEqual(api.calls, []) + + +if __name__ == "__main__": + unittest.main()