Option C Tools
Loading...
Searching...
No Matches
test_octrc_template.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_scaffold/test_octrc_template.py
4
5"""
6Purpose
7-------
8OI-530 regression coverage — the scaffolded ``.octrc.json`` must ship
9with a live ``linter.profile`` default plus a discoverable (but inert)
10``_git_example`` stanza so new projects inherit sensible defaults and
11can copy-paste branch protection into place without reading docs.
12
13Responsibilities
14----------------
15- ``linter.profile == "compact"`` after scaffold.
16- ``_git_example`` is present and documents ``protected_branches`` +
17 ``branch_profile_map``.
18- :func:`oct.core.octrc.load_octrc_safe` round-trips the template without
19 dropping the underscore-prefixed example key.
20
21Diagnostics
22-----------
23Domain: SCAFFOLD-TESTS
24Levels:
25 L2 — test lifecycle
26 L3 — assertion details
27 L4 — deep tracing
28
29Contracts
30---------
31- All scaffold operations write to ``tmp_path``; no real project
32 directories are created.
33"""
34
35from __future__ import annotations
36
37import json
38from pathlib import Path
39
40from oct.core.octrc import load_octrc_safe
41from oct.scaffold import run_scaffold
42
43
45 run_scaffold("demo", tmp_path, include_venv=False)
46 octrc = tmp_path / "demo" / ".option_c" / "octrc.json"
47 data = json.loads(octrc.read_text(encoding="utf-8"))
48
49 assert data["linter"]["profile"] == "compact"
50
51
53 run_scaffold("demo", tmp_path, include_venv=False)
54 octrc = tmp_path / "demo" / ".option_c" / "octrc.json"
55 data = json.loads(octrc.read_text(encoding="utf-8"))
56
57 example = data.get("_git_example")
58 assert isinstance(example, dict)
59 assert "main" in example["protected_branches"]
60 assert example["branch_profile_map"]["main"] == "strict"
61
62
64 run_scaffold("demo", tmp_path, include_venv=False)
65 project = tmp_path / "demo"
66
67 data = load_octrc_safe(project)
68
69 # The underscore key is preserved (the loader does not strip it).
70 # OI-530: its purpose is discoverability; consumers never read it.
71 assert "_git_example" in data
72 assert data["linter"]["profile"] == "compact"
test_octrc_template_round_trips_through_safe_loader(Path tmp_path)