fix(invariants): join package checks at startup

This commit is contained in:
Tianyi Cui
2026-07-20 01:53:09 +08:00
parent 684fcf3357
commit e80fc3e61b
31 changed files with 596 additions and 314 deletions
+15 -18
View File
@@ -12,24 +12,21 @@ export const name = 'retention-invariant'
export const inject = ['invariants']
/** Assert exact head-retention accounting after the budget is exceeded. */
const install: InvariantInstaller = (ctx, fail) => {
ctx.effect(async () => {
const { ItemRetainer } = await import('./index.ts')
const retainer = new ItemRetainer<string>({ kind: 'head', maxItems: 2 })
retainer.push('first')
retainer.push('second')
retainer.push('third')
const result = retainer.finish()
assertInvariant(fail,
result.items.join(',') === 'first,second'
&& result.seen === 3
&& result.kept === 2
&& result.truncated
&& result.omitted.kind === 'exact'
&& result.omitted.count === 1,
'head retention must keep the prefix and report exact seen, kept, and omitted counts')
return () => {}
}, 'retention: validate exact head accounting')
const install: InvariantInstaller = async (_ctx, fail) => {
const { ItemRetainer } = await import('./index.ts')
const retainer = new ItemRetainer<string>({ kind: 'head', maxItems: 2 })
retainer.push('first')
retainer.push('second')
retainer.push('third')
const result = retainer.finish()
assertInvariant(fail,
result.items.join(',') === 'first,second'
&& result.seen === 3
&& result.kept === 2
&& result.truncated
&& result.omitted.kind === 'exact'
&& result.omitted.count === 1,
'head retention must keep the prefix and report exact seen, kept, and omitted counts')
}
/**