test_guard_config_index.py

tests/test_guard_config_index.py

The gate's config is the `guard:` section of `.clew.yaml`, read by gate and index alike.

test_a_guard_section_that_is_not_a_mapping_is_refused_by_the_gate

None test_guard_config_index.test_a_guard_section_that_is_not_a_mapping_is_refused_by_the_gate(Path tmp_path)

tests/test_guard_config_index.py:84

Checks

  • assert load_guard_config(tmp_path) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_guard_section_that_is_not_a_mapping_is_refused_by_the_gate → load_guard_config
REQ-DDB-GUARD-012measuredtest_a_guard_section_that_is_not_a_mapping_is_refused_by_the_gate → load_config
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-024inferredtest_a_guard_section_that_is_not_a_mapping_is_refused_by_the_gate → load_config → apply_opt_in_languages
Source · 8 lines
def test_a_guard_section_that_is_not_a_mapping_is_refused_by_the_gate(tmp_path: Path) -> None:
    path = _write(tmp_path, "guard: [validate]\n")

    with pytest.raises(ConfigError):
        load_config(path)
    assert load_guard_config(tmp_path) is None

Activity · 4 steps
lines 85–85path = _write(tmp_path, "guard: [validate]\n")lines 87–87with pytest.raises(ConfigError)lines 88–88load_config(path)lines 89–89assert load_guard_config(tmp_path) is None

test_a_leftover_doxygen_guard_yaml_is_not_read

None test_guard_config_index.test_a_leftover_doxygen_guard_yaml_is_not_read(Path tmp_path)

HARD BREAK, pinned. A repo that has not moved its config runs on the defaults; a silent fallback to the old file would leave two configs that can disagree.

tests/test_guard_config_index.py:126

Checks

  • assert load_guard_config(tmp_path) is None
  • assert load_declaration(tmp_path) == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_leftover_doxygen_guard_yaml_is_not_read → load_declaration
REQ-DDB-GUARD-012inferredtest_a_leftover_doxygen_guard_yaml_is_not_read → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-024inferredtest_a_leftover_doxygen_guard_yaml_is_not_read → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
REQ-DDB-WIKI-054inferredtest_a_leftover_doxygen_guard_yaml_is_not_read → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 8 lines
def test_a_leftover_doxygen_guard_yaml_is_not_read(tmp_path: Path) -> None:
    """HARD BREAK, pinned. A repo that has not moved its config runs on the defaults; a
    silent fallback to the old file would leave two configs that can disagree."""
    old = _GUARD.replace("guard:\n", "").replace("\n  ", "\n")
    _write(tmp_path, old + "x-clew:\n  index_scope:\n    roots: [src]\n", ".doxygen-guard.yaml")

    assert load_guard_config(tmp_path) is None
    assert load_declaration(tmp_path) == {}

1 more lines, not shown

Activity · 4 steps
lines 129–129old = _GUARD.replace("guard:\n", "").replace("\n ", "\n")lines 130–130_write(tmp_path, old + "x-clew:\n index_scope:\n roots: [src]\n", ".doxygen-guard.yaml")lines 132–132assert load_guard_config(tmp_path) is Nonelines 133–133assert load_declaration(tmp_path) == {}

test_an_invalid_section_degrades_the_index_and_is_refused_by_the_gate

None test_guard_config_index.test_an_invalid_section_degrades_the_index_and_is_refused_by_the_gate(Path tmp_path, caplog)

tests/test_guard_config_index.py:70

