quality-graph-github 0.1.10__tar.gz → 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/PKG-INFO +2 -2
  2. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/pyproject.toml +2 -2
  3. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/artifacts.py +28 -7
  4. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/commands.py +1 -3
  5. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/compiler.py +3 -0
  6. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/dashboard.py +10 -3
  7. quality_graph_github-0.2.0/src/qg_github/declarations.py +141 -0
  8. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/github.py +1 -1
  9. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/publication.py +121 -30
  10. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/reporting.py +10 -1
  11. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/runtime.py +5 -4
  12. quality_graph_github-0.1.10/src/qg_github/declarations.py +0 -69
  13. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/.gitignore +0 -0
  14. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/README.md +0 -0
  15. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/__init__.py +0 -0
  16. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/annotations.py +0 -0
  17. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/approvals.py +0 -0
  18. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/comments.py +0 -0
  19. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/controls.py +0 -0
  20. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/labels.py +0 -0
  21. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/presentation.py +0 -0
  22. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/provider.py +0 -0
  23. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/py.typed +0 -0
  24. {quality_graph_github-0.1.10 → quality_graph_github-0.2.0}/src/qg_github/required_checks.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: quality-graph-github
3
- Version: 0.1.10
3
+ Version: 0.2.0
4
4
  Summary: GitHub provider and Action runtime for Quality Graph
5
5
  Project-URL: Homepage, https://quality-graph.xyz/
6
6
  Project-URL: Documentation, https://quality-graph.xyz/
@@ -9,7 +9,7 @@ Requires-Python: >=3.12
9
9
  Requires-Dist: httpx>=0.28.1
10
10
  Requires-Dist: jinja2>=3.1.6
11
11
  Requires-Dist: pyyaml>=6.0.2
12
- Requires-Dist: quality-graph-core==0.1.10
12
+ Requires-Dist: quality-graph-core==0.2.0
13
13
  Description-Content-Type: text/markdown
14
14
 
15
15
  # Quality Graph GitHub Provider
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "quality-graph-github"
7
- version = "0.1.10"
7
+ version = "0.2.0"
8
8
  description = "GitHub provider and Action runtime for Quality Graph"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -13,7 +13,7 @@ dependencies = [
13
13
  "httpx>=0.28.1",
14
14
  "jinja2>=3.1.6",
15
15
  "pyyaml>=6.0.2",
16
- "quality-graph-core==0.1.10",
16
+ "quality-graph-core==0.2.0",
17
17
  ]
18
18
 
19
19
  [project.urls]
@@ -12,7 +12,7 @@ from pathlib import PurePosixPath
12
12
  from typing import TYPE_CHECKING
13
13
 
14
14
  from qg_github.github import GITHUB_PAGE_SIZE, GitHubPort
15
- from quality_graph_core.result import JsonValue, Result
15
+ from quality_graph_core.result import JsonValue, Provenance, Result, ResultStatus
16
16
 
17
17
  if TYPE_CHECKING:
18
18
  from collections.abc import Iterable, Mapping
@@ -46,6 +46,9 @@ class ArtifactExpectation:
46
46
  node_ids: frozenset[str]
47
47
  flow_id: str | None = None
48
48
  operation_ids: Mapping[str, str] = field(default_factory=dict)
49
+ run_attempt: int = 1
50
+ node_attempts: Mapping[str, int] = field(default_factory=dict)
51
+ node_conclusions: Mapping[str, str] = field(default_factory=dict)
49
52
 
50
53
 
51
54
  @dataclass(frozen=True)
@@ -63,19 +66,34 @@ def download_results(
63
66
  port: GitHubPort,
64
67
  expectation: ArtifactExpectation,
65
68
  ) -> dict[str, Result]:
66
- """Download the newest valid attempt for every expected node."""
67
- selected: dict[str, tuple[int, Result]] = {}
69
+ """Download results bound to the expected execution of each node."""
70
+ selected: dict[str, Result] = {}
71
+ seen: dict[tuple[str, int], Result] = {}
68
72
  for descriptor in _artifact_descriptors(port, expectation.workflow_run_id):
69
73
  if descriptor.node_id not in expectation.node_ids:
