runtime-fixture.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /** Temporary materialized packages for Desktop resource and profile behavior tests. */
  2. import { mkdirSync, writeFileSync } from 'node:fs'
  3. import { join } from 'node:path'
  4. import { DESKTOP_HOST_RUNTIME_FILES } from '../src/core-package-set.ts'
  5. import { DESKTOP_HOST_PROTOCOL_VERSION } from '../src/host-protocol.ts'
  6. import { writeDesktopRuntime, type DesktopRuntimeDescriptor } from '../src/runtime-tree.ts'
  7. /**
  8. * Write a package fixture with explicit runtime exports.
  9. * @param modules - Owning node_modules directory.
  10. * @param name - Package name.
  11. * @param fields - Manifest fields.
  12. * @param source - ESM entry contents.
  13. * @returns Installed package directory.
  14. */
  15. export function writePackage(modules: string, name: string, fields: Record<string, unknown> = {}, source = 'export const identity = {}\n'): string {
  16. const path = join(modules, name)
  17. mkdirSync(path, { recursive: true })
  18. writeFileSync(join(path, 'package.json'), JSON.stringify({ name, version: '1.0.0', type: 'module', exports: './index.js', ...fields }))
  19. writeFileSync(join(path, 'index.js'), source)
  20. return path
  21. }
  22. /**
  23. * Seal a minimal release containing Host entry files and a shared Cordis package.
  24. * @param root - New runtime directory.
  25. * @param version - Shell and dsh version.
  26. * @param nodeVersion - Bundled Node version used for native rebuild selection.
  27. * @returns Sealed runtime metadata.
  28. */
  29. export function runtimeFixture(root: string, version = '1.0.0', nodeVersion = '24.17.0'): DesktopRuntimeDescriptor {
  30. const names = ['@deepseek-ai/dsh', '@deepseek-ai/dsh-desktop-host', '@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app', '@deepseek-ai/cordis']
  31. for (const name of names) writePackage(join(root, 'node_modules'), name, { version })
  32. for (const file of DESKTOP_HOST_RUNTIME_FILES) {
  33. const path = join(root, 'node_modules', '@deepseek-ai/dsh-desktop-host', file)
  34. mkdirSync(join(path, '..'), { recursive: true })
  35. writeFileSync(path, '')
  36. }
  37. writeFileSync(join(root, 'package.json'), '{"type":"module"}\n')
  38. return writeDesktopRuntime(root, { schemaVersion: 1, version, nodeVersion, pnpmVersion: '11.7.0', hostProtocolVersion: DESKTOP_HOST_PROTOCOL_VERSION }, names)
  39. }