deer-flow/backend/tests/test_extension_api_surface.py
Totoro 517a8309a2
feat(extensions): allow ModelTool plugins to return structured artifacts (#6861)
* test(plugins): capture opt-in artifact RED (18 failed, 13 passed)

* feat(plugins): add typed opt-in artifacts (31 ToolNode tests pass)

* test(extensions): require API 0.2.6 (version RED verified)

* build(extensions): pin API 0.2.6 (installed wheel guards GREEN)

* test(examples): verify plugin artifacts through checkpoint restart

* test(extensions): reproduce artifact key coercion (8 RED cases)

* fix(extensions): reject non-string artifact keys (185 tests GREEN)

* fix(frontend): list bundled retrieval example in extension catalog

* test(mcp): reconcile recovered notification at stored due time

---------

Co-authored-by: Totoro-qaq <279883115+Totoro-qaq@users.noreply.github.com>
2026-10-14 17:24:32 +08:00

82 lines
2.5 KiB
Python

"""The contract package's public surface must import cleanly and stay complete.
A typo in a re-exported name breaks `import deerflow_extension_api` for every
extension, which is a silent-until-startup failure for third parties.
"""
import importlib
def test_public_surface_imports_and_matches_all():
module = importlib.import_module("deerflow_extension_api")
for name in module.__all__:
assert hasattr(module, name), f"__all__ advertises {name!r} but it is not exported"
def test_runtime_deps_is_exported_under_its_documented_name():
from deerflow_extension_api import ExtensionRuntimeDeps
assert ExtensionRuntimeDeps.__name__ == "ExtensionRuntimeDeps"
def test_api_version_matches_the_packaging_metadata():
"""A contract version that disagrees with the wheel's version makes pip
resolution and the ``@extension`` marker disagree about the same host."""
import tomllib
from pathlib import Path
from deerflow_extension_api import API_VERSION
pyproject = Path(__file__).resolve().parents[1] / "packages" / "extension-api" / "pyproject.toml"
declared = tomllib.loads(pyproject.read_text(encoding="utf-8"))["project"]["version"]
assert declared == API_VERSION
def test_every_contract_kind_added_for_the_0_2_series_is_exported():
import deerflow_extension_api as api
for name in (
"ActionContext",
"BackendAction",
"BrowserModule",
"ModelTool",
"PluginToolResult",
"PluginContribution",
"SettingsField",
"ToolContext",
"AgentAssemblyDescriptor",
"AgentAssemblyObserver",
"CompactionEvent",
"ContentKind",
"ContextCompactionObserver",
"ExtensionPrincipal",
"MessageProvenance",
"MiddlewareDescriptor",
"PROVENANCE_KEYS",
"ReleasePolicyProvider",
"ToolDescriptor",
"canonical_hash",
"collect_release_policies",
"provenance_kwargs",
"read_provenance",
"require_admin",
"resolve_principal",
):
assert name in api.__all__, f"{name} must be part of the public contract"
def test_registry_protocol_declares_every_registration_method():
from deerflow_extension_api import ExtensionRegistry
for method in (
"middlewares",
"task_lifecycle",
"system_model_observer",
"agent_assembly_observer",
"context_compaction_observer",
"service",
"routers",
"plugin",
):
assert hasattr(ExtensionRegistry, method), f"ExtensionRegistry must declare {method}()"