agent-zero/tests/test_git_version_label.py
frdel 2ec52e1968 Add /stop API and stop-button UI/behavior
Introduce a /stop API handler (api/stop.py) and its DOX to cancel an AgentContext run without deleting the context; it clears pause state, progress and logs an info step. Add tests for stopping behavior, chat working animation, and sidebar timestamp/spacing (tests/*). Update helpers/git._format_git_timestamp to emit UTC timestamps without a timezone suffix and add a test for it. Implement stop-related UI/UX: input-store.js gains a stop state, activateSendButton(), and stopAgent() to call /stop; chat-bar-input.html updates the send button markup, aria-label and stop styles. Update sidebar/chat list CSS to add the working-bubble animation, adjust chat row layout and action-button visibility, and left-sidebar/bottom styling (nowrap timestamp). Modify messages.js to hide kvps.finished from display and complete the active process group when finished. Minor welcome-composer and documentation updates to reflect these behaviors.
2026-07-28 09:26:06 +02:00

81 lines
2.3 KiB
Python

import subprocess
import sys
import types
from pathlib import Path
PROJECT_ROOT = Path(__file__).resolve().parents[1]
if str(PROJECT_ROOT) not in sys.path:
sys.path.insert(0, str(PROJECT_ROOT))
sys.modules["giturlparse"] = types.SimpleNamespace(
parse=lambda *args, **kwargs: types.SimpleNamespace(
owner="",
repo="",
name="",
valid=False,
)
)
from helpers import git
def run_git(repo_dir: Path, *args: str) -> str:
completed = subprocess.run(
["git", "-C", str(repo_dir), *args],
check=True,
text=True,
capture_output=True,
)
return completed.stdout.strip()
def init_repo_with_tag(repo_dir: Path, branch: str) -> None:
run_git(repo_dir, "init")
run_git(repo_dir, "branch", "-m", branch)
run_git(repo_dir, "config", "user.name", "Test User")
run_git(repo_dir, "config", "user.email", "test@example.com")
(repo_dir / "tracked.txt").write_text("one\n", encoding="utf-8")
run_git(repo_dir, "add", "tracked.txt")
run_git(repo_dir, "commit", "-m", "initial")
run_git(repo_dir, "tag", "v1.9")
def add_commit(repo_dir: Path, content: str) -> None:
(repo_dir / "tracked.txt").write_text(content, encoding="utf-8")
run_git(repo_dir, "add", "tracked.txt")
run_git(repo_dir, "commit", "-m", "update")
def test_git_timestamp_is_utc_without_a_timezone_suffix():
assert git._format_git_timestamp(0) == "1970-01-01 00:00:00"
def test_sidebar_version_timestamp_stays_on_one_line():
sidebar_bottom = (
PROJECT_ROOT / "webui/components/sidebar/bottom/sidebar-bottom.html"
).read_text(encoding="utf-8")
assert "white-space: nowrap;" in sidebar_bottom
def test_git_version_label_shows_commit_distance_on_development(tmp_path):
init_repo_with_tag(tmp_path, "development")
add_commit(tmp_path, "two\n")
info = git.get_repo_release_info(str(tmp_path))
assert info.release is not None
assert info.release.short_tag == "v1.9"
assert info.release.version == "D v1.9+1"
def test_git_version_label_hides_commit_distance_on_main(tmp_path):
init_repo_with_tag(tmp_path, "main")
add_commit(tmp_path, "two\n")
info = git.get_repo_release_info(str(tmp_path))
assert info.release is not None
assert info.release.short_tag == "v1.9"
assert info.release.version == "M v1.9"