static-shards.spec.ts 1.4 KB

1234567891011121314151617181920212223242526
  1. import { describe, expect, it } from 'vitest'
  2. import { selectStaticGates, staticShards } from './static-shards.ts'
  3. const completeInventory = staticShards.flatMap(shard => shard.gateIds).map(id => ({ id }))
  4. describe('static gate shards', () => {
  5. it.each(staticShards)('selects only the gates owned by $name', (shard) => {
  6. expect(selectStaticGates(completeInventory, shard.name).map(gate => gate.id)).toEqual(shard.gateIds)
  7. })
  8. it('selects multiple lanes in gate inventory order', () => {
  9. const selectedNames = new Set(['foundation', 'catalogs', 'prose'])
  10. const expected = staticShards
  11. .filter(shard => selectedNames.has(shard.name))
  12. .flatMap(shard => shard.gateIds)
  13. expect(selectStaticGates(completeInventory, 'foundation,catalogs,prose').map(gate => gate.id)).toEqual(expected)
  14. })
  15. it('rejects missing, duplicate, and unknown assignments', () => {
  16. expect(() => selectStaticGates(completeInventory.slice(1))).toThrow('assign every static gate exactly once')
  17. expect(() => selectStaticGates([...completeInventory, completeInventory[0]!])).toThrow('static gate IDs must be unique')
  18. expect(() => selectStaticGates(completeInventory, 'missing')).toThrow('unknown DSH_STATIC_SHARD')
  19. expect(() => selectStaticGates(completeInventory, 'foundation,foundation')).toThrow('nonempty and unique')
  20. expect(() => selectStaticGates(completeInventory, 'foundation,,prose')).toThrow('nonempty and unique')
  21. })
  22. })