Repository navigation
build(runtime): gate new Electron imports reachable from the Orca runtime - #15919
Conversation
1ed1500 to
a25d8f1
Compare
Verified on a real Windows hostThe Windows fail-open fix was previously argued from Node's documented path/URL forms. It is now proven on an actual Windows machine (Git Bash / MINGW64), running this branch at 1. The bug and the fix, measured: 2. The gate now actually runs there, and agrees with macOS: 36 entries on Windows, 36 on macOS — this also closes the open question about whether the checked-in baseline could diverge per platform. It does not: the repo-relative forward-slash normalisation holds. 3. It still fails when it should, with a usable message: Note the path renders forward-slash on Windows too, so the failure message and the baseline speak the same dialect. Before this fix, all three of those runs would have printed nothing and exited 0. |
b7e5155 to
e74e60c
Compare
a25d8f1 to
0c3b4c0
Compare
e74e60c to
a5c8f3d
Compare
0c3b4c0 to
3bf6460
Compare
a5c8f3d to
cd29acb
Compare
3bf6460 to
17ab89b
Compare
cd29acb to
66c5ccc
Compare
4c1133a to
bd69e21
Compare
|
Too many files changed for review (177 files, 100 file limit). Bypass the limit by tagging |
The one red check is a pre-existing failure on
|
…time The runtime is meant to become host-agnostic so it can also run on plain Node, but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that import `electron`, and the count grows silently: the import that breaks portability is usually several hops away, so no reviewer sees the edge. Add a reachability ratchet, modelled on the existing max-lines one. It bundles the runtime and its RPC server with esbuild, reads the metafile for every module importing `electron`, and diffs that against a checked-in baseline. A new module fails; a removed one forces the baseline to tighten. The list may only shrink. A per-file lint rule cannot do this — the point is precisely the transitive edges — so this runs as a build gate in `pnpm lint`. Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment ports landed, which is the migration made measurable. Verified: gate passes clean, fails with an actionable message when an `electron` import is added to a runtime module, and passes again when reverted.
… cwd Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack instead of a usable message. It failed closed, so it was never unsafe — just undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild so metafile keys stay repo-relative.
The ratchet was wired into the `lint` npm script, but CI's static-analysis job runs the individual checks rather than `pnpm lint`, so the gate would never have fired on a PR — it would have looked enforced while enforcing nothing. Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline is only ever produced by one platform.
ssh2's optional cpu-features dep points at a prebuilt .node that only exists where a build toolchain has run. Loading it made the gate pass locally and hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'. The gate only reads the import graph, never the addon, so resolve every .node to an external stub instead. Verified by hiding the local prebuild — which is CI's state — and re-running: still 36 entries, exit 0.
The entry guard compared import.meta.url against a `file://${process.argv[1]}`
template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url
is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint`
exited 0 on Windows without bundling, reading the baseline, or enforcing anything.
Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses.
CI runs this on ubuntu so enforcement was never actually lost, but a Windows
developer got a green gate that checked nothing.
bd69e21 to
fda832f
Compare
📝 WalkthroughWalkthroughThe change adds an esbuild-based check for 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: d48d25b8-25a8-4ae8-9b71-255eb337d5b3
📒 Files selected for processing (5)
.github/workflows/pr.ymlconfig/runtime-electron-baseline.txtconfig/scripts/check-runtime-electron-ratchet.mjsconfig/scripts/check-runtime-electron-ratchet.test.mjspackage.json
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| async function main() { | ||
| const write = process.argv.includes('--write') | ||
| const current = await collectElectronImporters() | ||
|
|
||
| if (write) { | ||
| writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`) | ||
| console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`) | ||
| return | ||
| } | ||
|
|
||
| const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8')) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Prevent --write from expanding the baseline.
Line 126 writes the current set before the script reads the existing baseline. If a new reachable Electron importer exists, --write adds it to the baseline and makes later CI checks pass. This bypasses the stated shrink-only ratchet.
Read and diff the baseline before this branch. Reject --write when added.length > 0. Allow it only to remove entries.
Proposed fix
async function main() {
const write = process.argv.includes('--write')
const current = await collectElectronImporters()
+ const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8'))
+ const { added, removed } = diffAgainstBaseline(current, baseline)
if (write) {
+ if (added.length > 0) {
+ console.error('[runtime-electron-ratchet] refusing to expand the baseline')
+ process.exitCode = 1
+ return
+ }
writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`)
console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`)
return
}
-
- const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8'))
- const { added, removed } = diffAgainstBaseline(current, baseline)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| async function main() { | |
| const write = process.argv.includes('--write') | |
| const current = await collectElectronImporters() | |
| if (write) { | |
| writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`) | |
| console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`) | |
| return | |
| } | |
| const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8')) | |
| async function main() { | |
| const write = process.argv.includes('--write') | |
| const current = await collectElectronImporters() | |
| const baseline = readBaseline(readFileSync(BASELINE_PATH, 'utf8')) | |
| const { added, removed } = diffAgainstBaseline(current, baseline) | |
| if (write) { | |
| if (added.length > 0) { | |
| console.error('[runtime-electron-ratchet] refusing to expand the baseline') | |
| process.exitCode = 1 | |
| return | |
| } | |
| writeFileSync(BASELINE_PATH, `${renderBaseline(current)}\n`) | |
| console.log(`[runtime-electron-ratchet] wrote ${current.length} entries to ${BASELINE_PATH}`) | |
| return | |
| } |
…time (stablyai#15919) * build(runtime): gate new Electron imports reachable from the Orca runtime The runtime is meant to become host-agnostic so it can also run on plain Node, but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that import `electron`, and the count grows silently: the import that breaks portability is usually several hops away, so no reviewer sees the edge. Add a reachability ratchet, modelled on the existing max-lines one. It bundles the runtime and its RPC server with esbuild, reads the metafile for every module importing `electron`, and diffs that against a checked-in baseline. A new module fails; a removed one forces the baseline to tighten. The list may only shrink. A per-file lint rule cannot do this — the point is precisely the transitive edges — so this runs as a build gate in `pnpm lint`. Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment ports landed, which is the migration made measurable. Verified: gate passes clean, fails with an actionable message when an `electron` import is added to a runtime module, and passes again when reverted. * fix(runtime-ratchet): resolve paths from the script, not the caller's cwd Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack instead of a usable message. It failed closed, so it was never unsafe — just undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild so metafile keys stay repo-relative. * ci(runtime-ratchet): actually run the gate in CI The ratchet was wired into the `lint` npm script, but CI's static-analysis job runs the individual checks rather than `pnpm lint`, so the gate would never have fired on a PR — it would have looked enforced while enforcing nothing. Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline is only ever produced by one platform. * fix(runtime-ratchet): mark native addons external so CI can run the gate ssh2's optional cpu-features dep points at a prebuilt .node that only exists where a build toolchain has run. Loading it made the gate pass locally and hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'. The gate only reads the import graph, never the addon, so resolve every .node to an external stub instead. Verified by hiding the local prebuild — which is CI's state — and re-running: still 36 entries, exit 0. * fix(runtime-ratchet): stop the gate failing open on Windows The entry guard compared import.meta.url against a `file://${process.argv[1]}` template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint` exited 0 on Windows without bundling, reading the baseline, or enforcing anything. Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses. CI runs this on ubuntu so enforcement was never actually lost, but a Windows developer got a green gate that checked nothing. (cherry picked from commit cbea753)
…time (stablyai#15919) * build(runtime): gate new Electron imports reachable from the Orca runtime The runtime is meant to become host-agnostic so it can also run on plain Node, but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that import `electron`, and the count grows silently: the import that breaks portability is usually several hops away, so no reviewer sees the edge. Add a reachability ratchet, modelled on the existing max-lines one. It bundles the runtime and its RPC server with esbuild, reads the metafile for every module importing `electron`, and diffs that against a checked-in baseline. A new module fails; a removed one forces the baseline to tighten. The list may only shrink. A per-file lint rule cannot do this — the point is precisely the transitive edges — so this runs as a build gate in `pnpm lint`. Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment ports landed, which is the migration made measurable. Verified: gate passes clean, fails with an actionable message when an `electron` import is added to a runtime module, and passes again when reverted. * fix(runtime-ratchet): resolve paths from the script, not the caller's cwd Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack instead of a usable message. It failed closed, so it was never unsafe — just undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild so metafile keys stay repo-relative. * ci(runtime-ratchet): actually run the gate in CI The ratchet was wired into the `lint` npm script, but CI's static-analysis job runs the individual checks rather than `pnpm lint`, so the gate would never have fired on a PR — it would have looked enforced while enforcing nothing. Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline is only ever produced by one platform. * fix(runtime-ratchet): mark native addons external so CI can run the gate ssh2's optional cpu-features dep points at a prebuilt .node that only exists where a build toolchain has run. Loading it made the gate pass locally and hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'. The gate only reads the import graph, never the addon, so resolve every .node to an external stub instead. Verified by hiding the local prebuild — which is CI's state — and re-running: still 36 entries, exit 0. * fix(runtime-ratchet): stop the gate failing open on Windows The entry guard compared import.meta.url against a `file://${process.argv[1]}` template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint` exited 0 on Windows without bundling, reading the baseline, or enforcing anything. Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses. CI runs this on ubuntu so enforcement was never actually lost, but a Windows developer got a green gate that checked nothing.
…time (stablyai#15919) * build(runtime): gate new Electron imports reachable from the Orca runtime The runtime is meant to become host-agnostic so it can also run on plain Node, but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that import `electron`, and the count grows silently: the import that breaks portability is usually several hops away, so no reviewer sees the edge. Add a reachability ratchet, modelled on the existing max-lines one. It bundles the runtime and its RPC server with esbuild, reads the metafile for every module importing `electron`, and diffs that against a checked-in baseline. A new module fails; a removed one forces the baseline to tighten. The list may only shrink. A per-file lint rule cannot do this — the point is precisely the transitive edges — so this runs as a build gate in `pnpm lint`. Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment ports landed, which is the migration made measurable. Verified: gate passes clean, fails with an actionable message when an `electron` import is added to a runtime module, and passes again when reverted. * fix(runtime-ratchet): resolve paths from the script, not the caller's cwd Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack instead of a usable message. It failed closed, so it was never unsafe — just undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild so metafile keys stay repo-relative. * ci(runtime-ratchet): actually run the gate in CI The ratchet was wired into the `lint` npm script, but CI's static-analysis job runs the individual checks rather than `pnpm lint`, so the gate would never have fired on a PR — it would have looked enforced while enforcing nothing. Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline is only ever produced by one platform. * fix(runtime-ratchet): mark native addons external so CI can run the gate ssh2's optional cpu-features dep points at a prebuilt .node that only exists where a build toolchain has run. Loading it made the gate pass locally and hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'. The gate only reads the import graph, never the addon, so resolve every .node to an external stub instead. Verified by hiding the local prebuild — which is CI's state — and re-running: still 36 entries, exit 0. * fix(runtime-ratchet): stop the gate failing open on Windows The entry guard compared import.meta.url against a `file://${process.argv[1]}` template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint` exited 0 on Windows without bundling, reading the baseline, or enforcing anything. Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses. CI runs this on ubuntu so enforcement was never actually lost, but a Windows developer got a green gate that checked nothing.
…time (stablyai#15919) * build(runtime): gate new Electron imports reachable from the Orca runtime The runtime is meant to become host-agnostic so it can also run on plain Node, but nothing enforced that. `orca-runtime.ts` reaches dozens of modules that import `electron`, and the count grows silently: the import that breaks portability is usually several hops away, so no reviewer sees the edge. Add a reachability ratchet, modelled on the existing max-lines one. It bundles the runtime and its RPC server with esbuild, reads the metafile for every module importing `electron`, and diffs that against a checked-in baseline. A new module fails; a removed one forces the baseline to tighten. The list may only shrink. A per-file lint rule cannot do this — the point is precisely the transitive edges — so this runs as a build gate in `pnpm lint`. Baseline starts at 36, down from 50 before the SecretStore and AppEnvironment ports landed, which is the migration made measurable. Verified: gate passes clean, fails with an actionable message when an `electron` import is added to a runtime module, and passes again when reverted. * fix(runtime-ratchet): resolve paths from the script, not the caller's cwd Run from anywhere but the repo root, the gate died with an unhandled ENOENT stack instead of a usable message. It failed closed, so it was never unsafe — just undebuggable. Anchor ROOT to import.meta.dirname and pass absWorkingDir to esbuild so metafile keys stay repo-relative. * ci(runtime-ratchet): actually run the gate in CI The ratchet was wired into the `lint` npm script, but CI's static-analysis job runs the individual checks rather than `pnpm lint`, so the gate would never have fired on a PR — it would have looked enforced while enforcing nothing. Runs on ubuntu-latest alongside the max-lines ratchet, so the checked-in baseline is only ever produced by one platform. * fix(runtime-ratchet): mark native addons external so CI can run the gate ssh2's optional cpu-features dep points at a prebuilt .node that only exists where a build toolchain has run. Loading it made the gate pass locally and hard-fail on CI with 'Could not resolve ../build/Release/cpufeatures.node'. The gate only reads the import graph, never the addon, so resolve every .node to an external stub instead. Verified by hiding the local prebuild — which is CI's state — and re-running: still 36 entries, exit 0. * fix(runtime-ratchet): stop the gate failing open on Windows The entry guard compared import.meta.url against a `file://${process.argv[1]}` template. On Windows argv[1] is a native path (C:\repo\...) while import.meta.url is file:///C:/repo/..., so they never match: main() never ran and `pnpm lint` exited 0 on Windows without bundling, reading the baseline, or enforcing anything. Use pathToFileURL, which is the idiom check-max-lines-ratchet.mjs:225 already uses. CI runs this on ubuntu so enforcement was never actually lost, but a Windows developer got a green gate that checked nothing.
ELI5
The two PRs below this one moved Electron-specific calls behind small interfaces, so the Orca runtime gets closer to running on plain Node.
The problem: nothing stops that from silently undoing itself. The import that breaks portability is almost never in the file being reviewed — it's three hops away. Someone adds
import { app } from 'electron'to a module, that module is imported by another, which is imported by the runtime, and no reviewer ever sees the edge.This PR adds a gate that does see it. It bundles the runtime, asks the bundler which modules ended up importing
electron, and compares that list to a checked-in file. A new one fails CI. The list may only shrink.Why a build gate and not a lint rule
A lint rule sees one file. The thing that matters here is reachability — the transitive edge. So this bundles
orca-runtime.tsandruntime-rpc.tswith esbuild and reads the metafile, which is the only cheap way to get a true answer. It runs inpnpm lintalongside the existing ratchets.Modelled directly on
config/scripts/check-max-lines-ratchet.mjs, which exists for the same reason: freeze today's set, fail on growth, force the baseline to tighten when it shrinks.The number
Baseline starts at 36. It was 50 before #15916 and #15918 landed their ports. That is the migration made measurable — and it's why the gate also fails when the count drops: a stale baseline that doesn't tighten is a gate quietly losing its floor.
Proof it works
Not just "the tests pass" — I proved the gate actually gates:
check-runtime-electron-ratchet.test.mjsoxlintThe test file covers the pure functions (baseline parsing, diffing in both directions) plus one real end-to-end assertion that the checked-in baseline still matches what the runtime actually reaches. That last one is deliberately not a fixture: the value of this gate is the transitive edges, and a fixture cannot model those.
User-facing trade-offs
None at runtime. One developer-facing cost:
pnpm lintgets an esbuild bundle (a few seconds). If someone legitimately needs a new Electron import inside the runtime graph, the failure message tells them the two ways out (put it behind a port insrc/main/host/, or move it out of the graph) rather than just refusing.Review loops
prefer-templatelint errors; verified the gate's three-state behaviour empirically rather than assuming it.Verdict: ready to merge, after #15918. This is the piece that makes the other two durable — without it they decay.
Commits added after this PR was opened
fix(runtime-ratchet): resolve paths from the script, not the caller's cwdENOENTstack instead of a usable message. It failed closed, so it was never unsafe — just undebuggable. Now anchors toimport.meta.dirnameand passesabsWorkingDirto esbuild so metafile keys stay repo-relative.ci(runtime-ratchet): actually run the gate in CIlintnpm script, but CI's static-analysis job runs the individual checks rather thanpnpm lint— so this would have looked enforced while enforcing nothing. Now a step next to the max-lines ratchet, onubuntu-latest, so the checked-in baseline is only ever produced by one platform.The second one is worth dwelling on: a ratchet that does not run is worse than no ratchet, because it manufactures false confidence. Caught by reading
.github/workflows/pr.ymlrather than assumingpnpm lintwas the CI entrypoint.Final regression evidence
mainpnpm typecheck(node + web + cli projects)oxlint(full repo)Round-2 review findings applied
Two more landed after the last push, both against this file, both fail-open bugs — the class this PR exists to prevent:
import.meta.urlagainst a`file://${process.argv[1]}`template. On Windowsargv[1]isC:\repo\...whileimport.meta.urlisfile:///C:/repo/..., somain()never ran andpnpm lintexited 0 without bundling or reading the baseline.pathToFileURL— the idiomcheck-max-lines-ratchet.mjs:225already uses and I should have copied. CI runs on ubuntu so enforcement was never actually lost; a Windows developer just got a green gate that checked nothing.mkdtempSyncat module scope runs once per test environment — one per file, not per worker — with nothing removing them. Proven: a three-file run under an isolatedTMPDIRpreviously added directories, now leaves zero.Reviewer verdict on the rest: P0 none. Security and backcompat sections came back clean — "desktop at-rest encryption and userData resolution are pass-throughs of the previous Electron calls; already-sealed credentials keep the same byte path." The
ProcessMetriccast was checked and structurally satisfies every field the collector reads; the soleisPackaged()rewrite calls the method; missing-baseline and esbuild-failure both fail closed.