Skip to content

Commit 5ee76a8

Browse files
radroidclaude
andcommitted
fix(coil): restore the release, and make two of its checks capable of failing
Releases have been red since #53 landed. Build 106 was the last one published; every run after it failed before publishing anything. Three defects, all in the new bundle-size checks, and the third is the one worth reading twice. 1. The exclusions CLI wrote nothing on Windows. All three scripts guarded their CLI entry point with `import.meta.url === \`file://${process.argv[1]}\``. That is false on Windows, where argv[1] is a native path: the template builds `file://D:\a\...` while `import.meta.url` is `file:///D:/a/...`. It works on macOS and Linux only because an absolute POSIX path already begins with `/`, which is why it passed review and passed on one runner. So `node desktop-file-exclusions.mjs` parsed, ran nothing, wrote nothing and exited 0, and the release step correctly refused an empty exclusion list. The same guard is in verify-desktop-bundle.mjs, which the release invokes as a CLI — so on Windows that verification would have exited 0 without running even once the rest of this was fixed. Fixed with `pathToFileURL`, which is what Node provides for this conversion. 2. app.asar was never under release/. Both checks searched `release/`. The build copies only FILES out of its staging dir — `if (!stat || stat.type !== "File") continue` — and the macOS `.app` and Windows `win-unpacked/` are directories, so the trees holding app.asar are never copied there. The staging dir was also a SCOPED temp dir, deleted when the build exits, so there was nothing to find anywhere. T3CODE_DESKTOP_KEEP_STAGE keeps it, one new step resolves it through `os.tmpdir()` rather than assuming /tmp or %TEMP%, and a cleanup step drops it again before the upload. 3. The app-update.yml guard had never been able to fail. Same wrong directory, opposite outcome. It searched release/ for a file that only exists inside the .app, found nothing, printed "No app-update.yml packaged", and passed — every run, unconditionally. It was never checking the claim it is the only evidence for: that this fork's toast is the sole update surface and upstream's electron-updater is off. A check that fails loudly costs one red build. A check that cannot fail costs nothing until the day it was supposed to catch something. Tests cover the shape that broke rather than the line: invoked as a CLI, these scripts must actually do something. They cannot run on Windows here — this fork has no Windows CI runner — so that platform's correctness rests on pathToFileURL being the right primitive, not on a green check. That asymmetry is the same one that let this ship. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent da8bd18 commit 5ee76a8

5 files changed

Lines changed: 181 additions & 7 deletions

File tree

