| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- /** Boot the materialized target runtime without access to a user's Harness profile. */
- import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
- import { tmpdir } from 'node:os'
- import { join } from 'node:path'
- import { DesktopHostProcess } from '../src/host-process.ts'
- import { createPluginProfile } from '../src/project-manager.ts'
- import type { DesktopRuntimeDescriptor } from '../src/runtime-tree.ts'
- /**
- * Prove the final resource tree boots and serves its matching Web frontend.
- * @param root - Materialized dsh resources.
- * @param node - Prepared target Electron executable.
- * @param runtime - Verified resource descriptor.
- */
- export async function smokeDesktopRuntime(root: string, node: string, runtime: DesktopRuntimeDescriptor): Promise<void> {
- const home = mkdtempSync(join(tmpdir(), 'dsh-desktop-smoke-'))
- const profile = join(home, 'profiles', 'desktop')
- const host = new DesktopHostProcess(node, root, profile, undefined, { ...process.env, DSH_HOME: home })
- try {
- createPluginProfile(profile)
- const pluginName = 'desktop-runtime-smoke-plugin'
- const plugin = join(profile, 'node_modules', pluginName)
- mkdirSync(plugin, { recursive: true })
- const cordis = runtime.sharedPackages.find(entry => entry.name === '@deepseek-ai/cordis')
- if (cordis === undefined) throw new Error('desktop runtime: missing shared Cordis package')
- writeFileSync(join(plugin, 'package.json'), JSON.stringify({
- name: pluginName, version: '1.0.0', type: 'module', exports: './index.js',
- peerDependencies: { '@deepseek-ai/cordis': cordis.version }, dsh: { bundle: { patch: './bundle.yml' } },
- }))
- writeFileSync(join(plugin, 'index.js'), `
- import { Context } from '@deepseek-ai/cordis'
- export function apply(ctx) {
- if (!(ctx instanceof Context)) throw new Error('desktop runtime: external plugin loaded another Cordis instance')
- ctx.effect(() => ctx.webServer.register({ kind: 'exact', path: '/desktop-smoke',
- handler(_request, response) { response.end('plugin route ready') } }))
- }
- `)
- writeFileSync(join(plugin, 'bundle.yml'), '- insert:\n - id: desktop-runtime-smoke-plugin\n name: desktop-runtime-smoke-plugin\n inject: [webServer]\n')
- const manifest = JSON.parse(readFileSync(join(profile, 'package.json'), 'utf8')) as {
- dependencies: Record<string, string>
- dsh: { profile: { bundles: string[] } }
- }
- manifest.dependencies[pluginName] = '1.0.0'
- manifest.dsh.profile.bundles.push(pluginName)
- writeFileSync(join(profile, 'package.json'), JSON.stringify(manifest))
- writeFileSync(join(profile, 'cordis.patch.yml'), '- id: webserver\n config:\n host: 127.0.0.1\n port: 0\n')
- const ready = await host.start()
- const login = await fetch(ready.url, { redirect: 'manual' })
- const cookie = login.headers.getSetCookie().map(value => value.split(';')[0]).join('; ')
- const response = await fetch(new URL('/', ready.url), { headers: { cookie } })
- if (response.status !== 200 || !(await response.text()).includes('<html')) {
- throw new Error('desktop runtime: packaged frontend smoke failed')
- }
- const pluginResponse = await fetch(new URL('/desktop-smoke', ready.url), { headers: { cookie } })
- if (await pluginResponse.text() !== 'plugin route ready') throw new Error('desktop runtime: plugin HTTP route failed')
- } finally {
- await host.stop()
- rmSync(home, { recursive: true, force: true })
- }
- }
|