test_guard_contract.py

tests/guard/test_guard_contract.py

Tests for the machine-readable consumer contract.

test_adding_a_schema_key_shows_up_without_touching_contract_py

test_guard_contract.TestResolvedIsGeneratedFromSchema.test_adding_a_schema_key_shows_up_without_touching_contract_py(self)

The property that makes drift impossible, asserted directly.

tests/guard/test_guard_contract.py:190

Checks

  • assert scalars <= resolved_keys

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_adding_a_schema_key_shows_up_without_touching_contract_py → build_effective_contract
Source · 13 lines
    def test_adding_a_schema_key_shows_up_without_touching_contract_py(self):
        """The property that makes drift impossible, asserted directly."""
        from clew.guard.config import _OPEN_DICT, _MapOf

        scalars = {
            k
            for k, v in CONFIG_SCHEMA["validate"].items()
            if v is not _OPEN_DICT and not isinstance(v, dict | _MapOf)
        }
        resolved_keys = set(build_effective_contract(CONFIG_DEFAULTS)["resolved"])
        assert scalars <= resolved_keys

Activity · 4 steps
lines 192–192from clew.guard.config import _OPEN_DICT, _MapOflines 194–198scalars = { k for k, v in CONFIG_SCHEMA["validate"].items() if v is not _OPEN_DICT and not isinstance(v, dict | _MapOf) }lines 199–199resolved_keys = set(build_effective_contract(CONFIG_DEFAULTS)["resolved"])lines 200–200assert scalars <= resolved_keys

test_carries_contract_version

test_guard_contract.TestSchemaContract.test_carries_contract_version(self)

tests/guard/test_guard_contract.py:33

Checks

  • assert build_schema_contract()["contract_version"] == CONTRACT_VERSION

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_carries_contract_version → build_schema_contract
Source · 3 lines
    def test_carries_contract_version(self):
        assert build_schema_contract()["contract_version"] == CONTRACT_VERSION
Activity · 1 steps
lines 34–34assert build_schema_contract()["contract_version"] == CONTRACT_VERSION

test_catalog_block_envelope

test_guard_contract.TestContractEnvelopeShape.test_catalog_block_envelope(self)

tests/guard/test_guard_contract.py:247

Checks

  • assert set(build_schema_contract()["requirements_catalog"]) == self.CATALOG_KEYS

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_catalog_block_envelope → build_schema_contract
Source · 3 lines
    def test_catalog_block_envelope(self):
        assert set(build_schema_contract()["requirements_catalog"]) == self.CATALOG_KEYS
Activity · 1 steps
lines 248–248assert set(build_schema_contract()["requirements_catalog"]) == self.CATALOG_KEYS

test_catalog_constants_match_the_module

test_guard_contract.TestSchemaContract.test_catalog_constants_match_the_module(self)

tests/guard/test_guard_contract.py:53

