Coverage for /home/runner/work/bijux-cli/bijux-cli/src/bijux_cli/contracts/audit.py: 100%
9 statements
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
« prev ^ index » next coverage.py v7.10.4, created at 2025-08-19 23:36 +0000
1# SPDX-License-Identifier: MIT
2# Copyright © 2025 Bijan Mousavi
4"""Defines the contract for the audit logging and diagnostics service.
6This module specifies the `AuditProtocol`, a formal interface that any
7auditing service within the application must implement. This ensures a
8consistent API for logging command executions and performing system health
9checks, promoting modularity and testability.
10"""
12from __future__ import annotations
14from typing import Any, Protocol, TypeVar, runtime_checkable
16from bijux_cli.contracts.process import ProcessPoolProtocol
18T = TypeVar("T")
21@runtime_checkable
22class AuditProtocol(
23 ProcessPoolProtocol,
24 Protocol,
25):
26 """Defines the contract for audit logging and system diagnostics.
28 This interface specifies the methods required for securely logging command
29 executions, retrieving audit trails, and performing diagnostic checks on
30 the CLI environment. It inherits from `ProcessPoolProtocol` to manage
31 command execution.
32 """
34 def log(self, cmd: list[str], *, executor: str) -> None:
35 """Logs a command execution for auditing purposes.
37 Args:
38 cmd (list[str]): The command and its arguments to log.
39 executor (str): The name or identifier of the entity that executed
40 the command.
42 Returns:
43 None:
44 """
45 ...
47 def get_commands(self) -> list[dict[str, Any]]:
48 """Returns a copy of all recorded audit commands.
50 Returns:
51 list[dict[str, Any]]: A list of dictionaries, where each dictionary
52 represents a logged command execution.
53 """
54 ...
56 def cli_audit(self) -> None:
57 """Performs a CLI-specific audit and status check.
59 This method is the entry point for the `bijux audit` command.
60 Implementations should gather and log the current audit status without
61 raising exceptions or executing external commands.
63 Returns:
64 None:
65 """
66 ...