egress.spec.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { describe, expect, it, vi } from 'vitest'
  2. import { Context } from '@deepseek-ai/cordis'
  3. import { installProxyFromEnvironment } from '@deepseek-ai/dsh-http-proxy'
  4. import SubagentRuntime from '@deepseek-ai/dsh-subagent'
  5. import PtcWorkflowEngine from '../src/index.ts'
  6. import { fakeParent, mountPtcRuntime } from './setup.ts'
  7. describe('workflow program environment', () => {
  8. it('does not expose ambient credentials, proxy settings or host loader paths', async () => {
  9. const ctx = new Context()
  10. await mountPtcRuntime(ctx)
  11. await ctx.plugin(SubagentRuntime)
  12. ctx.subagents.registerProvider({
  13. name: 'stub',
  14. capabilities: { agentOptions: false, outputSchema: false, depthLimit: false, toolFilter: false, persona: false },
  15. inheritsParentContext: false,
  16. start: () => Promise.reject(new Error('environment script must not start a child')),
  17. })
  18. await ctx.plugin(PtcWorkflowEngine, { provider: 'stub' })
  19. const disposeProxy = await installProxyFromEnvironment({
  20. get: name => name === 'HTTP_PROXY' || name === 'HTTPS_PROXY'
  21. ? { value: 'http://fixture:canary@proxy.example:8080' } : undefined,
  22. }, () => undefined)
  23. vi.stubEnv('WORKFLOW_ENV_CANARY', 'must-not-inherit')
  24. vi.stubEnv('TSX_TSCONFIG_PATH', '/fixture/tsconfig.json')
  25. try {
  26. const run = ctx.workflowEngine.start({
  27. script: "return { ...globalThis.constructor.constructor('return process')().env }",
  28. meta: { name: 'environment', description: 'program environment' },
  29. parent: fakeParent(ctx),
  30. })
  31. try {
  32. const result = await run.result
  33. expect(result.stopReason).toBe('completed')
  34. expect(result.value).toEqual({})
  35. } finally { await run.dispose() }
  36. } finally {
  37. vi.unstubAllEnvs()
  38. await disposeProxy()
  39. }
  40. })
  41. })