code: nextjs,memory,max (1 files)

This commit is contained in:
2025-12-26 00:30:35 +00:00
parent 8d59e0275a
commit d204e58e1e

View File

@@ -0,0 +1,26 @@
import { describe, it, expect } from 'vitest'
import type { SandboxedLuaEngineState } from './types'
import { enforceMaxMemory } from './enforce-max-memory'
const createState = (usageBytes: number, maxMemory: number): SandboxedLuaEngineState =>
({
maxMemory,
getLuaMemoryUsageBytes: () => usageBytes,
}) as SandboxedLuaEngineState
describe('enforceMaxMemory', () => {
it('does not throw when usage is under the limit', () => {
const state = createState(512, 1024)
expect(() => enforceMaxMemory.call(state)).not.toThrow()
})
it('throws when usage exceeds the limit', () => {
const state = createState(2048, 1024)
expect(() => enforceMaxMemory.call(state)).toThrow(/Memory limit exceeded/)
})
it('does not throw when maxMemory is disabled', () => {
const state = createState(2048, 0)
expect(() => enforceMaxMemory.call(state)).not.toThrow()
})
})