mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 16:02:32 +00:00
* oom(01): A1-shared-readers — reintroduce #10179 subset Files: 18 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(02): A2-shared-image-media — reintroduce #10179 subset Files: 7 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(03): A3-shared-fs-listing — reintroduce #10179 subset Files: 21 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(04): A4-shared-remote-relay — reintroduce #10179 subset Files: 8 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(05): A5-shared-misc — reintroduce #10179 subset Files: 28 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> * oom(06): B-shared-wiring — reintroduce #10179 subset Files: 81 applied, 0 deleted (from6eb70d8370) Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { SecurePathHardeningCache } from './secure-path-hardening-cache'
|
|
|
|
describe('SecurePathHardeningCache', () => {
|
|
it('accepts a UTF-8 key at the exact per-key boundary', () => {
|
|
const cache = new SecurePathHardeningCache<number>({
|
|
maxEntries: 2,
|
|
maxKeyBytes: 6,
|
|
maxTotalKeyBytes: 6
|
|
})
|
|
|
|
expect(cache.set('界界', 1)).toBe(true)
|
|
expect(cache.get('界界')).toBe(1)
|
|
expect(cache.state()).toMatchObject({ entries: 1, keyBytes: 6 })
|
|
})
|
|
|
|
it('rejects one byte beyond the per-key boundary without evicting retained state', () => {
|
|
const cache = new SecurePathHardeningCache<number>({
|
|
maxEntries: 2,
|
|
maxKeyBytes: 6,
|
|
maxTotalKeyBytes: 12
|
|
})
|
|
cache.set('kept', 1)
|
|
|
|
expect(cache.set('1234567', 2)).toBe(false)
|
|
expect(cache.state().paths).toEqual(['kept'])
|
|
})
|
|
|
|
it('evicts the least-recently-used entry at the count boundary', () => {
|
|
const cache = new SecurePathHardeningCache<number>({
|
|
maxEntries: 2,
|
|
maxKeyBytes: 32,
|
|
maxTotalKeyBytes: 64
|
|
})
|
|
cache.set('old', 1)
|
|
cache.set('hot', 2)
|
|
expect(cache.get('old')).toBe(1)
|
|
|
|
cache.set('new', 3)
|
|
|
|
expect(cache.state().paths).toEqual(['old', 'new'])
|
|
expect(cache.get('hot')).toBeUndefined()
|
|
})
|
|
|
|
it('evicts LRU entries until aggregate UTF-8 key bytes fit', () => {
|
|
const cache = new SecurePathHardeningCache<number>({
|
|
maxEntries: 10,
|
|
maxKeyBytes: 12,
|
|
maxTotalKeyBytes: 12
|
|
})
|
|
cache.set('aaaa', 1)
|
|
cache.set('bbbb', 2)
|
|
|
|
expect(cache.set('界界', 3)).toBe(true)
|
|
expect(cache.state()).toEqual({
|
|
entries: 2,
|
|
keyBytes: 10,
|
|
paths: ['bbbb', '界界']
|
|
})
|
|
})
|
|
})
|