Recover from corrupt ops-cron store and tighten cron tool schemas.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
oliver 2026-09-10 10:34:41 +08:00
parent b1bb0067a0
commit 25454a5c8c
4 changed files with 58 additions and 6 deletions

View file

@ -60,6 +60,23 @@ test('createJobRecord fires ASAP when one-shot at is slightly in the past', () =
)
})
test('createStore recovers from NUL-corrupt store.json', async () => {
const { createStore } = await import('../lib/store.js')
const { mkdtemp, writeFile, readFile, rm } = await import('node:fs/promises')
const { tmpdir } = await import('node:os')
const { join } = await import('node:path')
const dir = await mkdtemp(join(tmpdir(), 'dsh-cron-store-'))
const filePath = join(dir, 'store.json')
await writeFile(filePath, `{\u0000"jobs":[]}`, 'utf8')
const store = createStore({ filePath })
const state = await store.read()
assert.equal(Array.isArray(state.jobs), true)
assert.equal(state.jobs.length, 0)
const rewritten = await readFile(filePath, 'utf8')
assert.equal(rewritten.includes('\u0000'), false)
await rm(dir, { recursive: true, force: true })
})
test('resolveCreateAgentPreset prefers explicit then peer then session then host default', async () => {
assert.equal(
await resolveCreateAgentPreset({ agent_preset: 'explicit' }, {}, {}),