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
30 changes: 22 additions & 8 deletions apps/desktop/loopx-control-plane/src-tauri/src/macos_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use flate2::read::GzDecoder;
use serde_json::Value;
use tauri_plugin_updater::Update;

const PUBLIC_DEFAULT_CONTRACT: &str =
const ARTIFACT_CONTRACT_POLICY: &str =
include_str!("../../../../../loopx/cli_commands/public_default_contract.json");

/// Read the publisher's observed contract inside the signature-verified bytes
Expand All @@ -31,7 +31,8 @@ pub(crate) fn qualify_candidate(
}
let invalid = "runtime_bundle_invalid";
let unavailable = "update_platform_unavailable";
let supported: Value = serde_json::from_str(PUBLIC_DEFAULT_CONTRACT).map_err(|_| invalid)?;
let policy: Value = serde_json::from_str(ARTIFACT_CONTRACT_POLICY).map_err(|_| invalid)?;
let supported = policy["readable_contracts"].as_array().ok_or(invalid)?;
let identity_path = Path::new("LoopX.app/Contents/Resources/runtime/identity.json");
let mut archive = tar::Archive::new(GzDecoder::new(Cursor::new(verified_bytes)));
let mut qualified = false;
Expand All @@ -46,7 +47,11 @@ pub(crate) fn qualify_candidate(
let mut raw = Vec::new();
entry.read_to_end(&mut raw).map_err(|_| invalid)?;
let identity = crate::bundled_runtime::parse_identity(&raw)?;
if identity["default_contract"] != supported {
let observed = identity
.get("default_contract")
.filter(|contract| contract.is_object())
.ok_or(unavailable)?;
if !supported.contains(observed) {
return Err(unavailable.into());
}
qualified = true;
Expand Down Expand Up @@ -194,7 +199,7 @@ mod tests {
Some(serde_json::json!({"surface": "unknown"})),
Some(serde_json::json!({
"surface": "complete_turn",
"schema_version": "loopx_turn_envelope_v1",
"schema_version": "loopx_turn_envelope_v0",
"interaction_schema_version": "loopx_interaction_contract_v0"
})),
];
Expand All @@ -216,10 +221,19 @@ mod tests {
assert!(qualify_candidate("stable", "2.3.0", &bytes).is_ok());
}

identity["default_contract"] = serde_json::from_str(PUBLIC_DEFAULT_CONTRACT).unwrap();
fs::write(identity_path, identity.to_string()).unwrap();
let bytes = archive(&candidate);
crate::prepared_update::save(&cache, "main", version, "unused", &bytes).unwrap();
for (surface, schema_version) in [
("quota_packet", None),
("complete_turn", Some("loopx_turn_envelope_v1")),
] {
identity["default_contract"] = serde_json::json!({
"surface": surface,
"schema_version": schema_version,
"interaction_schema_version": "loopx_interaction_contract_v0"
});
fs::write(&identity_path, identity.to_string()).unwrap();
let bytes = archive(&candidate);
crate::prepared_update::save(&cache, "main", version, "unused", &bytes).unwrap();
}
let pointer = fs::read(cache.join("prepared.json")).unwrap();
assert!(crate::prepared_update::save(&cache, "main", version, "unused", b"bad").is_err());
assert_eq!(fs::read(cache.join("prepared.json")).unwrap(), pointer);
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 @@ -157,6 +157,18 @@ When the qualification command itself runs from newer source code, pass a local
snapshot from the older installed CLI with `--installed-doctor-json`; this
option is read-only and accepted only by `update check`.

Runtime artifact readers and the macOS preview updater recognize the exact
`quota_packet` and Complete Turn v1 identities. The publisher still requires
the observed writer to match the single `publication_surface` in the same
contract declaration, currently `quota_packet`. Qualify and publish a
compatible preview on that current writer first. A later C1 release needs its
own writer qualification and supported-Host adoption evidence.

runtime 制品读取器和 macOS 预览更新器识别 `quota_packet` 与 Complete Turn v1 的
精确身份。发布器仍要求实际 writer 匹配同一声明中的唯一 `publication_surface`,
当前为 `quota_packet`。先用当前 writer 验证并发布兼容预览。后续 C1 发布需具备自己
的 writer 资格与受支持 Host 的采用证据。

## Named Version Contract

LoopX releases are tagged and built from GitHub. The release workflow
Expand Down
16 changes: 13 additions & 3 deletions loopx/cli_commands/public_default_contract.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"surface": "quota_packet",
"schema_version": null,
"interaction_schema_version": "loopx_interaction_contract_v0"
"publication_surface": "quota_packet",
"readable_contracts": [
{
"surface": "quota_packet",
"schema_version": null,
"interaction_schema_version": "loopx_interaction_contract_v0"
},
{
"surface": "complete_turn",
"schema_version": "loopx_turn_envelope_v1",
"interaction_schema_version": "loopx_interaction_contract_v0"
}
]
}
21 changes: 14 additions & 7 deletions loopx/cli_commands/update_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@
from ..capabilities.issue_fix.repository_snapshot import _REPO_PATTERN as REPOSITORY_PATTERN

RUNTIME_ARTIFACT_SCHEMA_VERSION = "loopx_runtime_artifact_v1"
PUBLIC_DEFAULT_CONTRACT = json.loads(
_ARTIFACT_CONTRACT_POLICY = json.loads(
Path(__file__).with_name("public_default_contract.json").read_text(encoding="utf-8")
)
_READABLE_DEFAULT_CONTRACTS = _ARTIFACT_CONTRACT_POLICY["readable_contracts"]
PUBLIC_DEFAULT_CONTRACT, = (
contract for contract in _READABLE_DEFAULT_CONTRACTS
if contract["surface"] == _ARTIFACT_CONTRACT_POLICY["publication_surface"]
)
SHA = re.compile(r"[0-9a-f]{40}")
MAX_MANIFEST = 256 * 1024
MAX_ARCHIVE = 256 * 1024 * 1024
Expand Down Expand Up @@ -64,11 +69,11 @@ def standalone_source() -> str:
source = source.replace(old, "\n" + binding + "\n", 1)
# The public installer is one file, so embed the policy that the Python
# publishers and the native updater read from the distribution contract.
binding_start = source.index("\nPUBLIC_DEFAULT_CONTRACT = ")
binding_end = source.index("\nSHA = ", binding_start)
binding_start = source.index("\n_ARTIFACT_CONTRACT_POLICY = ")
binding_end = source.index("\n_READABLE_DEFAULT_CONTRACTS = ", binding_start)
return (
source[:binding_start]
+ f"\nPUBLIC_DEFAULT_CONTRACT = {PUBLIC_DEFAULT_CONTRACT!r}"
+ f"\n_ARTIFACT_CONTRACT_POLICY = {_ARTIFACT_CONTRACT_POLICY!r}"
+ source[binding_end:]
)

Expand Down Expand Up @@ -141,10 +146,12 @@ def validate_manifest(value: dict[str, Any], *, revision: str | None = None) ->
raise ValueError("Runtime artifact has no bounded download sources")
for url in urls:
safe_url(url)
# Historical v1 snapshots remain readable. Newly produced artifacts and
# the publisher require the observed contract; absence is not qualification.
# Readers can cross a version boundary in either direction. Publication
# still checks the observed writer against the single declared default.
if "default_contract" in value:
validate_default_contract(value["default_contract"])
contract = value["default_contract"]
if not isinstance(contract, dict) or contract not in _READABLE_DEFAULT_CONTRACTS:
raise ValueError("Unsupported runtime default contract in artifact metadata")
return dict(value)


Expand Down
19 changes: 16 additions & 3 deletions tests/test_update_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def test_exported_bootstrap_validates_metadata_without_an_installed_package(tmp_
assert module['validate_manifest'](value)==value
profile = module['PUBLIC_DEFAULT_CONTRACT']
assert module['validate_manifest']({**value, 'default_contract':profile})['default_contract']==profile
c1 = {'surface':'complete_turn','schema_version':'loopx_turn_envelope_v1',
'interaction_schema_version':'loopx_interaction_contract_v0'}
assert module['validate_manifest']({**value, 'default_contract':c1})['default_contract']==c1
try:module['validate_default_contract'](c1)
except ValueError:pass
else:raise AssertionError('reader compatibility promoted the publication default')
for invalid in [None, {}, {'surface':'complete_turn','schema_version':'loopx_turn_envelope_v1'}, {'surface':'unknown'}]:
try:module['validate_manifest']({**value,'default_contract':invalid})
except ValueError:pass
Expand Down Expand Up @@ -98,14 +104,14 @@ def manifest(body: bytes, url: str):


@pytest.mark.parametrize("profile", [None, {}, {"surface": "future"},
{"surface": "complete_turn", "schema_version": "loopx_turn_envelope_v1",
{"surface": "complete_turn", "schema_version": "loopx_turn_envelope_v0",
"interaction_schema_version": "loopx_interaction_contract_v0"}])
def test_unqualified_default_stops_before_download_or_activation(monkeypatch, profile):
descriptor = {**manifest(b"runtime", "https://publisher.invalid/runtime"), "default_contract": profile}
calls = []
monkeypatch.setattr(update, "download_artifact", lambda *_a, **_kw: calls.append("download"))
monkeypatch.setattr(update, "run_installer", lambda *_a, **_kw: calls.append("activate"))
with pytest.raises(ValueError, match="unqualified for public adoption"):
with pytest.raises(ValueError, match="Unsupported runtime default contract"):
update.install_artifact(descriptor, env={}, timeout_seconds=10)
assert calls == []

Expand All @@ -115,12 +121,19 @@ def test_qualified_scope_and_historical_metadata_remain_readable():
assert update.validate_manifest(historical) == historical
current = {**historical, "default_contract": dict(update.PUBLIC_DEFAULT_CONTRACT)}
assert update.validate_manifest(current) == current
c1 = {"surface": "complete_turn", "schema_version": "loopx_turn_envelope_v1",
"interaction_schema_version": "loopx_interaction_contract_v0"}
compatible = {**historical, "default_contract": c1}
assert update.validate_manifest(compatible) == compatible
with pytest.raises(ValueError, match="unqualified for public adoption"):
update.validate_default_contract(c1)


def test_archive_contract_mismatch_stops_before_installer(tmp_path, monkeypatch):
archive = tmp_path / "runtime.tar.gz"
identity = json.dumps({"source_revision": "a" * 40, "package_version": "1.2.3",
"default_contract": {"surface": "complete_turn"}}).encode()
"default_contract": {"surface": "complete_turn", "schema_version": "loopx_turn_envelope_v1",
"interaction_schema_version": "loopx_interaction_contract_v0"}}).encode()
with tarfile.open(archive, "w:gz") as target:
for name, content in [("runtime-artifact.json", identity), ("scripts/install-local.sh", b"exit 99\n")]:
member = tarfile.TarInfo(name)
Expand Down
Loading