Checks

  • assert catalog["name_column_default"] == REQUIREMENTS_NAME_COLUMN_DEFAULT
  • assert catalog["root_key"] == "requirements"
  • assert catalog["required_fields"] == ["name"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_catalog_constants_match_the_module → build_schema_contract
Source · 6 lines
    def test_catalog_constants_match_the_module(self):
        catalog = build_schema_contract()["requirements_catalog"]
        assert catalog["name_column_default"] == REQUIREMENTS_NAME_COLUMN_DEFAULT
        assert catalog["root_key"] == "requirements"
        assert catalog["required_fields"] == ["name"]
Activity · 4 steps
lines 54–54catalog = build_schema_contract()["requirements_catalog"]lines 55–55assert catalog["name_column_default"] == REQUIREMENTS_NAME_COLUMN_DEFAULTlines 56–56assert catalog["root_key"] == "requirements"lines 57–57assert catalog["required_fields"] == ["name"]

test_count_matches_file_list

test_guard_contract.TestFilesContract.test_count_matches_file_list(self, tmp_path, monkeypatch)

tests/guard/test_guard_contract.py:118

Show on the map →

Called by none

Calls _tree, build_files_contract

Checks

  • assert contract["count"] == len(contract["files"])

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_count_matches_file_list → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_count_matches_file_list → build_files_contract → toolchain_contract
REQ-DDB-GUARD-013measuredtest_count_matches_file_list → build_files_contract → find_source_files
REQ-DDB-GUARD-015measuredtest_count_matches_file_list → build_files_contract
REQ-DDB-PIPE-011measuredtest_count_matches_file_list → build_files_contract → find_source_files → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_count_matches_file_list → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 5 lines
    def test_count_matches_file_list(self, tmp_path, monkeypatch):
        monkeypatch.chdir(self._tree(tmp_path))
        contract = build_files_contract(["."], CONFIG_DEFAULTS)
        assert contract["count"] == len(contract["files"])
Activity · 3 steps
lines 119–119monkeypatch.chdir(self._tree(tmp_path))lines 120–120contract = build_files_contract(["."], CONFIG_DEFAULTS)lines 121–121assert contract["count"] == len(contract["files"])

test_effective_envelope

test_guard_contract.TestContractEnvelopeShape.test_effective_envelope(self)

tests/guard/test_guard_contract.py:250

Checks

  • assert set(build_effective_contract(CONFIG_DEFAULTS)) == self.EFFECTIVE_KEYS

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_effective_envelope → build_effective_contract
Source · 3 lines
    def test_effective_envelope(self):
        assert set(build_effective_contract(CONFIG_DEFAULTS)) == self.EFFECTIVE_KEYS
Activity · 1 steps
lines 251–251assert set(build_effective_contract(CONFIG_DEFAULTS)) == self.EFFECTIVE_KEYS

test_emitted_config_loads

test_guard_contract.TestContractRoundTrips.test_emitted_config_loads(self, tmp_path, monkeypatch)

tests/guard/test_guard_contract.py:143

Checks

  • assert load_config(tmp_path / ".clew.yaml")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_emitted_config_loads → load_config
REQ-DDB-GUARD-015measuredtest_emitted_config_loads → build_effective_contract
REQ-DDB-GUARD-024measuredtest_emitted_config_loads → load_config → apply_opt_in_languages
Source · 8 lines
    def test_emitted_config_loads(self, tmp_path, monkeypatch):
        import yaml as _yaml

        monkeypatch.chdir(tmp_path)
        emitted = build_effective_contract(load_config(tmp_path / "nonexistent.yaml"))["config"]
        (tmp_path / ".clew.yaml").write_text(guard_yaml(_yaml.safe_dump(emitted)))
        assert load_config(tmp_path / ".clew.yaml")
Activity · 5 steps
lines 144–144import yaml as _yamllines 146–146monkeypatch.chdir(tmp_path)lines 147–147emitted = build_effective_contract(load_config(tmp_path / "nonexistent.yaml"))["config"]lines 148–148(tmp_path / ".clew.yaml").write_text(guard_yaml(_yaml.safe_dump(emitted)))lines 149–149assert load_config(tmp_path / ".clew.yaml")

test_excluded_path_is_absent_and_gate_skips_it

test_guard_contract.TestFilesAgreesWithTheGate.test_excluded_path_is_absent_and_gate_skips_it(self, tmp_path, monkeypatch)

tests/guard/test_guard_contract.py:268

Checks

  • assert not any("tests/t.c" in f for f in listed)
  • assert validate_file("tests/t.c", config, no_git=True) == []
  • assert any("src/a.c" in f for f in listed)
  • assert validate_file("src/a.c", config, no_git=True) != []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_excluded_path_is_absent_and_gate_skips_it → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_excluded_path_is_absent_and_gate_skips_it → build_files_contract → toolchain_contract
REQ-DDB-GUARD-001measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file
REQ-DDB-GUARD-002inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_version_staleness
REQ-DDB-GUARD-003measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_tags
REQ-DDB-GUARD-004measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_req_coverage
REQ-DDB-GUARD-005measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_return_presence
REQ-DDB-GUARD-006measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_file_presence
REQ-DDB-GUARD-007measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_duplicate_tags
REQ-DDB-GUARD-009inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_req_coverage → _has_active_requirements → filter_requirements_by_version
REQ-DDB-GUARD-011inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_req_coverage → _has_active_requirements → load_requirements_full
REQ-DDB-GUARD-013measuredtest_excluded_path_is_absent_and_gate_skips_it → build_files_contract → find_source_files
REQ-DDB-GUARD-014inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_req_coverage → _has_active_requirements → filter_requirements_by_version → parse_version
REQ-DDB-GUARD-015measuredtest_excluded_path_is_absent_and_gate_skips_it → build_files_contract
REQ-DDB-GUARD-016inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_req_coverage → _has_active_requirements → filter_requirements_by_version → _summarise_id
REQ-DDB-GUARD-018measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → parse_source_file
REQ-DDB-GUARD-019measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_file_presence → _check_file_block_tags → parse_doxygen_tags
REQ-DDB-GUARD-020measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → parse_content_for_file → language_for_file
REQ-DDB-GUARD-021inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _find_preceding_doxygen → _find_python_docstring_block
REQ-DDB-GUARD-023inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → get_file_at_revision
REQ-DDB-GUARD-024inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_file_presence → _check_file_block_tags → apply_autobrief
REQ-DDB-GUARD-025measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _js_returns_void
REQ-DDB-GUARD-026measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_bus_tags
REQ-DDB-GUARD-027inferredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → check_req_exists → _uncheckable
REQ-DDB-PIPE-011measuredtest_excluded_path_is_absent_and_gate_skips_it → validate_file → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_excluded_path_is_absent_and_gate_skips_it → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 18 lines
    def test_excluded_path_is_absent_and_gate_skips_it(self, tmp_path, monkeypatch):
        from clew.guard.main import validate_file

        (tmp_path / "src").mkdir()
        (tmp_path / "tests").mkdir()
        (tmp_path / "src" / "a.c").write_text("void A(void) { }")
        (tmp_path / "tests" / "t.c").write_text("void T(void) { }")
        monkeypatch.chdir(tmp_path)
        ## 2.0.0 (R5-CFG F18): excludes are globs; a regex is written `re:`.
        config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/**"]}})

        listed = build_files_contract(["."], config)["files"]
        assert not any("tests/t.c" in f for f in listed)
        assert validate_file("tests/t.c", config, no_git=True) == []

        assert any("src/a.c" in f for f in listed)
        assert validate_file("src/a.c", config, no_git=True) != []
Activity · 12 steps
lines 269–269from clew.guard.main import validate_filelines 271–271(tmp_path / "src").mkdir()lines 272–272(tmp_path / "tests").mkdir()lines 273–273(tmp_path / "src" / "a.c").write_text("void A(void) { }")lines 274–274(tmp_path / "tests" / "t.c").write_text("void T(void) { }")lines 275–275monkeypatch.chdir(tmp_path)lines 277–277config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/**"]}})lines 279–279listed = build_files_contract(["."], config)["files"]lines 280–280assert not any("tests/t.c" in f for f in listed)lines 281–281assert validate_file("tests/t.c", config, no_git=True) == []lines 283–283assert any("src/a.c" in f for f in listed)lines 284–284assert validate_file("src/a.c", config, no_git=True) != []

test_excluded_paths_are_absent

test_guard_contract.TestFilesContract.test_excluded_paths_are_absent(self, tmp_path, monkeypatch)

tests/guard/test_guard_contract.py:105

Checks

  • assert any("a.c" in f for f in contract["files"])
  • assert not any("test_a.c" in f for f in contract["files"])

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_excluded_paths_are_absent → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_excluded_paths_are_absent → build_files_contract → toolchain_contract
REQ-DDB-GUARD-013measuredtest_excluded_paths_are_absent → build_files_contract → find_source_files
REQ-DDB-GUARD-015measuredtest_excluded_paths_are_absent → build_files_contract
REQ-DDB-PIPE-011measuredtest_excluded_paths_are_absent → build_files_contract → find_source_files → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_excluded_paths_are_absent → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 8 lines
    def test_excluded_paths_are_absent(self, tmp_path, monkeypatch):
        root = self._tree(tmp_path)
        monkeypatch.chdir(root)
        config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/"]}})
        contract = build_files_contract(["."], config)
        assert any("a.c" in f for f in contract["files"])
        assert not any("test_a.c" in f for f in contract["files"])
Activity · 6 steps
lines 106–106root = self._tree(tmp_path)lines 107–107monkeypatch.chdir(root)lines 108–108config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/"]}})lines 109–109contract = build_files_contract(["."], config)lines 110–110assert any("a.c" in f for f in contract["files"])lines 111–111assert not any("test_a.c" in f for f in contract["files"])

test_exposes_exclude_patterns

test_guard_contract.TestEffectiveContract.test_exposes_exclude_patterns(self)

tests/guard/test_guard_contract.py:83

Checks

  • assert build_effective_contract(config)["resolved"]["exclude"] == ["^vendor/"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_exposes_exclude_patterns → build_effective_contract
Source · 4 lines
    def test_exposes_exclude_patterns(self):
        config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["^vendor/"]}})
        assert build_effective_contract(config)["resolved"]["exclude"] == ["^vendor/"]
Activity · 2 steps
lines 84–84config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["^vendor/"]}})lines 85–85assert build_effective_contract(config)["resolved"]["exclude"] == ["^vendor/"]

test_exposes_req_pattern

test_guard_contract.TestEffectiveContract.test_exposes_req_pattern(self)

tests/guard/test_guard_contract.py:87

Checks

  • assert build_effective_contract(config)["resolved"]["req_pattern"] == "^R-[0-9]+$"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_exposes_req_pattern → build_effective_contract
Source · 6 lines
    def test_exposes_req_pattern(self):
        config = deep_merge(
            CONFIG_DEFAULTS, {"validate": {"tags": {"req": {"pattern": "^R-[0-9]+$"}}}}
        )
        assert build_effective_contract(config)["resolved"]["req_pattern"] == "^R-[0-9]+$"
Activity · 2 steps
lines 88–90config = deep_merge( CONFIG_DEFAULTS, {"validate": {"tags": {"req": {"pattern": "^R-[0-9]+$"}}}} )lines 91–91assert build_effective_contract(config)["resolved"]["req_pattern"] == "^R-[0-9]+$"

test_files_envelope

test_guard_contract.TestContractEnvelopeShape.test_files_envelope(self, tmp_path, monkeypatch)

tests/guard/test_guard_contract.py:253

Checks

  • assert set(build_files_contract(["."], CONFIG_DEFAULTS)) == self.FILES_KEYS

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_files_envelope → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_files_envelope → build_files_contract → toolchain_contract
REQ-DDB-GUARD-013measuredtest_files_envelope → build_files_contract → find_source_files
REQ-DDB-GUARD-015measuredtest_files_envelope → build_files_contract
REQ-DDB-PIPE-011inferredtest_files_envelope → build_files_contract → find_source_files → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_files_envelope → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 4 lines
    def test_files_envelope(self, tmp_path, monkeypatch):
        monkeypatch.chdir(tmp_path)
        assert set(build_files_contract(["."], CONFIG_DEFAULTS)) == self.FILES_KEYS
Activity · 2 steps
lines 254–254monkeypatch.chdir(tmp_path)lines 255–255assert set(build_files_contract(["."], CONFIG_DEFAULTS)) == self.FILES_KEYS

test_id_column_scoped_to_flat_formats

test_guard_contract.TestSchemaContract.test_id_column_scoped_to_flat_formats(self)

The mapping YAML form keys by ID, so id_column does not apply to it.

tests/guard/test_guard_contract.py:59

Checks

  • assert "yaml" not in catalog["formats_using_id_column"]
  • assert set(catalog["formats_using_id_column"]) == {"csv", "json"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_id_column_scoped_to_flat_formats → build_schema_contract
Source · 6 lines
    def test_id_column_scoped_to_flat_formats(self):
        """The mapping YAML form keys by ID, so id_column does not apply to it."""
        catalog = build_schema_contract()["requirements_catalog"]
        assert "yaml" not in catalog["formats_using_id_column"]
        assert set(catalog["formats_using_id_column"]) == {"csv", "json"}
Activity · 3 steps
lines 61–61catalog = build_schema_contract()["requirements_catalog"]lines 62–62assert "yaml" not in catalog["formats_using_id_column"]lines 63–63assert set(catalog["formats_using_id_column"]) == {"csv", "json"}

test_is_json_serializable

test_guard_contract.TestSchemaContract.test_is_json_serializable(self)

tests/guard/test_guard_contract.py:30

Checks

  • assert json.loads(render(build_schema_contract()))

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-015measuredtest_is_json_serializable → build_schema_contract
REQ-DDB-PIPE-011measured
REQ-DDB-WIKI-054inferred
Source · 3 lines
    def test_is_json_serializable(self):
        assert json.loads(render(build_schema_contract()))
Activity · 1 steps
lines 31–31assert json.loads(render(build_schema_contract()))
test_guard_contract.TestEffectiveContract.test_is_json_serializable(self)

tests/guard/test_guard_contract.py:93

Checks

  • assert json.loads(render(build_effective_contract(CONFIG_DEFAULTS)))

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-015measuredtest_is_json_serializable → build_effective_contract
REQ-DDB-PIPE-011measured
REQ-DDB-WIKI-054inferred
Source · 4 lines
    def test_is_json_serializable(self):
        assert json.loads(render(build_effective_contract(CONFIG_DEFAULTS)))

Activity · 1 steps
lines 94–94assert json.loads(render(build_effective_contract(CONFIG_DEFAULTS)))
test_guard_contract.TestFilesContract.test_is_json_serializable(self, tmp_path, monkeypatch)

tests/guard/test_guard_contract.py:129

Show on the map →

Called by none

Calls _tree, build_files_contract

Checks

  • assert json.loads(render(build_files_contract(["."], CONFIG_DEFAULTS)))

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_is_json_serializable → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_is_json_serializable → build_files_contract → toolchain_contract
REQ-DDB-GUARD-013measuredtest_is_json_serializable → build_files_contract → find_source_files
REQ-DDB-GUARD-015measuredtest_is_json_serializable → build_files_contract
REQ-DDB-PIPE-011measuredtest_is_json_serializable → build_files_contract → find_source_files → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_is_json_serializable → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 5 lines
    def test_is_json_serializable(self, tmp_path, monkeypatch):
        monkeypatch.chdir(self._tree(tmp_path))
        assert json.loads(render(build_files_contract(["."], CONFIG_DEFAULTS)))

Activity · 2 steps
lines 130–130monkeypatch.chdir(self._tree(tmp_path))lines 131–131assert json.loads(render(build_files_contract(["."], CONFIG_DEFAULTS)))

test_names_the_config_file_and_section

test_guard_contract.TestSchemaContract.test_names_the_config_file_and_section(self)

tests/guard/test_guard_contract.py:36

Checks

  • assert (contract["config_file"], contract["config_section"]) == (".clew.yaml", "guard")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_names_the_config_file_and_section → build_schema_contract
Source · 4 lines
    def test_names_the_config_file_and_section(self):
        contract = build_schema_contract()
        assert (contract["config_file"], contract["config_section"]) == (".clew.yaml", "guard")
Activity · 2 steps
lines 37–37contract = build_schema_contract()lines 38–38assert (contract["config_file"], contract["config_section"]) == (".clew.yaml", "guard")

test_nested_lookalike_path_agrees

test_guard_contract.TestFilesAgreesWithTheGate.test_nested_lookalike_path_agrees(self, tmp_path, monkeypatch)

^tests/ must not match src/tests/, in either the listing or the gate.

tests/guard/test_guard_contract.py:286

Checks

  • assert any("src/tests/n.c" in f for f in listed)
  • assert validate_file("src/tests/n.c", config, no_git=True) != []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_nested_lookalike_path_agrees → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_nested_lookalike_path_agrees → build_files_contract → toolchain_contract
REQ-DDB-GUARD-001measuredtest_nested_lookalike_path_agrees → validate_file
REQ-DDB-GUARD-002inferredtest_nested_lookalike_path_agrees → validate_file → check_version_staleness
REQ-DDB-GUARD-003measuredtest_nested_lookalike_path_agrees → validate_file → check_tags
REQ-DDB-GUARD-004measuredtest_nested_lookalike_path_agrees → validate_file → check_req_coverage
REQ-DDB-GUARD-005measuredtest_nested_lookalike_path_agrees → validate_file → check_return_presence
REQ-DDB-GUARD-006measuredtest_nested_lookalike_path_agrees → validate_file → check_file_presence
REQ-DDB-GUARD-007measuredtest_nested_lookalike_path_agrees → validate_file → check_duplicate_tags
REQ-DDB-GUARD-009inferredtest_nested_lookalike_path_agrees → validate_file → check_req_coverage → _has_active_requirements → filter_requirements_by_version
REQ-DDB-GUARD-011inferredtest_nested_lookalike_path_agrees → validate_file → check_req_coverage → _has_active_requirements → load_requirements_full
REQ-DDB-GUARD-013measuredtest_nested_lookalike_path_agrees → build_files_contract → find_source_files
REQ-DDB-GUARD-014inferredtest_nested_lookalike_path_agrees → validate_file → check_req_coverage → _has_active_requirements → filter_requirements_by_version → parse_version
REQ-DDB-GUARD-015measuredtest_nested_lookalike_path_agrees → build_files_contract
REQ-DDB-GUARD-016inferredtest_nested_lookalike_path_agrees → validate_file → check_req_coverage → _has_active_requirements → filter_requirements_by_version → _summarise_id
REQ-DDB-GUARD-018measuredtest_nested_lookalike_path_agrees → validate_file → parse_source_file
REQ-DDB-GUARD-019measuredtest_nested_lookalike_path_agrees → validate_file → check_file_presence → _check_file_block_tags → parse_doxygen_tags
REQ-DDB-GUARD-020measuredtest_nested_lookalike_path_agrees → validate_file → parse_content_for_file → language_for_file
REQ-DDB-GUARD-021inferredtest_nested_lookalike_path_agrees → validate_file → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _find_preceding_doxygen → _find_python_docstring_block
REQ-DDB-GUARD-023inferredtest_nested_lookalike_path_agrees → validate_file → get_file_at_revision
REQ-DDB-GUARD-024inferredtest_nested_lookalike_path_agrees → validate_file → check_file_presence → _check_file_block_tags → apply_autobrief
REQ-DDB-GUARD-025measuredtest_nested_lookalike_path_agrees → validate_file → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _js_returns_void
REQ-DDB-GUARD-026measuredtest_nested_lookalike_path_agrees → validate_file → check_bus_tags
REQ-DDB-GUARD-027inferredtest_nested_lookalike_path_agrees → validate_file → check_req_exists → _uncheckable
REQ-DDB-PIPE-011measuredtest_nested_lookalike_path_agrees → validate_file → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_nested_lookalike_path_agrees → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 13 lines
    def test_nested_lookalike_path_agrees(self, tmp_path, monkeypatch):
        """^tests/ must not match src/tests/, in either the listing or the gate."""
        from clew.guard.main import validate_file

        (tmp_path / "src" / "tests").mkdir(parents=True)
        (tmp_path / "src" / "tests" / "n.c").write_text("void N(void) { }")
        monkeypatch.chdir(tmp_path)
        ## 2.0.0 (R5-CFG F18): excludes are globs; a regex is written `re:`.
        config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/**"]}})

        listed = build_files_contract(["."], config)["files"]
        assert any("src/tests/n.c" in f for f in listed)
        assert validate_file("src/tests/n.c", config, no_git=True) != []

1 more lines, not shown

Activity · 8 steps
lines 288–288from clew.guard.main import validate_filelines 290–290(tmp_path / "src" / "tests").mkdir(parents=True)lines 291–291(tmp_path / "src" / "tests" / "n.c").write_text("void N(void) { }")lines 292–292monkeypatch.chdir(tmp_path)lines 294–294config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/**"]}})lines 296–296listed = build_files_contract(["."], config)["files"]lines 297–297assert any("src/tests/n.c" in f for f in listed)lines 298–298assert validate_file("src/tests/n.c", config, no_git=True) != []

test_null_section_is_accepted_by_the_schema

test_guard_contract.TestContractRoundTrips.test_null_section_is_accepted_by_the_schema(self)

A section may be an explicit null (the shape `config --effective` can emit); the schema must permit it. 2.0.0: `impact.requirements` (the old null-by-default node) moved to the top-level catalog section, so a remaining `guard:` node carries the property.

tests/guard/test_guard_contract.py:162

Checks

  • assert validate_config_schema({"impact": None}) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_null_section_is_accepted_by_the_schema → validate_config_schema
Source · 7 lines
    def test_null_section_is_accepted_by_the_schema(self):
        """A section may be an explicit null (the shape `config --effective` can emit); the schema
        must permit it. 2.0.0: `impact.requirements` (the old null-by-default node) moved to the
        top-level catalog section, so a remaining `guard:` node carries the property."""
        assert validate_config_schema({"impact": None}) == []

Activity · 1 steps
lines 166–166assert validate_config_schema({"impact": None}) == []

test_open_nodes_are_marked_not_dropped

test_guard_contract.TestSchemaContract.test_open_nodes_are_marked_not_dropped(self)

tests/guard/test_guard_contract.py:40

Checks

  • assert schema["validate"]["languages"]["<name>"]["extensions"] == "list"
  • assert schema["validate"]["tags"]["<name>"]["pattern"] == "str"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_open_nodes_are_marked_not_dropped → build_schema_contract
Source · 7 lines
    def test_open_nodes_are_marked_not_dropped(self):
        ## 2.0.0 (R5-CFG F12): `tags` and `languages` are no longer open — any NAME, each entry of
        ## one checked shape — and the contract publishes that shape under "<name>".
        schema = build_schema_contract()["config_schema"]
        assert schema["validate"]["languages"]["<name>"]["extensions"] == "list"
        assert schema["validate"]["tags"]["<name>"]["pattern"] == "str"
Activity · 3 steps
lines 43–43schema = build_schema_contract()["config_schema"]lines 44–44assert schema["validate"]["languages"]["<name>"]["extensions"] == "list"lines 45–45assert schema["validate"]["tags"]["<name>"]["pattern"] == "str"

test_opt_in_languages_are_published_but_not_in_force

test_guard_contract.TestContractEnvelopeShape.test_opt_in_languages_are_published_but_not_in_force(self)

tests/guard/test_guard_contract.py:242

Checks

  • assert "rust" in contract["opt_in_language_defaults"]
  • assert "rust" not in contract["config_defaults"]["validate"]["languages"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_opt_in_languages_are_published_but_not_in_force → build_schema_contract
Source · 5 lines
    def test_opt_in_languages_are_published_but_not_in_force(self):
        contract = build_schema_contract()
        assert "rust" in contract["opt_in_language_defaults"]
        assert "rust" not in contract["config_defaults"]["validate"]["languages"]
Activity · 3 steps
lines 243–243contract = build_schema_contract()lines 244–244assert "rust" in contract["opt_in_language_defaults"]lines 245–245assert "rust" not in contract["config_defaults"]["validate"]["languages"]

test_private_keys_are_stripped

test_guard_contract.TestContractRoundTrips.test_private_keys_are_stripped(self)

tests/guard/test_guard_contract.py:151

Checks

  • assert "_current_version_resolved" not in contract["config"]["validate"]
  • assert contract["resolved"]["current_version"] == "auto:git"
  • assert "requirements" not in contract["config"], "the catalog is not a guard: key"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_private_keys_are_stripped → build_effective_contract
Source · 11 lines
    def test_private_keys_are_stripped(self):
        ## 2.0.0 (R5-CFG F7/F9/F14): the key this tested moved; the test follows it.
        config = deep_merge(
            CONFIG_DEFAULTS,
            {"validate": {"current_version": "auto:git", "_current_version_resolved": "v1.2.3"}},
        )
        contract = build_effective_contract(config)
        assert "_current_version_resolved" not in contract["config"]["validate"]
        assert contract["resolved"]["current_version"] == "auto:git"
        assert "requirements" not in contract["config"], "the catalog is not a guard: key"
Activity · 5 steps
lines 153–156config = deep_merge( CONFIG_DEFAULTS, {"validate": {"current_version": "auto:git", "_current_version_resolved": "v1.2.3"}}, )lines 157–157contract = build_effective_contract(config)lines 158–158assert "_current_version_resolved" not in contract["config"]["validate"]lines 159–159assert contract["resolved"]["current_version"] == "auto:git"lines 160–160assert "requirements" not in contract["config"], "the catalog is not a guard: key"

test_reports_declared_requirements

test_guard_contract.TestEffectiveContract.test_reports_declared_requirements(self, tmp_path)

tests/guard/test_guard_contract.py:70

Checks

  • assert resolved["requirements"]["declared"] is True
  • assert resolved["requirements"]["file"] == "docs/requirements.yaml"
  • assert resolved["requirements"]["format"] == "yaml"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-012measuredtest_reports_declared_requirements → load_config
REQ-DDB-GUARD-015measuredtest_reports_declared_requirements → build_effective_contract
REQ-DDB-GUARD-024inferredtest_reports_declared_requirements → load_config → apply_opt_in_languages
Source · 9 lines
    def test_reports_declared_requirements(self, tmp_path):
        config_file = tmp_path / ".clew.yaml"
        ## 2.0.0 (R5-CFG F7/F9/F14): the key this tested moved; the test follows it.
        config_file.write_text("requirements:\n  file: docs/requirements.yaml\n  format: yaml\n")
        resolved = build_effective_contract(load_config(config_file))["resolved"]
        assert resolved["requirements"]["declared"] is True
        assert resolved["requirements"]["file"] == "docs/requirements.yaml"
        assert resolved["requirements"]["format"] == "yaml"
Activity · 6 steps
lines 71–71config_file = tmp_path / ".clew.yaml"lines 73–73config_file.write_text("requirements:\n file: docs/requirements.yaml\n format: yaml\n")lines 74–74resolved = build_effective_contract(load_config(config_file))["resolved"]lines 75–75assert resolved["requirements"]["declared"] is Truelines 76–76assert resolved["requirements"]["file"] == "docs/requirements.yaml"lines 77–77assert resolved["requirements"]["format"] == "yaml"

test_reports_the_patterns_that_produced_the_set

test_guard_contract.TestFilesContract.test_reports_the_patterns_that_produced_the_set(self, tmp_path, monkeypatch)

tests/guard/test_guard_contract.py:113

Checks

  • assert build_files_contract(["."], config)["exclude"] == ["tests/"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_reports_the_patterns_that_produced_the_set → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_reports_the_patterns_that_produced_the_set → build_files_contract → toolchain_contract
REQ-DDB-GUARD-013measuredtest_reports_the_patterns_that_produced_the_set → build_files_contract → find_source_files
REQ-DDB-GUARD-015measuredtest_reports_the_patterns_that_produced_the_set → build_files_contract
REQ-DDB-PIPE-011measuredtest_reports_the_patterns_that_produced_the_set → build_files_contract → find_source_files → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_reports_the_patterns_that_produced_the_set → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 5 lines
    def test_reports_the_patterns_that_produced_the_set(self, tmp_path, monkeypatch):
        monkeypatch.chdir(self._tree(tmp_path))
        config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/"]}})
        assert build_files_contract(["."], config)["exclude"] == ["tests/"]
Activity · 3 steps
lines 114–114monkeypatch.chdir(self._tree(tmp_path))lines 115–115config = deep_merge(CONFIG_DEFAULTS, {"validate": {"exclude": ["tests/"]}})lines 116–116assert build_files_contract(["."], config)["exclude"] == ["tests/"]

test_reports_undeclared_requirements

test_guard_contract.TestEffectiveContract.test_reports_undeclared_requirements(self)

tests/guard/test_guard_contract.py:79

Checks

  • assert resolved["requirements"] == {"declared": False}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_reports_undeclared_requirements → build_effective_contract
Source · 4 lines
    def test_reports_undeclared_requirements(self):
        resolved = build_effective_contract(CONFIG_DEFAULTS)["resolved"]
        assert resolved["requirements"] == {"declared": False}
Activity · 2 steps
lines 80–80resolved = build_effective_contract(CONFIG_DEFAULTS)["resolved"]lines 81–81assert resolved["requirements"] == {"declared": False}

test_scalar_validate_keys_all_appear

test_guard_contract.TestResolvedIsGeneratedFromSchema.test_scalar_validate_keys_all_appear(self)

tests/guard/test_guard_contract.py:177

Checks

  • assert expected, "expected scalar keys under validate.*"
  • assert key in resolved, key

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_scalar_validate_keys_all_appear → build_effective_contract
Source · 13 lines
    def test_scalar_validate_keys_all_appear(self):
        from clew.guard.config import _OPEN_DICT, _MapOf

        resolved = build_effective_contract(CONFIG_DEFAULTS)["resolved"]
        expected = [
            k
            for k, spec in CONFIG_SCHEMA["validate"].items()
            if spec is not _OPEN_DICT and not isinstance(spec, dict | _MapOf)
        ]
        assert expected, "expected scalar keys under validate.*"
        for key in expected:
            assert key in resolved, key
Activity · 6 steps
lines 178–178from clew.guard.config import _OPEN_DICT, _MapOflines 180–180resolved = build_effective_contract(CONFIG_DEFAULTS)["resolved"]lines 181–185expected = [ k for k, spec in CONFIG_SCHEMA["validate"].items() if spec is not _OPEN_DICT and not isinstance(spec, dict | _MapOf) ]lines 186–186assert expected, "expected scalar keys under validate.*"lines 187–187◇ for key in expectedlines 188–188assert key in resolved, key

test_schema_envelope

test_guard_contract.TestContractEnvelopeShape.test_schema_envelope(self)

tests/guard/test_guard_contract.py:239

Checks

  • assert set(build_schema_contract()) == self.SCHEMA_KEYS

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_schema_envelope → build_schema_contract
Source · 3 lines
    def test_schema_envelope(self):
        assert set(build_schema_contract()) == self.SCHEMA_KEYS
Activity · 1 steps
lines 240–240assert set(build_schema_contract()) == self.SCHEMA_KEYS

test_trace_section_absent

test_guard_contract.TestSchemaContract.test_trace_section_absent(self)

tests/guard/test_guard_contract.py:65

Checks

  • assert "trace" not in build_schema_contract()["config_schema"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_trace_section_absent → build_schema_contract
Source · 4 lines
    def test_trace_section_absent(self):
        assert "trace" not in build_schema_contract()["config_schema"]

Activity · 1 steps
lines 66–66assert "trace" not in build_schema_contract()["config_schema"]

test_types_encoded_by_name

test_guard_contract.TestSchemaContract.test_types_encoded_by_name(self)

tests/guard/test_guard_contract.py:47

Checks

  • assert schema["impact"]["report_dir"] == "str"
  • assert schema["validate"]["presence"]["require_doxygen"] == "bool"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-GUARD-015measuredtest_types_encoded_by_name → build_schema_contract
Source · 6 lines
    def test_types_encoded_by_name(self):
        schema = build_schema_contract()["config_schema"]
        ## 2.0.0 (R5-CFG F7/F9/F14): the key this tested moved; the test follows it.
        assert schema["impact"]["report_dir"] == "str"
        assert schema["validate"]["presence"]["require_doxygen"] == "bool"
Activity · 3 steps
lines 48–48schema = build_schema_contract()["config_schema"]lines 50–50assert schema["impact"]["report_dir"] == "str"lines 51–51assert schema["validate"]["presence"]["require_doxygen"] == "bool"

test_without_excludes_test_files_are_included

test_guard_contract.TestFilesContract.test_without_excludes_test_files_are_included(self, tmp_path, monkeypatch)

Guards the test above: absence must come from the exclude, not from the walk.

tests/guard/test_guard_contract.py:123

Show on the map →

Called by none

Calls _tree, build_files_contract

Checks

  • assert any("test_a.c" in f for f in contract["files"])

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_without_excludes_test_files_are_included → build_files_contract → find_source_files → _git_ls_files → git_argv
REQ-DDB-CONFIG-009measuredtest_without_excludes_test_files_are_included → build_files_contract → toolchain_contract
REQ-DDB-GUARD-013measuredtest_without_excludes_test_files_are_included → build_files_contract → find_source_files
REQ-DDB-GUARD-015measuredtest_without_excludes_test_files_are_included → build_files_contract
REQ-DDB-PIPE-011measuredtest_without_excludes_test_files_are_included → build_files_contract → find_source_files → gate_exclusion → binary_file
REQ-DDB-WIKI-054inferredtest_without_excludes_test_files_are_included → build_files_contract → toolchain_contract → _gate_matcher → load_toolchain_config → _string_list → all
Source · 6 lines
    def test_without_excludes_test_files_are_included(self, tmp_path, monkeypatch):
        """Guards the test above: absence must come from the exclude, not from the walk."""
        monkeypatch.chdir(self._tree(tmp_path))
        contract = build_files_contract(["."], CONFIG_DEFAULTS)
        assert any("test_a.c" in f for f in contract["files"])
Activity · 3 steps
lines 125–125monkeypatch.chdir(self._tree(tmp_path))lines 126–126contract = build_files_contract(["."], CONFIG_DEFAULTS)lines 127–127assert any("test_a.c" in f for f in contract["files"])