Option C Tools
Loading...
Searching...
No Matches
test_mcp_debug_config_path.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_mcp/test_mcp_debug_config_path.py
4
5"""
6Purpose
7-------
8OI-504 regression tests — ``_load_debug_config_patterns()`` must look up
9``debug_config.json`` at ``<root>/oc_diagnostics/debug_config.json`` first
10(the canonical location since v0.9.0) and fall back to the legacy
11``<root>/debug_config.json`` only when the canonical path is absent.
12
13Responsibilities
14----------------
15- Canonical ``oc_diagnostics/debug_config.json`` is preferred when present.
16- Legacy root-level ``debug_config.json`` is still read when the canonical
17 path is missing.
18- Neither path present → returns ``[]`` (safe default, no raise).
19
20Diagnostics
21-----------
22Domain: MCP-TESTS
23Levels:
24 L2 — test lifecycle
25 L3 — assertion details
26 L4 — deep tracing
27
28Contracts
29---------
30- Function never raises; returns a list.
31"""
32
33import json
34from pathlib import Path
35
36from oct.mcp.config import McpConfig
37from oct.mcp.server import _load_debug_config_patterns
38
39
40_CANONICAL_PATTERNS = [{"name": "canonical", "pattern": "CANONICAL-SECRET"}]
41_LEGACY_PATTERNS = [{"name": "legacy", "pattern": "LEGACY-SECRET"}]
42
43
44def _make_config() -> McpConfig:
45 return McpConfig(trust_repo_config=True, profile="default")
46
47
49 (tmp_path / "oc_diagnostics").mkdir()
50 (tmp_path / "oc_diagnostics" / "debug_config.json").write_text(
51 json.dumps({"redaction_patterns": _CANONICAL_PATTERNS}),
52 encoding="utf-8",
53 )
54 # Legacy file also present — canonical must still win.
55 (tmp_path / "debug_config.json").write_text(
56 json.dumps({"redaction_patterns": _LEGACY_PATTERNS}),
57 encoding="utf-8",
58 )
59
60 patterns = _load_debug_config_patterns(tmp_path, _make_config())
61
62 assert patterns == _CANONICAL_PATTERNS
63
64
66 (tmp_path / "debug_config.json").write_text(
67 json.dumps({"redaction_patterns": _LEGACY_PATTERNS}),
68 encoding="utf-8",
69 )
70
71 patterns = _load_debug_config_patterns(tmp_path, _make_config())
72
73 assert patterns == _LEGACY_PATTERNS
74
75
77 patterns = _load_debug_config_patterns(tmp_path, _make_config())
78 assert patterns == []