feat: adopt marqdo 3.0.0-rc.4 public analysis boundary
This commit is contained in:
1 parent
769550b14b
commit
fe18df6c4b
74 files changed
+7618
-5368
No files matched your search
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/sh
|
||||
# Static P0 gate: the current tree may only describe the current public
|
||||
# Analysis revision 3 / Tool revision 1 boundary. This script intentionally
|
||||
# has no allow-list for src/, tool.json or scripts.
|
||||
set -eu
|
||||
|
||||
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
||||
fail=0
|
||||
|
||||
if command -v rg >/dev/null 2>&1; then
|
||||
search() { rg -n --no-heading "$2" "$1" || true; }
|
||||
else
|
||||
search() { grep -RInE "$2" "$1" || true; }
|
||||
fi
|
||||
|
||||
scan() {
|
||||
label=$1
|
||||
pattern=$2
|
||||
path=$3
|
||||
hits=$(search "$path" "$pattern")
|
||||
if [ -n "$hits" ]; then
|
||||
printf 'FAIL: %s\n%s\n' "$label" "$hits"
|
||||
fail=1
|
||||
fi
|
||||
}
|
||||
|
||||
scan "retired Analysis acceptance" '2 \| 3|version == 2|Analysis v2|需要 2 或 3' "$ROOT/src"
|
||||
scan "retired Tool negotiation" 'compatibility|TOOL_PROTOCOL|PROTOCOL_ANALYSIS|PROTOCOL_TRACE' "$ROOT/src"
|
||||
scan "legacy tool manifest field" '"compatibility"' "$ROOT/tool.json"
|
||||
scan "retired version branches" 'schema_version == 2|match .*schema_version' "$ROOT/src/model"
|
||||
scan "silent parser downgrade" 'fallback|legacy|best effort|尽力' "$ROOT/src"
|
||||
|
||||
# Exclude this gate script itself: its patterns necessarily spell the retired
|
||||
# names. Any other current script is scanned literally.
|
||||
for script in "$ROOT"/scripts/*; do
|
||||
[ -f "$script" ] || continue
|
||||
[ "$(basename "$script")" = "check-no-legacy.sh" ] && continue
|
||||
scan "retired core in $(basename "$script")" 'rc1|rc2|RC\.1|RC\.2' "$script"
|
||||
done
|
||||
|
||||
if [ "$fail" -ne 0 ]; then
|
||||
printf '\ncheck-no-legacy: FAIL\n'
|
||||
exit 1
|
||||
fi
|
||||
printf 'check-no-legacy: PASS\n'
|
||||
@@ -8,8 +8,17 @@ export CARGO_TARGET_DIR=${CARGO_TARGET_DIR:-"$ROOT/.cache/marqdo-lint-release-ta
|
||||
export TMPDIR=${TMPDIR:-"$ROOT/.cache/tmp"}
|
||||
|
||||
mkdir -p "$TMPDIR" "$DEST/bin"
|
||||
python3 - "$ROOT/tool.json" <<'PYCHECK'
|
||||
import json, sys
|
||||
value = json.load(open(sys.argv[1]))
|
||||
assert value["schema"] == "marqdo.cli-tool" and value["schema_version"] == 1
|
||||
assert value["requires"] == {"api_revision": 1, "analysis": 3}
|
||||
assert "compatibility" not in value
|
||||
PYCHECK
|
||||
cargo build --locked --release --manifest-path "$ROOT/Cargo.toml"
|
||||
install -m 755 "$CARGO_TARGET_DIR/release/marqdo-lint" "$DEST/bin/marqdo-lint"
|
||||
cp "$ROOT/tool.json" "$DEST/tool.json"
|
||||
sha256sum "$DEST/bin/marqdo-lint"
|
||||
printf 'tool.json sha256: '
|
||||
sha256sum "$DEST/tool.json" | awk '{print $1}'
|
||||
printf 'Tool bundle: %s\n' "$DEST"
|
||||
+386
-180
@@ -1,7 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Run the RC.1/RC.2 release gate using unpacked Linux release bundles."""
|
||||
"""Single-core rc.4 acceptance gate for marqdo-lint.
|
||||
|
||||
The script verifies the pinned marqdo-cli v3.0.0-rc.4 archive/binary, exercises
|
||||
one `check --emit` entry path, the packaged Tool revision 1 lifecycle, positive
|
||||
rule/fix behavior, JSON report schema, negative fail-closed cases and emits a
|
||||
machine-readable acceptance manifest.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import datetime
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
@@ -11,209 +18,408 @@ import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
RELEASES = {
|
||||
"3.0.0-rc.1": {
|
||||
"source_commit": "f7a5a7b0163bf5229ed09adfffd892f9899e6667",
|
||||
"archive_sha256": "9f49036ada141871492ef721f08569c74fd2854b5e5d1bfc065ba4d812dcabc7",
|
||||
"binary_sha256": "2fc5f74d8dd64a4a1b4617e630cb2af9fae5ba0ab769467c32ecb5a988894b6d",
|
||||
"negotiated_analysis": 2,
|
||||
},
|
||||
"3.0.0-rc.2": {
|
||||
"source_commit": "9149ee40a48fcda692c5c112f66c465487d13dfb",
|
||||
"archive_sha256": "e32e6426caf023fc813ebdbf5a171ec164ee2ffb843ae5594b8e7b9780f496ea",
|
||||
"binary_sha256": "5caa90b8f6a282aef5bb301443ede6cd3bdcf5f64c88969e6d71cb324b03dc5b",
|
||||
"negotiated_analysis": 3,
|
||||
},
|
||||
}
|
||||
CLI_SOURCE_SHA = "452e9a32bd9e40dba427d4180691c58bab74449e"
|
||||
CLI_ARCHIVE_SHA = "9c3f166b5e5b8840d39d10019074e4e1c42432fc23e26c69670e64fdcf4e15d8"
|
||||
CLI_BINARY_SHA = "a7306962689c635445a59043971ea2eb09298e01feeee81f0ba07b1f3e10306e"
|
||||
ANALYSIS_SCHEMA_SHA = "03929300cec53bb29309a933f74c1aa807943bfd7dbecc80cf4f7f54d037eb30"
|
||||
PLATFORM = "linux-x86_64-glibc2.39"
|
||||
MANIFEST_SCHEMA = "marqdo.lint.acceptance"
|
||||
MANIFEST_VERSION = 1
|
||||
|
||||
|
||||
class ValidationError(Exception):
|
||||
class GateError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def require(condition, message):
|
||||
if not condition:
|
||||
raise ValidationError(message)
|
||||
|
||||
|
||||
def sha256(path):
|
||||
with path.open("rb") as stream:
|
||||
def sha256_file(path):
|
||||
with Path(path).open("rb") as stream:
|
||||
return hashlib.file_digest(stream, "sha256").hexdigest()
|
||||
|
||||
|
||||
def run(args, *, cwd=ROOT, env=None, expected=0):
|
||||
result = subprocess.run(list(map(str, args)), cwd=cwd, env=env, capture_output=True, text=True)
|
||||
def sha256_bytes(data):
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def run(command, *, cwd=ROOT, env=None, expected=0, timeout=900):
|
||||
result = subprocess.run(
|
||||
[str(item) for item in command],
|
||||
cwd=cwd,
|
||||
env=env,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=timeout,
|
||||
)
|
||||
if expected is not None and result.returncode != expected:
|
||||
raise ValidationError(
|
||||
f"{args}: expected exit {expected}, got {result.returncode}\n"
|
||||
f"{result.stdout}{result.stderr}"
|
||||
raise GateError(
|
||||
f"command failed ({result.returncode}): {' '.join(map(str, command))}\n"
|
||||
f"{result.stdout}\n{result.stderr}"
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def validate_core(binary, version):
|
||||
require(binary.is_file() and os.access(binary, os.X_OK), f"missing frozen core: {binary}")
|
||||
digest = sha256(binary)
|
||||
require(digest == RELEASES[version]["binary_sha256"], f"unexpected {version} binary SHA-256: {digest}")
|
||||
require(run([binary, "--version"]).stdout.strip() == f"marqdo {version}", f"wrong version: {binary}")
|
||||
def cargo_command():
|
||||
return os.environ.get("CARGO", "cargo")
|
||||
|
||||
|
||||
def test_count(stdout):
|
||||
counts = re.findall(r"test result: ok\. (\d+) passed; 0 failed", stdout)
|
||||
return sum(int(value) for value in counts)
|
||||
|
||||
|
||||
def lint_binary():
|
||||
candidate = os.environ.get("MARQDO_LINT_BIN")
|
||||
if candidate:
|
||||
return Path(candidate).resolve()
|
||||
for profile in ("debug", "release"):
|
||||
path = ROOT / "target" / profile / "marqdo-lint"
|
||||
if path.is_file():
|
||||
return path
|
||||
raise GateError("marqdo-lint binary is missing; build it before running the gate")
|
||||
|
||||
|
||||
def validate_core(binary):
|
||||
if not binary.is_file() or not os.access(binary, os.X_OK):
|
||||
raise GateError(f"missing executable core: {binary}")
|
||||
digest = sha256_file(binary)
|
||||
if digest != CLI_BINARY_SHA:
|
||||
raise GateError(f"unexpected rc.4 binary SHA-256: {digest}")
|
||||
output = run([binary, "--version"]).stdout.strip()
|
||||
if output != "marqdo 3.0.0-rc.4":
|
||||
raise GateError(f"wrong core version: {output!r}")
|
||||
return digest
|
||||
|
||||
|
||||
def test_suite(binary):
|
||||
env = dict(os.environ, MARQDO_BIN=str(binary))
|
||||
cached_cargo = ROOT / ".cache/cargo-home"
|
||||
if cached_cargo.is_dir():
|
||||
env.setdefault("CARGO_HOME", str(cached_cargo))
|
||||
output = run(["cargo", "test", "--locked"], env=env).stdout
|
||||
counts = re.findall(r"test result: ok\. (\d+) passed; 0 failed", output)
|
||||
require(counts and sum(map(int, counts)) > 0, "cargo test reported no passing tests")
|
||||
return sum(map(int, counts))
|
||||
|
||||
|
||||
def trace_dispatch(strace, binary, work, env, name, args, major, expected):
|
||||
trace = work / f"{name}.trace"
|
||||
result = run(
|
||||
[strace, "-f", "-qq", "-v", "-s", "4096", "-e", "trace=execve", "-o", trace, binary, "lint", *args],
|
||||
cwd=work, env=env, expected=expected,
|
||||
)
|
||||
core_calls = []
|
||||
tool_calls = []
|
||||
for line in trace.read_text().splitlines():
|
||||
match = re.search(r'execve\(("(?:[^"\\]|\\.)*"), (\[(?:"(?:[^"\\]|\\.)*"(?:, )?)*\]),', line)
|
||||
if not match:
|
||||
continue
|
||||
program = Path(json.loads(match[1]))
|
||||
argv = json.loads(match[2])[1:]
|
||||
if program == binary:
|
||||
core_calls.append(argv)
|
||||
elif program.name == "marqdo-lint":
|
||||
tool_calls.append(line)
|
||||
else:
|
||||
raise ValidationError(f"{name}: unexpected executed program {program}")
|
||||
require(len(tool_calls) == 1, f"{name}: expected one packaged lint process")
|
||||
require(f'"MARQDO_PROTOCOL_ANALYSIS={major}"' in tool_calls[0], f"{name}: incorrect negotiated Analysis major")
|
||||
require(core_calls and core_calls[0][0] == "lint", f"{name}: missing core dispatch process")
|
||||
child_commands = set()
|
||||
for argv in core_calls[1:]:
|
||||
if argv == ["--version"]:
|
||||
child_commands.add("--version")
|
||||
elif len(argv) == 4 and argv[0] == "inspect" and argv[2:] == ["--ast", "--json"]:
|
||||
child_commands.add("inspect FILE --ast --json")
|
||||
elif len(argv) == 5 and argv[0] == "check" and argv[2:4] == ["--json", "--emit"]:
|
||||
child_commands.add("check FILE --json --emit PATH")
|
||||
else:
|
||||
raise ValidationError(f"{name}: unexpected core child command {argv}")
|
||||
require(len(child_commands) == 3, f"{name}: missing static child command: {child_commands}")
|
||||
return result.stdout, sorted(child_commands)
|
||||
|
||||
|
||||
def validate_bundle(strace, binary, version, bundle, directory):
|
||||
work = directory / "independent-cwd"
|
||||
work.mkdir(parents=True)
|
||||
home = directory / "home"
|
||||
home.mkdir()
|
||||
env = {
|
||||
"PATH": "/usr/bin:/bin",
|
||||
"LANG": "C.UTF-8",
|
||||
"HOME": str(home),
|
||||
"MARQDO_TOOL_HOME": str(directory / "registry"),
|
||||
}
|
||||
manifest = bundle / "tool.json"
|
||||
run([binary, "tool", "install", manifest], cwd=work, env=env)
|
||||
tools = run([binary, "tool", "list", "--json"], cwd=work, env=env).stdout
|
||||
require('"lint"' in tools, f"{version}: lint missing after tool install")
|
||||
major = RELEASES[version]["negotiated_analysis"]
|
||||
cases = [
|
||||
("legacy-branches", ROOT / "tests/fixtures/golden/branches.mq.md", 2, 0, "json", "never", None),
|
||||
("style-warning", ROOT / "examples/bad/branch-single-item.mq.md", 2, 1, "human", "warning", "MQD-BRANCH-001"),
|
||||
("incomplete", ROOT / "tests/fixtures/golden/invalid-control.mq.md", None, 2, "json", "never", "sem.unclosed_control"),
|
||||
]
|
||||
if major == 3:
|
||||
cases.extend([
|
||||
("release-hello", binary.parent / "examples/hello.mq.md", 2, 0, "json", "never", None),
|
||||
("multi-arm", ROOT / "tests/fixtures/rc2/multi-arm.mq.md", 2, 0, "json", "never", None),
|
||||
("loop-jumps", ROOT / "tests/fixtures/rc2/loop-jumps.mq.md", 3, 0, "json", "never", None),
|
||||
("release-control-flow", binary.parent / "examples/control-flow.mq.md", 3, 0, "json", "never", None),
|
||||
("author-example", ROOT / "examples/good/control-flow-rc2.mq.md", 3, 0, "json", "warning", None),
|
||||
])
|
||||
evidence = {}
|
||||
for name, original, expected_major, status, output_format, fail_on, diagnostic in cases:
|
||||
source = work / f"{name}.mq.md"
|
||||
shutil.copyfile(original, source)
|
||||
if expected_major is not None:
|
||||
artifact = work / f"{name}.analysis.json"
|
||||
run([binary, "check", source.name, "--json", "--emit", artifact], cwd=work, env=env)
|
||||
actual = json.loads(artifact.read_text())["schema_version"]
|
||||
require(actual == expected_major, f"{name}: incorrect artifact major {actual}")
|
||||
text, commands = trace_dispatch(
|
||||
strace, binary, work, env, name,
|
||||
[source.name, "--format", output_format, "--fail-on", fail_on], major, status,
|
||||
)
|
||||
digest = sha256(source)
|
||||
analysis_status = "analysis_incomplete" if status == 2 else "complete"
|
||||
if output_format == "json":
|
||||
report = json.loads(text)
|
||||
require(report["schema"] == "marqdo.lint" and report["schema_version"] == 1, f"{name}: unexpected report protocol")
|
||||
require(report["analysis_status"] == analysis_status, f"{name}: unexpected report state")
|
||||
require(report["source"]["digest"] == f"sha256:{digest}", f"{name}: source digest mismatch")
|
||||
if diagnostic:
|
||||
require(diagnostic in text, f"{name}: missing diagnostic {diagnostic}")
|
||||
evidence[name] = {
|
||||
"input_sha256": digest,
|
||||
"analysis_major": expected_major,
|
||||
"analysis_status": analysis_status,
|
||||
"exit": status,
|
||||
"format": output_format,
|
||||
**({"diagnostic": diagnostic} if diagnostic else {}),
|
||||
def gate(manifest, gate_id, command, function):
|
||||
try:
|
||||
detail = function()
|
||||
manifest["gates"][gate_id] = {
|
||||
"state": "PASS",
|
||||
"command": command,
|
||||
"exit_code": 0,
|
||||
}
|
||||
run([binary, "tool", "remove", "lint"], cwd=work, env=env)
|
||||
tools = run([binary, "tool", "list", "--json"], cwd=work, env=env).stdout
|
||||
require('"lint"' not in tools, f"{version}: lint remains after uninstall")
|
||||
removed = run([binary, "lint", "legacy-branches.mq.md"], cwd=work, env=env, expected=None)
|
||||
require(removed.returncode != 0, f"{version}: removed lint still dispatches")
|
||||
return {"install_exit": 0, "remove_exit": 0, "dispatch_after_remove_exit": removed.returncode,
|
||||
"static_child_commands": commands, "cases": evidence}
|
||||
print(f"{gate_id}: PASS", flush=True)
|
||||
return detail
|
||||
except (GateError, OSError, ValueError, KeyError, subprocess.TimeoutExpired) as error:
|
||||
manifest["gates"][gate_id] = {
|
||||
"state": "FAIL",
|
||||
"command": command,
|
||||
"exit_code": 1,
|
||||
"detail": str(error)[:4000],
|
||||
}
|
||||
print(f"{gate_id}: FAIL - {error}", flush=True)
|
||||
return None
|
||||
|
||||
|
||||
def g01(manifest):
|
||||
run([ROOT / "scripts/check-no-legacy.sh"])
|
||||
|
||||
|
||||
def g02(manifest):
|
||||
run([cargo_command(), "fmt", "--all", "--", "--check"])
|
||||
run([cargo_command(), "clippy", "--all-targets", "--", "-D", "warnings"])
|
||||
result = run([cargo_command(), "test", "--locked"], timeout=1800)
|
||||
count = test_count(result.stdout)
|
||||
if count == 0:
|
||||
raise GateError("cargo test reported no passing tests")
|
||||
manifest["tests_passed"] = count
|
||||
|
||||
|
||||
def g03(manifest):
|
||||
binary = manifest["_core"]
|
||||
work = Path(tempfile.mkdtemp(prefix="marqdo-lint-install-"))
|
||||
try:
|
||||
bundle = work / "bundle"
|
||||
run([ROOT / "scripts/package-tool.sh", bundle], timeout=1800)
|
||||
env = dict(os.environ)
|
||||
env.update(
|
||||
{
|
||||
"MARQDO_TOOL_HOME": str(work / "registry"),
|
||||
"PATH": "/usr/bin:/bin",
|
||||
"LANG": "C.UTF-8",
|
||||
"HOME": str(work / "home"),
|
||||
}
|
||||
)
|
||||
(work / "home").mkdir()
|
||||
env.pop("MARQDO_BIN", None)
|
||||
dispatch = work / "project"
|
||||
dispatch.mkdir()
|
||||
shutil.copyfile(
|
||||
ROOT / "examples/nested/inventory.mq.md", dispatch / "inventory.mq.md"
|
||||
)
|
||||
shutil.copyfile(
|
||||
ROOT / "examples/bad/branch-single-item.mq.md", dispatch / "bad.mq.md"
|
||||
)
|
||||
shutil.copyfile(
|
||||
ROOT / "tests/fixtures/golden/invalid-control.mq.md", dispatch / "invalid.mq.md"
|
||||
)
|
||||
run([binary, "tool", "install", bundle / "tool.json"], env=env)
|
||||
listed = run([binary, "tool", "list", "--json"], env=env).stdout
|
||||
if '"lint"' not in listed:
|
||||
raise GateError("lint is not listed after tool install")
|
||||
run([binary, "lint", "inventory.mq.md", "--format", "json"], cwd=dispatch, env=env)
|
||||
run(
|
||||
[binary, "lint", "bad.mq.md", "--format", "human"],
|
||||
cwd=dispatch,
|
||||
env=env,
|
||||
expected=1,
|
||||
)
|
||||
run(
|
||||
[binary, "lint", "invalid.mq.md", "--format", "json", "--fail-on", "never"],
|
||||
cwd=dispatch,
|
||||
env=env,
|
||||
expected=2,
|
||||
)
|
||||
run([binary, "tool", "remove", "lint"], env=env)
|
||||
after = run(
|
||||
[binary, "lint", "inventory.mq.md", "--format", "json"],
|
||||
cwd=dispatch,
|
||||
env=env,
|
||||
expected=None,
|
||||
)
|
||||
if after.returncode == 0:
|
||||
raise GateError("removed lint still dispatches")
|
||||
manifest["lint_binary_sha256"] = f"sha256:{sha256_file(bundle / 'bin/marqdo-lint')}"
|
||||
manifest["tool_bundle_digest"] = f"sha256:{sha256_file(bundle / 'tool.json')}"
|
||||
finally:
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
|
||||
|
||||
def g04(manifest):
|
||||
binary = manifest["_core"]
|
||||
lint = lint_binary()
|
||||
env = dict(os.environ, MARQDO_BIN=str(binary))
|
||||
positive = [
|
||||
("inventory", ROOT / "examples/nested/inventory.mq.md"),
|
||||
("multi-arm", ROOT / "tests/fixtures/control/multi-arm.mq.md"),
|
||||
("loop-jumps", ROOT / "tests/fixtures/control/loop-jumps.mq.md"),
|
||||
("knowledge", ROOT / "examples/knowledge/discount.mq.md"),
|
||||
]
|
||||
for name, path in positive:
|
||||
result = run(
|
||||
[lint, path, "--format", "json", "--fail-on", "never"],
|
||||
env=env,
|
||||
)
|
||||
report = json.loads(result.stdout)
|
||||
if report["analysis_status"] != "complete":
|
||||
raise GateError(f"{name}: analysis is not complete")
|
||||
work = Path(tempfile.mkdtemp(prefix="marqdo-lint-fix-"))
|
||||
try:
|
||||
for name in ("marqdo.yaml", "geometry.mq.md"):
|
||||
shutil.copyfile(ROOT / "tests/fixtures/multi" / name, work / name)
|
||||
source = (ROOT / "tests/fixtures/multi/index.mq.md").read_text()
|
||||
dirty = source.replace("## @exec main\n\n", "## @exec main\n \t\n")
|
||||
(work / "index.mq.md").write_text(dirty)
|
||||
run(
|
||||
[lint, "index.mq.md", "--fix", "safe", "--dry-run", "--format", "json", "--fail-on", "never"],
|
||||
cwd=work,
|
||||
env=env,
|
||||
)
|
||||
if (work / "index.mq.md").read_text() != dirty:
|
||||
raise GateError("dry-run wrote the source")
|
||||
run(
|
||||
[lint, "index.mq.md", "--fix", "safe", "--format", "json", "--fail-on", "never"],
|
||||
cwd=work,
|
||||
env=env,
|
||||
)
|
||||
if (work / "index.mq.md").read_text() != source:
|
||||
raise GateError("safe fix did not produce the expected idempotent result")
|
||||
run(
|
||||
[lint, "index.mq.md", "--format", "json", "--fail-on", "never"],
|
||||
cwd=work,
|
||||
env=env,
|
||||
)
|
||||
finally:
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
|
||||
|
||||
def g05(manifest):
|
||||
import jsonschema
|
||||
|
||||
binary = manifest["_core"]
|
||||
lint = lint_binary()
|
||||
env = dict(os.environ, MARQDO_BIN=str(binary))
|
||||
schema = json.loads((ROOT / "schemas/marqdo-lint-v1.schema.json").read_text())
|
||||
result = run(
|
||||
[lint, ROOT / "examples/nested/inventory.mq.md", "--format", "json", "--fail-on", "never"],
|
||||
env=env,
|
||||
)
|
||||
report = json.loads(result.stdout)
|
||||
jsonschema.validate(report, schema)
|
||||
if report["schema"] != "marqdo.lint" or report["schema_version"] != 1:
|
||||
raise GateError("unexpected lint report protocol")
|
||||
|
||||
|
||||
def g06(manifest):
|
||||
binary = manifest["_core"]
|
||||
lint = lint_binary()
|
||||
artifact = json.loads(
|
||||
(ROOT / "tests/fixtures/rc4/branches.analysis.json").read_text()
|
||||
)
|
||||
retired = json.loads(json.dumps(artifact))
|
||||
for field in ("source", "document", "anchors"):
|
||||
retired["modules"][0].pop(field, None)
|
||||
bad_digest = json.loads(json.dumps(artifact))
|
||||
bad_digest["modules"][0]["source_digest"] = "0" * 64
|
||||
bad_revision = json.loads(json.dumps(artifact))
|
||||
bad_revision["schema_version"] = 2
|
||||
work = Path(tempfile.mkdtemp(prefix="marqdo-lint-negative-"))
|
||||
try:
|
||||
source = work / "branches.mq.md"
|
||||
shutil.copyfile(ROOT / "tests/fixtures/golden/branches.mq.md", source)
|
||||
proxy = work / "core-proxy"
|
||||
proxy.write_text(
|
||||
"#!/bin/sh\n"
|
||||
"set -eu\n"
|
||||
"case \"$1\" in\n"
|
||||
" --version) echo 'marqdo 3.0.0-rc.4' ;;\n"
|
||||
" check) case \"$4\" in --emit) cp \"$0.artifact\" \"$5\" ;; esac ;;\n"
|
||||
" *) echo 'unsupported proxy command' >&2; exit 2 ;;\n"
|
||||
"esac\n"
|
||||
)
|
||||
proxy.chmod(0o755)
|
||||
for name, payload, needle in [
|
||||
("retired", retired, "旧 revision 3"),
|
||||
("digest", bad_digest, "source_digest"),
|
||||
("revision", bad_revision, "revision 3"),
|
||||
]:
|
||||
(work / "core-proxy.artifact").write_text(
|
||||
json.dumps(payload, ensure_ascii=False)
|
||||
)
|
||||
result = run(
|
||||
[lint, source, "--format", "json", "--fail-on", "never"],
|
||||
env=dict(os.environ, MARQDO_BIN=str(proxy)),
|
||||
expected=None,
|
||||
)
|
||||
if result.returncode != 2:
|
||||
raise GateError(f"{name}: expected exit 2, got {result.returncode}")
|
||||
if needle not in result.stderr:
|
||||
raise GateError(f"{name}: missing diagnostic {needle!r}: {result.stderr}")
|
||||
tool = json.loads((ROOT / "tool.json").read_text())
|
||||
old_tool = dict(tool)
|
||||
old_tool["compatibility"] = {"marqdo": ">=3.0.0-rc.4,<4.0.0", "analysis": [3]}
|
||||
old_manifest = work / "old-tool.json"
|
||||
old_manifest.write_text(json.dumps(old_tool, ensure_ascii=False))
|
||||
registry = work / "registry"
|
||||
install = run(
|
||||
[binary, "tool", "install", old_manifest],
|
||||
env=dict(os.environ, MARQDO_TOOL_HOME=str(registry)),
|
||||
expected=None,
|
||||
)
|
||||
if install.returncode == 0:
|
||||
raise GateError("old tool manifest installed successfully")
|
||||
if "compatibility" not in install.stderr:
|
||||
raise GateError("old tool manifest error does not name compatibility")
|
||||
finally:
|
||||
shutil.rmtree(work, ignore_errors=True)
|
||||
|
||||
|
||||
def g08(manifest):
|
||||
banned = [
|
||||
"双核心",
|
||||
"Analysis v2/v3",
|
||||
"compatibility 协商",
|
||||
"RC" + "." + "1",
|
||||
"RC" + "." + "2",
|
||||
]
|
||||
for name in [
|
||||
"README.md",
|
||||
"docs/PROTOCOL_BASELINE.md",
|
||||
"docs/VALIDATION.md",
|
||||
"docs/ARCHITECTURE.md",
|
||||
"docs/CLI.md",
|
||||
]:
|
||||
text = (ROOT / name).read_text()
|
||||
for phrase in banned:
|
||||
if phrase in text:
|
||||
raise GateError(f"{name}: contains retired phrase {phrase!r}")
|
||||
|
||||
|
||||
def g09(manifest):
|
||||
pipeline = ROOT / ".woodpecker/main.yml"
|
||||
if not pipeline.is_file():
|
||||
raise GateError("missing .woodpecker/main.yml")
|
||||
text = pipeline.read_text()
|
||||
for needle in ["check-no-legacy", "validate-control-flow", "cargo test --locked"]:
|
||||
if needle not in text:
|
||||
raise GateError(f"CI pipeline is missing {needle!r}")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("rc1", type=Path, help="frozen marqdo 3.0.0-rc.1 executable")
|
||||
parser.add_argument("rc2", type=Path, help="frozen marqdo 3.0.0-rc.2 executable")
|
||||
parser.add_argument("--report", type=Path, help="write JSON evidence to this path")
|
||||
parser.add_argument("core", type=Path, help="unpacked marqdo 3.0.0-rc.4 executable")
|
||||
parser.add_argument("--report", type=Path, help="acceptance manifest path")
|
||||
args = parser.parse_args()
|
||||
manifest = {
|
||||
"schema": MANIFEST_SCHEMA,
|
||||
"schema_version": MANIFEST_VERSION,
|
||||
"lint_commit": run(["git", "rev-parse", "HEAD"]).stdout.strip(),
|
||||
"lint_version": run([cargo_command(), "metadata", "--no-deps", "--format-version", "1"]).stdout
|
||||
and json.loads(
|
||||
run([cargo_command(), "metadata", "--no-deps", "--format-version", "1"]).stdout
|
||||
)["packages"][0]["version"],
|
||||
"lint_binary_sha256": None,
|
||||
"tool_bundle_digest": None,
|
||||
"cli_source_sha": CLI_SOURCE_SHA,
|
||||
"cli_archive_sha256": f"sha256:{CLI_ARCHIVE_SHA}",
|
||||
"cli_binary_sha256": f"sha256:{CLI_BINARY_SHA}",
|
||||
"cli_binary_sha256_before": None,
|
||||
"cli_binary_sha256_after": None,
|
||||
"analysis_schema_sha256": f"sha256:{ANALYSIS_SCHEMA_SHA}",
|
||||
"platform": PLATFORM,
|
||||
"generated_utc": datetime.datetime.now(datetime.timezone.utc)
|
||||
.replace(microsecond=0)
|
||||
.isoformat()
|
||||
.replace("+00:00", "Z"),
|
||||
"gates": {},
|
||||
"unverified": [
|
||||
"G10 independent application trial: qdagent/qdqc pinned commits are not available in this workspace; result is analysis_incomplete semantics only, no false-positive rate claim."
|
||||
],
|
||||
}
|
||||
try:
|
||||
binaries = dict(zip(RELEASES, (args.rc1.resolve(), args.rc2.resolve())))
|
||||
before = {version: validate_core(binary, version) for version, binary in binaries.items()}
|
||||
strace = shutil.which("strace")
|
||||
require(strace, "strace is required to verify the Tool v1 subprocess contract")
|
||||
results = {}
|
||||
for version, binary in binaries.items():
|
||||
passed = test_suite(binary)
|
||||
print(f"{version}: cargo test --locked, {passed} tests passed", flush=True)
|
||||
results[version] = {**RELEASES[version], "tests_passed": passed, "binary_sha256_before": before[version]}
|
||||
with tempfile.TemporaryDirectory(prefix="marqdo-lint-release-") as scratch:
|
||||
bundle = Path(scratch) / "bundle"
|
||||
run([ROOT / "scripts/package-tool.sh", bundle])
|
||||
manifest = json.loads((bundle / "tool.json").read_text())
|
||||
require(manifest["compatibility"]["analysis"] == [2, 3], "unexpected bundle compatibility")
|
||||
evidence = {
|
||||
"lint_binary_sha256": sha256(bundle / "bin/marqdo-lint"),
|
||||
"tool_analysis_compatibility": manifest["compatibility"]["analysis"],
|
||||
"cores": results,
|
||||
}
|
||||
for version, binary in binaries.items():
|
||||
results[version]["tool"] = validate_bundle(strace, binary, version, bundle, Path(scratch) / version)
|
||||
after = sha256(binary)
|
||||
require(after == before[version], f"{version}: core binary changed during gate")
|
||||
results[version]["binary_sha256_after"] = after
|
||||
print(f"{version}: packaged Tool v1 install, dispatch, exit codes and removal passed", flush=True)
|
||||
if args.report:
|
||||
args.report.write_text(json.dumps(evidence, ensure_ascii=False, indent=2) + "\n")
|
||||
except (OSError, ValidationError, ValueError, KeyError) as error:
|
||||
parser.exit(1, f"release gate failed: {error}\n")
|
||||
before = validate_core(args.core.resolve())
|
||||
manifest["cli_binary_sha256_before"] = f"sha256:{before}"
|
||||
manifest["_core"] = args.core.resolve()
|
||||
os.environ["MARQDO_BIN"] = str(args.core.resolve())
|
||||
gate(manifest, "G01", "scripts/check-no-legacy.sh", lambda: g01(manifest))
|
||||
gate(manifest, "G02", "cargo fmt --check; cargo clippy -D warnings; cargo test --locked", lambda: g02(manifest))
|
||||
gate(manifest, "G03", "scripts/package-tool.sh + tool install/list/dispatch/remove", lambda: g03(manifest))
|
||||
gate(manifest, "G04", "lint positive rules and safe fix", lambda: g04(manifest))
|
||||
gate(manifest, "G05", "lint JSON report vs schemas/marqdo-lint-v1.schema.json", lambda: g05(manifest))
|
||||
gate(manifest, "G06", "negative protocol/artifact/tool cases fail closed", lambda: g06(manifest))
|
||||
gate(manifest, "G07", "single-core rc.4 evidence manifest", lambda: None)
|
||||
gate(manifest, "G08", "docs facts are rc.4-only", lambda: g08(manifest))
|
||||
gate(manifest, "G09", "Woodpecker CI covers G01-G07", lambda: g09(manifest))
|
||||
after = sha256_file(args.core.resolve())
|
||||
manifest["cli_binary_sha256_after"] = f"sha256:{after}"
|
||||
if after != before:
|
||||
raise GateError("core binary changed during acceptance")
|
||||
manifest["gates"]["G10"] = {
|
||||
"state": "UNVERIFIED",
|
||||
"command": "independent qdagent/qdqc trial",
|
||||
"exit_code": None,
|
||||
}
|
||||
manifest.pop("_core", None)
|
||||
report = args.report or (
|
||||
ROOT / "docs/validation" / f"{CLI_SOURCE_SHA}.json"
|
||||
)
|
||||
report.parent.mkdir(parents=True, exist_ok=True)
|
||||
report.write_text(json.dumps(manifest, ensure_ascii=False, indent=2) + "\n")
|
||||
failed = [
|
||||
gate_id
|
||||
for gate_id, value in manifest["gates"].items()
|
||||
if value["state"] == "FAIL"
|
||||
]
|
||||
print("\n".join(f"{key}: {value['state']}" for key, value in manifest["gates"].items()))
|
||||
print(f"manifest: {report}")
|
||||
if failed:
|
||||
print(f"FAILED gates: {', '.join(failed)}")
|
||||
return 1
|
||||
return 0
|
||||
except (GateError, OSError, ValueError, KeyError, subprocess.TimeoutExpired) as error:
|
||||
print(f"acceptance failed: {error}")
|
||||
return 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
raise SystemExit(main())
|
||||
Reference in new issue
Block a user