fix(phase2): restore agent streams and persist extension installations

This commit is contained in:
2026-09-06 02:21:27 +08:00
parent 9497519e8b
commit 7001794a22
35 changed files with 870 additions and 39 deletions
+33
View File
@@ -0,0 +1,33 @@
import pytest
from app.acceptance import score
def segment(text, speaker='A', start=0, end=1):
return dict(text=text, speaker=speaker, start=start, end=end)
def test_exact_and_renamed_speakers():
result = score([segment('你好 世界')], [segment('你好 世界', 'cluster_4')])
assert result['text']['cer']['rate'] == 0
assert result['speaker']['der'] == 0
assert result['quality_gate'] == 'not_evaluated'
def test_edits_missed_and_false_alarms():
result = score([segment('a b')], [segment('a c', start=0, end=2)])
assert result['text']['wer']['rate'] == 0.5
assert result['speaker']['false_alarm_seconds'] == 1
result = score([segment('a')], [])
assert result['speaker']['der'] == 1
def test_overlap_and_confusion():
result = score([segment('a'), segment('b', 'B')], [segment('a')])
assert result['speaker']['der'] == 0.5
result = score([segment('a'), segment('b','B',1,2)], [segment('a','X',0,2)])
assert result['speaker']['confusion_seconds'] == 1
def test_requires_reference_and_valid_timing():
with pytest.raises(ValueError): score([], [])
with pytest.raises(ValueError): score([segment('a', end=float('nan'))], [])
@@ -0,0 +1,68 @@
from pathlib import Path
import pytest
from app.agent.tools import ToolRegistry
from app.extensions import SkillRuntime
from app.extensions.installed import InstalledRuntime
def package(root):
root.mkdir(parents=True)
(root / 'skill.yaml').write_text('skill_id: audit\nname: Audit\nversion: 1.0.0\npermissions: []\ntools: []\n', encoding='utf-8')
return root
def runtime(data):
return InstalledRuntime(SkillRuntime(ToolRegistry()), 'skill', data)
def test_restores_enabled_and_disabled_without_deleting_directory_install(tmp_path):
root = package(tmp_path / 'user-source')
data = tmp_path / 'data'
first = runtime(data); first.install(root); first.enable('audit')
second = runtime(data); second.restore()
assert second.get('audit').enabled
second.disable('audit')
third = runtime(data); third.restore()
assert not third.get('audit').enabled
third.uninstall('audit')
assert root.exists()
fourth = runtime(data); fourth.restore()
assert fourth.list() == []
def test_owned_zip_removed_and_changed_packages_not_auto_enabled(tmp_path):
data = tmp_path / 'data'
owned = data / 'extension-packages/skill-test'
root = package(owned / 'nested')
first = runtime(data); first.install(root, managed_root=owned); first.enable('audit')
(root / 'prompt.md').write_text('changed', encoding='utf-8')
first.disable('audit')
with pytest.raises(Exception, match='Package changed'):
first.enable('audit')
second = runtime(data); second.restore()
assert second.list() == []
assert second.restore_errors[0]['id'] == 'audit'
first.uninstall('audit')
assert not owned.exists()
def test_rejects_claiming_user_directory_as_managed(tmp_path):
root = package(tmp_path / 'source')
with pytest.raises(ValueError, match='managed'):
runtime(tmp_path / 'data').install(root, managed_root=root)
assert root.exists()
def test_builtin_disabled_plugin_does_not_break_startup():
from app.container import build_container
first = build_container()
first.plugins.disable('text-tools')
second = build_container()
assert not second.plugins.get('text-tools').enabled
assert second.skills.get('knowledge-assistant').missing_dependencies
second.plugins.enable('text-tools')
third = build_container()
assert third.plugins.get('text-tools').enabled
assert third.skills.get('knowledge-assistant').enabled
for container in (first, second, third):
container.plugins.shutdown(); container.mcp_servers.shutdown()