Files
mlx-knife/tests_2.0/test_cli_log_json_flag.py
The BROKE Cluster Team f5fe1dd061 Release 2.0.0-beta.5: Enhanced error handling & bug fixes
Features:
- Enhanced error handling & logging (ADR-004): Unified error envelope, structured logging with JSON support, request correlation
- Legacy format detection (Issue #37): Runtime compatibility check for weight file formats

Bug Fixes:
- Issue #37: Models with legacy weight formats now correctly detected as runtime-incompatible
- CLI regression fix: mlxk2 without arguments shows help instead of JSON error

Test Status: 295/295 passed, 14 skipped
2025-10-21 00:24:47 +02:00

58 lines
1.9 KiB
Python

"""
Test for --log-json CLI flag (ADR-004 improvement).
Minimal test: Verify flag sets MLXK2_LOG_JSON environment variable.
"""
import os
import sys
from unittest.mock import patch, MagicMock
def test_serve_log_json_flag_sets_env_var():
"""--log-json flag should set MLXK2_LOG_JSON=1 environment variable."""
# Mock start_server to prevent actual server start
with patch('mlxk2.operations.serve.start_server') as mock_start_server:
# Simulate CLI invocation: mlxk2 serve --log-json
test_args = ['mlxk2', 'serve', '--log-json']
with patch.object(sys, 'argv', test_args):
# Clear MLXK2_LOG_JSON before test
os.environ.pop('MLXK2_LOG_JSON', None)
# Import and run CLI
from mlxk2.cli import main
try:
main()
except SystemExit:
pass # Ignore exit (server would run indefinitely)
# Verify environment variable was set
assert os.environ.get('MLXK2_LOG_JSON') == '1', \
"MLXK2_LOG_JSON should be set to '1' when --log-json flag is present"
# Verify start_server was called
assert mock_start_server.called, "start_server should have been called"
def test_serve_without_log_json_flag():
"""Without --log-json, MLXK2_LOG_JSON should remain unset."""
with patch('mlxk2.operations.serve.start_server') as mock_start_server:
test_args = ['mlxk2', 'serve']
with patch.object(sys, 'argv', test_args):
# Clear MLXK2_LOG_JSON before test
os.environ.pop('MLXK2_LOG_JSON', None)
from mlxk2.cli import main
try:
main()
except SystemExit:
pass
# Verify environment variable was NOT set
assert os.environ.get('MLXK2_LOG_JSON') != '1', \
"MLXK2_LOG_JSON should not be set without --log-json flag"