|
18 | 18 |
|
19 | 19 | import pytest |
20 | 20 |
|
21 | | -from veadk.cli.studio_package import write_studio_package |
| 21 | +from veadk.cli.studio_package import ( |
| 22 | + build_local_studio_requirements, |
| 23 | + write_studio_package, |
| 24 | +) |
22 | 25 | from veadk.cli.studio_sidecar_prerequisites import ( |
23 | 26 | DEFAULT_SIDECAR_BASE_IMAGE, |
24 | 27 | SIDECAR_BASE_IMAGE_ENV, |
@@ -52,6 +55,99 @@ def test_write_studio_package_bootstraps_the_preloaded_cli_archive( |
52 | 55 | assert '--archive "$ROOT_DIR/agentkit-linux-x64.tar.gz"' in run_script |
53 | 56 |
|
54 | 57 |
|
| 58 | +def test_write_studio_update_package_bootstraps_cli_from_remote_artifact( |
| 59 | + tmp_path: Path, |
| 60 | +) -> None: |
| 61 | + package = tmp_path / "package" |
| 62 | + |
| 63 | + write_studio_package( |
| 64 | + package, |
| 65 | + requirements="veadk-python\n", |
| 66 | + site_logo=None, |
| 67 | + provider="byteplus", |
| 68 | + bundle_agentkit_cli=False, |
| 69 | + ) |
| 70 | + |
| 71 | + run_script = (package / "run.sh").read_text(encoding="utf-8") |
| 72 | + assert "studio_companion --provider byteplus" in run_script |
| 73 | + assert "--archive" not in run_script |
| 74 | + assert "--runtime-manifest" not in run_script |
| 75 | + assert "export VEADK_STUDIO_AGENTKIT_CLI_ARCHIVE=" not in run_script |
| 76 | + assert "export VEADK_STUDIO_AGENTKIT_CLI_RUNTIME_MANIFEST=" not in run_script |
| 77 | + |
| 78 | + |
| 79 | +def test_local_studio_update_skips_full_offline_runtime( |
| 80 | + monkeypatch: pytest.MonkeyPatch, |
| 81 | + tmp_path: Path, |
| 82 | +) -> None: |
| 83 | + source_root = tmp_path / "source" |
| 84 | + package = tmp_path / "package" |
| 85 | + source_root.mkdir() |
| 86 | + (source_root / "pyproject.toml").write_text("", encoding="utf-8") |
| 87 | + (source_root / "uv.lock").write_text("", encoding="utf-8") |
| 88 | + (source_root / "README.md").write_text("", encoding="utf-8") |
| 89 | + (source_root / "LICENSE").write_text("", encoding="utf-8") |
| 90 | + (source_root / "frontend").mkdir() |
| 91 | + (source_root / "frontend" / "package.json").write_text("{}", encoding="utf-8") |
| 92 | + (source_root / "frontend" / "package-lock.json").write_text("{}", encoding="utf-8") |
| 93 | + (source_root / "veadk").mkdir() |
| 94 | + |
| 95 | + monkeypatch.setattr( |
| 96 | + "veadk.cli.studio_package._stage_wheel_source", |
| 97 | + lambda _source, _assets, wheel_source: wheel_source.mkdir(parents=True), |
| 98 | + ) |
| 99 | + monkeypatch.setattr( |
| 100 | + "veadk.cli.studio_package.shutil.which", lambda _: "/usr/bin/uv" |
| 101 | + ) |
| 102 | + |
| 103 | + def _build(command: list[str], *, check: bool) -> None: |
| 104 | + assert check is True |
| 105 | + output_dir = Path(command[-1]) |
| 106 | + (output_dir / "veadk_python-test-py3-none-any.whl").write_bytes(b"wheel") |
| 107 | + |
| 108 | + monkeypatch.setattr("veadk.cli.studio_package.subprocess.run", _build) |
| 109 | + monkeypatch.setattr( |
| 110 | + "veadk.cli.studio_package.validate_studio_wheel", lambda *_args: None |
| 111 | + ) |
| 112 | + |
| 113 | + def _stage_dependencies(destination: Path, **_: object) -> tuple[Path, ...]: |
| 114 | + dependency = destination / "dependency-test-py3-none-any.whl" |
| 115 | + dependency.write_bytes(b"dependency") |
| 116 | + return (dependency,) |
| 117 | + |
| 118 | + monkeypatch.setattr( |
| 119 | + "veadk.cli.studio_package.stage_studio_dependency_wheels", |
| 120 | + _stage_dependencies, |
| 121 | + ) |
| 122 | + monkeypatch.setattr( |
| 123 | + "veadk.cli.studio_package.stage_studio_dependency_sources", |
| 124 | + lambda *_args, **_kwargs: pytest.fail("thin update staged source archives"), |
| 125 | + ) |
| 126 | + monkeypatch.setattr( |
| 127 | + "veadk.cli.studio_package.stage_studio_agentkit_cli_archive", |
| 128 | + lambda *_args, **_kwargs: pytest.fail("thin update staged the CLI archive"), |
| 129 | + ) |
| 130 | + monkeypatch.setattr( |
| 131 | + "veadk.cli.studio_package.build_studio_offline_runtime", |
| 132 | + lambda *_args, **_kwargs: pytest.fail("thin update built an offline runtime"), |
| 133 | + ) |
| 134 | + |
| 135 | + requirements = build_local_studio_requirements( |
| 136 | + source_root, |
| 137 | + package, |
| 138 | + provider="byteplus", |
| 139 | + offline_runtime=False, |
| 140 | + ) |
| 141 | + |
| 142 | + assert requirements == ( |
| 143 | + "./dependency-test-py3-none-any.whl\n./veadk_python-test-py3-none-any.whl\n" |
| 144 | + ) |
| 145 | + assert sorted(path.name for path in package.iterdir()) == [ |
| 146 | + "dependency-test-py3-none-any.whl", |
| 147 | + "veadk_python-test-py3-none-any.whl", |
| 148 | + ] |
| 149 | + |
| 150 | + |
55 | 151 | def test_project_keeps_native_cli_outside_python_distributions() -> None: |
56 | 152 | root = Path(__file__).resolve().parents[2] |
57 | 153 | project = (root / "pyproject.toml").read_text(encoding="utf-8") |
|
0 commit comments