70
74
  message = f"artifact targets unknown graph node: {descriptor.node_id}"
75
+ raise DeclarationMismatchError(message)
76
+ if descriptor.attempt > expectation.run_attempt:
77
+ message = "result artifact attempt exceeds the latest workflow attempt"
71
78
  raise ArtifactError(message)
72
79
  archive = port.download(f"/actions/artifacts/{descriptor.id}/zip")
73
80
  result = _result_from_archive(archive, descriptor)
74
81
  _validate_result(result, descriptor, expectation)
75
- current = selected.get(descriptor.node_id)
76
- if current is None or descriptor.attempt >= current[0]:
77
- selected[descriptor.node_id] = (descriptor.attempt, result)
78
- return {node_id: result for node_id, (_, result) in selected.items()}
82
+ key = (descriptor.node_id, descriptor.attempt)
83
+ if key in seen and seen[key] != result:
84
+ message = f"conflicting result artifacts for node {key[0]} attempt {key[1]}"
85
+ raise ArtifactError(message)
86
+ seen[key] = result
87
+ expected_attempt = expectation.node_attempts.get(
88
+ descriptor.node_id, expectation.run_attempt
89
+ )
90
+ if descriptor.attempt == expected_attempt:
91
+ conclusion = expectation.node_conclusions.get(descriptor.node_id)
92
+ if result.status is ResultStatus.PASSED and conclusion not in {None, "success"}:
93
+ message = f"passed result contradicts workflow job state: {descriptor.node_id}"
94
+ raise ArtifactError(message)
95
+ selected[descriptor.node_id] = result
96
+ return selected
79
97
 
80
98
 
81
99
  def _artifact_descriptors(port: GitHubPort, run_id: int) -> tuple[ArtifactDescriptor, ...]:
@@ -173,6 +191,9 @@ def _validate_result(
173
191
  expectation: ArtifactExpectation,
174
192
  ) -> None:
175
193
  provenance = result.provenance
194
+ if not isinstance(provenance, Provenance):
195
+ message = "GitHub artifact contains foreign provider provenance"
196
+ raise ArtifactError(message)
176
197
  expected = (
177
198
  expectation.repository,
178
199
  expectation.pull_request,
@@ -220,11 +220,9 @@ def _command_context(port: GitHubPort, number: int) -> CommandContext:
220
220
  frozenset(node.id for node in graph.nodes),
221
221
  graph.flow_id,
222
222
  {node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
223
+ run_attempt=attempt,
223
224
  )
224
225
  graph, results = read_pr_results(port, graph, expectation)
225
- if any(result.provenance.run_attempt > attempt for result in results.values()):
226
- message = "result artifact attempt exceeds the latest workflow attempt"
227
- raise ValueError(message)
228
226
  state = effective_graph(graph, results, set())
229
227
  return CommandContext(graph, run_id, state.targets)
230
228
 
@@ -248,6 +248,9 @@ def _validate_explicit_flows(graph: Graph) -> None:
248
248
  message = "GitHub supports one executable release flow per declaration"
249
249
  raise ValueError(message)
250
250
  for flow in graph.flows:
251
+ if flow.presentation == "gitlab-mr":
252
+ message = "GitHub cannot use GitLab MR presentation"
253
+ raise ValueError(message)
251
254
  for branch in flow.branches:
252
255
  _default_branch(branch)
253
256
  _validate_release_contract(graph, flow)
@@ -32,6 +32,7 @@ class DashboardRow:
32
32
  metric: str
33
33
  summary_url: str
34
34
  logs_url: str
35
+ logs_label: str = "Logs"
35
36
 
36
37
 
37
38
  @dataclass(frozen=True)
@@ -108,6 +109,8 @@ def final_dashboard(
108
109
  graph: Graph,
109
110
  results: Mapping[str, Result],
110
111
  run: DashboardRun,
112
+ *,
113
+ job_urls: Mapping[str, str] | None = None,
111
114
  ) -> DashboardModel:
112
115
  """Build a final dashboard in declaration order."""
113
116
  rows: list[DashboardRow] = []
@@ -122,7 +125,8 @@ def final_dashboard(
122
125
  status,
123
126
  dashboard_metric(result),
124
127
  f"{run.url}#quality-graph-{node.id}",
125
- run.url,
128
+ (job_urls or {}).get(node.id, run.url),
129
+ "Logs" if node.id in (job_urls or {}) else "Workflow run",
126
130
  )
127
131
  )
