summaryrefslogtreecommitdiff
path: root/tests/cli.test.sh
diff options
context:
space:
mode:
authorChristopher Warner <cwarner@kernelcode.com>2026-10-10 18:42:38 -0400
committerChristopher Warner <cwarner@kernelcode.com>2026-10-10 18:42:38 -0400
commit78862ba855c6e66cac64a86c25dca6149d8fb2fd (patch)
tree8259c5337ba7ef0e08ea25f720770ac79510573c /tests/cli.test.sh
parent50b9b2b4c0db6a5e1d9dd511d062d99ae2e11dd3 (diff)
downloadiphone-notes-78862ba855c6e66cac64a86c25dca6149d8fb2fd.tar.gz
iphone-notes-78862ba855c6e66cac64a86c25dca6149d8fb2fd.tar.bz2
iphone-notes-78862ba855c6e66cac64a86c25dca6149d8fb2fd.tar.xz
iphone-notes-78862ba855c6e66cac64a86c25dca6149d8fb2fd.zip
test: cover helpers, dry-run CLI, and conventional commits
Extract pure note helpers for unit tests, add ICLOUD_NOTES_DRY_RUN so create and status can be exercised without Chromium, and gate git history on Conventional Commits 1.0.0 subjects. Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'tests/cli.test.sh')
-rwxr-xr-xtests/cli.test.sh82
1 files changed, 79 insertions, 3 deletions
diff --git a/tests/cli.test.sh b/tests/cli.test.sh
index aefb371..d3f8d88 100755
--- a/tests/cli.test.sh
+++ b/tests/cli.test.sh
@@ -1,19 +1,29 @@
#!/usr/bin/env bash
-# Smoke tests for icloud-note CLI (no Apple login / network create required).
+# CLI smoke + dry-run tests (no Apple network / no visible browser).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
CLI=(node "$ROOT/scripts/icloud-note.mjs")
+TMP="$(mktemp -d)"
+trap 'rm -rf "$TMP"' EXIT
+export ICLOUD_NOTES_CONFIG="$TMP/cfg"
+export ICLOUD_NOTES_DRY_RUN=1
fail() { echo "FAIL: $*" >&2; exit 1; }
pass() { echo "ok: $*"; }
-out="$("${CLI[@]}" help 2>&1)" || fail "help exited non-zero"
-[[ "$out" == *"icloud-note create"* ]] || fail "help missing create usage"
+# --- help ---
+for flag in help -h --help; do
+ out="$("${CLI[@]}" "$flag" 2>&1)" || fail "help ($flag) exited non-zero"
+ [[ "$out" == *"icloud-note create"* ]] || fail "help missing create ($flag)"
+done
+out="$("${CLI[@]}" help 2>&1)"
[[ "$out" == *"headless"* ]] || fail "help should say create/status are headless"
[[ "$out" != *"--headed"* ]] || fail "help must not advertise --headed"
+[[ "$out" == *"$ICLOUD_NOTES_CONFIG"* ]] || fail "help should show ICLOUD_NOTES_CONFIG path"
pass "help"
+# --- unknown ---
set +e
err="$("${CLI[@]}" nosuchcmd 2>&1)"
code=$?
@@ -22,6 +32,7 @@ set -e
[[ "$err" == *"Unknown command"* ]] || fail "unknown command message"
pass "unknown command"
+# --- create validation ---
set +e
err="$("${CLI[@]}" create 2>&1)"
code=$?
@@ -30,4 +41,69 @@ set -e
[[ "$err" == *"Provide --title"* ]] || fail "create empty message"
pass "create requires content"
+# --- create dry-run (no browser) ---
+out="$("${CLI[@]}" create --title "T" --body "hello" 2>&1)" || fail "create dry-run failed"
+[[ "$out" == *'dry-run: would create note title="T"'* ]] || fail "create dry-run output: $out"
+[[ "$out" == *"chars="* ]] || fail "create dry-run missing chars"
+pass "create dry-run --title/--body"
+
+printf 'from file\n' > "$TMP/body.txt"
+out="$("${CLI[@]}" create --title "FileNote" --body-file "$TMP/body.txt" 2>&1)" \
+ || fail "create body-file failed"
+[[ "$out" == *'title="FileNote"'* ]] || fail "body-file title: $out"
+pass "create --body-file"
+
+out="$(printf 'stdin body' | "${CLI[@]}" create --title "Stdin" --body-file - 2>&1)" \
+ || fail "create stdin body-file failed"
+[[ "$out" == *'title="Stdin"'* ]] || fail "stdin title: $out"
+pass "create --body-file -"
+
+out="$("${CLI[@]}" create "Positional" --body "x" 2>&1)" || fail "positional create failed"
+[[ "$out" == *'title="Positional"'* ]] || fail "positional title: $out"
+pass "create positional title"
+
+# --- status dry-run without session ---
+set +e
+err="$("${CLI[@]}" status 2>&1)"
+code=$?
+set -e
+[[ "$code" -ne 0 ]] || fail "status without session should fail"
+[[ "$err" == *"No saved session"* ]] || fail "status empty message: $err"
+pass "status dry-run without session"
+
+mkdir -p "$ICLOUD_NOTES_CONFIG"
+echo '{"cookies":[]}' > "$ICLOUD_NOTES_CONFIG/storage-state.json"
+out="$("${CLI[@]}" status 2>&1)" || fail "status dry-run with state failed"
+[[ "$out" == *"dry-run status"* ]] || fail "status dry-run ok: $out"
+pass "status dry-run with session file"
+
+# --- login dry-run must not open a browser ---
+set +e
+err="$("${CLI[@]}" login 2>&1)"
+code=$?
+set -e
+[[ "$code" -ne 0 ]] || fail "login dry-run should refuse"
+[[ "$err" == *"dry-run"* ]] || fail "login dry-run message: $err"
+pass "login dry-run refuses browser"
+
+# --- login without display (real path, no dry-run) ---
+unset ICLOUD_NOTES_DRY_RUN
+set +e
+err="$(env -u DISPLAY -u WAYLAND_DISPLAY ICLOUD_NOTES_CONFIG="$ICLOUD_NOTES_CONFIG" \
+ "${CLI[@]}" login 2>&1)"
+code=$?
+set -e
+[[ "$code" -ne 0 ]] || fail "login without DISPLAY should fail"
+[[ "$err" == *"graphical session"* ]] || fail "login DISPLAY message: $err"
+pass "login requires graphical session"
+
+# --- setup script present ---
+[[ -x "$ROOT/scripts/setup.sh" ]] || fail "setup.sh not executable"
+pass "setup.sh executable"
+
+# --- skill / docs mention headless ---
+rg -q 'headless' "$ROOT/SKILL.md" || fail "SKILL.md should mention headless"
+rg -q 'headless' "$ROOT/README.md" || fail "README.md should mention headless"
+pass "docs mention headless"
+
echo "All cli tests passed."