fix: accept equivalent remote runtime lock formatting

This commit is contained in:
mesalogo
2026-09-09 11:29:37 +08:00
parent e35ea7692f
commit 5782667a40
2 changed files with 17 additions and 10 deletions
@@ -102,6 +102,21 @@ describe('remote Runtime verification metadata loader', () => {
}) })
}) })
it('canonicalizes equivalent Runtime lock formatting', async () => {
const fixture = await createFixture()
await writeFile(
fixture.paths.runtimeLockPath,
JSON.stringify(runtimeLock)
)
await expect(
loadRemoteRuntimeVerificationMetadata(fixture.paths)
).resolves.toMatchObject({
runtimeLock,
canonicalRemoteRuntimeLockBytes: canonical(runtimeLock)
})
})
it.each([ it.each([
{ bytes: Buffer.from('not json\n'), error: 'invalid JSON' }, { bytes: Buffer.from('not json\n'), error: 'invalid JSON' },
{ {
@@ -100,8 +100,7 @@ export async function loadRemoteRuntimeVerificationMetadata(
readCanonicalMetadata( readCanonicalMetadata(
paths.keyRegistryPath, paths.keyRegistryPath,
{ parse: parseAgentReleaseKeyRegistry }, { parse: parseAgentReleaseKeyRegistry },
'Runtime release-key registry', 'Runtime release-key registry'
true
), ),
readCanonicalMetadata( readCanonicalMetadata(
paths.runtimeLockPath, paths.runtimeLockPath,
@@ -133,8 +132,7 @@ function assertSafeVerificationInjection(
async function readCanonicalMetadata<T>( async function readCanonicalMetadata<T>(
filePathInput: string, filePathInput: string,
schema: { parse(value: unknown): T }, schema: { parse(value: unknown): T },
label: string, label: string
acceptEquivalentJsonFormatting = false
): Promise<CanonicalMetadata<T>> { ): Promise<CanonicalMetadata<T>> {
const filePath = resolve(filePathInput) const filePath = resolve(filePathInput)
const pathStat = await lstat(filePath) const pathStat = await lstat(filePath)
@@ -207,12 +205,6 @@ async function readCanonicalMetadata<T>(
`${JSON.stringify(value, null, 2)}\n`, `${JSON.stringify(value, null, 2)}\n`,
'utf8' 'utf8'
) )
if (
!acceptEquivalentJsonFormatting &&
!canonicalBytes.equals(bytes)
) {
throw new Error(`${label} is not canonical`)
}
return { bytes: canonicalBytes, value } return { bytes: canonicalBytes, value }
} }