fix: suppress runtime context in minimal profiles

This commit is contained in:
Yichen Jiang
2026-08-12 23:28:15 +08:00
parent c4e24071d6
commit ece8645080
41 changed files with 400 additions and 233 deletions

View File

@@ -142,6 +142,23 @@ describe('scoped cache-safe context', () => {
expect(renderContextSnapshot(await ctx.systemPrompt.assemble({ scope: scopeKeyOf(scope) })))
.toContain('global policy')
})
it('suppresses all context for one scope and restores it when disposed', async () => {
const ctx = await mount()
const scope = await mintScope(ctx, 'suppressed-context')
const key = scopeKeyOf(scope)
ctx.systemPrompt.context({ name: 'policy', order: 1, text: 'global policy' })
const dispose = scope.ctx.systemPrompt.suppressRuntimeContext()
const suppressed = await ctx.systemPrompt.assemble({ scope: key })
expect(suppressed.contexts).toEqual([])
const global = await ctx.systemPrompt.assemble()
expect(renderContextSnapshot(global)).toContain('global policy')
dispose()
expect(renderContextSnapshot(await ctx.systemPrompt.assemble({ scope: key })))
.toContain('global policy')
})
})
describe('scoped tool providers and toolOrder × restriction', () => {

View File

@@ -49,6 +49,25 @@ describe('SystemPrompt', () => {
expect(renderPrompt(assembly)).toBe('You are a helpful software engineer assistant.')
})
it('can suppress runtime context without evaluating providers or accepting waterfall additions', async () => {
const ctx = new Context()
await ctx.plugin(SystemPrompt, { includeRuntimeContext: false })
let providerCalls = 0
ctx.systemPrompt.context({
name: 'policy',
order: 0,
text: () => `policy ${++providerCalls}`,
})
ctx.on('system-prompt/assemble', async (assembly, _context, next) => {
assembly.contexts.push({ name: 'late', text: 'late context' })
return next()
})
const assembly = await ctx.systemPrompt.assemble()
expect(assembly.contexts).toEqual([])
expect(providerCalls).toBe(0)
})
it('tolerates a schema-bypassing direct construction (persona omitted)', async () => {
// ctx.plugin validates + defaults the config first; a direct construction
// skips the schema, so the ctor's `?? ''` narrowing is what fires.