code: nextjs,frontends,types (3 files)

This commit is contained in:
2025-12-26 00:30:03 +00:00
parent e20a289b1d
commit fb367a3358
3 changed files with 67 additions and 0 deletions
@@ -0,0 +1,12 @@
import type { SandboxedLuaEngineState } from './types'
export function enforceMaxMemory(this: SandboxedLuaEngineState): void {
if (!Number.isFinite(this.maxMemory) || this.maxMemory <= 0) return
const usageBytes = this.getLuaMemoryUsageBytes()
if (usageBytes > this.maxMemory) {
throw new Error(
`Memory limit exceeded: ${usageBytes} bytes used (max ${this.maxMemory})`
)
}
}
@@ -23,4 +23,8 @@ export interface SandboxedLuaEngineState {
setupSandboxedEnvironment: () => void
/** Execute code with timeout */
executeWithTimeout: (code: string, context?: LuaExecutionContext) => Promise<LuaExecutionResult>
/** Read current Lua heap usage in bytes */
getLuaMemoryUsageBytes: () => number
/** Enforce maxMemory threshold */
enforceMaxMemory: () => void
}
@@ -0,0 +1,51 @@
import { describe, expect, it } from 'vitest'
import { collectFileEntries } from './collect-file-entries'
import type { FileNode } from './types'
describe('collectFileEntries', () => {
it('respects exportPath overrides while keeping root folder names', () => {
const tree: FileNode[] = [
{
id: 'root',
name: 'social_hub',
type: 'folder',
children: [
{
id: 'lua',
name: 'Lua',
type: 'folder',
exportPath: 'seed/scripts',
children: [
{
id: 'manifest',
name: 'manifest.json',
type: 'file',
content: '{"scripts":[]}',
},
],
},
{
id: 'metadata',
name: 'metadata',
type: 'folder',
exportPath: 'seed',
children: [
{
id: 'meta-file',
name: 'metadata.json',
type: 'file',
content: '{"packageId":"social_hub"}',
},
],
},
],
},
]
const entries = collectFileEntries(tree)
const paths = entries.map((entry) => entry.path)
expect(paths).toContain('social_hub/seed/scripts/manifest.json')
expect(paths).toContain('social_hub/seed/metadata.json')
})
})