fix(schedule): validate snapshot marker arrays

This commit is contained in:
pku-xht
2026-08-07 19:47:12 +08:00
committed by Tianyi Cui
parent b8d4e004ed
commit 9dc4ad91fa
4 changed files with 64 additions and 24 deletions

View File

@@ -82,8 +82,24 @@ function validateReading(
if (turn !== expected.turn || step !== expected.step) {
fail(`time-context reading names turn ${turn}/step ${step}, expected turn ${expected.turn}/step ${expected.step}`)
}
if (Object.keys(event.data.source).length !== 2) {
fail('time-context source must not duplicate request authority')
const source = event.data.source
/* v8 ignore next 2 -- replay and dispatch callers select this exact package-owned source before validation. */
if (source.kind !== 'plugin' || source.plugin !== SOURCE_NAME) {
fail('time-context source must retain package ownership')
}
const sections: unknown = 'sections' in source ? source.sections : undefined
const section: unknown = Array.isArray(sections) ? sections[0] : undefined
if (Object.keys(source).length !== 4
|| source.form !== 'snapshot'
|| !Array.isArray(sections)
|| sections.length !== 1
|| typeof section !== 'object'
|| section === null
|| !('name' in section)
|| section.name !== SOURCE_NAME
|| !('text' in section)
|| section.text !== block.text) {
fail('time-context source must carry only the exact snapshot text, not request authority')
}
const renderedAuthority = `Session time zone: ${match[4]}.\nClient time zone for this request: ${match[5]}.`
const expectedAuthority = renderTimeZoneContext(