@futurelastic/colab-handbook 1.12.0-rc.15 → 1.12.0-rc.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/README.md +19 -0
- package/templates/ci-laravel.yml +57 -0
- package/templates/ci-node.yml +53 -0
- package/templates/ci-python.yml +53 -0
- package/tools/colab +23 -5
- package/tools/lib/hermetic.js +72 -6
package/package.json
CHANGED
package/templates/README.md
CHANGED
|
@@ -31,6 +31,25 @@ Starting points you **copy into your own repo**. That is the entire model.
|
|
|
31
31
|
| `docs-lint.yml` | `.github/workflows/docs-lint.yml` | Every repo that copied `docs-lint.mjs` | Advisory job — `continue-on-error: true` on the lint step, so a finding never blocks a merge until a repo deliberately removes that line. Requires `docs-lint.mjs` to already be in the repo; does not vendor it. |
|
|
32
32
|
| `branch-name.yml` | `.github/workflows/branch-name.yml` | Opt-in — any repo that wants §4's branch shape checked on every PR | One step, no dependencies: the PR's head branch against CONVENTIONS.md §4's regex, both shapes (`<type>/<slug>-<N>` and the `<login>/<machine>/` prefixed one) passing as shipped. Once the repo declares `branchPrefix: machine`, delete the `?` after the regex's first group to require the prefix. The head ref reaches the script through `env:`, never interpolated — on a public repo it is attacker-chosen. |
|
|
33
33
|
|
|
34
|
+
### The `dedupe` job — why a claimed branch's first run skips the suite (#418)
|
|
35
|
+
|
|
36
|
+
All three CI templates open with a `dedupe` job. It runs only on the push that **creates** a
|
|
37
|
+
ref, which is what a session claim does: it pushes the new branch at trunk's head. It checks
|
|
38
|
+
nothing out, needs `permissions: actions: read`, and asks whether this same workflow already
|
|
39
|
+
has a green, non-pull-request run at this exact sha. If one exists, every other job is
|
|
40
|
+
skipped and the run still concludes `success`. If not, or if the check cannot run, the suite
|
|
41
|
+
runs as before. Every later push skips the guard, so real commits always get the full suite.
|
|
42
|
+
Two things to keep in a copy:
|
|
43
|
+
|
|
44
|
+
- **The guard calls `gh`.** GitHub-hosted images have it. On a self-hosted image without
|
|
45
|
+
`gh`, the guard prints a notice and the suite runs, so nothing breaks, but nothing is saved
|
|
46
|
+
either.
|
|
47
|
+
- **Every other job needs `!cancelled()` in its `if:`.** Without it, a job inherits the
|
|
48
|
+
implicit `success()`, which reads every ancestor, `dedupe` included. A job that only needs
|
|
49
|
+
`dedupe` indirectly would then be skipped on every ordinary push. That is why the Laravel
|
|
50
|
+
`migrations` job checks `needs.build.result == 'success'` explicitly. Add the same pair of
|
|
51
|
+
conditions to any job you add.
|
|
52
|
+
|
|
34
53
|
### Migration round-trip — what the Laravel job proves, and what it cannot
|
|
35
54
|
|
|
36
55
|
`ci-laravel.yml`'s `migrations` job runs every migration **twice per engine**: once from
|
package/templates/ci-laravel.yml
CHANGED
|
@@ -104,8 +104,59 @@ env:
|
|
|
104
104
|
# jobs from different runs interleave, and trunk can wait behind branch runs.
|
|
105
105
|
# Read CONVENTIONS.md §7, "Self-hosted runners", before choosing a label.
|
|
106
106
|
jobs:
|
|
107
|
+
# Already tested at this sha? (#418) — the claim push.
|
|
108
|
+
# A session's claim pushes its branch at the moment it is cut (CONVENTIONS.md §5, the
|
|
109
|
+
# claim record), so the branch's first push sits on a sha trunk has usually already
|
|
110
|
+
# run. Without this job that push re-runs the whole suite on a tested commit (~19% of
|
|
111
|
+
# all runs, measured across five adopting repos). This job runs ONLY on a ref's first
|
|
112
|
+
# push (`github.event.created`), checks nothing out, and asks one question: does THIS
|
|
113
|
+
# workflow already have a completed, green, non-PR run at THIS exact sha? Yes → every
|
|
114
|
+
# other job is skipped and the run concludes `success` — a branch-CI `green` that is
|
|
115
|
+
# true, because the same workflow passed at the same sha. Anything else — trunk still
|
|
116
|
+
# running, red, never run, `gh` missing, the API failing — and the suite runs as
|
|
117
|
+
# before (fail-open: this job never fails the run). Every later push has
|
|
118
|
+
# `created == false`, so a real commit always gets the full suite, with no extra hop.
|
|
119
|
+
# Why not simply `if: !github.event.created` on every job: a run whose jobs are ALL
|
|
120
|
+
# skipped concludes `skipped`, which `colab ship` reads as not-green (CONVENTIONS.md
|
|
121
|
+
# §4, "Branch CI"). This job is the one that ends green.
|
|
122
|
+
dedupe:
|
|
123
|
+
name: Already tested at this sha?
|
|
124
|
+
if: github.event_name == 'push' && github.event.created
|
|
125
|
+
runs-on: ubuntu-latest # EDIT: the same label as the jobs below; it needs `gh` (GitHub-hosted images have it).
|
|
126
|
+
permissions:
|
|
127
|
+
actions: read
|
|
128
|
+
outputs:
|
|
129
|
+
tested: ${{ steps.check.outputs.tested }}
|
|
130
|
+
steps:
|
|
131
|
+
- name: Look for a green run of this workflow at this sha
|
|
132
|
+
id: check
|
|
133
|
+
env:
|
|
134
|
+
GH_TOKEN: ${{ github.token }}
|
|
135
|
+
REPO: ${{ github.repository }}
|
|
136
|
+
RUN_ID: ${{ github.run_id }}
|
|
137
|
+
SHA: ${{ github.sha }}
|
|
138
|
+
run: |
|
|
139
|
+
tested=false
|
|
140
|
+
if ! command -v gh >/dev/null 2>&1; then
|
|
141
|
+
echo "::notice::gh is not installed on this runner — running the full suite (#418)."
|
|
142
|
+
elif ! WFID="$(gh api "repos/$REPO/actions/runs/$RUN_ID" --jq .workflow_id 2>/dev/null)" || [ -z "$WFID" ]; then
|
|
143
|
+
echo "::notice::Could not read this run's workflow id — running the full suite (#418)."
|
|
144
|
+
elif ! N="$(gh api "repos/$REPO/actions/workflows/$WFID/runs?head_sha=$SHA&status=success&per_page=20" \
|
|
145
|
+
--jq "[.workflow_runs[] | select(.id != $RUN_ID and .event != \"pull_request\")] | length" 2>/dev/null)"; then
|
|
146
|
+
echo "::notice::Could not list this workflow's runs at $SHA — running the full suite (#418)."
|
|
147
|
+
elif [ "${N:-0}" -ge 1 ] 2>/dev/null; then
|
|
148
|
+
tested=true
|
|
149
|
+
echo "This workflow already passed at $SHA ($N green run(s)) — skipping the suite (#418)."
|
|
150
|
+
echo "Already tested: this workflow has a green run at \`$SHA\` — suite skipped (#418)." >> "$GITHUB_STEP_SUMMARY"
|
|
151
|
+
else
|
|
152
|
+
echo "No green run of this workflow at $SHA yet — running the full suite."
|
|
153
|
+
fi
|
|
154
|
+
echo "tested=$tested" >> "$GITHUB_OUTPUT"
|
|
155
|
+
|
|
107
156
|
gitleaks:
|
|
108
157
|
name: Secret scan (gitleaks)
|
|
158
|
+
needs: dedupe
|
|
159
|
+
if: ${{ !cancelled() && needs.dedupe.outputs.tested != 'true' }}
|
|
109
160
|
runs-on: ubuntu-latest # EDIT: self-hosted label if this repo needs one.
|
|
110
161
|
steps:
|
|
111
162
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
@@ -145,6 +196,8 @@ jobs:
|
|
|
145
196
|
|
|
146
197
|
build:
|
|
147
198
|
name: Build (Laravel + Vite)
|
|
199
|
+
needs: dedupe
|
|
200
|
+
if: ${{ !cancelled() && needs.dedupe.outputs.tested != 'true' }}
|
|
148
201
|
runs-on: ubuntu-latest # EDIT: self-hosted label if this repo needs one.
|
|
149
202
|
# Re-exported so the migrations job below resolves PHP exactly once, here.
|
|
150
203
|
outputs:
|
|
@@ -376,6 +429,10 @@ jobs:
|
|
|
376
429
|
migrations:
|
|
377
430
|
name: Migration round-trip (${{ matrix.engine }})
|
|
378
431
|
needs: build
|
|
432
|
+
# Explicit result check, not the implicit success(): success() reads EVERY ancestor,
|
|
433
|
+
# including `dedupe`, which is skipped on every ordinary push — so the implicit
|
|
434
|
+
# form would skip this job on exactly the runs it exists for (#418).
|
|
435
|
+
if: ${{ !cancelled() && needs.build.result == 'success' }}
|
|
379
436
|
runs-on: ubuntu-latest # EDIT: self-hosted label if this repo needs one.
|
|
380
437
|
strategy:
|
|
381
438
|
fail-fast: false
|
package/templates/ci-node.yml
CHANGED
|
@@ -69,8 +69,59 @@ env:
|
|
|
69
69
|
# jobs from different runs interleave, and trunk can wait behind branch runs.
|
|
70
70
|
# Read CONVENTIONS.md §7, "Self-hosted runners", before choosing a label.
|
|
71
71
|
jobs:
|
|
72
|
+
# Already tested at this sha? (#418) — the claim push.
|
|
73
|
+
# A session's claim pushes its branch at the moment it is cut (CONVENTIONS.md §5, the
|
|
74
|
+
# claim record), so the branch's first push sits on a sha trunk has usually already
|
|
75
|
+
# run. Without this job that push re-runs the whole suite on a tested commit (~19% of
|
|
76
|
+
# all runs, measured across five adopting repos). This job runs ONLY on a ref's first
|
|
77
|
+
# push (`github.event.created`), checks nothing out, and asks one question: does THIS
|
|
78
|
+
# workflow already have a completed, green, non-PR run at THIS exact sha? Yes → every
|
|
79
|
+
# other job is skipped and the run concludes `success` — a branch-CI `green` that is
|
|
80
|
+
# true, because the same workflow passed at the same sha. Anything else — trunk still
|
|
81
|
+
# running, red, never run, `gh` missing, the API failing — and the suite runs as
|
|
82
|
+
# before (fail-open: this job never fails the run). Every later push has
|
|
83
|
+
# `created == false`, so a real commit always gets the full suite, with no extra hop.
|
|
84
|
+
# Why not simply `if: !github.event.created` on every job: a run whose jobs are ALL
|
|
85
|
+
# skipped concludes `skipped`, which `colab ship` reads as not-green (CONVENTIONS.md
|
|
86
|
+
# §4, "Branch CI"). This job is the one that ends green.
|
|
87
|
+
dedupe:
|
|
88
|
+
name: Already tested at this sha?
|
|
89
|
+
if: github.event_name == 'push' && github.event.created
|
|
90
|
+
runs-on: ubuntu-latest # EDIT: the same label as the jobs below; it needs `gh` (GitHub-hosted images have it).
|
|
91
|
+
permissions:
|
|
92
|
+
actions: read
|
|
93
|
+
outputs:
|
|
94
|
+
tested: ${{ steps.check.outputs.tested }}
|
|
95
|
+
steps:
|
|
96
|
+
- name: Look for a green run of this workflow at this sha
|
|
97
|
+
id: check
|
|
98
|
+
env:
|
|
99
|
+
GH_TOKEN: ${{ github.token }}
|
|
100
|
+
REPO: ${{ github.repository }}
|
|
101
|
+
RUN_ID: ${{ github.run_id }}
|
|
102
|
+
SHA: ${{ github.sha }}
|
|
103
|
+
run: |
|
|
104
|
+
tested=false
|
|
105
|
+
if ! command -v gh >/dev/null 2>&1; then
|
|
106
|
+
echo "::notice::gh is not installed on this runner — running the full suite (#418)."
|
|
107
|
+
elif ! WFID="$(gh api "repos/$REPO/actions/runs/$RUN_ID" --jq .workflow_id 2>/dev/null)" || [ -z "$WFID" ]; then
|
|
108
|
+
echo "::notice::Could not read this run's workflow id — running the full suite (#418)."
|
|
109
|
+
elif ! N="$(gh api "repos/$REPO/actions/workflows/$WFID/runs?head_sha=$SHA&status=success&per_page=20" \
|
|
110
|
+
--jq "[.workflow_runs[] | select(.id != $RUN_ID and .event != \"pull_request\")] | length" 2>/dev/null)"; then
|
|
111
|
+
echo "::notice::Could not list this workflow's runs at $SHA — running the full suite (#418)."
|
|
112
|
+
elif [ "${N:-0}" -ge 1 ] 2>/dev/null; then
|
|
113
|
+
tested=true
|
|
114
|
+
echo "This workflow already passed at $SHA ($N green run(s)) — skipping the suite (#418)."
|
|
115
|
+
echo "Already tested: this workflow has a green run at \`$SHA\` — suite skipped (#418)." >> "$GITHUB_STEP_SUMMARY"
|
|
116
|
+
else
|
|
117
|
+
echo "No green run of this workflow at $SHA yet — running the full suite."
|
|
118
|
+
fi
|
|
119
|
+
echo "tested=$tested" >> "$GITHUB_OUTPUT"
|
|
120
|
+
|
|
72
121
|
gitleaks:
|
|
73
122
|
name: Secret scan (gitleaks)
|
|
123
|
+
needs: dedupe
|
|
124
|
+
if: ${{ !cancelled() && needs.dedupe.outputs.tested != 'true' }}
|
|
74
125
|
runs-on: ubuntu-latest # EDIT: self-hosted label if this repo needs one.
|
|
75
126
|
steps:
|
|
76
127
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
@@ -115,6 +166,8 @@ jobs:
|
|
|
115
166
|
|
|
116
167
|
build:
|
|
117
168
|
name: Build
|
|
169
|
+
needs: dedupe
|
|
170
|
+
if: ${{ !cancelled() && needs.dedupe.outputs.tested != 'true' }}
|
|
118
171
|
# A repo can adopt this template before it has any application code at all —
|
|
119
172
|
# a fresh Tier B scaffold with decisions locked and a backlog filed, nothing
|
|
120
173
|
# else. Unguarded, every step below still runs: "Install dependencies" warns
|
package/templates/ci-python.yml
CHANGED
|
@@ -83,8 +83,59 @@ env:
|
|
|
83
83
|
# jobs from different runs interleave, and trunk can wait behind branch runs.
|
|
84
84
|
# Read CONVENTIONS.md §7, "Self-hosted runners", before choosing a label.
|
|
85
85
|
jobs:
|
|
86
|
+
# Already tested at this sha? (#418) — the claim push.
|
|
87
|
+
# A session's claim pushes its branch at the moment it is cut (CONVENTIONS.md §5, the
|
|
88
|
+
# claim record), so the branch's first push sits on a sha trunk has usually already
|
|
89
|
+
# run. Without this job that push re-runs the whole suite on a tested commit (~19% of
|
|
90
|
+
# all runs, measured across five adopting repos). This job runs ONLY on a ref's first
|
|
91
|
+
# push (`github.event.created`), checks nothing out, and asks one question: does THIS
|
|
92
|
+
# workflow already have a completed, green, non-PR run at THIS exact sha? Yes → every
|
|
93
|
+
# other job is skipped and the run concludes `success` — a branch-CI `green` that is
|
|
94
|
+
# true, because the same workflow passed at the same sha. Anything else — trunk still
|
|
95
|
+
# running, red, never run, `gh` missing, the API failing — and the suite runs as
|
|
96
|
+
# before (fail-open: this job never fails the run). Every later push has
|
|
97
|
+
# `created == false`, so a real commit always gets the full suite, with no extra hop.
|
|
98
|
+
# Why not simply `if: !github.event.created` on every job: a run whose jobs are ALL
|
|
99
|
+
# skipped concludes `skipped`, which `colab ship` reads as not-green (CONVENTIONS.md
|
|
100
|
+
# §4, "Branch CI"). This job is the one that ends green.
|
|
101
|
+
dedupe:
|
|
102
|
+
name: Already tested at this sha?
|
|
103
|
+
if: github.event_name == 'push' && github.event.created
|
|
104
|
+
runs-on: ubuntu-latest # EDIT: the same label as the jobs below; it needs `gh` (GitHub-hosted images have it).
|
|
105
|
+
permissions:
|
|
106
|
+
actions: read
|
|
107
|
+
outputs:
|
|
108
|
+
tested: ${{ steps.check.outputs.tested }}
|
|
109
|
+
steps:
|
|
110
|
+
- name: Look for a green run of this workflow at this sha
|
|
111
|
+
id: check
|
|
112
|
+
env:
|
|
113
|
+
GH_TOKEN: ${{ github.token }}
|
|
114
|
+
REPO: ${{ github.repository }}
|
|
115
|
+
RUN_ID: ${{ github.run_id }}
|
|
116
|
+
SHA: ${{ github.sha }}
|
|
117
|
+
run: |
|
|
118
|
+
tested=false
|
|
119
|
+
if ! command -v gh >/dev/null 2>&1; then
|
|
120
|
+
echo "::notice::gh is not installed on this runner — running the full suite (#418)."
|
|
121
|
+
elif ! WFID="$(gh api "repos/$REPO/actions/runs/$RUN_ID" --jq .workflow_id 2>/dev/null)" || [ -z "$WFID" ]; then
|
|
122
|
+
echo "::notice::Could not read this run's workflow id — running the full suite (#418)."
|
|
123
|
+
elif ! N="$(gh api "repos/$REPO/actions/workflows/$WFID/runs?head_sha=$SHA&status=success&per_page=20" \
|
|
124
|
+
--jq "[.workflow_runs[] | select(.id != $RUN_ID and .event != \"pull_request\")] | length" 2>/dev/null)"; then
|
|
125
|
+
echo "::notice::Could not list this workflow's runs at $SHA — running the full suite (#418)."
|
|
126
|
+
elif [ "${N:-0}" -ge 1 ] 2>/dev/null; then
|
|
127
|
+
tested=true
|
|
128
|
+
echo "This workflow already passed at $SHA ($N green run(s)) — skipping the suite (#418)."
|
|
129
|
+
echo "Already tested: this workflow has a green run at \`$SHA\` — suite skipped (#418)." >> "$GITHUB_STEP_SUMMARY"
|
|
130
|
+
else
|
|
131
|
+
echo "No green run of this workflow at $SHA yet — running the full suite."
|
|
132
|
+
fi
|
|
133
|
+
echo "tested=$tested" >> "$GITHUB_OUTPUT"
|
|
134
|
+
|
|
86
135
|
gitleaks:
|
|
87
136
|
name: Secret scan (gitleaks)
|
|
137
|
+
needs: dedupe
|
|
138
|
+
if: ${{ !cancelled() && needs.dedupe.outputs.tested != 'true' }}
|
|
88
139
|
runs-on: ubuntu-latest # EDIT: self-hosted label if this repo needs one.
|
|
89
140
|
steps:
|
|
90
141
|
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
|
|
@@ -129,6 +180,8 @@ jobs:
|
|
|
129
180
|
|
|
130
181
|
build:
|
|
131
182
|
name: Build (Python)
|
|
183
|
+
needs: dedupe
|
|
184
|
+
if: ${{ !cancelled() && needs.dedupe.outputs.tested != 'true' }}
|
|
132
185
|
runs-on: ubuntu-latest # EDIT: self-hosted label if this repo needs one.
|
|
133
186
|
defaults:
|
|
134
187
|
run:
|
package/tools/colab
CHANGED
|
@@ -2398,7 +2398,7 @@ function cmdGateRecorded(argv) {
|
|
|
2398
2398
|
// `live-env:`.
|
|
2399
2399
|
// ---------------------------------------------------------------------------
|
|
2400
2400
|
|
|
2401
|
-
const HELP_GATE_HERMETIC = `colab gate-hermetic [--net auto|on] [--keep VAR,...] [--json] [--verbose] [--repo <path>] -- <test command...>
|
|
2401
|
+
const HELP_GATE_HERMETIC = `colab gate-hermetic [--net auto|on] [--keep VAR,...] [--no-pin] [--json] [--verbose] [--repo <path>] -- <test command...>
|
|
2402
2402
|
|
|
2403
2403
|
Runs the repo's TEST STEP twice and gives one verdict (#403, code-wrap A3):
|
|
2404
2404
|
|
|
@@ -2408,7 +2408,11 @@ Runs the repo's TEST STEP twice and gives one verdict (#403, code-wrap A3):
|
|
|
2408
2408
|
daemon/fleet runtime unset (*_URL *_HOST *_PORT *_TOKEN *_KEY *_SECRET *_SOCK
|
|
2409
2409
|
COLAB_* CLAUDE* GH_* …); network off where the platform allows it —
|
|
2410
2410
|
macOS sandbox-exec, Linux unshare --net (loopback stays up in both) — and the
|
|
2411
|
-
line saying which is always printed.
|
|
2411
|
+
line saying which is always printed. Toolchain-manager homes you have NOT set
|
|
2412
|
+
(RUSTUP_HOME CARGO_HOME PYENV_ROOT RBENV_ROOT ASDF_DATA_DIR NVM_DIR VOLTA_HOME
|
|
2413
|
+
MISE_DATA_DIR GOPATH) are pinned to their real directory first, when it exists,
|
|
2414
|
+
so a rustup/pyenv/asdf proxy still finds the installed toolchain instead of
|
|
2415
|
+
trying to download one (#447). Every pin is printed.
|
|
2412
2416
|
|
|
2413
2417
|
Verdicts (exit 0 = may count as green, 1 = not):
|
|
2414
2418
|
green both runs passed exit 0
|
|
@@ -2425,6 +2429,8 @@ pass \`-- sh -c '…'\` for pipes or &&.
|
|
|
2425
2429
|
--net on do not cut the network (reported); default auto = best effort
|
|
2426
2430
|
--keep A,B pass these variables through to the hermetic run anyway — printed in the
|
|
2427
2431
|
verdict, so a pass-through is never silent
|
|
2432
|
+
--no-pin do not pin toolchain-manager homes: the strict run, for a suite suspected of
|
|
2433
|
+
reading a manager's own config or package cache (~/.cargo/config.toml, …)
|
|
2428
2434
|
--json one JSON object instead of the text verdict
|
|
2429
2435
|
--verbose print each run's full output (default: failing names + a short tail on red)
|
|
2430
2436
|
--repo <path> working tree to run in (default: cwd)
|
|
@@ -2440,7 +2446,7 @@ function cmdGateHermetic(argv) {
|
|
|
2440
2446
|
const cmd = dd === -1 ? [] : argv.slice(dd + 1);
|
|
2441
2447
|
const opts = parseArgs(own, {
|
|
2442
2448
|
values: { '--repo': 'repo', '--net': 'net', '--keep': 'keep' },
|
|
2443
|
-
flags: { '--json': 'json', '--verbose': 'verbose', '-h': 'help', '--help': 'help' },
|
|
2449
|
+
flags: { '--json': 'json', '--verbose': 'verbose', '--no-pin': 'noPin', '-h': 'help', '--help': 'help' },
|
|
2444
2450
|
});
|
|
2445
2451
|
if (opts.help) return print(HELP_GATE_HERMETIC);
|
|
2446
2452
|
if (opts._.length) throw new UserError(`unexpected argument "${opts._[0]}" — the test command goes after \`--\` (see --help)`);
|
|
@@ -2488,7 +2494,10 @@ function cmdGateHermetic(argv) {
|
|
|
2488
2494
|
if (normal.ok && !skip) {
|
|
2489
2495
|
homeDir = fs.mkdtempSync(path.join(os.tmpdir(), 'colab-hermetic-home-'));
|
|
2490
2496
|
try {
|
|
2491
|
-
|
|
2497
|
+
const pins = opts.noPin ? [] : hermetic.toolchainPins(process.env, (d) => {
|
|
2498
|
+
try { return fs.statSync(d).isDirectory(); } catch (_) { return false; }
|
|
2499
|
+
});
|
|
2500
|
+
envInfo = hermetic.hermeticEnv(process.env, homeDir, keep, { pins });
|
|
2492
2501
|
net = hermetic.probeNetworkIsolation({
|
|
2493
2502
|
platform: process.platform, mode: netMode,
|
|
2494
2503
|
run: (c, a) => spawnSync(c, a, { stdio: 'ignore' }),
|
|
@@ -2508,7 +2517,7 @@ function cmdGateHermetic(argv) {
|
|
|
2508
2517
|
verdict, ok: exitCode === 0, command: cmd,
|
|
2509
2518
|
liveEnv: { skip, trunkSource, value: trunkLive.value },
|
|
2510
2519
|
normal: { ok: normal.ok, exit: normal.exit },
|
|
2511
|
-
hermetic: herm ? { ok: herm.ok, exit: herm.exit, stripped: envInfo.stripped, kept: envInfo.kept, network: net.note } : null,
|
|
2520
|
+
hermetic: herm ? { ok: herm.ok, exit: herm.exit, stripped: envInfo.stripped, kept: envInfo.kept, pinned: envInfo.pinned, network: net.note } : null,
|
|
2512
2521
|
failing, notes,
|
|
2513
2522
|
}, null, 2));
|
|
2514
2523
|
return exitCode;
|
|
@@ -2522,6 +2531,8 @@ function cmdGateHermetic(argv) {
|
|
|
2522
2531
|
lines.push(`hermetic run: ${herm.ok ? 'green' : 'RED'} (exit ${herm.exit === null ? 'none' : herm.exit}${herm.signal ? `, ${herm.signal}` : ''})`);
|
|
2523
2532
|
lines.push(` HOME=<fresh empty dir>; unset ${envInfo.stripped.length} var(s)${envInfo.stripped.length ? `: ${envInfo.stripped.join(' ')}` : ''}`);
|
|
2524
2533
|
if (envInfo.kept.length) lines.push(` --keep passed through: ${envInfo.kept.join(' ')}`);
|
|
2534
|
+
if (envInfo.pinned.length) lines.push(` toolchain homes pinned to their real dirs: ${envInfo.pinned.join(' ')}`);
|
|
2535
|
+
else if (opts.noPin) lines.push(' toolchain homes: NOT pinned (--no-pin)');
|
|
2525
2536
|
lines.push(` ${net.note}`);
|
|
2526
2537
|
} else {
|
|
2527
2538
|
lines.push('hermetic run: not attempted (normal run is red)');
|
|
@@ -2541,6 +2552,13 @@ function cmdGateHermetic(argv) {
|
|
|
2541
2552
|
for (const l of hermetic.tail(out)) lines.push(` | ${l}`);
|
|
2542
2553
|
}
|
|
2543
2554
|
}
|
|
2555
|
+
if (verdict === 'live-env' && hermetic.looksLikeToolchainMiss(herm.output)) {
|
|
2556
|
+
lines.push('', 'hint: the hermetic failure looks like a toolchain manager that could not find its install',
|
|
2557
|
+
' (a proxy trying to download a toolchain with the network off) — not necessarily the tests. Its',
|
|
2558
|
+
' default homes under $HOME are pinned already, so its install lives elsewhere (or --no-pin was given):',
|
|
2559
|
+
' export the manager\'s home variable (e.g. RUSTUP_HOME, CARGO_HOME) so it passes through, and re-run.',
|
|
2560
|
+
' Name it in the distill comment (#447).');
|
|
2561
|
+
}
|
|
2544
2562
|
lines.push('', `VERDICT: ${verdict} — ${hermetic.VERDICT_TEXT[verdict]}`);
|
|
2545
2563
|
print(lines.join('\n'));
|
|
2546
2564
|
return exitCode;
|
package/tools/lib/hermetic.js
CHANGED
|
@@ -51,6 +51,70 @@ const TEST_RUNNER_LEAKS = ['NODE_TEST_CONTEXT', 'NODE_TEST_WORKER_ID'];
|
|
|
51
51
|
// HOME-derived locations re-pointed INTO the fresh home, so nothing reaches the real one through them.
|
|
52
52
|
const XDG_DIRS = { XDG_CONFIG_HOME: '.config', XDG_DATA_HOME: '.local/share', XDG_CACHE_HOME: '.cache', XDG_STATE_HOME: '.local/state' };
|
|
53
53
|
|
|
54
|
+
// Toolchain-manager homes (#447). A version manager's proxy (`cargo`/`rustc` from rustup, a pyenv
|
|
55
|
+
// or asdf shim, …) finds its installed toolchain through ONE variable whose default is under
|
|
56
|
+
// $HOME. With HOME swapped for an empty dir the proxy finds nothing, tries to install a toolchain,
|
|
57
|
+
// and — network off — fails; the verdict then read `live-env` and blamed the code for a machine
|
|
58
|
+
// dependency it does not have (measured: a rustup-managed Rust workspace, `live-env` locally,
|
|
59
|
+
// green on CI where the container brings its own toolchain). An installed toolchain is the
|
|
60
|
+
// compiler/interpreter the test step runs ON, not live state the tests READ, so the variable is
|
|
61
|
+
// pinned to the real directory BEFORE HOME moves — only when the caller has not set it already
|
|
62
|
+
// (a set value passes through untouched: none of these names match a strip rule) and only when
|
|
63
|
+
// that directory actually exists (nothing is invented). Every pin is printed in the verdict, the
|
|
64
|
+
// same visibility rule as --keep. The cost, stated: such a home also holds the manager's own
|
|
65
|
+
// config and package cache (~/.cargo/config.toml, ~/.cargo/registry, ~/go/pkg/mod), and a test
|
|
66
|
+
// reading THOSE is not caught — `--no-pin` restores the strict run for a suite suspected of it.
|
|
67
|
+
const TOOLCHAIN_HOMES = [
|
|
68
|
+
{ name: 'RUSTUP_HOME', rel: '.rustup', manager: 'rustup' },
|
|
69
|
+
{ name: 'CARGO_HOME', rel: '.cargo', manager: 'rustup/cargo' },
|
|
70
|
+
{ name: 'PYENV_ROOT', rel: '.pyenv', manager: 'pyenv' },
|
|
71
|
+
{ name: 'RBENV_ROOT', rel: '.rbenv', manager: 'rbenv' },
|
|
72
|
+
{ name: 'ASDF_DATA_DIR', rel: '.asdf', manager: 'asdf' },
|
|
73
|
+
{ name: 'NVM_DIR', rel: '.nvm', manager: 'nvm' },
|
|
74
|
+
{ name: 'VOLTA_HOME', rel: '.volta', manager: 'volta' },
|
|
75
|
+
// mise follows XDG_DATA_HOME, which the hermetic run re-points — so its default must be resolved
|
|
76
|
+
// against the CALLER's XDG_DATA_HOME, not the fresh one.
|
|
77
|
+
{ name: 'MISE_DATA_DIR', rel: '.local/share/mise', xdg: ['XDG_DATA_HOME', 'mise'], manager: 'mise' },
|
|
78
|
+
{ name: 'GOPATH', rel: 'go', manager: 'go (GOTOOLCHAIN downloads + module cache)' },
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Which toolchain homes to pin → `[{ name, value, manager }]`. `exists(path)` is injected so this
|
|
83
|
+
* stays pure; the CLI passes a real directory check. A variable already set in `env` is never in
|
|
84
|
+
* the list — it reaches the hermetic run unchanged anyway.
|
|
85
|
+
*/
|
|
86
|
+
function toolchainPins(env, exists) {
|
|
87
|
+
const home = env.HOME;
|
|
88
|
+
const pins = [];
|
|
89
|
+
for (const t of TOOLCHAIN_HOMES) {
|
|
90
|
+
if (env[t.name]) continue;
|
|
91
|
+
let dir = null;
|
|
92
|
+
if (t.xdg && env[t.xdg[0]]) dir = `${env[t.xdg[0]].replace(/\/+$/, '')}/${t.xdg[1]}`;
|
|
93
|
+
else if (home) dir = `${home.replace(/\/+$/, '')}/${t.rel}`;
|
|
94
|
+
if (dir && exists(dir)) pins.push({ name: t.name, value: dir, manager: t.manager });
|
|
95
|
+
}
|
|
96
|
+
return pins;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// The output shapes of a version manager that could not find its toolchain — what a missed pin
|
|
100
|
+
// looks like. Used only for a hint line under a `live-env` verdict; the verdict itself is unchanged.
|
|
101
|
+
const TOOLCHAIN_MISS_PATTERNS = [
|
|
102
|
+
/syncing channel updates for/i, // rustup proxy installing a toolchain
|
|
103
|
+
/static\.rust-lang\.org/i,
|
|
104
|
+
/rustup could not choose a version|no default toolchain/i,
|
|
105
|
+
/pyenv: version .* is not installed/i,
|
|
106
|
+
/rbenv: version .* is not installed/i,
|
|
107
|
+
/No version is set for command|No preset version installed/i, // asdf
|
|
108
|
+
/mise .*(is not installed|missing:)/i,
|
|
109
|
+
/go: downloading go\d|toolchain not available/i,
|
|
110
|
+
];
|
|
111
|
+
|
|
112
|
+
/** True when a failed run's output looks like a toolchain manager missing its install. */
|
|
113
|
+
function looksLikeToolchainMiss(output) {
|
|
114
|
+
const s = String(output || '');
|
|
115
|
+
return TOOLCHAIN_MISS_PATTERNS.some((re) => re.test(s));
|
|
116
|
+
}
|
|
117
|
+
|
|
54
118
|
function shouldStrip(name) {
|
|
55
119
|
if (name === 'HOME' || name === 'PATH') return false;
|
|
56
120
|
if (STRIP_EXACT.has(name) || STRIP_EXACT.has(name.toLowerCase())) return true;
|
|
@@ -65,15 +129,17 @@ function normalEnv(env) {
|
|
|
65
129
|
}
|
|
66
130
|
|
|
67
131
|
/**
|
|
68
|
-
* The hermetic run's env → `{ env, stripped, kept }`. `home` is the fresh directory the
|
|
69
|
-
* created. `keep` names variables the caller explicitly passes through anyway — every one is
|
|
70
|
-
* echoed in the verdict, so a pass-through is visible, never silent.
|
|
132
|
+
* The hermetic run's env → `{ env, stripped, kept, pinned }`. `home` is the fresh directory the
|
|
133
|
+
* caller created. `keep` names variables the caller explicitly passes through anyway — every one is
|
|
134
|
+
* echoed in the verdict, so a pass-through is visible, never silent. `pins` (from `toolchainPins`)
|
|
135
|
+
* are toolchain-manager homes set to their real directories before HOME moves (#447) — echoed too.
|
|
71
136
|
*/
|
|
72
|
-
function hermeticEnv(env, home, keep = []) {
|
|
137
|
+
function hermeticEnv(env, home, keep = [], { pins = [] } = {}) {
|
|
73
138
|
const keepSet = new Set(keep);
|
|
74
139
|
const out = {};
|
|
75
140
|
const stripped = [];
|
|
76
141
|
const kept = [];
|
|
142
|
+
for (const p of pins) out[p.name] = p.value;
|
|
77
143
|
for (const [k, v] of Object.entries(env)) {
|
|
78
144
|
if (TEST_RUNNER_LEAKS.includes(k)) continue;
|
|
79
145
|
if (keepSet.has(k)) { out[k] = v; if (shouldStrip(k)) kept.push(k); continue; }
|
|
@@ -83,7 +149,7 @@ function hermeticEnv(env, home, keep = []) {
|
|
|
83
149
|
}
|
|
84
150
|
out.HOME = home;
|
|
85
151
|
for (const [k, rel] of Object.entries(XDG_DIRS)) if (!keepSet.has(k)) out[k] = `${home}/${rel}`;
|
|
86
|
-
return { env: out, stripped: stripped.sort(), kept: kept.sort() };
|
|
152
|
+
return { env: out, stripped: stripped.sort(), kept: kept.sort(), pinned: pins.map((p) => p.name) };
|
|
87
153
|
}
|
|
88
154
|
|
|
89
155
|
// ---- the network ----------------------------------------------------------------------------
|
|
@@ -188,6 +254,6 @@ const VERDICT_TEXT = {
|
|
|
188
254
|
};
|
|
189
255
|
|
|
190
256
|
module.exports = {
|
|
191
|
-
parseLiveEnv, shouldStrip, normalEnv, hermeticEnv, probeNetworkIsolation, parseFailures, tail,
|
|
257
|
+
parseLiveEnv, shouldStrip, normalEnv, hermeticEnv, toolchainPins, looksLikeToolchainMiss, TOOLCHAIN_HOMES, probeNetworkIsolation, parseFailures, tail,
|
|
192
258
|
classify, VERDICT_TEXT, DARWIN_PROFILE, LINUX_WRAPPER, TEST_RUNNER_LEAKS,
|
|
193
259
|
};
|