fix(invariants): harden runtime contracts and gates

This commit is contained in:
Tianyi Cui
2026-07-21 00:25:38 +08:00
parent a4be4b5e52
commit 0c08e34a4a
27 changed files with 288 additions and 111 deletions
@@ -260,6 +260,28 @@ describe('InvariantService lifecycle', () => {
expect(retry).toHaveBeenCalledOnce()
})
it('rolls back publication effects and ownership when child-fiber publication fails', async () => {
const { ctx } = await setup()
const leaked = vi.fn()
let rejectPublication = true
const stopRejecting = ctx.on('internal/plugin', (fiber) => {
if (!rejectPublication || fiber.uid === null) return
rejectPublication = false
fiber.ctx.on('invariants-test/ping', leaked, { global: true })
throw new Error('publication failed')
})
const failed = runtimeRegistration(ctx.invariants.register('@deepseek-ai/dsh-publication-probe', () => {}))
await expect(Promise.resolve(failed)).rejects.toThrow('publication failed')
ctx.emit('invariants-test/ping')
expect(leaked).not.toHaveBeenCalled()
stopRejecting()
const retry = runtimeRegistration(ctx.invariants.register('@deepseek-ai/dsh-publication-probe', () => {}))
await retry
await retry()
})
it('joins asynchronous checks and rolls back their effects on failure', async () => {
const { ctx } = await setup()
const leaked = vi.fn()