Skip to content

Commit 9d3e107

Browse files
authored
Fix run-tests.sh silently truncating recursive ** glob buckets (#14700)
Bash only expands ** recursively when globstar is enabled. run-tests.sh passed its resolved test-file list unquoted to the final deno invocation, letting bash re-expand it with globstar off, so a bucket like qmd-files/**/*.qmd matched only one directory level deep and silently dropped anything nested further - the ff-matrix CI job ran 10 tests on ubuntu-latest against 271 on windows-latest for the same bucket. A prior fix (9d718d1) added `shopt -s globstar` to the CI wrapper, but run-tests.sh runs as its own bash process, so the setting never reached the actual expansion. - Convert the resolved file lists to bash arrays and quote them at the deno invocation, so bash never touches the glob pattern and a literal string reaches smoke-all.test.ts's own expandGlobSync (matching the path run-tests.ps1 already relies on) - Drop the now-dead `shopt -s globstar` from the CI wrapper - Fix a related regression this exposed: the multi-file loop iterated `"$*"` instead of `"$@"`, collapsing several file args into one token - Add tests/run-tests-recursive-glob.test.sh and tests/run-tests-multiple-file-args.test.sh, standalone regression tests against the real run-tests.sh with a stubbed deno binary - Ignore feature-format-matrix render byproducts (.typ, .quarto_ipynb) now that the full qmd-files tree actually renders in CI - Fix a host-dependent font assertion in a typst smoke test (Georgia isn't available on Ubuntu CI runners), surfaced once this fixture started actually running in CI
1 parent d31f704 commit 9d3e107

6 files changed

Lines changed: 193 additions & 14 deletions

File tree

‎.github/workflows/test-smokes.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ jobs:
317317
echo ">>> ./run-tests.sh ${file}"
318318
# Run tests without -e so we don't exit on first failure
319319
set +e
320-
shopt -s globstar && ./run-tests.sh "$file"
320+
./run-tests.sh "$file"
321321
status=$?
322322
set -e
323323
echo "::endgroup::"

‎dev-docs/feature-format-matrix/.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ qmd-files/**/*.html
55
qmd-files/**/*.pdf
66
qmd-files/**/*.md
77
qmd-files/**/*.mdx
8+
qmd-files/**/*.typ
89

