mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-14 04:01:35 +00:00
59 lines
3.0 KiB
TypeScript
59 lines
3.0 KiB
TypeScript
/** 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 { linkDesktopHostPackages, validateDesktopPluginGraph } from '../src/profile-packages.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 Node 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')
|
|
}
|
|
`)
|
|
writeFileSync(join(plugin, 'bundle.yml'), '- insert:\n - id: desktop-runtime-smoke-plugin\n name: desktop-runtime-smoke-plugin\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))
|
|
linkDesktopHostPackages(profile, root, runtime)
|
|
validateDesktopPluginGraph(profile, root, runtime, [pluginName])
|
|
const ready = await host.start()
|
|
if (ready.dshVersion !== runtime.release.version) throw new Error('desktop runtime: Host reported another dsh release')
|
|
const response = await host.fetch(new Request('dsh-app://app/'))
|
|
if (response.status !== 200 || !(await response.text()).includes('<html')) {
|
|
throw new Error('desktop runtime: packaged frontend smoke failed')
|
|
}
|
|
} finally {
|
|
await host.stop()
|
|
rmSync(home, { recursive: true, force: true })
|
|
}
|
|
}
|