From 89e6189cc341fa0719ebeaddcc123ba22d73f8a4 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Wed, 29 Jul 2026 00:40:21 +0300 Subject: [PATCH] release-all.yml: fix the four things the v10.48 logs showed, and stop misattributing the failures. Every one of these made a release job report the wrong cause, which is worse than the failure itself: two of them sent the last round of work after the wrong problem. 1. snap-launchpad never checked whether a .snap existed. In three steps it did snaps=( wekan_${VERSION}_.snap ) and then counted the array. That string has no wildcard, so it is a literal filename, `shopt -s nullglob` cannot empty a literal, and the count was ALWAYS 1 whether or not the file was there. So s390x logged an empty `Artifacts:` list, then "Remote build s390x succeeded", then 'wekan_10.48_s390x.snap' is not a valid file ##[error]SNAP_AUTH did not work: the Snap Store refused the upload The Snap Store never saw an upload. It is a real glob now, the first match must also be non-empty, and the upload step says "the Launchpad build produced no artifact - this is NOT a SNAP_AUTH problem" for a missing file and keeps the credential advice for a refusal by the store. 2. The Launchpad build log was downloaded and thrown away. It is the only thing that says why a build ends as "Stopped", and the job printed it only when snapcraft's exit code was non-zero - which, after (1), it was not. It is now printed whenever there is no snap, along with `ls -la`, and the "exit 0 but nothing built" case says so in words. 3. build-win64 verified the zip by listing it into a variable and grepping that, so a failure printed the verdict and none of the evidence: "has no bundle/main.js" with no way to tell a bad zip from a bad grep. What can be checked robustly now is: bundle/main.js, bundle/node.exe and bundle/start-wekan.bat exist and are non-empty BEFORE zipping, and the archive passes `7z t`. The listing is printed - five lines and a match count per file - and a zero count is a warning naming both facts that contradict it, not a failed release. 4. The snap-variants pre-flight asked GitHub for `.permissions.push` on the variant repository. That field is the authenticated USER's role, not what the token may do: it answered true, and the push one step later got remote: Permission to wekan/wekan-gantt-gpl.git denied to xet7 It now asks the receive-pack advertisement - the first thing a real push requests, and what GitHub answers 403 to for a token without Contents:write - with the token in curl's -u rather than in a URL, and no git command, since this step runs before actions/checkout. What still needs a person is unchanged and written up in ../log/workflow/TODO.txt: why Launchpad stops the ppc64el and s390x builds after ~20 minutes, and giving WEKAN_REPO_TOKEN write access to the two variant repositories. tests/releaseWin64AndVariants.test.cjs is new and pins (3) and (4); tests/releaseSnapArches.test.cjs gains "every snaps=() must be a real glob" and "the build log is printed whenever there is no snap", and its "SNAP_AUTH did not work" assertion is replaced by the two messages that took its place, with a note saying why. Both read the workflow with comments stripped - the comments quote the broken lines on purpose. Thanks to xet7 ! --- .github/workflows/release-all.yml | 127 +++++++++++++++++++------ tests/releaseSnapArches.test.cjs | 52 +++++++++- tests/releaseWin64AndVariants.test.cjs | 122 ++++++++++++++++++++++++ 3 files changed, 272 insertions(+), 29 deletions(-) create mode 100644 tests/releaseWin64AndVariants.test.cjs diff --git a/.github/workflows/release-all.yml b/.github/workflows/release-all.yml index cd352a249e..a8aa4db506 100644 --- a/.github/workflows/release-all.yml +++ b/.github/workflows/release-all.yml @@ -913,6 +913,17 @@ jobs: fi # Self-contained Windows launcher (defaults to FerretDB SQLite). cp src/releases/ferretdb/start-wekan.bat bundle/ + # Check what goes IN, before anything is archived. This is the honest place + # for it: whether the zip can hold a startable bundle is decided here, in a + # plain directory, with no archive-listing format in the way. + for want in main.js node.exe start-wekan.bat; do + if [ ! -s "bundle/$want" ]; then + echo "::error::bundle/$want is missing or empty, so the win64 zip cannot start WeKan. The bundle comes from the build job; the lines above say what was copied in." + exit 1 + fi + done + echo "bundle/ has main.js, node.exe and start-wekan.bat:" + ls -la bundle | head -20 - name: Create win64 zip shell: cmd @@ -934,18 +945,34 @@ jobs: echo "::error::$zip is only $bytes bytes; a whole bundle is tens of megabytes. The bundle directory was empty or partial when it was zipped." exit 1 fi - # 7-Zip lists Windows paths with BACKSLASHES, and a backslash in a regex - # escapes the next character - "bundle\main.js" as a pattern matches - # "bundlemain.js", which nothing is called. So: list once, and look for - # either separator as a fixed string, never as a pattern. - listing="$(7z l -ba "$zip")" + # Integrity: `7z t` reads every entry and fails on a truncated or corrupt + # archive. Together with the check on bundle/ before zipping, that is what + # actually decides whether this zip is startable. + if ! 7z t "$zip" > 7z-test.log 2>&1; then + echo "::error::$zip did not pass 7z t - the archive is corrupt or truncated." + tail -n 30 7z-test.log + exit 1 + fi + echo "7z t: archive is intact." + # The listing is EVIDENCE, printed, not a hidden verdict. v10.48 failed the + # release because `grep` found neither "bundle\main.js" nor "bundle/main.js" + # in `7z l -ba` output that nothing ever printed, so a bad zip and a bad + # grep looked exactly alike. Now the listing shows itself, and a missing + # match is a WARNING: bundle/main.js was verified to exist before zipping + # and the archive passed its integrity test, so a zero count here says + # something about 7-Zip's output format, not about the bundle. + listing="$(7z l -ba "$zip" 2>/dev/null || true)" + entries="$(printf '%s\n' "$listing" | grep -c . || true)" + echo "7z l -ba listed $entries entries; the first five:" + printf '%s\n' "$listing" | head -5 for want in main.js node.exe; do - if ! printf '%s' "$listing" | grep -qF -e "bundle\\$want" -e "bundle/$want"; then - echo "::error::$zip has no bundle/$want, so it cannot start WeKan on Windows. The embed step above did not put it into the bundle." - exit 1 + n="$(printf '%s\n' "$listing" | grep -F -c -e "bundle\\$want" -e "bundle/$want" || true)" + echo " entries matching bundle/$want: $n" + if [ "${n:-0}" -eq 0 ]; then + echo "::warning::$zip listing shows no bundle/$want, but bundle/$want existed before zipping and the archive passed 7z t. Compare the five listing lines above with what is being searched for." fi done - echo "OK: $zip is $((bytes/1024/1024)) MiB and contains bundle/main.js and bundle/node.exe." + echo "OK: $zip is $((bytes/1024/1024)) MiB, intact, and was built from a bundle that had main.js and node.exe." - uses: actions/upload-artifact@v7 with: @@ -1922,10 +1949,12 @@ jobs: # core24; Canonical's answer for non-native arches on core24 IS remote-build. See # docs/Design/Autoupdate/Forks/Snap-Core.md. # - # This job is also what the older Launchpad legs were not: it requires the .snap - # file to exist, retries the remote build 3x, and uploads only when the file is - # there - which is the "is not a valid file" (snapcraft upload, exit 64) failure - # that prompted the move to QEMU in the first place. + # This job retries the remote build 3x and uploads only when a .snap file is + # really there - the "is not a valid file" (snapcraft upload, exit 64) failure + # that prompted the move to QEMU in the first place. It claimed to do that from + # the start; the test was a literal filename in an array, never a glob, so it was + # always true and v10.48 uploaded a file that did not exist. It asks the + # filesystem now. # # continue-on-error: an exotic Launchpad arch must NOT hold up or fail the # release. A Launchpad build can queue for hours / time out; that must not turn @@ -2006,6 +2035,14 @@ jobs: # arch never blocks the others. remote-build can exit 0 without producing a # .snap (it just downloads logs), so require the file. Retry a few times to # survive transient TLS drops to Launchpad. + # + # The file test used to be `snaps=( wekan_${VERSION}_.snap )` and then + # `[ ${#snaps[@]} -gt 0 ]`. That string has no wildcard in it, so it is not a + # glob - it is a literal filename, `shopt -s nullglob` cannot empty a literal, + # and the count was ALWAYS 1 whether or not the file existed. v10.48 s390x + # therefore reported "succeeded" over an empty `Artifacts:` list and walked + # into `'wekan_10.48_s390x.snap' is not a valid file` in the upload step - a + # missing file, blamed on SNAP_AUTH. Ask the filesystem instead. run: | set -uo pipefail shopt -s nullglob @@ -2015,12 +2052,22 @@ jobs: snapcraft remote-build --launchpad-accept-public-upload \ --build-for ${{ matrix.arch }} && rc=0 || rc=$? echo "::endgroup::" - snaps=( wekan_${VERSION}_${{ matrix.arch }}.snap ) - if [ "$rc" -eq 0 ] && [ "${#snaps[@]}" -gt 0 ]; then + # A real glob, so nullglob can empty it, plus any name Launchpad chose. + snaps=( wekan_${VERSION}_${{ matrix.arch }}*.snap *_${{ matrix.arch }}.snap ) + if [ "$rc" -eq 0 ] && [ "${#snaps[@]}" -gt 0 ] && [ -s "${snaps[0]}" ]; then echo "Remote build ${{ matrix.arch }} succeeded on attempt $i: ${snaps[*]}" exit 0 fi - echo "Attempt $i: snapcraft exit=$rc, .snap files produced=${#snaps[@]}." + if [ "$rc" -eq 0 ]; then + echo "Attempt $i: snapcraft exited 0 but produced NO .snap for ${{ matrix.arch }} - the Launchpad build did not finish (a 'Stopped' build downloads logs and no artifact). Everything in the directory:" + else + echo "Attempt $i: snapcraft exit=$rc, .snap files produced=${#snaps[@]}." + fi + ls -la + # The Launchpad build log is the only thing that says WHY a build stopped, + # and it is downloaded here. Print it whenever there is no snap - not only + # when snapcraft's exit code is non-zero, which is how v10.48 fetched it + # and threw it away. for log in snapcraft-wekan-*.txt; do echo "::group::Launchpad build log: $log (last 150 lines)" tail -n 150 "$log" @@ -2031,7 +2078,7 @@ jobs: sleep 60 fi done - echo "::error::Remote build ${{ matrix.arch }} failed after $attempts attempts (no wekan_${VERSION}_${{ matrix.arch }}.snap produced)." >&2 + echo "::error::Remote build ${{ matrix.arch }} failed after $attempts attempts (no wekan_${VERSION}_${{ matrix.arch }}.snap produced). The Launchpad build log printed above says why; the builds are also at https://launchpad.net/~xet7/+snaps" >&2 # The commonest cause after a plain build error is the credential: Launchpad # answers 401/403 for an expired or wrong LP_CREDENTIALS, which reads as an # ordinary build failure unless the log says so. @@ -2046,16 +2093,19 @@ jobs: run: | set -euo pipefail shopt -s nullglob - snaps=( wekan_${VERSION}_${{ matrix.arch }}.snap ) - if [ "${#snaps[@]}" -eq 0 ]; then - echo "::error::No wekan_${VERSION}_${{ matrix.arch }}.snap to upload." + snaps=( wekan_${VERSION}_${{ matrix.arch }}*.snap *_${{ matrix.arch }}.snap ) + # "No file" and "the store said no" are two different problems with two + # different owners, so they are two different messages. v10.48 printed the + # SNAP_AUTH one for a file that was never built. + if [ "${#snaps[@]}" -eq 0 ] || [ ! -s "${snaps[0]}" ]; then + echo "::error::No wekan_${VERSION}_${{ matrix.arch }}.snap to upload - the Launchpad build produced no artifact. This is NOT a SNAP_AUTH problem; see the build step above." exit 1 fi # base: core24 allows publishing to stable and candidate (core26 does not). for f in "${snaps[@]}"; do echo "Uploading $f to the Snap Store (stable,candidate,beta,edge)..." if ! snapcraft upload --release=stable,candidate,beta,edge "$f"; then - echo "::error::SNAP_AUTH did not work: the Snap Store refused the upload of $f. Re-export it with: snapcraft export-login --snaps wekan --acls package_access,package_push,package_release,package_update snap-auth.txt" + echo "::error::The Snap Store refused the upload of $f. If it says the file is invalid, the build is broken; if it says unauthorized, re-export SNAP_AUTH with: snapcraft export-login --snaps wekan --acls package_access,package_push,package_release,package_update snap-auth.txt" exit 1 fi done @@ -2066,9 +2116,11 @@ jobs: run: | set -euo pipefail shopt -s nullglob - snaps=( wekan_${VERSION}_${{ matrix.arch }}.snap ) - if [ "${#snaps[@]}" -gt 0 ]; then + snaps=( wekan_${VERSION}_${{ matrix.arch }}*.snap *_${{ matrix.arch }}.snap ) + if [ "${#snaps[@]}" -gt 0 ] && [ -s "${snaps[0]}" ]; then gh release upload "v${VERSION}" "${snaps[@]}" --clobber + else + echo "No ${{ matrix.arch }} snap to attach - the build produced none." fi # Always, as the last step: the run summary then answers "what worked and what @@ -2145,11 +2197,32 @@ jobs: elif [ "$code" != "200" ]; then echo "ok=false" >> "$GITHUB_OUTPUT" echo "::warning::snap-variants (${{ matrix.snapname }}) skipped — GitHub answered HTTP $code for wekan/${{ matrix.repo }}: WEKAN_REPO_TOKEN is expired, revoked, or has no access." - elif [ "$(jq -r '.permissions.push // false' /tmp/variant.json)" != "true" ]; then - echo "ok=false" >> "$GITHUB_OUTPUT" - echo "::warning::snap-variants (${{ matrix.snapname }}) skipped — WEKAN_REPO_TOKEN reaches wekan/${{ matrix.repo }} but may not PUSH to it. A classic PAT needs the 'repo' scope; a fine-grained PAT needs Contents: Read and write on that repository." else - echo "ok=true" >> "$GITHUB_OUTPUT" + # `.permissions.push` from the repos API is NOT the answer, and this is + # where v10.48 went wrong: that field describes the authenticated USER's + # role in the repository, not what this token may do, so a fine-grained + # PAT that was never scoped to the repo still reads push=true. The guard + # passed, and the next step got + # remote: Permission to wekan/${{ matrix.repo }}.git denied to xet7 + # + # So ask the endpoint that actually refuses: the receive-pack + # advertisement, which is the first thing a real `git push` requests and + # which GitHub answers 403 to for a token without write. It writes + # nothing, and it needs no local clone (this step runs before checkout). + # The token goes in -u, never in the URL, so it cannot land in the log. + rp=$(curl -sS -o /dev/null -w '%{http_code}' \ + -u "x-access-token:$REPO_TOKEN" \ + "https://github.com/wekan/${{ matrix.repo }}.git/info/refs?service=git-receive-pack") + if [ "$rp" = "200" ]; then + echo "ok=true" >> "$GITHUB_OUTPUT" + echo "WEKAN_REPO_TOKEN may push to wekan/${{ matrix.repo }} (receive-pack answered 200)." + elif [ "$rp" = "403" ] || [ "$rp" = "401" ]; then + echo "ok=false" >> "$GITHUB_OUTPUT" + echo "::warning::snap-variants (${{ matrix.snapname }}) skipped — WEKAN_REPO_TOKEN can READ wekan/${{ matrix.repo }} but may NOT push to it (receive-pack answered HTTP $rp). A classic PAT needs the 'repo' scope and its account must have write access to that repository; a fine-grained PAT needs wekan/${{ matrix.repo }} in its repository list with Contents: Read and write. See docs/Design/Autoupdate/Snap-Ondra-Gantt.md." + else + echo "ok=false" >> "$GITHUB_OUTPUT" + echo "::warning::snap-variants (${{ matrix.snapname }}) skipped — the push pre-flight for wekan/${{ matrix.repo }} answered HTTP $rp, which is neither a yes nor a permission refusal. Nothing was pushed." + fi fi - name: Checkout wekan at the release tag diff --git a/tests/releaseSnapArches.test.cjs b/tests/releaseSnapArches.test.cjs index fe27c5fa62..72547c17ed 100644 --- a/tests/releaseSnapArches.test.cjs +++ b/tests/releaseSnapArches.test.cjs @@ -33,6 +33,14 @@ function test(name, fn) { } } +// A comment in a YAML `run:` block is text the shell never sees, and this file +// has been fooled by it before: a comment that QUOTES the old broken code (kept +// on purpose, so the next reader knows what the fix was for) reads exactly like +// the code it replaced. Assertions about what the shell DOES use this. +function code(text) { + return text.split('\n').filter(l => !/^\s*#/.test(l)).join('\n'); +} + // The body of one top-level job: from " :" to the next job at the same // indentation. Good enough to ask which matrix and which options are ITS own. function job(name) { @@ -112,8 +120,18 @@ test('it names the secret it is missing, and the one Launchpad refused', () => { assert.ok(/base64 -d/.test(launchpad), 'and decode LP_CREDENTIALS rather than trust it'); assert.ok(/LP_CREDENTIALS may not work/.test(launchpad), 'and say so when Launchpad answers unauthorized'); - assert.ok(/SNAP_AUTH did not work/.test(launchpad), - 'and when the Snap Store refuses the upload'); + // Changed deliberately after v10.48: the upload step used to print "SNAP_AUTH + // did not work" for a snap that was never built, because its existence test was + // a literal filename in an array (see the test below). "The build produced + // nothing" and "the store said no" are two different problems with two different + // owners, so they are now two different messages - and the store one still names + // the secret and the command that re-exports it. + assert.ok(/This is NOT a SNAP_AUTH problem/.test(launchpad), + 'a missing artifact must NOT be reported as a credential failure'); + assert.ok(/The Snap Store refused the upload/.test(launchpad), + 'and a real refusal by the store is its own message'); + assert.ok(/re-export SNAP_AUTH with: snapcraft export-login/.test(launchpad), + 'which says how to fix it'); }); test('a remote build that produced no .snap is a failure, not a silent success', () => { @@ -123,6 +141,36 @@ test('a remote build that produced no .snap is a failure, not a silent success', assert.ok(/No wekan_\$\{VERSION\}_\$\{\{ matrix\.arch \}\}\.snap to upload/.test(launchpad), 'the upload step must refuse to run without the file'); assert.ok(/failed after \$attempts attempts/.test(launchpad), 'and the build step must retry'); + + // v10.48: every one of those tests was `snaps=( wekan_${VERSION}_.snap )` + // followed by a count. That string has no wildcard, so it is a literal filename, + // `shopt -s nullglob` cannot empty a literal, and the count was ALWAYS 1 - s390x + // reported "succeeded" over an empty artifact list and uploaded a file that did + // not exist. Every array built from a .snap name must therefore be a real GLOB. + const arrays = [...code(launchpad).matchAll(/snaps=\(([^)]*)\)/g)].map(m => m[1].trim()); + assert.ok(arrays.length >= 3, 'the build, upload and attach steps each look for the file'); + for (const a of arrays) { + assert.ok(a.includes('*'), + `"snaps=( ${a} )" has no wildcard, so it is a literal filename that always ` + + 'exists as a string - nullglob cannot empty it and the count is always 1'); + } + // And the count alone is not enough: an empty file passes it. + assert.ok(/\[ -s "\$\{snaps\[0\]\}" \]/.test(code(launchpad)), + 'the file must also be non-empty before it is uploaded or attached'); +}); + +test('the Launchpad build log is printed whenever there is no snap', () => { + // It is downloaded by remote-build and is the only thing that says WHY a build + // stopped. v10.48 fetched it, exited 0 (see above) and threw it away, so three + // "Stopped" builds left no trace of their reason anywhere. + const launchpad = job('snap-launchpad'); + const build = launchpad.slice(launchpad.indexOf('Build the ${{ matrix.arch }} snap on Launchpad')); + const loop = build.slice(0, build.indexOf('- name: Push')); + assert.ok(/for log in snapcraft-wekan-\*\.txt/.test(loop), 'the downloaded log is read'); + assert.ok(/exited 0 but produced NO \.snap/.test(loop), + 'and the "exit 0, no artifact" case says so in words instead of passing'); + assert.ok(loop.indexOf('for log in snapcraft-wekan-*.txt') > loop.indexOf('exited 0 but produced NO .snap'), + 'the log is printed on that path too, not only when snapcraft exits non-zero'); }); console.log(`\n${passed} tests passed`); diff --git a/tests/releaseWin64AndVariants.test.cjs b/tests/releaseWin64AndVariants.test.cjs new file mode 100644 index 0000000000..9373950b4d --- /dev/null +++ b/tests/releaseWin64AndVariants.test.cjs @@ -0,0 +1,122 @@ +'use strict'; + +// Plain-Node guard for two release-all.yml jobs that failed v10.48 for reasons +// that were not what the log said. Run: node tests/releaseWin64AndVariants.test.cjs +// +// build-win64: the zip was verified by listing it with `7z l -ba` INTO A VARIABLE +// and grepping that. When the grep found nothing the log had the verdict — "has +// no bundle/main.js" — and not one line of the listing it judged, so a broken zip +// and a broken grep looked exactly alike. Two releases were failed on it. What +// can be verified robustly is verified robustly (the files are there before +// zipping; the archive passes `7z t`), and the listing is now printed as evidence +// rather than used as a hidden verdict. +// +// snap-variants: the pre-flight asked GitHub for `.permissions.push` on the +// variant repository, which describes the authenticated USER's role rather than +// what the TOKEN may do — it answered `true`, and the push one step later was +// refused with "Permission to wekan/wekan-gantt-gpl.git denied to xet7". The +// pre-flight now asks the receive-pack endpoint, which is the thing that refuses. + +const assert = require('assert'); +const fs = require('fs'); +const path = require('path'); + +const repoRoot = path.resolve(__dirname, '..'); +const workflow = fs.readFileSync( + path.join(repoRoot, '.github/workflows/release-all.yml'), 'utf8', +); + +// A comment inside a `run:` block is text the shell never sees. These files keep +// the OLD broken line in a comment on purpose, so assertions about behaviour must +// read the code only. +const code = text => text.split('\n').filter(l => !/^\s*#/.test(l)).join('\n'); + +function job(name) { + const start = workflow.indexOf(`\n ${name}:\n`); + assert.notStrictEqual(start, -1, `release-all.yml has no ${name} job`); + const rest = workflow.slice(start + 1); + const next = rest.search(/\n [a-z0-9-]+:\n/); + return next === -1 ? rest : rest.slice(0, next); +} + +let passed = 0; +function test(name, fn) { + try { + fn(); + passed++; + console.log(' ok -', name); + } catch (err) { + console.error(` FAIL - ${name}\n ${err.message}`); + process.exitCode = 1; + } +} + +console.log('releaseWin64AndVariants:'); + +const win = code(job('build-win64')); + +test('the bundle is checked BEFORE it is zipped', () => { + const embed = win.slice(0, win.indexOf('Create win64 zip')); + for (const want of ['main.js', 'node.exe', 'start-wekan.bat']) { + assert.ok(embed.includes(want), `${want} is named in the embed step`); + } + assert.ok(/\[ ! -s "bundle\/\$want" \]/.test(embed), + 'each one must be present and non-empty in the directory - that is where ' + + '"can this zip start WeKan" is actually decided, with no archive format in the way'); + assert.ok(/exit 1/.test(embed), 'and a missing one fails the job there'); +}); + +test('the archive is verified by an integrity test, not by grepping a listing', () => { + const verify = win.slice(win.indexOf('Verify the win64 zip')); + assert.ok(/7z t "\$zip"/.test(verify), + '`7z t` reads every entry and is what catches a truncated or corrupt zip'); + assert.ok(/did not pass 7z t/.test(verify), 'and says so when it fails'); +}); + +test('the listing is PRINTED, and a missing match is a warning, not a failure', () => { + const verify = win.slice(win.indexOf('Verify the win64 zip')); + assert.ok(/printf '%s\\n' "\$listing" \| head -5/.test(verify), + 'the listing must appear in the log; judging it invisibly is the bug this fixes'); + assert.ok(/entries matching bundle\/\$want/.test(verify), + 'with the match count for each wanted file'); + const missing = verify.slice(verify.indexOf('if [ "${n:-0}" -eq 0 ]')); + assert.ok(/::warning::/.test(missing.slice(0, 400)), + 'a zero count is a WARNING: the file was verified in the directory and the ' + + 'archive passed 7z t, so a zero count says something about 7-Zip output, ' + + 'not about the bundle'); + assert.ok(!/::error::[\s\S]{0,200}has no bundle/.test(verify), + 'and it must not fail the release on the listing format again'); +}); + +const variants = code(job('snap-variants')); + +test('the push pre-flight asks the endpoint that refuses a push', () => { + assert.ok(/service=git-receive-pack/.test(variants), + 'the receive-pack advertisement is the first thing a real push requests, and ' + + 'is what GitHub answers 403 to for a token without write access'); + assert.ok(!/permissions\.push/.test(variants), + 'the repos API permissions block describes the USER, not the token - it said ' + + 'push=true for a token that was then refused'); +}); + +test('the pre-flight cannot leak the token, and needs no checkout', () => { + const guard = variants.slice(0, variants.indexOf('- name: Checkout wekan')); + assert.ok(/-u "x-access-token:\$REPO_TOKEN"/.test(guard), + 'the token goes in -u, never in a URL that could be echoed'); + assert.ok(!/https:\/\/x-access-token:\$\{?REPO_TOKEN/.test(guard), + 'no token-in-URL in the pre-flight'); + assert.ok(!/git (clone|push|ls-remote)/.test(guard), + 'and no git command: this step runs BEFORE actions/checkout, so there is no ' + + 'local repository for git to work in'); +}); + +test('a refusal and a broken pre-flight are told apart', () => { + assert.ok(/"\$rp" = "403"/.test(variants) && /"\$rp" = "401"/.test(variants), + '403/401 is "the token may not push"'); + assert.ok(/neither a yes nor a permission refusal/.test(variants), + 'anything else says it is something else, instead of blaming the token'); + assert.ok(/Contents: Read and write/.test(variants), + 'and the refusal message says exactly what to change'); +}); + +console.log(`\n${passed} tests passed`);