feat(skill): complete shared Office runtime builds for SDK carriers
This commit is contained in:
1 parent
6e49ccad18
commit
8fad9ccd8c
40 files changed
+779
-325
No files matched your search
@@ -0,0 +1,156 @@
|
||||
{
|
||||
"nodeVersion": "24.21.0",
|
||||
"pythonVersion": "3.12.14",
|
||||
"pythonRelease": "20260901",
|
||||
"targets": {
|
||||
"win-x64": {
|
||||
"nodeArchive": "win-x64.zip",
|
||||
"nodeSha256": "158f7685b44de51f6c0df1d153526cbcd3e1bc739a8dfc607721cef75de9e541",
|
||||
"pythonTarget": "x86_64-pc-windows-msvc",
|
||||
"pythonSha256": "7c45c9622400d578709a9b2cddbe8124cc21d382409d9f13406d706d28e31b14",
|
||||
"wheels": [
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/2d/57/8aeaf160312f7f489dea47ab61e430b5cb051f59a98ae68b7133ce8fa06a/numpy-2.3.5-cp312-cp312-win_amd64.whl",
|
||||
"sha256": "86945f2ee6d10cdfd67bcb4069c1662dd711f7e2a4343db5cecec06b87cf31aa"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/75/08/67cc404b3a966b6df27b38370ddd96b3b023030b572283d035181854aac5/pandas-3.0.1-cp312-cp312-win_amd64.whl",
|
||||
"sha256": "536232a5fe26dd989bd633e7a0c450705fdc86a207fec7254a55e9a22950fe43"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/45/89/da2f7971a317f83d807fdd4065c0af40208e59e692cc43d315a71a0e96d1/pillow-12.3.0-cp312-cp312-win_amd64.whl",
|
||||
"sha256": "a2b55dd6b2a4c4b7d87ffa56bdb33fdc5fdb9a462173861a7bc097f17d91cb09"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/3a/5b/6ed903e4e6278a020c8a6f0dbbe78030d041840a6b4a64ea441a1e414077/lxml-6.1.3-cp312-cp312-win_amd64.whl",
|
||||
"sha256": "3e9a00d1c2c30936f7add097c41afc5da6556c580909104aafd382cac92a855c"
|
||||
}
|
||||
]
|
||||
},
|
||||
"mac-arm64": {
|
||||
"nodeArchive": "darwin-arm64.tar.gz",
|
||||
"nodeSha256": "bed7eea5325e1108f32ce5228ddd6a5f0f08a499ee42aa7442aea583702f6057",
|
||||
"pythonTarget": "aarch64-apple-darwin",
|
||||
"pythonSha256": "81a359f1cfadd4da11766534c5913791cea55f26e1bb902cacd2a531bb1e4b2b",
|
||||
"wheels": [
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/c5/65/df0db6c097892c9380851ab9e44b52d4f7ba576b833996e0080181c0c439/numpy-2.3.5-cp312-cp312-macosx_11_0_arm64.whl",
|
||||
"sha256": "ee3888d9ff7c14604052b2ca5535a30216aa0a58e948cdd3eeb8d3415f638769"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/7c/f1/e2567ffc8951ab371db2e40b2fe068e36b81d8cf3260f06ae508700e5504/pandas-3.0.1-cp312-cp312-macosx_11_0_arm64.whl",
|
||||
"sha256": "0ab749dfba921edf641d4036c4c21c0b3ea70fea478165cb98a998fb2a261955"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/d8/66/9a386a92561f402389a4fc70c18838bf6d35eb5eb5c6850b4b2dc64f5048/pillow-12.3.0-cp312-cp312-macosx_11_0_arm64.whl",
|
||||
"sha256": "ffd0c5368496f41b0944be820fcb7a838aa6e623d250b01acf2643939c3f99d7"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/dd/1f/a180b57d9eeabaab77f9d5aa30356898ea749c4795596a8f66d1eb6bef2e/lxml-6.1.3-cp312-cp312-macosx_10_13_universal2.whl",
|
||||
"sha256": "0c0710ac085a157b593c38fbcacd950f15c4afa8e2057527185875ab302752bc"
|
||||
}
|
||||
]
|
||||
},
|
||||
"mac-x64": {
|
||||
"nodeArchive": "darwin-x64.tar.gz",
|
||||
"nodeSha256": "1462cb3b3046b815cf8ea436d3da450ec1a9f11dac7e5a46b0ada5305d7e8097",
|
||||
"pythonTarget": "x86_64-apple-darwin",
|
||||
"pythonSha256": "65b195c9cedc1fef6767f044f9822069adbd1bd9204d424ece4628776fdc04bb",
|
||||
"wheels": [
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/44/37/e669fe6cbb2b96c62f6bbedc6a81c0f3b7362f6a59230b23caa673a85721/numpy-2.3.5-cp312-cp312-macosx_10_13_x86_64.whl",
|
||||
"sha256": "74ae7b798248fe62021dbf3c914245ad45d1a6b0cb4a29ecb4b31d0bfbc4cc3e"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/37/51/b467209c08dae2c624873d7491ea47d2b47336e5403309d433ea79c38571/pandas-3.0.1-cp312-cp312-macosx_10_13_x86_64.whl",
|
||||
"sha256": "476f84f8c20c9f5bc47252b66b4bb25e1a9fc2fa98cead96744d8116cb85771d"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/37/bf/fb3ebff8ddcb76aac5a01389251bbbb9519922a9b520d8247c1ca864a25d/pillow-12.3.0-cp312-cp312-macosx_10_13_x86_64.whl",
|
||||
"sha256": "ba09209fbe443b4acccebe845d8a138b89a8f4fbaeedd44953490b5315d5e965"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/a8/25/070c92013a1c029a602b03560d68772313d918268667fa993da7961759c9/lxml-6.1.3-cp312-cp312-macosx_10_13_x86_64.whl",
|
||||
"sha256": "623c8799c17128753c65699f1c3aa32402657393a9ad6db09ed8b98ddf76611d"
|
||||
}
|
||||
]
|
||||
},
|
||||
"linux-x64": {
|
||||
"nodeArchive": "linux-x64.tar.gz",
|
||||
"nodeSha256": "6e1db87ef58b8819e5d5402eff1536491b18edd8eb7bee5ef7897876e88dc5ff",
|
||||
"pythonTarget": "x86_64-unknown-linux-gnu",
|
||||
"pythonSha256": "72748da13197c1fb161e3afeef20a6a385ff24f2165e6e2758e47008e7faba4c",
|
||||
"wheels": [
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/b6/23/2a1b231b8ff672b4c450dac27164a8b2ca7d9b7144f9c02d2396518352eb/numpy-2.3.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl",
|
||||
"sha256": "0d8163f43acde9a73c2a33605353a4f1bc4798745a8b1d73183b28e5b435ae28"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/3d/fe/89d77e424365280b79d99b3e1e7d606f5165af2f2ecfaf0c6d24c799d607/pandas-3.0.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl",
|
||||
"sha256": "532527a701281b9dd371e2f582ed9094f4c12dd9ffb82c0c54ee28d8ac9520c4"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/84/21/a35af28dcc61f37ed850a2d64c65c701321dfbf25085e469d5559360cbbf/pillow-12.3.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl",
|
||||
"sha256": "78cb2c6865a35ab8ff8b75fd122f6033b92a62c82801110e48ddd6c936a45d91"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/db/36/aa413bc214dc4f785ad2b2ddd8cc99aae7062d49ab155e91e6011af00daf/lxml-6.1.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl",
|
||||
"sha256": "379f8a75cf6eb7eef0af074b55f49ab73b868388a98de14646abcdfa4564bb11"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"wheels": [
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl",
|
||||
"sha256": "a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/b7/ce/149a00dd41f10bc29e5921b496af8b574d8413afcd5e30dfa0ed46c2cc5e/six-1.17.0-py2.py3-none-any.whl",
|
||||
"sha256": "4721f391ed90541fddacab5acf947aa0d3dc7d27b2e1e8eda2be8970586c3274"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/5c/23/c7abc0ca0a1526a0774eca151daeb8de62ec457e77262b66b359c3c7679e/tzdata-2025.2-py2.py3-none-any.whl",
|
||||
"sha256": "1a403fada01ff9221ca8044d701868fa132215d84beb92242d9acd2147f667a8"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/d0/00/1e03a4989fa5795da308cd774f05b704ace555a70f9bf9d3be057b680bcf/python_docx-1.2.0-py3-none-any.whl",
|
||||
"sha256": "3fd478f3250fbbbfd3b94fe1e985955737c145627498896a8a6bf81f4baf66c7"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/d9/4f/00be2196329ebbff56ce564aa94efb0fbc828d00de250b1980de1a34ab49/python_pptx-1.0.2-py3-none-any.whl",
|
||||
"sha256": "160838e0b8565a8b1f67947675886e9fea18aa5e795db7ae531606d68e785cba"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/c0/da/977ded879c29cbd04de313843e76868e6e13408a94ed6b987245dc7c8506/openpyxl-3.1.5-py2.py3-none-any.whl",
|
||||
"sha256": "5282c12b107bffeef825f4617dc029afaf41d0ea60823bbb665ef3079dc79de2"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/3a/0c/3662f4a66880196a590b202f0db82d919dd2f89e99a27fadef91c4a33d41/xlsxwriter-3.2.9-py3-none-any.whl",
|
||||
"sha256": "9a5db42bc5dff014806c58a20b9eae7322a134abb6fce3c92c181bfb275ec5b3"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl",
|
||||
"sha256": "481caa481374e813c1b176ada14e97f1f67a4539ce9cfeb3f350d78d6370c2e8"
|
||||
},
|
||||
{
|
||||
"url": "https://files.pythonhosted.org/packages/c1/8b/5fe2cc11fee489817272089c4203e679c63b570a5aaeb18d852ae3cbba6a/et_xmlfile-2.0.0-py3-none-any.whl",
|
||||
"sha256": "7a91720bc756843502c3b7504c77b8fe44217c85c537d85037f0f536151b2caa"
|
||||
}
|
||||
],
|
||||
"pythonPackages": {
|
||||
"numpy": "2.3.5",
|
||||
"pandas": "3.0.1",
|
||||
"python-dateutil": "2.9.0.post0",
|
||||
"six": "1.17.0",
|
||||
"tzdata": "2025.2",
|
||||
"python-docx": "1.2.0",
|
||||
"python-pptx": "1.0.2",
|
||||
"openpyxl": "3.1.5",
|
||||
"Pillow": "12.3.0",
|
||||
"lxml": "6.1.3",
|
||||
"XlsxWriter": "3.2.9",
|
||||
"typing_extensions": "4.16.0",
|
||||
"et_xmlfile": "2.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
import { createHash } from 'node:crypto'
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { basename, join } from 'node:path'
|
||||
import { zipSync } from 'fflate'
|
||||
import { expect, it } from 'vitest'
|
||||
import { downloadPrimaryRuntimeAsset, prepareOfficeSkillAssets, primaryRuntimePayloadDigest, smokePrimaryRuntime, unpackPrimaryRuntimeWheel } from './prepare.ts'
|
||||
import lock from './lock.json' with { type: 'json' }
|
||||
|
||||
const libraryWheel = Buffer.from('UEsDBAoAAAAAAASeLl0sYMPjDAAAAAwAAAAJAAAAc2FtcGxlLnB5c2FtcGxlID0gNDIKUEsBAh4DCgAAAAAABJ4uXSxgw+MMAAAADAAAAAkAAAAAAAAAAQAAAKSBAAAAAHNhbXBsZS5weVBLBQYAAAAAAQABADcAAAAzAAAAAAA=', 'base64')
|
||||
const relocatedWheel = Buffer.from('UEsDBAoAAAAAAASeLl3x0Nj9FAAAABQAAAAeAAAAc2FtcGxlLTEuMC5kYXRhL3NjcmlwdHMvc2FtcGxlcmVxdWlyZXMgcmVsb2NhdGlvbgpQSwECHgMKAAAAAAAEni5d8dDY/RQAAAAUAAAAHgAAAAAAAAABAAAApIEAAAAAc2FtcGxlLTEuMC5kYXRhL3NjcmlwdHMvc2FtcGxlUEsFBgAAAAABAAEATAAAAFAAAAAAAA==', 'base64')
|
||||
const externalLibraryWheel = Buffer.from('UEsDBBQAAAAAAAAAIVyBOE8OHAAAABwAAAAhAAAAc2FtcGxlLTEuMC5kYXRhL3B1cmVsaWIvc2FtcGxlLnB5cmVxdWlyZXMgbGlicmFyeSByZWxvY2F0aW9uClBLAQIUAxQAAAAAAAAAIVyBOE8OHAAAABwAAAAhAAAAAAAAAAAAAACAAQAAAABzYW1wbGUtMS4wLmRhdGEvcHVyZWxpYi9zYW1wbGUucHlQSwUGAAAAAAEAAQBPAAAAWwAAAAAA', 'base64')
|
||||
|
||||
it.each(Object.entries(lock.targets))('records every locked wheel distribution and version for %s', (_target, artifact) => {
|
||||
const normalize = (name: string): string => name.toLowerCase().replace(/[-_.]+/gu, '-')
|
||||
const distributions = [...artifact.wheels, ...lock.wheels].map(({ url }) => {
|
||||
const [name, version] = basename(new URL(url).pathname).split('-')
|
||||
return [normalize(name!), version] as const
|
||||
})
|
||||
const declared = Object.entries(lock.pythonPackages).map(([name, version]) => [normalize(name), version] as const)
|
||||
expect(new Set(distributions.map(([name]) => name)).size).toBe(distributions.length)
|
||||
expect(new Set(declared.map(([name]) => name)).size).toBe(declared.length)
|
||||
expect(Object.fromEntries(distributions)).toEqual(Object.fromEntries(declared))
|
||||
})
|
||||
|
||||
it('keeps a target payload identity independent of other target archives', () => {
|
||||
const changed = structuredClone(lock)
|
||||
changed.targets['win-x64'].wheels[0]!.sha256 = 'a'.repeat(64)
|
||||
expect(primaryRuntimePayloadDigest('mac-arm64', changed, '11.7.0')).toBe(primaryRuntimePayloadDigest('mac-arm64', lock, '11.7.0'))
|
||||
expect(primaryRuntimePayloadDigest('win-x64', changed, '11.7.0')).not.toBe(primaryRuntimePayloadDigest('win-x64', lock, '11.7.0'))
|
||||
})
|
||||
|
||||
it('invalidates payload identity for shared wheels, package versions and package-manager changes', () => {
|
||||
const wheel = structuredClone(lock), distribution = structuredClone(lock)
|
||||
wheel.wheels[0]!.sha256 = 'a'.repeat(64)
|
||||
distribution.pythonPackages['python-docx'] = '1.2.1'
|
||||
const original = primaryRuntimePayloadDigest('mac-arm64', lock, '11.7.0')
|
||||
expect(primaryRuntimePayloadDigest('mac-arm64', wheel, '11.7.0')).not.toBe(original)
|
||||
expect(primaryRuntimePayloadDigest('mac-arm64', distribution, '11.7.0')).not.toBe(original)
|
||||
expect(primaryRuntimePayloadDigest('mac-arm64', lock, '11.7.1')).not.toBe(original)
|
||||
})
|
||||
|
||||
it('reports missing distribution metadata before trying to execute a stale native payload', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'desktop-stale-runtime-'))
|
||||
try {
|
||||
await writeFile(join(root, 'runtime.json'), JSON.stringify({ platform: process.platform, arch: process.arch }))
|
||||
expect(() => { smokePrimaryRuntime(root) }).toThrow('missing Python distribution versions; prepare the payload')
|
||||
} 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)
|
||||
expect(await downloadPrimaryRuntimeAsset('https://unused.invalid/library.whl', hash, root)).toBe(archive)
|
||||
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')
|
||||
await expect(downloadPrimaryRuntimeAsset('https://unused.invalid/library.whl', hash, root)).rejects.toThrow('checksum mismatch')
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('fully extracts a large deflate-compressed wheel entry', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'desktop-large-wheel-'))
|
||||
try {
|
||||
const expected = Buffer.alloc(1024 * 1024)
|
||||
// Seeded xorshift bytes keep the compressed entry larger than the stream buffers.
|
||||
let state = 26
|
||||
for (let index = 0; index < expected.length; index++) {
|
||||
state ^= state << 13
|
||||
state ^= state >>> 17
|
||||
state ^= state << 5
|
||||
expected[index] = state & 255
|
||||
}
|
||||
const archive = join(root, 'large.whl')
|
||||
await writeFile(archive, zipSync({ 'large.bin': expected }, { level: 6 }))
|
||||
await unpackPrimaryRuntimeWheel(archive, root)
|
||||
expect(await readFile(join(root, 'large.bin'))).toEqual(expected)
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('retains auxiliary wheel scripts without generating command wrappers', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'desktop-wheel-'))
|
||||
try {
|
||||
const archive = join(root, 'relocated.whl')
|
||||
await writeFile(archive, relocatedWheel)
|
||||
await unpackPrimaryRuntimeWheel(archive, join(root, 'site-packages'))
|
||||
expect(await readFile(join(root, 'site-packages/sample-1.0.data/scripts/sample'), 'utf8')).toBe('requires relocation\n')
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('rejects library files requiring an unsupported installation scheme', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'desktop-wheel-'))
|
||||
try {
|
||||
const archive = join(root, 'relocated.whl')
|
||||
await writeFile(archive, externalLibraryWheel)
|
||||
await expect(unpackPrimaryRuntimeWheel(archive, join(root, 'site-packages'))).rejects.toThrow('unsupported installation paths')
|
||||
} finally {
|
||||
await rm(root, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('copies complete Office resources outside the application archive and removes obsolete assets', async () => {
|
||||
const root = await mkdtemp(join(tmpdir(), 'desktop-office-assets-'))
|
||||
try {
|
||||
const source = join(root, 'package', 'assets')
|
||||
const destination = join(root, 'Contents', 'Resources', 'runtime', 'office-skills')
|
||||
await mkdir(join(source, 'scripts'), { recursive: true })
|
||||
await writeFile(join(source, 'scripts', 'check_office.py'), 'print("checker")\n')
|
||||
for (const name of ['office-docx', 'office-pptx', 'office-xlsx']) {
|
||||
await mkdir(join(source, name))
|
||||
await writeFile(join(source, name, 'SKILL.md'), `# ${name}\n`)
|
||||
}
|
||||
await prepareOfficeSkillAssets(source, destination)
|
||||
await writeFile(join(destination, 'obsolete.py'), 'old helper')
|
||||
await prepareOfficeSkillAssets(source, destination)
|
||||
for (const name of ['office-docx', 'office-pptx', 'office-xlsx']) {
|
||||
expect(await readFile(join(destination, name, 'SKILL.md'), 'utf8')).toBe(`# ${name}\n`)
|
||||
}
|
||||
expect(await readFile(join(destination, 'scripts', 'check_office.py'), 'utf8')).toBe('print("checker")\n')
|
||||
await expect(readFile(join(destination, 'obsolete.py'))).rejects.toMatchObject({ code: 'ENOENT' })
|
||||
} finally { await rm(root, { recursive: true, force: true }) }
|
||||
})
|
||||
|
||||
it('gives Python-only payloads a distinct identity', () => {
|
||||
expect(primaryRuntimePayloadDigest('linux-x64', lock, undefined)).not.toBe(primaryRuntimePayloadDigest('linux-x64', lock, '11.7.0'))
|
||||
})
|
||||
@@ -0,0 +1,210 @@
|
||||
/** 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 { cp } from 'node:fs/promises'
|
||||
import { createRequire } from 'node:module'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { dirname, join, resolve } from 'node:path'
|
||||
import { parseArgs } from 'node:util'
|
||||
import extractZip from 'extract-zip'
|
||||
import { x as extractTar } from 'tar'
|
||||
import { workspaceDependencyPaths, type PrimaryRuntimeManifest } from '../../packages/skill/tool-workspace-dependencies/src/index.ts'
|
||||
import lock from './lock.json' with { type: 'json' }
|
||||
|
||||
/**
|
||||
* 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 cache - Download cache directory.
|
||||
* @returns Verified local archive path.
|
||||
*/
|
||||
export async function downloadPrimaryRuntimeAsset(url: string, sha256: string, cache: string): Promise<string> {
|
||||
const destination = join(cache, sha256)
|
||||
let bytes: Buffer
|
||||
try { bytes = readFileSync(destination) } catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error
|
||||
const response = await fetch(url)
|
||||
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)
|
||||
return destination
|
||||
}
|
||||
|
||||
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`
|
||||
return downloadPrimaryRuntimeAsset(`https://github.com/astral-sh/python-build-standalone/releases/download/${lock.pythonRelease}/${encodeURIComponent(filename)}`, artifact.pythonSha256, cache)
|
||||
}
|
||||
|
||||
/**
|
||||
* Identify the inputs that assemble one target's payload, excluding unrelated target locks.
|
||||
* @param target - Runtime target whose archives are installed.
|
||||
* @param runtimeLock - Locked interpreter and wheel inputs.
|
||||
* @param pnpmVersion - Package-manager version copied into the payload.
|
||||
* @returns SHA-256 payload identity for installation reuse.
|
||||
*/
|
||||
export function primaryRuntimePayloadDigest(
|
||||
target: keyof typeof lock.targets, runtimeLock: typeof lock, pnpmVersion: string | undefined,
|
||||
): string {
|
||||
const { pythonVersion, pythonRelease, nodeVersion, wheels, pythonPackages } = runtimeLock
|
||||
// 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: 3, target, pythonVersion, pythonRelease, nodeVersion: pnpmVersion === undefined ? undefined : nodeVersion,
|
||||
artifact: runtimeLock.targets[target], wheels, pythonPackages, pnpm: pnpmVersion,
|
||||
})).digest('hex')
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpack a locked library wheel, retaining auxiliary scripts in its distribution data directory.
|
||||
* @param archive - Hash-verified wheel archive.
|
||||
* @param destination - Absolute site-packages directory.
|
||||
* @returns Resolves after extraction without command wrappers; rejects other wheel installation schemes.
|
||||
*/
|
||||
export async function unpackPrimaryRuntimeWheel(archive: string, destination: string): Promise<void> {
|
||||
await extractZip(archive, {
|
||||
dir: destination,
|
||||
onEntry: (entry) => {
|
||||
const [directory, scheme] = entry.fileName.split('/')
|
||||
if (directory?.endsWith('.data') && scheme !== '' && scheme !== 'scripts') {
|
||||
throw new Error(`primary runtime: wheel requires unsupported installation paths: ${entry.fileName}`)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the skill package's complete asset tree to ordinary filesystem resources.
|
||||
* @param source - The package's assets directory.
|
||||
* @param destination - External Office skill resource directory.
|
||||
* @returns Resolves after replacing the external assets with the complete package tree.
|
||||
*/
|
||||
export async function prepareOfficeSkillAssets(source: string, destination: string): Promise<void> {
|
||||
rmSync(destination, { recursive: true, force: true })
|
||||
await cp(source, destination, { recursive: true, dereference: true })
|
||||
}
|
||||
|
||||
/** A locked interpreter and wheel target. */
|
||||
export type PrimaryRuntimeTarget = keyof typeof lock.targets
|
||||
|
||||
/** Build-only inputs shared by Desktop and SDK carriers. */
|
||||
export interface PreparePrimaryRuntimeOptions {
|
||||
/** Target whose archives and wheels are downloaded. */
|
||||
readonly target: PrimaryRuntimeTarget
|
||||
/** Resource directory receiving primary-runtime/ and office-skills/. */
|
||||
readonly output: string
|
||||
/** SHA-256-addressed archive cache. */
|
||||
readonly cache: string
|
||||
/** Carrier release recorded in the legacy desktopVersion manifest field. */
|
||||
readonly version: string
|
||||
/** Omit Node.js and pnpm for carriers providing only Python. */
|
||||
readonly pythonOnly?: boolean
|
||||
}
|
||||
|
||||
/**
|
||||
* Materialize locked interpreters, libraries and Office resources without executing target code.
|
||||
* @param options - Explicit target and carrier-owned output locations.
|
||||
* @returns Resolves after the complete payload and skills have been copied to the output directory.
|
||||
*/
|
||||
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-'))
|
||||
try {
|
||||
const output = join(staging, 'payload')
|
||||
const dependencies = join(output, 'dependencies')
|
||||
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 })
|
||||
}
|
||||
await extractTar({ file: await pythonArchive(target, paths.downloads), cwd: dependencies })
|
||||
const manifest: PrimaryRuntimeManifest = {
|
||||
desktopVersion: options.version,
|
||||
platform: target === 'win-x64' ? 'win32' : target === 'linux-x64' ? 'linux' : 'darwin',
|
||||
arch: target === 'mac-arm64' ? 'arm64' : 'x64',
|
||||
payloadDigest: primaryRuntimePayloadDigest(target, lock, pnpmVersion),
|
||||
pythonPackages: lock.pythonPackages,
|
||||
components: {
|
||||
python: lock.pythonVersion,
|
||||
...(pnpmVersion === undefined ? {} : { node: lock.nodeVersion, pnpm: pnpmVersion }),
|
||||
numpy: lock.pythonPackages.numpy, pandas: lock.pythonPackages.pandas,
|
||||
},
|
||||
}
|
||||
const entries = workspaceDependencyPaths(output, manifest)
|
||||
for (const wheel of [...artifact.wheels, ...lock.wheels]) {
|
||||
await unpackPrimaryRuntimeWheel(await downloadPrimaryRuntimeAsset(wheel.url, wheel.sha256, paths.downloads), 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 })
|
||||
} 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'),
|
||||
join(paths.runtime, 'office-skills'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the native payload's interpreters, package manager and Python libraries.
|
||||
* @param root - Final payload directory, including any platform signatures.
|
||||
* @param environment - Scrubbed subprocess environment; defaults to excluding credential-shaped names.
|
||||
*/
|
||||
export function smokePrimaryRuntime(root: string, environment: NodeJS.ProcessEnv = Object.fromEntries(
|
||||
Object.entries(process.env).filter(([name]) => !/(?:KEY|SECRET|TOKEN|PASSWORD)/iu.test(name)),
|
||||
)): void {
|
||||
const manifest = JSON.parse(readFileSync(join(root, 'runtime.json'), 'utf8')) as PrimaryRuntimeManifest
|
||||
if (manifest.platform !== process.platform || manifest.arch !== process.arch) return
|
||||
if (manifest.pythonPackages === undefined) throw new Error('primary runtime: missing Python distribution versions; prepare the payload before running its smoke checks.')
|
||||
const entries = workspaceDependencyPaths(root, manifest)
|
||||
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),
|
||||
manifest.components.python, join(dirname(root), 'office-skills', 'scripts', 'check_office.py')], options)
|
||||
execFileSync(entries.python, ['-I', '-B', '-m', 'pip', 'check'], options)
|
||||
if (entries.node !== undefined) execFileSync(entries.node, ['-e', `if (process.versions.node !== ${JSON.stringify(manifest.components.node)}) process.exit(1)`], options)
|
||||
if (entries.pnpm !== undefined && entries.node !== undefined) execFileSync(entries.node, [entries.pnpm, '--version'], options)
|
||||
}
|
||||
|
||||
if (import.meta.main) {
|
||||
const { values } = parseArgs({ options: {
|
||||
target: { type: 'string' }, output: { type: 'string' }, cache: { type: 'string' },
|
||||
'python-only': { type: 'boolean', default: false },
|
||||
} })
|
||||
if (!values.target || !Object.hasOwn(lock.targets, values.target) || !values.output) {
|
||||
throw new Error(`Usage: pnpm run prepare:primary-runtime --target <${Object.keys(lock.targets).join('|')}> --output <directory> [--cache <directory>] [--python-only]`)
|
||||
}
|
||||
const { version } = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8')) as { version: string }
|
||||
const output = resolve(values.output)
|
||||
await preparePrimaryRuntime({
|
||||
target: values.target as PrimaryRuntimeTarget, output,
|
||||
cache: values.cache ?? join(tmpdir(), 'dsh-primary-runtime-downloads'), version,
|
||||
pythonOnly: values['python-only'],
|
||||
})
|
||||
smokePrimaryRuntime(join(output, 'primary-runtime'))
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
"""Exercise the relocated Office payload with its own isolated interpreter."""
|
||||
|
||||
import importlib.metadata
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
import numpy
|
||||
import pandas
|
||||
from docx import Document
|
||||
from docx.shared import Inches as DocxInches
|
||||
from openpyxl import Workbook, load_workbook
|
||||
from openpyxl.styles import Font
|
||||
from PIL import Image
|
||||
from pptx import Presentation
|
||||
from pptx.chart.data import CategoryChartData
|
||||
from pptx.enum.chart import XL_CHART_TYPE
|
||||
from pptx.util import Inches
|
||||
|
||||
|
||||
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
|
||||
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.
|
||||
expected_names = {re.sub(r"[-_.]+", "-", name).lower() for name in versions} | {"pip"}
|
||||
installed_names = {
|
||||
re.sub(r"[-_.]+", "-", distribution.metadata["Name"]).lower()
|
||||
for distribution in importlib.metadata.distributions()
|
||||
}
|
||||
assert installed_names == expected_names, {"unexpected": sorted(installed_names - expected_names), "missing": sorted(expected_names - installed_names)}
|
||||
for name, expected in versions.items():
|
||||
actual = importlib.metadata.version(name)
|
||||
assert actual == expected, (name, actual, expected)
|
||||
assert numpy.arange(4).sum() == 6
|
||||
assert pandas.DataFrame({"n": [1, 2]}).n.sum() == 3
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix="dsh-office-smoke-") as directory:
|
||||
root = Path(directory)
|
||||
image = root / "chart.png"
|
||||
Image.new("RGB", (80, 40), "#2878bc").save(image)
|
||||
with Image.open(image) as restored:
|
||||
assert restored.size == (80, 40)
|
||||
|
||||
document = Document()
|
||||
document.add_heading("Office 文档", 0)
|
||||
document.add_paragraph("Editable text")
|
||||
document.add_table(rows=2, cols=2).cell(1, 1).text = "42"
|
||||
document.add_picture(str(image), width=DocxInches(1))
|
||||
document.save(root / "document.docx")
|
||||
reopened_document = Document(root / "document.docx")
|
||||
assert reopened_document.tables[0].cell(1, 1).text == "42"
|
||||
assert reopened_document.paragraphs[0].text == "Office 文档"
|
||||
|
||||
presentation = Presentation()
|
||||
slide = presentation.slides.add_slide(presentation.slide_layouts[6])
|
||||
slide.shapes.add_textbox(Inches(1), Inches(1), Inches(4), Inches(1)).text = "Office 演示"
|
||||
slide.shapes.add_picture(str(image), Inches(1), Inches(2))
|
||||
chart_data = CategoryChartData()
|
||||
chart_data.categories = ["A", "B"]
|
||||
chart_data.add_series("Values", [2, 4])
|
||||
slide.shapes.add_chart(XL_CHART_TYPE.COLUMN_CLUSTERED, Inches(3), Inches(2), Inches(4), Inches(3), chart_data)
|
||||
presentation.save(root / "presentation.pptx")
|
||||
reopened_presentation = Presentation(root / "presentation.pptx")
|
||||
assert len(reopened_presentation.slides) == 1
|
||||
chart = next(shape.chart for shape in reopened_presentation.slides[0].shapes if shape.has_chart)
|
||||
assert list(chart.series[0].values) == [2.0, 4.0]
|
||||
|
||||
workbook = Workbook()
|
||||
sheet = workbook.active
|
||||
sheet.append(["Value", "Formula"])
|
||||
sheet.append([42, "=A2*2"])
|
||||
sheet["A1"].font = Font(bold=True)
|
||||
workbook.save(root / "workbook.xlsx")
|
||||
reopened_workbook = load_workbook(root / "workbook.xlsx")
|
||||
try:
|
||||
assert reopened_workbook.active["A2"].value == 42
|
||||
assert reopened_workbook.active["B2"].value == "=A2*2"
|
||||
assert reopened_workbook.active["A1"].font.bold
|
||||
finally:
|
||||
reopened_workbook.close()
|
||||
assert pandas.read_excel(root / "workbook.xlsx")["Value"].iloc[0] == 42
|
||||
for file, arguments in [
|
||||
("document.docx", ["--contains", "Office 文档"]),
|
||||
("presentation.pptx", ["--contains", "Office 演示", "--count", "1"]),
|
||||
("workbook.xlsx", ["--contains", "Value", "--count", "1"]),
|
||||
]:
|
||||
checked = subprocess.run([sys.executable, "-I", "-B", sys.argv[3], str(root / file), *arguments],
|
||||
check=False, capture_output=True, text=True, timeout=30)
|
||||
assert checked.returncode == 0 and json.loads(checked.stdout)["verdict"] == "pass", checked.stdout + checked.stderr
|
||||
print("Office runtime versions and document round trips passed.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user