128
132
  if result is not None and (result.controls or result.notes):
@@ -163,6 +167,7 @@ def pending_dashboard(
163
167
  "—",
164
168
  f"{run.url}#quality-graph-{node.id}",
165
169
  run.url,
170
+ "Workflow run",
166
171
  )
167
172
  for node in graph.nodes
168
173
  )
@@ -183,6 +188,7 @@ def live_dashboard(
183
188
  run: DashboardRun,
184
189
  *,
185
190
  managed_labels: tuple[str, ...] = (),
191
+ job_urls: Mapping[str, str] | None = None,
186
192
  ) -> DashboardModel:
187
193
  """Build a live dashboard from authoritative GitHub job statuses."""
188
194
  rows = tuple(
@@ -192,7 +198,8 @@ def live_dashboard(
192
198
  statuses.get(node.node_id, ResultStatus.WAITING),
193
199
  "—",
194
200
  f"{run.url}#quality-graph-{node.node_id}",
195
- run.url,
201
+ (job_urls or {}).get(node.node_id, run.url),
202
+ "Logs" if node.node_id in (job_urls or {}) else "Workflow run",
196
203
  )
197
204
  for node in nodes
198
205
  )
@@ -252,7 +259,7 @@ def _render(model: DashboardModel) -> str:
252
259
  ]
253
260
  lines.extend(
254
261
  f"| {_table(row.title)} | {_status_icon(row.status)} {row.status.value} | "
255
- f"{row.metric} | [Summary]({row.summary_url}) · [Logs]({row.logs_url}) |"
262
+ f"{row.metric} | [Summary]({row.summary_url}) · [{row.logs_label}]({row.logs_url}) |"
256
263
  for row in model.rows
257
264
  )
258
265
  if model.control_groups:
