Coverage for / home / runner / work / bijux-cli / bijux-cli / src / bijux_cli / services / diagnostics / contracts.py: 100%
29 statements
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 17:59 +0000
« prev ^ index » next coverage.py v7.13.2, created at 2026-01-26 17:59 +0000
1# SPDX-License-Identifier: Apache-2.0
2# Copyright © 2025 Bijan Mousavi
4"""Defines contracts for diagnostics services."""
6from __future__ import annotations
8from collections.abc import Mapping
9from dataclasses import dataclass
10from typing import Any, Protocol, runtime_checkable
13@dataclass(frozen=True)
14class DiagnosticsConfig:
15 """Configuration for diagnostics services."""
17 enabled: bool
18 telemetry_enabled: bool
21@runtime_checkable
22class AuditProtocol(Protocol):
23 """Defines the contract for auditing command execution."""
25 def log(self, cmd: list[str], *, executor: str) -> None:
26 """Record a command execution."""
27 ...
29 def run(self, cmd: list[str], *, executor: str) -> tuple[int, bytes, bytes]:
30 """Run a command through the audit service."""
31 ...
33 def cli_audit(self) -> None:
34 """Run an audit of the CLI environment."""
35 ...
37 def shutdown(self) -> None:
38 """Shutdown the audit service."""
39 ...
42@runtime_checkable
43class DocsProtocol(Protocol):
44 """Defines the contract for documentation generation."""
46 def render(self, spec: Mapping[str, Any], *, fmt: Any, pretty: bool = False) -> str:
47 """Render a document spec to a string."""
48 ...
50 def write(
51 self,
52 spec: Mapping[str, Any],
53 *,
54 fmt: Any,
55 name: str,
56 pretty: bool = False,
57 ) -> str:
58 """Write a document spec to disk."""
59 ...
62@runtime_checkable
63class DoctorProtocol(Protocol):
64 """Defines the contract for health checks."""
66 def check_health(self) -> str:
67 """Run health checks and return a summary."""
68 ...
71@runtime_checkable
72class MemoryProtocol(Protocol):
73 """Defines the contract for key-value memory storage."""
75 def get(self, key: str) -> Any:
76 """Retrieve a stored value."""
77 ...
79 def set(self, key: str, value: Any) -> None:
80 """Store a key-value pair."""
81 ...
83 def delete(self, key: str) -> None:
84 """Delete a stored value."""
85 ...
87 def clear(self) -> None:
88 """Clear all stored values."""
89 ...
91 def keys(self) -> list[str]:
92 """List stored keys."""
93 ...
96__all__ = [
97 "AuditProtocol",
98 "DocsProtocol",
99 "DoctorProtocol",
100 "MemoryProtocol",
101 "DiagnosticsConfig",
102]