Checks

  • assert load_guard_config(tmp_path) is None
  • assert str(path) in caplog.text and "no_such_key" in caplog.text, ("the index must say which file it could not use and why, not fall back silently" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_invalid_section_degrades_the_index_and_is_refused_by_the_gate → load_guard_config
REQ-DDB-GUARD-012measuredtest_an_invalid_section_degrades_the_index_and_is_refused_by_the_gate → load_config
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-024inferredtest_an_invalid_section_degrades_the_index_and_is_refused_by_the_gate → load_config → apply_opt_in_languages
Source · 14 lines
def test_an_invalid_section_degrades_the_index_and_is_refused_by_the_gate(
    tmp_path: Path, caplog
) -> None:
    path = _write(tmp_path, "guard:\n  validate:\n    no_such_key: 1\n")

    with caplog.at_level(logging.WARNING):
        assert load_guard_config(tmp_path) is None
    assert str(path) in caplog.text and "no_such_key" in caplog.text, (
        "the index must say which file it could not use and why, not fall back silently"
    )
    with pytest.raises(ConfigError):
        load_config(path)

Activity · 6 steps
lines 73–73path = _write(tmp_path, "guard:\n validate:\n no_such_key: 1\n")lines 75–75with caplog.at_level(logging.WARNING)lines 76–76assert load_guard_config(tmp_path) is Nonelines 77–79assert str(path) in caplog.text and "no_such_key" in caplog.text, ( "the index must say which file it could not use and why, not fall back silently" )lines 80–80with pytest.raises(ConfigError)lines 81–81load_config(path)

test_no_file_and_no_section_both_mean_nothing_declared

None test_guard_config_index.test_no_file_and_no_section_both_mean_nothing_declared(Path tmp_path)

tests/test_guard_config_index.py:61

Show on the map →

Called by none

Calls _write, load_guard_config

Checks

  • assert load_guard_config(tmp_path) is None
  • assert load_guard_config(tmp_path) is None, ("a .clew.yaml with no guard: section declares nothing to the gate" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_no_file_and_no_section_both_mean_nothing_declared → load_guard_config
REQ-DDB-GUARD-012measuredtest_no_file_and_no_section_both_mean_nothing_declared → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-024inferredtest_no_file_and_no_section_both_mean_nothing_declared → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
Source · 9 lines
def test_no_file_and_no_section_both_mean_nothing_declared(tmp_path: Path) -> None:
    assert load_guard_config(tmp_path) is None

    _write(tmp_path, "index_scope:\n  roots: [src]\n")
    assert load_guard_config(tmp_path) is None, (
        "a .clew.yaml with no guard: section declares nothing to the gate"
    )

Activity · 3 steps
lines 62–62assert load_guard_config(tmp_path) is Nonelines 64–64_write(tmp_path, "index_scope:\n roots: [src]\n")lines 65–67assert load_guard_config(tmp_path) is None, ( "a .clew.yaml with no guard: section declares nothing to the gate" )

test_the_gate_reads_the_same_section

None test_guard_config_index.test_the_gate_reads_the_same_section(Path tmp_path)

tests/test_guard_config_index.py:52

Show on the map →

Called by none

Calls _write, load_config

Checks

  • assert cfg["validate"]["tags"]["req"]["pattern"] == "^REQ-[0-9]{4}$"
  • assert cfg["requirements"]["file"] == "catalog.yaml"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-GUARD-012measuredtest_the_gate_reads_the_same_section → load_config
REQ-DDB-GUARD-024measuredtest_the_gate_reads_the_same_section → load_config → apply_opt_in_languages
Source · 9 lines
def test_the_gate_reads_the_same_section(tmp_path: Path) -> None:
    path = _write(tmp_path, _GUARD)

    cfg = load_config(path)

    assert cfg["validate"]["tags"]["req"]["pattern"] == "^REQ-[0-9]{4}$"
    assert cfg["requirements"]["file"] == "catalog.yaml"

Activity · 4 steps
lines 53–53path = _write(tmp_path, _GUARD)lines 55–55cfg = load_config(path)lines 57–57assert cfg["validate"]["tags"]["req"]["pattern"] == "^REQ-[0-9]{4}$"lines 58–58assert cfg["requirements"]["file"] == "catalog.yaml"

test_the_guard_section_is_known_but_is_not_an_index_declaration

None test_guard_config_index.test_the_guard_section_is_known_but_is_not_an_index_declaration(Path tmp_path)

tests/test_guard_config_index.py:92

Checks

  • assert load_declaration(tmp_path) == {"index_scope": {"roots": ["src"]}}
  • assert load_declaration(tmp_path) == {}, ("a file that configures only the gate must declare nothing to the index" )
  • assert "configures only the gate" in describe_declaration(tmp_path)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_guard_section_is_known_but_is_not_an_index_declaration → load_declaration
REQ-DDB-GUARD-012inferredtest_the_guard_section_is_known_but_is_not_an_index_declaration → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_the_guard_section_is_known_but_is_not_an_index_declaration → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 17 lines
def test_the_guard_section_is_known_but_is_not_an_index_declaration(tmp_path: Path) -> None:
    ## A `guard:`-ONLY file (2.0.0: `_GUARD` also carries the top-level catalog, which IS the
    ## repository's declaration, so this property needs a file without one).
    gate_only = _GUARD.split("guard:\n", 1)[1]
    gate_only = "guard:\n" + gate_only
    _write(tmp_path, gate_only + "index_scope:\n  roots: [src]\n")
    (tmp_path / "src").mkdir()

    assert load_declaration(tmp_path) == {"index_scope": {"roots": ["src"]}}

    _write(tmp_path, gate_only)
    assert load_declaration(tmp_path) == {}, (
        "a file that configures only the gate must declare nothing to the index"
    )
    assert "configures only the gate" in describe_declaration(tmp_path)

Activity · 8 steps
lines 95–95gate_only = _GUARD.split("guard:\n", 1)[1]lines 96–96gate_only = "guard:\n" + gate_onlylines 97–97_write(tmp_path, gate_only + "index_scope:\n roots: [src]\n")lines 98–98(tmp_path / "src").mkdir()lines 100–100assert load_declaration(tmp_path) == {"index_scope": {"roots": ["src"]}}lines 102–102_write(tmp_path, gate_only)lines 103–105assert load_declaration(tmp_path) == {}, ( "a file that configures only the gate must declare nothing to the index" )lines 106–106assert "configures only the gate" in describe_declaration(tmp_path)

test_the_index_reads_the_guard_section_of_clew_yaml

None test_guard_config_index.test_the_index_reads_the_guard_section_of_clew_yaml(Path tmp_path)

tests/test_guard_config_index.py:42

Checks

  • assert cfg is not None
  • assert cfg["requirements"]["file"] == "catalog.yaml"
  • assert resolve_req_id_pattern(cfg).pattern == "^REQ-[0-9]{4}$"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_index_reads_the_guard_section_of_clew_yaml → load_guard_config
REQ-DDB-GUARD-012measuredtest_the_index_reads_the_guard_section_of_clew_yaml → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-024measuredtest_the_index_reads_the_guard_section_of_clew_yaml → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
Source · 10 lines
def test_the_index_reads_the_guard_section_of_clew_yaml(tmp_path: Path) -> None:
    _write(tmp_path, _GUARD)

    cfg = load_guard_config(tmp_path)

    assert cfg is not None
    assert cfg["requirements"]["file"] == "catalog.yaml"
    assert resolve_req_id_pattern(cfg).pattern == "^REQ-[0-9]{4}$"

Activity · 5 steps
lines 43–43_write(tmp_path, _GUARD)lines 45–45cfg = load_guard_config(tmp_path)lines 47–47assert cfg is not Nonelines 48–48assert cfg["requirements"]["file"] == "catalog.yaml"lines 49–49assert resolve_req_id_pattern(cfg).pattern == "^REQ-[0-9]{4}$"

test_the_schema_contract_names_the_file_and_section

None test_guard_config_index.test_the_schema_contract_names_the_file_and_section()

tests/test_guard_config_index.py:118

Checks

  • assert contract["config_file"] == CONFIG_FILE_NAME
  • assert contract["config_section"] == CONFIG_SECTION
  • assert "passthrough_prefix" not in contract

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-GUARD-015measuredtest_the_schema_contract_names_the_file_and_section → build_schema_contract
Source · 8 lines
def test_the_schema_contract_names_the_file_and_section() -> None:
    contract = build_schema_contract()

    assert contract["config_file"] == CONFIG_FILE_NAME
    assert contract["config_section"] == CONFIG_SECTION
    assert "passthrough_prefix" not in contract

Activity · 4 steps
lines 119–119contract = build_schema_contract()lines 121–121assert contract["config_file"] == CONFIG_FILE_NAMElines 122–122assert contract["config_section"] == CONFIG_SECTIONlines 123–123assert "passthrough_prefix" not in contract

test_the_scope_fallback_names_where_it_looked

None test_guard_config_index.test_the_scope_fallback_names_where_it_looked(Path tmp_path)

tests/test_guard_config_index.py:109

Show on the map →

Called by none

Calls _write, derive_scope

Checks

  • assert f"no {CONFIG_FILE_NAME} was found" in reason
  • assert "exists but carries no index_scope" in reason

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_scope_fallback_names_where_it_looked → derive_scope
REQ-DDB-GUARD-012measuredtest_the_scope_fallback_names_where_it_looked → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_the_scope_fallback_names_where_it_looked → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 9 lines
def test_the_scope_fallback_names_where_it_looked(tmp_path: Path) -> None:
    reason = derive_scope(tmp_path).reason
    assert f"no {CONFIG_FILE_NAME} was found" in reason

    _write(tmp_path, _GUARD)
    reason = derive_scope(tmp_path).reason
    assert "exists but carries no index_scope" in reason

Activity · 5 steps
lines 110–110reason = derive_scope(tmp_path).reasonlines 111–111assert f"no {CONFIG_FILE_NAME} was found" in reasonlines 113–113_write(tmp_path, _GUARD)lines 114–114reason = derive_scope(tmp_path).reasonlines 115–115assert "exists but carries no index_scope" in reason