diff --git a/.woodpecker/main.yml b/.woodpecker/main.yml index 3849559..5891b37 100644 --- a/.woodpecker/main.yml +++ b/.woodpecker/main.yml @@ -50,7 +50,7 @@ steps: depends_on: [test, minimum-rust] commands: - apt-get update - - apt-get install -y --no-install-recommends ca-certificates git openssl python3 build-essential + - apt-get install -y --no-install-recommends ca-certificates git openssl python3 python3-jsonschema build-essential # Release archives must ship both binaries: the provider worker is the # only supported transport and resolution is a sibling-of-CLI lookup. - cargo build --release --locked -p marqdo-cli -p marqdo-provider-worker diff --git a/COMPATIBILITY.md b/COMPATIBILITY.md index 3069e13..a860c7d 100644 --- a/COMPATIBILITY.md +++ b/COMPATIBILITY.md @@ -62,7 +62,7 @@ evidence: [`docs/evidence/2026-11-22-rfc-ext-0003-core-hardcoding.md`](docs/evid | Release archive must ship the verified `stdlib/` | **Delivery requirement.** Archive contains `stdlib.json` + all modules and `RELEASE_INFO.json` carries its name/version/tree/alias digests/count/files. Removing or tampering with it fails closed; release builds do not fall back to the build-machine source path. | | Core resource kinds enforced on every registration path (H-04) | Provider name or declared kind equal to `stdio/file/tcp/tls/udp/tcp-listener` is rejected with `ext.manifest_invalid` (CLI) / `ResourceUnsupported` (host) before registration. No provider may shadow a core kind. | | `resource_request` operation ownership (H-03) | New domain/business operations are forbidden in the core: ship a pure `.mq.md` package, ABI export or Provider. The exact reviewed allowlist is pinned by `architecture_boundaries.rs`; see `docs/architecture/resource-operations.md`. | -| Heading Annotations v1 (H-05/H-07) | **Proposed, not implemented.** This build still rejects unknown `@foo` with `sem.invalid_mode_marker`; no annotation manifest, `annotation.unknown`, Analysis v3 or sidecar exists yet. Target `3.1.x`; ADR-0060 and `spec/heading-annotations-v1.md`. | +| Heading Annotations v1 (H-05/H-07) | **Proposed, not implemented.** This build still rejects unknown `@foo` with `sem.invalid_mode_marker`; no annotation manifest, `annotation.unknown` or heading annotations projection exists yet. Target `3.1.x`; ADR-0060 and `spec/heading-annotations-v1.md`. | | Foreign removal F-B (H-02) | **Deferred, not claimed.** The one-shot permission-gated `foreign.*` primitive remains (F-A); its grants/digest/timeout/wire/output negatives are unchanged and must not be skipped. ADR-0063 and `spec/foreign.md` §8. | ## Structured control flow (RFC-CTRL-0005, unreleased) diff --git a/docs/releasing.md b/docs/releasing.md index d148262..8972bb5 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -128,7 +128,10 @@ artifacts so the examples run without a compiler) and `tests/consumers/`. `RELEASE_INFO.json` records the stdlib `name`, `version`, `tree_digest`, `aliases_digest`, `file_count` and `files`. `package.py` recomputes both digests with the same canonical algorithm as the runtime and refuses to package a mismatch -with `stdlib/stdlib.json` (RFC-EXT-0003 H-08 / T-PKG-04). The bundled stdlib is a +with `stdlib/stdlib.json` (RFC-EXT-0003 H-08 / T-PKG-04). +The `protocols.analysis` field identifies the default Analysis major. +`protocols.analysis_versions` lists all majors the archive can emit. +The archive smoke exercises a published example and a consumer for each major. The bundled stdlib is a runtime requirement, not a build-machine side effect: a release binary must never fall back to the compile-time source path. @@ -147,7 +150,7 @@ python3 tools/release/smoke.py \ It verifies the `.sha256`, `RELEASE_INFO.json`/`SOURCE_SHA`, both stdlib digests against `stdlib/stdlib.json` and the staged tree, offline -`--version`/`--help`, `check`/`run`/`call`, lock/sync, Analysis v2 and Trace v2 +`--version`/`--help`, `check`/`run`/`call`, lock/sync, Analysis v2/v3 and Trace v2 consumers, Tool install/dispatch, native + worker plugin transports, a foreign kernel, Resource Provider v2 through the shipped worker (positive, unauthorized and missing-helper fail-closed), the pure math package and optional diff --git a/tools/ci/test_release_archive.py b/tools/ci/test_release_archive.py index 1189b04..f7478d4 100644 --- a/tools/ci/test_release_archive.py +++ b/tools/ci/test_release_archive.py @@ -8,7 +8,9 @@ compile-time source path. from __future__ import annotations +import contextlib import importlib.util +import io import json import unittest from pathlib import Path @@ -66,6 +68,18 @@ class ReleaseArchiveContractTest(unittest.TestCase): self.assertIn('"stdlib": stdlib_info', source) self.assertIn("verify_stdlib()", source) + def test_archive_analysis_metadata_preserves_default_and_declares_each_major(self) -> None: + self.smoke.verify_analysis_metadata({"analysis": 2, "analysis_versions": [2, 3]}) + for malformed in ( + {"analysis": 3, "analysis_versions": [2, 3]}, + {"analysis": 2, "analysis_versions": [2]}, + {"analysis": 2, "analysis_versions": [2, 3, 4]}, + {"analysis": 2}, + ): + with self.subTest(protocols=malformed), contextlib.redirect_stderr(io.StringIO()): + with self.assertRaises(SystemExit): + self.smoke.verify_analysis_metadata(malformed) + def test_release_discovery_does_not_fall_back_to_the_source_tree(self) -> None: source = (ROOT / "crates/cli/src/stdlib.rs").read_text(encoding="utf-8") fallback = source.index("CARGO_MANIFEST_DIR") diff --git a/tools/release/cold-install.sh b/tools/release/cold-install.sh index 7802338..f92d108 100644 --- a/tools/release/cold-install.sh +++ b/tools/release/cold-install.sh @@ -36,6 +36,9 @@ docker run --rm --network none --user 65534:65534 \ test -x ./marqdo-provider-worker ./marqdo run examples/hello.mq.md | grep -F "你好,Marqdo" ./marqdo check examples/multi-module/index.mq.md --emit /tmp/analysis.json + ./marqdo check examples/control-flow.mq.md --emit /tmp/control-analysis.json + grep -Eq "\"schema_version\"[[:space:]]*:[[:space:]]*3" /tmp/control-analysis.json + test "$(./marqdo call examples/control-flow.mq.md main)" = 5 ./marqdo call examples/math-library-demo.mq.md main test "$(./marqdo call examples/factorial.mq.md 阶乘 --arg n=5)" = 120 ./marqdo run tests/consumers/fixtures/execution-events/basic.mq.md \ diff --git a/tools/release/package.py b/tools/release/package.py index 0d04fba..d2f21e3 100644 --- a/tools/release/package.py +++ b/tools/release/package.py @@ -265,6 +265,7 @@ def stage(stage_dir: Path, version: str, source_sha: str, target: str) -> dict: "stdlib": stdlib_info, "protocols": { "analysis": 2, + "analysis_versions": [2, 3], "trace": 2, "execution_events": 1, "tool": 1, diff --git a/tools/release/smoke.py b/tools/release/smoke.py index 40930a2..669be41 100644 --- a/tools/release/smoke.py +++ b/tools/release/smoke.py @@ -3,7 +3,7 @@ Extracts the archive into a fresh temporary directory and exercises the shipped binaries only (never the development source tree): version/help, check/run/call, -lock/sync for a path dependency, Analysis v2 + Trace v2 consumers, Tool +lock/sync for a path dependency, Analysis v2/v3 and Trace v2 consumers, Tool install/dispatch, native and worker plugin transports, foreign kernel, the Provider v2 worker (positive, unauthorized and missing-helper fail-closed), and strict mode when the host genuinely supports it. @@ -16,6 +16,7 @@ from __future__ import annotations import argparse import hashlib +import importlib.util import json import os import shutil @@ -166,6 +167,53 @@ class Runner: fail(f"`marqdo {' '.join(args)} --json` is not JSON: {error}\n{result.stdout}") +ANALYSIS_CASES = { + 2: ("examples/multi-module/index.mq.md", "analysis_consumer.py"), + 3: ("examples/control-flow.mq.md", "analysis_v3_consumer.py"), +} + + +def verify_analysis_metadata(protocols: dict) -> None: + if protocols.get("analysis") != min(ANALYSIS_CASES): + fail("RELEASE_INFO.json does not identify the default Analysis version") + if protocols.get("analysis_versions") != sorted(ANALYSIS_CASES): + fail("RELEASE_INFO.json Analysis versions do not match the archive smoke cases") + + +def run_consumer(install: Path, consumer: str, *paths: Path) -> None: + result = subprocess.run( + [sys.executable, str(install / "tests" / "consumers" / consumer), *map(str, paths)], + capture_output=True, + text=True, + ) + if result.returncode != 0: + fail(f"{consumer} failed:\n{result.stdout}\n{result.stderr}") + + +def verify_analysis_protocols(runner: Runner, install: Path, info: dict) -> None: + protocols = info["protocols"] + verify_analysis_metadata(protocols) + for schema_version, (source, consumer) in ANALYSIS_CASES.items(): + analysis = install / f"analysis-v{schema_version}.json" + trace = install / f"trace-for-analysis-v{schema_version}.json" + runner.run(["check", source, "--emit", str(analysis)]) + document = json.loads(analysis.read_text(encoding="utf-8")) + if document.get("schema") != "marqdo.analysis" or document.get("schema_version") != schema_version: + fail(f"{source} did not produce Analysis v{schema_version}") + if document.get("producer", {}).get("version") != info["product_version"]: + fail("Analysis producer.version does not match the released product version") + runner.run(["run", source, "--trace-file", str(trace)]) + run_consumer(install, consumer, analysis) + run_consumer(install, "trace_consumer.py", analysis, trace) + + # CI installs jsonschema. The standalone smoke can use stdlib Python. + if importlib.util.find_spec("jsonschema") is not None: + run_consumer( + install, "validate_protocols.py", analysis, trace, + install / "examples" / "tool-unknown-name" / "tool.json", + ) + + def main(argv: list[str]) -> int: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--archive", required=True) @@ -241,45 +289,8 @@ def main(argv: list[str]) -> int: if factor != "120": fail(f"factorial call printed {factor!r}, expected 120") - # Static Analysis v2 + Trace v2 through the public consumers. - analysis = install / "analysis.json" - trace = install / "trace.json" - runner.run( - [ - "check", - "examples/multi-module/index.mq.md", - "--emit", - str(analysis), - ] - ) + verify_analysis_protocols(runner, install, info) runner.run(["check", "examples/multi-module/index.mq.md", "--refs"]) - document = json.loads(analysis.read_text(encoding="utf-8")) - if document.get("schema") != "marqdo.analysis" or document.get("schema_version") != 2: - fail("--emit did not write Analysis v2") - if document.get("producer", {}).get("version") != version: - fail("Analysis producer.version does not match the released product version") - runner.run( - [ - "run", - "examples/multi-module/index.mq.md", - "--trace-file", - str(trace), - ] - ) - run_trace = json.loads(trace.read_text(encoding="utf-8")) - if run_trace.get("schema") != "marqdo.trace" or run_trace.get("schema_version") != 2: - fail("--trace-file did not write Trace v2") - for consumer in ("analysis_consumer.py", "trace_consumer.py"): - command = [ - sys.executable, - str(install / "tests" / "consumers" / consumer), - str(analysis), - ] - if consumer == "trace_consumer.py": - command.append(str(trace)) - result = subprocess.run(command, capture_output=True, text=True) - if result.returncode != 0: - fail(f"{consumer} failed:\n{result.stdout}\n{result.stderr}") # Execution Events v1: the released binary's live NDJSON stream, # validated by the independent consumer shipped in the archive. run_help = runner.run(["run", "--help"]).stdout @@ -326,23 +337,6 @@ def main(argv: list[str]) -> int: f"{validate_events.stdout}\n{validate_events.stderr}" ) - validate = subprocess.run( - [ - sys.executable, - str(install / "tests" / "consumers" / "validate_protocols.py"), - str(analysis), - str(trace), - str(install / "examples" / "tool-unknown-name" / "tool.json"), - ], - capture_output=True, - text=True, - ) - if validate.returncode != 0: - if "jsonschema" in validate.stderr and "ModuleNotFoundError" in validate.stderr: - print("smoke: note: jsonschema is not installed; schema validation skipped") - else: - fail(f"validate_protocols.py failed:\n{validate.stdout}\n{validate.stderr}") - # Tool Protocol v1: install and dispatch an independent process. runner.run(["tool", "install", "examples/tool-unknown-name/tool.json"]) listed = runner.run(["tool", "list"]).stdout