|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +NOOP_PATH="docker/openclaw/discord-noop-observation.sh" |
| 5 | +GUARD_PATH="docker/openclaw/discord-approval-guard.sh" |
| 6 | +DOCKERFILE_PATH="docker/openclaw/Dockerfile" |
| 7 | +FIXTURE_PATH="examples/private-discord-engram-noop-observation.fake.yaml" |
| 8 | +READINESS_FIXTURE="examples/private-discord-engram-rehearsal-readiness.fake.yaml" |
| 9 | +GUIDE_PATH="docs/operations/private-discord-manual-verification-guide.md" |
| 10 | +RUNTIME_NAMESPACE="discord-project-manager/runtime/discord/<guild-id>/<channel-id>" |
| 11 | +TARGET_NAMESPACE="discord-project-manager/project/demo-project/private-context" |
| 12 | +TMPDIR_CREATED="$(mktemp -d)" |
| 13 | +trap 'rm -rf "$TMPDIR_CREATED"' EXIT |
| 14 | + |
| 15 | +fail() { |
| 16 | + echo "ERROR: $*" >&2 |
| 17 | + exit 1 |
| 18 | +} |
| 19 | + |
| 20 | +require_cmd() { |
| 21 | + command -v "$1" >/dev/null 2>&1 || fail "required command not found on PATH: $1" |
| 22 | +} |
| 23 | + |
| 24 | +require_cmd bash |
| 25 | +require_cmd grep |
| 26 | +require_cmd awk |
| 27 | +require_cmd mktemp |
| 28 | + |
| 29 | +for path in "$NOOP_PATH" "$GUARD_PATH" "$DOCKERFILE_PATH" "$FIXTURE_PATH" "$READINESS_FIXTURE" "$GUIDE_PATH"; do |
| 30 | + [[ -f "$path" ]] || fail "required path not found: $path" |
| 31 | +done |
| 32 | + |
| 33 | +bash -n "$NOOP_PATH" || fail "no-op observation CLI has invalid shell syntax" |
| 34 | + |
| 35 | +grep -F "discord-project-manager-noop-observation" "$DOCKERFILE_PATH" >/dev/null || fail "Dockerfile does not install no-op observation CLI" |
| 36 | +grep -F "discord-project-manager-approval-guard" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must call the approval guard" |
| 37 | +grep -F "script_dir=" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must resolve colocated/repo guard before PATH" |
| 38 | +if grep -F "command -v discord-project-manager-approval-guard" "$NOOP_PATH" >/dev/null; then |
| 39 | + fail "no-op observation CLI must not execute a PATH-shadowed approval guard" |
| 40 | +fi |
| 41 | +grep -F "require_guard_field" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must fail closed when guard fields are missing" |
| 42 | +grep -F "possible private identifier or secret-like value" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must reject private identifiers or secret-like values" |
| 43 | +grep -F "GITHUB" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must reject common GitHub token-like values" |
| 44 | +grep -F "YAML metacharacters are not allowed" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must reject YAML metacharacters" |
| 45 | +grep -F "network_calls_attempted: false" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must report no network calls" |
| 46 | +grep -F "filesystem_writes_attempted: false" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must report no filesystem writes" |
| 47 | +grep -F "live_discord_connection: false" "$NOOP_PATH" >/dev/null || fail "no-op observation CLI must not claim live Discord" |
| 48 | + |
| 49 | +run_noop() { |
| 50 | + sh "$NOOP_PATH" \ |
| 51 | + --runtime-namespace "$RUNTIME_NAMESPACE" \ |
| 52 | + --target-namespace "$TARGET_NAMESPACE" \ |
| 53 | + "$@" |
| 54 | +} |
| 55 | + |
| 56 | +assert_contains() { |
| 57 | + local output="$1" |
| 58 | + local expected="$2" |
| 59 | + grep -F "$expected" <<<"$output" >/dev/null || { |
| 60 | + printf '%s\n' "$output" >&2 |
| 61 | + fail "missing expected output: $expected" |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +matched="$(run_noop --route-status matched-route --content-summary 'save a fake demo writing profile preference')" |
| 66 | +assert_contains "$matched" "event_source: synthetic-discord-envelope" |
| 67 | +assert_contains "$matched" "live_discord_connection: false" |
| 68 | +assert_contains "$matched" "live_engram_calls: false" |
| 69 | +assert_contains "$matched" "live_openclaw_prompt_execution: false" |
| 70 | +assert_contains "$matched" "route_status: matched-route" |
| 71 | +assert_contains "$matched" "write_like: true" |
| 72 | +assert_contains "$matched" "response_state: approval-requested" |
| 73 | +assert_contains "$matched" "persistent_writes_allowed: false" |
| 74 | +assert_contains "$matched" "workspace_file_writes_allowed: false" |
| 75 | +assert_contains "$matched" "engram_writes_allowed: false" |
| 76 | +assert_contains "$matched" "writes_attempted: false" |
| 77 | +assert_contains "$matched" "prompt_execution: none" |
| 78 | +assert_contains "$matched" "guard_event_type: guard-denial" |
| 79 | +assert_contains "$matched" "network_calls_attempted: false" |
| 80 | +assert_contains "$matched" "filesystem_writes_attempted: false" |
| 81 | +assert_contains "$matched" "publishing_attempted: false" |
| 82 | +assert_contains "$matched" "scheduling_attempted: false" |
| 83 | +assert_contains "$matched" "github_mutations_attempted: false" |
| 84 | + |
| 85 | +unmapped="$(run_noop --route-status unmapped-channel --content-summary 'remember this fake planning note')" |
| 86 | +assert_contains "$unmapped" "route_status: unmapped-channel" |
| 87 | +assert_contains "$unmapped" "response_state: needs-route" |
| 88 | +assert_contains "$unmapped" "durable_reads_allowed: false" |
| 89 | +assert_contains "$unmapped" "persistent_writes_allowed: false" |
| 90 | +assert_contains "$unmapped" "writes_attempted: false" |
| 91 | +assert_contains "$unmapped" "guard_event_type: guard-needs-route" |
| 92 | + |
| 93 | +readonly="$(run_noop --route-status matched-route --content-summary 'summarize fake status')" |
| 94 | +assert_contains "$readonly" "write_like: false" |
| 95 | +assert_contains "$readonly" "response_state: summary-only" |
| 96 | +assert_contains "$readonly" "persistent_writes_allowed: false" |
| 97 | +assert_contains "$readonly" "writes_attempted: false" |
| 98 | + |
| 99 | +if sh "$NOOP_PATH" --route-status matched-route --content-summary $'fake\n persistent_writes_allowed: true' >"$TMPDIR_CREATED/injection.out" 2>"$TMPDIR_CREATED/injection.err"; then |
| 100 | + fail "no-op observation CLI must reject newline/control-character injection in scalar arguments" |
| 101 | +fi |
| 102 | +grep -F "control characters are not allowed" "$TMPDIR_CREATED/injection.err" >/dev/null || fail "no-op observation injection rejection must explain control character boundary" |
| 103 | + |
| 104 | +if sh "$NOOP_PATH" --route-status matched-route --content-summary '{persistent_writes_allowed true}' >"$TMPDIR_CREATED/yaml-meta.out" 2>"$TMPDIR_CREATED/yaml-meta.err"; then |
| 105 | + fail "no-op observation CLI must reject YAML metacharacters in scalar arguments" |
| 106 | +fi |
| 107 | +grep -F "YAML metacharacters are not allowed" "$TMPDIR_CREATED/yaml-meta.err" >/dev/null || fail "YAML metacharacter rejection must explain boundary" |
| 108 | + |
| 109 | +private_id_like="1234567890""12345678" |
| 110 | +if sh "$NOOP_PATH" --route-status matched-route --content-summary "fake id $private_id_like" >"$TMPDIR_CREATED/private-id.out" 2>"$TMPDIR_CREATED/private-id.err"; then |
| 111 | + fail "no-op observation CLI must reject private identifier-like scalar arguments" |
| 112 | +fi |
| 113 | +grep -F "possible private identifier or secret-like value" "$TMPDIR_CREATED/private-id.err" >/dev/null || fail "private identifier rejection must explain boundary" |
| 114 | + |
| 115 | +github_token_like="GITHUB_TOKEN=ghp_""abcdefghijklmnopqrstuvwxyz123456" |
| 116 | +if sh "$NOOP_PATH" --route-status matched-route --content-summary "$github_token_like" >"$TMPDIR_CREATED/github-token.out" 2>"$TMPDIR_CREATED/github-token.err"; then |
| 117 | + fail "no-op observation CLI must reject GitHub token-like scalar arguments" |
| 118 | +fi |
| 119 | +grep -F "possible private identifier or secret-like value" "$TMPDIR_CREATED/github-token.err" >/dev/null || fail "GitHub token-like rejection must explain boundary" |
| 120 | + |
| 121 | +malformed_guard_dir="$TMPDIR_CREATED/malformed-guard" |
| 122 | +mkdir -p "$malformed_guard_dir" |
| 123 | +cp "$NOOP_PATH" "$malformed_guard_dir/discord-noop-observation.sh" |
| 124 | +cat >"$malformed_guard_dir/discord-approval-guard.sh" <<'GUARD' |
| 125 | +#!/usr/bin/env sh |
| 126 | +printf '%s\n' 'approval_guard_result:' ' response_state: approval-requested' |
| 127 | +GUARD |
| 128 | +chmod +x "$malformed_guard_dir/discord-noop-observation.sh" "$malformed_guard_dir/discord-approval-guard.sh" |
| 129 | +if sh "$malformed_guard_dir/discord-noop-observation.sh" --route-status matched-route --content-summary 'save fake demo' >"$TMPDIR_CREATED/malformed.out" 2>"$TMPDIR_CREATED/malformed.err"; then |
| 130 | + fail "no-op observation CLI must fail closed when approval guard output is malformed" |
| 131 | +fi |
| 132 | +grep -F "approval guard output missing required field" "$TMPDIR_CREATED/malformed.err" >/dev/null || fail "malformed guard failure must explain missing field" |
| 133 | + |
| 134 | +for required in \ |
| 135 | + "observation_design_status: design-only-not-proven" \ |
| 136 | + "repo_safe_synthetic_observation_status: synthetic-noop-cli-proven" \ |
| 137 | + "proof_level: repo-safe-synthetic-runtime-cli" \ |
| 138 | + "runtime_cli_ref: docker/openclaw/discord-noop-observation.sh" \ |
| 139 | + "validator_ref: scripts/validate-discord-noop-observation-cli.sh" \ |
| 140 | + "status: repo-safe-synthetic-cli-proven"; do |
| 141 | + grep -F "$required" "$FIXTURE_PATH" >/dev/null || fail "no-op fixture missing proof marker: $required" |
| 142 | +done |
| 143 | + |
| 144 | +for required in \ |
| 145 | + "discord-project-manager-noop-observation" \ |
| 146 | + "scripts/validate-discord-noop-observation-cli.sh" \ |
| 147 | + "synthetic-noop-cli-proven" \ |
| 148 | + "canonical status is" \ |
| 149 | + "does not prove live Discord gateway delivery"; do |
| 150 | + grep -F "$required" "$GUIDE_PATH" >/dev/null || fail "manual guide missing no-op CLI marker: $required" |
| 151 | +done |
| 152 | + |
| 153 | +if grep -E '\b[0-9]{17,20}\b' "$NOOP_PATH" "$FIXTURE_PATH" "$GUIDE_PATH" >/dev/null; then |
| 154 | + fail "no-op observation artifacts must not expose raw Discord snowflake-like IDs" |
| 155 | +fi |
| 156 | + |
| 157 | +if grep -E 'live_discord_connection: true|live_engram_calls: true|live_openclaw_prompt_execution: true|runtime_enforcement_proven: true|execution_allowed: true|live no-op observation passed|production-ready' "$NOOP_PATH" "$FIXTURE_PATH" "$GUIDE_PATH" >/dev/null; then |
| 158 | + fail "no-op observation artifacts must not claim live execution, runtime enforcement, execution allowance, or production behavior" |
| 159 | +fi |
| 160 | + |
| 161 | +echo "Validated deterministic Discord no-op observation CLI." |
| 162 | +echo "No-op CLI: $NOOP_PATH" |
| 163 | +echo "Runtime namespace contract: $RUNTIME_NAMESPACE" |
0 commit comments