Skip to content

Commit 8f4346a

Browse files
committed
Initialize pinned tools and workspace ownership in browser containers
Signed-off-by: tulsi <[email protected]>
1 parent 2e44a02 commit 8f4346a

4 files changed

Lines changed: 144 additions & 8 deletions

File tree

‎.github/actions/setup/action.yml‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@ runs:
1818
# A faster JS-only job must not freeze an incomplete cache for Rust jobs.
1919
key: hermit-${{ runner.os }}-${{ runner.arch }}-${{ github.job }}-${{ hashFiles('bin/**') }}
2020
- uses: cashapp/activate-hermit@cea9af7913204a965fd488637a8d1811bba2e616 # v1
21+
- name: Verify pinned tool entry points
22+
shell: bash
23+
run: |
24+
./bin/node --version
25+
./bin/pnpm --version
26+
echo "$GITHUB_WORKSPACE/bin" >> "$GITHUB_PATH"
27+
# Later entries take precedence: keep concrete minimal Rust ahead of
28+
# bin/cargo, whose Hermit proxy would provision the full Rust archive.
29+
if [ -n "${HERMIT_PREPEND_PATH:-}" ]; then
30+
echo "$HERMIT_PREPEND_PATH" >> "$GITHUB_PATH"
31+
fi
2132
- name: Resolve pnpm store
2233
id: pnpm
2334
shell: bash
24-
run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT"
35+
run: |
36+
store=$(./bin/pnpm store path --silent)
37+
test -n "$store"
38+
echo "path=$store" >> "$GITHUB_OUTPUT"
2539
- name: Cache pnpm store
2640
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
2741
with:
@@ -30,10 +44,10 @@ runs:
3044
restore-keys: pnpm-${{ runner.os }}-${{ runner.arch }}-
3145
- name: Install locked dependencies
3246
shell: bash
33-
run: pnpm install --frozen-lockfile
47+
run: ./bin/pnpm install --frozen-lockfile
3448
- name: Verify pinned browser image
3549
if: inputs.browsers == 'true'
3650
shell: bash
3751
env:
3852
PLAYWRIGHT_ENGINE: ${{ inputs.browser-engine }}
39-
run: node scripts/check-browser-image.mjs
53+
run: ./bin/node scripts/check-browser-image.mjs

‎.github/workflows/ci.yml‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ jobs:
115115
defaults:
116116
run:
117117
shell: bash
118+
env:
119+
HOME: /root
118120
timeout-minutes: 15
119121
steps:
120122
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
121123
with:
122124
persist-credentials: false
125+
- name: Trust this container workspace
126+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
123127
- uses: ./.github/actions/setup
124128
with:
125129
browsers: "true"
@@ -161,6 +165,8 @@ jobs:
161165
defaults:
162166
run:
163167
shell: bash
168+
env:
169+
HOME: /root
164170
# Six file-level shards split the large file groups that remain together
165171
# with four or five shards, leaving room for setup inside the same deadline.
166172
timeout-minutes: 15
@@ -173,12 +179,14 @@ jobs:
173179
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4
174180
with:
175181
persist-credentials: false
182+
- name: Trust this container workspace
183+
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
176184
# The browser image already contains both engines and their libraries.
177185
# Its native fixture still needs a compiler/linker and the repository Rust pin.
178186
- name: Native fixture build prerequisites
179187
run: |
180188
apt-get update
181-
apt-get install --no-install-recommends -y build-essential
189+
apt-get install --no-install-recommends -y gcc libc6-dev
182190
- name: Resolve pinned browser Rust
183191
id: browser-rust
184192
run: |
@@ -206,6 +214,12 @@ jobs:
206214
with:
207215
browsers: "true"
208216
browser-engine: ${{ matrix.engine }}
217+
- name: Verify native fixture tool paths
218+
run: |
219+
test "$(command -v cargo)" = "$HERMIT_PREPEND_PATH/cargo"
220+
test "$(command -v rustc)" = "$HERMIT_PREPEND_PATH/rustc"
221+
cargo --version
222+
rustc --version
209223
# This journey uses a real native plugin-manager bridge. Provision it
210224
# before Playwright starts: a cold Rust install/build is test setup, not
211225
# browser behavior, and must not consume the journey's subprocess budget.

