just-bash-nx 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,225 @@
1
+ # Built-in initialization script for just-bash-nx CLI.
2
+ # This file is sourced implicitly unless --no-init is provided.
3
+
4
+ export JUST_BASH=1
5
+
6
+ # Reusable host-command mocks for npx just-bash-nx verification.
7
+ # Source this file inside the same shell process as the script under test.
8
+
9
+ # ---------- helpers ----------
10
+ _mock_now_ms() {
11
+ date +%s000
12
+ }
13
+
14
+ _mock_escape_json() {
15
+ # Minimal JSON string escaper for test data.
16
+ printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
17
+ }
18
+
19
+ # Parse repeatable flags as lines into stdout.
20
+ # usage: _mock_collect_flag_values "--jid" "$@"
21
+ _mock_collect_flag_values() {
22
+ flag="$1"
23
+ shift
24
+ while [ "$#" -gt 0 ]; do
25
+ if [ "$1" = "$flag" ] && [ "$#" -ge 2 ]; then
26
+ printf '%s\n' "$2"
27
+ shift 2
28
+ continue
29
+ fi
30
+ shift
31
+ done
32
+ }
33
+
34
+ _mock_find_next() {
35
+ flag="$1"
36
+ shift
37
+ while [ "$#" -gt 0 ]; do
38
+ if [ "$1" = "$flag" ] && [ "$#" -ge 2 ]; then
39
+ printf '%s' "$2"
40
+ return 0
41
+ fi
42
+ shift
43
+ done
44
+ return 1
45
+ }
46
+
47
+ # ---------- command mocks ----------
48
+
49
+ fetch-messages() {
50
+ thread_ts="$(_mock_find_next --thread-timestamp "$@" || true)"
51
+ days="$(_mock_find_next --days "$@" || true)"
52
+ [ -z "$days" ] && days=2
53
+
54
+ ts="$(_mock_now_ms)"
55
+ msg_text="mock message"
56
+ if [ -n "$thread_ts" ]; then
57
+ msg_text="mock message for thread ${thread_ts}"
58
+ ts="$thread_ts"
59
+ fi
60
+
61
+ cat <<JSON
62
+ {"messages":[{"messageId":"m-1","content":"$(_mock_escape_json "$msg_text")","time":$ts,"senderJid":"mock.user@xmpp.zoom.us"}],"participants":[{"jid":"mock.user@xmpp.zoom.us","displayName":"Mock User"}],"currentUser":{"jid":"me@xmpp.zoom.us","displayName":"Me"},"meta":{"days":$days,"threadTimestamp":"$(_mock_escape_json "${thread_ts:-}")"}}
63
+ JSON
64
+ }
65
+
66
+ get-user() {
67
+ jid="$(_mock_find_next --jid "$@" || true)"
68
+ query="$(_mock_find_next --query "$@" || true)"
69
+ email="$(_mock_find_next --email "$@" || true)"
70
+
71
+ if [ -n "$jid" ]; then
72
+ cat <<JSON
73
+ {"matchType":"exact","query":"$(_mock_escape_json "$jid")","user":{"jid":"$(_mock_escape_json "$jid")","displayName":"Mock By JID","email":"mock@zoom.us"}}
74
+ JSON
75
+ return 0
76
+ fi
77
+
78
+ if [ -n "$query" ]; then
79
+ cat <<JSON
80
+ {"matchType":"exact","query":"$(_mock_escape_json "$query")","user":{"jid":"mock.query@xmpp.zoom.us","displayName":"$(_mock_escape_json "$query")"}}
81
+ JSON
82
+ return 0
83
+ fi
84
+
85
+ if [ -n "$email" ]; then
86
+ cat <<JSON
87
+ {"matchType":"exact","query":"$(_mock_escape_json "$email")","user":{"jid":"mock.email@xmpp.zoom.us","displayName":"Mock By Email","email":"$(_mock_escape_json "$email")"}}
88
+ JSON
89
+ return 0
90
+ fi
91
+
92
+ echo '{"matchType":"not_found","query":"","candidates":[]}'
93
+ }
94
+
95
+ send-chat() {
96
+ sid="$(_mock_find_next --session-id "$@" || true)"
97
+ content="$(_mock_find_next --content "$@" || true)"
98
+ thread_ts="$(_mock_find_next --thread-timestamp "$@" || true)"
99
+ [ -z "$sid" ] && sid="mock-session"
100
+
101
+ cat <<JSON
102
+ {"messageId":"msg-$(_mock_now_ms)","sessionId":"$(_mock_escape_json "$sid")","echo":{"content":"$(_mock_escape_json "${content:-}")","threadTimestamp":"$(_mock_escape_json "${thread_ts:-}")"}}
103
+ JSON
104
+ }
105
+
106
+ edit-chat() {
107
+ sid="$(_mock_find_next --session-id "$@" || true)"
108
+ mid="$(_mock_find_next --message-id "$@" || true)"
109
+ content="$(_mock_find_next --content "$@" || true)"
110
+ [ -z "$sid" ] && sid="mock-session"
111
+ [ -z "$mid" ] && mid="mock-message-id"
112
+
113
+ cat <<JSON
114
+ {"ok":true,"sessionId":"$(_mock_escape_json "$sid")","messageId":"$(_mock_escape_json "$mid")","updatedContent":"$(_mock_escape_json "${content:-}")"}
115
+ JSON
116
+ }
117
+
118
+ add-members() {
119
+ sid="$(_mock_find_next --session-id "$@" || true)"
120
+ [ -z "$sid" ] && sid="mock-session"
121
+
122
+ jids="$(_mock_collect_flag_values --jid "$@")"
123
+ emails="$(_mock_collect_flag_values --email "$@")"
124
+
125
+ invited=0
126
+ [ -n "$jids" ] && invited=$((invited + $(printf '%s\n' "$jids" | sed '/^$/d' | wc -l | tr -d ' ')))
127
+ [ -n "$emails" ] && invited=$((invited + $(printf '%s\n' "$emails" | sed '/^$/d' | wc -l | tr -d ' ')))
128
+
129
+ first_jid=""
130
+ if [ -n "$jids" ]; then
131
+ first_jid="$(printf '%s\n' "$jids" | sed -n '1p')"
132
+ fi
133
+
134
+ if [ -n "$first_jid" ] && [ "${MOCK_ADD_MEMBERS_DENY_FIRST:-0}" = "1" ]; then
135
+ cat <<JSON
136
+ {"sessionId":"$(_mock_escape_json "$sid")","invitedCount":$((invited-1)),"notAllowedList":[{"jid":"$(_mock_escape_json "$first_jid")","reason":"mock_denied"}],"echo":{"jids":"$(_mock_escape_json "$jids")","emails":"$(_mock_escape_json "$emails")"}}
137
+ JSON
138
+ return 0
139
+ fi
140
+
141
+ cat <<JSON
142
+ {"sessionId":"$(_mock_escape_json "$sid")","invitedCount":$invited,"notAllowedList":[],"echo":{"jids":"$(_mock_escape_json "$jids")","emails":"$(_mock_escape_json "$emails")"}}
143
+ JSON
144
+ }
145
+
146
+ add-mention-group() {
147
+ sid="$(_mock_find_next --session-id "$@" || true)"
148
+ name="$(_mock_find_next --name "$@" || true)"
149
+ desc="$(_mock_find_next --description "$@" || true)"
150
+ members="$(_mock_collect_flag_values --member "$@")"
151
+ [ -z "$sid" ] && sid="mock-session"
152
+ [ -z "$name" ] && name="@mock"
153
+ member_count=0
154
+ [ -n "$members" ] && member_count="$(printf '%s\n' "$members" | sed '/^$/d' | wc -l | tr -d ' ')"
155
+
156
+ cat <<JSON
157
+ {"ok":true,"channelId":"$(_mock_escape_json "$sid")","name":"$(_mock_escape_json "$name")","description":"$(_mock_escape_json "${desc:-}")","memberCount":$member_count}
158
+ JSON
159
+ }
160
+
161
+ get-members() {
162
+ sid="$(_mock_find_next --session-id "$@" || true)"
163
+ [ -z "$sid" ] && sid="mock-session"
164
+ force="false"
165
+ if _mock_find_next --force-update "$@" >/dev/null 2>&1; then
166
+ force="true"
167
+ fi
168
+
169
+ cat <<JSON
170
+ {"sessionId":"$(_mock_escape_json "$sid")","memberCount":2,"members":[{"jid":"a@xmpp.zoom.us"},{"jid":"b@xmpp.zoom.us"}],"pendingMembers":[],"meta":{"forceUpdate":$force}}
171
+ JSON
172
+ }
173
+
174
+ create-channel() {
175
+ name="$(_mock_find_next --name "$@" || true)"
176
+ [ -z "$name" ] && name="~mock"
177
+ public=false
178
+ if _mock_find_next --public "$@" >/dev/null 2>&1; then
179
+ public=true
180
+ fi
181
+ jids="$(_mock_collect_flag_values --jid "$@")"
182
+
183
+ cat <<JSON
184
+ {"id":"$(_mock_escape_json "${name}@conference.xmpp.zoom.us")","jid":"$(_mock_escape_json "${name}@conference.xmpp.zoom.us")","channelId":"$(_mock_escape_json "sid-${name}")","subject":"$(_mock_escape_json "$name")","meta":{"isPublic":$public,"jids":"$(_mock_escape_json "$jids")"}}
185
+ JSON
186
+ }
187
+
188
+ get-channel() {
189
+ name="$(_mock_find_next --name "$@" || true)"
190
+ [ -z "$name" ] && name="~mock"
191
+ if [ "$name" = "~missing" ]; then
192
+ echo '{"found":false,"subject":"~missing","reason":"not_found","message":"Channel \"~missing\" was not found."}'
193
+ return 0
194
+ fi
195
+
196
+ cat <<JSON
197
+ {"id":"$(_mock_escape_json "${name}@conference.xmpp.zoom.us")","jid":"$(_mock_escape_json "${name}@conference.xmpp.zoom.us")","channelId":"$(_mock_escape_json "sid-${name}")","subject":"$(_mock_escape_json "$name")","deeplink":"zoommtg://chat?sid=$(_mock_escape_json "sid-${name}")"}
198
+ JSON
199
+ }
200
+
201
+ open-session() {
202
+ sid="$(_mock_find_next --session-id "$@" || true)"
203
+ [ -z "$sid" ] && sid="mock-session"
204
+
205
+ cat <<JSON
206
+ {"ok":true,"sessionId":"$(_mock_escape_json "$sid")","deeplink":"zoommtg://chat?sid=$(_mock_escape_json "$sid")"}
207
+ JSON
208
+ }
209
+
210
+ create-or-update-skill() {
211
+ content="$(_mock_find_next --content "$@" || true)"
212
+ update_sid="$(_mock_find_next --update-session-id "$@" || true)"
213
+ update_mid="$(_mock_find_next --update-message-id "$@" || true)"
214
+ cmds="$(_mock_collect_flag_values --command "$@")"
215
+ refs="$(_mock_collect_flag_values --reference "$@")"
216
+
217
+ mode="create"
218
+ if [ -n "$update_sid" ] || [ -n "$update_mid" ]; then
219
+ mode="update"
220
+ fi
221
+
222
+ cat <<JSON
223
+ {"channelId":"${update_sid:-mock-session}","messageId":"skill-$(_mock_now_ms)","mode":"$mode","echo":{"content":"$(_mock_escape_json "${content:-}")","commands":"$(_mock_escape_json "$cmds")","references":"$(_mock_escape_json "$refs")","updateSessionId":"$(_mock_escape_json "${update_sid:-}")","updateMessageId":"$(_mock_escape_json "${update_mid:-}")"}}
224
+ JSON
225
+ }