Files
Artemis-Eapil/tests/unit/test_ui_command.py
T

67 lines
2.2 KiB
Python

# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
import os
from artemis.interfaces.cli.commands import ui
from artemis.interfaces.cli.commands.ui import (
_resolve_npm_executable,
_showcase_build_required,
)
def test_resolve_npm_executable_prefers_windows_command_shim(monkeypatch):
paths = {
"npm.cmd": r"C:\Program Files\nodejs\npm.cmd",
"npm.exe": None,
"npm": r"C:\Program Files\nodejs\npm.cmd",
}
monkeypatch.setattr(ui.shutil, "which", paths.get)
assert _resolve_npm_executable("win32") == paths["npm.cmd"]
def test_resolve_npm_executable_uses_npm_on_posix(monkeypatch):
monkeypatch.setattr(
ui.shutil,
"which",
lambda command: "/usr/local/bin/npm" if command == "npm" else None,
)
assert _resolve_npm_executable("linux") == "/usr/local/bin/npm"
def test_showcase_build_required_when_source_is_newer(tmp_path):
showcase_dir = tmp_path / "showcase_ui"
source_file = showcase_dir / "src" / "app" / "agent.service.ts"
built_index = showcase_dir / "dist" / "frontend" / "browser" / "index.html"
source_file.parent.mkdir(parents=True)
built_index.parent.mkdir(parents=True)
source_file.write_text("source", encoding="utf-8")
built_index.write_text("build", encoding="utf-8")
os.utime(built_index, (100, 100))
os.utime(source_file, (200, 200))
assert _showcase_build_required(showcase_dir) is True
def test_showcase_build_not_required_when_build_is_current(tmp_path):
showcase_dir = tmp_path / "showcase_ui"
source_file = showcase_dir / "src" / "app" / "agent.service.ts"
built_index = showcase_dir / "dist" / "frontend" / "browser" / "index.html"
source_file.parent.mkdir(parents=True)
built_index.parent.mkdir(parents=True)
source_file.write_text("source", encoding="utf-8")
built_index.write_text("build", encoding="utf-8")
os.utime(source_file, (100, 100))
os.utime(built_index, (200, 200))
assert _showcase_build_required(showcase_dir) is False