Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .github/workflows/runtime-snapshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,39 @@ jobs:
shell: bash
run: |
set -euo pipefail
revision="$(python -c 'import json; print(json.load(open("runtime/loopx-runtime.json"))["source_revision"])')"
# Validate the downloaded qualification before any remote mutation.
# Successful installation alone does not qualify outcome/cost claims.
revision="$(python - <<'PY'
import hashlib
import json
from pathlib import Path
import re
root = Path("runtime")
manifest_bytes = (root / "loopx-runtime.json").read_bytes()
manifest = json.loads(manifest_bytes)
revision = manifest["source_revision"]
if not isinstance(revision, str) or not re.fullmatch(r"[0-9a-f]{40}", revision):
raise SystemExit("Invalid runtime source revision")
qualification = json.loads((root / f"qualification-{revision}.json").read_bytes())
checks = ("ok", "clean_install", "upgrade", "doctor", "skills", "frontend_bundle_contract",
"frontend_http", "no_frontend_build_tools", "license_notices", "activation_failure_restored")
if any(qualification.get(check) is not True for check in checks):
raise SystemExit("Runtime installation qualification is missing or failed")
if manifest["channel"] != "main" or any(qualification.get(key) != manifest[key]
for key in ("source_revision", "channel", "sha256")):
raise SystemExit("Runtime qualification does not match the candidate")
archive = root / f"loopx-runtime-{revision}.tar.gz"
with archive.open("rb") as stream:
digest = hashlib.file_digest(stream, "sha256").hexdigest()
if type(manifest["size"]) is not int or type(qualification.get("bytes")) is not int or (
archive.stat().st_size != manifest["size"] or qualification["bytes"] != manifest["size"]
or digest != manifest["sha256"]):
raise SystemExit("Qualified runtime bytes differ from the candidate")
if (root / f"loopx-runtime-{revision}.json").read_bytes() != manifest_bytes:
raise SystemExit("Immutable runtime metadata differs from the channel candidate")
print(revision)
PY
)"
# Keep each immutable snapshot below GitHub's per-release asset cap.
# The existing channel release retains its historical assets and URL.
tag="runtime-main-${revision}"
Expand Down
12 changes: 12 additions & 0 deletions docs/product/release-readiness.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,18 @@ Reserve `qualification.json` for the workflow's attested runtime qualification.
Use `RELEASE-QUALIFICATION.json` for a separately maintained release overview;
GitHub Release asset names must also be unique when compared ignoring case.

The main runtime publisher verifies its downloaded installation qualification
against the source revision, channel, archive digest and byte count before any
remote write. Every installation/recovery check must pass, and immutable metadata
must match the candidate channel metadata. Missing, failed or mismatched evidence
leaves the existing releases and channel untouched. This engineering qualification
does not establish model outcomes, complete-cost benefit or C1 default adoption.

main 运行时发布器在任何远端写入前,将下载的安装资格与源码提交、渠道、归档摘要及
字节数逐项核对。安装和恢复检查必须全部通过,不可变元数据必须与候选渠道元数据一致。
证据缺失、失败或不匹配时,保留已有发布及渠道。此工程资格不证明模型结果、完整成本收益
或 C1 默认采用资格。

