M4:触发历史的翻页游标写成 Z 结尾,照原样拼进查询串也能翻页

next_before 原来是「2026-10-06T14:37:03.376320+00:00」,照接口说明「原样传回」拼进地址时「+」被查询串解成空格,
回 422「翻页位置需要是接口返回的 next_before」。界面用 URLSearchParams 编码不受影响,照说明写脚本、做集成的会撞上。
现在游标是 UTC 的 Z 结尾、精确到微秒(和运行列表的游标一个写法,放进地址不用编码);解析时 Z、+00:00、被解成空格
的「 00:00」(老的游标照原样拼进地址时就是这样)都认,不是时间的照旧回 422。check-schedules 的假接口照服务端用记录
时间作游标,另加一节:老服务端给 +00:00 的游标时,页面编码成 %2B 传回、第二页接得上、不重复。
This commit is contained in:
ThearchyHelios
2026-10-07 00:02:15 +08:00
parent e410d2a6a7
commit df6b0dd3ae
3 changed files with 131 additions and 5 deletions
+18 -2
View File
@@ -578,12 +578,15 @@ async function reply(state, method, path, url, body) {
return { json: { fire: f, run_id: 'run-new-1' } }
}
if (method === 'GET' && rest === '/fires') {
// 游标照服务端的写法:最后一条的记录时间,UTC 写成 Z 结尾;legacyCursor 时写成老服务端的 +00:00(「+」不编码
// 放进查询串会被解成空格,页面得照样翻得过去)
const cursor = (f) => (state.legacyCursor ? f.created_at.replace(/Z$/, '+00:00') : f.created_at)
const limit = Number(url.searchParams.get('limit') ?? 20)
const before = url.searchParams.get('before')
const start = before ? state.fires.findIndex((f) => f.fire_at === before) + 1 : 0
const start = before ? state.fires.findIndex((f) => cursor(f) === before) + 1 : 0
const items = state.fires.slice(start, start + limit)
const more = start + limit < state.fires.length
return { json: { items, next_before: more ? items.at(-1).fire_at : null } }
return { json: { items, next_before: more ? cursor(items.at(-1)) : null } }
}
if (method === 'POST' && rest === '/webhook/test') return { json: state.webhookTest ?? WEBHOOK_TEST_OK }
}
@@ -1439,6 +1442,19 @@ await section('详情:触发历史分页', async () => {
.some((x) => x.key === 'POST /schedules/preview'))
check('没有页面报错', !errors.length, errors.join(' | '))
// 老服务端给的游标带 +00:00:页面照样编码成 %2B 传回去,第二页接得上、不重复
const legacy = await open('/schedules/s-weekly?tab=history', { state: freshState({ legacyCursor: true }) })
await legacy.page.locator('[data-fire-id]').first().waitFor()
await legacy.page.locator('[data-fire-more]').click()
await until(async () => (await legacy.page.locator('[data-fire-id]').count()) === 25)
const old = legacy.sent.filter((s) => s.key === 'GET /schedules/s-weekly/fires').at(-1)
const want = makeFires()[19].created_at.replace(/Z$/, '+00:00')
check('老服务端的 +00:00 游标:编码后原样传回(「+」写成 %2B)', (old?.search ?? '').includes('%2B')
&& new URLSearchParams(old?.search ?? '').get('before') === want, old?.search ?? '')
check('……接在后面,共 25 条、没有重复的行', new Set(await legacy.page.locator('[data-fire-id]')
.evaluateAll((els) => els.map((e) => e.getAttribute('data-fire-id')))).size === 25)
check('……没有页面报错', !legacy.errors.length, legacy.errors.join(' | '))
const none = freshState({ fires: [] })
const e = await open('/schedules/s-stock?tab=history', { state: none })
await e.page.locator('[data-fire-empty]').waitFor()