test(spill-policy): guard loader export shape

This commit is contained in:
Dudu-0223
2026-07-09 11:04:34 +08:00
parent c9310d2a19
commit fef4313685

View File

@@ -10,6 +10,7 @@
import { describe, expect, it, vi } from 'vitest'
import { Context } from 'cordis'
import Loader from '@cordisjs/plugin-loader'
import { CallId } from '@deepseek-ai/dsh-llm'
import type { ContentBlock } from '@deepseek-ai/dsh-llm'
import { SessionId } from '@deepseek-ai/dsh-session'
@@ -82,6 +83,20 @@ describe('disabled mode', () => {
})
})
describe('loader export shape', () => {
it('has no default export and keeps name/inject/Config through unwrapExports', () => {
expect('default' in SpillPolicy).toBe(false)
const loader = Object.create(Loader.prototype) as Loader
const unwrapped = loader.unwrapExports(SpillPolicy) as Record<string, unknown>
expect(unwrapped).toBe(SpillPolicy)
expect(unwrapped.name).toBe('spill-policy')
expect(unwrapped.inject).toEqual(['tools'])
expect(unwrapped.Config).toBeDefined()
expect(typeof unwrapped.apply).toBe('function')
})
})
describe('config validation', () => {
it('rejects a negative maxInlineBytes at load', async () => {
await expect(setup({ maxInlineBytes: -1 })).rejects.toThrow(/non-negative integer/)