@@ -37,7 +37,6 @@ results_file="${output_dir}/results.json"
3737# - We can work with a write-able file-system
3838# - We avoid copying files between the docker host and client giving a nice speedup.
3939build_dir=/tmp/build
40- cache_dir=${build_dir} /cache
4140
4241if [ ! -d " ${input_dir} " ]; then
4342 echo " No such directory: ${input_dir} "
5554mkdir -p ${build_dir}
5655pushd " ${build_dir} " > /dev/null || exit
5756
58- # Put the basic spago project in place
59- cp " ${input_dir} " /* .dhall .
57+ # Put the spago project in place: copy and rewrite the package name to match
58+ # the pre-compiled lockfile so we can use --pure mode (no registry access).
59+ sed ' s/^ name: .*/ name: pre-compiled/' " ${input_dir} /spago.yaml" > spago.yaml
6060ln -s " ${input_dir} " /src .
6161ln -s " ${input_dir} " /test .
6262
63- # Setup cache directory. We require a writable dhall cache because dhall will
64- # attempt to fetch the upstream package-set definition.
65- mkdir ${cache_dir}
66- cp -R " ${HOME} " /.cache/dhall ${cache_dir}
67- cp -R " ${HOME} " /.cache/dhall-haskell ${cache_dir}
68-
6963# Setup our prepared node setup.
7064ln -s " ${base_dir} /pre-compiled/node_modules" .
7165
@@ -75,17 +69,15 @@ ln -s "${base_dir}/pre-compiled/node_modules" .
7569# flag).
7670cp -R -p " ${base_dir} /pre-compiled/output" .
7771cp -R " ${base_dir} /pre-compiled/.spago" .
72+ cp " ${base_dir} /pre-compiled/spago.lock" .
7873
7974echo " Build and test ${slug} in ${build_dir} ..."
8075
8176# Run the tests for the provided implementation file and redirect stdout and
82- # stderr to capture it. We do our best to minimize the output to emit and
83- # compiler errors or unit test output as this scrubbed and presented to the
84- # student. In addition spago will try to write to ~/cache/.spago and will fail
85- # on a read-only mount and thus we skip the global cache and request to not
86- # install packages.
87- export XDG_CACHE_HOME=${cache_dir}
88- spago_output=$( npx spago --global-cache skip --no-psa test --no-install 2>&1 )
77+ # stderr to capture it.
78+ # --offline --pure: use cached packages and lockfile, no registry/network access
79+ # HOME=/tmp: Spago's SQLite cache needs a writable directory (Docker runs --read-only)
80+ spago_output=$( HOME=/tmp npx spago test --offline --pure 2>&1 )
8981exit_code=$?
9082
9183popd > /dev/null || exit
@@ -95,9 +87,30 @@ popd > /dev/null || exit
9587if [ $exit_code -eq 0 ]; then
9688 jq -n ' {version: 1, status: "pass"}' > " ${results_file} "
9789else
98- sanitized_spago_output=$( echo " ${spago_output} " | sed -E \
99- -e ' /^Compiling/d' \
100- -e ' /at.*:[[:digit:]]+:[[:digit:]]+\)?/d' )
90+ sanitized_spago_output=$( printf ' %s\n' " ${spago_output} " | awk '
91+ BEGIN { blanks = 2 }
92+ /^Reading Spago workspace/ || \
93+ /^✓ Selecting package/ || \
94+ /^Checking dependencies/ || \
95+ /^Downloading dependencies/ || \
96+ /^No lockfile found/ || \
97+ /^Lockfile written/ || \
98+ /^Building\.\.\./ || \
99+ /^\[[[:space:]]*[0-9]+ of [0-9]+\] Compiling / || \
100+ /^✓ Build succeeded/ || \
101+ /^Running tests for package/ || \
102+ /^✘ Tests failed/ || \
103+ /^✘ Failed to build/ || \
104+ /^[[:space:]]+Src[[:space:]]+Lib[[:space:]]+All/ || \
105+ /^Warnings[[:space:]]+[0-9]/ || \
106+ /^Errors[[:space:]]+[0-9]/ || \
107+ /^[[:space:]]+at .*(\.js|\.mjs|node:internal).*:[0-9]/ { next }
108+ /^\[WARNING / { warn = 1; next }
109+ warn && /^$/ { warn = 0; next }
110+ warn { next }
111+ NF { blanks = 0; print; next }
112+ blanks < 2 { blanks++; print }
113+ ' )
101114
102115 jq --null-input --arg output " ${sanitized_spago_output} " ' {version: 1, status: "fail", message: $output}' > " ${results_file} "
103116fi
0 commit comments