fix(release): validate an admitted channel request once per process
channelBuildRequest re-ran the authoritative Python validator (a fresh interpreter importing hermes_cli.release_channels and scripts.bundles.desktop_prepare) on every call, including repeated calls with byte-identical request JSON. verifyBundleStamp admits the channel request on each call, so the tests-js "channel smoke binds the complete admitted request" test started 59 Python interpreters; on a loaded runner that alone passed its 15 s budget (CI run 45707403899: 17.2 s, timed out on a PR with no JS changes). Remember the exact (interpreter, request bytes) pairs the validator accepted in this process and skip only those repeats. Rejections are never cached, and every distinct request (and every fresh CLI process) is still validated. Measured locally, tests-js/bundle-smoke-metadata.test.mjs, channel smoke test: idle: 3426 ms -> 811 ms taskset -c 0 + 4 cpu0 spinners: 16705-18642 ms (timeout) -> 3708 ms The new contract test proves one validator run per distinct accepted request and one per rejected attempt; it fails on the base (2 runs for 2 identical admissions).
This commit is contained in:
@@ -8,6 +8,12 @@ import { createRequire } from 'node:module'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
|
||||
// Exact request bytes (per interpreter) the authoritative validator accepted in
|
||||
// this process. A build and its smoke verifier admit one request many times;
|
||||
// each spawn starts a Python interpreter, so re-validating identical bytes
|
||||
// multiplies cost without adding a check. Rejections are never cached.
|
||||
const admittedChannelRequests = new Set()
|
||||
|
||||
/** Build-only structured bridge; never read by the installed runtime.
|
||||
* @param {NodeJS.ProcessEnv} [env]
|
||||
* @returns {import('../apps/desktop/electron/install-stamp.js').ChannelBuildRequest | null}
|
||||
@@ -26,9 +32,14 @@ export function channelBuildRequest(env = process.env) {
|
||||
'from scripts.bundles.desktop_prepare import validate_channel_request',
|
||||
'validate_channel_request(decode_json(sys.stdin.buffer.read()))'
|
||||
].join('; ')
|
||||
execFileSync(env.HERMES_PYTHON || 'python', ['-I', '-S', '-c', validator, path.resolve(import.meta.dirname, '..')], {
|
||||
env, input: env._HERMES_CHANNEL_REQUEST_JSON, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 30_000
|
||||
})
|
||||
const python = env.HERMES_PYTHON || 'python'
|
||||
const admitted = JSON.stringify([python, env._HERMES_CHANNEL_REQUEST_JSON])
|
||||
if (!admittedChannelRequests.has(admitted)) {
|
||||
execFileSync(python, ['-I', '-S', '-c', validator, path.resolve(import.meta.dirname, '..')], {
|
||||
env, input: env._HERMES_CHANNEL_REQUEST_JSON, encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'], timeout: 30_000
|
||||
})
|
||||
admittedChannelRequests.add(admitted)
|
||||
}
|
||||
if (env.HERMES_PAYLOAD_VERSION && env.HERMES_PAYLOAD_VERSION !== value.version) throw new Error('Channel package version conflicts with prepared request')
|
||||
Object.freeze(value.identity)
|
||||
Object.freeze(value.bundleEnv)
|
||||
|
||||
@@ -7,7 +7,7 @@ import { bundleIdentity, shouldVerifyMacDmg, verifyBundleStamp, verifyMacDmg, ve
|
||||
import { stampAssertions } from '../tests/install/e2e-assets/mac-bundled-manifest.cjs'
|
||||
import { randomBytes } from 'node:crypto'
|
||||
import { buildStampPayload } from '../apps/desktop/scripts/write-build-stamp.mjs'
|
||||
import { releaseVersion } from '../scripts/msix-shared.mjs'
|
||||
import { channelBuildRequest, releaseVersion } from '../scripts/msix-shared.mjs'
|
||||
|
||||
const commit = 'a'.repeat(40)
|
||||
|
||||
@@ -112,6 +112,33 @@ test('channel smoke binds the complete admitted request, not a commit-build iden
|
||||
} finally { fs.rmSync(temp, { recursive: true, force: true }) }
|
||||
}, 15_000)
|
||||
|
||||
test.skipIf(process.platform === 'win32')('channel admission validates each distinct request once and re-checks every rejection', () => {
|
||||
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'channel-admit-'))
|
||||
try {
|
||||
const log = path.join(temp, 'calls'), python = path.join(temp, 'python')
|
||||
fs.writeFileSync(python, `#!/bin/sh\necho x >> '${log}'\nexec python "$@"\n`, { mode: 0o755 })
|
||||
const calls = () => fs.existsSync(log) ? fs.readFileSync(log, 'utf8').split('\n').filter(Boolean).length : 0
|
||||
const token = randomBytes(8).toString('hex')
|
||||
const request = { schema: 1, buildId: randomBytes(16).toString('hex'), channel: `smoke-${token}`,
|
||||
repository: 'NousResearch/hermes-agent', publicBase: 'https://releases.example.test', commit,
|
||||
sourceVersion: '1.2.3', sequence: 1, version: '0.0.1', windowsVersion: '0.0.1.0', bundleEnv: {},
|
||||
identity: { token, displayName: 'Smoke Channel', appId: `com.example.preview-${token}`,
|
||||
appNamePascal: `Smoke${token}`, artifactNamePascal: `Artifact${token}`,
|
||||
msixAppIdWithOrg: `Example.Smoke${token}`, cliName: `smoke-${token}`, windowsExecutableName: `smoke-${token}` } }
|
||||
const admit = value => channelBuildRequest({ HERMES_PYTHON: python, HERMES_DESKTOP_VARIANT: 'bundled',
|
||||
PATH: process.env.PATH, _HERMES_CHANNEL_REQUEST_JSON: JSON.stringify(value) })
|
||||
expect(admit(request)).toEqual(request)
|
||||
expect(admit(request)).toEqual(request)
|
||||
expect(calls()).toBe(1)
|
||||
const insecure = { ...request, publicBase: 'http://releases.example.test' }
|
||||
expect(() => admit(insecure)).toThrow()
|
||||
expect(() => admit(insecure)).toThrow()
|
||||
expect(calls()).toBe(3)
|
||||
expect(admit({ ...request, buildId: randomBytes(16).toString('hex') }).channel).toBe(request.channel)
|
||||
expect(calls()).toBe(4)
|
||||
} finally { fs.rmSync(temp, { recursive: true, force: true }) }
|
||||
})
|
||||
|
||||
test('workspace admission rejects reuse and symlink escapes before creating anything outside runner temp', () => {
|
||||
const temp = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'smoke-paths-')))
|
||||
const cli = path.resolve(import.meta.dirname, '../tests/install/e2e-assets/bundle-smoke-metadata.mjs')
|
||||
|
||||
Reference in New Issue
Block a user