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([
{ bytes: Buffer.from('not json\n'), error: 'invalid JSON' },
{
@@ -100,8 +100,7 @@ export async function loadRemoteRuntimeVerificationMetadata(
readCanonicalMetadata(
paths.keyRegistryPath,
{ parse: parseAgentReleaseKeyRegistry },
'Runtime release-key registry',
true
'Runtime release-key registry'
),
readCanonicalMetadata(
paths.runtimeLockPath,
@@ -133,8 +132,7 @@ function assertSafeVerificationInjection(
async function readCanonicalMetadata<T>(
filePathInput: string,
schema: { parse(value: unknown): T },
label: string,
acceptEquivalentJsonFormatting = false
label: string
): Promise<CanonicalMetadata<T>> {
const filePath = resolve(filePathInput)
const pathStat = await lstat(filePath)
@@ -207,12 +205,6 @@ async function readCanonicalMetadata<T>(
`${JSON.stringify(value, null, 2)}\n`,
'utf8'
)
if (
!acceptEquivalentJsonFormatting &&
!canonicalBytes.equals(bytes)
) {
throw new Error(`${label} is not canonical`)
}
return { bytes: canonicalBytes, value }
}