diff --git a/docs/product/release-readiness.md b/docs/product/release-readiness.md index 8f94298765..cc11f1419a 100644 --- a/docs/product/release-readiness.md +++ b/docs/product/release-readiness.md @@ -281,10 +281,12 @@ main 运行时发布器在任何远端写入前,将下载的安装资格与源 证据缺失、失败或不匹配时,保留已有发布及渠道。此工程资格不证明模型结果、完整成本收益 或 C1 默认采用资格。 -New runtime descriptors carry the supported `default_contract`. Qualification -observes the installed candidate's ordinary quota writer in an isolated original -Goal with context delivery off; the publisher requires that observation to match -the immutable descriptor. Desktop packaging observes its actual archived source +New runtime descriptors carry the observed, supported `default_contract`. +The builder probes the committed runtime before writing a channel descriptor +or replacing existing output. Qualification checks the installed candidate's +ordinary quota writer in an isolated original Goal with context delivery off. +The publisher requires that observation to match the immutable descriptor. +Desktop packaging observes its actual archived source through the same probe and support validator. Runtime updates reject an unsupported declared contract before downloading or activating it, and bind the archive's contract identity to its metadata. Historical v1 descriptors remain readable. @@ -295,8 +297,9 @@ met. Installation checks or a new boolean cannot extend that scope. Explicit complete-contract opt-in, context-delivery configuration and historical recovery retain their existing owners; this boundary does not switch an installed writer. -新 runtime 描述符携带支持的 `default_contract`。资格检查在隔离的原始 Goal 中,关闭 -上下文传输后观察安装候选的普通 quota writer;发布器要求该观察与不可变描述符一致。 +新 runtime 描述符记录实际观测到且受支持的 `default_contract`。构建器在写入渠道描述符 +或替换已有制品之前探测已提交的 runtime。安装资格检查在隔离的原始 Goal 中关闭 +上下文传输后再次观察普通 quota writer。发布器要求安装后的观察与不可变描述符一致。 桌面打包通过相同探测与支持校验器检查实际归档源码。runtime 更新在下载或激活前拒绝 未支持的声明契约,并核对归档身份与元数据中的契约;历史 v1 描述符保留读取兼容。 当前分发范围是已有 `quota_packet` writer;完整契约默认切换在满足原 RFC §9 同单会话 diff --git a/scripts/runtime_artifact.py b/scripts/runtime_artifact.py index 7735dc316d..5097b35f88 100644 --- a/scripts/runtime_artifact.py +++ b/scripts/runtime_artifact.py @@ -18,12 +18,19 @@ import subprocess import sys import tarfile +import tempfile import tomllib ROOT = Path(__file__).resolve().parents[1] sys.path.insert(0, str(ROOT)) from loopx.presentation.chat_bundle import source_digest, validate_bundle # noqa: E402 -from loopx.cli_commands.update_artifact import PUBLIC_DEFAULT_CONTRACT, RUNTIME_ARTIFACT_SCHEMA_VERSION, validate_manifest # noqa: E402 +from loopx.cli_commands.update_artifact import ( # noqa: E402 + RUNTIME_ARTIFACT_SCHEMA_VERSION, + extract_artifact, + validate_default_contract, + validate_manifest, +) +from scripts.qualify_runtime_artifact import observe_default_contract # noqa: E402 PATHS = ("loopx", "scripts", "skills", "docs", "man", "examples", "apps/presentation", ".github", "README.md", "LICENSE", "NOTICE", "LICENSE-MIT", "pyproject.toml", "setup.py", "MANIFEST.in") @@ -41,6 +48,19 @@ MEDIA_SUFFIXES = {".png", ".jpg", ".jpeg", ".gif", ".webp", ".mp4", ".mov", ".webm"} +def _qualified_default_contract(root: Path, revision: str) -> dict: + with tempfile.TemporaryDirectory(prefix="loopx-runtime-contract-") as temporary: + staging = Path(temporary) + archive = staging / "source.tar.gz" + subprocess.run( + ["git", "archive", "--format=tar.gz", f"--output={archive}", revision, "loopx", "scripts"], + cwd=root, + check=True, + ) + source = extract_artifact(archive, staging / "source") + return validate_default_contract(observe_default_contract(source)) + + def build(root: Path, output: Path, *, repository: str, channel: str) -> dict: revision = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root, text=True).strip() manifest = validate_bundle(root / "loopx/web/chat", source_root=root) @@ -50,6 +70,9 @@ def build(root: Path, output: Path, *, repository: str, channel: str) -> dict: committed = subprocess.check_output(["git", "show", f"{revision}:{name}"], cwd=root) if source_digest(Path(name), committed) != digest: raise ValueError(f"Frontend input differs from committed source: {name}") + # A channel descriptor must describe the committed runtime. The installation + # qualification independently checks the default again after installation. + default_contract = _qualified_default_contract(root, revision) output.mkdir(parents=True, exist_ok=True) filename = f"loopx-runtime-{revision}.tar.gz" optional_name = f"loopx-resources-{revision}.tar.gz" @@ -95,7 +118,7 @@ def build(root: Path, output: Path, *, repository: str, channel: str) -> dict: inventory["runtime"].append({"path": member.name, "bytes": len(content), "sha256": hashlib.sha256(content).hexdigest()}) identity = json.dumps({"schema_version": RUNTIME_ARTIFACT_SCHEMA_VERSION, "source_revision": revision, - "package_version": version, "default_contract": PUBLIC_DEFAULT_CONTRACT}).encode() + "package_version": version, "default_contract": default_contract}).encode() member = tarfile.TarInfo("runtime-artifact.json") member.size, member.mode = len(identity), 0o644 runtime.addfile(member, io.BytesIO(identity)) @@ -107,7 +130,7 @@ def build(root: Path, output: Path, *, repository: str, channel: str) -> dict: archive = output / filename result = validate_manifest({"schema_version": RUNTIME_ARTIFACT_SCHEMA_VERSION, "source_revision": revision, "package_version": version, "channel": channel, "size": archive.stat().st_size, - "default_contract": dict(PUBLIC_DEFAULT_CONTRACT), + "default_contract": default_contract, "sha256": hashlib.sha256(archive.read_bytes()).hexdigest(), "urls": [f"https://github.com/{repository}/releases/download/{tag}/{filename}"], "resources": {"filename": optional_name, "size": (output / optional_name).stat().st_size, diff --git a/tests/test_runtime_snapshot_publication.py b/tests/test_runtime_snapshot_publication.py index 1a2d0ca969..5245c1d0c4 100644 --- a/tests/test_runtime_snapshot_publication.py +++ b/tests/test_runtime_snapshot_publication.py @@ -9,6 +9,7 @@ import shlex import subprocess import sys +import tarfile import pytest import yaml @@ -298,7 +299,8 @@ def test_failed_view_does_not_replace_an_existing_release(publication, tag): @pytest.mark.parametrize("channel", ["main", "stable"]) -def test_builder_freezes_correct_archive_url_before_publication(tmp_path, monkeypatch, channel): +@pytest.mark.parametrize("supported", [True, False], ids=["supported-default", "unqualified-default"]) +def test_builder_qualifies_committed_default_before_writing_artifacts(tmp_path, monkeypatch, channel, supported): from scripts import runtime_artifact as builder root = tmp_path / "source" @@ -310,6 +312,7 @@ def test_builder_freezes_correct_archive_url_before_publication(tmp_path, monkey (path / "fixture.txt").write_text("public fixture", encoding="utf-8") else: path.write_text("public fixture", encoding="utf-8") + (root / "scripts/install-local.sh").write_text("#!/bin/sh\n", encoding="utf-8") (root / "pyproject.toml").write_text('[project]\nversion = "1.2.3"\n', encoding="utf-8") bundle = root / "loopx/web/chat" bundle.mkdir(parents=True) @@ -320,17 +323,43 @@ def test_builder_freezes_correct_archive_url_before_publication(tmp_path, monkey for args in (["init", "--quiet"], ["add", "--", *builder.PATHS], ["commit", "--quiet", "-m", "Synthetic runtime"]): subprocess.run(["git", *args], cwd=root, env=env, check=True, capture_output=True, timeout=15) revision = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root, text=True, encoding="utf-8").strip() + (root / "loopx/fixture.txt").write_text("uncommitted runtime", encoding="utf-8") # Frontend qualification is independent; archive and descriptor creation # still execute through the real committed-source builder below. monkeypatch.setattr(builder, "validate_bundle", lambda *_a, **_kw: { "source_revision": revision, "source_files": {}, "files": {"index.html": "fixture"}}) + + def observe(source: Path) -> dict: + assert source != root + assert (source / "loopx/fixture.txt").read_text(encoding="utf-8") == "public fixture" + if supported: + return dict(PUBLIC_DEFAULT_CONTRACT) + return {"surface": "complete_turn", "schema_version": "loopx_turn_envelope_v1", + "interaction_schema_version": "loopx_interaction_contract_v0"} + + monkeypatch.setattr(builder, "observe_default_contract", observe) output = tmp_path / "runtime" + if not supported: + output.mkdir() + previous = output / "loopx-runtime.json" + previous.write_bytes(b"previous descriptor") + with pytest.raises(ValueError, match="unqualified for public adoption"): + builder.build(root, output, repository="example/loopx", channel=channel) + assert list(output.iterdir()) == [previous] + assert previous.read_bytes() == b"previous descriptor" + return + descriptor = builder.build(root, output, repository="example/loopx", channel=channel) tag = f"runtime-main-{revision}" if channel == "main" else "v1.2.3" assert descriptor["urls"] == [f"https://github.com/example/loopx/releases/download/{tag}/loopx-runtime-{revision}.tar.gz"] assert json.loads((output / "loopx-runtime.json").read_text(encoding="utf-8")) == descriptor - assert (output / f"loopx-runtime-{revision}.tar.gz").stat().st_size == descriptor["size"] + runtime = output / f"loopx-runtime-{revision}.tar.gz" + assert runtime.stat().st_size == descriptor["size"] assert descriptor["default_contract"] == PUBLIC_DEFAULT_CONTRACT + with tarfile.open(runtime, "r:gz") as archive: + identity = archive.extractfile("runtime-artifact.json") + assert identity is not None + assert json.load(identity)["default_contract"] == descriptor["default_contract"] def test_release_probe_observes_real_default_without_model_or_active_goal():