blob: 083f73ab171c6e32da034539ecc4d5217b8b564c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
#!/usr/bin/env bash
# CLI smoke + dry-run tests (no Apple network / no visible browser).
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT"
cargo build -q
CLI=("$ROOT/target/debug/icloud-note")
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: $*"; }
# --- help ---
out="$("${CLI[@]}" 2>&1)" || fail "no-args help failed"
[[ "$out" == *"icloud-note create"* ]] || fail "help missing create: $out"
[[ "$out" == *"icloud-note update"* ]] || fail "help missing update: $out"
[[ "$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"
set +e
out_h="$("${CLI[@]}" -h 2>&1)"
code_h=$?
set -e
[[ "$code_h" -eq 0 ]] || fail "-h exited $code_h"
[[ "$out_h" == *"create"* || "$out_h" == *"Create"* ]] || fail "-h missing create"
pass "help"
# --- unknown ---
set +e
err="$("${CLI[@]}" nosuchcmd 2>&1)"
code=$?
set -e
[[ "$code" -ne 0 ]] || fail "unknown command should fail"
pass "unknown command"
# --- create validation ---
set +e
err="$("${CLI[@]}" create 2>&1)"
code=$?
set -e
[[ "$code" -ne 0 ]] || fail "create without content should fail"
[[ "$err" == *"Provide --title"* ]] || fail "create empty message: $err"
pass "create requires content"
# --- create dry-run ---
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"
# --- update validation / dry-run ---
set +e
err="$("${CLI[@]}" update --body "x" 2>&1)"
code=$?
set -e
[[ "$code" -ne 0 ]] || fail "update without title should fail"
[[ "$err" == *"Provide --title"* ]] || fail "update empty title message: $err"
pass "update requires title"
out="$("${CLI[@]}" update --title "Existing" --body "revised" 2>&1)" \
|| fail "update dry-run failed"
[[ "$out" == *'dry-run: would update note match="Existing"'* ]] || fail "update dry-run: $out"
[[ "$out" == *'title="Existing"'* ]] || fail "update dry-run title: $out"
pass "update dry-run"
out="$("${CLI[@]}" update --match-title "Old" --title "New" --body "x" 2>&1)" \
|| fail "update match-title dry-run failed"
[[ "$out" == *'match="Old"'* ]] || fail "match-title: $out"
[[ "$out" == *'title="New"'* ]] || fail "new title in update dry-run: $out"
pass "update --match-title dry-run"
# --- 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/browser-profile/Default"
out="$("${CLI[@]}" status 2>&1)" || fail "status dry-run with profile failed"
[[ "$out" == *"dry-run status"* ]] || fail "status dry-run ok: $out"
pass "status dry-run with session profile"
# --- 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 ---
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"
[[ -x "$ROOT/scripts/setup.sh" ]] || fail "setup.sh not executable"
pass "setup.sh executable"
rg -q 'headless' "$ROOT/SKILL.md" || fail "SKILL.md should mention headless"
rg -q 'Rust|cargo' "$ROOT/README.md" || fail "README should mention Rust"
pass "docs"
echo "All cli tests passed."
|