diff --git a/.github/workflows/chat-catalog-testops-case.yml b/.github/workflows/chat-catalog-testops-case.yml index 73ca9502d92..7924c3e0200 100644 --- a/.github/workflows/chat-catalog-testops-case.yml +++ b/.github/workflows/chat-catalog-testops-case.yml @@ -119,7 +119,7 @@ jobs: (cd chat-completion-build && sha256sum -c chat-completion-build.tar.gz.sha256) tar -xzf chat-completion-build/chat-completion-build.tar.gz -C "$GITHUB_WORKSPACE" pnpm install --frozen-lockfile --ignore-scripts - (cd .testops-trusted && node tests/runner-e2e/prepare-report-lock.mjs && pnpm install --frozen-lockfile --ignore-scripts --store-dir "$RUNNER_TEMP/chat-completion-retention-store") + (cd .testops-trusted && node tests/runner-e2e/prepare-report-lock.mjs && node tests/runner-e2e/prepare-report-lock.mjs --reporting-install -- pnpm install --frozen-lockfile --ignore-scripts --store-dir "$RUNNER_TEMP/chat-completion-retention-store") - name: Qualify the pinned provider runtime and preinstalled browser run: | node packages/paperclip-runner/scripts/materialize-opencode-binary.mjs @@ -202,7 +202,7 @@ jobs: - name: Install trusted reporting dependencies with lifecycle scripts disabled run: | node tests/runner-e2e/prepare-report-lock.mjs - pnpm install --frozen-lockfile --ignore-scripts --store-dir "$RUNNER_TEMP/chat-completion-report-store" + node tests/runner-e2e/prepare-report-lock.mjs --reporting-install -- pnpm install --frozen-lockfile --ignore-scripts --store-dir "$RUNNER_TEMP/chat-completion-report-store" - name: Prepare unchanged exact-key report and cell policies id: session run: node cli/node_modules/tsx/dist/cli.mjs tests/runner-e2e/manual-private-transfer.ts report-session diff --git a/.github/workflows/chat-catalog-testops.yml b/.github/workflows/chat-catalog-testops.yml index 86874807be8..7958becbe09 100644 --- a/.github/workflows/chat-catalog-testops.yml +++ b/.github/workflows/chat-catalog-testops.yml @@ -265,7 +265,7 @@ jobs: - name: Install trusted reporting dependencies without lifecycle scripts run: | node tests/runner-e2e/prepare-report-lock.mjs - pnpm install --frozen-lockfile --ignore-scripts + node tests/runner-e2e/prepare-report-lock.mjs --reporting-install -- pnpm install --frozen-lockfile --ignore-scripts - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 with: artifact-ids: ${{ needs.select.outputs.artifact_id }} diff --git a/.github/workflows/runner-full-stack-e2e.yml b/.github/workflows/runner-full-stack-e2e.yml index df00eb932fa..c7b9ded7df6 100644 --- a/.github/workflows/runner-full-stack-e2e.yml +++ b/.github/workflows/runner-full-stack-e2e.yml @@ -238,7 +238,7 @@ jobs: run: node tests/runner-e2e/prepare-report-lock.mjs - name: Validate report dependency manifests offline - run: pnpm install --lockfile-only --frozen-lockfile --ignore-scripts --offline + run: node tests/runner-e2e/prepare-report-lock.mjs --reporting-preflight - name: Classify manual evidence before any protected credential job id: evidence_route @@ -1122,7 +1122,7 @@ jobs: set -euo pipefail test "$(git rev-parse HEAD)" = "$GITHUB_SHA" node tests/runner-e2e/prepare-report-lock.mjs - pnpm install --frozen-lockfile --ignore-scripts --store-dir "$RUNNER_TEMP/manual-private-publication-store" + node tests/runner-e2e/prepare-report-lock.mjs --reporting-install -- pnpm install --frozen-lockfile --ignore-scripts --store-dir "$RUNNER_TEMP/manual-private-publication-store" - name: Bind protected original run and compatible target evidence protocol id: manual_private @@ -1593,7 +1593,7 @@ jobs: run: node tests/runner-e2e/prepare-report-lock.mjs - name: Install pinned reporting dependencies - run: pnpm install --frozen-lockfile --ignore-scripts --store-dir "${{ runner.temp }}/eval-report-store" + run: node tests/runner-e2e/prepare-report-lock.mjs --reporting-install -- pnpm install --frozen-lockfile --ignore-scripts --store-dir "${{ runner.temp }}/eval-report-store" - name: Prepare exact manual report storage identity id: manual_report @@ -2211,7 +2211,7 @@ jobs: run: node tests/runner-e2e/prepare-report-lock.mjs - name: Install pinned publication dependencies - run: pnpm install --frozen-lockfile --ignore-scripts --store-dir "${{ runner.temp }}/eval-publisher-store" + run: node tests/runner-e2e/prepare-report-lock.mjs --reporting-install -- pnpm install --frozen-lockfile --ignore-scripts --store-dir "${{ runner.temp }}/eval-publisher-store" - name: Install publisher-only Chromium run: pnpm exec playwright install --with-deps --only-shell chromium diff --git a/tests/runner-e2e/README.md b/tests/runner-e2e/README.md index afa4be32129..10eb9829409 100644 --- a/tests/runner-e2e/README.md +++ b/tests/runner-e2e/README.md @@ -765,3 +765,37 @@ Use `--port 4320` for another port, `--refresh` to refresh the history snapshot, or `--offline` to require cached data. Offline mode supports reports and assets already visited; it reports uncached artifacts explicitly. The preview contains only published evidence, not private Playwright traces or videos. + + +## Reporting-only dependency preparation + +Trusted report/publisher checkouts use `prepare-report-lock.mjs --reporting-install` +around their existing frozen, scripts-disabled install and own store. After the +reviewed lock and patch hashes are authenticated, only the two exact Photon/grpc +patch declarations absent from that lock may be omitted temporarily. All package +versions and canonical patches remain locked; normal frozen pnpm rejects any +other manifest mismatch. This installs the canonical **unpatched reporting graph**, +not the patched Photon product runtime. Never allocate a Photon client or produce +a product installed-artifact proof from that reporting checkout. + +Both original manifest byte streams are restored before reporting or SDK evidence +checks, including after an installer error. The default `prepareReportLock` API, +product installs, reviewed SDK reference, registry and trusted managed lock are +unchanged. The separate `--reporting-preflight` mode runs only the fixed offline, +frozen, scripts-disabled, lockfile-only validation in a credential-free job. It +refuses OIDC/AWS capabilities; protected install mode refuses preflight options. + +Ownership is exclusive per checkout. A restoration error retains the exact +beforeimages in `.paperclip-reporting-dependencies/` and blocks another invocation. +SIGTERM, SIGKILL or runner loss can bypass JavaScript cleanup: **automatic exact +restoration is not promised on interruption**. Do not delete the ownership directory +or retry in that checkout. Preserve the failed checkout/evidence and retry the +normal job from a **fresh disposable checkout of the same trusted workflow SHA**, +with a fresh job-local reporting store. The fresh checkout must contain the original +committed manifests and no ownership directory; an accidentally reused checkout +fails closed. Local retained-checkout restoration requires explicit owner review of +both saved beforeimages and current files before either is replaced; the helper +never takes over a stale owner. Do not reuse its installed modules as product inputs. + +`pnpm test:e2e:runner:unit` includes the Vitest reporting-owner controls through +`tests/runner-e2e/vitest.config.ts`; no separate unowned Node test lane is needed. diff --git a/tests/runner-e2e/prepare-report-lock.mjs b/tests/runner-e2e/prepare-report-lock.mjs index f713cca39b0..2cca31a6ac6 100644 --- a/tests/runner-e2e/prepare-report-lock.mjs +++ b/tests/runner-e2e/prepare-report-lock.mjs @@ -59,8 +59,15 @@ export async function refreshReportLock(root = path.resolve(import.meta.dirname, if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) { const args = process.argv.slice(2); - const usage = 'Usage: prepare-report-lock.mjs [--refresh [--trusted-lock-sha256 ]]'; + const usage = 'Usage: prepare-report-lock.mjs [--reporting-preflight | --reporting-install -- pnpm install --frozen-lockfile --ignore-scripts [--store-dir PATH] | --refresh [--trusted-lock-sha256 ]]'; if (args.length === 0) console.log(await prepareReportLock()); + else if (args[0] === '--reporting-preflight' || args[0] === '--reporting-install') { + const { withReportingDependencies, reportingPnpmArguments } = await import('./report-only-dependencies.mjs'); + const options = reportingPnpmArguments(args[0], args.slice(1)); + await prepareReportLock(); + await withReportingDependencies(path.resolve(import.meta.dirname, '../..'), + () => execFileSync('pnpm', options, { cwd: path.resolve(import.meta.dirname, '../..'), stdio: 'inherit' })); + } else if (args.length === 1 && args[0] === '--refresh') console.log(await refreshReportLock()); else if (args.length === 3 && args[0] === '--refresh' && args[1] === '--trusted-lock-sha256' && /^[0-9a-f]{64}$/.test(args[2])) { console.log(await refreshReportLock(undefined, { trustedLockSha256: args[2] })); diff --git a/tests/runner-e2e/report-only-dependencies.mjs b/tests/runner-e2e/report-only-dependencies.mjs new file mode 100644 index 00000000000..30fd2568ce8 --- /dev/null +++ b/tests/runner-e2e/report-only-dependencies.mjs @@ -0,0 +1,127 @@ +// Explicit reporting checkout preparation only. Never call on a product/SDK build. +import { createHash } from 'node:crypto'; +import { readFile, writeFile, mkdir, rm } from 'node:fs/promises'; +import path from 'node:path'; + +const hash = bytes => createHash('sha256').update(bytes).digest('hex'); +const extras = new Map([ + ['@grpc/grpc-js@1.14.5', 'patches/@grpc__grpc-js@1.14.5.patch'], + ['@photon-ai/advanced-imessage@2.2.0', 'patches/@photon-ai__advanced-imessage@2.2.0.patch'], +]); +const fail = () => { throw new Error('Reporting dependency configuration is not compatible with the reviewed lock'); }; +function scalar(value) { + if (value.startsWith('"')) { const parsed = JSON.parse(value); if (typeof parsed !== 'string') fail(); return parsed; } + if (/^'(?:[^']|'')*'$/.test(value)) return value.slice(1, -1).replaceAll("''", "'"); + if (!/^[A-Za-z0-9@_./+*^~<>=:|()%,-]+$/.test(value)) fail(); + return value; +} +function block(text, name) { + if (text.length > 8 * 1024 * 1024 || text.includes('\r') || text.includes('\t')) fail(); + const lines = text.split('\n'), starts = lines.flatMap((line, i) => line === name + ':' ? [i] : []); + if (starts.length !== 1) fail(); + const start = starts[0] + 1; + let end = start; + while (end < lines.length && (!lines[end] || lines[end].startsWith(' ') || lines[end].startsWith('#'))) end++; + return { lines, start, end, body: lines.slice(start, end).filter(line => line && !line.trimStart().startsWith('#')) }; +} +function put(map, key, value) { if (map.has(key)) fail(); map.set(key, value); } +function patchInventory(lock) { + const lines = block(lock, 'patchedDependencies').body, entries = new Map(); + for (let i = 0; i < lines.length; i += 3) { + const key = /^ (.+):$/.exec(lines[i] ?? ''), digest = /^ hash: ([a-z0-9]+)$/.exec(lines[i + 1] ?? ''), file = /^ path: (.+)$/.exec(lines[i + 2] ?? ''); + if (!key || !digest || !file) fail(); + const name = scalar(key[1]), filePath = scalar(file[1]); + if (!/^patches\/[A-Za-z0-9@_.+-]+\.patch$/.test(filePath)) fail(); + put(entries, name, filePath); + } + if (!entries.size) fail(); + return entries; +} +function configurationExtras(entries, reviewed) { + for (const [name, file] of reviewed) if (entries.get(name) !== file) fail(); + const remove = []; + for (const [name, file] of entries) { + if (reviewed.has(name)) continue; + if (extras.get(name) !== file) fail(); + remove.push(name); + } + return remove.sort(); +} +async function installWithReviewedPatches(root, install, ownership) { + const policy = JSON.parse(await readFile(path.join(root, 'tests/runner-e2e/report-lock.json'), 'utf8')); + if (![policy.outputSha256, policy.patchSha256].every(value => typeof value === 'string' && /^[a-f0-9]{64}$/.test(value))) fail(); + const lock = await readFile(path.join(root, 'pnpm-lock.yaml')); + const patch = await readFile(path.join(root, 'tests/runner-e2e/report-lock.patch')); + if (hash(lock) !== policy.outputSha256 || hash(patch) !== policy.patchSha256) fail(); + const reviewed = patchInventory(lock.toString('utf8')); + const packagePath = path.join(root, 'package.json'), workspacePath = path.join(root, 'pnpm-workspace.yaml'); + const packageBytes = await readFile(packagePath, 'utf8'), manifest = JSON.parse(packageBytes); + const rootEntries = new Map(Object.entries(manifest.pnpm?.patchedDependencies ?? {})); + const remove = configurationExtras(rootEntries, reviewed); + const workspace = await readFile(workspacePath, 'utf8'), section = block(workspace, 'patchedDependencies'); + const workspaceEntries = new Map(), lineNames = new Map(); + for (let i = section.start; i < section.end; i++) { + const line = section.lines[i]; if (!line || line.trimStart().startsWith('#')) continue; + const match = /^ (.+): ([^\n]+)$/.exec(line); if (!match) fail(); + const name = scalar(match[1]); put(workspaceEntries, name, scalar(match[2])); lineNames.set(i, name); + } + if (JSON.stringify(configurationExtras(workspaceEntries, reviewed)) !== JSON.stringify(remove)) fail(); + await writeFile(path.join(ownership, 'package.json.before'), packageBytes, { flag: 'wx', mode: 0o600 }); + await writeFile(path.join(ownership, 'pnpm-workspace.yaml.before'), workspace, { flag: 'wx', mode: 0o600 }); + // Restore exact Source bytes before report/evidence code runs, even on failure. + // No product installer or reviewed SDK reference calls this reporting-only owner. + let result, primary, failed = false; + try { + if (remove.length) { + for (const name of remove) delete manifest.pnpm.patchedDependencies[name]; + const nextWorkspace = section.lines.filter((_, i) => !remove.includes(lineNames.get(i))).join('\n'); + await writeFile(packagePath, JSON.stringify(manifest, null, 2) + '\n'); + await writeFile(workspacePath, nextWorkspace); + } + result = await install(); + } catch (error) { primary = error; failed = true; } + const cleanup = remove.length ? await Promise.allSettled([ + writeFile(packagePath, packageBytes), writeFile(workspacePath, workspace), + ]) : []; + const errors = cleanup.filter(item => item.status === 'rejected').map(item => item.reason); + if (errors.length) { + const error = new AggregateError(failed ? [primary, ...errors] : errors, 'Reporting install or exact Source restoration failed'); + error.reportingRestorationFailed = true; + throw error; + } + if (failed) throw primary; + return result; +} + +export async function withReportingDependencies(root, install) { + // No stale-owner takeover: a crashed install must be inspected/restored first. + const ownership = path.join(root, '.paperclip-reporting-dependencies'); + await mkdir(ownership, { mode: 0o700 }); + let result, primary, failed = false; + try { result = await installWithReviewedPatches(root, install, ownership); } + catch (error) { primary = error; failed = true; } + // Preserve exact beforeimages and exclusive ownership if restoration failed. + if (failed && primary?.reportingRestorationFailed) throw primary; + try { await rm(ownership, { recursive: true }); } + catch (error) { + throw new AggregateError(failed ? [primary, error] : [error], 'Reporting install ownership cleanup failed'); + } + if (failed) throw primary; + return result; +} + +export function reportingPnpmArguments(mode, args, environment = process.env) { + if (mode === '--reporting-preflight') { + if (args.length || ['ACTIONS_ID_TOKEN_REQUEST_URL', 'ACTIONS_ID_TOKEN_REQUEST_TOKEN', + 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_SESSION_TOKEN', 'AWS_WEB_IDENTITY_TOKEN_FILE'] + .some(name => environment[name])) throw new Error('Reporting preflight requires a credential-free job and no caller options'); + return ['install', '--lockfile-only', '--frozen-lockfile', '--ignore-scripts', '--offline']; + } + const prefix = ['--', 'pnpm', 'install', '--frozen-lockfile', '--ignore-scripts']; + if (mode !== '--reporting-install' || !prefix.every((value, i) => args[i] === value) + || !(args.length === prefix.length || (args.length === prefix.length + 2 + && args[5] === '--store-dir' && typeof args[6] === 'string' && args[6] + && !args[6].startsWith('-') && !args[6].includes('\0')))) + throw new Error('Reporting install requires the fixed frozen, scripts-disabled command and optional own store'); + return args.slice(2); +} diff --git a/tests/runner-e2e/report-only-dependencies.test.mjs b/tests/runner-e2e/report-only-dependencies.test.mjs new file mode 100644 index 00000000000..a77b95bbc83 --- /dev/null +++ b/tests/runner-e2e/report-only-dependencies.test.mjs @@ -0,0 +1,95 @@ +import { test } from 'vitest'; +import assert from 'node:assert/strict'; +import { mkdtemp, mkdir, readFile, writeFile, rm, stat } from 'node:fs/promises'; +import { tmpdir } from 'node:os'; +import path from 'node:path'; +import { createHash } from 'node:crypto'; +import { withReportingDependencies, reportingPnpmArguments } from './report-only-dependencies.mjs'; +const digest = bytes => createHash('sha256').update(bytes).digest('hex'); +const grpc = '@grpc/grpc-js@1.14.5', photon = '@photon-ai/advanced-imessage@2.2.0'; +const canonical = { 'postgres@3.4.9': 'patches/postgres@3.4.9.patch' }; +async function fixture(run, mutate = async () => {}) { + const root = await mkdtemp(path.join(tmpdir(), 'reporting-patches-')); + try { + const directory = path.join(root, 'tests/runner-e2e'); await mkdir(directory, { recursive: true }); + const patches = { ...canonical, [grpc]: 'patches/@grpc__grpc-js@1.14.5.patch', [photon]: 'patches/@photon-ai__advanced-imessage@2.2.0.patch' }; + await writeFile(path.join(root, 'package.json'), JSON.stringify({ private: true, scripts: { postinstall: 'MUST_NOT_RUN' }, pnpm: { patchedDependencies: patches } }, null, 2) + '\n'); + await writeFile(path.join(root, 'pnpm-workspace.yaml'), 'packages:\n - packages/*\npatchedDependencies:\n' + Object.entries(patches).map(([key, value]) => ` "${key}": ${value}\n`).join('') + '\noverrides:\n stable: 1\n'); + await writeFile(path.join(root, 'pnpm-lock.yaml'), "lockfileVersion: '9.0'\npatchedDependencies:\n postgres@3.4.9:\n hash: abc123\n path: patches/postgres@3.4.9.patch\nimporters:\n .:\n dependencies:\n stable:\n specifier: ^1.0.0\n version: 1.0.0\n"); + await writeFile(path.join(directory, 'report-lock.patch'), 'authenticated fixture patch\n'); + const lock = await readFile(path.join(root, 'pnpm-lock.yaml')), patch = await readFile(path.join(directory, 'report-lock.patch')); + await writeFile(path.join(directory, 'report-lock.json'), JSON.stringify({ outputSha256: digest(lock), patchSha256: digest(patch) })); + await mutate(root); + const names = ['package.json', 'pnpm-workspace.yaml', 'pnpm-lock.yaml', 'tests/runner-e2e/report-lock.json', 'tests/runner-e2e/report-lock.patch']; + const before = await Promise.all(names.map(async name => [name, await readFile(path.join(root, name)), (await stat(path.join(root, name))).mode])); + await run(root); + for (const [name, bytes, mode] of before) { assert.deepEqual(await readFile(path.join(root, name)), bytes, name); assert.equal((await stat(path.join(root, name))).mode, mode); } + } finally { await rm(root, { recursive: true, force: true }); } +} +test('reporting scope uses canonical patches then restores exact Source, repeatedly', () => fixture(async root => { + for (let i = 0; i < 2; i++) await withReportingDependencies(root, async () => { + assert.deepEqual(JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8')).pnpm.patchedDependencies, canonical); + const workspace = await readFile(path.join(root, 'pnpm-workspace.yaml'), 'utf8'); + assert.ok(!workspace.includes(grpc)); assert.ok(!workspace.includes(photon)); assert.ok(workspace.includes('postgres@3.4.9')); + }); +})); +test('failed frozen installer preserves exact primary error and restores both Source files', () => fixture(async root => { + const reason = new Error('actual installer refusal'); + await assert.rejects(withReportingDependencies(root, async () => { throw reason; }), error => error === reason); +})); +test('overlapping invocation refuses before changing active reporting scope', () => fixture(async root => { + await withReportingDependencies(root, async () => { + await assert.rejects(withReportingDependencies(root, async () => assert.fail('second installer entered')), { code: 'EEXIST' }); + assert.deepEqual(JSON.parse(await readFile(path.join(root, 'package.json'), 'utf8')).pnpm.patchedDependencies, canonical); + }); +})); +for (const variant of ['unknown-lock', 'changed-patch', 'unknown-patch', 'changed-canonical-path', 'wrong-extra-path', 'workspace-disagreement', 'duplicate-workspace-key']) { + test(`refuses ${variant} before installer/config writes`, () => fixture(async root => { + await assert.rejects(withReportingDependencies(root, async () => assert.fail('installer entered'))); + }, async root => { + if (variant === 'unknown-lock') return writeFile(path.join(root, 'pnpm-lock.yaml'), 'unknown'); + if (variant === 'changed-patch') return writeFile(path.join(root, 'tests/runner-e2e/report-lock.patch'), 'changed'); + if (variant.startsWith('workspace') || variant === 'duplicate-workspace-key') { + const file = path.join(root, 'pnpm-workspace.yaml'), text = await readFile(file, 'utf8'); + return writeFile(file, variant === 'duplicate-workspace-key' ? text.replace('patchedDependencies:', 'patchedDependencies:\n postgres@3.4.9: patches/postgres@3.4.9.patch') : text.replace(` "${grpc}": patches/@grpc__grpc-js@1.14.5.patch\n`, '')); + } + const file = path.join(root, 'package.json'), manifest = JSON.parse(await readFile(file, 'utf8')); + if (variant === 'unknown-patch') manifest.pnpm.patchedDependencies['other@1'] = 'patches/other.patch'; + if (variant === 'changed-canonical-path') manifest.pnpm.patchedDependencies['postgres@3.4.9'] = 'patches/other.patch'; + if (variant === 'wrong-extra-path') manifest.pnpm.patchedDependencies[grpc] = 'patches/other.patch'; + await writeFile(file, JSON.stringify(manifest)); + })); +} + +test('failed restoration retains both exact beforeimages, primary error and exclusive ownership', () => fixture(async root => { + const packagePath = path.join(root, 'package.json'), workspacePath = path.join(root, 'pnpm-workspace.yaml'); + const originalPackage = await readFile(packagePath), originalWorkspace = await readFile(workspacePath); + const reason = new Error('frozen installer failed before restoration'); + await assert.rejects(withReportingDependencies(root, async () => { + await rm(packagePath); await mkdir(packagePath); throw reason; + }), error => error instanceof AggregateError && error.errors[0] === reason + && error.errors.some(item => item.code === 'EISDIR')); + const ownership = path.join(root, '.paperclip-reporting-dependencies'); + assert.deepEqual(await readFile(path.join(ownership, 'package.json.before')), originalPackage); + assert.deepEqual(await readFile(path.join(ownership, 'pnpm-workspace.yaml.before')), originalWorkspace); + assert.deepEqual(await readFile(workspacePath), originalWorkspace); + await assert.rejects(withReportingDependencies(root, async () => assert.fail('retry entered')), { code: 'EEXIST' }); + // Explicit test-fixture disposal/recovery, never automatic stale-owner takeover. + await rm(packagePath, { recursive: true }); await writeFile(packagePath, originalPackage); + await rm(ownership, { recursive: true }); +})); +test('only credential-free preflight admits the fixed offline lockfile-only command', () => { + assert.deepEqual(reportingPnpmArguments('--reporting-preflight', [], {}), + ['install', '--lockfile-only', '--frozen-lockfile', '--ignore-scripts', '--offline']); + assert.throws(() => reportingPnpmArguments('--reporting-preflight', ['--offline'], {})); + for (const name of ['ACTIONS_ID_TOKEN_REQUEST_URL', 'ACTIONS_ID_TOKEN_REQUEST_TOKEN', 'AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY', 'AWS_SESSION_TOKEN', 'AWS_WEB_IDENTITY_TOKEN_FILE']) + assert.throws(() => reportingPnpmArguments('--reporting-preflight', [], { [name]: 'controlled capability sentinel' })); +}); +test('protected reporting install refuses preflight, resolver and lifecycle option changes', () => { + const prefix = ['--', 'pnpm', 'install', '--frozen-lockfile', '--ignore-scripts']; + assert.deepEqual(reportingPnpmArguments('--reporting-install', [...prefix, '--store-dir', '/owned/report-store'], {}), + ['install', '--frozen-lockfile', '--ignore-scripts', '--store-dir', '/owned/report-store']); + for (const extra of ['--lockfile-only', '--offline', '--no-frozen-lockfile', '--resolution-only', '--ignore-scripts=false']) + assert.throws(() => reportingPnpmArguments('--reporting-install', [...prefix, extra], {})); + assert.throws(() => reportingPnpmArguments('--reporting-install', ['--', 'pnpm', 'install', '--frozen-lockfile'], {})); +}); diff --git a/tests/runner-e2e/workflow-security.test.ts b/tests/runner-e2e/workflow-security.test.ts index ecf320784b6..ed7a8359cad 100644 --- a/tests/runner-e2e/workflow-security.test.ts +++ b/tests/runner-e2e/workflow-security.test.ts @@ -282,9 +282,10 @@ describe("public repository paid workflow security", () => { expect(authorizeJob.match(/actions\/checkout@/gu)).toHaveLength(1); expect(authorizeJob).toContain("ref: ${{ github.sha }}"); expect(authorizeJob).not.toContain("ref: ${{ needs.authorize.outputs.target_sha }}"); - expect(authorizeJob.match(/run: pnpm install.*$/gmu)).toEqual([ - "run: pnpm install --lockfile-only --frozen-lockfile --ignore-scripts --offline", + expect(authorizeJob.match(/run: node tests\/runner-e2e\/prepare-report-lock\.mjs --reporting-preflight$/gmu)).toEqual([ + "run: node tests/runner-e2e/prepare-report-lock.mjs --reporting-preflight", ]); + expect(authorizeJob).not.toContain("run: pnpm install"); expect(targetLockJob).toContain("name: Resolve target pnpm lockfile"); expect(targetLockJob).toContain("needs: authorize"); expect(targetLockJob).toContain( @@ -800,6 +801,8 @@ describe("public repository paid workflow security", () => { expect(job).not.toContain("resolved-target-lockfile"); expect(job, jobName).not.toContain("--no-frozen-lockfile"); expect(job, jobName).not.toContain("--lockfile-only"); + expect(job, jobName).not.toContain("--reporting-preflight"); + expect(job, jobName).toContain("--reporting-install -- pnpm install --frozen-lockfile --ignore-scripts"); expect(install, jobName).toBeGreaterThan(job.indexOf("ref: ${{ github.sha }}")); const credentials = job.indexOf("aws-actions/configure-aws-credentials@"); if (credentials >= 0) expect(install).toBeLessThan(credentials);