Skip to content

Commit 9c724df

Browse files
committed
fix(ci): fingerprint the environment a lane inherits (#1429)
Found while confirming round 4's witnesses, not reported. Step digests covered step-level `env`, but workflow- and job-level `env:` reaches every step in the lane, so `NODE_OPTIONS=--import ./x.ts` there injects into a plain gate step while the step itself stays byte-identical. Ten jobs carry job-level env today, so this was live rather than theoretical. Modelled at the lane, not folded into each step: one env block is one fact about the lane, and folding it in would have forced every step in those ten jobs into the step inventory. LANE_ENVIRONMENTS is 11 entries, fingerprinted the same way, inert-checked the same way. Also checked the other paths where a lane could exist without being modelled: reusable workflow calls (`jobs.<id>.uses`), `container:`/`services:`, and `defaults.run` at workflow or job level. None are used in this repo today, so they are not gaps now — but they would be silent if introduced, which is worth knowing rather than assuming. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SkS4S8XXrfkJ8TD1VBKkvJ
1 parent c94ffbc commit 9c724df

5 files changed

Lines changed: 201 additions & 3 deletions

File tree

‎scripts/gate/audit.test.ts‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import assert from 'node:assert/strict';
1212
import path from 'node:path';
1313
import test from 'node:test';
1414
import { audit } from './audit.ts';
15-
import { NON_GATE_STEPS } from './declarations.ts';
15+
import { LANE_ENVIRONMENTS, NON_GATE_STEPS } from './declarations.ts';
1616
import { categories, covered, loadModel, stepDigest, type Lane, type Model } from './model.ts';
1717
import { CHECK_CATALOG } from '../check-affected/checks.ts';
1818

@@ -226,6 +226,46 @@ test('a gate invocation cannot carry a payload or an injecting environment', ()
226226
assert.deepEqual(bypassesFor('pnpm gate fallow --base "$FALLOW_BASE"'), []);
227227
});
228228