‎docs/contributing.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,9 @@ the complete suite still runs with `pnpm test` / `just scan`:
344344
version; setup verifies the installed package against image metadata and launches
345345
the selected engine (both engines for measurements) before tests. No missing
346346
image or library silently falls back to downloading or skipping an engine.
347-
Hermit still pins Node/pnpm. Functional jobs install `build-essential` for the
347+
Hermit still pins Node/pnpm; setup invokes repository entry points explicitly.
348+
Browser containers use a consistent root home and trust only their exact
349+
checked-out workspace. Functional jobs install `gcc` and `libc6-dev` for the
348350
native fixture and use a commit-pinned Rust installer with the repository's
349351
`bin/.rust-*.pkg` version. `HERMIT_PREPEND_PATH` keeps the minimal compiler/Cargo
350352
toolchain selected through nested commands. Each runner builds the native

‎tests/integration/browser-ci.test.mjs‎

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ test("browser fixture retains a validated repository Rust pin and linker before
113113
);
114114
assert.match(
115115
prerequisites.run,
116-
/apt-get install --no-install-recommends -y build-essential/,
116+
/apt-get install --no-install-recommends -y gcc libc6-dev/,
117117
);
118118
assert.ok(steps.indexOf(resolve) < steps.indexOf(install));
119119
assert.ok(steps.indexOf(install) < steps.indexOf(select));
@@ -422,6 +422,20 @@ test("browser jobs use one immutable image matching the package pin, without per
422422
assert.equal(job.container.image, image);
423423
assert.equal(job.container.options, "--init --ipc=host");
424424
assert.equal(job.defaults.run.shell, "bash");
425+
assert.equal(job.env.HOME, "/root");
426+
const trust = job.steps.find(
427+
(step) => step.name === "Trust this container workspace",
428+
);
429+
assert.equal(
430+
trust.run,
431+
'git config --global --add safe.directory "$GITHUB_WORKSPACE"',
432+
);
433+
assert.ok(
434+
job.steps.indexOf(trust) <
435+
job.steps.findIndex((step) => step.uses === "./.github/actions/setup"),
436+
);
437+
assert.equal(trust.if, undefined);
438+
assert.equal(trust["continue-on-error"], undefined);
425439
assert.equal(job["timeout-minutes"], 15);
426440
assert.equal(
427441
job.steps.find((step) => step.uses === "./.github/actions/setup").with
@@ -444,11 +458,13 @@ test("browser jobs use one immutable image matching the package pin, without per
444458
verify = steps.find((step) => step.name === "Verify pinned browser image");
445459
assert.equal(verify.if, "inputs.browsers == 'true'");
446460
assert.equal(verify["continue-on-error"], undefined);
447-
assert.equal(verify.run, "node scripts/check-browser-image.mjs");
461+
assert.equal(verify.run, "./bin/node scripts/check-browser-image.mjs");
448462
assert.equal(verify.env.PLAYWRIGHT_ENGINE, `\${{ inputs.browser-engine }}`);
449463
assert.ok(
450464
steps.indexOf(verify) >
451-
steps.findIndex((step) => step.run === "pnpm install --frozen-lockfile"),
465+
steps.findIndex(
466+
(step) => step.run === "./bin/pnpm install --frozen-lockfile",
467+
),
452468
);
453469
assert.doesNotMatch(
454470
read(".github/actions/setup/action.yml"),
@@ -481,3 +497,93 @@ test("image verification rejects version/image mismatch and never silently omits
481497
])
482498
assert.throws(() => imageEngines(bad, version, "all"));
483499
});
500+
501+
test("setup calls pinned entry points and fails before caching an empty pnpm path", (t) => {
502+
const { steps } = parse(read(".github/actions/setup/action.yml")).runs;
503+
const verify = steps.find(
504+
(step) => step.name === "Verify pinned tool entry points",
505+
);
506+
const store = steps.find((step) => step.id === "pnpm");
507+
assert.ok(steps.indexOf(verify) < steps.indexOf(store));
508+
assert.match(verify.run, /\.\/bin\/node --version/);
509+
assert.match(verify.run, /\.\/bin\/pnpm --version/);
510+
assert.match(verify.run, /GITHUB_WORKSPACE\/bin/);
511+
assert.ok(
512+
verify.run.indexOf('echo "$HERMIT_PREPEND_PATH"') >
513+
verify.run.indexOf('echo "$GITHUB_WORKSPACE/bin"'),
514+
);
515+
const stepsBrowser = parse(workflow).jobs.browser.steps;
516+
const nativePaths = stepsBrowser.find(
517+
(step) => step.name === "Verify native fixture tool paths",
518+
);
519+
assert.ok(
520+
stepsBrowser.indexOf(nativePaths) >
521+
stepsBrowser.findIndex((step) => step.uses === "./.github/actions/setup"),
522+
);
523+
assert.ok(
524+
stepsBrowser.indexOf(nativePaths) <
525+
stepsBrowser.findIndex((step) =>
526+
step.uses?.startsWith("Swatinem/rust-cache@"),
527+
),
528+
);
529+
assert.equal(nativePaths.if, undefined);
530+
assert.equal(nativePaths["continue-on-error"], undefined);
531+
const cwd = mkdtempSync(join(tmpdir(), "buzz-pnpm-path-"));
532+
t.after(() => rmSync(cwd, { recursive: true, force: true }));
533+
mkdirSync(join(cwd, "bin"));
534+
writeFileSync(
535+
join(cwd, "bin", "pnpm"),
536+
'#!/bin/sh\n[ "$1 $2 $3" = "store path --silent" ] || exit 2\nprintf "%s" "$STORE"\nexit "$RESULT"\n',
537+
{ mode: 0o755 },
538+
);
539+
mkdirSync(join(cwd, "toolchain"));
540+
for (const command of ["cargo", "rustc"]) {
541+
writeFileSync(join(cwd, "toolchain", command), "#!/bin/sh\nexit 0\n", {
542+
mode: 0o755,
543+
});
544+
writeFileSync(join(cwd, "bin", command), "#!/bin/sh\nexit 99\n", {
545+
mode: 0o755,
546+
});
547+
}
548+
const checkPaths = (path) =>
549+
spawnSync("bash", ["-eo", "pipefail", "-c", nativePaths.run], {
550+
cwd,
551+
env: {
552+
...process.env,
553+
PATH: path,
554+
HERMIT_PREPEND_PATH: join(cwd, "toolchain"),
555+
},
556+
encoding: "utf8",
557+
timeout: 5000,
558+
});
559+
assert.equal(
560+
checkPaths(`${cwd}/toolchain:${cwd}/bin:${process.env.PATH}`).status,
561+
0,
562+
);
563+
assert.notEqual(
564+
checkPaths(`${cwd}/bin:${cwd}/toolchain:${process.env.PATH}`).status,
565+
0,
566+
"Rust proxies must not win over concrete minimal tools",
567+
);
568+
const output = join(cwd, "output");
569+
const execute = (path, result = "0") => {
570+
writeFileSync(output, "");
571+
return spawnSync("bash", ["-eo", "pipefail", "-c", store.run], {
572+
cwd,
573+
env: {
574+
...process.env,
575+
GITHUB_OUTPUT: output,
576+
STORE: path,
577+
RESULT: result,
578+
},
579+
encoding: "utf8",
580+
timeout: 5000,
581+
});
582+
};
583+
assert.equal(execute("/pinned store").status, 0);
584+
assert.equal(readFileSync(output, "utf8"), "path=/pinned store\n");
585+
assert.notEqual(execute("").status, 0);
586+
assert.equal(readFileSync(output, "utf8"), "");
587+
assert.equal(execute("", "7").status, 7);
588+
assert.equal(readFileSync(output, "utf8"), "");
589+
});

0 commit comments

Comments
 (0)