Merge master into feat/experimental-dsh-cua
This commit is contained in:
commit
1b781d683b
1361 files changed
+19617
-4073
No files matched your search
@@ -1,8 +1,12 @@
|
||||
import { chmod, mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises'
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, expect, it } from 'vitest'
|
||||
import { copyOfficeSidecar } from './build-exe-for-python-sdk-office.ts'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { c as tar } from 'tar'
|
||||
import { downloadOfficeSidecar, runtimeNpmArchive } from './build-exe-for-python-sdk-office.ts'
|
||||
|
||||
import { officePackageDirectories } from './libreoffice-packages.mjs'
|
||||
|
||||
const temporaryDirectories: string[] = []
|
||||
|
||||
@@ -24,33 +28,8 @@ async function fixture() {
|
||||
return { root, staging, destination, packageAt }
|
||||
}
|
||||
|
||||
it('copies package-owned data, licenses, helper permissions, and nested dependencies', async () => {
|
||||
const { staging, destination, packageAt } = await fixture()
|
||||
const entry = await packageAt('@deepseek-ai/libreoffice-kit', { optionalDependencies: { '@deepseek-ai/libreoffice-kit-wasm': '0.0.1' }, dependencies: { decoder: '1' } })
|
||||
const engine = await packageAt('@deepseek-ai/libreoffice-kit-wasm')
|
||||
const decoder = await packageAt('decoder', { dependencies: { codec: '1' } }, entry)
|
||||
await packageAt('codec', {}, decoder)
|
||||
await packageAt('codec', { version: '2.0.0' })
|
||||
const assets = ['assets/soffice.data', 'prebuilds.json', 'licenses/LICENSE', 'bin/helper']
|
||||
for (const name of assets) {
|
||||
const path = join(engine, name)
|
||||
await mkdir(dirname(path), { recursive: true })
|
||||
await writeFile(path, name)
|
||||
}
|
||||
await chmod(join(engine, 'bin/helper'), 0o755)
|
||||
|
||||
const packages = await copyOfficeSidecar(staging, destination, { platform: 'linux', arch: 'x64' })
|
||||
|
||||
expect(packages).toHaveLength(4)
|
||||
expect(await readFile(join(destination, 'node_modules/@deepseek-ai/libreoffice-kit-wasm/assets/soffice.data'), 'utf8')).toBe('assets/soffice.data')
|
||||
expect(await readFile(join(destination, 'node_modules/@deepseek-ai/libreoffice-kit-wasm/licenses/LICENSE'), 'utf8')).toBe('licenses/LICENSE')
|
||||
expect(await readFile(join(destination, 'node_modules/@deepseek-ai/libreoffice-kit/node_modules/decoder/node_modules/codec/package.json'), 'utf8')).toContain('codec')
|
||||
await expect(stat(join(destination, 'node_modules/codec'))).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
if (process.platform !== 'win32') expect((await stat(join(destination, 'node_modules/@deepseek-ai/libreoffice-kit-wasm/bin/helper'))).mode & 0o111).toBe(0o111)
|
||||
})
|
||||
|
||||
it('copies installed target optionals and leaves other platforms and absent optionals out', async () => {
|
||||
const { staging, destination, packageAt } = await fixture()
|
||||
it('locates installed target optionals and leaves other platforms and absent optionals out', async () => {
|
||||
const { staging, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', {
|
||||
optionalDependencies: { native: '1', foreign: '1', absent: '1' },
|
||||
})
|
||||
@@ -58,84 +37,112 @@ it('copies installed target optionals and leaves other platforms and absent opti
|
||||
await packageAt('native', { os: ['linux'], cpu: ['x64'] })
|
||||
await packageAt('foreign', { os: ['darwin'], cpu: ['arm64'] })
|
||||
|
||||
const packages = await copyOfficeSidecar(staging, destination, { platform: 'linux', arch: 'x64' })
|
||||
const packages = await officePackageDirectories(staging, { platform: 'linux', arch: 'x64' })
|
||||
|
||||
expect(packages.map(path => path.replaceAll('\\', '/'))).toEqual([
|
||||
expect(packages.map(path => path.slice(staging.length + 1).replaceAll('\\', '/'))).toEqual([
|
||||
'node_modules/@deepseek-ai/libreoffice-kit',
|
||||
'node_modules/@deepseek-ai/libreoffice-kit-wasm',
|
||||
'node_modules/native',
|
||||
])
|
||||
})
|
||||
|
||||
it('rejects a missing required dependency before producing a sidecar', async () => {
|
||||
const { staging, destination, packageAt } = await fixture()
|
||||
it('rejects a missing required dependency in the deployed closure', async () => {
|
||||
const { staging, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', { dependencies: { 'dsh-missing-office-fixture': '1' } })
|
||||
|
||||
await expect(copyOfficeSidecar(staging, destination, { platform: 'linux', arch: 'x64' }))
|
||||
await expect(officePackageDirectories(staging, { platform: 'linux', arch: 'x64' }))
|
||||
.rejects.toThrow('dsh-missing-office-fixture required by @deepseek-ai/libreoffice-kit is missing')
|
||||
await expect(stat(destination)).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
})
|
||||
|
||||
it('rejects an incomplete installed optional instead of omitting it', async () => {
|
||||
const { staging, destination, packageAt } = await fixture()
|
||||
const { staging, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', { optionalDependencies: { broken: '1' } })
|
||||
await mkdir(join(staging, 'node_modules/broken'), { recursive: true })
|
||||
|
||||
await expect(copyOfficeSidecar(staging, destination, { platform: 'linux', arch: 'x64' }))
|
||||
await expect(officePackageDirectories(staging, { platform: 'linux', arch: 'x64' }))
|
||||
.rejects.toMatchObject({ code: 'ENOENT' })
|
||||
})
|
||||
|
||||
it('rejects an ancestor dependency outside the deployed closure', async () => {
|
||||
const { root, staging, destination, packageAt } = await fixture()
|
||||
const { root, staging, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', { dependencies: { 'ancestor-office-fixture': '1' } })
|
||||
await packageAt('ancestor-office-fixture', {}, root)
|
||||
|
||||
await expect(copyOfficeSidecar(staging, destination, { platform: 'linux', arch: 'x64' }))
|
||||
await expect(officePackageDirectories(staging, { platform: 'linux', arch: 'x64' }))
|
||||
.rejects.toThrow('outside the deployed closure')
|
||||
})
|
||||
|
||||
it('requires the declared WASM engine inside the deployed closure', async () => {
|
||||
const { root, staging, destination, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', { optionalDependencies: { '@deepseek-ai/libreoffice-kit-wasm': '0.0.1' } })
|
||||
it.each([true, false])('requires a staged WASM engine when declared=%s even when an ancestor has one', async (declared) => {
|
||||
const { root, staging, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', declared ? { optionalDependencies: { '@deepseek-ai/libreoffice-kit-wasm': '0.0.1' } } : {})
|
||||
await packageAt('@deepseek-ai/libreoffice-kit-wasm', {}, root)
|
||||
await expect(copyOfficeSidecar(staging, destination, { platform: 'linux', arch: 'x64' }))
|
||||
await expect(officePackageDirectories(staging, { platform: 'linux', arch: 'x64' }))
|
||||
.rejects.toThrow('Office engine @deepseek-ai/libreoffice-kit-wasm required for linux/x64 is missing.')
|
||||
await expect(stat(destination)).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
})
|
||||
|
||||
it.each([
|
||||
['darwin', 'arm64', 'darwin-arm64'], ['darwin', 'x64', 'darwin-x64'],
|
||||
['win32', 'arm64', 'win32-arm64'], ['win32', 'x64', 'win32-x64'],
|
||||
['linux', 'x64', 'linux-x64'], ['linux', 'arm64', 'wasm'], ['freebsd', 'x64', 'wasm'],
|
||||
])('copies only the %s/%s engine even when other engines are staged', async (platform, arch, selected) => {
|
||||
const { staging, destination, packageAt } = await fixture()
|
||||
])('locates only the %s/%s engine even when other engines are staged', async (platform, arch, selected) => {
|
||||
const { staging, packageAt } = await fixture()
|
||||
const targets = ['darwin-arm64', 'darwin-x64', 'win32-arm64', 'win32-x64', 'linux-x64', 'wasm']
|
||||
const names = targets.map(target => `@deepseek-ai/libreoffice-kit-${target}`)
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', { optionalDependencies: Object.fromEntries(names.map(name => [name, '0.0.1'])) })
|
||||
for (const name of names) await packageAt(name)
|
||||
const expected = `@deepseek-ai/libreoffice-kit-${selected}`
|
||||
const packages = await copyOfficeSidecar(staging, destination, { platform, arch })
|
||||
expect(packages.map(path => path.replaceAll('\\', '/'))).toEqual([
|
||||
const packages = await officePackageDirectories(staging, { platform, arch })
|
||||
expect(packages.map(path => path.slice(staging.length + 1).replaceAll('\\', '/'))).toEqual([
|
||||
'node_modules/@deepseek-ai/libreoffice-kit', `node_modules/${expected}`,
|
||||
])
|
||||
})
|
||||
|
||||
it.each(['darwin', 'win32', 'linux'])('%s requires its native package even when WASM is staged', async (platform) => {
|
||||
const { staging, destination, packageAt } = await fixture()
|
||||
const { staging, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit', { optionalDependencies: {
|
||||
'@deepseek-ai/libreoffice-kit-wasm': '0.0.1', [`@deepseek-ai/libreoffice-kit-${platform}-arm64`]: '0.0.1',
|
||||
} })
|
||||
await packageAt('@deepseek-ai/libreoffice-kit-wasm')
|
||||
await expect(copyOfficeSidecar(staging, destination, { platform, arch: 'arm64' }))
|
||||
await expect(officePackageDirectories(staging, { platform, arch: 'arm64' }))
|
||||
.rejects.toThrow(`Office engine @deepseek-ai/libreoffice-kit-${platform}-arm64 required for ${platform}/arm64 is missing.`)
|
||||
await expect(stat(destination)).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
})
|
||||
|
||||
it('requires a staged Linux WASM engine even when an ancestor has one', async () => {
|
||||
const { root, staging, destination, packageAt } = await fixture()
|
||||
await packageAt('@deepseek-ai/libreoffice-kit')
|
||||
await packageAt('@deepseek-ai/libreoffice-kit-wasm', {}, root)
|
||||
await expect(copyOfficeSidecar(staging, destination, { platform: 'linux', arch: 'x64' }))
|
||||
.rejects.toThrow('Office engine @deepseek-ai/libreoffice-kit-wasm required for linux/x64 is missing.')
|
||||
await expect(stat(destination)).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
it('downloads pinned npm packages into the sidecar without resolving or executing package scripts', async () => {
|
||||
const { root, destination } = await fixture()
|
||||
const source = join(root, 'package')
|
||||
await mkdir(source)
|
||||
await writeFile(join(source, 'package.json'), JSON.stringify({ name: 'fixture', version: '1.0.0', scripts: { install: 'must-not-run' } }))
|
||||
await writeFile(join(source, 'worker.js'), 'worker')
|
||||
const archive = join(root, 'package.tgz')
|
||||
await tar({ file: archive, cwd: root, gzip: true }, ['package'])
|
||||
const bytes = await readFile(archive)
|
||||
const checksum = createHash('sha512').update(bytes).digest()
|
||||
const cache = join(root, 'archives')
|
||||
await mkdir(cache)
|
||||
await writeFile(join(cache, checksum.toString('hex')), bytes)
|
||||
const artifact = { name: 'fixture', version: '1.0.0', directory: 'node_modules/fixture',
|
||||
url: 'https://unused.invalid/fixture.tgz', integrity: `sha512-${checksum.toString('base64')}` }
|
||||
await downloadOfficeSidecar([artifact], destination, cache)
|
||||
expect(await readFile(join(destination, 'node_modules/fixture/worker.js'), 'utf8')).toBe('worker')
|
||||
await expect(downloadOfficeSidecar([{ ...artifact, directory: 'node_modules/../../outside' }], destination, cache))
|
||||
.rejects.toThrow('invalid package directory')
|
||||
await expect(downloadOfficeSidecar([{ ...artifact, version: '2.0.0' }], destination, cache))
|
||||
.rejects.toThrow('package identity mismatch')
|
||||
await writeFile(join(cache, checksum.toString('hex')), 'corrupted archive')
|
||||
await expect(downloadOfficeSidecar([artifact], destination, cache)).rejects.toThrow('checksum mismatch')
|
||||
})
|
||||
|
||||
|
||||
it('takes npm integrity from the workspace lock without querying registry metadata', async () => {
|
||||
const { root } = await fixture()
|
||||
const lockfile = join(root, 'pnpm-lock.yaml')
|
||||
const integrity = `sha512-${Buffer.alloc(64, 7).toString('base64')}`
|
||||
await writeFile(lockfile, JSON.stringify({ packages: { '@scope/[email protected]': { resolution: { integrity } } } }))
|
||||
expect(await runtimeNpmArchive('@scope/fixture', '1.2.3', lockfile)).toEqual({
|
||||
name: '@scope/fixture', version: '1.2.3', integrity,
|
||||
url: 'https://registry.npmjs.org/@scope/fixture/-/fixture-1.2.3.tgz',
|
||||
})
|
||||
await expect(runtimeNpmArchive('@scope/fixture', '1.2.4', lockfile)).rejects.toThrow('missing SHA-512 integrity')
|
||||
await writeFile(lockfile, JSON.stringify({ packages: { '@scope/[email protected]': { resolution: { integrity: 'sha256-invalid' } } } }))
|
||||
await expect(runtimeNpmArchive('@scope/fixture', '1.2.3', lockfile)).rejects.toThrow('missing SHA-512 integrity')
|
||||
})
|
||||
@@ -1,6 +1,8 @@
|
||||
/** Keep LibreOffice workers, prebuilt engines, and their dependencies on the real filesystem. */
|
||||
import { cp, mkdir, rm } from 'node:fs/promises'
|
||||
import { join, relative, sep } from 'node:path'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { isAbsolute, join, relative, sep } from 'node:path'
|
||||
import { downloadRuntimeNpmPackage, type RuntimeNpmArchive } from './primary-runtime/prepare.ts'
|
||||
import { load as parseYaml } from 'js-yaml'
|
||||
import { officePackageDirectories } from './libreoffice-packages.mjs'
|
||||
|
||||
/** pkg applies these exclusions to dependency `files` as well as root asset globs. */
|
||||
@@ -9,29 +11,53 @@ export const OFFICE_ASSET_IGNORES = [
|
||||
'**/node_modules/@deepseek-ai/libreoffice-kit-*/**',
|
||||
]
|
||||
|
||||
/** One npm package at its existing sidecar dependency location. */
|
||||
export interface OfficePackageArchive extends RuntimeNpmArchive {
|
||||
/** Relative package directory inside the sidecar. */
|
||||
readonly directory: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the installed Office dependency tree without changing package contents or executable modes.
|
||||
* Harness sidecars require the kit's declared target native engine, or WASM for other targets.
|
||||
* Missing target engines fail with their package name; missing required dependencies or paths outside the deployed closure also fail.
|
||||
* @param staging - Symlink-free deployed Node closure.
|
||||
* @param destination - Target-specific Office directory beside the executable; replaced when present.
|
||||
* @param target - Node platform and CPU of the executable.
|
||||
* @returns Relative package directories included in the sidecar.
|
||||
* Resolve one installed npm version against its reviewed workspace lock integrity.
|
||||
* @param name - Published package name.
|
||||
* @param version - Exact installed version.
|
||||
* @param lockfile - Workspace lock recording the exact published archive.
|
||||
* @returns Locked npm tarball identity; rejects versions without SHA-512 integrity.
|
||||
*/
|
||||
export async function copyOfficeSidecar(
|
||||
staging: string,
|
||||
destination: string,
|
||||
target: { platform: string; arch: string },
|
||||
): Promise<string[]> {
|
||||
export async function runtimeNpmArchive(name: string, version: string, lockfile = join(import.meta.dirname, '../pnpm-lock.yaml')): Promise<RuntimeNpmArchive> {
|
||||
const lock = parseYaml(await readFile(lockfile, 'utf8')) as { packages?: Record<string, { resolution?: { integrity?: string } }> }
|
||||
const integrity = lock.packages?.[`${name}@${version}`]?.resolution?.integrity
|
||||
if (typeof integrity !== 'string' || !/^sha512-[A-Za-z0-9+/]+={0,2}$/u.test(integrity)) {
|
||||
throw new Error(`runtime npm lock: missing SHA-512 integrity for ${name}@${version}`)
|
||||
}
|
||||
return { name, version, url: `https://registry.npmjs.org/${name}/-/${name.split('/').at(-1)}-${version}.tgz`, integrity }
|
||||
}
|
||||
|
||||
/**
|
||||
* Lock the installed Office closure to published npm tarballs, preserving nested dependency locations.
|
||||
* @param staging - Complete installed Node closure.
|
||||
* @param target - Sidecar platform and CPU.
|
||||
* @returns Download records for the selected engine and all dependencies.
|
||||
*/
|
||||
export async function officeSidecarArchives(staging: string, target: { platform: string; arch: string }): Promise<OfficePackageArchive[]> {
|
||||
const directories = await officePackageDirectories(staging, target)
|
||||
await rm(destination, { recursive: true, force: true })
|
||||
await mkdir(destination, { recursive: true })
|
||||
for (const source of directories) {
|
||||
const nestedModules = join(source, 'node_modules')
|
||||
await cp(source, join(destination, relative(staging, source)), {
|
||||
recursive: true,
|
||||
filter: path => path !== nestedModules && !path.startsWith(nestedModules + sep),
|
||||
})
|
||||
return Promise.all(directories.map(async (directory) => {
|
||||
const manifest = JSON.parse(await readFile(join(directory, 'package.json'), 'utf8')) as { name: string; version: string }
|
||||
return { ...await runtimeNpmArchive(manifest.name, manifest.version), directory: relative(staging, directory).split(sep).join('/') }
|
||||
}))
|
||||
}
|
||||
|
||||
/**
|
||||
* Download the complete pinned Office sidecar without npm or package lifecycle scripts.
|
||||
* @param packages - Build-locked npm packages and dependency locations.
|
||||
* @param destination - Empty sidecar directory.
|
||||
* @param cache - Verified archive cache.
|
||||
* @returns Resolves after all packages are unpacked and checked.
|
||||
*/
|
||||
export async function downloadOfficeSidecar(packages: readonly OfficePackageArchive[], destination: string, cache: string): Promise<void> {
|
||||
for (const artifact of packages) {
|
||||
if (isAbsolute(artifact.directory) || artifact.directory.split(/[\\/]/u).some(part => part === '..')
|
||||
|| !artifact.directory.startsWith('node_modules/')) throw new Error(`Office download: invalid package directory ${artifact.directory}`)
|
||||
await downloadRuntimeNpmPackage(artifact, join(destination, artifact.directory), cache)
|
||||
}
|
||||
return directories.map(directory => relative(staging, directory))
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { chmod, mkdir, mkdtemp, readFile, readlink, rm, stat, symlink, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { expect, it, onTestFinished } from 'vitest'
|
||||
import { resolvePrimaryRuntime } from '../packages/skill/tool-workspace-dependencies/src/index.ts'
|
||||
import { syncPythonRuntimeProduct } from './build-exe-for-python-sdk-resources.ts'
|
||||
|
||||
it('copies standalone SDK products with their executable permissions', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'sdk-product-'))
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }))
|
||||
const source = join(root, 'source')
|
||||
const destination = join(root, 'destination')
|
||||
await writeFile(source, 'executable')
|
||||
await chmod(source, 0o755)
|
||||
await syncPythonRuntimeProduct(source, destination)
|
||||
expect(await readFile(destination, 'utf8')).toBe('executable')
|
||||
expect((await stat(destination)).mode & 0o777).toBe((await stat(source)).mode & 0o777)
|
||||
})
|
||||
|
||||
// Windows uses python.exe and does not require POSIX file symlink privileges.
|
||||
it.skipIf(process.platform === 'win32')('keeps SDK Python resources usable after deleting the build output', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'sdk-resource-aliases-'))
|
||||
onTestFinished(() => rm(root, { recursive: true, force: true }))
|
||||
const source = join(root, 'dist-exe', 'resources')
|
||||
const destination = join(root, 'carrier', 'resources')
|
||||
const bin = 'primary-runtime/dependencies/python/bin'
|
||||
await mkdir(join(source, bin), { recursive: true })
|
||||
await mkdir(join(source, 'primary-runtime/dependencies/python/lib/python3.12/site-packages'), { recursive: true })
|
||||
await writeFile(join(source, 'primary-runtime/runtime.json'), JSON.stringify({
|
||||
desktopVersion: '1', platform: process.platform, arch: process.arch, python: '3.12.14', pythonPackages: {},
|
||||
}))
|
||||
await writeFile(join(source, bin, 'python3.12'), 'interpreter')
|
||||
for (const alias of ['python', 'python3']) await symlink('python3.12', join(source, bin, alias))
|
||||
await mkdir(destination, { recursive: true })
|
||||
await writeFile(join(destination, 'stale'), 'previous product')
|
||||
|
||||
await syncPythonRuntimeProduct(source, destination)
|
||||
await rm(join(root, 'dist-exe'), { recursive: true })
|
||||
|
||||
await expect(stat(join(destination, 'stale'))).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
const paths = await resolvePrimaryRuntime(join(destination, 'primary-runtime'))
|
||||
expect(await readFile(paths.python, 'utf8')).toBe('interpreter')
|
||||
for (const alias of ['python', 'python3']) {
|
||||
expect(await readlink(join(destination, bin, alias))).toBe('python3.12')
|
||||
expect(await readFile(join(destination, bin, alias), 'utf8')).toBe('interpreter')
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,17 @@
|
||||
/** Copy SDK runtime products while preserving relocatable resource links. */
|
||||
import { chmod, copyFile, cp, rm, stat } from 'node:fs/promises'
|
||||
|
||||
/**
|
||||
* Replace one executable or resource directory in the Python development carrier.
|
||||
* @param source - Built product with any relative links contained in its resource tree.
|
||||
* @param destination - Product path inside the prepared carrier directory.
|
||||
* @returns Resolves after copying the product and retaining its executable permissions.
|
||||
*/
|
||||
export async function syncPythonRuntimeProduct(source: string, destination: string): Promise<void> {
|
||||
const entry = await stat(source)
|
||||
if (entry.isDirectory()) {
|
||||
await rm(destination, { recursive: true, force: true })
|
||||
await cp(source, destination, { recursive: true, verbatimSymlinks: true })
|
||||
} else await copyFile(source, destination)
|
||||
await chmod(destination, entry.mode & 0o777)
|
||||
}
|
||||
@@ -175,7 +175,8 @@ describe('Python runtime executable builder CLI', () => {
|
||||
expect(result.status).toBe(0)
|
||||
expect(result.stdout).toContain('exec pkg')
|
||||
expect(result.stdout).toContain('--sea --targets node24-macos-x64')
|
||||
expect(result.stdout).toContain('prepare Python and Office skills for mac-x64')
|
||||
expect(result.stdout).toContain('keep only node-pty prebuilds darwin-x64')
|
||||
expect(result.stdout).toContain('lock optional resource downloads and copy Office skills')
|
||||
expect(result.stdout).toContain(join(root, 'dist-exe', 'macos-x64'))
|
||||
})
|
||||
|
||||
|
||||
@@ -6,17 +6,21 @@
|
||||
* runtime imports that pkg cannot discover statically.
|
||||
*/
|
||||
|
||||
import { createHash } from 'node:crypto'
|
||||
import { build as bundle } from 'tsdown'
|
||||
import { spawn } from 'node:child_process'
|
||||
import { pnpmInvocation, restoreLegacyHoists } from './executable-packaging.ts'
|
||||
import { existsSync, statSync } from 'node:fs'
|
||||
import { chmod, copyFile, cp, mkdir, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { chmod, copyFile, cp, glob, mkdir, readFile, readdir, rm, writeFile } from 'node:fs/promises'
|
||||
import { basename, dirname, join, resolve, sep } from 'node:path'
|
||||
import { parseArgs } from 'node:util'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { resolveLinuxNodePtyAddon, resolveWindowsNodePtyAddons } from './executable-native-pty.ts'
|
||||
import { copyOfficeSidecar, OFFICE_ASSET_IGNORES } from './build-exe-for-python-sdk-office.ts'
|
||||
import { officeSidecarArchives, runtimeNpmArchive, OFFICE_ASSET_IGNORES } from './build-exe-for-python-sdk-office.ts'
|
||||
import { syncPythonRuntimeProduct } from './build-exe-for-python-sdk-resources.ts'
|
||||
import { deduplicateStagedWorkspacePackages, materializeStagedLinks } from './build-exe-for-python-sdk-staging.ts'
|
||||
import { preparePrimaryRuntime, smokePrimaryRuntime, type PrimaryRuntimeTarget } from './primary-runtime/prepare.ts'
|
||||
import { prepareOfficeSkillAssets } from './primary-runtime/prepare.ts'
|
||||
import primaryLock from './primary-runtime/lock.json' with { type: 'json' }
|
||||
|
||||
const root = resolve(import.meta.dirname, '..')
|
||||
|
||||
@@ -45,6 +49,7 @@ const DEPLOY_ONLY_DOCS = ['README.md', 'README.zh.md', 'README.i18n.yaml']
|
||||
*/
|
||||
const ASSET_GLOBS = [
|
||||
'package.json',
|
||||
'*.mjs',
|
||||
'node_modules/**/*.js',
|
||||
'node_modules/**/*.cjs',
|
||||
'node_modules/**/*.mjs',
|
||||
@@ -301,6 +306,9 @@ class SingleExeBuild {
|
||||
for (const name of DEPLOY_ONLY_DOCS) console.log(`build-exe-for-python-sdk: [dry-run] rm -f ${join(this.staging, name)}`)
|
||||
} else {
|
||||
await Promise.all(DEPLOY_ONLY_DOCS.map(name => rm(join(this.staging, name), { force: true })))
|
||||
for await (const file of glob('node_modules/**/{README*.md,CHANGELOG*.md,HISTORY*.md,*.map,*.d.ts,*.d.mts,*.d.cts}', {
|
||||
cwd: this.staging, exclude: ['node_modules/**/assets/**'],
|
||||
})) await rm(join(this.staging, file), { force: true })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,7 +339,14 @@ class SingleExeBuild {
|
||||
|
||||
/** Add the executable entry and pkg assets to the staged manifest. */
|
||||
async injectPkgConfig(): Promise<void> {
|
||||
const patch = { bin: ENTRY_BIN, pkg: { assets: ASSET_GLOBS, ignore: OFFICE_ASSET_IGNORES } }
|
||||
const sourceModules = join(root, 'node_modules').replaceAll('\\', '/')
|
||||
const patch = { bin: ENTRY_BIN, pkg: { assets: ASSET_GLOBS, ignore: [
|
||||
...OFFICE_ASSET_IGNORES,
|
||||
`${sourceModules}/**`, `${sourceModules}/.pnpm/**`,
|
||||
...['packages', 'apps', 'vendor', 'native', 'scripts'].map(directory => `${join(root, directory).replaceAll('\\', '/')}/**`),
|
||||
`${root.replaceAll('\\', '/')}/tsconfig*.json`,
|
||||
'**/*.map', '**/*.d.ts', '**/*.d.mts', '**/*.d.cts',
|
||||
] } }
|
||||
const manifestPath = join(this.staging, 'package.json')
|
||||
if (this.cli.dryRun) {
|
||||
console.log(`build-exe-for-python-sdk: [dry-run] patch ${manifestPath} with ${JSON.stringify(patch)}`)
|
||||
@@ -343,8 +358,28 @@ class SingleExeBuild {
|
||||
if (!existsSync(join(this.staging, ENTRY_BIN))) {
|
||||
throw new Error(`build-exe-for-python-sdk: staged bootstrap ${join(this.staging, ENTRY_BIN)} is missing.`)
|
||||
}
|
||||
const helpers = [
|
||||
{ name: 'primary-runtime', source: 'scripts/primary-runtime/prepare.ts', exports: 'downloadNodeRuntime, preparePrimaryRuntime' },
|
||||
{ name: 'office-sidecar', source: 'scripts/build-exe-for-python-sdk-office.ts', exports: 'downloadOfficeSidecar' },
|
||||
]
|
||||
const entries: Record<string, string> = {}
|
||||
for (const helper of helpers) {
|
||||
const entry = join(this.staging, `.${helper.name}-entry.ts`)
|
||||
entries[helper.name] = entry
|
||||
await writeFile(entry, `export { ${helper.exports} } from ${JSON.stringify(join(root, helper.source).replaceAll('\\', '/'))}\n`)
|
||||
}
|
||||
try {
|
||||
await bundle({ config: false, tsconfig: false, inputOptions: { tsconfig: false }, target: 'es2024', entry: entries,
|
||||
outDir: this.staging, clean: false, format: 'esm', platform: 'node', dts: false,
|
||||
deps: { neverBundle: [/^@deepseek-ai\//u], alwaysBundle: [/.*/u] }, shims: true, outExtensions: () => ({ js: '.mjs' }),
|
||||
define: { 'import.meta.main': 'false' } })
|
||||
} finally {
|
||||
for (const entry of Object.values(entries)) await rm(entry, { force: true })
|
||||
}
|
||||
const manifest = JSON.parse(await readFile(manifestPath, 'utf8')) as Record<string, unknown>
|
||||
await writeFile(manifestPath, `${JSON.stringify({ ...manifest, ...patch }, null, 2)}\n`)
|
||||
await this.run('resource helper imports', process.execPath, ['--input-type=module', '--eval',
|
||||
['primary-runtime.mjs', 'office-sidecar.mjs'].map(file => `await import(${JSON.stringify(pathToFileURL(join(this.staging, file)).href)})`).join('\n')])
|
||||
console.log(`build-exe-for-python-sdk: injected pkg config into ${manifestPath}`)
|
||||
}
|
||||
|
||||
@@ -357,6 +392,7 @@ class SingleExeBuild {
|
||||
const productBase = join(this.outDir, `${OUTPUT_BASENAME}-${target.platform}-${target.arch}`)
|
||||
const product = target.platform === 'win' ? `${productBase}.exe` : productBase
|
||||
await this.prepareNativePty(target)
|
||||
const platform = target.platform === 'macos' ? 'darwin' : target.platform === 'win' ? 'win32' : target.platform
|
||||
if (!this.cli.dryRun) await mkdir(this.outDir, { recursive: true })
|
||||
await this.runPnpm(`pkg ${target.spec}`, [
|
||||
'exec',
|
||||
@@ -371,26 +407,22 @@ class SingleExeBuild {
|
||||
if (!this.cli.dryRun && !existsSync(product)) {
|
||||
throw new Error(`build-exe-for-python-sdk: product ${product} is missing after the pkg run; inspect ${this.outDir}.`)
|
||||
}
|
||||
const office = `${productBase}-office`
|
||||
if (this.cli.dryRun) {
|
||||
console.log(`build-exe-for-python-sdk: [dry-run] copy Office dependency closure from ${this.staging} to ${office}`)
|
||||
} else {
|
||||
const platform = target.platform === 'macos' ? 'darwin' : target.platform === 'win' ? 'win32' : target.platform
|
||||
const packages = await copyOfficeSidecar(this.staging, office, { platform, arch: target.arch })
|
||||
console.log(`build-exe-for-python-sdk: copied ${packages.length} Office packages to ${office}`)
|
||||
}
|
||||
const ripgrep = await this.copyRipgrepSidecar(target, product)
|
||||
const resources = join(this.outDir, `${target.platform}-${target.arch}`)
|
||||
const runtimeTarget = `${target.platform === 'macos' ? 'mac' : target.platform}-${target.arch}` as PrimaryRuntimeTarget
|
||||
if (this.cli.dryRun) {
|
||||
console.log(`build-exe-for-python-sdk: [dry-run] prepare Python and Office skills for ${runtimeTarget} in ${resources}`)
|
||||
console.log(`build-exe-for-python-sdk: [dry-run] lock optional resource downloads and copy Office skills to ${resources}`)
|
||||
} else {
|
||||
const { version } = JSON.parse(await readFile(join(root, 'package.json'), 'utf8')) as { version: string }
|
||||
await preparePrimaryRuntime({ target: runtimeTarget, output: resources,
|
||||
cache: join(tmpdir(), 'dsh-primary-runtime-downloads'), version })
|
||||
smokePrimaryRuntime(join(resources, 'primary-runtime'))
|
||||
await rm(resources, { recursive: true, force: true })
|
||||
await mkdir(resources, { recursive: true })
|
||||
const { version, packageManager } = JSON.parse(await readFile(join(root, 'package.json'), 'utf8')) as { version: string; packageManager: string }
|
||||
const office = await officeSidecarArchives(this.staging, { platform, arch: target.arch })
|
||||
const pnpm = await runtimeNpmArchive('pnpm', packageManager.replace('pnpm@', ''))
|
||||
const inputs = { version, target: `${target.platform === 'macos' ? 'mac' : target.platform}-${target.arch}`, office, pnpm }
|
||||
const identity = createHash('sha256').update(JSON.stringify({ ...inputs, primaryLock })).digest('hex')
|
||||
await writeFile(join(resources, 'downloads.json'), JSON.stringify({ ...inputs, identity }, undefined, 2) + '\n')
|
||||
await prepareOfficeSkillAssets(join(this.staging, 'node_modules/@deepseek-ai/dsh-skill-office/assets'), join(resources, 'office-skills'))
|
||||
}
|
||||
if (target.platform !== 'macos') return [product, ripgrep, office, resources]
|
||||
if (target.platform !== 'macos') return [product, ripgrep, resources]
|
||||
const spawnHelper = `${product}-spawn-helper`
|
||||
const source = join(this.staging, 'node_modules', 'node-pty', 'prebuilds', `darwin-${target.arch}`, 'spawn-helper')
|
||||
if (this.cli.dryRun) {
|
||||
@@ -399,7 +431,7 @@ class SingleExeBuild {
|
||||
await copyFile(source, spawnHelper)
|
||||
await chmod(spawnHelper, 0o755)
|
||||
}
|
||||
return [product, ripgrep, spawnHelper, office, resources]
|
||||
return [product, ripgrep, spawnHelper, resources]
|
||||
}
|
||||
|
||||
/** Copy the target ripgrep binary beside the executable so Node can spawn it outside pkg's virtual filesystem. */
|
||||
@@ -446,6 +478,17 @@ class SingleExeBuild {
|
||||
'node_modules',
|
||||
'node-pty',
|
||||
)
|
||||
const platform = target.platform === 'macos' ? 'darwin' : target.platform === 'win' ? 'win32' : target.platform
|
||||
const selected = `${platform}-${target.arch}`
|
||||
const prebuilds = join(this.staging, 'node_modules/node-pty/prebuilds')
|
||||
if (this.cli.dryRun) console.log(`build-exe-for-python-sdk: [dry-run] keep only node-pty prebuilds ${selected}`)
|
||||
else {
|
||||
const source = join(packageDirectory, 'prebuilds', selected)
|
||||
if (existsSync(source)) await cp(source, join(prebuilds, selected), { recursive: true })
|
||||
for (const entry of await readdir(prebuilds, { withFileTypes: true })) {
|
||||
if (entry.isDirectory() && entry.name !== selected) await rm(join(prebuilds, entry.name), { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
if (target.platform === 'win') {
|
||||
if (target.arch !== 'x64') {
|
||||
throw new Error('build-exe-for-python-sdk: Windows supports x64 only.')
|
||||
@@ -514,11 +557,7 @@ class SingleExeBuild {
|
||||
await mkdir(destDir, { recursive: true })
|
||||
for (const path of products) {
|
||||
const destination = join(destDir, basename(path))
|
||||
if (statSync(path).isDirectory()) {
|
||||
await rm(destination, { recursive: true, force: true })
|
||||
await cp(path, destination, { recursive: true })
|
||||
} else await copyFile(path, destination)
|
||||
await chmod(destination, statSync(path).mode & 0o777)
|
||||
await syncPythonRuntimeProduct(path, destination)
|
||||
console.log(`build-exe-for-python-sdk: synced ${destination}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,11 +56,6 @@ def runtime_filenames(executable_name: str) -> tuple[str, ...]:
|
||||
return (*names, f"{executable_name}-spawn-helper") if "-macos-" in executable_name else names
|
||||
|
||||
|
||||
def office_sidecar_name(executable_name: str) -> str:
|
||||
"""Return the complete Office dependency directory for one executable."""
|
||||
return f"{executable_name.removesuffix('.exe')}-office"
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--package", choices=("sdk", "runtime"), required=True)
|
||||
@@ -229,54 +224,19 @@ def stage_runtime(destination: Path, version: str, executable: Path, executable_
|
||||
source_directory = executable.parent
|
||||
for filename in runtime_filenames(executable_name):
|
||||
shutil.copy2(source_directory / filename, runtime_dir / filename)
|
||||
office = office_sidecar_name(executable_name)
|
||||
shutil.copytree(source_directory / office, runtime_dir / office)
|
||||
resources = executable_name.removeprefix("deepseek-harness-sdk-runtime-").removesuffix(".exe")
|
||||
# Wheels materialize interpreter aliases because pip does not restore symlinks.
|
||||
shutil.copytree(source_directory / resources, runtime_dir / resources)
|
||||
|
||||
|
||||
def verify_office_payload(archive: zipfile.ZipFile, office_modules: str, platform_tag: str) -> None:
|
||||
"""Check packaged engine assets and native helper executable permissions."""
|
||||
names = set(archive.namelist())
|
||||
adapter = f"{office_modules}/@deepseek-ai/libreoffice-kit/package.json"
|
||||
if adapter not in names:
|
||||
raise RuntimeError("Office dependency is missing: libreoffice-kit")
|
||||
engines = f"{office_modules}/@deepseek-ai"
|
||||
target = next(name for name, value in PLATFORMS.items() if value[0] == platform_tag)
|
||||
native_target = target.replace("win-", "win32-").replace("macos-", "darwin-")
|
||||
declared = json.loads(archive.read(adapter)).get("optionalDependencies", {})
|
||||
selected = native_target if f"@deepseek-ai/libreoffice-kit-{native_target}" in declared else "wasm"
|
||||
for required in (f"libreoffice-kit-{selected}/prebuilds.json",):
|
||||
if f"{engines}/{required}" not in names:
|
||||
raise RuntimeError(f"Office dependency is missing: {required}")
|
||||
manifests = (
|
||||
name for name in names
|
||||
if name.startswith(f"{engines}/libreoffice-kit-")
|
||||
and name.endswith("/prebuilds.json")
|
||||
and name.count("/") == engines.count("/") + 2
|
||||
)
|
||||
for manifest_path in manifests:
|
||||
if manifest_path != f"{engines}/libreoffice-kit-{selected}/prebuilds.json":
|
||||
raise RuntimeError(f"Unexpected Office engine for {platform_tag}: {manifest_path}")
|
||||
manifest = json.loads(archive.read(manifest_path))
|
||||
engine = manifest["engine"]
|
||||
native = engine["kind"] == "native"
|
||||
fields = ("executable",) if native else ("loader", "wasm", "data", "metadata")
|
||||
for field in fields:
|
||||
asset = f"{manifest_path.rsplit('/', 1)[0]}/{engine[field]}"
|
||||
if asset not in names:
|
||||
raise RuntimeError(f"Office engine asset is missing: {asset}")
|
||||
mode = archive.getinfo(asset).external_attr >> 16
|
||||
if native and platform_tag != "win_amd64" and mode & stat.S_IXUSR == 0:
|
||||
raise RuntimeError(f"Office helper lost its executable bit: {asset}")
|
||||
|
||||
|
||||
def verify_wheel(
|
||||
wheel: Path,
|
||||
package: str,
|
||||
version: str,
|
||||
platform: tuple[str, str] | None,
|
||||
) -> None:
|
||||
if wheel.stat().st_size > 100_000_000:
|
||||
raise RuntimeError(f"{wheel} is {wheel.stat().st_size} bytes and exceeds the PyPI single-file limit of 100000000 bytes")
|
||||
expected_tag = "py3-none-any" if platform is None else f"py3-none-{platform[0]}"
|
||||
expected_distribution = SDK_DISTRIBUTION if package == "sdk" else RUNTIME_DISTRIBUTION
|
||||
dist_info = f"{expected_distribution.replace('-', '_')}-{version}.dist-info"
|
||||
@@ -308,15 +268,12 @@ def verify_wheel(
|
||||
]
|
||||
if package == "runtime":
|
||||
assert platform is not None
|
||||
office = office_sidecar_name(platform[1])
|
||||
resources = platform[1].removeprefix("deepseek-harness-sdk-runtime-").removesuffix(".exe")
|
||||
expected_files = sorted((*runtime_filenames(platform[1]), office, resources))
|
||||
expected_files = sorted((*runtime_filenames(platform[1]), resources))
|
||||
found_files = sorted({name.split("/runtime/", 1)[1].split("/", 1)[0] for name in runtime_payload})
|
||||
if found_files != expected_files:
|
||||
raise RuntimeError(f"{wheel} runtime payload must be {expected_files}, found {found_files}")
|
||||
office_modules = f"deepseek_harness_runtime/runtime/{office}/node_modules"
|
||||
verify_office_payload(archive, office_modules, platform[0])
|
||||
validate = runpy.run_path(str(ROOT / "python/sdk-runtime/src/deepseek_harness_runtime/_resources.py"))["validate_resources"]
|
||||
validate = runpy.run_path(str(ROOT / "python/sdk-runtime/src/deepseek_harness_runtime/_resources.py"))["validate_downloads"]
|
||||
target = next(name for name, value in PLATFORMS.items() if value == platform)
|
||||
validate(zipfile.Path(archive, f"deepseek_harness_runtime/runtime/{resources}/"), target)
|
||||
for runtime_file in runtime_payload:
|
||||
|
||||
@@ -929,19 +929,19 @@ describe('Runtime and LLM e2e Blacksmith routing', () => {
|
||||
it('keeps native release and dispatch builders hosted while routing x64 CI by platform', () => {
|
||||
const workflow = loadWorkflow('.github/workflows/build-exe-for-python-sdk.yml')
|
||||
const build = workflowJob(workflow, 'build')
|
||||
for (const [target, runner, variable, blacksmith] of [
|
||||
['node24-linux-x64', 'ubuntu-latest', 'DSH_CI_FAILOVER_LINUX', 'blacksmith-2vcpu-ubuntu-2404'],
|
||||
['node24-win-x64', 'windows-2025', 'DSH_CI_FAILOVER_WINDOWS', 'blacksmith-2vcpu-windows-2025'],
|
||||
['node24-linux-arm64', 'ubuntu-24.04-arm', 'DSH_CI_FAILOVER_LINUX', 'ubuntu-24.04-arm'],
|
||||
['node24-macos-arm64', 'macos-latest', 'DSH_CI_FAILOVER_LINUX', 'macos-latest'],
|
||||
['node24-macos-x64', 'macos-15-intel', 'DSH_CI_FAILOVER_LINUX', 'macos-15-intel'],
|
||||
for (const [target, runner, variable, blacksmith, releaseRunner] of [
|
||||
['node24-linux-x64', 'ubuntu-latest', 'DSH_CI_FAILOVER_LINUX', 'blacksmith-2vcpu-ubuntu-2404', 'ubuntu-latest'],
|
||||
['node24-win-x64', 'windows-2025', 'DSH_CI_FAILOVER_WINDOWS', 'blacksmith-2vcpu-windows-2025', 'windows-2025'],
|
||||
['node24-linux-arm64', 'ubuntu-24.04-arm', 'DSH_CI_FAILOVER_LINUX', 'ubuntu-24.04-arm', 'ubuntu-24.04-arm'],
|
||||
['node24-macos-arm64', 'macos-latest', 'DSH_CI_FAILOVER_LINUX', 'macos-latest', 'macos-15-xlarge'],
|
||||
['node24-macos-x64', 'macos-15-intel', 'DSH_CI_FAILOVER_LINUX', 'macos-15-intel', 'macos-15-large'],
|
||||
] as const) {
|
||||
for (const ci of [false, true]) {
|
||||
for (const release of [false, true]) {
|
||||
for (const mode of ['', 'selfhosted', 'unexpected', 'blacksmith']) {
|
||||
const vars = { DSH_CI_FAILOVER_LINUX: 'blacksmith', DSH_CI_FAILOVER_WINDOWS: 'blacksmith', [variable]: mode }
|
||||
expect(evaluateRunsOn(build['runs-on'], { inputs: { ci, release }, vars, matrix: { target, runner } }), `${target} ci=${ci} release=${release} mode=${mode}`)
|
||||
.toBe(ci && !release && mode === 'blacksmith' ? blacksmith : runner)
|
||||
.toBe(release ? releaseRunner : ci && mode === 'blacksmith' ? blacksmith : runner)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -184,10 +184,12 @@ describe('client bundle purity gate', () => {
|
||||
neverBundle: (specifier: string) => boolean
|
||||
}
|
||||
|
||||
expect(requesting.neverBundle('react')).toBe(true)
|
||||
expect(requesting.neverBundle('zod')).toBe(false)
|
||||
expect(plain.neverBundle('react')).toBe(true)
|
||||
expect(plain.neverBundle('@deepseek-ai/dsh-client-store')).toBe(true)
|
||||
for (const bundle of [requesting, plain]) {
|
||||
for (const specifier of ['react', 'zod', '@tanstack/react-virtual', '@deepseek-ai/dsh-client-store']) {
|
||||
expect(bundle.neverBundle(specifier)).toBe(true)
|
||||
}
|
||||
expect(bundle.neverBundle('zod/v3')).toBe(false)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ async function temporaryRoot(): Promise<string> {
|
||||
}
|
||||
|
||||
describe('coverage file timing report', () => {
|
||||
it('includes import and hook costs once without serializing coverage or test objects', async () => {
|
||||
it('preserves duplicate file records and costs without serializing coverage or test objects', async () => {
|
||||
const root = await temporaryRoot()
|
||||
const reporter = new CoverageFileTimesReporter()
|
||||
reporter.onInit({ config: { root, outputFile: { fileTimes: 'times.json' } } })
|
||||
@@ -38,10 +38,13 @@ describe('coverage file timing report', () => {
|
||||
// timing report must read only their paths and diagnostics.
|
||||
toJSON: () => { throw new Error('test module was serialized') },
|
||||
}
|
||||
await reporter.onTestRunEnd([module])
|
||||
await reporter.onTestRunEnd([module, module])
|
||||
|
||||
const output = await readFile(join(root, 'times.json'), 'utf8')
|
||||
expect(JSON.parse(output)).toEqual({ 'packages/a/tests/x.spec.ts': 315 })
|
||||
expect(JSON.parse(output)).toEqual([
|
||||
{ file: 'packages/a/tests/x.spec.ts', duration: 315 },
|
||||
{ file: 'packages/a/tests/x.spec.ts', duration: 315 },
|
||||
])
|
||||
expect(output.endsWith('\n')).toBe(true)
|
||||
expect(output).not.toContain('coverageMap')
|
||||
expect(output).not.toContain('assertionResults')
|
||||
@@ -52,7 +55,7 @@ describe('coverage file timing report', () => {
|
||||
const reporter = new CoverageFileTimesReporter()
|
||||
reporter.onInit({ config: { root, outputFile: { fileTimes: 'times.json' } } })
|
||||
await reporter.onTestRunEnd([])
|
||||
expect(await readFile(join(root, 'times.json'), 'utf8')).toBe('{}\n')
|
||||
expect(await readFile(join(root, 'times.json'), 'utf8')).toBe('[]\n')
|
||||
})
|
||||
|
||||
const missingOutputs: ResolvedConfig['outputFile'][] = ['report.json', {}, { fileTimes: '' }]
|
||||
|
||||
@@ -3,7 +3,7 @@ import { writeFile } from 'node:fs/promises'
|
||||
import { relative, resolve, sep } from 'node:path'
|
||||
import type { Reporter, ResolvedConfig, TestModule } from 'vitest/node'
|
||||
|
||||
/** Vitest reporter that writes repository-relative file durations to `outputFile.fileTimes`. */
|
||||
/** Vitest reporter that writes repository-relative file and duration records to `outputFile.fileTimes`. */
|
||||
export default class CoverageFileTimesReporter implements Reporter {
|
||||
private root = ''
|
||||
private outputFile = ''
|
||||
@@ -28,16 +28,16 @@ export default class CoverageFileTimesReporter implements Reporter {
|
||||
* @returns after the compact timing report has been written.
|
||||
*/
|
||||
public async onTestRunEnd(testModules: readonly Pick<TestModule, 'moduleId' | 'diagnostic'>[]): Promise<void> {
|
||||
const durations: Record<string, number> = {}
|
||||
for (const module of testModules) {
|
||||
const records = testModules.map((module) => {
|
||||
const diagnostic = module.diagnostic()
|
||||
const file = relative(this.root, module.moduleId).split(sep).join('/')
|
||||
durations[file] = diagnostic.environmentSetupDuration
|
||||
const duration = diagnostic.environmentSetupDuration
|
||||
+ diagnostic.prepareDuration
|
||||
+ diagnostic.setupDuration
|
||||
+ diagnostic.collectDuration
|
||||
+ diagnostic.duration
|
||||
}
|
||||
await writeFile(this.outputFile, `${JSON.stringify(durations)}\n`, 'utf8')
|
||||
return { file, duration }
|
||||
})
|
||||
await writeFile(this.outputFile, `${JSON.stringify(records)}\n`, 'utf8')
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
forwardedCoverageArgs,
|
||||
parseCoveragePartitionCount,
|
||||
parseCoverageTestTimeout,
|
||||
parseListOutput,
|
||||
parseFileInventory,
|
||||
readFileDurations,
|
||||
writeFileDurations,
|
||||
type CoverageCommand,
|
||||
@@ -40,6 +40,11 @@ async function writeBlob(command: CoverageCommand): Promise<void> {
|
||||
if (command.blobPath === undefined) return
|
||||
await mkdir(dirname(command.blobPath), { recursive: true })
|
||||
await writeFile(command.blobPath, '{}')
|
||||
const configArgument = command.args.find(argument => argument.startsWith('--config='))!
|
||||
const source = await readFile(join(command.cwd, configArgument.slice('--config='.length)), 'utf8')
|
||||
const files = [...source.matchAll(/"([^"\n]+\.spec\.tsx?)"/g)].map(match => match[1]!)
|
||||
const reportArgument = command.args.find(argument => argument.startsWith('--outputFile.fileTimes='))!
|
||||
await writeFile(join(command.cwd, reportArgument.slice('--outputFile.fileTimes='.length)), JSON.stringify(files.map(file => ({ file, duration: 0 }))))
|
||||
}
|
||||
|
||||
async function temporaryRoot(): Promise<string> {
|
||||
@@ -196,24 +201,36 @@ describe('weighted partition assignment', () => {
|
||||
})
|
||||
|
||||
describe('coverage file inventory', () => {
|
||||
it('parses vitest list --filesOnly output, keeps project ownership, and drops exempt suites', async () => {
|
||||
it('keeps JSON file paths and project ownership while dropping exempt suites', async () => {
|
||||
const root = await temporaryRoot()
|
||||
const exemptDir = join(root, 'packages/experimental/webworker-runtime/tests')
|
||||
await mkdir(exemptDir, { recursive: true })
|
||||
await writeFile(join(exemptDir, 'transform-corpus.spec.ts'), '')
|
||||
const output = [
|
||||
'[thread-safe] packages/a/tests/a.spec.ts',
|
||||
'[process-bound] packages/b/tests/b.spec.ts',
|
||||
'[thread-safe] packages/experimental/webworker-runtime/tests/transform-corpus.spec.ts',
|
||||
'not a test line',
|
||||
].join('\n')
|
||||
const inventory = parseListOutput(output, root)
|
||||
const output = JSON.stringify([
|
||||
{ projectName: 'thread-safe', file: join(root, 'packages/a/tests/a.spec.ts') },
|
||||
{ projectName: 'process-bound', file: join(root, 'packages/b/tests/with spaces.spec.ts') },
|
||||
{ projectName: 'thread-safe', file: join(exemptDir, 'transform-corpus.spec.ts') },
|
||||
])
|
||||
const inventory = parseFileInventory(output, root)
|
||||
expect(inventory.files).toEqual([
|
||||
'packages/a/tests/a.spec.ts',
|
||||
'packages/b/tests/b.spec.ts',
|
||||
'packages/b/tests/with spaces.spec.ts',
|
||||
])
|
||||
expect(inventory.projectOf.get('packages/a/tests/a.spec.ts')).toBe('thread-safe')
|
||||
expect(inventory.projectOf.get('packages/b/tests/b.spec.ts')).toBe('process-bound')
|
||||
expect(inventory.projectOf.get('packages/b/tests/with spaces.spec.ts')).toBe('process-bound')
|
||||
})
|
||||
|
||||
it.each(['[', '{}', '[null]', '[{}]', '[{"file":42}]', '[{"file":"a.spec.ts","projectName":"unknown"}]'])('rejects malformed inventories instead of dropping entries: %s', async (output) => {
|
||||
const root = await temporaryRoot()
|
||||
expect(() => parseFileInventory(output, root)).toThrow()
|
||||
})
|
||||
|
||||
it('rejects duplicate file ownership', async () => {
|
||||
const root = await temporaryRoot()
|
||||
const file = join(root, 'a.spec.ts')
|
||||
expect(() => parseFileInventory(JSON.stringify([
|
||||
{ file, projectName: 'thread-safe' }, { file, projectName: 'process-bound' },
|
||||
]), root)).toThrow('more than once')
|
||||
})
|
||||
|
||||
it('removes every Typert package from instrumented files and project assignments', async () => {
|
||||
@@ -230,8 +247,8 @@ describe('coverage file inventory', () => {
|
||||
await writeFile(join(root, file), '')
|
||||
}
|
||||
const retained = 'packages/api/gateway/tests/rpc.spec.ts'
|
||||
const inventory = parseListOutput(
|
||||
[...typertFiles, retained].map(file => `[thread-safe] ${file}`).join('\n'),
|
||||
const inventory = parseFileInventory(
|
||||
JSON.stringify([...typertFiles, retained].map(file => ({ projectName: 'thread-safe', file: join(root, file) }))),
|
||||
root,
|
||||
)
|
||||
expect(inventory.files).toEqual([retained])
|
||||
@@ -272,19 +289,21 @@ describe('coverage file inventory', () => {
|
||||
it('extracts per-file durations from compact partition timing reports', async () => {
|
||||
const root = await temporaryRoot()
|
||||
const report = join(root, 'partition-1.times.json')
|
||||
await writeFile(report, JSON.stringify({
|
||||
'packages/a/tests/x.spec.ts': 500,
|
||||
'packages/a/tests/y.spec.ts': 0,
|
||||
'packages/a/tests/invalid.spec.ts': -1,
|
||||
'packages/a/tests/malformed.spec.ts': 'unknown',
|
||||
}))
|
||||
await writeFile(report, JSON.stringify([
|
||||
{ file: 'packages/a/tests/x.spec.ts', duration: 500 },
|
||||
{ file: 'packages/a/tests/y.spec.ts', duration: 0 },
|
||||
{ file: 'packages/a/tests/invalid.spec.ts', duration: -1 },
|
||||
{ file: 'packages/a/tests/malformed.spec.ts', duration: 'unknown' },
|
||||
null,
|
||||
{ duration: 10 },
|
||||
]))
|
||||
const durations = collectPartitionDurations([report])
|
||||
expect(durations.get('packages/a/tests/x.spec.ts')).toBe(500)
|
||||
expect(durations.get('packages/a/tests/y.spec.ts')).toBe(0)
|
||||
expect(durations.size).toBe(2)
|
||||
})
|
||||
|
||||
it.each(['null', '[]', '42', '"invalid"', '{'])('ignores corrupt timing metadata %s', async (contents) => {
|
||||
it.each(['null', '{}', '42', '"invalid"', '{'])('ignores corrupt timing metadata %s', async (contents) => {
|
||||
const root = await temporaryRoot()
|
||||
const report = join(root, 'partition.times.json')
|
||||
await writeFile(report, contents)
|
||||
@@ -442,6 +461,31 @@ describe('coverage location canonicalization', () => {
|
||||
})
|
||||
|
||||
describe('coverage partition coordinator', () => {
|
||||
it.each(['omitted', 'unexpected', 'duplicate', 'malformed', 'unnamed', 'missing-report'])('refuses %s test results even when every partition exits successfully', async (failure) => {
|
||||
const root = await temporaryRoot()
|
||||
const runCommand = vi.fn(async (command: CoverageCommand) => {
|
||||
await writeBlob(command)
|
||||
if (command.label === 'partition 1/2') {
|
||||
const reportArgument = command.args.find(argument => argument.startsWith('--outputFile.fileTimes='))!
|
||||
const reportPath = join(root, reportArgument.slice('--outputFile.fileTimes='.length))
|
||||
let report = JSON.parse(await readFile(reportPath, 'utf8')) as Array<{ file: string; duration: number }>
|
||||
if (failure === 'omitted') report = []
|
||||
if (failure === 'unexpected') report.push({ file: 'unassigned.spec.ts', duration: 0 })
|
||||
if (failure === 'duplicate') report.push(report[0]!)
|
||||
await writeFile(reportPath, failure === 'malformed' ? '{}' : JSON.stringify(report))
|
||||
if (failure === 'unnamed') await writeFile(reportPath, '[{}]')
|
||||
if (failure === 'missing-report') await rm(reportPath)
|
||||
}
|
||||
return passed
|
||||
})
|
||||
const coordinator = new CoveragePartitionCoordinator({
|
||||
root, partitions: 2, pnpmEntrypoint: '/pnpm.cjs', files: ['a.spec.ts', 'b.spec.ts'], runCommand,
|
||||
})
|
||||
await expect(coordinator.run()).rejects.toThrow()
|
||||
expect(runCommand).toHaveBeenCalledTimes(2)
|
||||
await expect(access(join(root, 'coverage/.partitioned/vitest-partition-1.config.ts'))).resolves.toBeUndefined()
|
||||
})
|
||||
|
||||
const weightedFiles = ['a.spec.ts', 'b.spec.ts', 'c.spec.ts']
|
||||
const weightedDurations = new Map([
|
||||
['a.spec.ts', 100],
|
||||
@@ -466,6 +510,7 @@ describe('coverage partition coordinator', () => {
|
||||
})
|
||||
|
||||
await expect(coordinator.run()).resolves.toBe(0)
|
||||
await expect(access(join(root, 'coverage/.partitioned'))).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
|
||||
// The coordinator passes a root-relative argument and runs every child with
|
||||
// the repository root as its working directory, so the argument must name
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
import { spawn } from 'node:child_process'
|
||||
import { globSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { lstat, mkdir, readdir, rm, unlink, writeFile } from 'node:fs/promises'
|
||||
import { lstat, mkdir, readdir, readFile, rm, unlink, writeFile } from 'node:fs/promises'
|
||||
import { join, relative, sep } from 'node:path'
|
||||
import type { TestUserConfig } from 'vitest/config'
|
||||
import { coverageExemptHeavySuites } from './coverage-exempt.ts'
|
||||
@@ -165,19 +165,27 @@ export interface InstrumentedInventory {
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse `vitest list --filesOnly` output into the instrumented inventory:
|
||||
* one `[pool] path` line per file, deduplicated, minus the exempt heavy
|
||||
* suites that `vitest list` itself does not exclude.
|
||||
* Parse Vitest's JSON file inventory, excluding uninstrumented heavy suites.
|
||||
* @param output - JSON written by `vitest list --filesOnly --json=<file>`.
|
||||
* @param root - repository root used to make file paths relative.
|
||||
* @returns sorted test files and their owning Vitest projects.
|
||||
* @throws when a record is malformed or a file has multiple project assignments.
|
||||
*/
|
||||
export function parseListOutput(output: string, root: string): InstrumentedInventory {
|
||||
export function parseFileInventory(output: string, root: string): InstrumentedInventory {
|
||||
const entries: unknown = JSON.parse(output)
|
||||
if (!Array.isArray(entries)) throw new Error('coverage inventory must be a JSON array')
|
||||
const files = new Set<string>()
|
||||
const projectOf = new Map<string, string>()
|
||||
for (const line of output.split(/\r?\n/)) {
|
||||
const match = /^\[([^\]]+)\]\s+(\S+\.spec\.(?:ts|tsx))$/.exec(line)
|
||||
if (match !== null && match[1] !== undefined && match[2] !== undefined) {
|
||||
files.add(match[2])
|
||||
projectOf.set(match[2], match[1])
|
||||
for (const value of entries) {
|
||||
const entry: unknown = value
|
||||
if (entry === null || typeof entry !== 'object' || !('file' in entry) || typeof entry.file !== 'string'
|
||||
|| !('projectName' in entry) || (entry.projectName !== 'thread-safe' && entry.projectName !== 'process-bound')) {
|
||||
throw new Error('coverage inventory requires a file and its thread-safe or process-bound project')
|
||||
}
|
||||
const file = relative(root, entry.file).split(sep).join('/')
|
||||
if (files.has(file)) throw new Error(`coverage inventory lists ${file} more than once`)
|
||||
files.add(file)
|
||||
projectOf.set(file, entry.projectName)
|
||||
}
|
||||
for (const suite of coverageExemptHeavySuites) {
|
||||
for (const file of globSync(suite.exclude, { cwd: root })) {
|
||||
@@ -201,26 +209,24 @@ export function parseListOutput(output: string, root: string): InstrumentedInven
|
||||
async function collectInstrumentedFiles(
|
||||
root: string,
|
||||
pnpmEntrypoint: string,
|
||||
inventoryPath: string,
|
||||
filters: readonly string[] = [],
|
||||
): Promise<InstrumentedInventory> {
|
||||
const invocation = pnpmInvocation(['exec', 'vitest', 'list', '--filesOnly', ...filters], { npm_execpath: pnpmEntrypoint })
|
||||
const output = await runListCommand(invocation.command, invocation.args, root)
|
||||
return parseListOutput(output, root)
|
||||
const invocation = pnpmInvocation(['exec', 'vitest', 'list', '--filesOnly', `--json=${inventoryPath}`, ...filters], { npm_execpath: pnpmEntrypoint })
|
||||
await runListCommand(invocation.command, invocation.args, root)
|
||||
return parseFileInventory(await readFile(inventoryPath, 'utf8'), root)
|
||||
}
|
||||
|
||||
/** Run `vitest list` and return its stdout, or throw with exit code and stderr. */
|
||||
function runListCommand(command: string, args: string[], root: string): Promise<string> {
|
||||
/** Wait for `vitest list` to write its JSON file, or throw with exit code and stderr. */
|
||||
function runListCommand(command: string, args: string[], root: string): Promise<void> {
|
||||
return new Promise((resolveList, rejectList) => {
|
||||
const child = spawn(command, args, { cwd: root, env: process.env, stdio: ['ignore', 'pipe', 'pipe'] })
|
||||
let output = ''
|
||||
const child = spawn(command, args, { cwd: root, env: process.env, stdio: ['ignore', 'ignore', 'pipe'] })
|
||||
let errorOutput = ''
|
||||
child.stdout.setEncoding('utf8')
|
||||
child.stderr.setEncoding('utf8')
|
||||
child.stdout.on('data', (chunk: string) => { output += chunk })
|
||||
child.stderr.on('data', (chunk: string) => { errorOutput += chunk })
|
||||
child.once('error', (error: Error) => { rejectList(error) })
|
||||
child.once('close', (code) => {
|
||||
if (code === 0) resolveList(output)
|
||||
if (code === 0) resolveList()
|
||||
else rejectList(new Error(`vitest list exited with ${String(code ?? 'signal')}${errorOutput === '' ? '' : `: ${errorOutput.trim().slice(0, 300)}`}`))
|
||||
})
|
||||
})
|
||||
@@ -301,7 +307,7 @@ export function writeFileDurations(
|
||||
|
||||
/**
|
||||
* Extract per-file durations from compact timing reports, one per partition.
|
||||
* @param reportFiles - reports mapping repository-relative file paths to milliseconds.
|
||||
* @param reportFiles - reports listing repository-relative file paths and milliseconds.
|
||||
* @returns finite, non-negative file costs from readable reports.
|
||||
*/
|
||||
export function collectPartitionDurations(reportFiles: readonly string[]): Map<string, number> {
|
||||
@@ -313,10 +319,13 @@ export function collectPartitionDurations(reportFiles: readonly string[]): Map<s
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
if (report === null || typeof report !== 'object' || Array.isArray(report)) continue
|
||||
for (const [path, duration] of Object.entries(report)) {
|
||||
if (typeof duration !== 'number' || !Number.isFinite(duration) || duration < 0) continue
|
||||
durations.set(path, duration)
|
||||
if (!Array.isArray(report)) continue
|
||||
for (const entry of report) {
|
||||
const record: unknown = entry
|
||||
if (record !== null && typeof record === 'object' && 'file' in record && typeof record.file === 'string'
|
||||
&& 'duration' in record && typeof record.duration === 'number' && Number.isFinite(record.duration) && record.duration >= 0) {
|
||||
durations.set(record.file, record.duration)
|
||||
}
|
||||
}
|
||||
}
|
||||
return durations
|
||||
@@ -479,13 +488,15 @@ export class CoveragePartitionCoordinator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Run every partition before one merged threshold check.
|
||||
* Run every partition and verify its test-file inventory before one merged threshold check.
|
||||
* Failed runs retain inventories, partition configs, and test reports in coverage/.partitioned.
|
||||
* @returns zero only when every partition and the merge command succeed.
|
||||
*/
|
||||
public async run(): Promise<number> {
|
||||
await removeOwnedTree(join(this.root, 'coverage'))
|
||||
await mkdir(this.blobsRoot, { recursive: true })
|
||||
|
||||
let succeeded = false
|
||||
try {
|
||||
const assignments = await this.assignFiles()
|
||||
this.assertNonEmptyAssignments(assignments)
|
||||
@@ -506,13 +517,16 @@ export class CoveragePartitionCoordinator {
|
||||
// run, but the completed partitions' timings are still worth keeping.
|
||||
this.persistDurations(this.partitions)
|
||||
await this.assertCompleteBlobSet(commands)
|
||||
await this.assertCompleteTestFiles(assignments)
|
||||
|
||||
const mergeCommand = this.mergeCommand()
|
||||
console.log(`coverage-partitions: start ${mergeCommand.label}`)
|
||||
const mergeResult = await this.runCommand(mergeCommand)
|
||||
return results.some(commandFailed) || commandFailed(mergeResult) ? 1 : 0
|
||||
succeeded = !results.some(commandFailed) && !commandFailed(mergeResult)
|
||||
return succeeded ? 0 : 1
|
||||
} finally {
|
||||
await removeOwnedTree(this.temporaryRoot)
|
||||
if (succeeded) await removeOwnedTree(this.temporaryRoot)
|
||||
else console.error(`coverage-partitions: diagnostics retained at ${this.relativePath(this.temporaryRoot)}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +573,7 @@ export class CoveragePartitionCoordinator {
|
||||
// values (`--testTimeout 5000`) must never be mistaken for filters.
|
||||
const separator = this.vitestArgs.indexOf('--')
|
||||
const filters = separator >= 0 ? this.vitestArgs.slice(separator + 1) : []
|
||||
const inventory = await collectInstrumentedFiles(this.root, this.pnpmEntrypoint, filters)
|
||||
const inventory = await collectInstrumentedFiles(this.root, this.pnpmEntrypoint, join(this.temporaryRoot, 'inventory.json'), filters)
|
||||
files = inventory.files
|
||||
this.projectOf = inventory.projectOf
|
||||
weights = readFileDurations(this.root)
|
||||
@@ -651,6 +665,30 @@ export class CoveragePartitionCoordinator {
|
||||
throw new Error(`coverage partitions produced ${JSON.stringify(actual)}; expected ${JSON.stringify(expected)}.`)
|
||||
}
|
||||
}
|
||||
|
||||
/** Require each compact timing report to account for every assigned file exactly once. */
|
||||
private async assertCompleteTestFiles(assignments: readonly (readonly string[])[]): Promise<void> {
|
||||
await Promise.all(assignments.map(async (expected, index) => {
|
||||
const path = join(this.temporaryRoot, `partition-${index + 1}.times.json`)
|
||||
const report: unknown = JSON.parse(await readFile(path, 'utf8'))
|
||||
if (!Array.isArray(report)) {
|
||||
throw new Error(`coverage partition report ${path} must contain file timing records`)
|
||||
}
|
||||
const actual = report.map((result: unknown) => {
|
||||
if (result === null || typeof result !== 'object' || !('file' in result) || typeof result.file !== 'string') {
|
||||
throw new Error(`coverage partition report ${path} contains a test result without a filename`)
|
||||
}
|
||||
return result.file
|
||||
})
|
||||
const observed = new Set(actual)
|
||||
const assigned = new Set(expected)
|
||||
const missing = expected.filter(file => !observed.has(file))
|
||||
const unexpected = actual.filter(file => !assigned.has(file))
|
||||
if (missing.length > 0 || unexpected.length > 0 || observed.size !== actual.length) {
|
||||
throw new Error(`coverage partition ${index + 1}: missing files ${JSON.stringify(missing)}; unexpected files ${JSON.stringify(unexpected)}; duplicate results ${actual.length - observed.size}`)
|
||||
}
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
/** Spawn one pnpm-backed command without a platform shell. */
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
{
|
||||
"AGENTS.md": 1960,
|
||||
"docs/AGENTS.md": 1320,
|
||||
"AGENTS.md": 2080,
|
||||
"docs/AGENTS.md": 1430,
|
||||
"docs/architecture.md": 2410,
|
||||
"docs/cordis-primer.md": 600,
|
||||
"docs/defensive-patterns.md": 550,
|
||||
"docs/testing.md": 1350,
|
||||
"packages/AGENTS.md": 750,
|
||||
"packages/AGENTS.md": 810,
|
||||
"packages/README.md": 994
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export async function apply(ctx, config) {
|
||||
if (json === undefined) throw new Error('Office skill did not supply CLI paths')
|
||||
const { libreofficeKit: { node, cli } } = JSON.parse(json)
|
||||
const options = { env: { ...process.env, PATH: '' }, timeout: 120_000 }
|
||||
const capabilities = await promisify(execFile)(node, [cli, 'capabilities'], options)
|
||||
const capabilities = await promisify(execFile)(node, [cli, 'capabilities', '--json'], options)
|
||||
await promisify(execFile)(node, [cli, 'convert', '--input', config.input, '--output', config.output + '.cli.pdf'], options)
|
||||
const pdf = await readFile(config.output + '.cli.pdf')
|
||||
if (pdf.subarray(0, 5).toString() !== '%PDF-') throw new Error('Skill CLI did not create a PDF')
|
||||
|
||||
@@ -474,9 +474,6 @@
|
||||
"bfa9b3c146cb954091623aa0ceddd08e3d346a8fd1651168021397e4d7750f1d": 2,
|
||||
"f5a208f3ac88b7d5c0de75f72c4a4652b85e21f4ebddf397bd2ff3265a66f6e2": 2
|
||||
},
|
||||
"packages/client/ui-chat/tests/chat-branch-tails.client.spec.tsx": {
|
||||
"12a4fcbcbe9194fe012835a6c0346eab98441db62b74da62f80a8cd510774c5a": 1
|
||||
},
|
||||
"packages/client/ui-chat/tests/chat-view.client.spec.tsx": {
|
||||
"6061de0a1e01547eb1abf9d4e1b5fa79fda112fa35dda980775491123413dcce": 3,
|
||||
"6787497d471fc8faaa78ffcbd497c36ceba82c1b8ee16d0d450b405ad4dddc25": 1
|
||||
@@ -552,11 +549,6 @@
|
||||
"5f1a0867b42cf35dac7fdf5839e3a39c2384c5b3b03142e799a36733ad96b9da": 1,
|
||||
"8342608ac37fdc653b6e751e7192472328c9d1baecf1f66d79a65529db5c4d6a": 1
|
||||
},
|
||||
"packages/client/ui-goal/tests/goal-command-input.client.spec.tsx": {
|
||||
"1c1b6199197153a573f0fe4407b8558555422b0d50dbbba17b25b3ca93c61c4d": 1,
|
||||
"ac130009bd2e1d0af0c730a148e5e01a5a504bf712c43692bc62a8084c73e148": 1,
|
||||
"c94a4dd0df97005875a97b9228b3f536765ee6d31872ee05e69677da27086124": 1
|
||||
},
|
||||
"packages/client/ui-input-trigger/tests/apply.client.spec.ts": {
|
||||
"fc590cb703f599e5bb15f23909cedddeb2a77cb2cad0d4b9b8e664a62c46f44e": 1
|
||||
},
|
||||
@@ -625,7 +617,7 @@
|
||||
},
|
||||
"packages/client/ui-settings-models/tests/apply.client.spec.ts": {
|
||||
"0464c472dfc74994388bf63a6b3c110df506ce44fe47a5040e93c67a5eb3b4ae": 1,
|
||||
"04984a2ce1486250236e638e0197da0a1a840855ed3975c59130a85358c7e5fe": 5,
|
||||
"04984a2ce1486250236e638e0197da0a1a840855ed3975c59130a85358c7e5fe": 4,
|
||||
"5c8c41ba658c0576bea6c34b1226c27e7b0328c03c9eea0d6c920f940c9d8f5b": 1
|
||||
},
|
||||
"packages/client/ui-settings-models/tests/components.client.spec.tsx": {
|
||||
@@ -784,10 +776,6 @@
|
||||
"efed1d00d0f288a0c2716c88ee57ba53ace8f627abba4bd2c20de596755b5bad": 1,
|
||||
"f37cbef85628f8df72f3d455868ac0715105f463a9bd858f10e2cb5f984baefb": 1
|
||||
},
|
||||
"packages/client/ui-trajectory/tests/table.client.spec.tsx": {
|
||||
"8230c12479e8aa0eb39efd18be824c802edff5965e6e4f062089753e65f2e7cf": 1,
|
||||
"bfc698b45e3bff20b13dd4dc94cca8df3902a5d534fc57e80306ad2c9e96e4b7": 1
|
||||
},
|
||||
"packages/client/ui-trajectory/tests/views.client.spec.tsx": {
|
||||
"958ba19bf4d19e2dd44b271fa784091302bd3a2fdf291db6839fc49da543c5cf": 2
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { basename, join } from 'node:path'
|
||||
import { zipSync } from 'fflate'
|
||||
@@ -55,13 +55,29 @@ it('reports missing distribution metadata before trying to execute a stale nativ
|
||||
} finally { await rm(root, { recursive: true, force: true }) }
|
||||
})
|
||||
|
||||
// Native Windows payloads require python.exe rather than POSIX interpreter aliases.
|
||||
it.skipIf(process.platform === 'win32')('rejects expanded interpreter aliases in the native payload smoke', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'primary-expanded-aliases-'))
|
||||
try {
|
||||
await writeFile(join(root, 'runtime.json'), JSON.stringify({ desktopVersion: '1', platform: process.platform, arch: process.arch,
|
||||
python: '3.12.14', pythonPackages: { numpy: '2.3.5' } }))
|
||||
await mkdir(join(root, 'dependencies/python/bin'), { recursive: true })
|
||||
for (const name of ['python', 'python3', 'python3.12']) await writeFile(join(root, 'dependencies/python/bin', name), 'interpreter')
|
||||
expect(() => { smokePrimaryRuntime(root) }).toThrow('Python commands must be relative aliases')
|
||||
} finally { await rm(root, { recursive: true, force: true }) }
|
||||
})
|
||||
|
||||
it('extracts a hash-verified cached library without a Python installer or network request', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'desktop-wheel-'))
|
||||
try {
|
||||
const hash = createHash('sha256').update(libraryWheel).digest('hex')
|
||||
const archive = join(root, hash)
|
||||
await writeFile(archive, libraryWheel)
|
||||
const original = await stat(archive)
|
||||
expect(await downloadPrimaryRuntimeAsset('https://unused.invalid/library.whl', hash, root)).toBe(archive)
|
||||
const reused = await stat(archive)
|
||||
expect(reused.ino).toBe(original.ino)
|
||||
expect(reused.mtimeMs).toBe(original.mtimeMs)
|
||||
await unpackPrimaryRuntimeWheel(archive, join(root, 'site-packages'))
|
||||
expect(await readFile(join(root, 'site-packages/sample.py'), 'utf8')).toBe('sample = 42\n')
|
||||
await writeFile(archive, 'corrupt archive')
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/** Prepare pinned, relocatable script interpreters without installing into the build host. */
|
||||
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { createHash } from 'node:crypto'
|
||||
import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { createHash, randomUUID } from 'node:crypto'
|
||||
import { cpSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readlinkSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { cp } from 'node:fs/promises'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
@@ -10,30 +10,101 @@ import { dirname, join, resolve } from 'node:path'
|
||||
import { parseArgs } from 'node:util'
|
||||
import extractZip from 'extract-zip'
|
||||
import { x as extractTar } from 'tar'
|
||||
import { parsePrimaryRuntime, workspaceDependencyPaths, type PrimaryRuntimeManifest } from '../../packages/skill/tool-workspace-dependencies/src/index.ts'
|
||||
import { copyPrimaryRuntime, parsePrimaryRuntime, workspaceDependencyPaths, type PrimaryRuntimeManifest } from '@deepseek-ai/dsh-tool-workspace-dependencies'
|
||||
import lock from './lock.json' with { type: 'json' }
|
||||
import { prunePrimaryRuntimePythonTests } from './prune-python-tests.ts'
|
||||
|
||||
/**
|
||||
* Download or reuse an archive only when its bytes match the release lock.
|
||||
* @param url - Locked archive URL.
|
||||
* @param sha256 - Expected SHA-256 digest.
|
||||
* @param sha256 - Expected hexadecimal digest for the selected algorithm.
|
||||
* @param cache - Download cache directory.
|
||||
* @param algorithm - Digest algorithm; npm archives use SHA-512.
|
||||
* @returns Verified local archive path.
|
||||
*/
|
||||
export async function downloadPrimaryRuntimeAsset(url: string, sha256: string, cache: string): Promise<string> {
|
||||
export async function downloadPrimaryRuntimeAsset(url: string, sha256: string, cache: string, algorithm: 'sha256' | 'sha512' = 'sha256'): Promise<string> {
|
||||
mkdirSync(cache, { recursive: true })
|
||||
const destination = join(cache, sha256)
|
||||
let bytes: Buffer
|
||||
let cached = true
|
||||
try { bytes = readFileSync(destination) } catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
||||
const response = await fetch(url)
|
||||
cached = false
|
||||
const timeout = Number(process.env.DSH_RESOURCE_DOWNLOAD_TIMEOUT_MS ?? '300000')
|
||||
if (!Number.isSafeInteger(timeout) || timeout < 1 || timeout > 2_147_483_647) throw new Error('DSH_RESOURCE_DOWNLOAD_TIMEOUT_MS must be an integer from 1 to 2147483647')
|
||||
const response = await fetch(url, { signal: AbortSignal.timeout(timeout) })
|
||||
if (!response.ok) throw new Error(`primary runtime download: ${String(response.status)} ${url}`)
|
||||
bytes = Buffer.from(await response.arrayBuffer())
|
||||
}
|
||||
if (createHash('sha256').update(bytes).digest('hex') !== sha256) throw new Error(`primary runtime download: checksum mismatch for ${url}`)
|
||||
writeFileSync(destination, bytes)
|
||||
if (createHash(algorithm).update(bytes).digest('hex') !== sha256) {
|
||||
rmSync(destination, { force: true })
|
||||
throw new Error(`primary runtime download: checksum mismatch for ${url}`)
|
||||
}
|
||||
if (cached) return destination
|
||||
const temporary = join(cache, `.${randomUUID()}`)
|
||||
try {
|
||||
writeFileSync(temporary, bytes)
|
||||
renameSync(temporary, destination)
|
||||
} finally {
|
||||
rmSync(temporary, { force: true })
|
||||
}
|
||||
return destination
|
||||
}
|
||||
|
||||
/** Pinned npm tarball, without dependency resolution or lifecycle scripts. */
|
||||
export interface RuntimeNpmArchive {
|
||||
/** Exact published package name. */
|
||||
readonly name: string
|
||||
/** Exact published version. */
|
||||
readonly version: string
|
||||
/** Registry tarball URL. */
|
||||
readonly url: string
|
||||
/** npm SHA-512 integrity. */
|
||||
readonly integrity: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Download and unpack one locked npm package without running its scripts.
|
||||
* @param artifact - Published tarball identity and integrity.
|
||||
* @param destination - Empty package directory.
|
||||
* @param cache - Verified archive cache.
|
||||
* @returns Resolves after package identity validation.
|
||||
*/
|
||||
export async function downloadRuntimeNpmPackage(artifact: RuntimeNpmArchive, destination: string, cache: string): Promise<void> {
|
||||
if (!/^sha512-[A-Za-z0-9+/]+={0,2}$/u.test(artifact.integrity)) throw new Error(`runtime download: invalid integrity for ${artifact.name}`)
|
||||
const checksum = Buffer.from(artifact.integrity.slice(7), 'base64').toString('hex')
|
||||
const archive = await downloadPrimaryRuntimeAsset(artifact.url, checksum, cache, 'sha512')
|
||||
mkdirSync(destination, { recursive: true })
|
||||
await extractTar({ file: archive, cwd: destination, strip: 1 })
|
||||
const installed = JSON.parse(readFileSync(join(destination, 'package.json'), 'utf8')) as { name?: string; version?: string }
|
||||
if (installed.name !== artifact.name || installed.version !== artifact.version) throw new Error(`runtime download: package identity mismatch for ${artifact.name}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the locked standalone Node independently of Python and pnpm.
|
||||
* @param target - Target interpreter platform.
|
||||
* @param destination - Directory receiving bin/node and LICENSE.
|
||||
* @param cache - Verified archive cache.
|
||||
* @returns Resolves after extracting the interpreter.
|
||||
*/
|
||||
export async function downloadNodeRuntime(target: PrimaryRuntimeTarget, destination: string, cache: string): Promise<void> {
|
||||
const artifact = lock.targets[target]
|
||||
const filename = `node-v${lock.nodeVersion}-${artifact.nodeArchive}`
|
||||
const archive = await downloadPrimaryRuntimeAsset(`https://nodejs.org/dist/v${lock.nodeVersion}/${filename}`, artifact.nodeSha256, cache)
|
||||
const staging = mkdtempSync(join(tmpdir(), 'dsh-node-'))
|
||||
try {
|
||||
if (target === 'win-x64') await extractZip(archive, { dir: staging })
|
||||
else await extractTar({ file: archive, cwd: staging })
|
||||
const source = join(staging, filename.replace(/\.(?:zip|tar\.gz)$/u, ''))
|
||||
mkdirSync(join(destination, 'bin'), { recursive: true })
|
||||
cpSync(join(source, ...(target === 'win-x64' ? ['node.exe'] : ['bin', 'node'])),
|
||||
join(destination, 'bin', target === 'win-x64' ? 'node.exe' : 'node'))
|
||||
cpSync(join(source, 'LICENSE'), join(destination, 'LICENSE'))
|
||||
} finally {
|
||||
rmSync(staging, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
async function pythonArchive(target: keyof typeof lock.targets, cache: string): Promise<string> {
|
||||
const artifact = lock.targets[target]
|
||||
const filename = `cpython-${lock.pythonVersion}+${lock.pythonRelease}-${artifact.pythonTarget}-install_only_stripped.tar.gz`
|
||||
@@ -54,7 +125,7 @@ export function primaryRuntimePayloadDigest(
|
||||
// Identity preserves key order within the selected target, wheel records and distribution map, plus wheel-entry order.
|
||||
// Bump format when extraction or assembly changes payload bytes without changing locked inputs.
|
||||
return createHash('sha256').update(JSON.stringify({
|
||||
format: 4, target, pythonVersion, pythonRelease, nodeVersion: pnpmVersion === undefined ? undefined : nodeVersion,
|
||||
format: 7, target, pythonVersion, pythonRelease, nodeVersion: pnpmVersion === undefined ? undefined : nodeVersion,
|
||||
artifact: runtimeLock.targets[target], wheels, pythonPackages, pnpm: pnpmVersion,
|
||||
})).digest('hex')
|
||||
}
|
||||
@@ -91,7 +162,7 @@ export async function prepareOfficeSkillAssets(source: string, destination: stri
|
||||
/** A locked interpreter and wheel target. */
|
||||
export type PrimaryRuntimeTarget = keyof typeof lock.targets
|
||||
|
||||
/** Build-only inputs shared by Desktop and SDK carriers. */
|
||||
/** Resource preparation inputs shared by builds and explicit SDK downloads. */
|
||||
export interface PreparePrimaryRuntimeOptions {
|
||||
/** Target whose archives and wheels are downloaded. */
|
||||
readonly target: PrimaryRuntimeTarget
|
||||
@@ -101,6 +172,10 @@ export interface PreparePrimaryRuntimeOptions {
|
||||
readonly cache: string
|
||||
/** Carrier release recorded in the legacy desktopVersion manifest field. */
|
||||
readonly version: string
|
||||
/** Locked npm pnpm tarball for installed carriers; build hosts otherwise copy their installed pnpm. */
|
||||
readonly pnpmArchive?: RuntimeNpmArchive
|
||||
/** Ordinary filesystem Office assets; build hosts otherwise resolve the workspace package. */
|
||||
readonly skillSource?: string
|
||||
/** Omit Node.js and pnpm for carriers providing only Python. */
|
||||
readonly pythonOnly?: boolean
|
||||
}
|
||||
@@ -113,7 +188,6 @@ export interface PreparePrimaryRuntimeOptions {
|
||||
export async function preparePrimaryRuntime(options: PreparePrimaryRuntimeOptions): Promise<void> {
|
||||
const { target } = options
|
||||
const paths = { runtime: resolve(options.output), downloads: resolve(options.cache) }
|
||||
const artifact = lock.targets[target]
|
||||
mkdirSync(paths.runtime, { recursive: true })
|
||||
mkdirSync(paths.downloads, { recursive: true })
|
||||
const staging = mkdtempSync(join(tmpdir(), 'dsh-primary-'))
|
||||
@@ -123,23 +197,18 @@ export async function preparePrimaryRuntime(options: PreparePrimaryRuntimeOption
|
||||
mkdirSync(dependencies, { recursive: true })
|
||||
let pnpmVersion: string | undefined
|
||||
if (!options.pythonOnly) {
|
||||
const nodeFilename = `node-v${lock.nodeVersion}-${artifact.nodeArchive}`
|
||||
const nodeArchive = await downloadPrimaryRuntimeAsset(`https://nodejs.org/dist/v${lock.nodeVersion}/${nodeFilename}`, artifact.nodeSha256, paths.downloads)
|
||||
const unpackedNode = join(staging, 'node')
|
||||
mkdirSync(unpackedNode)
|
||||
if (target === 'win-x64') await extractZip(nodeArchive, { dir: unpackedNode })
|
||||
else await extractTar({ file: nodeArchive, cwd: unpackedNode })
|
||||
const nodeSource = join(unpackedNode, nodeFilename.replace(/\.(?:zip|tar\.gz)$/u, ''))
|
||||
mkdirSync(join(dependencies, 'node', 'bin'), { recursive: true })
|
||||
mkdirSync(join(dependencies, 'node', 'node_modules'))
|
||||
writeFileSync(join(dependencies, 'node', 'node_modules', 'README.txt'), 'Reserved for bundled Node packages. pnpm uses its default installation directories.\n')
|
||||
cpSync(join(nodeSource, ...(target === 'win-x64' ? ['node.exe'] : ['bin', 'node'])),
|
||||
join(dependencies, 'node', 'bin', target === 'win-x64' ? 'node.exe' : 'node'))
|
||||
cpSync(join(nodeSource, 'LICENSE'), join(dependencies, 'node', 'LICENSE'))
|
||||
const require = createRequire(import.meta.url)
|
||||
const pnpmManifest = require.resolve('pnpm')
|
||||
pnpmVersion = (JSON.parse(readFileSync(pnpmManifest, 'utf8')) as { version: string }).version
|
||||
await cp(dirname(pnpmManifest), join(dependencies, 'pnpm'), { recursive: true, dereference: true })
|
||||
const node = join(dependencies, 'node')
|
||||
await downloadNodeRuntime(target, node, paths.downloads)
|
||||
mkdirSync(join(node, 'node_modules'))
|
||||
writeFileSync(join(node, 'node_modules', 'README.txt'), 'Reserved for bundled Node packages. pnpm uses its default installation directories.\n')
|
||||
if (options.pnpmArchive !== undefined) {
|
||||
pnpmVersion = options.pnpmArchive.version
|
||||
await downloadRuntimeNpmPackage(options.pnpmArchive, join(dependencies, 'pnpm'), paths.downloads)
|
||||
} else {
|
||||
const pnpmManifest = createRequire(import.meta.url).resolve('pnpm')
|
||||
pnpmVersion = (JSON.parse(readFileSync(pnpmManifest, 'utf8')) as { version: string }).version
|
||||
await cp(dirname(pnpmManifest), join(dependencies, 'pnpm'), { recursive: true, dereference: true })
|
||||
}
|
||||
}
|
||||
await extractTar({ file: await pythonArchive(target, paths.downloads), cwd: dependencies })
|
||||
const manifest: PrimaryRuntimeManifest = {
|
||||
@@ -152,18 +221,19 @@ export async function preparePrimaryRuntime(options: PreparePrimaryRuntimeOption
|
||||
pythonPackages: lock.pythonPackages,
|
||||
}
|
||||
const entries = workspaceDependencyPaths(output, manifest)
|
||||
for (const wheel of [...artifact.wheels, ...lock.wheels]) {
|
||||
for (const wheel of [...lock.targets[target].wheels, ...lock.wheels]) {
|
||||
await unpackPrimaryRuntimeWheel(await downloadPrimaryRuntimeAsset(wheel.url, wheel.sha256, paths.downloads), entries.pythonPackages)
|
||||
}
|
||||
prunePrimaryRuntimePythonTests(entries.pythonPackages)
|
||||
writeFileSync(join(output, 'runtime.json'), `${JSON.stringify(manifest, undefined, 2)}\n`)
|
||||
const destination = join(paths.runtime, 'primary-runtime')
|
||||
rmSync(destination, { recursive: true, force: true })
|
||||
await cp(output, destination, { recursive: true, dereference: true })
|
||||
await copyPrimaryRuntime(output, destination, manifest)
|
||||
} finally {
|
||||
rmSync(staging, { recursive: true, force: true })
|
||||
}
|
||||
const require = createRequire(import.meta.url)
|
||||
await prepareOfficeSkillAssets(join(dirname(require.resolve('@deepseek-ai/dsh-skill-office/package.json')), 'assets'),
|
||||
const assets = options.skillSource ?? join(dirname(createRequire(import.meta.url).resolve('@deepseek-ai/dsh-skill-office/package.json')), 'assets')
|
||||
await prepareOfficeSkillAssets(assets,
|
||||
join(paths.runtime, 'office-skills'))
|
||||
}
|
||||
|
||||
@@ -179,6 +249,16 @@ export function smokePrimaryRuntime(root: string, environment: NodeJS.ProcessEnv
|
||||
if (manifest.platform !== process.platform || manifest.arch !== process.arch) return
|
||||
if (Object.keys(manifest.pythonPackages).length === 0) throw new Error('primary runtime: missing Python distribution versions; prepare the payload before running its smoke checks.')
|
||||
const entries = workspaceDependencyPaths(root, manifest)
|
||||
if (manifest.platform !== 'win32') {
|
||||
const interpreter = `python${manifest.python.split('.').slice(0, 2).join('.')}`
|
||||
for (const name of ['python', 'python3']) {
|
||||
const path = join(dirname(entries.python), name)
|
||||
if (!lstatSync(path).isSymbolicLink() || readlinkSync(path) !== interpreter) {
|
||||
throw new Error(`primary runtime: Python commands must be relative aliases of ${interpreter}`)
|
||||
}
|
||||
}
|
||||
if (!lstatSync(join(dirname(entries.python), interpreter)).isFile()) throw new Error('primary runtime: versioned Python must be a regular file')
|
||||
}
|
||||
const options = { stdio: 'inherit', timeout: 120_000, env: environment } as const
|
||||
execFileSync(entries.python, ['-I', '-B', '-c', 'import decimal, xml.parsers.expat, lzma, uuid, numpy, pandas; assert numpy.arange(4).sum() == 6; assert pandas.DataFrame({"n": [1, 2]}).n.sum() == 3'], options)
|
||||
execFileSync(entries.python, ['-I', '-B', join(import.meta.dirname, 'smoke.py'), JSON.stringify(manifest.pythonPackages),
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { zipSync } from 'fflate'
|
||||
import { expect, it } from 'vitest'
|
||||
import lock from './lock.json' with { type: 'json' }
|
||||
import { unpackPrimaryRuntimeWheel } from './prepare.ts'
|
||||
import { prunePrimaryRuntimePythonTests } from './prune-python-tests.ts'
|
||||
|
||||
const records = {
|
||||
numpy: `numpy-${lock.pythonPackages.numpy}.dist-info/RECORD`,
|
||||
pandas: `pandas-${lock.pythonPackages.pandas}.dist-info/RECORD`,
|
||||
}
|
||||
|
||||
it('removes only NumPy/pandas test directories and keeps retained wheel files and RECORD hashes', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'primary-python-pruning-'))
|
||||
try {
|
||||
const removed = [
|
||||
'numpy/tests/test_numpy.py', 'numpy/_core/tests/test_core.py', 'numpy/_core/tests/data/values,small.csv',
|
||||
'numpy/testing/tests/test_utils.py', 'pandas/tests/io/test_excel.py', 'pandas/tests/io/data/workbook.xlsx',
|
||||
]
|
||||
const retained = [
|
||||
'numpy/__init__.py', 'numpy/_core/_multiarray_tests.so', 'numpy/_core/_multiarray_tests.pyd',
|
||||
'numpy/testing/__init__.py', 'numpy/_core/tests.py', 'numpy/data/values,small.csv',
|
||||
'pandas/__init__.py', 'pandas/testing.py', 'pandas/_testing/__init__.py', 'pandas/_libs/testing.pyd',
|
||||
`numpy-${lock.pythonPackages.numpy}.dist-info/licenses/LICENSE.txt`,
|
||||
`pandas-${lock.pythonPackages.pandas}.dist-info/LICENSE`,
|
||||
'other/tests/test_other.py', 'numpy_extra/tests/test_extra.py',
|
||||
]
|
||||
const files = Object.fromEntries([...removed, ...retained].map(path => [path, Buffer.from(`contents of ${path}\n`)]))
|
||||
// Quoted paths exercise RECORD's CSV encoding even when a filename contains a comma.
|
||||
const row = (path: string): string => `"${path}",sha256=${createHash('sha256').update(files[path]!).digest('base64url')},${files[path]!.length}\n`
|
||||
for (const [name, record] of Object.entries(records)) {
|
||||
const paths = [...removed, ...retained].filter(path => path.startsWith(`${name}/`) || path.startsWith(`${name}-`))
|
||||
files[record] = Buffer.from(`${paths.map(row).join('')}${record},,\n`)
|
||||
}
|
||||
const archive = join(root, 'libraries.whl')
|
||||
const sitePackages = join(root, 'site-packages')
|
||||
const wheel = Buffer.from(zipSync(files))
|
||||
await writeFile(archive, wheel)
|
||||
await unpackPrimaryRuntimeWheel(archive, sitePackages)
|
||||
await mkdir(join(sitePackages, 'numpy/empty/tests'), { recursive: true })
|
||||
|
||||
prunePrimaryRuntimePythonTests(sitePackages)
|
||||
|
||||
for (const path of [...removed, 'numpy/tests', 'numpy/empty/tests', 'pandas/tests']) {
|
||||
await expect(readFile(join(sitePackages, path))).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
}
|
||||
for (const path of retained) expect(await readFile(join(sitePackages, path))).toEqual(files[path])
|
||||
for (const [name, record] of Object.entries(records)) {
|
||||
const lines = (await readFile(join(sitePackages, record), 'utf8')).trimEnd().split('\n')
|
||||
const expected = retained.filter(path => path.startsWith(`${name}/`) || path.startsWith(`${name}-`))
|
||||
expect(lines).toHaveLength(expected.length + 1)
|
||||
for (const path of expected) {
|
||||
const expectedRow = row(path).trimEnd()
|
||||
expect(lines).toContain(path.includes(',') ? expectedRow : expectedRow.replace(`"${path}"`, path))
|
||||
}
|
||||
expect(lines).toContain(`${record},,`)
|
||||
}
|
||||
expect(await readFile(archive)).toEqual(wheel)
|
||||
const before = await Promise.all(Object.values(records).map(record => readFile(join(sitePackages, record))))
|
||||
prunePrimaryRuntimePythonTests(sitePackages)
|
||||
expect(await Promise.all(Object.values(records).map(record => readFile(join(sitePackages, record))))).toEqual(before)
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it.each(['"unterminated,,\n', 'numpy/tests/test_numpy.py,\n', '', ',,\n'])(
|
||||
'rejects malformed installed-file records before deleting that distribution\'s tests: %j', async (record) => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'primary-python-record-'))
|
||||
try {
|
||||
await mkdir(join(root, `numpy-${lock.pythonPackages.numpy}.dist-info`))
|
||||
await writeFile(join(root, records.numpy), record)
|
||||
await mkdir(join(root, 'numpy/tests'), { recursive: true })
|
||||
const testFile = join(root, 'numpy/tests/test_numpy.py')
|
||||
await writeFile(testFile, 'test fixture\n')
|
||||
expect(() => { prunePrimaryRuntimePythonTests(root) }).toThrow('invalid wheel RECORD')
|
||||
expect(await readFile(testFile, 'utf8')).toBe('test fixture\n')
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -0,0 +1,41 @@
|
||||
/** Remove upstream Python test suites from the staged primary runtime. */
|
||||
|
||||
import { readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import Papa from 'papaparse'
|
||||
import lock from './lock.json' with { type: 'json' }
|
||||
|
||||
function removeTestDirectories(root: string, directory: string): string[] {
|
||||
const removed: string[] = []
|
||||
for (const entry of readdirSync(join(root, directory), { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) continue
|
||||
const path = `${directory}/${entry.name}`
|
||||
if (entry.name === 'tests') {
|
||||
rmSync(join(root, path), { recursive: true })
|
||||
removed.push(path)
|
||||
} else {
|
||||
removed.push(...removeTestDirectories(root, path))
|
||||
}
|
||||
}
|
||||
return removed
|
||||
}
|
||||
|
||||
/**
|
||||
* Prune NumPy/pandas tests and their RECORD rows, preserving testing helpers and native extensions.
|
||||
* @param sitePackages - Staged site-packages directory containing the locked wheels.
|
||||
* @throws If a locked distribution's RECORD is missing or malformed.
|
||||
*/
|
||||
export function prunePrimaryRuntimePythonTests(sitePackages: string): void {
|
||||
for (const name of ['numpy', 'pandas'] as const) {
|
||||
const record = join(sitePackages, `${name}-${lock.pythonPackages[name]}.dist-info`, 'RECORD')
|
||||
const { data, errors } = Papa.parse<string[]>(readFileSync(record, 'utf8'), { delimiter: ',', skipEmptyLines: true })
|
||||
if (errors.length > 0 || data.length === 0
|
||||
|| !data.every((row): row is [string, string, string] => row.length === 3 && Boolean(row[0]))) {
|
||||
throw new Error(`primary runtime: invalid wheel RECORD: ${record}`)
|
||||
}
|
||||
const removed = removeTestDirectories(sitePackages, name)
|
||||
if (removed.length === 0) continue
|
||||
const retained = data.filter(([path]) => !removed.some(directory => path.startsWith(`${directory}/`)))
|
||||
writeFileSync(record, `${Papa.unparse(retained, { newline: '\n' })}\n`)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
"""Exercise the relocated Office payload with its own isolated interpreter."""
|
||||
|
||||
import csv
|
||||
import importlib.metadata
|
||||
import io
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
@@ -9,6 +11,8 @@ import sys
|
||||
import tempfile
|
||||
|
||||
import numpy
|
||||
# NumPy testing helpers require this native extension even without upstream test directories.
|
||||
import numpy._core._multiarray_tests
|
||||
import pandas
|
||||
from docx import Document
|
||||
from docx.shared import Inches as DocxInches
|
||||
@@ -21,9 +25,31 @@ from pptx.enum.chart import XL_CHART_TYPE
|
||||
from pptx.util import Inches
|
||||
|
||||
|
||||
def check_interpreters():
|
||||
"""Exercise command aliases, child execution and a pip-enabled virtual environment."""
|
||||
executable = Path(sys.executable)
|
||||
names = [executable.name] if sys.platform == "win32" else ["python", "python3", f"python{sys.version_info.major}.{sys.version_info.minor}"]
|
||||
for name in names:
|
||||
interpreter = executable.with_name(name)
|
||||
subprocess.run([
|
||||
str(interpreter), "-I", "-B", "-c",
|
||||
"import subprocess, sys; from pathlib import Path; "
|
||||
"assert Path(sys.executable) == Path(sys.argv[1]); "
|
||||
"subprocess.run([sys.executable, '-I', '-B', '-c', 'import ssl, sqlite3, ctypes'], check=True, timeout=30)",
|
||||
str(interpreter),
|
||||
], check=True, timeout=60)
|
||||
with tempfile.TemporaryDirectory(prefix="dsh python venv ") as directory:
|
||||
environment = Path(directory) / "environment"
|
||||
subprocess.run([str(executable.with_name(names[0])), "-I", "-B", "-m", "venv", str(environment)], check=True, timeout=60)
|
||||
python = environment / ("Scripts/python.exe" if sys.platform == "win32" else "bin/python")
|
||||
subprocess.run([str(python), "-I", "-B", "-c", "import sys; assert sys.prefix != sys.base_prefix"], check=True, timeout=30)
|
||||
subprocess.run([str(python), "-I", "-B", "-m", "pip", "check"], check=True, timeout=30)
|
||||
|
||||
|
||||
def main():
|
||||
"""Check installed versions and read back editable Office documents."""
|
||||
assert sys.version_info[:3] == tuple(map(int, sys.argv[2].split("."))), sys.version
|
||||
check_interpreters()
|
||||
versions = json.loads(sys.argv[1])
|
||||
# Only pip belongs to the interpreter baseline; all other distributions must be declared.
|
||||
# Each target's native release-host smoke must confirm this baseline.
|
||||
@@ -38,6 +64,16 @@ def main():
|
||||
assert actual == expected, (name, actual, expected)
|
||||
assert numpy.arange(4).sum() == 6
|
||||
assert pandas.DataFrame({"n": [1, 2]}).n.sum() == 3
|
||||
numpy.testing.assert_allclose(numpy.arange(4), [0, 1, 2, 3])
|
||||
pandas.testing.assert_frame_equal(pandas.DataFrame({"n": [1, 2]}), pandas.DataFrame({"n": [1, 2]}))
|
||||
for library in (numpy, pandas):
|
||||
root = Path(library.__file__).parent
|
||||
assert not any(path.is_dir() for path in root.rglob("tests")), root
|
||||
distribution = importlib.metadata.distribution(library.__name__)
|
||||
record = distribution.read_text("RECORD")
|
||||
assert record, library.__name__
|
||||
for file, _hash, _size in csv.reader(io.StringIO(record)):
|
||||
assert distribution.locate_file(file).is_file(), file
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="dsh-office-smoke-") as directory:
|
||||
root = Path(directory)
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/** Explicit resource acquisition through the Python carrier's private dispatcher. */
|
||||
import { spawn } from 'node:child_process'
|
||||
import { mkdir, mkdtemp, readFile, readdir, rm, writeFile, copyFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { expect, it } from 'vitest'
|
||||
|
||||
async function fixture() {
|
||||
const root = await mkdtemp(join(tmpdir(), 'dsh-resource-download-'))
|
||||
const bootstrap = join(root, 'node', 'runtime-bootstrap.mjs')
|
||||
const platform = process.platform === 'darwin' ? 'macos' : process.platform === 'win32' ? 'win' : process.platform
|
||||
const resources = join(root, `${platform}-${process.arch}`)
|
||||
const cache = join(root, 'cache')
|
||||
async function file(path: string, content: string) {
|
||||
await mkdir(dirname(path), { recursive: true })
|
||||
await writeFile(path, content)
|
||||
}
|
||||
await file(join(resources, 'downloads.json'), JSON.stringify({ identity: 'a'.repeat(64), office: [], pnpm: {} }))
|
||||
await mkdir(dirname(bootstrap), { recursive: true })
|
||||
await copyFile(new URL('../python/sdk-runtime/runtime-bootstrap.mjs', import.meta.url), bootstrap)
|
||||
await file(join(root, 'node/node_modules/@deepseek-ai/dsh-http-proxy/package.json'), '{"type":"module","exports":"./index.mjs"}')
|
||||
await file(join(root, 'node/node_modules/@deepseek-ai/dsh-http-proxy/index.mjs'), 'export async function installProxyFromEnvironment(env) { if (typeof env.get !== "function") throw new Error("missing environment lookup"); return async () => {} }')
|
||||
await file(join(root, 'node/node_modules/@deepseek-ai/dsh-sandbox-windows-acl/package.json'), '{"type":"module","exports":{"./runner":"./runner.mjs"}}')
|
||||
await file(join(root, 'node/node_modules/@deepseek-ai/dsh-sandbox-windows-acl/runner.mjs'), '')
|
||||
await file(join(root, 'node/node_modules/@deepseek-ai/dsh/package.json'), '{"type":"module"}')
|
||||
await file(join(root, 'node/node_modules/@deepseek-ai/dsh/lib/bin.js'), 'export async function runCli() { if (process.argv[2]) { console.log(JSON.stringify({ argv: process.argv.slice(2) })); return } console.log(JSON.stringify({ primary: process.env.DSH_BUNDLED_PRIMARY_RUNTIME, office: process.env.DSH_BUNDLED_OFFICE_CLI })) }')
|
||||
await file(join(root, 'node/primary-runtime.mjs'), `
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
export async function downloadNodeRuntime(target, destination) {
|
||||
if (process.env.DSH_RUNTIME_DOWNLOAD !== undefined) throw new Error("private selector leaked");
|
||||
await mkdir(join(destination, 'bin'), { recursive: true });
|
||||
await writeFile(join(destination, 'bin', process.platform === 'win32' ? 'node.exe' : 'node'), 'node');
|
||||
}
|
||||
export async function preparePrimaryRuntime({ output }) {
|
||||
if (process.env.DSH_RUNTIME_DOWNLOAD !== undefined) throw new Error("private selector leaked");
|
||||
await mkdir(join(output, 'primary-runtime'), { recursive: true });
|
||||
await writeFile(join(output, 'primary-runtime/runtime.json'), '{}');
|
||||
}
|
||||
`)
|
||||
await file(join(root, 'node/office-sidecar.mjs'), `
|
||||
import { mkdir, writeFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
export async function downloadOfficeSidecar(packages, destination) {
|
||||
const directory = join(destination, 'node_modules/@deepseek-ai/libreoffice-kit/lib');
|
||||
await mkdir(directory, { recursive: true });
|
||||
await writeFile(join(directory, 'cli.js'), 'cli');
|
||||
if (process.env.DSH_FIXTURE_FAIL) throw new Error('fixture download failed');
|
||||
if (process.env.DSH_FIXTURE_BARRIER) {
|
||||
process.stderr.write('ready\\n');
|
||||
await new Promise(resolve => process.stdin.once('data', resolve));
|
||||
process.stdin.pause();
|
||||
}
|
||||
}
|
||||
`)
|
||||
function run(resource?: string, extra: NodeJS.ProcessEnv = {}, args: string[] = []) {
|
||||
const child = spawn(process.execPath, [bootstrap, ...args], {
|
||||
env: { ...process.env, DSH_RESOURCE_CACHE: cache, DSH_RUNTIME_DOWNLOAD: resource, DSH_BUNDLED_PRIMARY_RUNTIME: undefined,
|
||||
DSH_OFFICE_SIDECAR: undefined, DSH_BUNDLED_OFFICE_CLI: undefined, ...extra },
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
})
|
||||
let stdout = '', stderr = ''
|
||||
child.stdout.on('data', (data) => { stdout += String(data) })
|
||||
let reportReady: (() => void) | undefined
|
||||
let failReady: ((error: Error) => void) | undefined
|
||||
const ready = extra.DSH_FIXTURE_BARRIER === undefined ? Promise.resolve()
|
||||
: new Promise<void>((resolve, reject) => { reportReady = resolve; failReady = reject })
|
||||
child.stderr.on('data', (data) => { stderr += String(data); if (stderr.includes('ready\n')) reportReady?.() })
|
||||
const done = new Promise<{ code: number | null; stdout: string; stderr: string }>((resolve, reject) => {
|
||||
child.once('error', reject)
|
||||
child.once('close', (code) => { failReady?.(new Error(`download exited before readiness: ${stderr}`)); resolve({ code, stdout, stderr }) })
|
||||
})
|
||||
return { child, ready, done }
|
||||
}
|
||||
return { root, cache, run }
|
||||
}
|
||||
|
||||
it('starts without downloading, independently downloads either resource, and reuses completed caches', async () => {
|
||||
const { root, cache, run } = await fixture()
|
||||
try {
|
||||
expect(await run().done).toMatchObject({ code: 0, stdout: '{}\n' })
|
||||
await expect(readdir(cache)).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
const primary = await run('primary').done
|
||||
expect(primary.code, primary.stderr).toBe(0)
|
||||
expect(JSON.parse(primary.stdout)).toBe(join(cache, 'a'.repeat(64), 'primary', 'primary-runtime'))
|
||||
await expect(readdir(join(cache, 'a'.repeat(64), 'office'))).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
const office = await run('office').done
|
||||
expect(office.code, office.stderr).toBe(0)
|
||||
const location = JSON.parse(office.stdout) as string
|
||||
expect(await readFile(join(location, 'node_modules/@deepseek-ai/libreoffice-kit/lib/cli.js'), 'utf8')).toBe('cli')
|
||||
expect(await run('office', { DSH_FIXTURE_FAIL: '1' }).done).toMatchObject({ code: 0, stdout: office.stdout })
|
||||
} finally { await rm(root, { recursive: true, force: true }) }
|
||||
})
|
||||
|
||||
it('cleans failed staging and allows an explicit retry', async () => {
|
||||
const { root, cache, run } = await fixture()
|
||||
try {
|
||||
const failed = await run('office', { DSH_FIXTURE_FAIL: '1' }).done
|
||||
expect(failed.code).toBe(1)
|
||||
expect(failed.stderr).toContain('fixture download failed')
|
||||
expect(await readdir(join(cache, 'a'.repeat(64)))).toEqual([])
|
||||
expect((await run('office').done).code).toBe(0)
|
||||
} finally { await rm(root, { recursive: true, force: true }) }
|
||||
})
|
||||
|
||||
it('publishes one complete cache when two processes download concurrently', async () => {
|
||||
const { root, cache, run } = await fixture()
|
||||
const jobs = [run('office', { DSH_FIXTURE_BARRIER: '1' }), run('office', { DSH_FIXTURE_BARRIER: '1' })]
|
||||
try {
|
||||
await Promise.all(jobs.map(job => job.ready))
|
||||
for (const job of jobs) job.child.stdin.end('continue')
|
||||
const results = await Promise.all(jobs.map(job => job.done))
|
||||
for (const result of results) expect(result.code, result.stderr).toBe(0)
|
||||
expect(results[0]!.stdout).toBe(results[1]!.stdout)
|
||||
expect(await readdir(join(cache, 'a'.repeat(64)))).toEqual(['office'])
|
||||
} finally {
|
||||
for (const job of jobs) if (job.child.exitCode === null && job.child.signalCode === null) job.child.kill()
|
||||
await Promise.allSettled(jobs.map(job => job.done))
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
it('leaves ordinary CLI arguments to the CLI and rejects an invalid private download selector', async () => {
|
||||
const { root, cache, run } = await fixture()
|
||||
try {
|
||||
expect(await run(undefined, {}, ['--download-office']).done).toMatchObject({
|
||||
code: 0, stdout: JSON.stringify({ argv: ['--download-office'] }) + '\n',
|
||||
})
|
||||
const rejected = await run('invalid').done
|
||||
expect(rejected.code).toBe(1)
|
||||
expect(rejected.stderr).toContain('DSH_RUNTIME_DOWNLOAD must select office or primary')
|
||||
await expect(readdir(cache)).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
} finally { await rm(root, { recursive: true, force: true }) }
|
||||
})
|
||||
@@ -884,10 +884,18 @@ def main() -> None:
|
||||
|
||||
def smoke_sdk_authoring(base_url: str, executable: Path, update_snapshots: bool) -> None:
|
||||
"""Query the bundled Python and switch skills without replacing that environment."""
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="dsh-sdk-authoring-cache-") as cache_directory:
|
||||
_smoke_sdk_authoring_cached(base_url, executable, update_snapshots, Path(cache_directory))
|
||||
|
||||
|
||||
def _smoke_sdk_authoring_cached(base_url: str, executable: Path, update_snapshots: bool, cache: Path) -> None:
|
||||
from deepseek_harness import DeepSeekHarness
|
||||
|
||||
resources = executable.with_name(executable.name.removeprefix("deepseek-harness-sdk-runtime-").removesuffix(".exe"))
|
||||
manifest = json.loads((resources / "primary-runtime/runtime.json").read_text())
|
||||
cache_environment = {**os.environ, "DSH_RESOURCE_CACHE": str(cache), "DSH_RUNTIME_DOWNLOAD": "primary"}
|
||||
primary = Path(json.loads(subprocess.check_output([str(executable)], encoding="utf-8", env=cache_environment)))
|
||||
resources = primary.parent
|
||||
manifest = json.loads((primary / "runtime.json").read_text())
|
||||
for mode in ("default", "replacement", "disabled"):
|
||||
with tempfile.TemporaryDirectory(prefix="dsh-sdk-authoring-") as temporary:
|
||||
root = Path(temporary).resolve()
|
||||
@@ -903,7 +911,7 @@ def smoke_sdk_authoring(base_url: str, executable: Path, update_snapshots: bool)
|
||||
provider="deepseek-official", model="smoke-model", cwd=str(root),
|
||||
dsh_bin=str(executable), dsh_home=str(home), patches=(str(patch),),
|
||||
api_key="sk-keyless-smoke", base_url=base_url,
|
||||
env={"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1"},
|
||||
env={"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1", "DSH_RESOURCE_CACHE": str(cache)},
|
||||
request_timeout_seconds=60,
|
||||
) as harness:
|
||||
result = harness.run(AUTHORING_PROMPT, session_id="authoring")
|
||||
@@ -958,7 +966,9 @@ def smoke_sdk_office(executable: Path) -> None:
|
||||
shutil.copytree(source, destination)
|
||||
else:
|
||||
shutil.copy2(source, destination)
|
||||
office = root / f"{stem}-office"
|
||||
cache_environment = {**os.environ, "DSH_RESOURCE_CACHE": str(root / "cache")}
|
||||
office = Path(json.loads(subprocess.check_output([str(relocated)], encoding="utf-8", env={**cache_environment, "DSH_RUNTIME_DOWNLOAD": "office"})))
|
||||
assert not (office.parent / "primary").exists(), "Office download unexpectedly prepared the authoring environment"
|
||||
adapter = office / "node_modules/@deepseek-ai/libreoffice-kit/package.json"
|
||||
native = stem.removeprefix("deepseek-harness-sdk-runtime-").replace("win-", "win32-").replace("macos-", "darwin-")
|
||||
declared = json.loads(adapter.read_text(encoding="utf-8")).get("optionalDependencies", {})
|
||||
@@ -997,7 +1007,7 @@ def smoke_sdk_office(executable: Path) -> None:
|
||||
patches=(str(patch),),
|
||||
api_key="sk-keyless-smoke",
|
||||
base_url="http://127.0.0.1:9",
|
||||
env={"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1"},
|
||||
env={"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1", "DSH_RESOURCE_CACHE": str(root / "cache")},
|
||||
# The startup plugin awaits a converter with a 120-second deadline before JSON-RPC is ready.
|
||||
initialize_timeout_seconds=180,
|
||||
request_timeout_seconds=180,
|
||||
@@ -1007,10 +1017,32 @@ def smoke_sdk_office(executable: Path) -> None:
|
||||
if result["backend"] != expected_backend:
|
||||
raise AssertionError(f"Office conversion did not use {expected_backend}: {result}")
|
||||
if not result["moduleUrl"].startswith(office.as_uri() + "/"):
|
||||
raise AssertionError(f"Office module was not loaded from the relocated wheel: {result}")
|
||||
raise AssertionError(f"Office module was not loaded from the downloaded sidecar: {result}")
|
||||
pdf = output.read_bytes()
|
||||
if len(pdf) < 100 or not pdf.startswith(b"%PDF-"):
|
||||
raise AssertionError(f"Office conversion produced an invalid PDF at {output}")
|
||||
workbook = root / "input.xlsx"
|
||||
with zipfile.ZipFile(workbook, "w", compression=zipfile.ZIP_DEFLATED) as archive:
|
||||
archive.writestr("[Content_Types].xml", '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>')
|
||||
archive.writestr("_rels/.rels", '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>')
|
||||
archive.writestr("xl/workbook.xml", '<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets></workbook>')
|
||||
archive.writestr("xl/_rels/workbook.xml.rels", '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/></Relationships>')
|
||||
archive.writestr("xl/worksheets/sheet1.xml", '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData><row r="1"><c r="A1"><f>1+2</f><v>0</v></c></row></sheetData></worksheet>')
|
||||
subprocess.run([sys.executable, "-c", """
|
||||
import sys, zipfile
|
||||
from pathlib import Path
|
||||
from xml.etree import ElementTree
|
||||
from deepseek_harness.office import convert, render_images, recalculate
|
||||
root = Path(sys.argv[1])
|
||||
assert convert(root / 'document.docx', root / 'python.pdf').backend == sys.argv[2]
|
||||
rendered = render_images(root / 'python.pdf', root / 'images', pages=[1])
|
||||
assert rendered.images and rendered.images[0].path.read_bytes().startswith(b'\\x89PNG')
|
||||
recalculate(root / 'input.xlsx', root / 'calculated.xlsx')
|
||||
with zipfile.ZipFile(root / 'calculated.xlsx') as archive:
|
||||
sheet = ElementTree.fromstring(archive.read('xl/worksheets/sheet1.xml'))
|
||||
assert sheet.find('.//{*}c[@r="A1"]/{*}v').text == '3'
|
||||
""", str(root), expected_backend], env={name: value for name, value in cache_environment.items() if name != "DSH_OFFICE_SIDECAR"}, check=True, timeout=180)
|
||||
assert not (office.parent / "primary").exists(), "Python Office API unexpectedly downloaded authoring resources"
|
||||
print(f"smoke-python-runtime: relocated Office {result['backend']} DOCX produced {len(pdf)} PDF bytes")
|
||||
|
||||
|
||||
@@ -1336,6 +1368,8 @@ def smoke_sdk_dynamic_tools(base_url: str, executable: Path, update_snapshots: b
|
||||
"DSH_PERMISSION_MODE": "danger-full-access", "DSH_TELEMETRY_DISABLED": "1",
|
||||
"HOME": str(user_home), "USERPROFILE": str(user_home),
|
||||
"DSH_AGENTS_HOME": str(user_home / ".agents"),
|
||||
# Pin the tool baseline independently of optional resources in the host cache.
|
||||
"DSH_PRIMARY_RUNTIME": "",
|
||||
},
|
||||
api_key="sk-keyless-smoke", base_url=base_url, request_timeout_seconds=60,
|
||||
) as harness:
|
||||
@@ -2307,11 +2341,17 @@ def build_dynamic_tools_snapshot_files(
|
||||
assert changes == [[], [{"type": "tool_addition", "tool": {"type": "tool_reference", "name": "snapshot_ping"}}], []], changes
|
||||
assert requests[1]["messages"][:len(requests[0]["messages"])] == requests[0]["messages"], "tool addition changed earlier messages"
|
||||
replacements = [(str(cwd), "{{cwd}}"), (result.session_id, "{{session}}")]
|
||||
header_references = {header["seq"]: f"{{{{header:{index + 1}}}}}" for index, header in enumerate(headers)}
|
||||
snapshot_events = [
|
||||
{**event, "data": {**event["data"], "headerSeq": header_references[event["data"]["headerSeq"]]}}
|
||||
if event["type"] == "developer/message" and "headerSeq" in event["data"] else event
|
||||
for event in events if event["type"] in {"request/header", "request/context", "developer/message"}
|
||||
]
|
||||
evidence = {
|
||||
"finalResponse": result.final_response,
|
||||
"declarations": declarations,
|
||||
"requestToolChanges": changes,
|
||||
"events": [event for event in events if event["type"] in {"request/header", "request/context", "developer/message"}],
|
||||
"events": snapshot_events,
|
||||
"toolCalls": calls,
|
||||
"pingResult": ping,
|
||||
}
|
||||
|
||||
@@ -56,7 +56,6 @@
|
||||
"job_list",
|
||||
"job_output",
|
||||
"list_agents",
|
||||
"load_workspace_dependencies",
|
||||
"read",
|
||||
"read_image",
|
||||
"send_message",
|
||||
@@ -87,7 +86,7 @@
|
||||
},
|
||||
{
|
||||
"type": "request/header",
|
||||
"seq": 20,
|
||||
"seq": 19,
|
||||
"time": 0,
|
||||
"data": {
|
||||
"header": {
|
||||
@@ -113,7 +112,6 @@
|
||||
"job_list",
|
||||
"job_output",
|
||||
"list_agents",
|
||||
"load_workspace_dependencies",
|
||||
"read",
|
||||
"read_image",
|
||||
"send_message",
|
||||
@@ -135,7 +133,7 @@
|
||||
},
|
||||
{
|
||||
"type": "developer/message",
|
||||
"seq": 21,
|
||||
"seq": 20,
|
||||
"time": 0,
|
||||
"data": {
|
||||
"turn": 1,
|
||||
@@ -153,13 +151,13 @@
|
||||
"role": "developer",
|
||||
"id": "{{messageId}}"
|
||||
},
|
||||
"headerSeq": 20
|
||||
"headerSeq": "{{header:2}}"
|
||||
},
|
||||
"surfaceOp": "append"
|
||||
},
|
||||
{
|
||||
"type": "request/header",
|
||||
"seq": 28,
|
||||
"seq": 26,
|
||||
"time": 0,
|
||||
"data": {
|
||||
"header": {
|
||||
@@ -185,7 +183,6 @@
|
||||
"job_list",
|
||||
"job_output",
|
||||
"list_agents",
|
||||
"load_workspace_dependencies",
|
||||
"read",
|
||||
"read_image",
|
||||
"send_message",
|
||||
@@ -206,7 +203,7 @@
|
||||
},
|
||||
{
|
||||
"type": "developer/message",
|
||||
"seq": 29,
|
||||
"seq": 27,
|
||||
"time": 0,
|
||||
"data": {
|
||||
"turn": 1,
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
/** Plugin metadata checks use private source-only packages and real resource exports. */
|
||||
|
||||
import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { existsSync, mkdirSync, mkdtempSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join } from 'node:path'
|
||||
import { afterEach, beforeEach, expect, it } from 'vitest'
|
||||
import { packageMetaProblems } from './verify-package-meta.ts'
|
||||
|
||||
const validSvg = '<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 36 36"><defs><linearGradient id="ink"><stop stop-color="#69B9FF" /></linearGradient></defs><path d="M8 8H28V28H8Z" fill="url(#ink)" /></svg>'
|
||||
|
||||
let root: string
|
||||
let dir: string
|
||||
beforeEach(() => {
|
||||
@@ -26,7 +28,7 @@ function json(path: string, contents: unknown): void {
|
||||
|
||||
function manifest(fields: object = {}): void {
|
||||
json('package.json', {
|
||||
name: '@test/plugin',
|
||||
name: '@deepseek-ai/dsh-test-plugin',
|
||||
description: 'Package description',
|
||||
type: 'module',
|
||||
exports: { '.': './lib/index.js', './package.json': './package.json', './locale/*.json': './locale/*.json' },
|
||||
@@ -46,14 +48,89 @@ it('does not require locale resources for exported package name and description'
|
||||
|
||||
it.each(['legacy.svg', './legacy.svg'])('accepts a manifest-only icon %s', (icon) => {
|
||||
manifest({ icon, files: ['legacy.svg'] })
|
||||
file('legacy.svg', 'legacy')
|
||||
file('legacy.svg', validSvg)
|
||||
expect(packageMetaProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
it.each(['manifest', 'export'])('accepts SVG geometry and local references selected by %s', (selection) => {
|
||||
manifest({
|
||||
...selection === 'manifest' ? { icon: './icon.svg' } : {},
|
||||
exports: { './package.json': './package.json', './icon': './icon.svg' }, files: ['icon.svg'],
|
||||
})
|
||||
file('icon.svg', validSvg.replace('<path ', '<use href="#outline"/><path id="outline" '))
|
||||
expect(packageMetaProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
it.each([
|
||||
['malformed XML', validSvg.replace('</svg>', ''), 'well-formed XML'],
|
||||
['wrong root', validSvg.replaceAll('svg', 'g'), 'svg root'],
|
||||
['wrong namespace', validSvg.replace('http://www.w3.org/2000/svg', 'urn:other'), 'SVG namespace'],
|
||||
['toolbar canvas', validSvg.replace('0 0 36 36', '0 0 16 16'), 'viewBox="0 0 36 36"'],
|
||||
['toolbar width', validSvg.replace('width="36"', 'width="16"'), 'width="36"'],
|
||||
['toolbar height', validSvg.replace('height="36"', 'height="16"'), 'height="36"'],
|
||||
['missing definition', validSvg.replace('url(#ink)', 'url(#missing)'), 'must name a local id'],
|
||||
['external definition', validSvg.replace('url(#ink)', 'url(https://example.test/ink.svg#ink)'), 'must name a local id'],
|
||||
['external href', validSvg.replace('<path ', '<path href="https://example.test/icon.svg" '), 'must name a local id'],
|
||||
['missing href target', validSvg.replace('<path ', '<path href="#missing" '), 'must name a local id'],
|
||||
['duplicate ids', validSvg.replace('<path ', '<path id="ink" '), 'unique ids'],
|
||||
['event handler', validSvg.replace('<path ', '<path onload="run()" '), 'event handler onload'],
|
||||
['empty artwork', validSvg.replace(/<path[^>]+\/>/u, ''), 'must contain geometry'],
|
||||
...['script', 'style', 'image', 'foreignObject', 'text', 'animate', 'animateTransform', 'animateMotion', 'set']
|
||||
.map(tag => [tag, validSvg.replace('</svg>', `<${tag} /></svg>`), 'self-contained geometry']),
|
||||
])('rejects SVG %s through metadata verification', (_name, source, diagnostic) => {
|
||||
manifest({ icon: './icon.svg', files: ['icon.svg'] })
|
||||
file('icon.svg', source)
|
||||
const problems = packageMetaProblems(root)
|
||||
expect(problems).toHaveLength(1)
|
||||
expect(problems[0]).toContain(`${join(dir, 'icon.svg')}:`)
|
||||
expect(problems[0]).toContain(diagnostic)
|
||||
})
|
||||
|
||||
it('validates the selected ./icon SVG fallback without a manifest icon', () => {
|
||||
manifest({ exports: { './package.json': './package.json', './icon': './icon.svg' }, files: ['icon.svg'] })
|
||||
file('icon.svg', validSvg.replace('width="36"', 'width="16"'))
|
||||
expect(packageMetaProblems(root)).toEqual([`${realpathSync(join(dir, 'icon.svg'))}: SVG icon must use width="36" height="36" viewBox="0 0 36 36"`])
|
||||
})
|
||||
|
||||
it('validates the manifest icon instead of the lower-priority SVG export', () => {
|
||||
manifest({ icon: './icon.svg', exports: { './package.json': './package.json', './icon': './fallback.svg' }, files: ['icon.svg', 'fallback.svg'] })
|
||||
file('icon.svg', validSvg)
|
||||
file('fallback.svg', 'not XML')
|
||||
expect(packageMetaProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
it.each(['png', 'jpg', 'jpeg', 'webp'].flatMap(extension => ['manifest', 'export'].map(selection => ({ extension, selection }))))(
|
||||
'keeps $extension bytes opaque for $selection icons', ({ extension, selection }) => {
|
||||
manifest({
|
||||
...selection === 'manifest' ? { icon: `./icon.${extension}` } : {},
|
||||
exports: { './package.json': './package.json', './icon': `./icon.${extension}` }, files: [`icon.${extension}`],
|
||||
})
|
||||
file(`icon.${extension}`, 'opaque raster bytes')
|
||||
expect(packageMetaProblems(root)).toEqual([])
|
||||
},
|
||||
)
|
||||
|
||||
it.each(['@local/demo', '@deepseek-ai/other'])('keeps nonofficial %s SVGs outside official artwork conventions', (name) => {
|
||||
manifest({ name, icon: './icon.svg', files: ['icon.svg'] })
|
||||
file('icon.svg', '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"/>')
|
||||
expect(packageMetaProblems(root)).toEqual([])
|
||||
})
|
||||
|
||||
it('checks official artwork in named nested packages', () => {
|
||||
manifest({ exports: { '.': './entry.js' }, files: ['nested'] })
|
||||
json('nested/package.json', {
|
||||
name: '@deepseek-ai/dsh-nested', exports: { './icon': './icon.svg' }, files: ['icon.svg'],
|
||||
})
|
||||
file('nested/icon.svg', validSvg.replace('width="36"', 'width="16"'))
|
||||
expect(packageMetaProblems(root)).toEqual([
|
||||
`${realpathSync(join(dir, 'nested/icon.svg'))}: SVG icon must use width="36" height="36" viewBox="0 0 36 36"`,
|
||||
])
|
||||
})
|
||||
|
||||
it('reads the manifest image and still rejects an unresolvable lower-priority export', () => {
|
||||
manifest({ icon: './legacy.svg', files: ['legacy.svg'],
|
||||
exports: { './package.json': './package.json', './icon': '../invalid.svg' } })
|
||||
file('legacy.svg', 'legacy')
|
||||
file('legacy.svg', validSvg)
|
||||
expect(packageMetaProblems(root)).toEqual([`${join(dir, 'package.json')}: exports["./icon"] must resolve to a file`])
|
||||
})
|
||||
|
||||
@@ -62,7 +139,7 @@ it.each([['display'], ['display/manifest.json'], ['display/logo.svg']])
|
||||
manifest({ files,
|
||||
exports: { './package.json': './display/manifest.json' } })
|
||||
json('display/manifest.json', { icon: './logo.svg' })
|
||||
file('display/logo.svg', 'legacy')
|
||||
file('display/logo.svg', validSvg)
|
||||
const problems = packageMetaProblems(root).join('\n')
|
||||
if (files.includes('display')) expect(problems).toBe('')
|
||||
else expect(problems).toContain(`files must include ${files.includes('display/manifest.json') ? 'display/logo.svg' : 'display/manifest.json'}`)
|
||||
@@ -71,15 +148,15 @@ it.each([['display'], ['display/manifest.json'], ['display/logo.svg']])
|
||||
it('requires the root manifest icon declaration to remain accessible', () => {
|
||||
manifest({ icon: './legacy.svg', files: ['legacy.svg'],
|
||||
exports: { './icon': './legacy.svg' } })
|
||||
file('legacy.svg', 'legacy')
|
||||
file('legacy.svg', validSvg)
|
||||
expect(packageMetaProblems(root).join('\n')).toContain('exports must expose its icon declaration')
|
||||
})
|
||||
|
||||
it.each([null, false, '', './missing.svg'])('diagnoses legacy icon %j despite a valid fallback export', (icon) => {
|
||||
manifest({ icon, files: ['fallback.svg'],
|
||||
exports: { './package.json': './package.json', './icon': './fallback.svg' } })
|
||||
file('fallback.svg', 'fallback')
|
||||
expect(packageMetaProblems(root).join('\n')).toContain('Plugin metadata for @test/plugin:')
|
||||
file('fallback.svg', validSvg)
|
||||
expect(packageMetaProblems(root).join('\n')).toContain('Plugin metadata for @deepseek-ai/dsh-test-plugin:')
|
||||
})
|
||||
|
||||
it.each([undefined, ['art'], ['art/*.webp'], ['./art/icon.webp']])('accepts an exported icon without other resources: %j', (files) => {
|
||||
@@ -96,7 +173,7 @@ it.each([['lib'], ['art', '!art/icon.webp']])('rejects an exported icon omitted
|
||||
|
||||
it.each([false, 1, '', './icon.gif', '/tmp/icon.svg', './missing.png', '../outside.svg'])('validates exported icon targets: %j', (icon) => {
|
||||
manifest({ exports: { './icon': icon } })
|
||||
expect(packageMetaProblems(root).join('\n')).toMatch(/Plugin metadata for @test\/plugin:|exports\["\.\/icon"\] must resolve to a file/u)
|
||||
expect(packageMetaProblems(root).join('\n')).toMatch(/Plugin metadata for @deepseek-ai\/dsh-test-plugin:|exports\["\.\/icon"\] must resolve to a file/u)
|
||||
})
|
||||
|
||||
it.each([['assets'], ['lib']])('checks publication of the Node-selected conditional icon: %j', (...files) => {
|
||||
@@ -116,8 +193,8 @@ it('ignores package.json exported at a subpath plugin address', () => {
|
||||
it.each([['search.svg'], ['lib']])('reads and publishes a subpath icon export: %j', (...files) => {
|
||||
manifest({ icon: './root.svg', exports: { './package.json': './package.json', './search': './search.js', './search/icon': './search.svg' },
|
||||
files: ['root.svg', ...files] })
|
||||
file('root.svg', 'root')
|
||||
file('search.svg', 'search')
|
||||
file('root.svg', validSvg)
|
||||
file('search.svg', validSvg)
|
||||
const problems = packageMetaProblems(root)
|
||||
if (files.includes('search.svg')) expect(problems).toEqual([])
|
||||
else expect(problems).toEqual([`${join(dir, 'package.json')}: files must include search.svg`])
|
||||
@@ -165,8 +242,8 @@ it.each([
|
||||
files: ['locale', 'icon.svg'], ...fields,
|
||||
})
|
||||
json('examples/nested/locale/en.json', { meta: { title } })
|
||||
file('examples/nested/icon.svg', '<svg/>')
|
||||
file('examples/nested/fallback.svg', '<svg/>')
|
||||
file('examples/nested/icon.svg', validSvg)
|
||||
file('examples/nested/fallback.svg', validSvg)
|
||||
const problems = packageMetaProblems(root)
|
||||
if (expected === undefined) expect(problems).toEqual([])
|
||||
else expect(problems.join('\n')).toContain(expected)
|
||||
@@ -255,7 +332,7 @@ it('does not read built locale JSON while checking a source icon declaration', (
|
||||
icon: './icon.svg', files: ['icon.svg'],
|
||||
exports: { './package.json': './package.json', './locale/en.json': './lib/locale/en.json' },
|
||||
})
|
||||
file('icon.svg', '<svg/>')
|
||||
file('icon.svg', validSvg)
|
||||
file('lib/locale/en.json', '{')
|
||||
json('locale/en.json', { meta: { title: 'Plugin' } })
|
||||
const problems = packageMetaProblems(root).join('\n')
|
||||
@@ -270,7 +347,7 @@ it.each(['lib', 'tests'])('rejects an icon declaration when its only locale is e
|
||||
})
|
||||
file(`${directory}/locale/en.json`, '{}')
|
||||
const problems = packageMetaProblems(root).join('\n')
|
||||
expect(problems).toContain('@test/plugin: icon metadata requires locale resources to resolve to source JSON')
|
||||
expect(problems).toContain('@deepseek-ai/dsh-test-plugin: icon metadata requires locale resources to resolve to source JSON')
|
||||
expect(problems).not.toContain('Plugin metadata for')
|
||||
})
|
||||
|
||||
@@ -594,7 +671,7 @@ it('reports metadata failures from more than one workspace package', () => {
|
||||
json('locale/en.json', { meta: { title: 'Second' } })
|
||||
json('locale/zh.json', { meta: { description: '' } })
|
||||
const problems = packageMetaProblems(root).join('\n')
|
||||
expect(problems).toContain('@test/plugin')
|
||||
expect(problems).toContain('@deepseek-ai/dsh-test-plugin')
|
||||
expect(problems).toContain('@test/second')
|
||||
})
|
||||
|
||||
@@ -603,6 +680,6 @@ it.each([[], ['locale']])('rejects a display manifest in build output without re
|
||||
if (locales.length > 0) json('locale/en.json', { meta: { title: 'Plugin' } })
|
||||
file('lib/display.json', '{')
|
||||
const problems = packageMetaProblems(root).join('\n')
|
||||
expect(problems).toContain('@test/plugin/package.json: display manifest must resolve to source JSON')
|
||||
expect(problems).toContain('@deepseek-ai/dsh-test-plugin/package.json: display manifest must resolve to source JSON')
|
||||
expect(problems).not.toContain('Plugin metadata for')
|
||||
})
|
||||
@@ -1,8 +1,9 @@
|
||||
/** Validate source locale metadata, Node resource exports, and package publication selections. */
|
||||
/** Validate source locale metadata, official SVG artwork, Node resource exports, and publication selections. */
|
||||
|
||||
import { globSync, readFileSync, realpathSync } from 'node:fs'
|
||||
import { basename, dirname, join, matchesGlob, relative, resolve } from 'node:path'
|
||||
import { fileURLToPath, pathToFileURL } from 'node:url'
|
||||
import { JSDOM } from 'jsdom'
|
||||
import { readPluginMeta, resolvePluginResource } from '../packages/boot/app-boot/src/package-meta.ts'
|
||||
|
||||
interface Manifest {
|
||||
@@ -72,7 +73,46 @@ function published(file: string, files: string[]): boolean {
|
||||
&& !files.some(pattern => pattern.startsWith('!') && covered(pattern.slice(1)))
|
||||
}
|
||||
|
||||
function packageProblems(manifestPath: string): string[] {
|
||||
/** Structural artwork conventions only; not an SVG sanitizer or a rendered-pixel check. */
|
||||
function svgArtworkProblems(icon: string, parser: DOMParser): string[] {
|
||||
const prefix = 'data:image/svg+xml;base64,'
|
||||
if (!icon.startsWith(prefix)) return []
|
||||
const document = parser.parseFromString(Buffer.from(icon.slice(prefix.length), 'base64').toString('utf8'), 'image/svg+xml')
|
||||
if (document.querySelector('parsererror') !== null) return ['SVG icon must contain well-formed XML']
|
||||
const svg = document.documentElement
|
||||
if (svg.localName !== 'svg' || svg.namespaceURI !== 'http://www.w3.org/2000/svg') {
|
||||
return ['SVG icon must have an svg root in the SVG namespace']
|
||||
}
|
||||
const problems: string[] = []
|
||||
if (svg.getAttribute('viewBox') !== '0 0 36 36' || svg.getAttribute('width') !== '36' || svg.getAttribute('height') !== '36') {
|
||||
problems.push('SVG icon must use width="36" height="36" viewBox="0 0 36 36"')
|
||||
}
|
||||
if (svg.querySelector('path, rect, circle, ellipse, line, polyline, polygon') === null) {
|
||||
problems.push('SVG icon must contain geometry')
|
||||
}
|
||||
if (svg.querySelector('script, style, image, foreignObject, text, animate, animateTransform, animateMotion, set') !== null) {
|
||||
problems.push('SVG icon must use self-contained geometry without scripts, styles, images, foreignObject, text, or animation')
|
||||
}
|
||||
const elements = [svg, ...svg.querySelectorAll('*')]
|
||||
const ids = elements.flatMap(element => element.hasAttribute('id') ? [element.id] : [])
|
||||
const uniqueIds = new Set(ids)
|
||||
if (uniqueIds.size !== ids.length) problems.push('SVG icon must use unique ids')
|
||||
for (const element of elements) {
|
||||
for (const attribute of element.attributes) {
|
||||
if (/^on/iu.test(attribute.name)) problems.push(`SVG icon must not use event handler ${attribute.name}`)
|
||||
const references = [...attribute.value.matchAll(/url\(([^)]+)\)/gu)].map(match => (match[1] ?? '').replace(/['"]/gu, '').trim())
|
||||
if (attribute.localName === 'href') references.push(attribute.value)
|
||||
for (const reference of references) {
|
||||
if (!reference.startsWith('#') || !uniqueIds.has(reference.slice(1))) {
|
||||
problems.push(`SVG icon reference ${reference} must name a local id`)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return problems
|
||||
}
|
||||
|
||||
function packageProblems(manifestPath: string, parser: DOMParser): string[] {
|
||||
const problems: string[] = []
|
||||
const dir = realpathSync(dirname(manifestPath))
|
||||
const pkg = JSON.parse(readFileSync(manifestPath, 'utf8')) as Manifest
|
||||
@@ -152,6 +192,9 @@ function packageProblems(manifestPath: string): string[] {
|
||||
: displayManifest !== undefined && typeof iconDocument?.icon === 'string'
|
||||
? resolve(dirname(displayManifest), iconDocument.icon)
|
||||
: lookup(`${specifier}/icon`)
|
||||
if (pkg.name.startsWith('@deepseek-ai/dsh-') && meta?.icon !== undefined) {
|
||||
problems.push(...svgArtworkProblems(meta.icon, parser).map(problem => `${iconTarget ?? specifier}: ${problem}`))
|
||||
}
|
||||
for (const target of [displayManifest, iconTarget]) {
|
||||
if (target === undefined) continue
|
||||
const file = relative(dir, target).replaceAll('\\', '/')
|
||||
@@ -209,18 +252,26 @@ function packageProblems(manifestPath: string): string[] {
|
||||
})) continue
|
||||
problems.push(`${manifestPath}: exports must expose ${document.file} as a plugin locale resource with an en.json discovery baseline`)
|
||||
}
|
||||
return problems.concat(children.flatMap(child => packageProblems(join(dir, child.file))))
|
||||
return problems.concat(children.flatMap(child => packageProblems(join(dir, child.file), parser)))
|
||||
}
|
||||
|
||||
/**
|
||||
* Check workspace and named nested package metadata without evaluating plugin entries or reading built output.
|
||||
* Selected SVG icons in @deepseek-ai/dsh-* packages follow official artwork conventions.
|
||||
* Other packages and supported raster icons keep their metadata and publication checks.
|
||||
* @param root - repository or fixture root.
|
||||
* @returns diagnostics for an empty package corpus, invalid metadata, inaccessible resources, or omitted publication files.
|
||||
* @returns diagnostics for an empty package corpus, invalid metadata or SVG artwork, inaccessible resources, or omitted publication files.
|
||||
*/
|
||||
export function packageMetaProblems(root: string): string[] {
|
||||
const manifests = globSync('packages/*/*/package.json', { cwd: root }).map(path => path.replaceAll('\\', '/'))
|
||||
if (manifests.length === 0) return [`${root}: no workspace package manifests found`]
|
||||
return manifests.flatMap(path => packageProblems(join(root, path)))
|
||||
const { window } = new JSDOM()
|
||||
try {
|
||||
const parser = new window.DOMParser()
|
||||
return manifests.flatMap(path => packageProblems(join(root, path), parser))
|
||||
} finally {
|
||||
window.close()
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
||||
@@ -229,6 +280,6 @@ if (process.argv[1] !== undefined && resolve(process.argv[1]) === fileURLToPath(
|
||||
console.error(problems.join('\n'))
|
||||
process.exitCode = 1
|
||||
} else {
|
||||
console.log('verify-package-meta: plugin locale metadata, resource exports, and publication files are valid.')
|
||||
console.log('verify-package-meta: plugin locale metadata, SVG artwork, resource exports, and publication files are valid.')
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user