@@ -0,0 +1,141 @@
1
+ """Accept declaration migrations that preserve every trusted required check."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import base64
6
+ from dataclasses import replace
7
+ from typing import TYPE_CHECKING
8
+ from urllib.parse import quote
9
+
10
+ from qg_github.artifacts import ArtifactError, DeclarationMismatchError, download_results
11
+ from qg_github.compiler import compile_graph, pr_contract
12
+ from qg_github.github import GITHUB_PAGE_SIZE, GitHubError
13
+ from qg_github.presentation import pr_presentation_graph
14
+ from quality_graph_core.graph import Graph
15
+
16
+ if TYPE_CHECKING:
17
+ from qg_github.artifacts import ArtifactExpectation
18
+ from qg_github.github import GitHubPort
19
+ from quality_graph_core.result import JsonValue, Result
20
+
21
+ MAX_DECLARATION_BYTES = 1_048_576
22
+
23
+
24
+ def read_pr_results(
25
+ port: GitHubPort, graph: Graph, expectation: ArtifactExpectation
26
+ ) -> tuple[Graph, dict[str, Result]]:
27
+ """Verify run provenance while preserving the trusted checks and governance."""
28
+ expectation = _execution_expectation(port, graph, expectation)
29
+ try:
30
+ return graph, download_results(port, expectation)
31
+ except DeclarationMismatchError as mismatch:
32
+ try:
33
+ head = _head_declaration(port, expectation.head_sha)
34
+ compiled = compile_graph(head)
35
+ projected = pr_presentation_graph(head)
36
+ except (GitHubError, ValueError, TypeError) as error:
37
+ raise mismatch from error
38
+ if (
39
+ projected is None
40
+ or compiled.graph_digest == expectation.graph_digest
41
+ or not _preserves_required_checks(graph, projected)
42
+ ):
43
+ message = (
44
+ "PR declaration changes existing required checks or governance; "
45
+ "the trusted base declaration must be updated before these results can be accepted"
46
+ )
47
+ raise DeclarationMismatchError(message) from mismatch
48
+ current = replace(
49
+ expectation,
50
+ graph_digest=compiled.graph_digest,
51
+ node_ids=frozenset(node.id for node in projected.nodes),
52
+ flow_id=projected.flow_id,
53
+ operation_ids={
54
+ node.id: node.operation_id
55
+ for node in projected.nodes
56
+ if node.operation_id is not None
57
+ },
58
+ )
59
+ current = _execution_expectation(port, projected, current)
60
+ return projected, download_results(port, current)
61
+
62
+
63
+ def _preserves_required_checks(base: Graph, head: Graph) -> bool:
64
+ """Allow additional nodes only when existing contracts remain identical."""
65
+ required = {node.id for node in base.nodes}
66
+ existing = tuple(node for node in head.nodes if node.id in required)
67
+ return pr_contract(replace(head, nodes=existing)) == pr_contract(base)
68
+
69
+
70
+ def _head_declaration(port: GitHubPort, sha: str) -> Graph:
71
+ value = port.request("GET", f"/contents/qg.yaml?ref={quote(sha, safe='')}")
72
+ if not isinstance(value, dict):
73
+ message = "head declaration response must be an object"
74
+ raise TypeError(message)
75
+ content = value.get("content")
76
+ if not isinstance(content, str):
77
+ message = "head declaration must be text"
78
+ raise TypeError(message)
79
+ decoded = base64.b64decode("".join(content.split()), validate=True)
80
+ if len(decoded) > MAX_DECLARATION_BYTES:
81
+ message = "head declaration exceeds the size limit"
82
+ raise ValueError(message)
83
+ return Graph.from_yaml(decoded.decode())
84
+
85
+
86
+ def _execution_expectation(
87
+ port: GitHubPort, graph: Graph, expectation: ArtifactExpectation
88
+ ) -> ArtifactExpectation:
89
+ if expectation.run_attempt < 1:
90
+ message = "workflow attempt must be positive"
91
+ raise ArtifactError(message)
92
+ if expectation.run_attempt == 1:
93
+ return expectation
94
+ by_title = {node.title: node.id for node in graph.nodes}
95
+ attempts: dict[str, int] = {}
96
+ conclusions: dict[str, str] = {}
97
+ for attempt in range(expectation.run_attempt, 0, -1):
98
+ jobs = _attempt_jobs(port, expectation.workflow_run_id, attempt)
99
+ matched: set[str] = set()
100
+ for job in jobs:
101
+ name = job.get("name")
102
+ node_id = by_title.get(name) if isinstance(name, str) else None
103
+ if node_id is None or node_id in attempts:
104
+ continue
105
+ if node_id in matched:
106
+ message = f"ambiguous workflow jobs for node {node_id} attempt {attempt}"
107
+ raise ArtifactError(message)
108
+ matched.add(node_id)
109
+ conclusion = job.get("conclusion")
110
+ if (
111
+ job.get("run_id") != expectation.workflow_run_id
112
+ or job.get("run_attempt") != attempt
113
+ or job.get("status") != "completed"
114
+ or not isinstance(conclusion, str)
115
+ ):
116
+ message = f"invalid workflow job evidence for node {node_id} attempt {attempt}"
117
+ raise ArtifactError(message)
118
+ conclusions[node_id] = conclusion
119
+ attempts.update(dict.fromkeys(matched, attempt))
120
+ if expectation.node_ids <= attempts.keys():
121
+ return replace(expectation, node_attempts=attempts, node_conclusions=conclusions)
122
+ message = "missing workflow job evidence for result artifacts"
123
+ raise ArtifactError(message)
124
+
125
+
126
+ def _attempt_jobs(port: GitHubPort, run_id: int, attempt: int) -> list[dict[str, JsonValue]]:
127
+ jobs: list[dict[str, JsonValue]] = []
128
+ page = 1
129
+ while True:
130
+ response = port.request(
131
+ "GET",
132
+ f"/actions/runs/{run_id}/attempts/{attempt}/jobs?per_page={GITHUB_PAGE_SIZE}&page={page}",
133
+ )
134
+ values = response.get("jobs") if isinstance(response, dict) else None
135
+ if not isinstance(values, list) or any(not isinstance(job, dict) for job in values):
136
+ message = f"invalid workflow jobs response for attempt {attempt}"
137
+ raise ArtifactError(message)
138
+ jobs.extend(job for job in values if isinstance(job, dict))
139
+ if len(values) < GITHUB_PAGE_SIZE:
140
+ return jobs
141
+ page += 1
@@ -95,7 +95,7 @@ class HttpGitHubPort:
95
95
  raise GitHubError(method, path, response.status_code)
96
96
  try:
97
97
  return cast("JsonValue", response.json())
98
- except json.JSONDecodeError as error:
98
+ except (json.JSONDecodeError, UnicodeDecodeError) as error:
99
99
  message = f"GitHub {method} {path} returned invalid JSON"
100
100
  raise RuntimeError(message) from error
101
101
 
@@ -6,6 +6,7 @@ import base64
6
6
  import json
7
7
  import time
8
8
  import urllib.parse
9
+ from collections import Counter
9
10
  from dataclasses import dataclass, replace
10
11
  from typing import TYPE_CHECKING, cast
11
12
 
@@ -29,7 +30,7 @@ from qg_github.labels import parse_label_state, reconcile_labels
29
30
  from qg_github.presentation import pr_presentation_graph
30
31
  from quality_graph_core.graph import Graph
31
32
  from quality_graph_core.policy import effective_graph
32
- from quality_graph_core.result import JsonValue, ResultStatus
33
+ from quality_graph_core.result import JsonValue, Provenance, ResultStatus
33
34
 
34
35
  if TYPE_CHECKING:
35
36
  from collections.abc import Callable, Mapping
@@ -201,18 +202,35 @@ def publish_workflow_jobs(
201
202
  is_current: Callable[[], bool] = lambda: True,
202
203
  ) -> bool:
203
204
  """Merge authoritative job lifecycle into the single live dashboard."""
204
- statuses = _workflow_node_statuses(port, nodes, run.id)
205
- terminal = len(statuses) == len(nodes) and all(
206
- status not in {ResultStatus.WAITING, ResultStatus.IN_PROGRESS}
207
- for status in statuses.values()
205
+ jobs = _workflow_jobs(port, run.id)
206
+ selected = _workflow_node_jobs(nodes, jobs, run)
207
+ statuses = {node_id: _workflow_job_status(job) for node_id, job in selected.items()}
208
+ current_attempt = run.attempt == 1 or any(
209
+ job.get("run_attempt") == run.attempt for job in selected.values()
210
+ )
211
+ terminal = (
212
+ current_attempt
213
+ and len(statuses) == len(nodes)
214
+ and all(
215
+ status not in {ResultStatus.WAITING, ResultStatus.IN_PROGRESS}
216
+ for status in statuses.values()
217
+ )
208
218
  )
209
219
  if terminal or not is_current():
210
220
  return True
211
- if len(statuses) < len(nodes) and _workflow_run_completed(port, run.id):
221
+ if (len(statuses) < len(nodes) or not current_attempt) and _workflow_run_completed(
222
+ port, run.id
223
+ ):
212
224
  return True
213
225
  existing = find_managed_comment(port, number, DASHBOARD_MARKER)
214
226
  previous_labels = parse_label_state(existing.body) if existing is not None else frozenset()
215
- model = live_dashboard(nodes, statuses, run, managed_labels=tuple(sorted(previous_labels)))
227
+ model = live_dashboard(
228
+ nodes,
229
+ statuses,
230
+ run,
231
+ managed_labels=tuple(sorted(previous_labels)),
232
+ job_urls=_workflow_job_urls(selected, run),
233
+ )
216
234
  upsert_managed_comment(port, number, DASHBOARD_MARKER, render_dashboard(model))
217
235
  return terminal
218
236
 
@@ -229,8 +247,7 @@ def _workflow_jobs(port: GitHubPort, run_id: int) -> tuple[JsonValue, ...]:
229
247
  response = _object(
230
248
  port.request(
231
249
  "GET",
232
- f"/actions/runs/{run_id}/jobs?filter=latest"
233
- f"&per_page={GITHUB_PAGE_SIZE}&page={page}",
250
+ f"/actions/runs/{run_id}/jobs?filter=all&per_page={GITHUB_PAGE_SIZE}&page={page}",
234
251
  ),
235
252
  "workflow jobs",
236
253
  )
@@ -241,21 +258,11 @@ def _workflow_jobs(port: GitHubPort, run_id: int) -> tuple[JsonValue, ...]:
241
258
  page += 1
242
259
 
243
260
 
244
- def _workflow_node_statuses(
245
- port: GitHubPort,
246
- nodes: tuple[DashboardNode, ...],
247
- run_id: int,
248
- ) -> dict[str, ResultStatus]:
249
- """Map declared nodes to authoritative GitHub workflow job statuses."""
250
- by_title = {node.title: node.node_id for node in nodes}
251
- statuses: dict[str, ResultStatus] = {}
252
- for value in _workflow_jobs(port, run_id):
253
- job = _object(value, "workflow job")
254
- name = _string(job.get("name"), "workflow job name")
255
- node_id = by_title.get(name)
256
- if node_id is not None:
257
- statuses[node_id] = _workflow_job_status(job)
258
- return statuses
261
+ def _optional_workflow_jobs(port: GitHubPort, run_id: int) -> tuple[JsonValue, ...]:
262
+ try:
263
+ return _workflow_jobs(port, run_id)
264
+ except (RuntimeError, TypeError):
265
+ return ()
259
266
 
260
267
 
261
268
  def _workflow_job_status(job: Mapping[str, JsonValue]) -> ResultStatus:
@@ -293,25 +300,43 @@ def _completed_dashboard(
293
300
  frozenset(node.id for node in graph.nodes),
294
301
  graph.flow_id,
295
302
  {node.id: node.operation_id for node in graph.nodes if node.operation_id is not None},
303
+ run_attempt=run.attempt,
296
304
  )
297
305
  try:
298
306
  graph, results = read_pr_results(port, graph, expectation)
299
307
  except ArtifactError as error:
300
308
  nodes = tuple(DashboardNode(node.id, node.title) for node in graph.nodes)
301
- statuses = _workflow_node_statuses(port, nodes, run.id)
302
- fallback = live_dashboard(nodes, statuses, run)
309
+ selected = _workflow_node_jobs(nodes, _optional_workflow_jobs(port, run.id), run)
310
+ statuses = {node_id: _workflow_job_status(job) for node_id, job in selected.items()}
311
+ fallback = live_dashboard(nodes, statuses, run, job_urls=_workflow_job_urls(selected, run))
303
312
  return (
304
313
  replace(
305
314
  fallback,
306
315
  status=ResultStatus.FAILED,
307
- message=f"The final dashboard could not be assembled: {error}",
316
+ message=(
317
+ f"The final dashboard could not be assembled: {error}. "
318
+ "Rows below show native job conclusions, not verified result artifacts."
319
+ ),
308
320
  ),
309
321
  None,
310
322
  )
311
323
  approvals = approval_ledger(port, pull.number)
312
324
  effective = effective_graph(graph, results, approvals)
313
- model = final_dashboard(graph, effective.results, run)
314
- missing = expectation.node_ids - results.keys()
325
+ nodes = tuple(DashboardNode(node.id, node.title) for node in graph.nodes)
326
+ selected = _workflow_node_jobs(
327
+ nodes,
328
+ _optional_workflow_jobs(port, run.id),
329
+ run,
330
+ attempts={
331
+ node_id: result.provenance.run_attempt
332
+ for node_id, result in results.items()
333
+ if isinstance(result.provenance, Provenance)
334
+ },
335
+ )
336
+ model = final_dashboard(
337
+ graph, effective.results, run, job_urls=_workflow_job_urls(selected, run)
338
+ )
339
+ missing = {node.id for node in graph.nodes} - results.keys()
315
340
  if missing:
316
341
  model = replace(
317
342
  model,
@@ -392,7 +417,7 @@ def _publish_check(port: GitHubPort, model: DashboardModel) -> None:
392
417
  "head_sha": model.head_sha,
393
418
  "external_id": external_id,
394
419
  "status": "completed" if completed else "in_progress",
395
- "details_url": next((row.logs_url for row in model.rows), ""),
420
+ "details_url": next((row.summary_url.split("#", 1)[0] for row in model.rows), ""),
396
421
  "output": {
397
422
  "title": "Quality Graph",
398
423
  "summary": model.message,
@@ -465,3 +490,69 @@ def _integer(value: JsonValue, context: str) -> int:
465
490
 
466
491
  def _optional_integer(value: JsonValue, context: str) -> int | None:
467
492
  return None if value is None else _integer(value, context)
493
+
494
+
495
+ def _workflow_node_jobs(
496
+ nodes: tuple[DashboardNode, ...],
497
+ jobs: tuple[JsonValue, ...],
498
+ run: DashboardRun,
499
+ *,
500
+ attempts: Mapping[str, int] | None = None,
501
+ ) -> dict[str, dict[str, JsonValue]]:
502
+ titles = Counter(node.title for node in nodes)
503
+ selected: dict[str, dict[str, JsonValue]] = {}
504
+ for node in nodes:
505
+ if titles[node.title] != 1:
506
+ continue
507
+ candidates = [
508
+ job
509
+ for job in jobs
510
+ if isinstance(job, dict)
511
+ and job.get("name") == node.title
512
+ and job.get("run_id", run.id) == run.id
513
+ and isinstance(attempt := job.get("run_attempt", run.attempt), int)
514
+ and not isinstance(attempt, bool)
515
+ and 0 < attempt <= run.attempt
516
+ and (attempts is None or attempt == attempts.get(node.node_id, run.attempt))
517
+ ]
518
+ newest = max(
519
+ (
520
+ value
521
+ for job in candidates
522
+ if isinstance(value := job.get("run_attempt", run.attempt), int)
523
+ ),
524
+ default=0,
525
+ )
526
+ matches = [job for job in candidates if job.get("run_attempt", run.attempt) == newest]
527
+ if len(matches) == 1:
528
+ selected[node.node_id] = matches[0]
529
+ return selected
530
+
531
+
532
+ def _workflow_job_urls(
533
+ jobs: Mapping[str, Mapping[str, JsonValue]], run: DashboardRun
534
+ ) -> dict[str, str]:
535
+ urls: dict[str, str] = {}
536
+ for node_id, job in jobs.items():
537
+ url = job.get("html_url")
538
+ identifier = job.get("id")
539
+ attempt = job.get("run_attempt")
540
+ if (
541
+ job.get("run_id") != run.id
542
+ or not isinstance(identifier, int)
543
+ or isinstance(identifier, bool)
544
+ or identifier <= 0
545
+ or not isinstance(attempt, int)
546
+ or isinstance(attempt, bool)
547
+ or not 0 < attempt <= run.attempt
548
+ or not isinstance(url, str)
549
+ ):
550
+ continue
551
+ parsed = urllib.parse.urlsplit(url)
552
+ if (
553
+ parsed.scheme == "https"
554
+ and parsed.netloc
555
+ and not any(char in url for char in "\n\r()|")
556
+ ):
557
+ urls[node_id] = url
558
+ return urls
@@ -30,7 +30,7 @@ def render_job_summary(result: Result) -> str:
30
30
  )
31
31
  if result.findings:
32
32
  lines.extend(("", "### Findings", ""))
33
- lines.extend(_finding_line(finding) for finding in result.findings[:MAX_SUMMARY_FINDINGS])
33
+ lines.extend(_finding_lines(result.findings[:MAX_SUMMARY_FINDINGS]))
34
34
  omitted = len(result.findings) - MAX_SUMMARY_FINDINGS
35
35
  if omitted > 0:
36
36
  notice = f"_{omitted} additional findings are available in the result artifact._"
@@ -129,3 +129,12 @@ def _bounded(value: str, maximum: int) -> str:
129
129
  if updated == omitted:
130
130
  return value[:prefix] + notice
131
131
  omitted = updated
132
+
133
+
134
+ def _finding_lines(findings: tuple[Finding, ...]) -> list[str]:
135
+ lines: list[str] = []
136
+ for group in dict.fromkeys(finding.group for finding in findings):
137
+ if group:
138
+ lines.extend((f"#### {html.escape(group)}", ""))
139
+ lines.extend(_finding_line(finding) for finding in findings if finding.group == group)
140
+ return lines
@@ -97,8 +97,7 @@ def collect(request: CollectionRequest) -> Result:
97
97
  """Collect one command outcome through its selected adapter."""
98
98
  try:
99
99
  if request.adapter is AdapterKind.EXIT_CODE:
100
- state = "passed" if request.context.command_succeeded else "failed"
101
- output = f"The declared command {state}."
100
+ output = ""
102
101
  if request.report_path is not None:
103
102
  try:
104
103
  output = read_report(request.workspace, request.report_path).decode()
@@ -117,8 +116,10 @@ def collect(request: CollectionRequest) -> Result:
117
116
  else:
118
117
  result = adapt_junit(request.context, report)
119
118
  return _with_policy_controls(request, result)
120
- except AdapterError as error:
121
- return _with_policy_controls(request, adapter_failure(request.context, error))
119
+ except (AdapterError, OSError) as error:
120
+ return _with_policy_controls(
121
+ request, adapter_failure(request.context, AdapterError(str(error)))
122
+ )
122
123
 
123
124
 
124
125
  def _with_policy_controls(request: CollectionRequest, result: Result) -> Result:
@@ -1,69 +0,0 @@
1
- """Accept declaration migrations only when the trusted PR contract is unchanged."""
2
-
3
- from __future__ import annotations
4
-
5
- import base64
6
- from dataclasses import replace
7
- from typing import TYPE_CHECKING
8
- from urllib.parse import quote
9
-
10
- from qg_github.artifacts import DeclarationMismatchError, download_results
11
- from qg_github.compiler import compile_graph, pr_contract
12
- from qg_github.github import GitHubError
13
- from qg_github.presentation import pr_presentation_graph
14
- from quality_graph_core.graph import Graph
15
-
16
- if TYPE_CHECKING:
17
- from qg_github.artifacts import ArtifactExpectation
18
- from qg_github.github import GitHubPort
19
- from quality_graph_core.result import Result
20
-
21
- MAX_DECLARATION_BYTES = 1_048_576
22
-
23
-
24
- def read_pr_results(
25
- port: GitHubPort, graph: Graph, expectation: ArtifactExpectation
26
- ) -> tuple[Graph, dict[str, Result]]:
27
- """Verify run provenance and allow only semantically identical PR declaration migrations."""
28
- try:
29
- return graph, download_results(port, expectation)
30
- except DeclarationMismatchError as mismatch:
31
- try:
32
- head = _head_declaration(port, expectation.head_sha)
33
- compiled = compile_graph(head)
34
- projected = pr_presentation_graph(head)
35
- except (GitHubError, ValueError, TypeError) as error:
36
- raise mismatch from error
37
- if (
38
- projected is None
39
- or compiled.graph_digest == expectation.graph_digest
40
- or pr_contract(projected) != pr_contract(graph)
41
- ):
42
- raise
43
- current = replace(
44
- expectation,
45
- graph_digest=compiled.graph_digest,
46
- flow_id=projected.flow_id,
47
- operation_ids={
48
- node.id: node.operation_id
49
- for node in projected.nodes
50
- if node.operation_id is not None
51
- },
52
- )
53
- return projected, download_results(port, current)
54
-
55
-
56
- def _head_declaration(port: GitHubPort, sha: str) -> Graph:
57
- value = port.request("GET", f"/contents/qg.yaml?ref={quote(sha, safe='')}")
58
- if not isinstance(value, dict):
59
- message = "head declaration response must be an object"
60
- raise TypeError(message)
61
- content = value.get("content")
62
- if not isinstance(content, str):
63
- message = "head declaration must be text"
64
- raise TypeError(message)
65
- decoded = base64.b64decode("".join(content.split()), validate=True)
66
- if len(decoded) > MAX_DECLARATION_BYTES:
67
- message = "head declaration exceeds the size limit"
68
- raise ValueError(message)
69
- return Graph.from_yaml(decoded.decode())