‎.github/workflows/coil-release.yml‎

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ jobs:
545545
# Issue #53. Takes the packaged asar from 189.66 MiB / 14,765 files to 99.02 MiB / 3,429.
546546
# Scoped to this step on purpose — see the note on the step that produces it.
547547
T3X_DESKTOP_FILE_EXCLUSIONS: ${{ steps.exclusions.outputs.value }}
548+
# Keeps electron-builder's staging tree after the build so the two checks below have
549+
# something to read. Without it `stageRoot` is a SCOPED temp dir — deleted the moment the
550+
# build process exits — and `app.asar` exists nowhere on disk by the time they run. The
551+
# cleanup step below removes it again, so the disk cost does not reach the upload.
552+
T3CODE_DESKTOP_KEEP_STAGE: "1"
548553
run: |
549554
set -euo pipefail
550555
node scripts/build-desktop-artifact.ts \
@@ -555,16 +560,57 @@ jobs:
555560
--skip-build \
556561
--verbose
557562
563+
# BOTH checks below used to search `release/`, and neither could work there.
564+
#
565+
# `release/` holds only the finished artifacts, because the build copies FILES out of its
566+
# staging dir and skips everything else — `if (!stat || stat.type !== "File") continue` in
567+
# scripts/build-desktop-artifact.ts. The macOS `.app` and the Windows `win-unpacked/` are
568+
# DIRECTORIES, so the trees that contain `app.asar` are never copied there. And the staging dir
569+
# itself was scoped, so it had already been deleted.
570+
#
571+
# The two failed in opposite directions, which is why only one was noticed: the asar check
572+
# exited 1 and took the release down, while the app-update.yml check found nothing, printed
573+
# "No app-update.yml packaged", and passed. It had never once been able to fail.
574+
#
575+
# `os.tmpdir()` is read through node rather than assuming /tmp or %TEMP%, so this resolves the
576+
# same directory the build used on both runners. Backslashes are folded to forward slashes
577+
# because git-bash's `find` cannot take a native Windows path but does accept `C:/...`.
578+
- name: Locate the staged bundle
579+
id: packaged
580+
shell: bash
581+
run: |
582+
set -euo pipefail
583+
tmp="$(node -p 'require("node:os").tmpdir().replace(/\\/g, "/")')"
584+
585+
# Newest first. A retried build leaves an older stage behind, and a check that reads the
586+
# previous run's tree is worth less than no check at all.
587+
dist=""
588+
for candidate in $(ls -dt "$tmp"/t3code-desktop-*-stage-*/app/dist 2>/dev/null || true); do
589+
dist="$candidate"
590+
break
591+
done
592+
593+
if [[ -z "$dist" || ! -d "$dist" ]]; then
594+
echo "::error::No staging dist found under $tmp — the checks below would verify nothing." >&2
595+
echo "Contents of $tmp:" >&2
596+
ls -la "$tmp" >&2 || true
597+
exit 1
598+
fi
599+
600+
echo "dist=$dist" >> "$GITHUB_OUTPUT"
601+
echo "Verifying the tree at $dist"
602+
ls -la "$dist" || true
603+
558604
- name: Verify no update feed was packaged
559605
shell: bash
560606
run: |
561607
set -euo pipefail
562608
# The machine-checkable form of "exactly one update surface". This is the claim most
563609
# likely to regress silently on an upstream sync, so it fails the release rather than
564610
# shipping an app with two updaters that disagree.
565-
if find release -name "app-update.yml" -print -quit | grep -q .; then
611+
if find "${{ steps.packaged.outputs.dist }}" -name "app-update.yml" -print -quit | grep -q .; then
566612
echo "::error::app-update.yml was packaged. Upstream's updater would be live in this build." >&2
567-
find release -name "app-update.yml" >&2
613+
find "${{ steps.packaged.outputs.dist }}" -name "app-update.yml" >&2
568614
exit 1
569615
fi
570616
echo "No app-update.yml packaged."
@@ -586,13 +632,26 @@ jobs:
586632
shell: bash
587633
run: |
588634
set -euo pipefail
589-
asar="$(find release -name "app.asar" -print -quit)"
635+
asar="$(find "${{ steps.packaged.outputs.dist }}" -name "app.asar" -print -quit)"
590636
if [[ -z "$asar" ]]; then
591-
echo "::error::No app.asar found under release/. Nothing was verified." >&2
637+
echo "::error::No app.asar under ${{ steps.packaged.outputs.dist }}. Nothing was verified." >&2
592638
exit 1
593639
fi
594640
node scripts/coil/verify-desktop-bundle.mjs --asar "$asar"
595641
642+
# The staging tree is a second full copy of the app — kept only for the two checks above, and
643+
# dropped here rather than at job end so it is gone before the upload. `always()` because a
644+
# failed check is exactly when the runner is closest to full.
645+
- name: Remove the staged bundle
646+
if: always()
647+
shell: bash
648+
run: |
649+
set -uo pipefail
650+
dist="${{ steps.packaged.outputs.dist }}"
651+
# Delete the stage root, not the dist inside it: <tmp>/t3code-desktop-...-stage-*/app/dist
652+
[[ -n "$dist" ]] && rm -rf "$(dirname "$(dirname "$dist")")" || true
653+
exit 0
654+
596655
# The machine-checkable form of "this update will not re-ask for permissions" (issue #70),
597656
# made against the .app inside the shipped .dmg rather than a staging copy.
598657
#

‎scripts/coil/desktop-bundle-reachability.mjs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
*/
4545

4646
import * as NodeFS from "node:fs";
47+
import * as NodeURL from "node:url";
4748
import * as NodeModule from "node:module";
4849
import * as NodePath from "node:path";
4950

@@ -534,7 +535,27 @@ function formatBytes(bytes) {
534535
return mib >= 1 ? `${mib.toFixed(1)} MiB` : `${(bytes / 1024).toFixed(0)} KiB`;
535536
}
536537

