Merge pull request 'feat: project verified independent component releases (marqdo#96 M4)' (#105) from feat/project-independent-releases into main
Merge pull request: project verified independent component releases (marqdo#96 M4)
This commit was merged in pull request #105.
This commit is contained in:
commit
b25edd25ff
2 files changed
+141
-3
No files matched your search
+106
-2
@@ -369,8 +369,99 @@ def asset_platform(kind: str, target: str) -> str:
|
||||
return "supported" if kind == "archive" else "not-applicable"
|
||||
|
||||
|
||||
def independent_rows(report: dict, components: list[dict], existing: dict[str, dict],
|
||||
repositories: set[str], refs: set[str]) -> list[dict]:
|
||||
"""Verified, independently released components that are not root-accepted.
|
||||
|
||||
The rows come from the same reconcile facts as accepted releases (tag ->
|
||||
SHA, same-SHA CI, evidence digest, asset bytes). They are exposed for
|
||||
discovery as ``integration_state: pending`` and never enter an offer,
|
||||
recommendation or download list; root acceptance stays a separate fact.
|
||||
"""
|
||||
by_component = {component["id"]: component for component in components}
|
||||
rows: list[dict] = []
|
||||
for entry in report["results"]:
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
if entry.get("repository") not in repositories:
|
||||
continue
|
||||
if entry.get("status") not in {"pending", "tracked"}:
|
||||
continue
|
||||
component_id = entry.get("component")
|
||||
require(component_id in by_component,
|
||||
f"independent release names unknown component {component_id!r}")
|
||||
kind = by_component[component_id]["kind"]
|
||||
require(kind != "app", f"application release {component_id} must go through acceptance")
|
||||
tag = entry.get("tag")
|
||||
require(isinstance(tag, str) and tag.startswith("v"), f"invalid independent tag {tag!r}")
|
||||
version = tag[1:]
|
||||
require(basename_ok(version), f"invalid independent version {version!r}")
|
||||
rid = release_id(component_id, version)
|
||||
if rid in existing:
|
||||
continue
|
||||
source_sha = entry.get("source_sha")
|
||||
index_sha256 = entry.get("index_sha256")
|
||||
ci = entry.get("ci")
|
||||
published_at = entry.get("published_at")
|
||||
require(isinstance(source_sha, str) and SHA.fullmatch(source_sha),
|
||||
f"{component_id}: invalid independent source SHA")
|
||||
require(isinstance(index_sha256, str) and HEX.fullmatch(index_sha256),
|
||||
f"{component_id}: invalid independent evidence digest")
|
||||
require(isinstance(ci, dict) and isinstance(ci.get("url"), str),
|
||||
f"{component_id}: missing independent CI evidence")
|
||||
asset_rows = []
|
||||
archive_ids = []
|
||||
for asset in entry.get("assets") or []:
|
||||
require(isinstance(asset, dict), f"{component_id}: invalid independent asset")
|
||||
name = asset.get("name")
|
||||
require(isinstance(name, str) and BASENAME.fullmatch(name),
|
||||
f"{component_id}: invalid independent asset name")
|
||||
kind_name = asset_kind(name)
|
||||
aid = f"{rid}-{name}"
|
||||
require(ID.fullmatch(aid), f"{component_id}: invalid independent asset id {aid}")
|
||||
row = {
|
||||
"asset_id": aid,
|
||||
"name": name,
|
||||
"size": asset["size"],
|
||||
"sha256": asset["sha256"],
|
||||
"target": asset["target"],
|
||||
"kind": kind_name,
|
||||
"download_url": f"{FORGE}/{entry['repository']}/releases/download/{tag}/{name}",
|
||||
"platform_status": asset_platform(kind_name, asset["target"]),
|
||||
"runtime_requirements": [],
|
||||
"signature_state": "unsigned",
|
||||
}
|
||||
asset_rows.append(row)
|
||||
if kind_name == "archive":
|
||||
archive_ids.append(aid)
|
||||
require(archive_ids, f"{component_id}: independent release has no archive asset")
|
||||
require(asset_rows, f"{component_id}: independent release has no assets")
|
||||
rows.append({
|
||||
"release_id": rid,
|
||||
"component_id": component_id,
|
||||
"version": version,
|
||||
"tag": tag,
|
||||
"channel": channel_of(version),
|
||||
"source_sha": source_sha,
|
||||
"published_at": utc_z(published_at, "published_at"),
|
||||
"release_url": f"{FORGE}/{entry['repository']}/releases/tag/{tag}",
|
||||
"evidence_url": f"{FORGE}/{entry['repository']}/releases/download/{tag}/release-evidence.json",
|
||||
"evidence_sha256": index_sha256,
|
||||
"distribution_state": "available",
|
||||
"integration_state": "pending",
|
||||
"assets": asset_rows,
|
||||
})
|
||||
refs.update({rows[-1]["release_url"], rows[-1]["evidence_url"], ci["url"]})
|
||||
return rows
|
||||
|
||||
|
||||
def basename_ok(value: str) -> bool:
|
||||
return BASENAME.fullmatch(value) is not None
|
||||
|
||||
|
||||
def build_snapshot(acceptances: list[dict], report: dict, components: list[dict],
|
||||
generated_at: str) -> dict:
|
||||
generated_at: str, *, include_independent: bool = False,
|
||||
independent_repositories: set[str] | None = None) -> dict:
|
||||
"""Merge one or more accepted products into the single public snapshot."""
|
||||
by_component = {component["id"]: component for component in components}
|
||||
app_components = {component["id"] for component in components if component["kind"] == "app"}
|
||||
@@ -478,6 +569,12 @@ def build_snapshot(acceptances: list[dict], report: dict, components: list[dict]
|
||||
"offer_id": offer_id,
|
||||
})
|
||||
|
||||
if include_independent:
|
||||
independent = independent_rows(
|
||||
report, components, rows, set(independent_repositories or set()), refs)
|
||||
for row in independent:
|
||||
rows[row["release_id"]] = row
|
||||
|
||||
snapshot = {
|
||||
"schema_version": SNAPSHOT_SCHEMA_VERSION,
|
||||
"snapshot_revision": None, # filled by write_outputs
|
||||
@@ -535,6 +632,10 @@ def main(argv: list[str]) -> int:
|
||||
parser.add_argument("--generated-at", required=True)
|
||||
parser.add_argument("--verified-at", default=None)
|
||||
parser.add_argument("--revision", type=int, required=True)
|
||||
parser.add_argument("--include-independent-releases", action="store_true",
|
||||
help="also expose verified component releases that root did not accept")
|
||||
parser.add_argument("--independent-repository", action="append", default=[],
|
||||
help="owner/name whose verified non-accepted releases become pending rows (repeatable)")
|
||||
parser.add_argument("--out-dir", type=Path, required=True)
|
||||
args = parser.parse_args(argv)
|
||||
|
||||
@@ -559,7 +660,10 @@ def main(argv: list[str]) -> int:
|
||||
graph = {row["id"]: {**row, "sha": pins.get(row["id"])} for row in components}
|
||||
validated = [(acceptance, validate(acceptance, report, graph, pins))
|
||||
for acceptance in acceptances]
|
||||
snapshot = build_snapshot(validated, report, components, args.generated_at)
|
||||
snapshot = build_snapshot(
|
||||
validated, report, components, args.generated_at,
|
||||
include_independent=args.include_independent_releases,
|
||||
independent_repositories=set(args.independent_repository or []))
|
||||
result = write_outputs(args.out_dir, snapshot, args.revision, verified_at)
|
||||
except ProjectionError as error:
|
||||
print(f"project-release: {error}", file=sys.stderr)
|
||||
|
||||
@@ -327,7 +327,8 @@ class Fixture:
|
||||
|
||||
|
||||
def run_projection(tmp: Path, fixture: Fixture, record, report: dict,
|
||||
revision: int = 0, out_name: str = "out", generated_at: str = "2026-12-02T06:30:00Z"):
|
||||
revision: int = 0, out_name: str = "out",
|
||||
generated_at: str = "2026-12-02T06:30:00Z", extra_args: list[str] | None = None):
|
||||
records = record if isinstance(record, list) else [record]
|
||||
acceptance_args: list[str] = []
|
||||
for index, item in enumerate(records):
|
||||
@@ -344,6 +345,7 @@ def run_projection(tmp: Path, fixture: Fixture, record, report: dict,
|
||||
"--generated-at", generated_at,
|
||||
"--revision", str(revision),
|
||||
"--out-dir", str(out),
|
||||
*(extra_args or []),
|
||||
], capture_output=True, text=True)
|
||||
return result, out
|
||||
|
||||
@@ -414,6 +416,38 @@ class ProjectReleaseTests(unittest.TestCase):
|
||||
self.assertEqual((out_b / "current.json").read_bytes(),
|
||||
(out_a / "current.json").read_bytes())
|
||||
|
||||
def test_projects_verified_independent_release_as_pending(self) -> None:
|
||||
independent_sha = "4" * 40
|
||||
independent = release_entry(
|
||||
component="std-data", path="stdlib/data", repository="cflmy/marqdo-std-data",
|
||||
tag="v0.1.1", source_sha=independent_sha, accepted_sha=independent_sha,
|
||||
index_sha256="e" * 64,
|
||||
ci={"pipeline_number": 27, "url": "https://ci.cflmy.cn/repos/10/pipeline/27",
|
||||
"source_sha": independent_sha},
|
||||
assets=[{"name": "marqdo-std-data-0.1.1-source.tar.gz", "size": 6763,
|
||||
"target": "source", "sha256": "9" * 64}],
|
||||
dependencies=[],
|
||||
published_at="2026-12-03T00:20:00+00:00",
|
||||
)
|
||||
report = self.report()
|
||||
report["results"].append(independent)
|
||||
result, out = run_projection(
|
||||
self.tmp, self.fixture, self.acceptance(), report,
|
||||
extra_args=["--include-independent-releases",
|
||||
"--independent-repository", "cflmy/marqdo-std-data"])
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
pointer = json.loads((out / "current.json").read_text(encoding="utf-8"))
|
||||
snapshot = json.loads((out / pointer["snapshot"].removeprefix("/data/")).read_text(encoding="utf-8"))
|
||||
rows = {row["release_id"]: row for row in snapshot["releases"]}
|
||||
self.assertIn("std-data-0.1.1", rows)
|
||||
pending = rows["std-data-0.1.1"]
|
||||
self.assertEqual(pending["integration_state"], "pending")
|
||||
self.assertEqual(pending["distribution_state"], "available")
|
||||
self.assertEqual(pending["channel"], "stable")
|
||||
self.assertEqual([offer["product"] for offer in snapshot["offers"]], ["marqdo"])
|
||||
self.assertEqual([item["offer_id"] for item in snapshot["recommendations"]],
|
||||
[snapshot["offers"][0]["offer_id"]])
|
||||
|
||||
def test_rejects_source_sha_not_pinned_by_root(self) -> None:
|
||||
record = self.acceptance()
|
||||
record["components"][0]["release"]["source_sha"] = "9" * 40
|
||||
|
||||
Reference in new issue
Block a user