clan-lib: Fix @API.register_abstract not throwing correct error when called directly without implementation

clan-app: Fix mypy lint

clan-lib: Mark test as with_core
This commit is contained in:
Qubasa
2025-07-10 14:20:57 +07:00
parent dd12104e2f
commit 3d26214009
5 changed files with 13 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ from clan_lib.dirs import user_data_dir
from clan_lib.log_manager import LogGroupConfig, LogManager
from clan_lib.log_manager import api as log_manager_api
from clan_app.api.file_gtk import open_file
from clan_app.api.file_gtk import open_clan_folder, open_file
from clan_app.api.middleware import (
ArgumentParsingMiddleware,
LoggingMiddleware,
@@ -56,10 +56,9 @@ def app_run(app_opts: ClanAppOptions) -> int:
# Populate the API global with all functions
load_in_all_api_functions()
API.overwrite_fn(open_file)
# Create a shared threads dictionary for both HTTP and Webview modes
shared_threads = {}
shared_threads: dict[str, tasks.WebThread] = {}
tasks.BAKEND_THREADS = shared_threads
# Start HTTP API server if requested
@@ -114,6 +113,9 @@ def app_run(app_opts: ClanAppOptions) -> int:
shared_threads=shared_threads,
)
API.overwrite_fn(open_file)
API.overwrite_fn(open_clan_folder)
# Add middleware to the webview
webview.add_middleware(ArgumentParsingMiddleware(api=API))
webview.add_middleware(LoggingMiddleware(log_manager=log_manager))

View File

@@ -126,7 +126,7 @@ class Webview:
)
else:
bridge = WebviewBridge(
webview=self, middleware_chain=tuple(self._middleware)
webview=self, middleware_chain=tuple(self._middleware), threads={}
)
self._bridge = bridge
return bridge

View File

@@ -97,7 +97,7 @@ class MethodRegistry:
def register_abstract(self, fn: Callable[..., T]) -> Callable[..., T]:
@wraps(fn)
def wrapper(*args: Any, op_key: str, **kwargs: Any) -> ApiResponse[T]:
def wrapper(*args: Any, **kwargs: Any) -> ApiResponse[T]:
msg = f"""{fn.__name__} - The platform didn't implement this function.
---

View File

@@ -1,11 +1,13 @@
from pathlib import Path
import pytest
from clan_cli.tests.fixtures_flakes import FlakeForTest
from clan_lib.clan.check import check_clan_valid
from clan_lib.flake import Flake
@pytest.mark.with_core
def test_check_clan_valid(
temporary_home: Path, test_flake_with_core: FlakeForTest, test_flake: FlakeForTest
) -> None:

View File

@@ -1,9 +1,13 @@
import logging
from clan_lib.api import API
from clan_lib.errors import ClanError
from clan_lib.flake import Flake
from clan_lib.nix_models.clan import InventoryMeta
from clan_lib.persist.inventory_store import InventoryStore
log = logging.getLogger(__name__)
@API.register
def get_clan_details(flake: Flake) -> InventoryMeta: