test-sync-to-codex-plugin.sh 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  4. REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
  5. SYNC_SCRIPT_SOURCE="$REPO_ROOT/scripts/sync-to-codex-plugin.sh"
  6. BASH_UNDER_TEST="/bin/bash"
  7. PACKAGE_VERSION="1.2.3"
  8. MANIFEST_VERSION="9.8.7"
  9. FAILURES=0
  10. TEST_ROOT=""
  11. pass() {
  12. echo " [PASS] $1"
  13. }
  14. fail() {
  15. echo " [FAIL] $1"
  16. FAILURES=$((FAILURES + 1))
  17. }
  18. assert_equals() {
  19. local actual="$1"
  20. local expected="$2"
  21. local description="$3"
  22. if [[ "$actual" == "$expected" ]]; then
  23. pass "$description"
  24. else
  25. fail "$description"
  26. echo " expected: $expected"
  27. echo " actual: $actual"
  28. fi
  29. }
  30. assert_contains() {
  31. local haystack="$1"
  32. local needle="$2"
  33. local description="$3"
  34. if printf '%s' "$haystack" | grep -Fq -- "$needle"; then
  35. pass "$description"
  36. else
  37. fail "$description"
  38. echo " expected to find: $needle"
  39. fi
  40. }
  41. assert_not_contains() {
  42. local haystack="$1"
  43. local needle="$2"
  44. local description="$3"
  45. if printf '%s' "$haystack" | grep -Fq -- "$needle"; then
  46. fail "$description"
  47. echo " did not expect to find: $needle"
  48. else
  49. pass "$description"
  50. fi
  51. }
  52. assert_matches() {
  53. local haystack="$1"
  54. local pattern="$2"
  55. local description="$3"
  56. if printf '%s' "$haystack" | grep -Eq -- "$pattern"; then
  57. pass "$description"
  58. else
  59. fail "$description"
  60. echo " expected to match: $pattern"
  61. fi
  62. }
  63. assert_not_matches() {
  64. local haystack="$1"
  65. local pattern="$2"
  66. local description="$3"
  67. if printf '%s' "$haystack" | grep -Eq -- "$pattern"; then
  68. fail "$description"
  69. echo " did not expect to match: $pattern"
  70. else
  71. pass "$description"
  72. fi
  73. }
  74. assert_path_absent() {
  75. local path="$1"
  76. local description="$2"
  77. if [[ ! -e "$path" ]]; then
  78. pass "$description"
  79. else
  80. fail "$description"
  81. echo " did not expect path to exist: $path"
  82. fi
  83. }
  84. assert_branch_absent() {
  85. local repo="$1"
  86. local pattern="$2"
  87. local description="$3"
  88. local branches
  89. branches="$(git -C "$repo" branch --list "$pattern")"
  90. if [[ -z "$branches" ]]; then
  91. pass "$description"
  92. else
  93. fail "$description"
  94. echo " did not expect matching branches:"
  95. echo "$branches" | sed 's/^/ /'
  96. fi
  97. }
  98. assert_current_branch() {
  99. local repo="$1"
  100. local expected="$2"
  101. local description="$3"
  102. local actual
  103. actual="$(git -C "$repo" branch --show-current)"
  104. assert_equals "$actual" "$expected" "$description"
  105. }
  106. assert_file_equals() {
  107. local path="$1"
  108. local expected="$2"
  109. local description="$3"
  110. local actual
  111. actual="$(cat "$path")"
  112. assert_equals "$actual" "$expected" "$description"
  113. }
  114. cleanup() {
  115. if [[ -n "$TEST_ROOT" && -d "$TEST_ROOT" ]]; then
  116. rm -rf "$TEST_ROOT"
  117. fi
  118. }
  119. configure_git_identity() {
  120. local repo="$1"
  121. git -C "$repo" config user.name "Test Bot"
  122. git -C "$repo" config user.email "test@example.com"
  123. }
  124. init_repo() {
  125. local repo="$1"
  126. git init -q -b main "$repo"
  127. configure_git_identity "$repo"
  128. }
  129. commit_fixture() {
  130. local repo="$1"
  131. local message="$2"
  132. git -C "$repo" commit -q -m "$message"
  133. }
  134. checkout_fixture_branch() {
  135. local repo="$1"
  136. local branch="$2"
  137. git -C "$repo" checkout -q -b "$branch"
  138. }
  139. write_upstream_fixture() {
  140. local repo="$1"
  141. local with_pure_ignored="${2:-1}"
  142. mkdir -p \
  143. "$repo/.codex-plugin" \
  144. "$repo/.kimi-plugin" \
  145. "$repo/.private-journal" \
  146. "$repo/assets" \
  147. "$repo/evals/drill" \
  148. "$repo/hooks" \
  149. "$repo/scripts" \
  150. "$repo/skills/example"
  151. if [[ "$with_pure_ignored" == "1" ]]; then
  152. mkdir -p "$repo/ignored-cache/tmp"
  153. fi
  154. cp "$SYNC_SCRIPT_SOURCE" "$repo/scripts/sync-to-codex-plugin.sh"
  155. cat > "$repo/package.json" <<EOF
  156. {
  157. "name": "fixture-upstream",
  158. "version": "$PACKAGE_VERSION"
  159. }
  160. EOF
  161. cat > "$repo/.gitignore" <<'EOF'
  162. .private-journal/
  163. EOF
  164. if [[ "$with_pure_ignored" == "1" ]]; then
  165. cat >> "$repo/.gitignore" <<'EOF'
  166. ignored-cache/
  167. EOF
  168. fi
  169. cat > "$repo/.codex-plugin/plugin.json" <<EOF
  170. {
  171. "name": "superpowers",
  172. "version": "$MANIFEST_VERSION"
  173. }
  174. EOF
  175. cat > "$repo/.kimi-plugin/plugin.json" <<EOF
  176. {
  177. "name": "superpowers",
  178. "version": "$MANIFEST_VERSION"
  179. }
  180. EOF
  181. cat > "$repo/assets/superpowers-small.svg" <<'EOF'
  182. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"></svg>
  183. EOF
  184. printf 'png fixture\n' > "$repo/assets/app-icon.png"
  185. printf 'eval harness fixture\n' > "$repo/evals/drill/README.md"
  186. cat > "$repo/hooks/hooks-codex.json" <<'EOF'
  187. {
  188. "hooks": {
  189. "SessionStart": [
  190. {
  191. "matcher": "startup|resume|clear",
  192. "hooks": [
  193. {
  194. "type": "command",
  195. "command": "\"${PLUGIN_ROOT}/hooks/run-hook.cmd\" session-start-codex",
  196. "async": false
  197. }
  198. ]
  199. }
  200. ]
  201. }
  202. }
  203. EOF
  204. cat > "$repo/hooks/session-start" <<'EOF'
  205. #!/usr/bin/env sh
  206. echo "session-start fixture"
  207. EOF
  208. cat > "$repo/hooks/session-start-codex" <<'EOF'
  209. #!/usr/bin/env sh
  210. echo "session-start-codex fixture"
  211. EOF
  212. cat > "$repo/hooks/run-hook.cmd" <<'EOF'
  213. @echo off
  214. echo run-hook fixture
  215. EOF
  216. chmod +x "$repo/hooks/session-start" "$repo/hooks/session-start-codex" "$repo/hooks/run-hook.cmd"
  217. cat > "$repo/skills/example/SKILL.md" <<'EOF'
  218. # Example Skill
  219. Fixture content.
  220. EOF
  221. printf 'tracked keep\n' > "$repo/.private-journal/keep.txt"
  222. printf 'ignored leak\n' > "$repo/.private-journal/leak.txt"
  223. if [[ "$with_pure_ignored" == "1" ]]; then
  224. printf 'ignored cache state\n' > "$repo/ignored-cache/tmp/state.json"
  225. fi
  226. git -C "$repo" add \
  227. .codex-plugin/plugin.json \
  228. .kimi-plugin/plugin.json \
  229. .gitignore \
  230. assets/app-icon.png \
  231. assets/superpowers-small.svg \
  232. evals/drill/README.md \
  233. hooks/hooks-codex.json \
  234. hooks/run-hook.cmd \
  235. hooks/session-start \
  236. hooks/session-start-codex \
  237. package.json \
  238. scripts/sync-to-codex-plugin.sh \
  239. skills/example/SKILL.md
  240. git -C "$repo" add -f .private-journal/keep.txt
  241. commit_fixture "$repo" "Initial upstream fixture"
  242. }
  243. write_destination_fixture() {
  244. local repo="$1"
  245. mkdir -p "$repo/plugins/superpowers/skills/example"
  246. printf 'fixture keep\n' > "$repo/plugins/superpowers/.fixture-keep"
  247. cat > "$repo/plugins/superpowers/skills/example/SKILL.md" <<'EOF'
  248. # Example Skill
  249. Fixture content.
  250. EOF
  251. git -C "$repo" add plugins/superpowers/.fixture-keep
  252. git -C "$repo" add plugins/superpowers/skills/example/SKILL.md
  253. commit_fixture "$repo" "Initial destination fixture"
  254. }
  255. add_openai_agent_metadata_fixture() {
  256. local repo="$1"
  257. mkdir -p "$repo/plugins/superpowers/skills/example/agents"
  258. cat > "$repo/plugins/superpowers/skills/example/agents/openai.yaml" <<'EOF'
  259. interface:
  260. display_name: "Example"
  261. short_description: "Destination-owned OpenAI metadata"
  262. EOF
  263. git -C "$repo" add plugins/superpowers/skills/example/agents/openai.yaml
  264. commit_fixture "$repo" "Add OpenAI agent metadata fixture"
  265. }
  266. dirty_tracked_destination_skill() {
  267. local repo="$1"
  268. cat > "$repo/plugins/superpowers/skills/example/SKILL.md" <<'EOF'
  269. # Example Skill
  270. Locally modified fixture content.
  271. EOF
  272. }
  273. write_synced_destination_fixture() {
  274. local repo="$1"
  275. mkdir -p \
  276. "$repo/plugins/superpowers/.codex-plugin" \
  277. "$repo/plugins/superpowers/.private-journal" \
  278. "$repo/plugins/superpowers/assets" \
  279. "$repo/plugins/superpowers/hooks" \
  280. "$repo/plugins/superpowers/skills/example/agents" \
  281. "$repo/plugins/superpowers/skills/example"
  282. cat > "$repo/plugins/superpowers/.codex-plugin/plugin.json" <<EOF
  283. {
  284. "name": "superpowers",
  285. "version": "$MANIFEST_VERSION"
  286. }
  287. EOF
  288. cat > "$repo/plugins/superpowers/assets/superpowers-small.svg" <<'EOF'
  289. <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1"></svg>
  290. EOF
  291. printf 'png fixture\n' > "$repo/plugins/superpowers/assets/app-icon.png"
  292. cat > "$repo/plugins/superpowers/hooks/hooks-codex.json" <<'EOF'
  293. {
  294. "hooks": {
  295. "SessionStart": [
  296. {
  297. "matcher": "startup|resume|clear",
  298. "hooks": [
  299. {
  300. "type": "command",
  301. "command": "\"${PLUGIN_ROOT}/hooks/run-hook.cmd\" session-start-codex",
  302. "async": false
  303. }
  304. ]
  305. }
  306. ]
  307. }
  308. }
  309. EOF
  310. cat > "$repo/plugins/superpowers/hooks/session-start" <<'EOF'
  311. #!/usr/bin/env sh
  312. echo "session-start fixture"
  313. EOF
  314. cat > "$repo/plugins/superpowers/hooks/session-start-codex" <<'EOF'
  315. #!/usr/bin/env sh
  316. echo "session-start-codex fixture"
  317. EOF
  318. cat > "$repo/plugins/superpowers/hooks/run-hook.cmd" <<'EOF'
  319. @echo off
  320. echo run-hook fixture
  321. EOF
  322. chmod +x "$repo/plugins/superpowers/hooks/session-start" "$repo/plugins/superpowers/hooks/session-start-codex" "$repo/plugins/superpowers/hooks/run-hook.cmd"
  323. cat > "$repo/plugins/superpowers/skills/example/SKILL.md" <<'EOF'
  324. # Example Skill
  325. Fixture content.
  326. EOF
  327. cat > "$repo/plugins/superpowers/skills/example/agents/openai.yaml" <<'EOF'
  328. interface:
  329. display_name: "Example"
  330. short_description: "Destination-owned OpenAI metadata"
  331. EOF
  332. printf 'tracked keep\n' > "$repo/plugins/superpowers/.private-journal/keep.txt"
  333. git -C "$repo" add \
  334. plugins/superpowers/.codex-plugin/plugin.json \
  335. plugins/superpowers/assets/app-icon.png \
  336. plugins/superpowers/assets/superpowers-small.svg \
  337. plugins/superpowers/hooks/hooks-codex.json \
  338. plugins/superpowers/hooks/run-hook.cmd \
  339. plugins/superpowers/hooks/session-start \
  340. plugins/superpowers/hooks/session-start-codex \
  341. plugins/superpowers/skills/example/agents/openai.yaml \
  342. plugins/superpowers/skills/example/SKILL.md \
  343. plugins/superpowers/.private-journal/keep.txt
  344. commit_fixture "$repo" "Initial synced destination fixture"
  345. }
  346. write_stale_ignored_destination_fixture() {
  347. local repo="$1"
  348. mkdir -p \
  349. "$repo/plugins/superpowers/.kimi-plugin" \
  350. "$repo/plugins/superpowers/.private-journal"
  351. printf 'fixture keep\n' > "$repo/plugins/superpowers/.fixture-keep"
  352. printf '{"name":"stale-kimi"}\n' > "$repo/plugins/superpowers/.kimi-plugin/plugin.json"
  353. printf 'stale ignored leak\n' > "$repo/plugins/superpowers/.private-journal/leak.txt"
  354. git -C "$repo" add \
  355. plugins/superpowers/.fixture-keep \
  356. plugins/superpowers/.kimi-plugin/plugin.json
  357. commit_fixture "$repo" "Initial stale ignored destination fixture"
  358. }
  359. write_fake_gh() {
  360. local bin_dir="$1"
  361. mkdir -p "$bin_dir"
  362. cat > "$bin_dir/gh" <<'EOF'
  363. #!/usr/bin/env bash
  364. set -euo pipefail
  365. if [[ "${1:-}" == "auth" && "${2:-}" == "status" ]]; then
  366. exit 0
  367. fi
  368. echo "unexpected gh invocation: $*" >&2
  369. exit 1
  370. EOF
  371. chmod +x "$bin_dir/gh"
  372. }
  373. run_preview() {
  374. local upstream="$1"
  375. local dest="$2"
  376. local fake_bin="$3"
  377. PATH="$fake_bin:$PATH" "$BASH_UNDER_TEST" "$upstream/scripts/sync-to-codex-plugin.sh" -n --local "$dest" 2>&1
  378. }
  379. run_bootstrap_preview() {
  380. local upstream="$1"
  381. local dest="$2"
  382. local fake_bin="$3"
  383. PATH="$fake_bin:$PATH" "$BASH_UNDER_TEST" "$upstream/scripts/sync-to-codex-plugin.sh" -n --bootstrap --local "$dest" 2>&1
  384. }
  385. run_preview_without_manifest() {
  386. local upstream="$1"
  387. local dest="$2"
  388. local fake_bin="$3"
  389. rm -f "$upstream/.codex-plugin/plugin.json"
  390. PATH="$fake_bin:$PATH" "$BASH_UNDER_TEST" "$upstream/scripts/sync-to-codex-plugin.sh" -n --local "$dest" 2>&1
  391. }
  392. run_preview_with_stale_ignored_destination() {
  393. local upstream="$1"
  394. local dest="$2"
  395. local fake_bin="$3"
  396. PATH="$fake_bin:$PATH" "$BASH_UNDER_TEST" "$upstream/scripts/sync-to-codex-plugin.sh" -n --local "$dest" 2>&1
  397. }
  398. run_apply() {
  399. local upstream="$1"
  400. local dest="$2"
  401. local fake_bin="$3"
  402. PATH="$fake_bin:$PATH" "$BASH_UNDER_TEST" "$upstream/scripts/sync-to-codex-plugin.sh" -y --local "$dest" 2>&1
  403. }
  404. run_help() {
  405. local upstream="$1"
  406. local fake_bin="$2"
  407. PATH="$fake_bin:$PATH" "$BASH_UNDER_TEST" "$upstream/scripts/sync-to-codex-plugin.sh" --help 2>&1
  408. }
  409. write_bootstrap_destination_fixture() {
  410. local repo="$1"
  411. printf 'bootstrap fixture\n' > "$repo/README.md"
  412. git -C "$repo" add README.md
  413. commit_fixture "$repo" "Initial bootstrap destination fixture"
  414. }
  415. main() {
  416. local upstream
  417. local mixed_only_upstream
  418. local dest
  419. local dest_branch
  420. local mixed_only_dest
  421. local stale_dest
  422. local dirty_apply_dest
  423. local dirty_apply_dest_branch
  424. local noop_apply_dest
  425. local noop_apply_dest_branch
  426. local fake_bin
  427. local bootstrap_dest
  428. local bootstrap_dest_branch
  429. local preview_status
  430. local preview_output
  431. local preview_section
  432. local bootstrap_status
  433. local bootstrap_output
  434. local missing_manifest_status
  435. local missing_manifest_output
  436. local mixed_only_status
  437. local mixed_only_output
  438. local stale_preview_status
  439. local stale_preview_output
  440. local stale_preview_section
  441. local dirty_apply_status
  442. local dirty_apply_output
  443. local noop_apply_status
  444. local noop_apply_output
  445. local help_output
  446. local script_source
  447. local dirty_skill_path
  448. local noop_openai_metadata_path
  449. echo "=== Test: sync-to-codex-plugin dry-run regression ==="
  450. TEST_ROOT="$(mktemp -d)"
  451. trap cleanup EXIT
  452. upstream="$TEST_ROOT/upstream"
  453. mixed_only_upstream="$TEST_ROOT/mixed-only-upstream"
  454. dest="$TEST_ROOT/destination"
  455. mixed_only_dest="$TEST_ROOT/mixed-only-destination"
  456. stale_dest="$TEST_ROOT/stale-destination"
  457. dirty_apply_dest="$TEST_ROOT/dirty-apply-destination"
  458. dirty_apply_dest_branch="fixture/dirty-apply-target"
  459. noop_apply_dest="$TEST_ROOT/noop-apply-destination"
  460. noop_apply_dest_branch="fixture/noop-apply-target"
  461. bootstrap_dest="$TEST_ROOT/bootstrap-destination"
  462. dest_branch="fixture/preview-target"
  463. bootstrap_dest_branch="fixture/bootstrap-preview-target"
  464. fake_bin="$TEST_ROOT/bin"
  465. init_repo "$upstream"
  466. write_upstream_fixture "$upstream"
  467. init_repo "$mixed_only_upstream"
  468. write_upstream_fixture "$mixed_only_upstream" 0
  469. init_repo "$dest"
  470. write_destination_fixture "$dest"
  471. add_openai_agent_metadata_fixture "$dest"
  472. checkout_fixture_branch "$dest" "$dest_branch"
  473. dirty_tracked_destination_skill "$dest"
  474. init_repo "$mixed_only_dest"
  475. write_destination_fixture "$mixed_only_dest"
  476. init_repo "$stale_dest"
  477. write_stale_ignored_destination_fixture "$stale_dest"
  478. init_repo "$dirty_apply_dest"
  479. write_synced_destination_fixture "$dirty_apply_dest"
  480. checkout_fixture_branch "$dirty_apply_dest" "$dirty_apply_dest_branch"
  481. dirty_tracked_destination_skill "$dirty_apply_dest"
  482. init_repo "$noop_apply_dest"
  483. write_synced_destination_fixture "$noop_apply_dest"
  484. checkout_fixture_branch "$noop_apply_dest" "$noop_apply_dest_branch"
  485. init_repo "$bootstrap_dest"
  486. write_bootstrap_destination_fixture "$bootstrap_dest"
  487. checkout_fixture_branch "$bootstrap_dest" "$bootstrap_dest_branch"
  488. write_fake_gh "$fake_bin"
  489. # This regression test is about dry-run content, so capture the preview
  490. # output even if the current script exits nonzero in --local mode.
  491. set +e
  492. preview_output="$(run_preview "$upstream" "$dest" "$fake_bin")"
  493. preview_status=$?
  494. bootstrap_output="$(run_bootstrap_preview "$upstream" "$bootstrap_dest" "$fake_bin")"
  495. bootstrap_status=$?
  496. mixed_only_output="$(run_preview "$mixed_only_upstream" "$mixed_only_dest" "$fake_bin")"
  497. mixed_only_status=$?
  498. stale_preview_output="$(run_preview_with_stale_ignored_destination "$upstream" "$stale_dest" "$fake_bin")"
  499. stale_preview_status=$?
  500. dirty_apply_output="$(run_apply "$upstream" "$dirty_apply_dest" "$fake_bin")"
  501. dirty_apply_status=$?
  502. noop_apply_output="$(run_apply "$upstream" "$noop_apply_dest" "$fake_bin")"
  503. noop_apply_status=$?
  504. missing_manifest_output="$(run_preview_without_manifest "$upstream" "$dest" "$fake_bin")"
  505. missing_manifest_status=$?
  506. set -e
  507. help_output="$(run_help "$upstream" "$fake_bin")"
  508. script_source="$(cat "$upstream/scripts/sync-to-codex-plugin.sh")"
  509. preview_section="$(printf '%s\n' "$preview_output" | sed -n '/^=== Preview (rsync --dry-run) ===$/,/^=== End preview ===$/p')"
  510. stale_preview_section="$(printf '%s\n' "$stale_preview_output" | sed -n '/^=== Preview (rsync --dry-run) ===$/,/^=== End preview ===$/p')"
  511. dirty_skill_path="$dirty_apply_dest/plugins/superpowers/skills/example/SKILL.md"
  512. noop_openai_metadata_path="$noop_apply_dest/plugins/superpowers/skills/example/agents/openai.yaml"
  513. echo ""
  514. echo "Preview assertions..."
  515. assert_equals "$preview_status" "0" "Preview exits successfully"
  516. assert_contains "$preview_output" "Version: $MANIFEST_VERSION" "Preview uses manifest version"
  517. assert_not_contains "$preview_output" "Version: $PACKAGE_VERSION" "Preview does not use package.json version"
  518. assert_contains "$preview_section" ".codex-plugin/plugin.json" "Preview includes manifest path"
  519. assert_not_contains "$preview_section" ".kimi-plugin/plugin.json" "Preview excludes Kimi manifest from Codex sync"
  520. assert_contains "$preview_section" "assets/superpowers-small.svg" "Preview includes SVG asset"
  521. assert_contains "$preview_section" "assets/app-icon.png" "Preview includes PNG asset"
  522. assert_contains "$preview_section" "hooks/hooks-codex.json" "Preview includes Codex hook manifest"
  523. assert_contains "$preview_section" "hooks/session-start" "Preview includes session-start hook"
  524. assert_contains "$preview_section" "hooks/session-start-codex" "Preview includes Codex session-start hook"
  525. assert_contains "$preview_section" "hooks/run-hook.cmd" "Preview includes hook command wrapper"
  526. assert_contains "$preview_section" ".private-journal/keep.txt" "Preview includes tracked ignored file"
  527. assert_not_contains "$preview_section" ".private-journal/leak.txt" "Preview excludes ignored untracked file"
  528. assert_not_contains "$preview_section" "ignored-cache/" "Preview excludes pure ignored directories"
  529. assert_not_contains "$preview_section" "evals/" "Preview excludes eval harness"
  530. assert_not_contains "$preview_output" "Overlay file (.codex-plugin/plugin.json) will be regenerated" "Preview omits overlay regeneration note"
  531. assert_not_contains "$preview_output" "Assets (superpowers-small.svg, app-icon.png) will be seeded from" "Preview omits assets seeding note"
  532. assert_contains "$preview_section" "skills/example/SKILL.md" "Preview reflects dirty tracked destination file"
  533. assert_not_matches "$preview_section" "\\*deleting +skills/example/agents/openai\\.yaml" "Preview preserves destination-owned OpenAI agent metadata"
  534. assert_current_branch "$dest" "$dest_branch" "Preview leaves destination checkout on its original branch"
  535. assert_branch_absent "$dest" "sync/superpowers-*" "Preview does not create sync branch in destination checkout"
  536. echo ""
  537. echo "Mixed-directory assertions..."
  538. assert_equals "$mixed_only_status" "0" "Mixed ignored directory preview exits successfully under /bin/bash"
  539. assert_contains "$mixed_only_output" ".private-journal/keep.txt" "Mixed ignored directory preview still includes tracked ignored file"
  540. assert_not_contains "$mixed_only_output" "ignored-cache/" "Mixed ignored directory preview has no pure ignored directory fixture"
  541. echo ""
  542. echo "Convergence assertions..."
  543. assert_equals "$stale_preview_status" "0" "Stale ignored destination preview exits successfully"
  544. assert_matches "$stale_preview_section" "\\*deleting +\\.kimi-plugin/plugin\\.json" "Preview deletes stale Kimi manifest from Codex plugin"
  545. assert_matches "$stale_preview_section" "\\*deleting +\\.private-journal/leak\\.txt" "Preview deletes stale ignored destination file"
  546. echo ""
  547. echo "Bootstrap assertions..."
  548. assert_equals "$bootstrap_status" "0" "Bootstrap preview exits successfully"
  549. assert_contains "$bootstrap_output" "Mode: BOOTSTRAP (creating plugins/superpowers/ when absent)" "Bootstrap preview describes directory creation"
  550. assert_not_contains "$bootstrap_output" "Assets:" "Bootstrap preview omits external assets path"
  551. assert_contains "$bootstrap_output" "Dry run only. Nothing was changed or pushed." "Bootstrap preview remains dry-run only"
  552. assert_path_absent "$bootstrap_dest/plugins/superpowers" "Bootstrap preview does not create destination plugin directory"
  553. assert_current_branch "$bootstrap_dest" "$bootstrap_dest_branch" "Bootstrap preview leaves destination checkout on its original branch"
  554. assert_branch_absent "$bootstrap_dest" "bootstrap/superpowers-*" "Bootstrap preview does not create bootstrap branch in destination checkout"
  555. echo ""
  556. echo "Apply assertions..."
  557. assert_equals "$dirty_apply_status" "1" "Dirty local apply exits with failure"
  558. assert_contains "$dirty_apply_output" "ERROR: local checkout has uncommitted changes under 'plugins/superpowers'" "Dirty local apply reports protected destination path"
  559. assert_current_branch "$dirty_apply_dest" "$dirty_apply_dest_branch" "Dirty local apply leaves destination checkout on its original branch"
  560. assert_branch_absent "$dirty_apply_dest" "sync/superpowers-*" "Dirty local apply does not create sync branch in destination checkout"
  561. assert_file_equals "$dirty_skill_path" "# Example Skill
  562. Locally modified fixture content." "Dirty local apply preserves tracked working-tree file content"
  563. assert_equals "$noop_apply_status" "0" "Clean no-op local apply exits successfully"
  564. assert_contains "$noop_apply_output" "No changes — embedded plugin was already in sync with upstream" "Clean no-op local apply reports no changes"
  565. assert_current_branch "$noop_apply_dest" "$noop_apply_dest_branch" "Clean no-op local apply leaves destination checkout on its original branch"
  566. assert_branch_absent "$noop_apply_dest" "sync/superpowers-*" "Clean no-op local apply does not create sync branch in destination checkout"
  567. assert_file_equals "$noop_openai_metadata_path" "interface:
  568. display_name: \"Example\"
  569. short_description: \"Destination-owned OpenAI metadata\"" "Clean no-op local apply preserves OpenAI agent metadata"
  570. echo ""
  571. echo "Missing manifest assertions..."
  572. assert_equals "$missing_manifest_status" "1" "Missing manifest exits with failure"
  573. assert_contains "$missing_manifest_output" "ERROR: committed Codex manifest missing at" "Missing manifest reports committed manifest path"
  574. echo ""
  575. echo "Help assertions..."
  576. assert_not_contains "$help_output" "--assets-src" "Help omits --assets-src"
  577. echo ""
  578. echo "Source assertions..."
  579. assert_not_contains "$script_source" "regenerated inline" "Source drops regenerated inline phrasing"
  580. assert_not_contains "$script_source" "Brand Assets directory" "Source drops Brand Assets directory phrasing"
  581. assert_not_contains "$script_source" "--assets-src" "Source drops --assets-src"
  582. if [[ $FAILURES -ne 0 ]]; then
  583. echo ""
  584. echo "FAILED: $FAILURES assertion(s) failed."
  585. exit 1
  586. fi
  587. echo ""
  588. echo "PASS"
  589. }
  590. main "$@"