perf: isolate pull check refreshes (Closes #521)
This commit is contained in:
1 parent
8907263760
commit
e5a352b418
8 files changed
+255
-10
No files matched your search
+35
-6
@@ -4055,7 +4055,7 @@ Promise.allSettled([first, concurrent]).then(async failed => {{
|
||||
]
|
||||
|
||||
|
||||
def test_pull_sheet_refreshes_checks_without_clearing_head_scoped_progress():
|
||||
def test_pull_sheet_refreshes_status_only_without_clearing_review_progress():
|
||||
script = f"""
|
||||
const createPullSheet = require({json.dumps(str(PULL_SHEET))});
|
||||
const values = new Map();
|
||||
@@ -4070,15 +4070,19 @@ const sheet = createPullSheet({{storage, fetchJson: url => {{
|
||||
const item = {{repository:'stackchain/api', number:7}};
|
||||
sheet.loadReview(item, 'abc123').then(first => {{
|
||||
sheet.toggleReviewed(item, first, 'src/api.py');
|
||||
return sheet.loadReview(item, 'abc123', {{refresh:true}}).then(refreshed => {{
|
||||
process.stdout.write(JSON.stringify({{calls, refreshed, progress:sheet.reviewState(item, refreshed)}}));
|
||||
return sheet.loadChecks(item).then(refreshed => {{
|
||||
const combined = {{...first, ...refreshed}};
|
||||
process.stdout.write(JSON.stringify({{calls, refreshed, progress:sheet.reviewState(item, combined)}}));
|
||||
}});
|
||||
}});
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], check=True, capture_output=True, text=True)
|
||||
output = json.loads(result.stdout)
|
||||
|
||||
assert len(output["calls"]) == 2
|
||||
assert output["calls"] == [
|
||||
"api/v1/repos/stackchain/api/pulls/7/review-data",
|
||||
"api/v1/repos/stackchain/api/pulls/7/checks",
|
||||
]
|
||||
assert output["refreshed"]["ci_state"] == "success"
|
||||
assert output["progress"] == {"reviewed": ["src/api.py"], "total": 1, "complete": True}
|
||||
|
||||
@@ -4483,6 +4487,28 @@ controller.load({{ repository: 'stackchain/api', number: 7 }}).then(detail =>
|
||||
}
|
||||
|
||||
|
||||
def test_review_controller_refreshes_checks_through_status_only_path():
|
||||
script = f"""
|
||||
const createReviewController = require({json.dumps(str(REVIEW_SHEET))});
|
||||
const calls = [];
|
||||
const controller = createReviewController({{ fetchJson: async (url, options) => {{
|
||||
calls.push({{url, accept:options.headers.Accept}});
|
||||
return {{head_sha:'abc123', ci_state:'success', checks:[]}};
|
||||
}} }});
|
||||
controller.loadChecks({{repository:'stackchain/api', number:7}}).then(status =>
|
||||
process.stdout.write(JSON.stringify({{calls, status}}))
|
||||
);
|
||||
"""
|
||||
result = subprocess.run(["node", "-e", script], check=True, capture_output=True, text=True)
|
||||
output = json.loads(result.stdout)
|
||||
|
||||
assert output["calls"] == [{
|
||||
"url": "api/v1/repos/stackchain/api/pulls/7/review/checks",
|
||||
"accept": "application/json",
|
||||
}]
|
||||
assert output["status"]["ci_state"] == "success"
|
||||
|
||||
|
||||
def test_review_diff_rows_escape_content_and_toggle_accessibly():
|
||||
script = f"""
|
||||
const reviewSheet = require({json.dumps(str(REVIEW_SHEET))});
|
||||
@@ -4553,7 +4579,7 @@ process.stdout.write(JSON.stringify({{result, offline}}));
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_mobile_pull_review_sheets_expose_actionable_refreshable_checks():
|
||||
async def test_mobile_pull_review_sheets_refresh_checks_without_reloading_diffs():
|
||||
html = await dashboard()
|
||||
|
||||
assert html.index('id="pull-checks"') < html.index('id="pull-files"')
|
||||
@@ -4561,7 +4587,10 @@ async def test_mobile_pull_review_sheets_expose_actionable_refreshable_checks():
|
||||
assert 'id="refresh-pull-checks"' in html
|
||||
assert 'id="refresh-review-checks"' in html
|
||||
assert "createReviewController.renderChecks" in html
|
||||
assert "{ refresh: true }" in html
|
||||
assert "pullController.loadChecks(item)" in html
|
||||
assert "reviewController.loadChecks(item)" in html
|
||||
assert "New commits detected. Reload review data before merging." in html
|
||||
assert "New commits detected. Reload the review before submitting feedback." in html
|
||||
assert "qs('#refresh-review-checks').disabled = offlineReview" in html
|
||||
assert ".ci-check-link" in html and "min-height:44px" in html
|
||||
assert ".ci-check-copy" in html and "overflow-wrap:anywhere" in html
|
||||
|
||||
@@ -125,6 +125,69 @@ async def test_assigned_pull_review_endpoint_loads_review_payload_on_demand(monk
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_gitea_pull_check_status_skips_files_reviews_and_diff():
|
||||
requests = []
|
||||
|
||||
async def handler(request):
|
||||
requests.append((request.method, request.url.path))
|
||||
if request.url.path.endswith("/pulls/7"):
|
||||
return httpx.Response(200, json={
|
||||
"state": "open", "draft": False, "mergeable": True, "merged": False,
|
||||
"head": {"sha": "abc123"},
|
||||
})
|
||||
if request.url.path.endswith("/commits/abc123/status"):
|
||||
return httpx.Response(200, json={
|
||||
"state": "success",
|
||||
"statuses": [{"context": "tests", "status": "success", "description": "Passed"}],
|
||||
})
|
||||
raise AssertionError(f"unexpected request: {request.method} {request.url.path}")
|
||||
|
||||
gitea_proxy.start_client(transport=httpx.MockTransport(handler))
|
||||
try:
|
||||
status = await gitea_proxy.pull_check_status("stackchain/api", 7)
|
||||
finally:
|
||||
await gitea_proxy.stop_client()
|
||||
|
||||
assert requests == [
|
||||
("GET", "/api/v1/repos/stackchain/api/pulls/7"),
|
||||
("GET", "/api/v1/repos/stackchain/api/commits/abc123/status"),
|
||||
]
|
||||
assert status == {
|
||||
"repository": "stackchain/api", "number": 7, "head_sha": "abc123",
|
||||
"state": "open", "draft": False, "mergeable": True, "merged": False,
|
||||
"ci_state": "success",
|
||||
"checks": [{"name": "tests", "state": "success", "description": "Passed", "url": ""}],
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_assigned_pull_checks_endpoint_authorizes_and_returns_status_only(monkeypatch):
|
||||
calls = []
|
||||
|
||||
async def assigned(repository, number):
|
||||
calls.append(("assigned", repository, number))
|
||||
return True
|
||||
|
||||
async def checks(repository, number):
|
||||
calls.append(("checks", repository, number))
|
||||
return {"head_sha": "abc123", "ci_state": "pending", "checks": []}
|
||||
|
||||
monkeypatch.setattr(main.gitea_proxy, "is_assigned_pull", assigned)
|
||||
monkeypatch.setattr(main.gitea_proxy, "pull_check_status", checks)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.get("/api/v1/repos/stackchain/api/pulls/7/checks")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["cache-control"] == "no-store"
|
||||
assert response.json() == {"head_sha": "abc123", "ci_state": "pending", "checks": []}
|
||||
assert calls == [
|
||||
("assigned", "stackchain/api", 7),
|
||||
("checks", "stackchain/api", 7),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_gitea_assigned_pull_review_includes_bounded_diff_previews():
|
||||
async def handler(request):
|
||||
|
||||
@@ -36,6 +36,33 @@ async def test_review_detail_endpoint_returns_normalized_no_store_payload(monkey
|
||||
assert response.json()["files"][0]["filename"] == "src/api.py"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_requested_review_checks_endpoint_authorizes_and_returns_status_only(monkeypatch):
|
||||
calls = []
|
||||
|
||||
async def requested(repository, number):
|
||||
calls.append(("requested", repository, number))
|
||||
return True
|
||||
|
||||
async def checks(repository, number):
|
||||
calls.append(("checks", repository, number))
|
||||
return {"head_sha": "def456", "ci_state": "success", "checks": []}
|
||||
|
||||
monkeypatch.setattr(main, "is_requested_review", requested)
|
||||
monkeypatch.setattr(main.gitea_proxy, "pull_check_status", checks)
|
||||
transport = httpx.ASGITransport(app=main.app)
|
||||
async with httpx.AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.get("/api/v1/repos/stackchain/api/pulls/7/review/checks")
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.headers["cache-control"] == "no-store"
|
||||
assert response.json() == {"head_sha": "def456", "ci_state": "success", "checks": []}
|
||||
assert calls == [
|
||||
("requested", "stackchain/api", 7),
|
||||
("checks", "stackchain/api", 7),
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_gitea_review_detail_returns_bounded_actionable_checks(monkeypatch):
|
||||
monkeypatch.setattr(gitea_proxy, "GITEA_URL", "https://forge.example/git")
|
||||
|
||||
Reference in new issue
Block a user