910
/.quarto/
11+
12+
**/*.quarto_ipynb

‎dev-docs/feature-format-matrix/qmd-files/css-properties/font-family/document.qmd‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ _quarto:
1919
typst:
2020
ensureTypstFileRegexMatches:
2121
-
22-
- '#{set text\(font: \("Georgia", "serif"\)\); table\('
22+
- '#{set text\(font: \("Libertinus Serif", "serif"\)\); table\('
2323
- []
2424
---
2525

2626
```{=html}
27-
<table style="font-family: Georgia, serif;">
27+
<table style="font-family: 'Libertinus Serif', serif;">
2828
<tr><td>A</td><td>B</td></tr>
2929
</table>
3030
```
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env bash
2+
# Regression test for run-tests.sh collapsing multiple .test.ts file
3+
# arguments into a single glued argv token.
4+
#
5+
# tests/README.md documents passing several .ts files at once, e.g.:
6+
# ./run-tests.sh smoke/extensions/extension-render-doc.test.ts smoke/smoke-all.test.ts
7+
#
8+
# run-tests.sh built TESTS_TO_RUN by looping `for file in "$*"; do`, which
9+
# joins all positional args into one string before iterating, so the loop
10+
# only ever runs once. That single glued string used to reach deno unquoted,
11+
# where bash's own word-splitting happened to reconstruct separate args -
12+
# but that's incidental, not something quoting the resulting array should be
13+
# allowed to depend on. This test runs the real run-tests.sh with two file
14+
# arguments and confirms each survives as its own deno argv token.
15+
set -uo pipefail
16+
17+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
18+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd)"
19+
20+
TMP="$(mktemp -d)"
21+
trap 'rm -rf "$TMP"' EXIT
22+
23+
fail() {
24+
echo "FAIL: $1"
25+
exit 1
26+
}
27+
28+
# --- Isolated fake repo skeleton, just enough for run-tests.sh to run ---
29+
mkdir -p "$TMP/tests"
30+
mkdir -p "$TMP/package/scripts/common"
31+
mkdir -p "$TMP/package/dist/bin/tools/stub"
32+
mkdir -p "$TMP/src/resources"
33+
34+
# Strip CR in case this checkout has core.autocrlf=true (Windows dev boxes);
35+
# CI checkouts on Linux/macOS never have CRLF here, this is a local-copy
36+
# normalization only, not part of the fix under test.
37+
tr -d '\r' < "$REPO_ROOT/tests/run-tests.sh" > "$TMP/tests/run-tests.sh"
38+
tr -d '\r' < "$REPO_ROOT/package/scripts/common/utils.sh" > "$TMP/package/scripts/common/utils.sh"
39+
chmod +x "$TMP/tests/run-tests.sh"
40+
41+
RECORD_FILE="$TMP/recorded-argv.txt"
42+
cat > "$TMP/package/dist/bin/tools/stub/deno" <<'EOF'
43+
#!/usr/bin/env bash
44+
printf '%s\n' "$@" > "$RECORD_FILE"
45+
exit 0
46+
EOF
47+
chmod +x "$TMP/package/dist/bin/tools/stub/deno"
48+
49+
# --- Invoke the real script with two separate .test.ts file arguments ---
50+
(
51+
cd "$TMP/tests" || exit 1
52+
export QUARTO_TESTS_NO_CONFIG=true
53+
export QUARTO_TESTS_FORCE_NO_VENV=true
54+
export DENO_DIR=stub
55+
export RECORD_FILE
56+
./run-tests.sh "foo.test.ts" "bar.test.ts"
57+
)
58+
59+
[ -f "$RECORD_FILE" ] || fail "deno stub was never invoked - run-tests.sh did not reach the final deno call"
60+
61+
mapfile -t recorded < "$RECORD_FILE"
62+
63+
found_foo=0
64+
found_bar=0
65+
found_glued=0
66+
for tok in "${recorded[@]}"; do
67+
[ "$tok" = "foo.test.ts" ] && found_foo=1
68+
[ "$tok" = "bar.test.ts" ] && found_bar=1
69+
[ "$tok" = "foo.test.ts bar.test.ts" ] && found_glued=1
70+
done
71+
72+
[ "$found_glued" -eq 0 ] || fail "foo.test.ts and bar.test.ts were glued into a single argv token - multiple file arguments were collapsed"
73+
[ "$found_foo" -eq 1 ] || fail "foo.test.ts missing from deno argv (got: ${recorded[*]})"
74+
[ "$found_bar" -eq 1 ] || fail "bar.test.ts missing from deno argv (got: ${recorded[*]})"
75+
76+
echo "PASS: multiple .test.ts file arguments reached deno as separate argv tokens"
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
# Regression test for run-tests.sh silently truncating recursive ** glob
3+
# buckets on Linux/macOS (quarto-cli-jho3).
4+
#
5+
# Runs the real run-tests.sh against a nested qmd fixture, with the deno
6+
# binary swapped for a recorder stub (via the DENO_DIR override run-tests.sh
7+
# already supports), and checks that a file nested two directories deep
8+
# under a `**` bucket still reaches the resolved test-file set. The
9+
# assertion re-expands any still-glob-shaped token itself (mirroring what
10+
# smoke-all.test.ts's expandGlobSync does), so it passes regardless of
11+
# whether the fix quotes the pattern through to deno or expands it in bash.
12+
set -uo pipefail
13+
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
15+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." >/dev/null 2>&1 && pwd)"
16+
17+
TMP="$(mktemp -d)"
18+
trap 'rm -rf "$TMP"' EXIT
19+
20+
fail() {
21+
echo "FAIL: $1"
22+
exit 1
23+
}
24+
25+
# --- Isolated fake repo skeleton, just enough for run-tests.sh to run ---
26+
mkdir -p "$TMP/tests"
27+
mkdir -p "$TMP/package/scripts/common"
28+
mkdir -p "$TMP/package/dist/bin/tools/stub"
29+
mkdir -p "$TMP/src/resources"
30+
31+
# Strip CR in case this checkout has core.autocrlf=true (Windows dev boxes);
32+
# CI checkouts on Linux/macOS never have CRLF here, this is a local-copy
33+
# normalization only, not part of the fix under test.
34+
tr -d '\r' < "$REPO_ROOT/tests/run-tests.sh" > "$TMP/tests/run-tests.sh"
35+
tr -d '\r' < "$REPO_ROOT/package/scripts/common/utils.sh" > "$TMP/package/scripts/common/utils.sh"
36+
chmod +x "$TMP/tests/run-tests.sh"
37+
38+
RECORD_FILE="$TMP/recorded-argv.txt"
39+
cat > "$TMP/package/dist/bin/tools/stub/deno" <<'EOF'
40+
#!/usr/bin/env bash
41+
printf '%s\n' "$@" > "$RECORD_FILE"
42+
exit 0
43+
EOF
44+
chmod +x "$TMP/package/dist/bin/tools/stub/deno"
45+
46+
# --- Nested fixture: one .qmd at depth 1, one at depth 2 under qmd-files/ ---
47+
mkdir -p "$TMP/qmd-files/a/b"
48+
: > "$TMP/qmd-files/a/one.qmd"
49+
: > "$TMP/qmd-files/a/b/two.qmd"
50+
51+
# --- Invoke the real script exactly as test-smokes.yml's bucket runner does ---
52+
(
53+
cd "$TMP/tests" || exit 1
54+
export QUARTO_TESTS_NO_CONFIG=true
55+
export QUARTO_TESTS_FORCE_NO_VENV=true
56+
export DENO_DIR=stub
57+
export RECORD_FILE
58+
./run-tests.sh "../qmd-files/**/*.qmd"
59+
)
60+
61+
[ -f "$RECORD_FILE" ] || fail "deno stub was never invoked - run-tests.sh did not reach the final deno call"
62+
63+
mapfile -t recorded < "$RECORD_FILE"
64+
65+
dashdash_index=-1
66+
for i in "${!recorded[@]}"; do
67+
if [ "${recorded[$i]}" = "--" ]; then
68+
dashdash_index=$i
69+
break
70+
fi
71+
done
72+
[ "$dashdash_index" -ge 0 ] || fail "no isolated '--' token in deno argv (got: ${recorded[*]})"
73+
74+
# Resolve the file tokens after '--' into an actual file set, expanding any
75+
# token that still looks like a glob pattern (mirrors expandGlobSync).
76+
resolved=()
77+
(
78+
cd "$TMP/tests" || exit 1
79+
shopt -s globstar nullglob
80+
for ((i = dashdash_index + 1; i < ${#recorded[@]}; i++)); do
81+
tok="${recorded[$i]}"
82+
if [[ "$tok" == *"*"* ]]; then
83+
for f in $tok; do
84+
echo "$f"
85+
done
86+
else
87+
echo "$tok"
88+
fi
89+
done
90+
) > "$TMP/resolved-files.txt"
91+
92+
grep -q 'a/one\.qmd$' "$TMP/resolved-files.txt" || fail "depth-1 fixture file (qmd-files/a/one.qmd) missing from resolved test set"
93+
grep -q 'a/b/two\.qmd$' "$TMP/resolved-files.txt" || fail "depth-2 fixture file (qmd-files/a/b/two.qmd) missing from resolved test set - recursive ** bucket was silently truncated"
94+
95+
echo "PASS: recursive ** bucket resolved both depth-1 and depth-2 fixture files"

‎tests/run-tests.sh‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,19 @@ else
130130
## Short version syntax to run smoke-all.test.ts
131131
## Only use if different than ./run-test.sh ./smoke/smoke-all.test.ts
132132
if [[ "$1" =~ smoke-all\.test\.ts ]]; then
133-
TESTS_TO_RUN=$@
133+
TESTS_TO_RUN=("$@")
134134
else
135135
# Check file argument
136-
SMOKE_ALL_FILES=""
137-
TESTS_TO_RUN=""
136+
SMOKE_ALL_FILES=()
137+
TESTS_TO_RUN=()
138138
if [[ ! -z "$*" ]]; then
139-
for file in "$*"; do
139+
for file in "$@"; do
140140
filename=$(basename "$file")
141141
# smoke-all.test.ts works with .qmd, .md and .ipynb but will ignored file starting with _
142142
if [[ $filename =~ ^[^_].*[.]qmd$ ]] || [[ $filename =~ ^[^_].*[.]ipynb$ ]] || [[ $filename =~ ^[^_].*[.]md$ ]]; then
143-
SMOKE_ALL_FILES="${SMOKE_ALL_FILES} ${file}"
143+
SMOKE_ALL_FILES+=("${file}")
144144
elif [[ $file =~ .*[.]ts$ ]]; then
145-
TESTS_TO_RUN="${TESTS_TO_RUN} ${file}"
145+
TESTS_TO_RUN+=("${file}")
146146
else
147147
echo "#### WARNING"
148148
echo "Only .ts, or .qmd, .md and .ipynb passed to smoke-all.test.ts are accepted (file starting with _ are ignored)."
@@ -151,17 +151,22 @@ else
151151
fi
152152
done
153153
fi
154-
if [ "$SMOKE_ALL_FILES" != "" ]; then
155-
if [ "$TESTS_TO_RUN" != "" ]; then
154+
if [ "${#SMOKE_ALL_FILES[@]}" -ne 0 ]; then
155+
if [ "${#TESTS_TO_RUN[@]}" -ne 0 ]; then
156156
echo "#### WARNING"
157157
echo "When passing .qmd, .md and/or .ipynb, only ./smoke/smoke-all.test.ts will be run. Other tests files are ignored."
158-
echo "Ignoring ${TESTS_TO_RUN}."
158+
echo "Ignoring ${TESTS_TO_RUN[*]}."
159159
echo "####"
160160
fi
161-
TESTS_TO_RUN="${SMOKE_ALL_TEST_FILE} -- ${SMOKE_ALL_FILES}"
161+
TESTS_TO_RUN=("${SMOKE_ALL_TEST_FILE}" "--" "${SMOKE_ALL_FILES[@]}")
162162
fi
163163
fi
164-
"${QUARTO_BIN_PATH}/tools/${DENO_ARCH_DIR}/deno" test ${QUARTO_DENO_OPTIONS} --check ${QUARTO_DENO_EXTRA_OPTIONS} "${QUARTO_IMPORT_MAP_ARG}" $TESTS_TO_RUN
164+
# TESTS_TO_RUN is an array and quoted here on purpose: a bucket can be a
165+
# literal, unexpanded ** glob pattern (e.g. from the ff-matrix CI bucket),
166+
# and smoke-all.test.ts expands it itself via expandGlobSync. Expanding it
167+
# here instead would depend on bash's own (non-recursive by default) glob
168+
# semantics and could silently drop deeply nested matches.
169+
"${QUARTO_BIN_PATH}/tools/${DENO_ARCH_DIR}/deno" test ${QUARTO_DENO_OPTIONS} --check ${QUARTO_DENO_EXTRA_OPTIONS} "${QUARTO_IMPORT_MAP_ARG}" "${TESTS_TO_RUN[@]}"
165170
SUCCESS=$?
166171
fi
167172

0 commit comments

Comments
 (0)