feat(PR-01): 0.2.0 Tool v1 bundle, scripts/ layout and CI lanes

- bump View product version to 0.2.0 (Cargo.toml, Cargo.lock, tool.json, CLI)
- move all maintenance scripts from tools/ to scripts/ per RFC-0002 §5.3
- add scripts/verify-frozen-cli.sh: records version/SHA and fails if the frozen
  CLI changes across a command sequence
- add .github/workflows/ci.yml: quality lane + frozen-CLI acceptance lane with
  archive SHA verification and evidence upload; update .woodpecker.yml paths
- record PR-01 black-box evidence: tool install/list/view --help/version,
  tamper rejection, tool remove, frozen CLI SHA unchanged
This commit is contained in:
cflmy committed 2026-11-22 12:51:36 +08:00
1 parent d0f1834e98
commit 5a61788bc9
26 files changed
+269 -57

No files matched your search

+227
View File
@@ -0,0 +1,227 @@
#!/usr/bin/env bash
# RFC-VIEW-0001 §18.1 one-command acceptance.
#
# Usage:
# MARQDO_BIN=/abs/path/to/frozen/marqdo scripts/acceptance.sh
#
# Optional:
# CLI_SOURCE_SHA=<sha> override the CLI source SHA for the evidence manifest
# SKIP_BROWSER=1 skip Chromium suite (recorded as SKIP, not PASS)
#
# The script never modifies or recompiles the frozen CLI; it records its
# SHA-256 before and after and fails if it changes.
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
: "${MARQDO_BIN:?set MARQDO_BIN to the frozen marqdo release binary}"
[[ -x "$MARQDO_BIN" ]] || { echo "error: MARQDO_BIN not executable" >&2; exit 1; }
work="$repo_root/dist/acceptance"
rm -rf "$work"
mkdir -p "$work"
statuses=""
record() { statuses="${statuses}$1=$2\n"; echo "[acceptance] $1: $2"; }
run_step() {
local name="$1"
shift
echo "==> $name"
if "$@"; then
record "$name" PASS
else
record "$name" FAIL
return 1
fi
}
core_before="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
cli_source_sha="${CLI_SOURCE_SHA:-}"
if [[ -z "$cli_source_sha" && -f "$(dirname "$MARQDO_BIN")/SOURCE_SHA" ]]; then
cli_source_sha="$(tr -d '[:space:]' < "$(dirname "$MARQDO_BIN")/SOURCE_SHA")"
fi
cli_source_sha="${cli_source_sha:-unknown}"
view_source_sha="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
export PATH="${HOME}/.cargo/bin:${PATH}"
export CARGO_HOME="${CARGO_HOME:-$repo_root/.cargo-home}"
# 0. code quality / unit / contract tests
run_step fmt cargo fmt --all -- --check
run_step clippy cargo clippy --all-targets -- -D warnings
run_step test cargo test --locked
run_step build cargo build --release --locked
# 1. controlled Tool bundle + frozen-CLI install smoke
run_step bundle env MARQDO_BIN="$MARQDO_BIN" ./scripts/package.sh
bundle="$repo_root/dist/marqdo-view"
archive="$(ls -t "$repo_root"/dist/marqdo-view-*-x86_64-unknown-linux-gnu.tar.gz | head -1)"
archive_sha="$(sha256sum "$archive" | cut -d' ' -f1)"
# 2. clean install from the *archive*, in a moved temporary directory
mkdir -p "$work/extracted"
tar -xzf "$archive" -C "$work/extracted"
extracted_bundle="$work/extracted/marqdo-view"
tool_home="$work/tool-home"
mkdir -p "$tool_home"
export MARQDO_TOOL_HOME="$tool_home"
run_step archive_install "$MARQDO_BIN" tool install "$extracted_bundle/tool.json"
run_step tool_list bash -c "'$MARQDO_BIN' tool list | grep -q view"
run_step view_help bash -c "'$MARQDO_BIN' view --help | grep -q 'marqdo-view'"
run_step verify "$MARQDO_BIN" view verify examples/mixed-modes/index.mq.md
run_step export "$MARQDO_BIN" view export examples/control-flow --out "$work/site"
test -f "$work/site/manifest.json"
# 3. Live browse smoke (no execution on open)
browse_log="$work/browse.log"
"$MARQDO_BIN" view examples/welcome --port 0 --no-open >"$browse_log" 2>&1 &
browse_pid=$!
trap 'kill "$browse_pid" 2>/dev/null || true' EXIT
browse_url=""
for _ in $(seq 1 100); do
browse_url="$(grep -o 'http://127.0.0.1:[0-9]*/' "$browse_log" | head -1 || true)"
[[ -n "$browse_url" ]] && break
sleep 0.1
done
if [[ -n "$browse_url" ]] && curl -sf "${browse_url}api/health" | grep -q '"ok": true'; then
record browse PASS
else
record browse FAIL
cat "$browse_log" >&2
exit 1
fi
kill "$browse_pid" 2>/dev/null || true
wait "$browse_pid" 2>/dev/null || true
trap - EXIT
# 4. Explicit real run through the installed tool + CSRF flow
run_log="$work/run.log"
"$MARQDO_BIN" view examples/control-flow --port 0 --no-open >"$run_log" 2>&1 &
run_pid=$!
trap 'kill "$run_pid" 2>/dev/null || true' EXIT
run_url=""
for _ in $(seq 1 100); do
run_url="$(grep -o 'http://127.0.0.1:[0-9]*/' "$run_log" | head -1 || true)"
[[ -n "$run_url" ]] && break
sleep 0.1
done
if [[ -n "$run_url" ]]; then
if python3 - "$run_url" <<'PY'
import json
import re
import sys
import urllib.request
url = sys.argv[1]
def get(path):
with urllib.request.urlopen(url.rstrip("/") + path, timeout=30) as response:
return response.read().decode("utf-8")
page = get("/")
match = re.search(r'name="mq-csrf-token" content="([0-9a-f]+)"', page)
assert match, "csrf token missing"
token = match.group(1)
body = json.dumps({"path": "index.mq.md", "mode": "pure", "confirm": True}).encode()
request = urllib.request.Request(
url.rstrip("/") + "/api/run",
data=body,
headers={"Content-Type": "application/json", "X-MQ-CSRF": token},
method="POST",
)
with urllib.request.urlopen(request, timeout=120) as response:
result = json.loads(response.read().decode("utf-8"))
assert result["ok"] is True, result
assert result["state"] == "succeeded", result
run_page = get(result["redirect"])
assert 'id="mq-run-panel"' in run_page, "run panel missing"
assert 'data-run-state="succeeded"' in run_page, "succeeded state missing"
assert "mq-run-chip" in run_page, "trace chips missing"
print("explicit real run: PASS (state=%s events=%s)" % (result["state"], result["events"]))
PY
then
record real_run PASS
else
record real_run FAIL
exit 1
fi
else
record real_run FAIL
cat "$run_log" >&2
exit 1
fi
kill "$run_pid" 2>/dev/null || true
wait "$run_pid" 2>/dev/null || true
trap - EXIT
# 5. project-local verification suites
run_step export_suite env MARQDO_BIN="$MARQDO_BIN" ./scripts/test-export.sh
run_step security_suite ./scripts/test-security.sh
if [[ "${SKIP_BROWSER:-0}" == "1" ]]; then
record browser SKIP
elif [[ -d "$repo_root/tests/browser/node_modules/playwright" && -d "$repo_root/tests/.cache/pw-browsers" ]]; then
run_step browser env MARQDO_BIN="$MARQDO_BIN" ./scripts/test-browser.sh
else
record browser SKIP
fi
# 6. frozen core must be byte-identical
core_after="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
if [[ "$core_before" != "$core_after" ]]; then
record core_sha FAIL
echo "error: frozen core binary changed during acceptance" >&2
exit 1
fi
record core_sha PASS
view_binary_sha="$(sha256sum "$bundle/bin/marqdo-view" | cut -d' ' -f1)"
target="$(python3 -c 'import json;print(json.load(open("dist/marqdo-view/RELEASE_INFO.json"))["target"])')"
evidence_dir="$repo_root/docs/evidence/$cli_source_sha"
mkdir -p "$evidence_dir"
python3 - "$evidence_dir/manifest.json" <<PY
import datetime
import json
import pathlib
path = pathlib.Path("$evidence_dir/manifest.json")
statuses = {}
for line in """${statuses}""".splitlines():
if "=" in line:
name, value = line.split("=", 1)
statuses[name] = value
manifest = {
"schema": "marqdo.view-conformance",
"schema_version": 1,
"view_source_sha": "$view_source_sha",
"view_binary_sha256": "$view_binary_sha",
"cli_source_sha": "$cli_source_sha",
"cli_binary_sha256_before": "$core_before",
"cli_binary_sha256_after": "$core_after",
"tool_protocol": 1,
"analysis_protocol": 2,
"trace_protocol": 2,
"target": "$target",
"archive_sha256": "$archive_sha",
"generated_at_utc": datetime.datetime.now(datetime.timezone.utc).isoformat(),
"tests": {
"contract": statuses.get("test", "FAIL"),
"browser": statuses.get("browser", "SKIP"),
"export": statuses.get("export_suite", "FAIL"),
"security": statuses.get("security_suite", "FAIL"),
},
"gates": statuses,
"commands": {
"script": "scripts/acceptance.sh",
"notes": "Generated from real command exit statuses; install/verify/export/run use the frozen CLI archive copied to an isolated tool home.",
},
}
path.write_text(json.dumps(manifest, indent=2, sort_keys=True) + "\\n")
print("evidence manifest:", path)
PY
echo
echo "acceptance: PASS"
echo "evidence: $evidence_dir/manifest.json"
echo "archive sha256: $archive_sha"
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env bash
# Regenerate committed Analysis v2 goldens from the frozen CLI release binary.
#
# Usage: MARQDO_BIN=/abs/path/marqdo scripts/gen-golden.sh
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
: "${MARQDO_BIN:?set MARQDO_BIN to the frozen marqdo binary}"
if [[ ! -x "$MARQDO_BIN" ]]; then
echo "error: MARQDO_BIN is not executable: $MARQDO_BIN" >&2
exit 1
fi
echo "golden core sha256: $(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
out="tests/golden/analysis-v2"
mkdir -p "$out"
"$MARQDO_BIN" check examples/mixed-modes/index.mq.md --emit "$out/mixed-modes.json"
"$MARQDO_BIN" check examples/control-flow/index.mq.md --emit "$out/control-flow.json"
"$MARQDO_BIN" check examples/tables-math/index.mq.md --emit "$out/tables-math.json"
"$MARQDO_BIN" check examples/welcome/00-welcome.mq.md --emit "$out/welcome.json"
# Trace v2 goldens come from the same frozen binary (pure mode, no grants).
out_trace="tests/golden/trace-v2"
mkdir -p "$out_trace"
( cd examples/control-flow \
&& "$MARQDO_BIN" run index.mq.md --mode pure --json --trace-file "$repo_root/$out_trace/control-flow.trace.json" > "$repo_root/$out_trace/control-flow.run.json" )
( cd examples/control-flow \
&& "$MARQDO_BIN" run index.mq.md --mode pure --json --trace-max-events 5 --trace-file "$repo_root/$out_trace/control-flow.truncated.trace.json" > "$repo_root/$out_trace/control-flow.truncated.run.json" )
if ( cd examples/mixed-modes \
&& "$MARQDO_BIN" run index.mq.md --mode pure --json --trace-file "$repo_root/$out_trace/mixed-modes.arity.trace.json" > "$repo_root/$out_trace/mixed-modes.arity.run.json" ); then
echo "error: mixed-modes without params unexpectedly ran" >&2
exit 1
fi
# Diagnostics fixture must fail: verify the failure shape stays as expected.
if "$MARQDO_BIN" check examples/diagnostics/index.mq.md --json >/dev/null 2>&1; then
echo "error: examples/diagnostics unexpectedly passed check" >&2
exit 1
fi
echo "goldens: PASS"
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
# Install the built bundle with a frozen marqdo CLI into an isolated tool home,
# then prove the command is served by this program (not by the Core).
#
# Usage: MARQDO_BIN=/abs/path/marqdo scripts/install-smoke.sh [tool.json]
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
manifest="${1:-$repo_root/dist/marqdo-view/tool.json}"
: "${MARQDO_BIN:?set MARQDO_BIN to the frozen marqdo binary}"
if [[ ! -x "$MARQDO_BIN" ]]; then
echo "error: MARQDO_BIN is not executable: $MARQDO_BIN" >&2
exit 1
fi
before="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
mkdir -p "$repo_root/dist"
tool_home="$(mktemp -d "$repo_root/dist/smoke-tool-home.XXXXXX")"
cleanup() {
rm -rf "$tool_home"
}
trap cleanup EXIT
export MARQDO_TOOL_HOME="$tool_home"
"$MARQDO_BIN" tool install "$manifest" >/dev/null
"$MARQDO_BIN" tool list | grep -q 'view'
help="$("$MARQDO_BIN" view --help)"
grep -q 'marqdo-view' <<<"$help"
grep -q 'export' <<<"$help"
grep -q 'verify' <<<"$help"
version="$("$MARQDO_BIN" view --version)"
grep -q 'marqdo-view' <<<"$version"
after="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
if [[ "$before" != "$after" ]]; then
echo "error: frozen core binary changed during install smoke test" >&2
exit 1
fi
echo "install-smoke: PASS (core sha256 $before unchanged, tool home $tool_home)"
+118
View File
@@ -0,0 +1,118 @@
#!/usr/bin/env bash
# Build and assemble the Tool Protocol v1 release bundle.
#
# Produces:
# dist/marqdo-view/ stable bundle path (RFC §18)
# dist/marqdo-view-<version>-<target>.tar.gz (+ .sha256)
#
# The bundle contains only the runtime binary, the manifest and the legal /
# compatibility files. CSS/JS/images are compiled into the binary (ADR-0002),
# so there is exactly one asset source for Live and Export.
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
: "${CARGO:=cargo}"
: "${MARQDO_BIN:=}"
version="$("$CARGO" metadata --no-deps --format-version 1 \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["packages"][0]["version"])')"
target="$("$CARGO" -vV 2>/dev/null | sed -n 's/^host: //p')"
target="${target:-x86_64-unknown-linux-gnu}"
echo "==> cargo build --release --locked"
"$CARGO" build --release --locked
dist="$repo_root/dist"
bundle="$dist/marqdo-view"
rm -rf "$bundle"
mkdir -p "$bundle/bin"
binary="$repo_root/target/release/marqdo-view"
if [[ ! -x "$binary" ]]; then
echo "error: missing release binary $binary" >&2
exit 1
fi
cp "$binary" "$bundle/bin/marqdo-view"
chmod 755 "$bundle/bin/marqdo-view"
cp tool.json "$bundle/tool.json"
cp README.md COMPATIBILITY.md CHANGELOG.md LICENSE-MIT LICENSE-APACHE "$bundle/"
# Verify the tool manifest and the binary agree on the version.
manifest_version="$(python3 -c 'import json;print(json.load(open("tool.json"))["version"])')"
if [[ "$manifest_version" != "$version" ]]; then
echo "error: tool.json version $manifest_version != package version $version" >&2
exit 1
fi
binary_version="$("$bundle/bin/marqdo-view" --version | awk '{print $2}')"
if [[ "$binary_version" != "$version" ]]; then
echo "error: binary prints version $binary_version, package is $version" >&2
exit 1
fi
source_sha="unknown"
if git rev-parse --verify HEAD >/dev/null 2>&1; then
source_sha="$(git rev-parse HEAD)"
fi
printf '%s\n' "$source_sha" > "$bundle/SOURCE_SHA"
python3 - "$bundle" "$version" "$target" "$source_sha" <<'PY'
import hashlib
import json
import pathlib
import sys
bundle = pathlib.Path(sys.argv[1])
version, target, source_sha = sys.argv[2], sys.argv[3], sys.argv[4]
files = []
for path in sorted(bundle.rglob('*')):
if not path.is_file():
continue
rel = path.relative_to(bundle).as_posix()
if rel in ('RELEASE_INFO.json', 'SHA256SUMS'):
continue
data = path.read_bytes()
files.append({
'path': rel,
'size': len(data),
'sha256': hashlib.sha256(data).hexdigest(),
})
info = {
'schema': 'marqdo.view-release-info',
'schema_version': 1,
'tool_name': 'marqdo-view',
'tool_version': version,
'command': 'view',
'target': target,
'source_sha': source_sha,
'compatibility': {
'marqdo': '>=3.0.0-beta.1,<4.0.0',
'analysis': [2],
'trace': [2],
'tool_protocol': 1,
'markdown_profile': 'marqdo.md.v1',
},
'files': files,
}
(bundle / 'RELEASE_INFO.json').write_text(json.dumps(info, indent=2, sort_keys=True) + '\n')
with (bundle / 'SHA256SUMS').open('w') as out:
for entry in files:
out.write(f"{entry['sha256']} {entry['path']}\n")
PY
# Deterministic archive: sorted paths, fixed owner, gzip without timestamps.
archive="marqdo-view-${version}-${target}.tar.gz"
tar --sort=name --owner=0 --group=0 --numeric-owner --mtime='UTC 2026-01-01' \
-C "$dist" -cf - marqdo-view | gzip -n > "$dist/$archive"
( cd "$dist" && sha256sum "$archive" > "$archive.sha256" )
if [[ -n "$MARQDO_BIN" ]]; then
echo "==> smoke install against frozen core"
MARQDO_BIN="$MARQDO_BIN" "$repo_root/scripts/install-smoke.sh" "$bundle/tool.json"
fi
echo "bundle: $bundle"
echo "archive: $dist/$archive"
echo "sha256: $(cut -d' ' -f1 "$dist/$archive.sha256")"
+87
View File
@@ -0,0 +1,87 @@
#!/usr/bin/env bash
# Browser acceptance for the Live reader: real Chromium, real frozen core.
#
# Usage:
# MARQDO_BIN=/abs/path/marqdo scripts/test-browser.sh
#
# Requires `cd tests/browser && npm install` once (Playwright + Chromium).
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
: "${MARQDO_BIN:?set MARQDO_BIN to the frozen marqdo binary}"
if [[ ! -x "$MARQDO_BIN" ]]; then
echo "error: MARQDO_BIN is not executable: $MARQDO_BIN" >&2
exit 1
fi
core_before="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-$repo_root/tests/.cache/pw-browsers}"
export MQ_SCREENSHOT_DIR="${MQ_SCREENSHOT_DIR:-$repo_root/tests/browser/artifacts}"
if [[ ! -d "$repo_root/tests/browser/node_modules/playwright" ]]; then
echo "error: Playwright is not installed; run: (cd tests/browser && npm install)" >&2
exit 1
fi
if [[ ! -d "$PLAYWRIGHT_BROWSERS_PATH" ]]; then
echo "error: Chromium is not installed; run: (cd tests/browser && npx playwright install chromium)" >&2
exit 1
fi
binary="$repo_root/target/release/marqdo-view"
if [[ ! -x "$binary" ]]; then
echo "==> cargo build --release --locked"
cargo build --release --locked
fi
server_pid=""
cleanup() {
if [[ -n "$server_pid" ]] && kill -0 "$server_pid" 2>/dev/null; then
kill "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
fi
}
trap cleanup EXIT
run_suite() {
local project="$1"
local log
log="$(mktemp "$repo_root/tests/.cache/browser-server.XXXXXX.log")"
echo "==> browser suite: $project"
"$binary" "$project" --port 0 --no-open >"$log" 2>&1 &
server_pid=$!
local url=""
for _ in $(seq 1 100); do
url="$(grep -o 'http://127.0.0.1:[0-9]*/' "$log" | head -1 || true)"
[[ -n "$url" ]] && break
if ! kill -0 "$server_pid" 2>/dev/null; then
echo "error: server exited during startup:" >&2
cat "$log" >&2
exit 1
fi
sleep 0.1
done
if [[ -z "$url" ]]; then
echo "error: server did not print a URL" >&2
cat "$log" >&2
exit 1
fi
MQ_URL="$url" MQ_PROJECT="$project" node tests/browser/reader.browser.cjs
kill "$server_pid" 2>/dev/null || true
wait "$server_pid" 2>/dev/null || true
server_pid=""
rm -f "$log"
}
mkdir -p "$repo_root/tests/.cache" "$MQ_SCREENSHOT_DIR"
run_suite examples/welcome
run_suite examples/control-flow
run_suite tests/fixtures/security-project
core_after="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
if [[ "$core_before" != "$core_after" ]]; then
echo "error: frozen core binary changed during browser tests" >&2
exit 1
fi
echo "browser: PASS (core sha256 $core_before unchanged; screenshots: $MQ_SCREENSHOT_DIR)"
+30
View File
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Contract-focused gate: formatting, lints, all tests, Tool v1 install smoke,
# static verify and static export against the frozen core. No browser.
#
# Usage: MARQDO_BIN=/abs/path/marqdo scripts/test-contract.sh
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
: "${MARQDO_BIN:?set MARQDO_BIN to the frozen marqdo binary}"
export PATH="${HOME}/.cargo/bin:${PATH}"
export CARGO_HOME="${CARGO_HOME:-$repo_root/.cargo-home}"
cargo fmt --all -- --check
cargo clippy --all-targets -- -D warnings
cargo test --locked
cargo build --release --locked
MARQDO_BIN="$MARQDO_BIN" ./scripts/package.sh
export MARQDO_TOOL_HOME="$repo_root/dist/contract-tool-home"
rm -rf "$MARQDO_TOOL_HOME"
"$MARQDO_BIN" tool install "$repo_root/dist/marqdo-view/tool.json" >/dev/null
"$MARQDO_BIN" view --help >/dev/null
"$MARQDO_BIN" view verify examples/mixed-modes/index.mq.md
"$MARQDO_BIN" view export examples/tables-math --out "$repo_root/dist/contract-site"
test -f "$repo_root/dist/contract-site/manifest.json"
echo "contract: PASS"
+82
View File
@@ -0,0 +1,82 @@
#!/usr/bin/env bash
# Static export acceptance: pure read-only, offline assets, safe paths.
#
# Usage: MARQDO_BIN=/abs/path/marqdo scripts/test-export.sh
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
: "${MARQDO_BIN:?set MARQDO_BIN to the frozen marqdo binary}"
[[ -x "$MARQDO_BIN" ]] || { echo "error: MARQDO_BIN not executable" >&2; exit 1; }
core_before="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
binary="$repo_root/target/release/marqdo-view"
[[ -x "$binary" ]] || cargo build --release --locked
site="$repo_root/dist/test-export-site"
rm -rf "$site"
MARQDO_BIN="$MARQDO_BIN" "$binary" export examples/welcome --out "$site"
python3 - "$site" <<'PY'
import hashlib
import json
import pathlib
import re
import sys
site = pathlib.Path(sys.argv[1])
manifest = json.loads((site / "manifest.json").read_text())
assert manifest["schema"] == "marqdo.view-export"
assert manifest["executed"] is False
assert manifest["pages"], "no pages exported"
for entry in manifest["files"]:
rel = entry["path"]
assert not rel.startswith("/") and ".." not in pathlib.PurePosixPath(rel).parts
data = (site / rel).read_bytes()
assert hashlib.sha256(data).hexdigest() == entry["sha256"], rel
index = (site / "index.html").read_text()
assert "/file?path=" not in index
assert re.search(r'<link rel="stylesheet" href="assets/reader\.[0-9a-f]{16}\.css"', index)
for pattern in ("<script src=\"http", "<link rel=\"stylesheet\" href=\"http", "url(http"):
assert pattern not in index, pattern
print("export manifest: PASS (%d pages, %d files)" % (len(manifest["pages"]), len(manifest["files"])))
PY
# X-04: open the exported site from file:// in a real browser (offline).
if [[ -d "$repo_root/tests/browser/node_modules/playwright" ]]; then
PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-$repo_root/tests/.cache/pw-browsers}" \
MQ_FILE="$site/index.html" node - "$repo_root/tests/browser" <<'JS'
const path = require("path");
const { chromium } = require(path.join(process.argv[2], "node_modules/playwright"));
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1280, height: 800 } });
const external = [];
const errors = [];
page.on("request", (request) => {
if (!request.url().startsWith("file:") && !request.url().startsWith("data:")) {
external.push(request.url());
}
});
page.on("console", (message) => {
if (message.type() === "error") errors.push(message.text());
});
page.on("pageerror", (error) => errors.push(String(error)));
await page.goto("file://" + process.env.MQ_FILE, { waitUntil: "load" });
const text = await page.locator(".mq-document").innerText();
if (text.trim().length < 20) throw new Error("offline page not readable");
if (external.length) throw new Error("offline page requested " + external.join(","));
if (errors.length) throw new Error("offline console errors: " + errors.join(" | "));
if ((await page.locator("link[rel=stylesheet]").count()) !== 1) throw new Error("stylesheet missing");
console.log("file:// offline browser check: PASS");
await browser.close();
})().catch((error) => { console.error(error.message); process.exit(1); });
JS
else
echo "note: Playwright not installed; skipped file:// browser check"
fi
core_after="$(sha256sum "$MARQDO_BIN" | cut -d' ' -f1)"
[[ "$core_before" == "$core_after" ]] || { echo "error: frozen core changed" >&2; exit 1; }
echo "export: PASS (offline site at $site; core sha256 $core_before unchanged)"
+22
View File
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
# Security/contract suite: HTTP boundary, CSRF/Origin, path escapes, XSS
# sanitization, export-no-exec, architectural coupling gates.
#
# Usage: scripts/test-security.sh
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"
cargo test --locked --test http_live
cargo test --locked --test rendering
cargo test --locked --test export
cargo test --locked --test no_coupling
cargo test --locked --test asset_integrity
if [[ -n "${MARQDO_FROZEN_BIN:-}" ]]; then
MARQDO_BIN="$MARQDO_FROZEN_BIN" ./scripts/test-export.sh
else
echo "note: MARQDO_FROZEN_BIN not set; skipped real-core export script"
fi
echo "security: PASS"
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Prove a frozen marqdo release binary is byte-identical before and after a
# command sequence (RFC-VIEW-0002 §2 / §9.4 / §10.2).
#
# Usage:
# scripts/verify-frozen-cli.sh /abs/path/marqdo [-- EXPECTED_SHA256] -- CMD [ARGS...]
# EXPECTED_SHA256=<hex> scripts/verify-frozen-cli.sh /abs/path/marqdo -- CMD [ARGS...]
# scripts/verify-frozen-cli.sh /abs/path/marqdo # version/SHA report only
#
# The script never rebuilds or modifies the CLI. It records the version, the
# SHA-256 before/after, and exits non-zero if the SHA changes or if an expected
# SHA (argument or EXPECTED_SHA256 env) does not match.
set -euo pipefail
core="${1:-}"
if [[ -z "$core" ]]; then
echo "usage: $0 /abs/path/marqdo [-- EXPECTED_SHA256] -- CMD [ARGS...]" >&2
exit 2
fi
shift
expected="${EXPECTED_SHA256:-}"
if [[ "${1:-}" == "--" && ( "${2:-}" =~ ^[0-9a-f]{64}$ ) ]]; then
expected="$2"
shift 2
fi
if [[ "${1:-}" == "--" ]]; then
shift
fi
if [[ ! -x "$core" ]]; then
echo "error: frozen CLI is not executable: $core" >&2
exit 2
fi
sha_before="$(sha256sum "$core" | cut -d' ' -f1)"
version_line="$("$core" --version 2>&1 | head -1)"
if [[ -n "$expected" && "$expected" != "$sha_before" ]]; then
echo "error: frozen CLI SHA-256 mismatch" >&2
echo " expected: $expected" >&2
echo " actual: $sha_before" >&2
exit 1
fi
if [[ $# -gt 0 ]]; then
"$@"
fi
sha_after="$(sha256sum "$core" | cut -d' ' -f1)"
if [[ "$sha_before" != "$sha_after" ]]; then
echo "error: frozen CLI binary changed during the command" >&2
echo " before: $sha_before" >&2
echo " after: $sha_after" >&2
exit 1
fi
printf 'verify-frozen-cli: PASS\n'
printf ' path: %s\n' "$core"
printf ' version: %s\n' "$version_line"
printf ' sha256: %s (unchanged)\n' "$sha_before"