Files
hermes-agent/tests-js/setup-pm-post.test.mjs
ethernet db3ac3ea00 fix(ci): the PM cache prune reads its lock-source input under the runner's real name
The runner maps a hyphenated input to INPUT_LOCK-SOURCE, not INPUT_LOCK_SOURCE.
The registration step read the underscored name, saw nothing, and threw
"invalid lockSource" from every job that composed setup-pm, so the whole CI
run failed before any consumer ran. The unit test used the same wrong
spelling, which is why it stayed green; it now drives the real mapping.
2026-09-19 01:38:09 -04:00

35 lines
1.5 KiB
JavaScript

import { mkdtempSync, readFileSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, expect, it, vi } from 'vitest'
import { run } from '../.github/actions/setup-pm/prune/index.mjs'
const directories = []
afterEach(() => {
for (const path of directories.splice(0)) rmSync(path, { recursive: true, force: true })
})
it('prunes the saved uv cache to the lock at teardown, never during registration', () => {
const directory = mkdtempSync(join(tmpdir(), 'pm-post-'))
directories.push(directory)
const state = join(directory, 'state')
const execute = vi.fn(() => ({ status: 0 }))
const cache = join(directory, 'cache with spaces')
const python = join(directory, 'prepared Python')
const lockSource = join(directory, 'checkout')
run({ GITHUB_STATE: state, INPUT_PYTHON: python, INPUT_CACHE: cache, 'INPUT_LOCK-SOURCE': lockSource }, execute)
expect(execute).not.toHaveBeenCalled()
const saved = Object.fromEntries(readFileSync(state, 'utf8').trim().split('\n').map(line => {
const index = line.indexOf('=')
return [`STATE_${line.slice(0, index)}`, line.slice(index + 1)]
}))
run({ ...saved, UV_CACHE_DIR: 'a later unrelated cache' }, execute)
expect(execute).toHaveBeenCalledWith(python, ['-m', 'pm.build_env', '--exact-lock', '--cache', cache, '--lock-source', lockSource], expect.objectContaining({
env: expect.objectContaining(saved),
stdio: 'inherit',
}))
execute.mockReturnValueOnce({ status: 1 })
expect(() => run(saved, execute)).toThrow('PM cache prune failed')
})