#!/usr/bin/env bash
set -euo pipefail

ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
output="$(env -i HOME="$HOME" PATH="/usr/bin:/bin" "$ROOT/wrappers/codex.sh" --health)"

node - "$output" <<'NODE'
const result = JSON.parse(process.argv[2]);
if (result.ok !== true || !String(result.version || '').startsWith('codex-cli ')) {
  throw new Error(`unexpected health result: ${JSON.stringify(result)}`);
}
console.log('PASS: codex wrapper resolves installed CLI with daemon-style PATH');
NODE
