feat: add plugin framework with UI contributions and suite selection
- Implemented PluginBlocks component to render various plugin UI elements. - Created SuitePicker for selecting test suites and questions. - Introduced usePluginUI hook for managing plugin UI state and manifest. - Developed DocsPage for comprehensive plugin framework documentation. - Added PluginPage to render pages declared by plugins based on the current path.
This commit is contained in:
+26
-42
@@ -1,46 +1,30 @@
|
||||
import re
|
||||
import textwrap
|
||||
from pathlib import Path
|
||||
from typing import Dict, List
|
||||
"""Prompt loading, kept as a thin façade over :mod:`suites`.
|
||||
|
||||
from config import TESTS_DIR
|
||||
``tests/`` used to be a flat directory of ``test1.txt`` … ``testN.txt``. It is
|
||||
now a set of named suites — built-ins under ``.core/suites/`` and custom ones
|
||||
under ``tests/<slug>/`` — so every question carries a qualified ``<slug>/<file>``
|
||||
ID. Two suites containing ``test1.txt`` is normal, and nothing downstream may
|
||||
key off the bare filename.
|
||||
|
||||
This module survives so ``runner.py`` and anything importing
|
||||
``load_test_prompts`` keep working; the logic lives in :mod:`suites`.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Dict, List, Optional, Sequence
|
||||
|
||||
from suites import load_prompts
|
||||
|
||||
__all__ = ["load_test_prompts"]
|
||||
|
||||
|
||||
def _natural_key(path: Path) -> List[object]:
|
||||
parts = re.split(r"(\d+)", path.stem)
|
||||
return [int(part) if part.isdigit() else part.lower() for part in parts]
|
||||
def load_test_prompts(slugs: Optional[Sequence[str]] = None) -> List[Dict[str, str]]:
|
||||
"""Questions to run.
|
||||
|
||||
|
||||
def load_test_prompts() -> List[Dict[str, str]]:
|
||||
"""Load prompt files from the tests directory."""
|
||||
if not TESTS_DIR.exists():
|
||||
return []
|
||||
|
||||
prompt_entries: List[Dict[str, str]] = []
|
||||
|
||||
for prompt_path in sorted(TESTS_DIR.glob("*.txt"), key=_natural_key):
|
||||
try:
|
||||
raw_text = prompt_path.read_text(encoding="utf-8")
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
prompt_text = textwrap.dedent(raw_text).strip()
|
||||
if not prompt_text:
|
||||
continue
|
||||
|
||||
title = prompt_path.stem
|
||||
for line in prompt_text.splitlines():
|
||||
stripped_line = line.strip()
|
||||
if stripped_line:
|
||||
title = stripped_line
|
||||
break
|
||||
|
||||
prompt_entries.append(
|
||||
{
|
||||
"title": title,
|
||||
"prompt": prompt_text,
|
||||
"filename": prompt_path.name,
|
||||
}
|
||||
)
|
||||
|
||||
return prompt_entries
|
||||
With no argument this is **every built-in suite**, deliberately excluding
|
||||
custom ones: a bare ``python auto-test.py`` should mean the same thing on
|
||||
every machine rather than depending on local scratch suites. Pass explicit
|
||||
slugs to include custom suites.
|
||||
"""
|
||||
return load_prompts(slugs)
|
||||
|
||||
Reference in New Issue
Block a user