summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Vincent <jesse@fsck.com>2026-10-23 03:47:21 +0000
committerJesse Vincent <jesse@fsck.com>2026-10-23 03:48:33 +0000
commitf713233eee9143d0a798976fd0d11609f91c0b5c (patch)
tree4aa32416b4a63178f738f17ecbfb82fd5d520310
parentb58deb3b948d4c305feeac122700100419ee2777 (diff)
fix(codex): accept linked git worktrees as checkoutsfix/codex-scripts-in-worktrees
package-codex-plugin.sh and sync-to-codex-plugin.sh checked for a checkout with [[ -d .git ]]. In a linked worktree .git is a file, so both scripts died with "not a git checkout" there, and tests/codex/test-package-codex-plugin.sh failed 9 checks when run from any worktree. Test that .git exists instead: it covers both layouts and still requires the path to be the root of a checkout, which matters for sync's user-supplied --local path. The scripts' later git commands already work in worktrees. Regression tests run the package script from a linked worktree of the repo, and a sync preview from a linked upstream worktree into a linked destination worktree. The package test is adapted from #1910. Co-authored-by: tianma-if <tianma-if@users.noreply.github.com> Claude-Session: https://claude.ai/code/session_01SHANcr4A71nzuU9et4Fnba
-rwxr-xr-xscripts/package-codex-plugin.sh2
-rwxr-xr-xscripts/sync-to-codex-plugin.sh4
-rwxr-xr-xtests/codex-plugin-sync/test-sync-to-codex-plugin.sh28
-rwxr-xr-xtests/codex/test-package-codex-plugin.sh22
4 files changed, 53 insertions, 3 deletions
diff --git a/scripts/package-codex-plugin.sh b/scripts/package-codex-plugin.sh
index 5308e28..fe90862 100755
--- a/scripts/package-codex-plugin.sh
+++ b/scripts/package-codex-plugin.sh
@@ -140,7 +140,7 @@ if [[ "$FORMAT" == "zip" ]]; then
command -v unzip >/dev/null || die "unzip not found in PATH"
fi
-[[ -d "$REPO_ROOT/.git" ]] || die "repo root is not a git checkout: $REPO_ROOT"
+[[ -e "$REPO_ROOT/.git" ]] || die "repo root is not a git checkout: $REPO_ROOT"
git -C "$REPO_ROOT" rev-parse --verify "$REF^{commit}" >/dev/null ||
die "git ref does not resolve to a commit: $REF"
diff --git a/scripts/sync-to-codex-plugin.sh b/scripts/sync-to-codex-plugin.sh
index fc80ab2..d1c65ca 100755
--- a/scripts/sync-to-codex-plugin.sh
+++ b/scripts/sync-to-codex-plugin.sh
@@ -179,7 +179,7 @@ command -v python3 >/dev/null || die "python3 not found in PATH"
gh auth status >/dev/null 2>&1 || die "gh not authenticated — run 'gh auth login'"
-[[ -d "$UPSTREAM/.git" ]] || die "upstream '$UPSTREAM' is not a git checkout"
+[[ -e "$UPSTREAM/.git" ]] || die "upstream '$UPSTREAM' is not a git checkout"
[[ -f "$UPSTREAM/.codex-plugin/plugin.json" ]] || die "committed Codex manifest missing at $UPSTREAM/.codex-plugin/plugin.json"
# Read the upstream version from the committed Codex manifest.
@@ -223,7 +223,7 @@ trap cleanup EXIT
if [[ -n "$LOCAL_CHECKOUT" ]]; then
DEST_REPO="$(cd "$LOCAL_CHECKOUT" && pwd)"
- [[ -d "$DEST_REPO/.git" ]] || die "--local path '$DEST_REPO' is not a git checkout"
+ [[ -e "$DEST_REPO/.git" ]] || die "--local path '$DEST_REPO' is not a git checkout"
else
echo "Cloning $FORK..."
CLEANUP_DIR="$(mktemp -d)"
diff --git a/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh b/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh
index 84282c2..fb3aaa7 100755
--- a/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh
+++ b/tests/codex-plugin-sync/test-sync-to-codex-plugin.sh
@@ -571,6 +571,12 @@ main() {
local bootstrap_output
local missing_manifest_status
local missing_manifest_output
+ local linked_upstream_main
+ local linked_upstream
+ local linked_dest_main
+ local linked_dest
+ local linked_preview_status
+ local linked_preview_output
local mixed_only_status
local mixed_only_output
local stale_preview_status
@@ -603,6 +609,10 @@ main() {
dest_branch="fixture/preview-target"
bootstrap_dest_branch="fixture/bootstrap-preview-target"
fake_bin="$TEST_ROOT/bin"
+ linked_upstream_main="$TEST_ROOT/linked-upstream-main"
+ linked_upstream="$TEST_ROOT/linked-upstream"
+ linked_dest_main="$TEST_ROOT/linked-destination-main"
+ linked_dest="$TEST_ROOT/linked-destination"
init_repo "$upstream"
write_upstream_fixture "$upstream"
@@ -635,6 +645,17 @@ main() {
write_bootstrap_destination_fixture "$bootstrap_dest"
checkout_fixture_branch "$bootstrap_dest" "$bootstrap_dest_branch"
+ # The sync script wants upstream on main, so park the primary checkout
+ # on another branch and check main out in the linked worktree.
+ init_repo "$linked_upstream_main"
+ write_upstream_fixture "$linked_upstream_main"
+ git -C "$linked_upstream_main" switch -q -c fixture/parked
+ git -C "$linked_upstream_main" worktree add -q "$linked_upstream" main
+
+ init_repo "$linked_dest_main"
+ write_destination_fixture "$linked_dest_main"
+ git -C "$linked_dest_main" worktree add -q -b fixture/linked-target "$linked_dest"
+
write_fake_gh "$fake_bin"
# This regression test is about dry-run content, so capture the preview
@@ -654,6 +675,8 @@ main() {
noop_apply_status=$?
missing_manifest_output="$(run_preview_without_manifest "$upstream" "$dest" "$fake_bin")"
missing_manifest_status=$?
+ linked_preview_output="$(run_preview "$linked_upstream" "$linked_dest" "$fake_bin")"
+ linked_preview_status=$?
set -e
help_output="$(run_help "$upstream" "$fake_bin")"
script_source="$(cat "$upstream/scripts/sync-to-codex-plugin.sh")"
@@ -731,6 +754,11 @@ Locally modified fixture content." "Dirty local apply preserves tracked working-
short_description: \"Destination-owned OpenAI metadata\"" "Clean no-op local apply preserves OpenAI agent metadata"
echo ""
+ echo "Linked worktree assertions..."
+ assert_equals "$linked_preview_status" "0" "Preview from a linked worktree into a linked worktree exits successfully"
+ assert_not_contains "$linked_preview_output" "is not a git checkout" "Linked worktrees are accepted as git checkouts"
+
+ echo ""
echo "Missing manifest assertions..."
assert_equals "$missing_manifest_status" "1" "Missing manifest exits with failure"
assert_contains "$missing_manifest_output" "ERROR: committed Codex manifest missing at" "Missing manifest reports committed manifest path"
diff --git a/tests/codex/test-package-codex-plugin.sh b/tests/codex/test-package-codex-plugin.sh
index 947cb6d..05e150a 100755
--- a/tests/codex/test-package-codex-plugin.sh
+++ b/tests/codex/test-package-codex-plugin.sh
@@ -9,6 +9,7 @@ FAILURES=0
TEST_ROOT="$(mktemp -d)"
cleanup() {
+ git -C "$REPO_ROOT" worktree remove --force "$TEST_ROOT/linked-worktree" >/dev/null 2>&1 || true
rm -rf "$TEST_ROOT"
}
trap cleanup EXIT
@@ -138,6 +139,8 @@ archive="$TEST_ROOT/superpowers"
tar_archive="$TEST_ROOT/superpowers.tar.gz"
extracted="$TEST_ROOT/extracted"
tar_extracted="$TEST_ROOT/tar-extracted"
+worktree_archive="$TEST_ROOT/superpowers-from-worktree.zip"
+linked_worktree="$TEST_ROOT/linked-worktree"
write_metadata_fixture "$metadata_source"
source_hooks="$(python3 -c 'import json; print(json.load(open("'"$REPO_ROOT"'/.codex-plugin/plugin.json")).get("hooks"))')"
@@ -160,6 +163,25 @@ assert_contains "$output" "Archive:" "reports archive path"
assert_contains "$output" "Format: zip" "reports default zip format"
assert_contains "$output" "SHA-256:" "reports archive checksum"
+if git -C "$REPO_ROOT" worktree add -q --detach "$linked_worktree" HEAD >/dev/null 2>&1; then
+ # The worktree is checked out at HEAD, so copy in the script under test
+ # (it may have uncommitted edits); that dirties the tree, hence --allow-dirty.
+ cp "$SCRIPT_UNDER_TEST" "$linked_worktree/scripts/package-codex-plugin.sh"
+ if output="$("$linked_worktree/scripts/package-codex-plugin.sh" --allow-dirty --metadata-source "$metadata_source" --output "$worktree_archive" 2>&1)"; then
+ pass "package script accepts a linked worktree checkout"
+ else
+ fail "package script accepts a linked worktree checkout"
+ printf '%s\n' "$output" | sed 's/^/ /'
+ fi
+ if [[ -f "$worktree_archive" ]]; then
+ pass "package script writes archive from a linked worktree"
+ else
+ fail "package script writes archive from a linked worktree"
+ fi
+else
+ fail "create linked worktree fixture"
+fi
+
extract_archive "$archive" "$extracted"
archive_paths="$(list_archive "$archive" | normalize_archive_paths)"