-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_app_preview_status_label_projection.py
More file actions
149 lines (141 loc) · 5.7 KB
/
Copy pathtest_app_preview_status_label_projection.py
File metadata and controls
149 lines (141 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import json
import pytest
from tests.fixtures.app_harness import AppHarness
from tests.fixtures.reviewer_bot import (
make_state,
make_tracked_review_state,
pull_request_payload,
review_payload,
)
from tests.fixtures.reviewer_bot_builders import (
accept_contributor_revision,
accept_reviewer_comment,
accept_reviewer_review,
)
from tests.fixtures.reviewer_bot_fakes import RouteGitHubApi
pytestmark = pytest.mark.integration
def test_execute_run_preview_status_label_projection_is_read_only_pr264_contract(monkeypatch, capsys):
harness = AppHarness(monkeypatch)
harness.set_event(
EVENT_NAME="workflow_dispatch",
EVENT_ACTION="",
MANUAL_ACTION="preview-status-label-projection",
ISSUE_NUMBER=264,
VALIDATION_NONCE="nonce-pr264-projection",
GITHUB_SHA="workflow-head",
GITHUB_REPOSITORY="rustfoundation/safety-critical-rust-coding-guidelines",
GITHUB_RUN_ID="777",
GITHUB_RUN_ATTEMPT="2",
)
state = make_state()
review = make_tracked_review_state(
state,
264,
reviewer="iglesias",
assigned_at="2026-02-26T04:58:03.401345+00:00",
active_cycle_started_at="2026-02-26T04:58:03.401345+00:00",
)
accept_reviewer_review(
review,
semantic_key="pull_request_review:77",
timestamp="2026-03-18T01:09:05Z",
actor="iglesias",
reviewed_head_sha="head-old",
)
accept_contributor_revision(
review,
semantic_key="pull_request_sync:264:head-live",
timestamp="2026-03-18T12:09:36.450502+00:00",
actor="manhatsu",
head_sha="head-live",
)
accept_reviewer_comment(
review,
semantic_key="issue_comment:4240237244",
timestamp="2026-04-13T23:23:25Z",
actor="iglesias",
)
routes = RouteGitHubApi().add_request(
"GET",
"issues/264",
status_code=200,
payload={
"number": 264,
"state": "open",
"pull_request": {},
"labels": [{"name": "status: awaiting reviewer response"}],
},
).add_request(
"GET",
"pulls/264",
status_code=200,
payload={
**pull_request_payload(264, head_sha="head-live", author="manhatsu"),
"requested_reviewers": [],
},
).add_pull_request_reviews(
264,
[
review_payload(
501,
state="APPROVED",
submitted_at="2026-03-18T12:10:42Z",
commit_id="head-live",
author="plaindocs",
)
],
).add_request(
"GET",
"issues/264/comments?per_page=100&page=1",
status_code=200,
payload=[
{
"id": 4240237244,
"user": {"login": "iglesias"},
"created_at": "2026-04-13T23:23:25Z",
"body": "LGTM",
},
{
"id": 4240517367,
"user": {"login": "github-actions[bot]"},
"created_at": "2026-04-14T00:44:23Z",
"body": "⚠️ **Review Reminder**\n\n"
"Hey @iglesias, it's been more than 14 days since you were assigned to review this.\n\n"
"If no action is taken within 14 days, you may be transitioned from Producer to Observer status.",
},
{
"id": 4240520000,
"user": {"login": "github-actions[bot]"},
"created_at": "2026-04-14T00:52:09Z",
"body": "⚠️ **Review Reminder**\n\n"
"Hey @iglesias, this review has already received its final transition notice.\n\n"
"If no action is taken, the reviewer may be transitioned from Producer to Observer status.",
},
],
)
harness.runtime.github.stub(routes)
harness.stub_load_state(lambda *, fail_on_unavailable=False: state)
harness.stub_lock(acquire=lambda: (_ for _ in ()).throw(AssertionError("preview should not acquire lock")))
harness.stub_save_state(lambda current: (_ for _ in ()).throw(AssertionError("preview should not save state")))
harness.stub_sync_status_labels(lambda current, issue_numbers: (_ for _ in ()).throw(AssertionError("preview should not sync labels")))
harness.runtime.github.get_user_permission_status = lambda username, required_permission="push": "granted"
result = harness.run_execute()
assert result.exit_code == 0
payload = json.loads(capsys.readouterr().out)
assert payload["preview_action"] == "preview-status-label-projection"
assert payload["response_state"] == "reviewer_reassignment_needed"
assert payload["reviewer_authority_outcome"] == "tracked_reviewer_confirmed"
assert payload["suppression_reason"] == "legacy_duplicate_reminders_exhausted"
assert payload["current_scope_basis"] == "reminder_cadence_exhausted"
assert payload["actual_status_labels"] == ["status: awaiting reviewer response"]
assert payload["desired_status_labels"] == ["status: reviewer reassignment needed"]
assert payload["labels_to_add"] == ["status: reviewer reassignment needed"]
assert payload["labels_to_remove"] == ["status: awaiting reviewer response"]
assert payload["projection_metadata"]["source"] == "reviewer_response_decision"
assert payload["lock_attempted"] is False
assert payload["state_save_attempted"] is False
assert payload["tracked_state_mutations_attempted"] is False
assert payload["touched_projection_attempted"] is False
assert payload["artifact_name"] == "reviewer-bot-preview-output-777-attempt-2"
assert payload["artifact_file"] == "preview-output.json"
assert payload["output_keys"] == sorted(payload.keys())