web-prompt-context.spec.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import { sep } from 'node:path'
  2. import { Context } from 'cordis'
  3. import { describe, expect, it } from 'vitest'
  4. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  5. import { HARNESS_SOURCE_SECTION } from '@deepseek-ai/dsh-app-boot'
  6. import type {} from '@deepseek-ai/dsh-host-webserver'
  7. import { prepareWebRuntimeContext } from '../src/web.ts'
  8. describe('prepareWebRuntimeContext', () => {
  9. it('installs both sections before a later systemPrompt consumer activates', async () => {
  10. const ctx = new Context()
  11. const sourceRoot = `${sep}opt${sep}harness-src`
  12. let observedSections: { name: string; text: string }[] | undefined
  13. try {
  14. prepareWebRuntimeContext(ctx, sourceRoot, 'production')
  15. ctx.provide('httpServer', { port: 3080 } as Context['httpServer'])
  16. const consumer = ctx.inject(['systemPrompt'], async (promptCtx) => {
  17. const assembly = await promptCtx.systemPrompt.assemble()
  18. observedSections = assembly.sections
  19. })
  20. await ctx.plugin(SystemPrompt, { persona: 'You are a coding agent.' })
  21. await consumer
  22. expect(observedSections?.map(section => section.name)).toContain(HARNESS_SOURCE_SECTION)
  23. expect(observedSections?.find(section => section.name === 'app:web-surface')?.text)
  24. .toContain('http://127.0.0.1:3080')
  25. } finally {
  26. await ctx.fiber.dispose()
  27. }
  28. })
  29. })