fix(release): verify helper producers and preserve rerun artifacts
This commit is contained in:
1 parent
3f579d45eb
commit
41beadfa2a
16 files changed
+382
-75
No files matched your search
@@ -1,10 +1,11 @@
|
||||
/** Byte-level source reuse survives unrelated releases and invalidates changed build inputs. */
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { chmodSync, copyFileSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, symlinkSync, utimesSync, writeFileSync } from 'node:fs'
|
||||
import { execFileSync, spawnSync } from 'node:child_process'
|
||||
import { chmodSync, copyFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync, symlinkSync, utimesSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { delimiter, dirname, join, resolve } from 'node:path'
|
||||
import { expect, it, onTestFinished } from 'vitest'
|
||||
import { cuaHelperBuildKey, cuaHelperSourceDigest, readCuaSigningSettings } from './build-inputs.ts'
|
||||
import { loadDesktopPackageEnvironment } from '../../apps/desktop/scripts/desktop-package-environment.mjs'
|
||||
import { cuaHelperBuildKey, cuaHelperSourceDigest, cuaHelperSourceMatches, readCuaSigningSettings } from './build-inputs.ts'
|
||||
|
||||
function fixture() {
|
||||
const root = mkdtempSync(join(tmpdir(), 'cua-inputs-'))
|
||||
@@ -19,6 +20,7 @@ function fixture() {
|
||||
'scripts/cua-helper/package.ts': 'build helper',
|
||||
'apps/desktop/scripts/notarize-macos.mjs': 'notarize helper',
|
||||
'.github/workflows/cua-helper-package.yml': 'build configuration',
|
||||
'.github/workflows/release-publish.yml': 'publish configuration',
|
||||
'packages/client/unrelated/src/index.ts': 'unrelated feature',
|
||||
}
|
||||
for (const [path, bytes] of Object.entries(files)) {
|
||||
@@ -121,3 +123,149 @@ it('loads fingerprinting and selection under plain Node with no node_modules dir
|
||||
{ cwd: f.root, encoding: 'utf8', timeout: 30_000, stdio: 'pipe' })
|
||||
expect(output.trim()).toBe('function function')
|
||||
})
|
||||
|
||||
const repository = 'deepseek-harness/deepseek-harness'
|
||||
|
||||
function producerSnapshot(root: string) {
|
||||
const git = (...args: string[]): string => execFileSync('git', args, { cwd: root, encoding: 'utf8', stdio: 'pipe' })
|
||||
git('add', '-A')
|
||||
git('-c', `core.hooksPath=${join(root, 'no-hooks')}`, '-c', 'commit.gpgsign=false', '-c', 'user.name=Fixture',
|
||||
'-c', '[email protected]', 'commit', '--quiet', '-m', 'fixture')
|
||||
const commit = git('rev-parse', 'HEAD').trim()
|
||||
const tree = git('ls-tree', '-r', '-z', 'HEAD').split('\0').filter(Boolean).map((entry) => {
|
||||
const [metadata, path] = entry.split('\t')
|
||||
const [mode, type, sha] = (metadata ?? '').split(' ')
|
||||
if (!path || !mode || !type || !sha) throw new Error('Invalid Git fixture tree entry')
|
||||
return { path, mode, type, sha }
|
||||
})
|
||||
const response = { truncated: false, tree }
|
||||
const responses: Record<string, unknown> = { [`repos/${repository}/git/trees/${commit}?recursive=1`]: response }
|
||||
for (const entry of tree.filter(entry => entry.path === 'package.json')) {
|
||||
const bytes = execFileSync('git', ['cat-file', 'blob', entry.sha], { cwd: root, stdio: 'pipe' })
|
||||
responses[`repos/${repository}/git/blobs/${entry.sha}`] = { sha: entry.sha, encoding: 'base64', content: bytes.toString('base64') }
|
||||
}
|
||||
return { commit, response, responses, api: (path: string): unknown => {
|
||||
if (!(path in responses)) throw new Error(`Unexpected GitHub fixture request ${path}`)
|
||||
return responses[path]
|
||||
} }
|
||||
}
|
||||
|
||||
it('compares GitHub commit objects independently of artifact claims while allowing a root version bump', () => {
|
||||
const f = fixture()
|
||||
const previous = producerSnapshot(f.root)
|
||||
expect(cuaHelperSourceMatches(f.root, repository, previous.commit, previous.api)).toBe(true)
|
||||
writeFileSync(join(f.root, 'package.json'), JSON.stringify({ version: '2.0.0', packageManager: '[email protected]' }))
|
||||
writeFileSync(join(f.root, 'packages/client/unrelated/src/index.ts'), 'another unrelated feature')
|
||||
expect(cuaHelperSourceMatches(f.root, repository, previous.commit, previous.api)).toBe(true)
|
||||
writeFileSync(f.source, 'changed native code')
|
||||
expect(cuaHelperSourceMatches(f.root, repository, previous.commit, previous.api)).toBe(false)
|
||||
})
|
||||
|
||||
it.each(['helper workflow', 'publish workflow', 'packaging script', 'manifest lifecycle', 'npm config', 'patch', 'tracked dependency', 'deleted file'])(
|
||||
'rejects independent producer source proof after a changed %s', (change) => {
|
||||
const f = fixture()
|
||||
const previous = producerSnapshot(f.root)
|
||||
const digest = cuaHelperSourceDigest(f.root)
|
||||
if (change === 'helper workflow') writeFileSync(join(f.root, '.github/workflows/cua-helper-package.yml'), 'forged uploader')
|
||||
if (change === 'publish workflow') writeFileSync(join(f.root, '.github/workflows/release-publish.yml'), 'forged caller')
|
||||
if (change === 'packaging script') writeFileSync(join(f.root, 'scripts/cua-helper/package.ts'), 'forged metadata')
|
||||
if (change === 'manifest lifecycle') writeFileSync(join(f.root, 'package.json'), JSON.stringify({
|
||||
version: '1.0.0', packageManager: '[email protected]', scripts: { postinstall: 'unexpected code' },
|
||||
}))
|
||||
if (change === 'npm config') writeFileSync(join(f.root, '.npmrc'), 'node-options=--require=./unexpected.cjs')
|
||||
if (change === 'patch') {
|
||||
mkdirSync(join(f.root, 'patches'))
|
||||
writeFileSync(join(f.root, 'patches/dependency.patch'), 'changed package code')
|
||||
}
|
||||
if (change === 'tracked dependency') {
|
||||
mkdirSync(join(f.root, 'apps/desktop/node_modules/unexpected'), { recursive: true })
|
||||
writeFileSync(join(f.root, 'apps/desktop/node_modules/unexpected/index.js'), 'unexpected dependency code')
|
||||
f.git('add', '--force', 'apps/desktop/node_modules')
|
||||
}
|
||||
if (change === 'deleted file') rmSync(f.source)
|
||||
f.git('add', '-A')
|
||||
expect(cuaHelperSourceDigest(f.root)).not.toBe(digest)
|
||||
expect(cuaHelperSourceMatches(f.root, repository, previous.commit, previous.api)).toBe(false)
|
||||
},
|
||||
)
|
||||
|
||||
it('stops source comparison when GitHub returns an incomplete tree', () => {
|
||||
const f = fixture()
|
||||
const previous = producerSnapshot(f.root)
|
||||
previous.response.truncated = true
|
||||
expect(() => cuaHelperSourceMatches(f.root, repository, previous.commit, previous.api)).toThrow('incomplete commit tree')
|
||||
})
|
||||
|
||||
it.each(['test', 'production'])('computes the same %s build key through selection and packaging configuration readers', (preset) => {
|
||||
const f = fixture()
|
||||
const config = join(f.root, 'config')
|
||||
mkdirSync(join(config, 'presets'), { recursive: true })
|
||||
mkdirSync(join(config, 'secrets'))
|
||||
writeFileSync(join(config, 'presets', `${preset}.env`), `DSH_DESKTOP_AUTO_UPDATE_ENV=${preset}\n`)
|
||||
writeFileSync(join(config, 'secrets/signing.p12'), 'fixture certificate')
|
||||
writeFileSync(join(config, 'secrets/macos-signing.env'), [
|
||||
'CSC_LINK=./signing.p12', 'CSC_KEY_PASSWORD=fixture-password', 'DSH_DESKTOP_MACOS_TEAM_ID=ABCDEFGHIJ',
|
||||
'DSH_DESKTOP_MACOS_SIGNING_IDENTITY=Fixture (ABCDEFGHIJ)',
|
||||
].join('\n'))
|
||||
const environment = { DSH_PACKAGING_CONFIG_DIR: config, DSH_PACKAGING_PRESET: preset }
|
||||
const source = cuaHelperSourceDigest(f.root)
|
||||
const run = (_command: string, args: string[]): string => args.join(' ')
|
||||
expect(cuaHelperBuildKey(source, readCuaSigningSettings(environment), run))
|
||||
.toBe(cuaHelperBuildKey(source, loadDesktopPackageEnvironment('darwin', environment), run))
|
||||
})
|
||||
|
||||
// The fake gh uses a POSIX executable shim; the production workflow runs on macOS.
|
||||
it.skipIf(process.platform === 'win32').each(['match', 'miss', 'api failure', 'missing gh'])(
|
||||
'runs the plain-Node selector entry with %s and no node_modules directory', (scenario) => {
|
||||
const f = fixture()
|
||||
for (const file of ['scripts/cua-helper/build-inputs.ts', 'scripts/cua-helper/select-artifact.ts',
|
||||
'apps/desktop/scripts/desktop-file-settings.mjs', 'apps/desktop/scripts/desktop-release-environment.mjs']) {
|
||||
mkdirSync(dirname(join(f.root, file)), { recursive: true })
|
||||
copyFileSync(resolve(file), join(f.root, file))
|
||||
}
|
||||
const snapshot = producerSnapshot(f.root)
|
||||
const key = 'a'.repeat(64)
|
||||
const base = `repos/${repository}/actions/runs/123`
|
||||
Object.assign(snapshot.responses, {
|
||||
[base]: { run_attempt: 2 },
|
||||
[`${base}/attempts/2`]: { id: 123, run_attempt: 2, status: 'completed', conclusion: 'success',
|
||||
event: 'workflow_dispatch', path: '.github/workflows/cua-helper-package.yml', head_sha: snapshot.commit,
|
||||
repository: { full_name: repository }, head_repository: { full_name: repository } },
|
||||
[`${base}/jobs?filter=all&per_page=100`]: [{ jobs: [{ name: 'package', conclusion: 'success', run_attempt: 2 }] }],
|
||||
[`${base}/artifacts?per_page=100`]: [{ artifacts: scenario === 'match'
|
||||
? [{ id: 456, name: `cua-helper-123-2-${key}`, expired: false, size_in_bytes: 4096 }] : [] }],
|
||||
})
|
||||
const data = join(f.root, 'responses.json')
|
||||
writeFileSync(data, JSON.stringify(snapshot.responses))
|
||||
const bin = join(f.root, 'fake-bin')
|
||||
mkdirSync(bin)
|
||||
if (scenario !== 'missing gh') {
|
||||
writeFileSync(join(bin, 'gh'), `#!/usr/bin/env node\nconst fs=require('node:fs');
|
||||
if(process.env.FIXTURE_API_FAILURE==='1') { console.error('fixture API failure'); process.exit(1); }
|
||||
const path=process.argv.at(-1); const data=JSON.parse(fs.readFileSync(process.env.FIXTURE_API_DATA,'utf8'));
|
||||
if(path.includes('/workflows/')) console.log(JSON.stringify([{workflow_runs:path.includes('cua-helper-package.yml')?[{id:123}]:[]}]));
|
||||
else if(path in data) console.log(JSON.stringify(data[path])); else {console.error('unexpected path '+path);process.exit(1);}
|
||||
`, { mode: 0o755 })
|
||||
}
|
||||
const output = join(f.root, 'outputs')
|
||||
const summary = join(f.root, 'summary')
|
||||
const result = spawnSync(process.execPath, [join(f.root, 'scripts/cua-helper/select-artifact.ts')], {
|
||||
cwd: f.root, encoding: 'utf8', timeout: 60_000,
|
||||
env: { ...process.env, NODE_OPTIONS: '', PATH: scenario === 'missing gh' ? bin : `${bin}${delimiter}${process.env.PATH ?? ''}`,
|
||||
GITHUB_REPOSITORY: repository, GITHUB_OUTPUT: output, GITHUB_STEP_SUMMARY: summary, CUA_RUN_ID: '', CUA_BUILD_KEY: key,
|
||||
FIXTURE_API_DATA: data, FIXTURE_API_FAILURE: scenario === 'api failure' ? '1' : '0' },
|
||||
})
|
||||
expect(result.error).toBeUndefined()
|
||||
expect(result.signal).toBeNull()
|
||||
if (scenario === 'api failure' || scenario === 'missing gh') {
|
||||
expect(result.status).toBe(1)
|
||||
expect(result.stderr).toContain(scenario === 'missing gh' ? 'install GitHub CLI (gh)' : 'check token permissions')
|
||||
expect(existsSync(output)).toBe(false)
|
||||
expect(existsSync(summary)).toBe(false)
|
||||
} else {
|
||||
expect(result.status, result.stderr).toBe(0)
|
||||
expect(readFileSync(output, 'utf8')).toBe(scenario === 'match' ? 'artifact-id=456\nrun-id=123\n' : 'artifact-id=\nrun-id=\n')
|
||||
expect(readFileSync(summary, 'utf8')).toContain(scenario === 'match' ? '跳过依赖安装' : '未找到')
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -1,4 +1,5 @@
|
||||
/** Content and machine identity for reusing a signed helper before installing dependencies. */
|
||||
import assert from 'node:assert/strict'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { appendFileSync, lstatSync, readFileSync } from 'node:fs'
|
||||
@@ -6,37 +7,110 @@ import { isAbsolute, join, resolve } from 'node:path'
|
||||
import { readDesktopPackageSettings } from '../../apps/desktop/scripts/desktop-file-settings.mjs'
|
||||
import { resolveMacOSSigningEnvironment } from '../../apps/desktop/scripts/desktop-release-environment.mjs'
|
||||
|
||||
const sourcePaths = [
|
||||
'packages/experimental/cua-macos/native', 'scripts/cua-helper', 'apps/desktop/scripts',
|
||||
'.github/workflows/cua-helper-package.yml', 'pnpm-lock.yaml', 'pnpm-workspace.yaml',
|
||||
':(glob)tsconfig*.json',
|
||||
const sourceDirectories = [
|
||||
'packages/experimental/cua-macos/native', 'scripts/cua-helper', 'apps/desktop/scripts', 'patches',
|
||||
]
|
||||
const sourceFiles = new Set([
|
||||
'.github/workflows/cua-helper-package.yml', '.github/workflows/release-publish.yml',
|
||||
'package.json', 'scripts/package.json', 'apps/package.json', 'apps/desktop/package.json',
|
||||
'pnpm-lock.yaml', 'pnpm-workspace.yaml', '.npmrc', '.pnpmfile.cjs', '.pnpmfile.mjs',
|
||||
])
|
||||
|
||||
/**
|
||||
* Hash tracked build inputs by path, raw bytes and executable mode; product version and unrelated packages are excluded.
|
||||
* Missing tracked files and links fail; build outputs and untracked files never enter the digest.
|
||||
* @param root - Clean repository checkout containing all helper build inputs.
|
||||
* @returns SHA-256 of the helper sources, resources, packaging scripts and locked dependencies.
|
||||
*/
|
||||
export function cuaHelperSourceDigest(root: string): string {
|
||||
const files = execFileSync('git', ['ls-files', '-z', '--', ...sourcePaths], { cwd: root, encoding: 'utf8' })
|
||||
.split('\0').filter(Boolean).sort()
|
||||
for (const required of ['packages/experimental/cua-macos/native/Package.swift', 'scripts/cua-helper/package.ts', 'pnpm-lock.yaml']) {
|
||||
function isSourceFile(path: string): boolean {
|
||||
return sourceFiles.has(path) || /^(?:(?:apps|apps\/desktop|scripts)\/)?tsconfig[^/]*\.json$/u.test(path)
|
||||
|| path.split('/').includes('node_modules')
|
||||
|| sourceDirectories.some(directory => path.startsWith(`${directory}/`))
|
||||
}
|
||||
|
||||
function trackedSources(root: string): string[] {
|
||||
const files = execFileSync('git', ['ls-files', '-z'], { cwd: root, encoding: 'utf8' })
|
||||
.split('\0').filter(isSourceFile).sort()
|
||||
for (const required of ['packages/experimental/cua-macos/native/Package.swift', 'scripts/cua-helper/package.ts',
|
||||
'package.json', 'pnpm-lock.yaml']) {
|
||||
if (!files.includes(required)) throw new Error(`CUA source: missing tracked build input ${required}`)
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
function manifestConfiguration(bytes: Buffer, root: boolean): Buffer {
|
||||
const manifest: unknown = JSON.parse(bytes.toString('utf8'))
|
||||
assert(manifest && typeof manifest === 'object' && !Array.isArray(manifest), 'CUA source: invalid package manifest')
|
||||
assert(!root || ('packageManager' in manifest && typeof manifest.packageManager === 'string'),
|
||||
'CUA source: package.json must declare packageManager')
|
||||
return Buffer.from(JSON.stringify(Object.fromEntries(Object.entries(manifest).filter(([name]) => name !== 'version'))))
|
||||
}
|
||||
|
||||
function sourceFile(root: string, file: string): { bytes: Buffer; executable: boolean } {
|
||||
const path = join(root, file)
|
||||
const stat = lstatSync(path)
|
||||
if (!stat.isFile()) throw new Error(`CUA source: build input must be a regular file: ${file}`)
|
||||
return { bytes: readFileSync(path), executable: (stat.mode & 0o111) !== 0 }
|
||||
}
|
||||
|
||||
function gitBlobHash(bytes: Buffer): string {
|
||||
return createHash('sha1').update(`blob ${bytes.length}\0`).update(bytes).digest('hex')
|
||||
}
|
||||
|
||||
/**
|
||||
* Hash tracked build inputs by path, bytes and executable mode; only package manifest version fields is excluded.
|
||||
* Missing tracked files and links fail; build outputs and untracked files never enter the digest.
|
||||
* @param root - Clean repository root containing all helper build inputs.
|
||||
* @returns SHA-256 of sources, resources, workflows, package configuration, patches and locked dependencies.
|
||||
*/
|
||||
export function cuaHelperSourceDigest(root: string): string {
|
||||
const hash = createHash('sha256')
|
||||
for (const file of trackedSources(root)) {
|
||||
const { bytes, executable } = sourceFile(root, file)
|
||||
const input = file === 'package.json' || file.endsWith('/package.json') ? manifestConfiguration(bytes, file === 'package.json') : bytes
|
||||
hash.update(`${file}\0`).update(createHash('sha256').update(input).digest()).update(Buffer.from([Number(executable)]))
|
||||
}
|
||||
return hash.digest('hex')
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare a producer's immutable GitHub commit tree with local build inputs independently of artifact metadata.
|
||||
* Incomplete trees, unreadable blobs and API failures stop selection; content differences return false.
|
||||
* @param root - Consumer repository root, before dependency installation.
|
||||
* @param repository - GitHub repository containing the authenticated producer run.
|
||||
* @param commit - Producer head SHA returned by GitHub, never an artifact-supplied revision.
|
||||
* @param api - Read-only GitHub JSON reader.
|
||||
* @returns Whether all selected file paths, bytes and executable modes match, excluding product version fields in package manifests.
|
||||
*/
|
||||
export function cuaHelperSourceMatches(root: string, repository: string, commit: string,
|
||||
api: (path: string) => unknown): boolean {
|
||||
assert(/^[a-f0-9]{40}$/u.test(commit), 'CUA source: invalid producer commit')
|
||||
const response = api(`repos/${repository}/git/trees/${commit}?recursive=1`)
|
||||
assert(response && typeof response === 'object' && 'truncated' in response && response.truncated === false
|
||||
&& 'tree' in response && Array.isArray(response.tree), 'CUA source: GitHub returned an incomplete commit tree')
|
||||
const tree = new Map<string, { sha: string; mode: string }>()
|
||||
const entries: unknown[] = response.tree
|
||||
for (const value of entries) {
|
||||
assert(value && typeof value === 'object' && 'path' in value && typeof value.path === 'string', 'CUA source: invalid tree entry')
|
||||
if (!isSourceFile(value.path) || ('type' in value && value.type === 'tree')) continue
|
||||
assert('sha' in value && typeof value.sha === 'string' && /^[a-f0-9]{40}$/u.test(value.sha)
|
||||
&& 'mode' in value && typeof value.mode === 'string' && 'type' in value, 'CUA source: invalid source entry')
|
||||
if (value.type !== 'blob' || !['100644', '100755'].includes(value.mode)) return false
|
||||
assert(!tree.has(value.path), 'CUA source: duplicate source entry')
|
||||
tree.set(value.path, { sha: value.sha, mode: value.mode })
|
||||
}
|
||||
const files = trackedSources(root)
|
||||
if (tree.size !== files.length) return false
|
||||
for (const file of files) {
|
||||
const path = join(root, file)
|
||||
const stat = lstatSync(path)
|
||||
if (!stat.isFile()) throw new Error(`CUA source: build input must be a regular file: ${file}`)
|
||||
hash.update(`${file}\0`).update(createHash('sha256').update(readFileSync(path)).digest())
|
||||
.update(Buffer.from([(stat.mode & 0o111) === 0 ? 0 : 1]))
|
||||
const remote = tree.get(file)
|
||||
if (!remote) return false
|
||||
const local = sourceFile(root, file)
|
||||
if (remote.mode !== (local.executable ? '100755' : '100644')) return false
|
||||
if (gitBlobHash(local.bytes) === remote.sha) continue
|
||||
if (file !== 'package.json' && !file.endsWith('/package.json')) return false
|
||||
const blob = api(`repos/${repository}/git/blobs/${remote.sha}`)
|
||||
assert(blob && typeof blob === 'object' && 'sha' in blob && blob.sha === remote.sha
|
||||
&& 'encoding' in blob && blob.encoding === 'base64' && 'content' in blob && typeof blob.content === 'string',
|
||||
'CUA source: invalid package manifest blob')
|
||||
const bytes = Buffer.from(blob.content, 'base64')
|
||||
assert(gitBlobHash(bytes) === remote.sha, 'CUA source: package manifest blob digest mismatch')
|
||||
if (!manifestConfiguration(local.bytes, file === 'package.json').equals(manifestConfiguration(bytes, file === 'package.json'))) return false
|
||||
}
|
||||
const manifest: unknown = JSON.parse(readFileSync(join(root, 'package.json'), 'utf8'))
|
||||
if (!manifest || typeof manifest !== 'object' || !('packageManager' in manifest) || typeof manifest.packageManager !== 'string') {
|
||||
throw new Error('CUA source: package.json must declare packageManager')
|
||||
}
|
||||
return hash.update(`packageManager\0${manifest.packageManager}`).digest('hex')
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,7 +132,7 @@ export function readCuaSigningSettings(environment: NodeJS.ProcessEnv): NodeJS.P
|
||||
* Bind source bytes to the active toolchain, preset and signing certificate container.
|
||||
* @param source - Current source digest.
|
||||
* @param environment - File-owned signing settings including CSC_LINK and the selected preset.
|
||||
* @param run - Synchronous toolchain query; injected tests never invoke signing or Apple's services.
|
||||
* @param run - Synchronous query returning the active compiler, SDK and Python version strings.
|
||||
* @returns SHA-256 build key; credential values and certificate bytes are not recorded.
|
||||
*/
|
||||
export function cuaHelperBuildKey(source: string, environment: NodeJS.ProcessEnv,
|
||||
@@ -85,7 +159,7 @@ if (process.argv[1] !== undefined && resolve(process.argv[1]) === import.meta.fi
|
||||
const root = resolve(import.meta.dirname, '../..')
|
||||
const sourceDigest = cuaHelperSourceDigest(root)
|
||||
const buildKey = cuaHelperBuildKey(sourceDigest, readCuaSigningSettings(env))
|
||||
appendFileSync(env.GITHUB_OUTPUT, `source-digest=${sourceDigest}\nbuild-key=${buildKey}\n`)
|
||||
appendFileSync(env.GITHUB_OUTPUT, `build-key=${buildKey}\n`)
|
||||
appendFileSync(env.GITHUB_STEP_SUMMARY, `CUA helper 源码摘要:\`${sourceDigest}\`。\n\n`)
|
||||
console.log(`CUA helper source digest: ${sourceDigest}`)
|
||||
}
|
||||
@@ -104,4 +104,4 @@ async function main(): Promise<void> {
|
||||
journal.finish(true)
|
||||
}
|
||||
|
||||
await main()
|
||||
if (process.argv[1] !== undefined && resolve(process.argv[1]) === import.meta.filename) await main()
|
||||
@@ -8,8 +8,9 @@ const key = 'a'.repeat(64)
|
||||
|
||||
function fixture() {
|
||||
const run = { id: 123, run_attempt: 2, status: 'completed', conclusion: 'success', event: 'workflow_dispatch',
|
||||
path: '.github/workflows/cua-helper-package.yml', repository: { full_name: repository }, head_repository: { full_name: repository } }
|
||||
const jobs = [{ jobs: [{ name: 'package', conclusion: 'success' }] }]
|
||||
path: '.github/workflows/cua-helper-package.yml', head_sha: 'c'.repeat(40), repository: { full_name: repository }, head_repository: { full_name: repository } }
|
||||
const jobs = [{ jobs: [{ name: 'package', conclusion: 'success', run_attempt: 2 }] }]
|
||||
const matchesSource = vi.fn((_commit: string) => true)
|
||||
const artifact = { id: 456, name: `cua-helper-123-2-${key}`, expired: false, size_in_bytes: 4096 }
|
||||
const artifacts = [{ artifacts: [{ ...artifact, id: 455, name: `cua-helper-123-1-${key}` }] }, { artifacts: [artifact] }]
|
||||
const api = vi.fn((path: string, paginate?: boolean) => {
|
||||
@@ -18,16 +19,16 @@ function fixture() {
|
||||
expect(paginate).toBe(true)
|
||||
if (path.includes('/workflows/cua-helper-package.yml/runs?')) return [{ workflow_runs: [{ id: 123 }] }]
|
||||
if (path.includes('/workflows/release-publish.yml/runs?')) return [{ workflow_runs: [] }]
|
||||
if (path === `${base}/attempts/2/jobs?per_page=100`) return jobs
|
||||
if (path === `${base}/jobs?filter=all&per_page=100`) return jobs
|
||||
if (path === `${base}/artifacts?per_page=100`) return artifacts
|
||||
throw new Error(`Unexpected GitHub request ${path}`)
|
||||
})
|
||||
return { run, jobs, artifact, artifacts, api }
|
||||
return { run, jobs, artifact, artifacts, api, matchesSource }
|
||||
}
|
||||
|
||||
it.each(['123', ''])('selects a matching artifact with run ID %j and pins the latest attempt', (runId) => {
|
||||
const f = fixture()
|
||||
expect(selectCuaHelperArtifact(repository, runId, key, f.api))
|
||||
expect(selectCuaHelperArtifact(repository, runId, key, f.api, f.matchesSource))
|
||||
.toEqual({ runId: '123', attempt: '2', artifactId: '456' })
|
||||
expect(f.api.mock.calls.filter(([path]) => path === base)).toHaveLength(1)
|
||||
expect(f.api.mock.calls.some(([path]) => path.includes('/workflows/'))).toBe(runId === '')
|
||||
@@ -37,21 +38,21 @@ it('allows successful helper packaging when later npm publication failed', () =>
|
||||
const f = fixture()
|
||||
f.run.path = '.github/workflows/release-publish.yml'
|
||||
f.run.conclusion = 'failure'
|
||||
f.jobs[0]!.jobs = [{ name: 'cua-helper / package', conclusion: 'success' }, { name: 'Publish to npm', conclusion: 'failure' }]
|
||||
expect(selectCuaHelperArtifact(repository, '123', key, f.api)?.artifactId).toBe('456')
|
||||
f.jobs[0]!.jobs = [{ name: 'cua-helper / package', conclusion: 'success', run_attempt: 2 }, { name: 'Publish to npm', conclusion: 'failure', run_attempt: 2 }]
|
||||
expect(selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)?.artifactId).toBe('456')
|
||||
})
|
||||
|
||||
it.each(['123/other', ' 123', '0', '-1', '2\nartifact-id=9', 'https://github.com/owner/repo/actions/runs/123'])(
|
||||
'rejects invalid run ID %j before reading GitHub', (runId) => {
|
||||
const f = fixture()
|
||||
expect(() => selectCuaHelperArtifact(repository, runId, key, f.api)).toThrow('numeric run ID')
|
||||
expect(() => selectCuaHelperArtifact(repository, runId, key, f.api, f.matchesSource)).toThrow('numeric run ID')
|
||||
expect(f.api).not.toHaveBeenCalled()
|
||||
},
|
||||
)
|
||||
|
||||
it.each(['wrong/repo/extra', '../repo', 'owner/..', 'owner/.'])('rejects invalid repository %s before reading GitHub', (repo) => {
|
||||
const f = fixture()
|
||||
expect(() => selectCuaHelperArtifact(repo, '123', key, f.api)).toThrow('invalid repository')
|
||||
expect(() => selectCuaHelperArtifact(repo, '123', key, f.api, f.matchesSource)).toThrow('invalid repository')
|
||||
expect(f.api).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
@@ -66,7 +67,7 @@ it.each(['workflow', 'event', 'repository', 'head_repository', 'id', 'attempt',
|
||||
if (change === 'attempt') f.run.run_attempt = 1
|
||||
if (change === 'running') f.run.status = 'in_progress'
|
||||
if (change === 'failed') f.run.conclusion = 'failure'
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api)).toThrow()
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).toThrow()
|
||||
expect(f.api.mock.calls.some(([path]) => path.includes('/artifacts'))).toBe(false)
|
||||
},
|
||||
)
|
||||
@@ -77,9 +78,9 @@ it.each(['failure', 'cancelled', 'skipped', 'missing', 'duplicate'])(
|
||||
f.run.path = '.github/workflows/release-publish.yml'
|
||||
f.run.conclusion = 'failure'
|
||||
f.jobs[0]!.jobs = status === 'missing' ? [] : status === 'duplicate'
|
||||
? [{ name: 'cua-helper / package', conclusion: 'success' }, { name: 'cua-helper / package', conclusion: 'success' }]
|
||||
: [{ name: 'cua-helper / package', conclusion: status }]
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api)).toThrow('successful cua-helper / package job')
|
||||
? [{ name: 'cua-helper / package', conclusion: 'success', run_attempt: 2 }, { name: 'cua-helper / package', conclusion: 'success', run_attempt: 2 }]
|
||||
: [{ name: 'cua-helper / package', conclusion: status, run_attempt: 2 }]
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).toThrow('last executed cua-helper / package job did not succeed')
|
||||
expect(f.api.mock.calls.some(([path]) => path.includes('/attempts/1') || path.includes('/artifacts'))).toBe(false)
|
||||
},
|
||||
)
|
||||
@@ -92,8 +93,8 @@ it.each(['missing', 'expired', 'empty', 'mismatch', 'legacy'] as const)(
|
||||
if (change === 'empty') f.artifact.size_in_bytes = 0
|
||||
if (change === 'mismatch') f.artifact.name = `cua-helper-123-2-${'b'.repeat(64)}`
|
||||
if (change === 'legacy') f.artifact.name = 'cua-helper-123-2'
|
||||
expect(selectCuaHelperArtifact(repository, '', key, f.api)).toBeUndefined()
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api)).toThrow('CUA reuse: run 123:')
|
||||
expect(selectCuaHelperArtifact(repository, '', key, f.api, f.matchesSource)).toBeUndefined()
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).toThrow('CUA reuse: run 123:')
|
||||
},
|
||||
)
|
||||
|
||||
@@ -107,7 +108,7 @@ it('selects a match across workflows and pages after a newer failed producer', (
|
||||
if (path.endsWith('/runs/124/attempts/1')) return { ...f.run, id: 124, run_attempt: 1, conclusion: 'failure' }
|
||||
return f.api(path, paginate)
|
||||
})
|
||||
expect(selectCuaHelperArtifact(repository, '', key, api, new Date('2026-11-03T00:00:00Z'))?.runId).toBe('123')
|
||||
expect(selectCuaHelperArtifact(repository, '', key, api, f.matchesSource, new Date('2026-11-03T00:00:00Z'))?.runId).toBe('123')
|
||||
const paths = api.mock.calls.map(([path]) => path)
|
||||
expect(paths.find(path => path.includes('/workflows/'))).toContain(encodeURIComponent('>=2026-10-20T00:00:00.000Z'))
|
||||
expect(paths.indexOf(`${base.replace('123', '124')}/attempts/1`)).toBeLessThan(paths.indexOf(base))
|
||||
@@ -118,12 +119,12 @@ it.each(['duplicate', 'invalid metadata'] as const)('stops automatic discovery o
|
||||
if (change === 'duplicate') f.artifacts.push({ artifacts: [{ ...f.artifact, id: 457 }] })
|
||||
const api = (path: string, paginate?: boolean): unknown => change === 'invalid metadata' && path.endsWith('/artifacts?per_page=100')
|
||||
? [{ artifacts: [{ ...f.artifact, expired: 'false' }] }] : f.api(path, paginate)
|
||||
expect(() => selectCuaHelperArtifact(repository, '', key, api)).toThrow()
|
||||
expect(() => selectCuaHelperArtifact(repository, '', key, api, f.matchesSource)).toThrow()
|
||||
})
|
||||
|
||||
it.each(['', '123'])('propagates unavailable GitHub evidence with selection %j', (runId) => {
|
||||
const api = vi.fn(() => { throw new Error('HTTP 403') })
|
||||
expect(() => selectCuaHelperArtifact(repository, runId, key, api)).toThrow('HTTP 403')
|
||||
expect(() => selectCuaHelperArtifact(repository, runId, key, api, () => true)).toThrow('HTTP 403')
|
||||
expect(api).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
@@ -131,7 +132,41 @@ it('does not query job or attempt details when artifact names exclude the reques
|
||||
const f = fixture()
|
||||
f.artifact.name = 'cua-helper-123-2-legacy'
|
||||
f.artifacts.shift()
|
||||
expect(selectCuaHelperArtifact(repository, '', key, f.api)).toBeUndefined()
|
||||
expect(selectCuaHelperArtifact(repository, '', key, f.api, f.matchesSource)).toBeUndefined()
|
||||
expect(f.api.mock.calls.map(([path]) => path).filter(path => !path.includes('/workflows/')))
|
||||
.toEqual([`${base}/artifacts?per_page=100`])
|
||||
})
|
||||
|
||||
it.each(['123', ''])('retains the original helper after a publish-only rerun with selection %j', (runId) => {
|
||||
const f = fixture()
|
||||
f.run.path = '.github/workflows/release-publish.yml'
|
||||
f.jobs[0]!.jobs = [{ name: 'cua-helper / package', conclusion: 'success', run_attempt: 1 },
|
||||
{ name: 'Publish to npm', conclusion: 'success', run_attempt: 2 }]
|
||||
f.artifacts.pop()
|
||||
expect(selectCuaHelperArtifact(repository, runId, key, f.api, f.matchesSource))
|
||||
.toEqual({ runId: '123', attempt: '1', artifactId: '455' })
|
||||
expect(f.matchesSource).toHaveBeenCalledExactlyOnceWith(f.run.head_sha)
|
||||
})
|
||||
|
||||
it('does not reuse an older successful helper after a newer helper execution failed', () => {
|
||||
const f = fixture()
|
||||
f.run.path = '.github/workflows/release-publish.yml'
|
||||
f.jobs[0]!.jobs = [{ name: 'cua-helper / package', conclusion: 'success', run_attempt: 1 },
|
||||
{ name: 'cua-helper / package', conclusion: 'failure', run_attempt: 2 }]
|
||||
expect(selectCuaHelperArtifact(repository, '', key, f.api, f.matchesSource)).toBeUndefined()
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).toThrow('did not succeed')
|
||||
expect(f.matchesSource).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('rejects forged artifact keys when independent producer source evidence differs', () => {
|
||||
const f = fixture()
|
||||
f.matchesSource.mockReturnValue(false)
|
||||
expect(selectCuaHelperArtifact(repository, '', key, f.api, f.matchesSource)).toBeUndefined()
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).toThrow('producer commit')
|
||||
})
|
||||
|
||||
it('stops when a new attempt appears during selection', () => {
|
||||
const f = fixture()
|
||||
f.jobs[0]!.jobs[0]!.run_attempt = 3
|
||||
expect(() => selectCuaHelperArtifact(repository, '123', key, f.api, f.matchesSource)).toThrow('run advanced')
|
||||
})
|
||||
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { appendFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import { cuaHelperSourceMatches } from './build-inputs.ts'
|
||||
|
||||
const workflows = ['cua-helper-package.yml', 'release-publish.yml'] as const
|
||||
|
||||
@@ -33,17 +34,19 @@ export interface CuaHelperSelection {
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a matching helper from the latest attempt of an explicit run, or recent completed producer runs.
|
||||
* Select the last executed helper job, preserving its producer attempt across pack/publish-only reruns.
|
||||
* Automatic misses rebuild; explicit misses and unreadable GitHub evidence fail without selecting another run.
|
||||
* @param repository - Same repository that owns the producer and consumer.
|
||||
* @param runId - Optional decimal run ID; empty selects automatic discovery.
|
||||
* @param buildKey - Source and machine configuration digest required by the consumer.
|
||||
* @param api - Read-only GitHub JSON reader; paginated responses are arrays of pages.
|
||||
* @param matchesSource - Independent comparison of the producer head SHA with the consuming build inputs.
|
||||
* @param now - Discovery time; automatic search covers the artifact's 14-day retention window.
|
||||
* @returns Matching producer artifact, or undefined when automatic discovery has no match.
|
||||
*/
|
||||
export function selectCuaHelperArtifact(repository: string, runId: string, buildKey: string,
|
||||
api: (path: string, paginate?: boolean) => unknown, now = new Date()): CuaHelperSelection | undefined {
|
||||
api: (path: string, paginate?: boolean) => unknown, matchesSource: (commit: string) => boolean,
|
||||
now = new Date()): CuaHelperSelection | undefined {
|
||||
assert(/^[\w.-]+\/[\w.-]+$/u.test(repository) && !repository.split('/').some(part => part === '.' || part === '..'),
|
||||
'CUA reuse: invalid repository')
|
||||
assert(runId === '' || /^[1-9]\d*$/u.test(runId), 'CUA reuse: enter the numeric run ID after /actions/runs/ in the run URL')
|
||||
@@ -60,10 +63,14 @@ export function selectCuaHelperArtifact(repository: string, runId: string, build
|
||||
if (run.status !== 'completed') return 'the latest attempt has not completed'
|
||||
if (workflow === 'cua-helper-package.yml' && run.conclusion !== 'success') return 'the latest packaging attempt did not succeed'
|
||||
const jobName = workflow === 'cua-helper-package.yml' ? 'package' : 'cua-helper / package'
|
||||
const jobs = rows(api(`${base}/runs/${candidate}/attempts/${attempt}/jobs?per_page=100`, true), 'jobs')
|
||||
const jobs = rows(api(`${base}/runs/${candidate}/jobs?filter=all&per_page=100`, true), 'jobs')
|
||||
.filter(job => job.name === jobName)
|
||||
if (jobs.length !== 1 || jobs[0]?.conclusion !== 'success') return `the latest attempt has no successful ${jobName} job`
|
||||
const name = `cua-helper-${candidate}-${attempt}-${buildKey}`
|
||||
const attempts = jobs.map(job => Number(id(job.run_attempt)))
|
||||
assert(attempts.every(value => value <= Number(attempt)), 'CUA reuse: run advanced during selection; retry with the same run ID')
|
||||
const producerAttempt = Math.max(0, ...attempts)
|
||||
const producers = jobs.filter(job => job.run_attempt === producerAttempt)
|
||||
if (producers.length !== 1 || producers[0]?.conclusion !== 'success') return `the last executed ${jobName} job did not succeed`
|
||||
const name = `cua-helper-${candidate}-${producerAttempt}-${buildKey}`
|
||||
const artifacts = (retained ?? rows(api(`${base}/runs/${candidate}/artifacts?per_page=100`, true), 'artifacts'))
|
||||
.filter(artifact => artifact.name === name)
|
||||
if (artifacts.length === 0) return 'no artifact matches the current source bytes and build configuration; use the producer run linked in its summary or rebuild'
|
||||
@@ -71,7 +78,9 @@ export function selectCuaHelperArtifact(repository: string, runId: string, build
|
||||
assert(artifacts.length === 1 && artifact !== undefined, 'CUA reuse: matching artifact is ambiguous')
|
||||
assert(typeof artifact.expired === 'boolean' && typeof artifact.size_in_bytes === 'number', 'CUA reuse: invalid artifact metadata')
|
||||
if (artifact.expired || artifact.size_in_bytes <= 0) return 'the matching artifact is expired or empty'
|
||||
return { runId: candidate, attempt, artifactId: id(artifact.id) }
|
||||
assert(typeof run.head_sha === 'string' && /^[a-f0-9]{40}$/u.test(run.head_sha), 'CUA reuse: invalid producer head SHA')
|
||||
if (!matchesSource(run.head_sha)) return 'the producer commit has different helper build inputs'
|
||||
return { runId: candidate, attempt: String(producerAttempt), artifactId: id(artifact.id) }
|
||||
}
|
||||
if (runId !== '') {
|
||||
const selected = selectRun(runId)
|
||||
@@ -94,18 +103,39 @@ export function selectCuaHelperArtifact(repository: string, runId: string, build
|
||||
return undefined
|
||||
}
|
||||
|
||||
function githubJson(path: string, paginate = false): unknown {
|
||||
let output: string
|
||||
try {
|
||||
output = execFileSync('gh', ['api', ...(paginate ? ['--paginate', '--slurp'] : []), path],
|
||||
{ encoding: 'utf8', timeout: 60_000, maxBuffer: 32 * 1024 * 1024 })
|
||||
} catch (error) {
|
||||
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
||||
throw new Error('CUA reuse: install GitHub CLI (gh) on the Mac runner PATH, then retry this workflow')
|
||||
}
|
||||
throw new Error('CUA reuse: GitHub lookup failed; check token permissions, rate limits and connectivity, then retry this workflow', { cause: error })
|
||||
}
|
||||
return JSON.parse(output)
|
||||
}
|
||||
|
||||
if (process.argv[1] !== undefined && resolve(process.argv[1]) === import.meta.filename) {
|
||||
const env = process.env
|
||||
if (!env.GITHUB_REPOSITORY || !env.GITHUB_OUTPUT || !env.GITHUB_STEP_SUMMARY || !env.CUA_BUILD_KEY) {
|
||||
throw new Error('CUA reuse: Actions context and CUA_BUILD_KEY are required')
|
||||
}
|
||||
const buildKey = env.CUA_BUILD_KEY
|
||||
const selection = selectCuaHelperArtifact(env.GITHUB_REPOSITORY, env.CUA_RUN_ID ?? '', buildKey, (path, paginate) =>
|
||||
JSON.parse(execFileSync('gh', ['api', ...(paginate ? ['--paginate', '--slurp'] : []), path],
|
||||
{ encoding: 'utf8', timeout: 60_000, maxBuffer: 8 * 1024 * 1024 })))
|
||||
appendFileSync(env.GITHUB_OUTPUT, `artifact-id=${selection?.artifactId ?? ''}\nrun-id=${selection?.runId ?? ''}\nattempt=${selection?.attempt ?? ''}\n`)
|
||||
const repository = env.GITHUB_REPOSITORY
|
||||
const root = resolve(import.meta.dirname, '../..')
|
||||
const sourceMatches = new Map<string, boolean>()
|
||||
const selection = selectCuaHelperArtifact(repository, env.CUA_RUN_ID ?? '', env.CUA_BUILD_KEY, githubJson, (commit) => {
|
||||
let matches = sourceMatches.get(commit)
|
||||
if (matches === undefined) {
|
||||
matches = cuaHelperSourceMatches(root, repository, commit, githubJson)
|
||||
sourceMatches.set(commit, matches)
|
||||
}
|
||||
return matches
|
||||
})
|
||||
appendFileSync(env.GITHUB_OUTPUT, `artifact-id=${selection?.artifactId ?? ''}\nrun-id=${selection?.runId ?? ''}\n`)
|
||||
const summary = selection
|
||||
? `复用 [CUA helper 构建](https://github.com/${env.GITHUB_REPOSITORY}/actions/runs/${selection.runId}/attempts/${selection.attempt}),run ID \`${selection.runId}\`,artifact ID \`${selection.artifactId}\`。跳过依赖安装、编译、签名和公证。`
|
||||
? `复用 [CUA helper 构建](https://github.com/${repository}/actions/runs/${selection.runId}/attempts/${selection.attempt}),run ID \`${selection.runId}\`,artifact ID \`${selection.artifactId}\`。跳过依赖安装、编译、签名和公证。`
|
||||
: '未找到源码逐字节一致且构建配置匹配的可用 CUA helper 产物,执行依赖安装和重新构建。'
|
||||
appendFileSync(env.GITHUB_STEP_SUMMARY, `${summary}\n`)
|
||||
console.log(summary)
|
||||
|
||||
@@ -8,7 +8,7 @@ import { verifyCuaHelperPayload } from './payload.ts'
|
||||
/**
|
||||
* Verify both helper applications in the exact provider tarball being published.
|
||||
* @param tarball - pnpm-produced provider package archive.
|
||||
* @param expected - Product version and source commit of the publishing checkout.
|
||||
* @param expected - Helper source digest of the publishing checkout.
|
||||
* @returns Resolves only when the archive has complete, digest-verified application generations.
|
||||
*/
|
||||
export async function verifyCuaHelperTarball(tarball: string, expected: { sourceDigest: string }): Promise<void> {
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { setTimeout as sleep } from 'node:timers/promises'
|
||||
import { afterEach, beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest'
|
||||
import { attempt, attemptEchoed, type CommandResult } from './process.ts'
|
||||
import { publishRelease } from './publish.ts'
|
||||
import { cuaHelperSourceDigest } from '../cua-helper/build-inputs.ts'
|
||||
import { verifyCuaHelperTarball } from '../cua-helper/verify-tarball.ts'
|
||||
import { packedIdentity, readPublishOrder } from './tarball.ts'
|
||||
|
||||
vi.mock('./process.ts', async importOriginal => ({
|
||||
@@ -23,6 +25,8 @@ vi.mock('./tarball.ts', async importOriginal => ({
|
||||
readPublishOrder: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('../cua-helper/verify-tarball.ts', () => ({ verifyCuaHelperTarball: vi.fn() }))
|
||||
|
||||
vi.mock('node:timers/promises', async importOriginal => ({
|
||||
...await importOriginal<typeof import('node:timers/promises')>(),
|
||||
setTimeout: vi.fn(),
|
||||
@@ -310,3 +314,18 @@ describe('release publication channels', () => {
|
||||
expect(attemptEchoed).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
it('verifies helper sources from the repository root when publication is invoked from a subdirectory', async () => {
|
||||
const fixture = packedRelease(['1.0.0'])
|
||||
vi.mocked(packedIdentity).mockReturnValue({ name: '@deepseek-ai/dsh-experimental-cua-macos', version: '1.0.0' })
|
||||
vi.mocked(verifyCuaHelperTarball).mockResolvedValue(undefined)
|
||||
registry()
|
||||
const root = resolve(import.meta.dirname, '../..')
|
||||
const sourceDigest = cuaHelperSourceDigest(root)
|
||||
const cwd = vi.spyOn(process, 'cwd').mockReturnValue(join(root, 'scripts'))
|
||||
try {
|
||||
await publishRelease('dsh', fixture.directory)
|
||||
expect(verifyCuaHelperTarball).toHaveBeenCalledExactlyOnceWith(fixture.packages[0]!.path, { sourceDigest })
|
||||
expect(attemptEchoed).toHaveBeenCalledOnce()
|
||||
} finally { cwd.mockRestore() }
|
||||
})
|
||||
@@ -188,7 +188,7 @@ export async function publishRelease(familyId: string, directory: string, distTa
|
||||
})
|
||||
for (const member of order) {
|
||||
if (member.name !== '@deepseek-ai/dsh-experimental-cua-macos') continue
|
||||
await verifyCuaHelperTarball(member.tarball, { sourceDigest: cuaHelperSourceDigest(process.cwd()) })
|
||||
await verifyCuaHelperTarball(member.tarball, { sourceDigest: cuaHelperSourceDigest(resolve(import.meta.dirname, '../..')) })
|
||||
}
|
||||
if (distTag !== undefined) {
|
||||
for (const member of order) verifyDistTag(member, distTag)
|
||||
|
||||
@@ -231,6 +231,8 @@ it('skips installation and signing on a helper match and exports the original pr
|
||||
|| step.name === 'Install locked dependencies' || step.name === 'Build and verify notarized applications'
|
||||
|| step.uses === 'actions/[email protected]')
|
||||
expect(expensive).toHaveLength(4)
|
||||
expect(job.steps.find(step => step.name === 'Install locked dependencies')?.run)
|
||||
.toBe('pnpm install --frozen-lockfile --ignore-scripts --ignore-pnpmfile')
|
||||
for (const step of expensive) {
|
||||
expect(job.steps.indexOf(select)).toBeLessThan(job.steps.indexOf(step))
|
||||
expect(evaluate(step.if!, { 'steps.retained.outputs.artifact-id': '456' })).toBe(false)
|
||||
|
||||
Reference in new issue
Block a user