229+
test('a lane cannot inject through its inherited environment', () => {
230+
// Found while confirming round 4 rather than reported: workflow- and job-level `env:`
231+
// reaches every step, so `NODE_OPTIONS` there injects into a plain gate step while the
232+
// step itself stays byte-identical. Ten lanes carry job-level env today.
233+
const injected = mutate((m) => ({
234+
lanes: m.lanes.map((lane) =>
235+
lane.label === 'Layering Guard'
236+
? {
237+
...lane,
238+
env: { NODE_OPTIONS: '--import ./scripts/layering/check.ts' },
239+
envDigest: 'injected000',
240+
}
241+
: lane,
242+
),
243+
}));
244+
assert.ok(
245+
audit(injected).some((failure) => failure.assertion === 'lane-env'),
246+
'an uninventoried lane environment must fail',
247+
);
248+
249+
const edited = mutate((m) => ({
250+
lanes: m.lanes.map((lane) =>
251+
lane.workflow === 'ios.yml' ? { ...lane, envDigest: 'tampered0000' } : lane,
252+
),
253+
}));
254+
const found = audit(edited);
255+
assert.ok(
256+
found.some((failure) => failure.assertion === 'lane-env'),
257+
'an edited env is unlisted',
258+
);
259+
assert.ok(
260+
found.some((failure) => /LANE_ENVIRONMENTS ios\.yml/.test(failure.message)),
261+
'and its old entry goes inert',
262+
);
263+
264+
// Non-vacuity: the live tree really does have lanes carrying env, so this is not
265+
// asserting about a shape the repo never uses.
266+
assert.ok(LANE_ENVIRONMENTS.length >= 10);
267+
});
268+
229269
test('a step is not hidden by working-directory', () => {
230270
// loadLanes used to drop these, which made anything placed in one invisible.
231271
const found = audit(

‎scripts/gate/audit.ts‎

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
// functions below, because CI can only reach a gate through `pnpm gate <id>`.
88

99
import { CHECK_CATALOG } from '../check-affected/checks.ts';
10-
import { NON_GATE_STEPS, type Unrouted } from './declarations.ts';
10+
import {
11+
LANE_ENVIRONMENTS,
12+
NON_GATE_STEPS,
13+
type LaneEnvironment,
14+
type Unrouted,
15+
} from './declarations.ts';
1116
import {
1217
categories,
1318
checkUnits,
@@ -131,6 +136,45 @@ function bypass(model: Model, declared: readonly Unrouted[]): Failure[] {
131136
});
132137
}
133138

139+
// 3b. A lane's inherited environment is fingerprinted too. `env` at workflow or job
140+
// level reaches every step, so `NODE_OPTIONS=--import ./x.ts` there would inject
141+
// into a plain gate step while the step itself stayed byte-identical.
142+
function laneEnvironments(model: Model, declared: readonly LaneEnvironment[]): Failure[] {
143+
return model.lanes
144+
.filter((lane) => lane.qualifying && lane.envDigest !== '')
145+
.flatMap((lane) => {
146+
if (
147+
declared.some(
148+
(entry) => entry.workflow === lane.workflow && entry.digest === lane.envDigest,
149+
)
150+
) {
151+
return [];
152+
}
153+
return [
154+
fail(
155+
'lane-env',
156+
`${lane.workflow} / ${lane.label}: the lane's inherited env is not in LANE_ENVIRONMENTS ` +
157+
`(digest ${lane.envDigest}): ${Object.keys(lane.env).sort().join(', ')}.`,
158+
),
159+
];
160+
});
161+
}
162+
163+
function inertEnvironment(entry: LaneEnvironment, model: Model): Failure[] {
164+
const live = model.lanes.some(
165+
(lane) =>
166+
lane.qualifying && lane.workflow === entry.workflow && lane.envDigest === entry.digest,
167+
);
168+
if (live) return [];
169+
return [
170+
fail(
171+
'inert',
172+
`LANE_ENVIRONMENTS ${entry.workflow} / "${entry.job}" (digest ${entry.digest}) matches no ` +
173+
`qualifying lane; the environment was edited or the job removed.`,
174+
),
175+
];
176+
}
177+
134178
// 4. Per-path coverage (#1420's class): every check a real selector run activates
135179
// for a category's path must be run by a lane that a PR touching only that path
136180
// actually starts. Assertion 1 can stay green while this fails — that is the point.
@@ -249,6 +293,8 @@ export function audit(model: Model, declared: readonly Unrouted[] = NON_GATE_STE
249293
return [
250294
...unowned(model),
251295
...bypass(model, declared),
296+
...laneEnvironments(model, LANE_ENVIRONMENTS),
297+
...LANE_ENVIRONMENTS.flatMap((entry) => inertEnvironment(entry, model)),
252298
...pathCoverage(model),
253299
...inert(model, declared),
254300
...unregisteredSuites(model),

‎scripts/gate/check.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { loadModel } from './model.ts';
1111
const HEADINGS: Readonly<Record<string, string>> = {
1212
owned: 'Registered checks no lane runs',
1313
bypass: 'Project code run outside `pnpm gate`',
14+
'lane-env': 'Lane environments that are not inventoried',
1415
'path-coverage': 'Paths whose selected checks no triggered lane runs',
1516
inert: 'Declarations that no longer apply',
1617
registered: 'Suites and projects no registered check covers',

‎scripts/gate/declarations.ts‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,3 +288,94 @@ export const NON_GATE_STEPS: readonly Unrouted[] = [
288288
['6153d35b3227', 'Stage the binary for upload'],
289289
]),
290290
];
291+
292+
/**
293+
* Workflow- and job-level `env:` a qualifying lane inherits. Every step in the lane sees
294+
* it, so one `NODE_OPTIONS=--import ./x.ts` here would inject into every gate step at
295+
* once — which is why the lane's environment is fingerprinted like a step body.
296+
*/
297+
export type LaneEnvironment = {
298+
readonly workflow: string;
299+
readonly job: string;
300+
readonly digest: string;
301+
readonly reason: string;
302+
};
303+
304+
export const LANE_ENVIRONMENTS: readonly LaneEnvironment[] = [
305+
{
306+
workflow: 'ci.yml',
307+
job: 'Web Platform Smoke',
308+
digest: '891c2cae5eb2',
309+
reason: 'opts the web platform smoke into its live-browser mode (AGENT_DEVICE_WEB_E2E)',
310+
},
311+
{
312+
workflow: 'concurrency-torture-nightly.yml',
313+
job: 'Concurrency Torture Nightly / Session/lease/lock torture sweep',
314+
digest: 'c9ae66e1a918',
315+
reason:
316+
'sweep size, seed and envelope path for the torture lane (TORTURE_ENVELOPE, TORTURE_RUNS, TORTURE_SEED_START)',
317+
},
318+
{
319+
workflow: 'conformance-differential.yml',
320+
job: 'Conformance Differential / iOS Conformance Differential',
321+
digest: '6a253505c017',
322+
reason:
323+
'simulator identity, CLI path and Maestro analytics opt-out (AGENT_DEVICE_CLI, AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH, AGENT_DEVICE_STATE_DIR, DIFFERENTIAL_ONLY, IOS_RUNTIME_VERSION, MAESTRO_CLI_NO_ANALYTICS)',
324+
},
325+
{
326+
workflow: 'ios.yml',
327+
job: 'iOS / Smoke Tests',
328+
digest: 'd92263e1990d',
329+
reason:
330+
'simulator runtime, derived-data and state paths, and the app event URL template (AGENT_DEVICE_IOS_APP_EVENT_URL_TEMPLATE, AGENT_DEVICE_IOS_PREPARE_TIMEOUT_MS, AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH, AGENT_DEVICE_STATE_DIR, AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS, IOS_RUNTIME_VERSION)',
331+
},
332+
{
333+
workflow: 'linux.yml',
334+
job: 'Linux / Smoke Tests',
335+
digest: 'e0f4b71e0be8',
336+
reason:
337+
'the Xvfb/AT-SPI desktop session the replay smoke needs (DISPLAY, GSETTINGS_BACKEND, GTK_A11Y, GTK_MODULES, NO_AT_BRIDGE, XDG_SESSION_TYPE)',
338+
},
339+
{
340+
workflow: 'macos.yml',
341+
job: 'macOS / Smoke Tests',
342+
digest: '6946ade697b3',
343+
reason:
344+
'derived-data and daemon state paths for the macOS runner (AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH, AGENT_DEVICE_STATE_DIR)',
345+
},
346+
{
347+
workflow: 'perf-nightly.yml',
348+
job: 'Perf Nightly / iOS Command Perf',
349+
digest: '5b24d473c591',
350+
reason:
351+
'benchmark round count, CLI path and device identity (AGENT_DEVICE_IOS_PREPARE_TIMEOUT_MS, AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH, AGENT_DEVICE_PERF_CLI, AGENT_DEVICE_STATE_DIR, IOS_RUNTIME_VERSION, PERF_ROUNDS)',
352+
},
353+
{
354+
workflow: 'perf-nightly.yml',
355+
job: 'Perf Nightly / Android Command Perf',
356+
digest: '4fce57762d05',
357+
reason:
358+
'benchmark round count, CLI path and device identity (AGENT_DEVICE_PERF_CLI, PERF_ROUNDS)',
359+
},
360+
{
361+
workflow: 'replays-nightly.yml',
362+
job: 'Replay Nightly / Android Full Emulator Suite',
363+
digest: '823688085eb9',
364+
reason:
365+
'device identity and state paths for the nightly replay suites (AGENT_DEVICE_STATE_DIR)',
366+
},
367+
{
368+
workflow: 'replays-nightly.yml',
369+
job: 'Replay Nightly / iOS Replay Suite',
370+
digest: '5aa7701df728',
371+
reason:
372+
'device identity and state paths for the nightly replay suites (AGENT_DEVICE_IOS_APP_EVENT_URL_TEMPLATE, AGENT_DEVICE_IOS_PREPARE_TIMEOUT_MS, AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH, AGENT_DEVICE_STATE_DIR, IOS_RUNTIME_VERSION)',
373+
},
374+
{
375+
workflow: 'replays-nightly.yml',
376+
job: 'Replay Nightly / macOS Replay Suite',
377+
digest: '6946ade697b3',
378+
reason:
379+
'device identity and state paths for the nightly replay suites (AGENT_DEVICE_IOS_RUNNER_DERIVED_PATH, AGENT_DEVICE_STATE_DIR)',
380+
},
381+
];

‎scripts/gate/model.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export type Lane = {
5353
readonly steps: readonly LaneStep[];
5454
readonly paths: readonly string[];
5555
readonly pathsIgnore: readonly string[];
56+
/**
57+
* Workflow- and job-level `env:`, which every step in the lane inherits. Modelled at
58+
* the lane rather than folded into each step's digest: one `NODE_OPTIONS` here injects
59+
* into every step at once, so it is one fact about the lane, not N facts about steps.
60+
*/
61+
readonly env: Readonly<Record<string, string>>;
62+
readonly envDigest: string;
5663
};
5764

5865
/**
@@ -307,10 +314,11 @@ function compositeSteps(
307314

308315
type WorkflowDoc = {
309316
name?: string;
317+
env?: Record<string, unknown>;
310318
// `on:` is YAML 1.1 truthy; the parser hands it back under `true`.
311319
on?: Record<string, never>;
312320
true?: Record<string, never>;
313-
jobs?: Record<string, { name?: string; steps?: RawStep[] }>;
321+
jobs?: Record<string, { name?: string; env?: Record<string, unknown>; steps?: RawStep[] }>;
314322
};
315323

316324
/**
@@ -359,6 +367,15 @@ function laneInvocations(
359367
return { gates: [...gates], verbatim: [...verbatim] };
360368
}
361369

370+
function inheritedEnv(
371+
doc: WorkflowDoc,
372+
job: { env?: Record<string, unknown> },
373+
): Record<string, string> {
374+
const env: Record<string, string> = {};
375+
for (const [key, value] of Object.entries({ ...doc.env, ...job.env })) env[key] = String(value);
376+
return env;
377+
}
378+
362379
function workflowLanes(
363380
file: string,
364381
doc: WorkflowDoc,
@@ -373,6 +390,7 @@ function workflowLanes(
373390
const { paths, pathsIgnore } = triggerPaths(on);
374391
return Object.entries(doc.jobs ?? {}).map(([jobId, job]) => {
375392
const steps = laneSteps(job, jobId, actionRoot, file);
393+
const env = inheritedEnv(doc, job);
376394
return {
377395
workflow: file,
378396
label: laneLabel(doc.name ?? file, job.name ?? jobId),
@@ -381,6 +399,8 @@ function workflowLanes(
381399
steps,
382400
paths,
383401
pathsIgnore,
402+
env,
403+
envDigest: Object.keys(env).length === 0 ? '' : stepDigest('', env),
384404
};
385405
});
386406
}

0 commit comments

Comments
 (0)