62
fi
63
done
64
65
+# Concurrent installer runs must not share one rc rewrite tmp file, so the
66
+# tmp suffix embeds the process id.
67
+grep -Fq '.composio.tmp.$$' "$repo_root/install.sh" ||
68
+ fail 'install.sh rc rewrites must use a per-process tmp suffix'
69
+
70
# The shell variants are served as standalone scripts, so their shared logic
71
# (including the URL-validation security checks) is intentionally copied.
72
# Enforce that they stay byte-identical except for the shell each hardcodes in
300
if [ "${TEST_INSTALL_HINT:-0}" = 1 ]; then
301
printf '%s\n' '│ Restart your shell so composio is on PATH │'
302
fi
303
+ # Mirror the reconciling CLI: write the managed block to the same startup
304
+ # files the installer verifies. TEST_INSTALL_RECONCILE=0 models stable
305
+ # CLIs that exit 0 without reconciling (they skip marker-bearing files).
306
+ if [ "${TEST_INSTALL_EXIT:-0}" = 0 ] && [ "${TEST_INSTALL_RECONCILE:-1}" = 1 ]; then
307
+ write_block() {
308
+ if [ -f "$1" ] && grep -Fq "$2" "$1"; then
309
+ return 0
310
+ fi
311
+ printf '\n# Composio CLI\n%s\n' "$2" >>"$1"
312
+ }
313
+ case ${3:-} in
314
+ zsh) write_block "$HOME/.zshrc" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\"" ;;
315
+ fish)
316
+ mkdir -p "$HOME/.config/fish"
317
+ write_block "$HOME/.config/fish/config.fish" "set --export PATH \"$COMPOSIO_BIN_DIR\" \$PATH"
318
+ ;;
319
+ bash)
320
+ write_block "$HOME/.bashrc" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\""
321
+ if [ -f "$HOME/.bash_profile" ]; then
322
+ write_block "$HOME/.bash_profile" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\""
323
+ elif [ -f "$HOME/.bash_login" ]; then
324
+ write_block "$HOME/.bash_login" "export PATH=\"$COMPOSIO_BIN_DIR:\$PATH\""
325
+ fi
326
+ ;;
327
+ esac
328
+ fi
329
exit "${TEST_INSTALL_EXIT:-0}"
330
fi
331
exit 98
354
unset CASE_GITHUB_URL CASE_API_BASE CASE_INSTALL_VERSION CASE_INSTALL_SHELL CASE_PLUGINS CASE_QUIET CASE_DEBUG CASE_HELP
355
unset CASE_ALLOW_HTTP_HOST CASE_CHECKSUM_MODE CASE_API_ASSET_URL CASE_BASE_MODE CASE_REDIRECT_DOWNGRADE
356
unset CASE_SHELL_CAPABILITY CASE_INSTALL_EXIT CASE_SETUP_EXIT CASE_VERSION_EXIT CASE_PATH_PREFIX CASE_UNSET_SHELL
326
- unset CASE_CURL_DELAY_URL CASE_CURL_DELAY_SECONDS CASE_SHELL_VALUE CASE_INSTALL_HINT
357
+ unset CASE_CURL_DELAY_URL CASE_CURL_DELAY_SECONDS CASE_SHELL_VALUE CASE_INSTALL_HINT CASE_INSTALL_RECONCILE
358
rm -f "$case_root/curl-parent.pid"
359
: >"$curl_log"
360
: >"$composio_log"
393
TEST_SHELL_CAPABILITY="${CASE_SHELL_CAPABILITY:-supported}" \
394
TEST_INSTALL_EXIT="${CASE_INSTALL_EXIT:-0}" \
395
TEST_INSTALL_HINT="${CASE_INSTALL_HINT:-0}" \
396
+ TEST_INSTALL_RECONCILE="${CASE_INSTALL_RECONCILE:-1}" \
397
TEST_SETUP_EXIT="${CASE_SETUP_EXIT:-0}" \
398
TEST_VERSION_EXIT="${CASE_VERSION_EXIT:-0}" \
399
TEST_CURL_DELAY_URL="${CASE_CURL_DELAY_URL:-}" \
425
TEST_CHECKSUM_MODE=missing \
426
TEST_SHELL_CAPABILITY="${CASE_SHELL_CAPABILITY:-supported}" \
427
TEST_INSTALL_EXIT="${CASE_INSTALL_EXIT:-0}" \
428
+ TEST_INSTALL_RECONCILE="${CASE_INSTALL_RECONCILE:-1}" \
429
TEST_CURL_DELAY_URL="${CASE_CURL_DELAY_URL:-}" \
430
TEST_CURL_DELAY_SECONDS="${CASE_CURL_DELAY_SECONDS:-1}" \
431
TEST_CURL_PARENT_PID_FILE="$case_root/curl-parent.pid" \
449
# for delegated CLI calls, but the ending must reflect only the PATH the
450
# invoking terminal inherited, which does not contain the bin dir here.
451
assert_tail "$output" "$case_b_tail" "$interpreter_name default auto Case B tail"
419
- [[ ! -e "$home/.bashrc" ]] || fail "$interpreter_name delegated default flow must not write rc files"
452
+ grep -Fq "export PATH=\"$bin_dir:\$PATH\"" "$home/.bashrc" || fail "$interpreter_name delegated default flow rc written by the CLI"
453
+ assert_not_contains "$output" 'Updated ~/.bashrc' "$interpreter_name delegated default flow must not rewrite rc files inline"
454
[[ $(wc -l <"$composio_log") -eq 3 ]] || fail "$interpreter_name default flow invoked extra CLI commands"
455
grep -Fq '|--version' "$composio_log" || fail "$interpreter_name version probe"
456
[[ ! -s "$case_root/git.log" ]] || fail "$interpreter_name must not use git"
641
assert_contains "$direct_output" 'Configured zsh shell setup (cli).' "$interpreter_name COMPOSIO_INSTALL_SHELL confirmation"
642
assert_not_contains "$direct_output" 'Required next step' "$interpreter_name COMPOSIO_INSTALL_SHELL must not print setup guidance"
643
assert_tail "$direct_output" "$case_b_tail" "$interpreter_name COMPOSIO_INSTALL_SHELL Case B tail"
610
- [[ ! -e "$direct_home/.zshrc" ]] || fail "$interpreter_name COMPOSIO_INSTALL_SHELL CLI path must not write rc files"
644
+ grep -Fq "export PATH=\"$direct_bin:\$PATH\"" "$direct_home/.zshrc" || fail "$interpreter_name COMPOSIO_INSTALL_SHELL CLI-written block"
645
+ assert_not_contains "$direct_output" 'Updated ~/.zshrc' "$interpreter_name COMPOSIO_INSTALL_SHELL CLI path must not rewrite rc files inline"
646
647
reset_case
648
CASE_INSTALL_SHELL=zsh
815
assert_contains "$shadow_output" "$shadow_dir/composio" "$interpreter_name shadow ending names the shadowing command"
816
assert_tail "$shadow_output" $'To use the newly installed CLI, run:\n\n '"$shadow_install/composio login" "$interpreter_name shadow tail avoids the shadowed bare command"
817
783
- # Pinned old CLI: supports --shell but ignores the invocation-origin hint and
784
- # prints its own boxed restart hint. A relative COMPOSIO_BIN_DIR must never
785
- # reach setup raw; startup files stay untouched; the installer's plain final
818
+ # Pinned old CLI: supports --shell but ignores the invocation-origin hint,
819
+ # prints its own boxed restart hint, and exits 0 without reconciling. A
820
+ # relative COMPOSIO_BIN_DIR must never reach setup raw; the installer must
821
+ # detect the unreconciled startup file and repair it inline; its plain final
822
# block prints after the old hint and supersedes it.
823
reset_case
824
CASE_INSTALL_HINT=1
825
+ CASE_INSTALL_RECONCILE=0
826
oldcli_home="$case_root/oldcli-home"
827
oldcli_work="$case_root/oldcli-work"
828
oldcli_install="$case_root/oldcli-install"
830
oldcli_output=$(cd "$oldcli_work" && run_installer "$oldcli_home" "$oldcli_install" "rel-bin" "$stable_tag" 2>&1)
831
grep -Fq "|installer|$oldcli_work/rel-bin|install --shell bash" "$composio_log" ||
832
fail "$interpreter_name old-CLI setup must receive the resolved absolute bin dir"
796
- [[ ! -e "$oldcli_home/.bashrc" && ! -e "$oldcli_home/.bash_profile" ]] ||
797
- fail "$interpreter_name old-CLI delegation must leave startup files unchanged"
833
+ grep -Fq "export PATH=\"$oldcli_work/rel-bin:\$PATH\"" "$oldcli_home/.bashrc" ||
834
+ fail "$interpreter_name old-CLI delegation must be reconciled inline with the absolute bin dir"
835
+ assert_contains "$oldcli_output" 'Configured bash shell setup (fallback).' "$interpreter_name old-CLI reconciliation disclosure"
836
assert_contains "$oldcli_output" '│ Restart your shell so composio is on PATH │' "$interpreter_name old-CLI restart hint passes through"
837
assert_tail "$oldcli_output" "$case_b_tail" "$interpreter_name old-CLI hint superseded by the installer tail"
838
891
grep -Fq 'alias reconcile-before=1' "$reconcile_home/.zshrc" || fail "$interpreter_name unmanaged content preserved (before block)"
892
grep -Fq 'alias reconcile-after=1' "$reconcile_home/.zshrc" || fail "$interpreter_name unmanaged content preserved (after block)"
893
894
+ # --- Symlinked startup files and mode preservation (managed dotfiles) ---
895
+
896
+ # Inline setup must write through a symlinked rc file: the symlink survives
897
+ # and its target receives the managed block (mirrors the CLI unit test
898
+ # 'preserves a symlinked .zshrc').
899
+ reset_case
900
+ CASE_SHELL_CAPABILITY=unsupported
901
+ CASE_SHELL_VALUE=/bin/zsh
902
+ symlink_home="$case_root/symlink-home"
903
+ symlink_store="$case_root/symlink-store"
904
+ symlink_bin="$case_root/symlink-bin"
905
+ mkdir -p "$symlink_home" "$symlink_store"
906
+ printf '%s\n' 'alias dotfiles-managed=1' >"$symlink_store/zshrc"
907
+ ln -s "$symlink_store/zshrc" "$symlink_home/.zshrc"
908
+ symlink_output=$(run_installer "$symlink_home" "$case_root/symlink-install" "$symlink_bin" "$stable_tag" 2>&1)
909
+ assert_contains "$symlink_output" 'Updated ~/.zshrc' "$interpreter_name symlinked rc update disclosure"
910
+ [[ -L "$symlink_home/.zshrc" ]] || fail "$interpreter_name symlinked rc must stay a symlink"
911
+ [[ $(readlink "$symlink_home/.zshrc") == "$symlink_store/zshrc" ]] || fail "$interpreter_name symlinked rc target must not change"
912
+ [[ $(grep -Fc '# Composio CLI' "$symlink_store/zshrc") -eq 1 ]] || fail "$interpreter_name symlink target must hold one managed block"
913
+ grep -Fq "export PATH=\"$symlink_bin:\$PATH\"" "$symlink_store/zshrc" || fail "$interpreter_name symlink target managed line"
914
+ grep -Fq 'alias dotfiles-managed=1' "$symlink_store/zshrc" || fail "$interpreter_name symlink target unmanaged content preserved"
915
+
916
+ # The inline rewrite must preserve the startup file's permission bits.
917
+ reset_case
918
+ CASE_SHELL_CAPABILITY=unsupported
919
+ CASE_SHELL_VALUE=/bin/zsh
920
+ mode_home="$case_root/mode-home"
921
+ mkdir -p "$mode_home"
922
+ printf '%s\n' 'alias mode-check=1' >"$mode_home/.zshrc"
923
+ chmod 600 "$mode_home/.zshrc"
924
+ run_installer "$mode_home" "$case_root/mode-install" "$case_root/mode-bin" "$stable_tag" >/dev/null 2>&1
925
+ grep -Fq '# Composio CLI' "$mode_home/.zshrc" || fail "$interpreter_name mode-preservation run must write the block"
926
+ case $(uname) in
927
+ Darwin) mode_actual=$(stat -f '%Lp' "$mode_home/.zshrc") ;;
928
+ *) mode_actual=$(stat -c '%a' "$mode_home/.zshrc") ;;
929
+ esac
930
+ [[ $mode_actual == 600 ]] || fail "$interpreter_name inline rewrite must preserve the file mode (got $mode_actual)"
931
+
932
+ # --- Delegated setup verification (stale managed blocks) ---
933
+
934
+ # A delegated CLI that exits 0 without reconciling a pre-seeded stale block
935
+ # must not be trusted: the installer verifies the startup file, reconciles
936
+ # inline, and reports the fallback disclosure with the Case B ending.
937
+ reset_case
938
+ CASE_INSTALL_SHELL=zsh
939
+ CASE_INSTALL_RECONCILE=0
940
+ stale_home="$case_root/stale-delegated-home"
941
+ stale_bin="$case_root/stale-delegated-bin"
942
+ mkdir -p "$stale_home"
943
+ printf '%s\n' 'alias stale-guard=1' '' '# Composio CLI' 'export PATH="/stale/old-bin:$PATH"' >"$stale_home/.zshrc"
944
+ stale_output=$(run_installer "$stale_home" "$case_root/stale-delegated-install" "$stale_bin" "$stable_tag" 2>&1)
945
+ grep -Fq "|installer|$stale_bin|install --shell zsh" "$composio_log" || fail "$interpreter_name stale delegation still delegates first"
946
+ assert_contains "$stale_output" 'Configured zsh shell setup (fallback).' "$interpreter_name stale delegation reconciles inline"
947
+ [[ $(grep -Fc '# Composio CLI' "$stale_home/.zshrc") -eq 1 ]] || fail "$interpreter_name stale reconcile keeps one marker block"
948
+ grep -Fq "export PATH=\"$stale_bin:\$PATH\"" "$stale_home/.zshrc" || fail "$interpreter_name stale reconcile names the current bin dir"
949
+ if grep -Fq '/stale/old-bin' "$stale_home/.zshrc"; then
950
+ fail "$interpreter_name stale managed path must be replaced after delegation"
951
+ fi
952
+ grep -Fq 'alias stale-guard=1' "$stale_home/.zshrc" || fail "$interpreter_name stale reconcile preserves unmanaged content"
953
+ assert_tail "$stale_output" "$case_b_tail" "$interpreter_name stale delegation Case B tail"
954
+
955
# --- Unsafe resolved bin dirs under the default flow (KD3) ---
956
957
unsafe_auto_index=0