fix(dsh): slim packaged runtime and surface startup errors
This commit is contained in:
1 parent
df250e04ba
commit
caa79e7fcf
7 files changed
+159
-5
No files matched your search
@@ -0,0 +1,40 @@
|
||||
from pathlib import Path
|
||||
import importlib.util
|
||||
|
||||
_MODULE = Path(__file__).resolve().parents[2] / 'packaging' / 'dsh_runtime_staging.py'
|
||||
_SPEC = importlib.util.spec_from_file_location('dsh_runtime_staging', _MODULE)
|
||||
_LOADED = importlib.util.module_from_spec(_SPEC)
|
||||
assert _SPEC and _SPEC.loader
|
||||
_SPEC.loader.exec_module(_LOADED)
|
||||
stage_node_modules = _LOADED.stage_node_modules
|
||||
|
||||
|
||||
def _package(root: Path, name: str, *, os=None, cpu=None, files=()):
|
||||
path = root / name
|
||||
path.mkdir(parents=True)
|
||||
manifest = {'name': name, 'version': '1.0.0'}
|
||||
if os is not None:
|
||||
manifest['os'] = os
|
||||
if cpu is not None:
|
||||
manifest['cpu'] = cpu
|
||||
import json
|
||||
(path / 'package.json').write_text(json.dumps(manifest), encoding='utf8')
|
||||
for relative, content in files:
|
||||
target = path / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_text(content, encoding='utf8')
|
||||
|
||||
|
||||
def test_stage_dsh_runtime_keeps_windows_runtime_and_prunes_other_platforms(tmp_path):
|
||||
source = tmp_path / 'node_modules'
|
||||
(source / '@deepseek-ai' / 'dsh').mkdir(parents=True)
|
||||
(source / '@deepseek-ai' / 'dsh' / 'package.json').write_text('{}', encoding='utf8')
|
||||
_package(source, 'win-addon', os=['win32'], cpu=['x64'], files=[('index.js', 'ok')])
|
||||
_package(source, 'linux-addon', os=['linux'], files=[('index.js', 'drop')])
|
||||
_package(source, 'docs-only', files=[('index.js', 'ok'), ('README.md', 'drop'), ('source.ts', 'drop')])
|
||||
staged = stage_node_modules(source, tmp_path / 'staged')
|
||||
assert (staged / 'win-addon' / 'index.js').read_text(encoding='utf8') == 'ok'
|
||||
assert not (staged / 'linux-addon').exists()
|
||||
assert (staged / 'docs-only' / 'index.js').is_file()
|
||||
assert not (staged / 'docs-only' / 'README.md').exists()
|
||||
assert not (staged / 'docs-only' / 'source.ts').exists()
|
||||
Reference in new issue
Block a user