#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" LINUXCNC_ROOT="${LINUXCNC_ROOT:-$ROOT_DIR/../linuxcnc}" UPSTREAM="$LINUXCNC_ROOT/src/emc/task/emctask.cc" SUBSET_SRC="$ROOT_DIR/vendor/linuxcnc/src/emc/task/emctask_wasm_subset.cc" SUBSET_HDR="$ROOT_DIR/vendor/linuxcnc/src/emc/task/emctask_wasm_subset.hh" TASK_WRAPPER="$ROOT_DIR/runtime/core/linuxcnc_wrap/linuxcnc_task_hal_wasm.cpp" WASM_TEST="$ROOT_DIR/tests/wasm/node/verify_task_hal_wasm.mjs" MATRIX="$ROOT_DIR/working/04-任务矩阵.md" fail() { printf 'task_emctask_update_snapshot_status=fail\n' printf 'task_emctask_update_snapshot_error=%s\n' "$1" exit 1 } require_file() { local label="$1" local file="$2" [[ -f "$file" ]] || fail "$label missing: $file" printf 'task_emctask_update_snapshot_%s=ok\n' "$label" } require_text() { local label="$1" local file="$2" local text="$3" grep -Fq "$text" "$file" || fail "$label missing" printf 'task_emctask_update_snapshot_%s=ok\n' "$label" } require_file upstream "$UPSTREAM" require_file subset_source "$SUBSET_SRC" require_file subset_header "$SUBSET_HDR" require_file task_wrapper "$TASK_WRAPPER" require_file wasm_test "$WASM_TEST" require_file matrix "$MATRIX" require_text upstream_determine_mode "$UPSTREAM" "EMC_TASK_MODE determineMode(" require_text upstream_determine_state "$UPSTREAM" "static EMC_TASK_STATE determineState(" require_text upstream_update "$UPSTREAM" "int emcTaskUpdate(" require_text subset_update "$SUBSET_HDR" "lc_emctask_subset_update" require_text subset_update_impl "$SUBSET_SRC" "lc_emctask_subset_update" require_text wrapper_motion_snapshot_input "$TASK_WRAPPER" "state.motion_snapshot.coord_mode" require_text wrapper_motion_enabled_input "$TASK_WRAPPER" "state.motion_snapshot.motion_enabled" require_text wrapper_io_estop_input "$TASK_WRAPPER" "emctask_subset_io_estop" require_text wrapper_update_source "$TASK_WRAPPER" "motionSnapshot,ioSnapshot" require_text wrapper_snapshot_count "$TASK_WRAPPER" "snapshotUpdateCount" require_text wasm_test_asserts_source "$WASM_TEST" "updateInputSource" require_text wasm_test_asserts_count "$WASM_TEST" "snapshotUpdateCount" require_text matrix_t038_done "$MATRIX" '| T-038 | `emctask.cc` determine/update 子集 | 完成 |' require_text matrix_t039_done "$MATRIX" '| T-039 | `emctask.cc` plan wait/synch/open/close 子集 | 完成 |' printf 'task_emctask_update_snapshot_status=ok\n'