sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -0,0 +1,71 @@
|
||||
"""Focused tests for the built-in public-document agent seed."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def _make_seed(monkeypatch, tmp_path):
|
||||
from app.gateway.routers import _gongwen_seed as seed
|
||||
|
||||
class FakePaths:
|
||||
def agent_dir(self, agent_id: str):
|
||||
return tmp_path / "agents" / agent_id
|
||||
|
||||
monkeypatch.setattr(seed, "get_paths", lambda: FakePaths())
|
||||
monkeypatch.setattr(seed, "_skills_public_dir", lambda: tmp_path / "skills" / "public")
|
||||
return seed
|
||||
|
||||
|
||||
def test_gongwen_seed_installs_agent_and_workflow_skill(tmp_path, monkeypatch):
|
||||
seed = _make_seed(monkeypatch, tmp_path)
|
||||
|
||||
assert seed.ensure_gongwen_agent() is True
|
||||
assert (tmp_path / "agents" / seed.GONGWEN_AGENT_ID / "config.yaml").is_file()
|
||||
skill = tmp_path / "skills" / "public" / seed.GONGWEN_WORKFLOW_SKILL / "SKILL.md"
|
||||
assert skill.is_file()
|
||||
assert "gongwen-assistant" in skill.read_text(encoding="utf-8")
|
||||
|
||||
# A same-version restart keeps deployed copies untouched.
|
||||
assert seed.ensure_gongwen_agent() is False
|
||||
|
||||
|
||||
def test_gongwen_seed_installs_the_engine_skill(tmp_path, monkeypatch):
|
||||
seed = _make_seed(monkeypatch, tmp_path)
|
||||
|
||||
assert seed.ensure_gongwen_agent() is True
|
||||
engine = tmp_path / "skills" / "public" / seed.GONGWEN_ENGINE_SKILL
|
||||
assert (engine / "SKILL.md").is_file()
|
||||
assert (engine / "scripts" / "run_gongwen.py").is_file()
|
||||
assert (engine / "scripts" / "delivery.py").is_file()
|
||||
assert (engine / "references" / "word-corrections.md").is_file()
|
||||
assert (engine / "vendor" / "docx" / "__init__.py").is_file()
|
||||
# Bytecode caches must never ship with the seed.
|
||||
assert not list(engine.rglob("__pycache__"))
|
||||
assert not list(engine.rglob("*.pyc"))
|
||||
# The deployed copy records the seed version it was written from.
|
||||
version = (engine / ".gongwen-seed-version").read_text(encoding="utf-8").strip()
|
||||
assert version == str(seed._SEED_VERSION)
|
||||
|
||||
|
||||
def test_gongwen_seed_refreshes_only_when_the_version_bumps(tmp_path, monkeypatch):
|
||||
seed = _make_seed(monkeypatch, tmp_path)
|
||||
|
||||
assert seed.ensure_gongwen_agent() is True
|
||||
workflow = tmp_path / "skills" / "public" / seed.GONGWEN_WORKFLOW_SKILL / "SKILL.md"
|
||||
original = workflow.read_text(encoding="utf-8")
|
||||
|
||||
# On-site edits at the same seed version survive a restart.
|
||||
workflow.write_text("on-site edit", encoding="utf-8")
|
||||
assert seed.ensure_gongwen_agent() is False
|
||||
assert workflow.read_text(encoding="utf-8") == "on-site edit"
|
||||
|
||||
# A pre-versioning deployment (no marker file) refreshes to the shipped
|
||||
# seed, which is the upgrade path for already-installed copies.
|
||||
(tmp_path / "skills" / "public" / seed.GONGWEN_WORKFLOW_SKILL / ".gongwen-seed-version").unlink()
|
||||
assert seed.ensure_gongwen_agent() is False
|
||||
assert workflow.read_text(encoding="utf-8") == original
|
||||
|
||||
# Bumping the seed version replaces stale deployed copies as well.
|
||||
workflow.write_text("stale edit", encoding="utf-8")
|
||||
monkeypatch.setattr(seed, "_SEED_VERSION", seed._SEED_VERSION + 1)
|
||||
assert seed.ensure_gongwen_agent() is True
|
||||
assert workflow.read_text(encoding="utf-8") == original
|
||||
Reference in new issue
Block a user