-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreflight.sh
More file actions
167 lines (147 loc) · 5.78 KB
/
Copy pathpreflight.sh
File metadata and controls
167 lines (147 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
set -uo pipefail
TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LIB="$TEST_DIR/../hooks/lib-companion.sh"
D=$(mktemp -d)
pass() {
printf 'PASS %s: %s\n' "$1" "$2"
}
fail() {
printf 'FAIL %s: %s\n' "$1" "$2"
exit 1
}
REAL_NODE=$(node -p 'process.execPath')
[ -n "$REAL_NODE" ] && [ -x "$REAL_NODE" ] ||
fail 0 "cannot resolve a real node binary"
mkdir -p "$D/shim"
{
printf '#!/usr/bin/env bash\n'
printf 'exec "%s" "$@"\n' "$REAL_NODE"
} > "$D/shim/node"
chmod +x "$D/shim/node"
export PATH="$D/shim:$PATH"
mkdir -p "$D/home/.codex"
printf 'model = "gpt-5.6-sol"\nmodel_reasoning_effort = "high"\n' > "$D/home/.codex/config.toml"
printf 'high\n' > "$D/home/.codex/maestro-impl-effort"
export HOME="$D/home"
LOG="$D/argv.log"
ERR="$D/stderr.log"
trap 'rm -rf "$D"' EXIT
. "$LIB"
companion_pin >/dev/null 2>&1 ||
fail 0 "no Codex pin; cannot exercise preflight"
cat > "$D/stub.cjs" <<'EOF'
const fs = require("node:fs");
const path = require("node:path");
const args = process.argv.slice(2);
fs.appendFileSync(process.env.PREFLIGHT_LOG, `${args.join(" ")}\n`);
if (args[0] === "--help") {
switch (path.basename(__filename, ".cjs")) {
case "drifted":
console.log("Usage:\n node x task [--background] [--model <m>] [--effort <none|minimal|low|medium|high|xhigh>] [prompt]");
break;
case "capable":
console.log("Usage:\n node x task [--background] [--write] [--model <m>] [--effort <none|minimal|low|medium|high|xhigh>] [prompt]");
break;
case "misleading":
console.log("Usage:\n node x task [--background] [--model <m>] [prompt]\n node x review [--write] [prompt]");
break;
case "silent":
break;
case "erroring":
console.error("error: unknown option '--help'");
process.exitCode = 1;
break;
}
} else if (args[0] === "task") {
console.log("started task-fake-abc123");
}
EOF
for stub in drifted capable misleading silent erroring; do
cp "$D/stub.cjs" "$D/$stub.cjs"
done
export PREFLIGHT_LOG="$LOG"
run_start() {
local stub=$1
local mode=${2:-read}
local job_file="$D/start.job" stdout="$D/start.stdout"
: > "$LOG"
: > "$ERR"
rm -f "$job_file" "$stdout"
if [ "$mode" = "write" ]; then
mkdir -p "$D/lease"
printf 'token=preflight-token\npid=%s\nprocess_start=unavailable\njob_id=unknown\nsession_id=preflight\nstarted_at=2026-01-01T00:00:00Z\nstarted_epoch=1\ndigest_before=unavailable\n' \
"$$" > "$D/lease/metadata"
export MAESTRO_LOCK_ACQUIRED=1 MAESTRO_LOCK_TOKEN=preflight-token MAESTRO_LOCK_DIR="$D/lease"
companion_start "$D/$stub.cjs" "hello" write gpt-5.6-sol high : \
"$job_file" "$stdout" "$ERR" 2>> "$ERR"
RC=$?
else
companion_start "$D/$stub.cjs" "hello" read gpt-5.6-sol high : \
"$job_file" "$stdout" "$ERR" 2>> "$ERR"
RC=$?
fi
OUTPUT=$(cat "$job_file" 2>/dev/null)
}
run_start drifted write
[ "$RC" -eq 3 ] ||
fail 1 "drifted write returned rc=$RC, want 3; output: $OUTPUT"
grep -qi 'flag drift' "$ERR" ||
fail 1 "drifted write did not report flag drift; stderr: $(cat "$ERR")"
grep -q '^task\( \|$\)' "$LOG" &&
fail 1 "drifted write attempted a task dispatch"
pass 1 "conclusive flag drift refuses write dispatch"
run_start misleading write
[ "$RC" -eq 3 ] ||
fail 1b "unrelated --write returned rc=$RC, want 3; output: $OUTPUT"
grep -qi 'flag drift' "$ERR" ||
fail 1b "unrelated --write did not report task flag drift; stderr: $(cat "$ERR")"
grep -q '^task\( \|$\)' "$LOG" &&
fail 1b "--write from another subcommand authorized a task dispatch"
pass 1b "--write on another subcommand does not authorize task"
run_start capable write
[ "$RC" -eq 0 ] ||
fail 2 "capable write returned rc=$RC, want 0; stderr: $(cat "$ERR")"
[ "$OUTPUT" = "task-fake-abc123" ] ||
fail 2 "capable write returned unexpected job id: $OUTPUT"
grep -q '^task .*--write' "$LOG" ||
fail 2 "capable write task invocation omitted --write"
grep -q '^task .*--effort high' "$LOG" ||
fail 2 "write task invocation omitted the explicit implementation effort"
pass 2 "advertised --write dispatches with explicit implementation effort"
run_start silent write
[ "$RC" -eq 0 ] ||
fail 3 "silent help blocked write dispatch with rc=$RC; stderr: $(cat "$ERR")"
grep -q '^task\( \|$\)' "$LOG" ||
fail 3 "silent help did not proceed to task dispatch"
pass 3 "silent help is inconclusive and does not block"
run_start erroring write
[ "$RC" -eq 0 ] ||
fail 4 "erroring help blocked write dispatch with rc=$RC; stderr: $(cat "$ERR")"
grep -q '^task\( \|$\)' "$LOG" ||
fail 4 "erroring help did not proceed to task dispatch"
pass 4 "erroring help is inconclusive and does not block"
run_start drifted
[ "$RC" -eq 0 ] ||
fail 5 "read-only dispatch returned rc=$RC; stderr: $(cat "$ERR")"
grep -q '^--help\( \|$\)' "$LOG" &&
fail 5 "read-only dispatch paid for a help probe"
grep -q '^task\( \|$\)' "$LOG" ||
fail 5 "read-only invocation did not dispatch a task"
grep -q -- '--write' "$LOG" &&
fail 5 "read-only task invocation included --write"
grep -q '^task .*--effort high' "$LOG" ||
fail 5 "read-only invocation omitted the explicit debate effort"
pass 5 "read-only dispatch skips the compatibility probe and pins debate effort"
CACHE="$HOME/.claude/plugins/cache/openai-codex/codex"
mkdir -p "$CACHE/1.0.2/scripts" "$CACHE/1.0.10/scripts"
: > "$CACHE/1.0.2/scripts/codex-companion.mjs"
: > "$CACHE/1.0.10/scripts/codex-companion.mjs"
sleep 1
touch "$CACHE/1.0.2/scripts/codex-companion.mjs"
RESOLVED=$(companion_resolve)
[ "$RESOLVED" = "$CACHE/1.0.10/scripts/codex-companion.mjs" ] ||
fail 6 "resolved $RESOLVED, want highest semantic version 1.0.10"
pass 6 "runtime companion resolution ignores cache mtime and selects highest semantic version"
echo "VERIFY PASS: task-scoped write preflight, inconclusive help allowed, read-only probe skipped, highest companion version selected"
exit 0