from __future__ import annotations
import base64
from pathlib import Path
import re
import shutil
import subprocess
import pytest
ROOT = Path(__file__).resolve().parents[1]
STORE = ROOT / "plugins" / "_agent_editor" / "webui" / "agent-editor-store.js"
MODAL = ROOT / "plugins" / "_agent_editor" / "webui" / "main.html"
TOOL_ROW = MODAL.with_name("tool-policy-row.html")
TOOLTIP_STORE = ROOT / "webui" / "components" / "tooltips" / "tooltip-store.js"
SWITCHER = (
ROOT
/ "plugins"
/ "_model_config"
/ "extensions"
/ "webui"
/ "chat-input-progress-start"
/ "model-switcher.html"
)
SWITCHER_MIXIN = ROOT / "plugins" / "_model_config" / "webui" / "switcher-mixin.js"
def test_agent_editor_surface_has_normative_entry_points_and_accessible_controls() -> None:
modal = MODAL.read_text(encoding="utf-8")
tool_row = TOOL_ROW.read_text(encoding="utf-8")
store = STORE.read_text(encoding="utf-8")
switcher = SWITCHER.read_text(encoding="utf-8")
tool_section = re.search(
r'data-agent-editor-section="3".*?(?=Edit" in switcher
assert "profile.customized" not in switcher
assert 'class="model-switcher-item agent-profile-edit"' not in switcher
assert "min-height: 24px" in re.search(
r"\.agent-profile-row-edit\s*\{([^}]*)\}", switcher
).group(1)
assert "createAgentProfileChat" not in switcher
assert all(
label in modal
for label in (
"Identity",
"Prompt files",
"Tools",
"MCPs",
"Skills",
"Review",
"Save & test",
)
)
assert 'aria-label="Editor mode"' in modal
assert "Allow selected" not in modal and "Block selected" not in modal
assert "No optional tools" not in modal
assert 'class="agent-model-preset-picker"' in modal
assert modal.count('x-model="$store.agentEditor.draft.modelPreset"') == 2
assert modal.count('$el.value = $store.agentEditor.draft.modelPreset') == 2
assert 'id="agent-editor-easy-model-preset"' in easy_surface
easy_identity = easy_surface[easy_surface.index(''):easy_surface.index('')]
assert easy_identity.index('id="agent-editor-name"') < easy_identity.index('id="agent-editor-easy-model-preset"')
assert easy_surface.index('id="agent-editor-easy-model-preset"') < easy_surface.index('id="agent-editor-instructions"')
assert '`Use current preset (${$store.agentEditor.state.model_preset.effective})`' in modal
assert 'x-for="preset in $store.agentEditor.state.model_presets"' in modal
assert modal.count("Edit Presets") == 2
assert "Manage presets" not in modal
assert "model-preset-row" not in modal
assert easy_surface.count('') == 3
assert '' in modal
assert 'action in ($store.agentEditor.toolExpanded(tool) ? (tool.visibleActions || tool.actions) : [])' in tool_row
assert re.findall(r'(Choose individual (?:tools|MCPs|skills))
', easy_surface) == ["Choose individual tools", "Choose individual MCPs", "Choose individual skills"]
assert 'Category ' not in tool_section
assert "indeterminate" not in modal
assert modal.count('path="/plugins/_agent_editor/webui/tool-policy-row.html"') == 2
assert (modal + tool_row).count('class="policy-state-control" role="group"') == 6
assert (modal + tool_row).count(':aria-pressed="$store.agentEditor.policyItemState') == 15
assert tool_row.count(':aria-pressed="$store.agentEditor.toolGroupState') == 3
assert ':aria-expanded="$store.agentEditor.toolExpanded(tool)"' in tool_row
assert ':aria-controls="$id(\'tool-actions\')"' in tool_row
assert 'Individual tool actions
' in tool_row
assert 'border-left' not in re.search(r'\.tool-actions \{([^}]+)\}', modal)[1]
assert mcp_section.count('class="policy-item-description"') == 1
assert skill_section.count('class="policy-item-description"') == 1
assert "Your changes override the built-in profile. The original files stay unchanged." in modal
assert 'x-model="$store.agentEditor.projectName"' in modal
assert 'x-init="$nextTick(() => $el.value = $store.agentEditor.projectName)"' in modal
assert '@change="$store.agentEditor.onScopeChanged()"' in modal
assert '