537-
if (import.meta.url === `file://${process.argv[1]}`) {
538+
/**
539+
* Whether this module was run directly, rather than imported.
540+
*
541+
* `import.meta.url === `file://${process.argv[1]}`` is the idiom this replaces, and it is broken on
542+
* Windows. `process.argv[1]` is a native path there (`D:\a\...`), so the template produces
543+
* `file://D:\a\...` while `import.meta.url` is `file:///D:/a/...` — drive letter after three
544+
* slashes, forward separators. They never match, so a Windows CLI run silently executed nothing,
545+
* exited 0, and printed no output.
546+
*
547+
* That is how it reached production: on macOS and Linux the idiom works, because an absolute POSIX
548+
* path already begins with `/`. Both CI callers of these scripts are `set -euo pipefail`, and
549+
* neither could see the difference between "verified" and "did nothing" — one release failed on the
550+
* empty stdout, the other passed a check that had not run. `pathToFileURL` is what Node provides for
551+
* exactly this, and it is correct on every platform.
552+
*/
553+
function isEntryPoint() {
554+
const entry = process.argv[1];
555+
return entry !== undefined && import.meta.url === NodeURL.pathToFileURL(entry).href;
556+
}
557+
558+
if (isEntryPoint()) {
538559
const rootIndex = process.argv.indexOf("--stage");
539560
const rootDir = rootIndex >= 0 ? process.argv[rootIndex + 1] : process.cwd();
540561
const limitIndex = process.argv.indexOf("--limit");

‎scripts/coil/desktop-bundle-size.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// @effect-diagnostics nodeBuiltinImport:off - Writes a real asar fixture to a temp dir; the point is to
22
// exercise the plain-Node file handling that verify-desktop-bundle.mjs uses on a CI runner.
3+
import * as NodeChildProcess from "node:child_process";
34
import * as NodeFS from "node:fs";
45
import * as NodeOS from "node:os";
56
import * as NodePath from "node:path";
7+
import * as NodeURL from "node:url";
68

79
import * as NodeServices from "@effect/platform-node/NodeServices";
810
import { assert, describe, it } from "@effect/vitest";
@@ -595,3 +597,52 @@ describe("verifyPackagedApp over a real asar", () => {
595597
});
596598
});
597599
});
600+
601+
/*
602+
* The regression that broke two releases: all three of these scripts are also CLIs, and their
603+
* entry-point guard was `import.meta.url === `file://${process.argv[1]}``. That is false on Windows,
604+
* where `process.argv[1]` is a native path — so `node <script>` parsed, ran nothing, wrote nothing,
605+
* and exited 0.
606+
*
607+
* The failure mode is what makes it worth a test rather than a comment. Both CI callers run under
608+
* `set -euo pipefail` and neither could tell "did the work" from "did nothing": the exclusions call
609+
* failed the release on empty stdout, and the bundle verification passed a check that never
610+
* executed. Exit code 0 is the wrong signal for both.
611+
*
612+
* These assert the shape that broke — invoked as a CLI, the script must actually do something — for
613+
* whichever platform the suite runs on. They cannot themselves run on Windows (this fork has no
614+
* Windows CI runner), so the correctness argument for that platform stays with `pathToFileURL`,
615+
* which is what Node provides for exactly this conversion.
616+
*/
617+
describe("the scripts still work when invoked as CLIs", () => {
618+
const scriptDir = NodePath.dirname(NodeURL.fileURLToPath(import.meta.url));
619+
620+
it("desktop-file-exclusions.mjs writes the list to stdout", () => {
621+
const result = NodeChildProcess.spawnSync(
622+
process.execPath,
623+
[NodePath.join(scriptDir, "desktop-file-exclusions.mjs")],
624+
{ encoding: "utf8" },
625+
);
626+
627+
assert.strictEqual(result.status, 0, result.stderr);
628+
// The exact failure: exit 0 with nothing written. An empty list is what the release step
629+
// rejects, so asserting "not empty" is asserting the thing that actually broke.
630+
assert.isNotEmpty(
631+
result.stdout,
632+
"the CLI produced no output, so its entry-point guard is wrong",
633+
);
634+
assert.strictEqual(result.stdout, renderExclusionEnvValue());
635+
});
636+
637+
it("verify-desktop-bundle.mjs refuses to exit 0 when handed nothing to verify", () => {
638+
// The other half. A verifier whose main never runs is indistinguishable from one that passed,
639+
// and this is the call the release makes, so it must fail loudly rather than quietly succeed.
640+
const result = NodeChildProcess.spawnSync(
641+
process.execPath,
642+
[NodePath.join(scriptDir, "verify-desktop-bundle.mjs")],
643+
{ encoding: "utf8" },
644+
);
645+
646+
assert.notStrictEqual(result.status, 0, "a no-argument run must not look like a pass");
647+
});
648+
});

