#!/usr/bin/env bash
set -uo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
FAIL=0
note() { echo "[v142-guards] $*"; }
die() { echo "[v142-guards] FAIL: $*" >&2; FAIL=1; }
pin_tag() {
local tag
tag="$(grep -m1 "$1.*tag = " "$REPO_ROOT/Cargo.toml" | sed -E 's/.*tag = "([^"]+)".*/\1/')"
[[ -z "$tag" ]] && { echo "[v142-guards] FAIL: 守卫常量派生失败(Cargo.toml 无 $1 tag 钉面)" >&2; exit 1; }
echo "$tag"
}
KERNEL_TAG="$(pin_tag 'xwkernel.git')"
# 守卫一: kernel 三件钉同钉 KERNEL_TAG(Cargo.toml [workspace.dependencies] 声明面,
# S6.1 收口判据)。[patch] 段条目排除——patch 是重定向面, 声明面三钉为判据本体。
# 红侧: 声明面任一钉偏离 KERNEL_TAG → 失守。
assert_v142_kernel_triple_pin() {
local n
n="$(awk -v tag="$KERNEL_TAG" '/^\[workspace\.dependencies\]/{inp=1;next} /^\[/{inp=0} inp && /^(kernel|kernel-macros|kernel-loader) = \{ git = .*tag = "/ && $0 ~ ("\"" tag "\"") {c++} END{print c+0}' "$REPO_ROOT/Cargo.toml")"
if [[ "$n" == "3" ]]; then
note "v142_kernel_triple_pin: kernel 声明面三钉同钉 $KERNEL_TAG ✓"
else
die "kernel 声明面三钉同钉 $KERNEL_TAG 计数=$n, 期望 3"
fi
}
assert_v142_retired_surface_absent() {
local leak=0
[[ -d "$REPO_ROOT/crates/xw-cli" ]] && leak=1
[[ -f "$REPO_ROOT/crates/xw-runtime/src/m3_seam_adapter.rs" ]] && leak=1
[[ -f "$REPO_ROOT/crates/xw-runtime/src/diagnostic_seam.rs" ]] && leak=1
if [[ "$leak" == "0" ]]; then
note "v142_retired_surface_absent: xw-cli 全 crate + seam 桥迁出面主线缺席 ✓"
else
die "退役面主线残留(xw-cli 目录存在 / m3_seam_adapter / diagnostic_seam)——全 crate 退役语义破坏"
fi
}
assert_v142_cone_lock_alive() {
local f="$REPO_ROOT/scripts/tests/cone_lock_reverse_lookup.sh"
if [[ -x "$f" ]] && grep -q '\[cone-lookup\]' "$f"; then
note "v142_cone_lock_alive: cone_lock_reverse_lookup.sh 存活可执行 ✓"
else
die "scripts/tests/cone_lock_reverse_lookup.sh 缺失/不可执行/失去 [cone-lookup] 代码标识"
fi
}
assert_v142_kernel_triple_pin
assert_v142_retired_surface_absent
assert_v142_cone_lock_alive
if [[ "$FAIL" -eq 0 ]]; then
note "三守卫全过 ✓"
fi
exit "$FAIL"