browser4-cli 4.13.18 → 4.13.20
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.
- package/README.md +3 -3
- package/bin/browser4-cli-darwin-arm64 +0 -0
- package/bin/browser4-cli-darwin-x64 +0 -0
- package/bin/browser4-cli-linux-arm64 +0 -0
- package/bin/browser4-cli-linux-musl-arm64 +0 -0
- package/bin/browser4-cli-linux-musl-x64 +0 -0
- package/bin/browser4-cli-linux-x64 +0 -0
- package/bin/browser4-cli-win32-x64.exe +0 -0
- package/package.json +1 -1
- package/scripts/README.md +20 -1
- package/scripts/install-browser4-cli.ps1 +174 -46
- package/scripts/install-browser4-cli.sh +98 -28
- package/scripts/tests/install-browser4-cli.tests.ps1 +150 -15
- package/scripts/tests/install-browser4-cli.tests.sh +157 -10
- package/scripts/tests/wait-for-npm-version.tests.sh +219 -0
- package/scripts/wait-for-npm-version.sh +89 -0
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# wait-for-npm-version.tests.sh
|
|
3
|
+
# Test suite for wait-for-npm-version.sh
|
|
4
|
+
# Uses only bash builtins and standard Unix tools -- no external test
|
|
5
|
+
# frameworks and no network: `npm` is stubbed on PATH.
|
|
6
|
+
#
|
|
7
|
+
# Run:
|
|
8
|
+
# bash cli/scripts/tests/wait-for-npm-version.tests.sh
|
|
9
|
+
|
|
10
|
+
set -euo pipefail
|
|
11
|
+
|
|
12
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
13
|
+
SCRIPT_UNDER_TEST="$(cd "$SCRIPT_DIR/.." && pwd)/wait-for-npm-version.sh"
|
|
14
|
+
|
|
15
|
+
PASS=0
|
|
16
|
+
FAIL=0
|
|
17
|
+
|
|
18
|
+
green() { echo -e "\033[0;32m$*\033[0m"; }
|
|
19
|
+
red() { echo -e "\033[0;31m$*\033[0m"; }
|
|
20
|
+
cyan() { echo -e "\033[0;36m$*\033[0m"; }
|
|
21
|
+
dim() { echo -e "\033[2m$*\033[0m"; }
|
|
22
|
+
|
|
23
|
+
# test <name> <command...>
|
|
24
|
+
# The whole command is forwarded: `test "x" bash -c "..."` must not drop the
|
|
25
|
+
# `-c "..."` part, or a bare `bash` would exit 0 and the assertion would pass
|
|
26
|
+
# vacuously.
|
|
27
|
+
test() {
|
|
28
|
+
local name="$1"
|
|
29
|
+
shift
|
|
30
|
+
if "$@"; then
|
|
31
|
+
PASS=$((PASS + 1))
|
|
32
|
+
green " PASS $name"
|
|
33
|
+
else
|
|
34
|
+
FAIL=$((FAIL + 1))
|
|
35
|
+
red " FAIL $name"
|
|
36
|
+
fi
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# ---- stub npm ---------------------------------------------------------
|
|
40
|
+
|
|
41
|
+
STUB_DIR="$(mktemp -d)"
|
|
42
|
+
cleanup() { rm -rf "$STUB_DIR"; }
|
|
43
|
+
trap cleanup EXIT
|
|
44
|
+
|
|
45
|
+
cat > "$STUB_DIR/npm" <<'STUB'
|
|
46
|
+
#!/usr/bin/env bash
|
|
47
|
+
# Fake `npm view <package>@<version> version`, driven by the test environment:
|
|
48
|
+
# FAKE_NPM_MODE available | available-after:<n> | unavailable |
|
|
49
|
+
# network-error-once | wrong-version
|
|
50
|
+
# FAKE_NPM_VERSION version reported on success
|
|
51
|
+
# FAKE_NPM_COUNT_FILE file counting the invocations
|
|
52
|
+
set -euo pipefail
|
|
53
|
+
|
|
54
|
+
count_file="${FAKE_NPM_COUNT_FILE:?FAKE_NPM_COUNT_FILE is required}"
|
|
55
|
+
count=0
|
|
56
|
+
if [ -f "$count_file" ]; then count="$(cat "$count_file")"; fi
|
|
57
|
+
count=$((count + 1))
|
|
58
|
+
printf '%s' "$count" > "$count_file"
|
|
59
|
+
|
|
60
|
+
not_found() {
|
|
61
|
+
echo "npm error code E404" >&2
|
|
62
|
+
echo "npm error 404 No match found for version ${FAKE_NPM_VERSION:?FAKE_NPM_VERSION is required}" >&2
|
|
63
|
+
exit 1
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
mode="${FAKE_NPM_MODE:?FAKE_NPM_MODE is required}"
|
|
67
|
+
case "$mode" in
|
|
68
|
+
available)
|
|
69
|
+
printf '%s\n' "$FAKE_NPM_VERSION"
|
|
70
|
+
;;
|
|
71
|
+
available-after:*)
|
|
72
|
+
threshold="${mode#available-after:}"
|
|
73
|
+
if [ "$count" -ge "$threshold" ]; then
|
|
74
|
+
printf '%s\n' "$FAKE_NPM_VERSION"
|
|
75
|
+
else
|
|
76
|
+
not_found
|
|
77
|
+
fi
|
|
78
|
+
;;
|
|
79
|
+
unavailable)
|
|
80
|
+
not_found
|
|
81
|
+
;;
|
|
82
|
+
wrong-version)
|
|
83
|
+
printf '%s\n' "0.0.1"
|
|
84
|
+
;;
|
|
85
|
+
network-error-once)
|
|
86
|
+
if [ "$count" -ge 2 ]; then
|
|
87
|
+
printf '%s\n' "$FAKE_NPM_VERSION"
|
|
88
|
+
else
|
|
89
|
+
echo "npm error network request to https://registry.npmjs.org failed" >&2
|
|
90
|
+
exit 1
|
|
91
|
+
fi
|
|
92
|
+
;;
|
|
93
|
+
*)
|
|
94
|
+
echo "fake npm: unknown FAKE_NPM_MODE '$mode'" >&2
|
|
95
|
+
exit 2
|
|
96
|
+
;;
|
|
97
|
+
esac
|
|
98
|
+
STUB
|
|
99
|
+
chmod +x "$STUB_DIR/npm"
|
|
100
|
+
|
|
101
|
+
# run_wait <mode> <timeout-seconds> <poll-interval-seconds> <package> <version>
|
|
102
|
+
# Sets RUN_STATUS, RUN_OUTPUT (stdout+stderr) and RUN_COUNT (npm invocations).
|
|
103
|
+
RUN_STATUS=0
|
|
104
|
+
RUN_OUTPUT=''
|
|
105
|
+
RUN_COUNT=0
|
|
106
|
+
|
|
107
|
+
run_wait() {
|
|
108
|
+
local mode="$1" timeout="$2" interval="$3" package="$4" version="$5"
|
|
109
|
+
local count_file="$STUB_DIR/count.$$.$RANDOM"
|
|
110
|
+
rm -f "$count_file"
|
|
111
|
+
|
|
112
|
+
RUN_STATUS=0
|
|
113
|
+
RUN_OUTPUT="$(
|
|
114
|
+
FAKE_NPM_MODE="$mode" \
|
|
115
|
+
FAKE_NPM_VERSION="$version" \
|
|
116
|
+
FAKE_NPM_COUNT_FILE="$count_file" \
|
|
117
|
+
PATH="$STUB_DIR:$PATH" \
|
|
118
|
+
bash "$SCRIPT_UNDER_TEST" "$package" "$version" "$timeout" "$interval" 2>&1
|
|
119
|
+
)" || RUN_STATUS=$?
|
|
120
|
+
|
|
121
|
+
RUN_COUNT=0
|
|
122
|
+
if [ -f "$count_file" ]; then RUN_COUNT="$(cat "$count_file")"; fi
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
# ---- pre-flight -------------------------------------------------------
|
|
126
|
+
|
|
127
|
+
cyan "============================================"
|
|
128
|
+
cyan " wait-for-npm-version.sh Test Suite"
|
|
129
|
+
cyan "============================================"
|
|
130
|
+
echo ""
|
|
131
|
+
|
|
132
|
+
dim "--- Pre-flight ---"
|
|
133
|
+
|
|
134
|
+
test "file exists" bash -c "[[ -f '$SCRIPT_UNDER_TEST' ]]"
|
|
135
|
+
test "starts with shebang" bash -c "head -c 20 '$SCRIPT_UNDER_TEST' | grep -q '^#!/bin/bash'"
|
|
136
|
+
test "bash syntax check passes" bash -c "bash -n '$SCRIPT_UNDER_TEST' 2>&1"
|
|
137
|
+
test "no non-ASCII bytes" bash -c "! grep -Pn '[^\\x00-\\x7F]' '$SCRIPT_UNDER_TEST' >/dev/null 2>&1"
|
|
138
|
+
|
|
139
|
+
echo ""
|
|
140
|
+
|
|
141
|
+
# ---- behaviour --------------------------------------------------------
|
|
142
|
+
|
|
143
|
+
test_version_visible_immediately() {
|
|
144
|
+
run_wait available 30 1 browser4-cli 1.2.3
|
|
145
|
+
[ "$RUN_STATUS" -eq 0 ] || return 1
|
|
146
|
+
[[ "$RUN_OUTPUT" == *"Verified browser4-cli@1.2.3 on npm"* ]] || return 1
|
|
147
|
+
[ "$RUN_COUNT" -eq 1 ] || return 1
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
test_waits_until_the_version_appears() {
|
|
151
|
+
run_wait "available-after:3" 30 1 browser4-cli 1.2.3
|
|
152
|
+
[ "$RUN_STATUS" -eq 0 ] || return 1
|
|
153
|
+
[[ "$RUN_OUTPUT" == *"Verified browser4-cli@1.2.3 on npm"* ]] || return 1
|
|
154
|
+
[ "$RUN_COUNT" -ge 3 ] || return 1
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
# Discrimination test for the CI failure this script fixes: the registry
|
|
158
|
+
# reports the version only on the 7th call -- beyond the 5 attempts the old
|
|
159
|
+
# inline loop allowed. A 3 s budget reproduces the old give-up, a 30 s budget
|
|
160
|
+
# rides it out.
|
|
161
|
+
test_keeps_polling_past_the_old_five_attempt_window() {
|
|
162
|
+
run_wait "available-after:7" 3 1 browser4-cli 1.2.3
|
|
163
|
+
[ "$RUN_STATUS" -eq 1 ] || return 1
|
|
164
|
+
|
|
165
|
+
run_wait "available-after:7" 30 1 browser4-cli 1.2.3
|
|
166
|
+
[ "$RUN_STATUS" -eq 0 ] || return 1
|
|
167
|
+
[ "$RUN_COUNT" -ge 7 ] || return 1
|
|
168
|
+
[[ "$RUN_OUTPUT" == *"Verified browser4-cli@1.2.3 on npm"* ]] || return 1
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
test_fails_when_the_version_never_appears() {
|
|
172
|
+
run_wait unavailable 3 1 browser4-cli 1.2.3
|
|
173
|
+
[ "$RUN_STATUS" -eq 1 ] || return 1
|
|
174
|
+
[[ "$RUN_OUTPUT" == *"unable to verify browser4-cli@1.2.3 on npm within 3s"* ]] || return 1
|
|
175
|
+
[[ "$RUN_OUTPUT" == *"E404"* ]] || return 1
|
|
176
|
+
[[ "$RUN_OUTPUT" == *"npm view browser4-cli@1.2.3 version"* ]] || return 1
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
test_tolerates_a_transient_registry_error() {
|
|
180
|
+
run_wait network-error-once 30 1 browser4-cli 1.2.3
|
|
181
|
+
[ "$RUN_STATUS" -eq 0 ] || return 1
|
|
182
|
+
[[ "$RUN_OUTPUT" == *"WARN: npm view failed"* ]] || return 1
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
test_reports_a_mismatched_version_and_keeps_waiting() {
|
|
186
|
+
run_wait wrong-version 3 1 browser4-cli 1.2.3
|
|
187
|
+
[ "$RUN_STATUS" -eq 1 ] || return 1
|
|
188
|
+
[[ "$RUN_OUTPUT" == *"npm reports '0.0.1'"* ]] || return 1
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
test_requires_both_arguments() {
|
|
192
|
+
local output status
|
|
193
|
+
output="$(PATH="$STUB_DIR:$PATH" bash "$SCRIPT_UNDER_TEST" 2>&1)" && status=0 || status=$?
|
|
194
|
+
[ "$status" -ne 0 ] || return 1
|
|
195
|
+
[[ "$output" == *"Usage:"* ]] || return 1
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
dim "--- Behaviour ---"
|
|
199
|
+
|
|
200
|
+
test "version already visible: verifies on the first poll" test_version_visible_immediately
|
|
201
|
+
test "waits until the registry reports the version" test_waits_until_the_version_appears
|
|
202
|
+
test "keeps polling past the old 5-attempt window" test_keeps_polling_past_the_old_five_attempt_window
|
|
203
|
+
test "fails when the version never appears" test_fails_when_the_version_never_appears
|
|
204
|
+
test "tolerates a transient registry error" test_tolerates_a_transient_registry_error
|
|
205
|
+
test "reports a mismatched version and keeps waiting" test_reports_a_mismatched_version_and_keeps_waiting
|
|
206
|
+
test "requires both arguments" test_requires_both_arguments
|
|
207
|
+
|
|
208
|
+
# ---- summary ----------------------------------------------------------
|
|
209
|
+
|
|
210
|
+
echo ""
|
|
211
|
+
cyan "============================================"
|
|
212
|
+
if [ "$FAIL" -eq 0 ]; then
|
|
213
|
+
green " All $PASS tests passed"
|
|
214
|
+
else
|
|
215
|
+
red " $FAIL of $((PASS + FAIL)) tests failed"
|
|
216
|
+
fi
|
|
217
|
+
cyan "============================================"
|
|
218
|
+
|
|
219
|
+
[ "$FAIL" -eq 0 ]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# ---------------------------------------------------------------------------
|
|
3
|
+
# wait-for-npm-version.sh -- wait until a published version is visible on npm
|
|
4
|
+
# ---------------------------------------------------------------------------
|
|
5
|
+
# Usage:
|
|
6
|
+
# wait-for-npm-version.sh <package> <version> [timeout-seconds] [poll-interval-seconds]
|
|
7
|
+
#
|
|
8
|
+
# Defaults: timeout 600 s, poll interval 15 s.
|
|
9
|
+
#
|
|
10
|
+
# `npm publish` exiting 0 only means the registry ACCEPTED the upload. npm now
|
|
11
|
+
# processes publishes asynchronously and answers with
|
|
12
|
+
# "Your package is being processed and may take a few minutes to become available."
|
|
13
|
+
# after which the new version stays invisible to `npm view` for an unpredictable
|
|
14
|
+
# while (observed on v4.13.18: still missing 41 s after a successful publish,
|
|
15
|
+
# i.e. past the whole 5 x 10 s window this script replaces). Verification must
|
|
16
|
+
# therefore wait minutes, not seconds -- otherwise a successful publish is
|
|
17
|
+
# reported as a failed release job, and everything gated on that job (the
|
|
18
|
+
# GitHub release) is skipped.
|
|
19
|
+
#
|
|
20
|
+
# Every answer that is not the expected version is retried:
|
|
21
|
+
# - 404 / "No match found for version" -> not published yet (expected, quiet)
|
|
22
|
+
# - any other error -> transient registry/network problem
|
|
23
|
+
# (logged, still retried)
|
|
24
|
+
#
|
|
25
|
+
# Exit codes:
|
|
26
|
+
# 0 the exact version is visible on the registry
|
|
27
|
+
# 1 still not visible when the timeout expires, or bad usage
|
|
28
|
+
#
|
|
29
|
+
# Designed for CI (GitHub Actions) but also runs on developer machines.
|
|
30
|
+
# ---------------------------------------------------------------------------
|
|
31
|
+
set -euo pipefail
|
|
32
|
+
|
|
33
|
+
PACKAGE="${1:?Usage: $0 <package> <version> [timeout-seconds] [poll-interval-seconds]}"
|
|
34
|
+
VERSION="${2:?Usage: $0 <package> <version> [timeout-seconds] [poll-interval-seconds]}"
|
|
35
|
+
TIMEOUT_SECONDS="${3:-600}"
|
|
36
|
+
POLL_INTERVAL_SECONDS="${4:-15}"
|
|
37
|
+
|
|
38
|
+
STDERR_FILE="$(mktemp)"
|
|
39
|
+
trap 'rm -f "$STDERR_FILE"' EXIT
|
|
40
|
+
|
|
41
|
+
started=$SECONDS
|
|
42
|
+
attempt=0
|
|
43
|
+
published=''
|
|
44
|
+
npm_error=''
|
|
45
|
+
|
|
46
|
+
while :; do
|
|
47
|
+
attempt=$((attempt + 1))
|
|
48
|
+
|
|
49
|
+
set +e
|
|
50
|
+
published="$(npm view "$PACKAGE@$VERSION" version 2>"$STDERR_FILE")"
|
|
51
|
+
status=$?
|
|
52
|
+
set -e
|
|
53
|
+
|
|
54
|
+
published="$(printf '%s' "$published" | tr -d '[:space:]')"
|
|
55
|
+
npm_error="$(head -n 1 "$STDERR_FILE" 2>/dev/null || true)"
|
|
56
|
+
elapsed=$((SECONDS - started))
|
|
57
|
+
|
|
58
|
+
if [ "$status" -eq 0 ] && [ "$published" = "$VERSION" ]; then
|
|
59
|
+
echo "Verified $PACKAGE@$VERSION on npm after ${elapsed}s (attempt $attempt)"
|
|
60
|
+
exit 0
|
|
61
|
+
fi
|
|
62
|
+
|
|
63
|
+
remaining=$((TIMEOUT_SECONDS - elapsed))
|
|
64
|
+
if [ "$remaining" -le 0 ]; then
|
|
65
|
+
break
|
|
66
|
+
fi
|
|
67
|
+
|
|
68
|
+
if [ "$status" -eq 0 ]; then
|
|
69
|
+
echo "WARN: npm reports '${published:-<empty>}' for $PACKAGE@$VERSION (attempt $attempt, ${elapsed}s elapsed, ${remaining}s left)"
|
|
70
|
+
elif printf '%s' "$npm_error" | grep -qE 'E404|404'; then
|
|
71
|
+
echo "Waiting for $PACKAGE@$VERSION to appear on npm (attempt $attempt, ${elapsed}s elapsed, ${remaining}s left) -- the registry may still be processing the publish"
|
|
72
|
+
else
|
|
73
|
+
echo "WARN: npm view failed (attempt $attempt, ${elapsed}s elapsed, ${remaining}s left): ${npm_error:-<no output>}"
|
|
74
|
+
fi
|
|
75
|
+
|
|
76
|
+
# never sleep past the deadline: the total wait stays within the budget
|
|
77
|
+
if [ "$POLL_INTERVAL_SECONDS" -gt "$remaining" ]; then
|
|
78
|
+
sleep "$remaining"
|
|
79
|
+
else
|
|
80
|
+
sleep "$POLL_INTERVAL_SECONDS"
|
|
81
|
+
fi
|
|
82
|
+
done
|
|
83
|
+
|
|
84
|
+
echo "ERROR: unable to verify $PACKAGE@$VERSION on npm within ${TIMEOUT_SECONDS}s after publish" >&2
|
|
85
|
+
echo "ERROR: last registry answer: ${npm_error:-<no output>}" >&2
|
|
86
|
+
echo "ERROR: the version may still be processing on the registry side; re-check with:" >&2
|
|
87
|
+
echo "ERROR: npm view $PACKAGE@$VERSION version" >&2
|
|
88
|
+
echo "ERROR: https://www.npmjs.com/package/$PACKAGE/v/$VERSION" >&2
|
|
89
|
+
exit 1
|