‎scripts/coil/desktop-file-exclusions.mjs‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
* `restore-cursor`), making that section moot without touching `pnpm.overrides`.
5454
*/
5555

56+
import * as NodeURL from "node:url";
57+
5658
/**
5759
* Third-party source maps: 18.2 MiB across ~2,290 files, and not one of them is read at runtime.
5860
*
@@ -229,6 +231,26 @@ export function renderExclusionEnvValue(globs = T3X_DESKTOP_FILE_EXCLUSIONS) {
229231
return globs.join(",");
230232
}
231233

232-
if (import.meta.url === `file://${process.argv[1]}`) {
234+
/**
235+
* Whether this module was run directly, rather than imported.
236+
*
237+
* `import.meta.url === `file://${process.argv[1]}`` is the idiom this replaces, and it is broken on
238+
* Windows. `process.argv[1]` is a native path there (`D:\a\...`), so the template produces
239+
* `file://D:\a\...` while `import.meta.url` is `file:///D:/a/...` — drive letter after three
240+
* slashes, forward separators. They never match, so a Windows CLI run silently executed nothing,
241+
* exited 0, and printed no output.
242+
*
243+
* That is how it reached production: on macOS and Linux the idiom works, because an absolute POSIX
244+
* path already begins with `/`. Both CI callers of these scripts are `set -euo pipefail`, and
245+
* neither could see the difference between "verified" and "did nothing" — one release failed on the
246+
* empty stdout, the other passed a check that had not run. `pathToFileURL` is what Node provides for
247+
* exactly this, and it is correct on every platform.
248+
*/
249+
function isEntryPoint() {
250+
const entry = process.argv[1];
251+
return entry !== undefined && import.meta.url === NodeURL.pathToFileURL(entry).href;
252+
}
253+
254+
if (isEntryPoint()) {
233255
process.stdout.write(renderExclusionEnvValue());
234256
}

‎scripts/coil/verify-desktop-bundle.mjs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*/
4646

4747
import * as NodeFS from "node:fs";
48+
import * as NodeURL from "node:url";
4849
import * as NodePath from "node:path";
4950

5051
import {
@@ -388,7 +389,27 @@ function formatMiB(bytes) {
388389
return `${(bytes / 1024 / 1024).toFixed(2)} MiB`;
389390
}
390391

391-
if (import.meta.url === `file://${process.argv[1]}`) {
392+
/**
393+
* Whether this module was run directly, rather than imported.
394+
*
395+
* `import.meta.url === `file://${process.argv[1]}`` is the idiom this replaces, and it is broken on
396+
* Windows. `process.argv[1]` is a native path there (`D:\a\...`), so the template produces
397+
* `file://D:\a\...` while `import.meta.url` is `file:///D:/a/...` — drive letter after three
398+
* slashes, forward separators. They never match, so a Windows CLI run silently executed nothing,
399+
* exited 0, and printed no output.
400+
*
401+
* That is how it reached production: on macOS and Linux the idiom works, because an absolute POSIX
402+
* path already begins with `/`. Both CI callers of these scripts are `set -euo pipefail`, and
403+
* neither could see the difference between "verified" and "did nothing" — one release failed on the
404+
* empty stdout, the other passed a check that had not run. `pathToFileURL` is what Node provides for
405+
* exactly this, and it is correct on every platform.
406+
*/
407+
function isEntryPoint() {
408+
const entry = process.argv[1];
409+
return entry !== undefined && import.meta.url === NodeURL.pathToFileURL(entry).href;
410+
}
411+
412+
if (isEntryPoint()) {
392413
const asarFlag = process.argv.indexOf("--asar");
393414
const appFlag = process.argv.indexOf("--verify-app");
394415
let asarPath;

0 commit comments

Comments
 (0)