For a browser-fixture error discovered after an immutable tag was published,
maintainers may dispatch the release workflow from reviewed tooling with
`tag` set to that existing release and `browser_fixture_commit` set to a full,
Expand Down
1 change: 1 addition & 0 deletions scripts/qualify_runtime_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def read(*args):
env={**env, "PYTHONPATH": str(release)}, cwd=release,
check=True, timeout=15, stdout=subprocess.DEVNULL)
return {"ok": True, "source_revision": manifest["source_revision"], "bytes": manifest["size"],
"channel": manifest["channel"], "sha256": manifest["sha256"],
"clean_install": results[0] == 0, "upgrade": results[1] == 0,
"doctor": True, "skills": True, "frontend_bundle_contract": True, "frontend_http": True,
"no_frontend_build_tools": True, "license_notices": True, "activation_failure_restored": True}
Expand Down
49 changes: 47 additions & 2 deletions tests/test_runtime_snapshot_publication.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import hashlib
import json
import os
from pathlib import Path
Expand Down Expand Up @@ -88,10 +89,18 @@ def publication(tmp_path):
runtime = tmp_path / "runtime"
runtime.mkdir()
for stem, suffix in (("loopx-runtime", ".tar.gz"), ("loopx-resources", ".tar.gz"),
("runtime-inventory", ".json"), ("qualification", ".json")):
("runtime-inventory", ".json")):
(runtime / f"{stem}-{REVISION}{suffix}").write_bytes(f"{stem}:immutable".encode())
manifest = json.dumps({"source_revision": REVISION, "urls": [
archive = runtime / f"loopx-runtime-{REVISION}.tar.gz"
manifest = json.dumps({"source_revision": REVISION, "channel": "main",
"size": archive.stat().st_size, "sha256": hashlib.sha256(archive.read_bytes()).hexdigest(), "urls": [
f"https://github.com/example/loopx/releases/download/{SNAPSHOT}/loopx-runtime-{REVISION}.tar.gz"]})
qualification = {"ok": True, "source_revision": REVISION, "channel": "main",
"bytes": archive.stat().st_size, "sha256": hashlib.sha256(archive.read_bytes()).hexdigest(),
"clean_install": True, "upgrade": True, "doctor": True, "skills": True,
"frontend_bundle_contract": True, "frontend_http": True,
"no_frontend_build_tools": True, "license_notices": True, "activation_failure_restored": True}
(runtime / f"qualification-{REVISION}.json").write_text(json.dumps(qualification), encoding="utf-8")
(runtime / "loopx-runtime.json").write_text(manifest, encoding="utf-8")
(runtime / f"loopx-runtime-{REVISION}.json").write_text(manifest, encoding="utf-8")
assets = {f"historical-{i}": b"historical".hex() for i in range(999)}
Expand Down Expand Up @@ -121,6 +130,42 @@ def publish(root):
capture_output=True, text=True, encoding="utf-8", timeout=30, check=False)


@pytest.mark.parametrize("failure", [
"missing", "invalid_json", "failed", "incomplete", "wrong_revision", "wrong_channel",
"wrong_size", "wrong_digest", "archive_changed", "manifest_changed", "frozen_manifest_changed", "truthy_status",
])
def test_unqualified_runtime_never_changes_remote_state(publication, failure):
qualification = publication / "runtime" / f"qualification-{REVISION}.json"
record = json.loads(qualification.read_text(encoding="utf-8"))
if failure == "missing":
qualification.unlink()
elif failure == "invalid_json":
qualification.write_text("{", encoding="utf-8")
elif failure == "frozen_manifest_changed":
(publication / "runtime" / f"loopx-runtime-{REVISION}.json").write_text("{}", encoding="utf-8")
elif failure in {"archive_changed", "manifest_changed"}:
if failure == "archive_changed":
(publication / "runtime" / f"loopx-runtime-{REVISION}.tar.gz").write_bytes(b"unqualified bytes")
else:
manifest = publication / "runtime/loopx-runtime.json"
data = json.loads(manifest.read_text(encoding="utf-8"))
data["channel"] = "stable"
manifest.write_text(json.dumps(data), encoding="utf-8")
else:
if failure == "incomplete":
del record["activation_failure_restored"]
else:
field, value = {"failed": ("ok", False), "wrong_revision": ("source_revision", PREVIOUS),
"wrong_channel": ("channel", "stable"), "wrong_size": ("bytes", 1),
"wrong_digest": ("sha256", "0" * 64), "truthy_status": ("clean_install", "true")}[failure]
record[field] = value
qualification.write_text(json.dumps(record), encoding="utf-8")
before = read_state(publication)
result = publish(publication)
assert result.returncode != 0
assert read_state(publication) == before


def test_full_legacy_release_keeps_history_and_publishes_then_retries(publication):
history = read_state(publication)["releases"]["runtime-main"]["assets"].copy()
result = publish(publication)
Expand Down
Loading