test_guard_external_catalogs.py

tests/guard/test_guard_external_catalogs.py

External requirements catalogs for the gate, and the silent no-catalog gap (GH #68, P6b-1).

test_a_pinned_external_catalogue_is_read_at_its_revision

None test_guard_external_catalogs.test_a_pinned_external_catalogue_is_read_at_its_revision(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)

`{repo, rev, path}` read with `git show`.

tests/guard/test_guard_external_catalogs.py:69

Show on the map →

Called by none

Calls _catalog, _run

Checks

  • assert code == 0, capsys.readouterr()
  • assert code == 1

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-001measured
REQ-DDB-GUARD-003measured
REQ-DDB-GUARD-004measured
REQ-DDB-GUARD-005measured
REQ-DDB-GUARD-006measured
REQ-DDB-GUARD-007measured
REQ-DDB-GUARD-011measured
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-018measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-020measured
REQ-DDB-GUARD-025measured
REQ-DDB-GUARD-026measured
REQ-DDB-GUARD-027measured
REQ-DDB-PIPE-011measured
REQ-DDB-SCHEMA-015measured
Source · 36 lines
def test_a_pinned_external_catalogue_is_read_at_its_revision(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
    """THE PIN, NOT THE WORKING TREE: an id added to the consumer's catalogue after the pinned
    revision is not satisfied by it.

    @brief `{repo, rev, path}` read with `git show`.
    """
    consumer = tmp_path / "consumer"
    consumer.mkdir()
    _catalog(consumer / "requirements.yaml", "REQ-PRD-001")

    def git(*args: str) -> str:
        return subprocess.run(
            ["git", "-c", "user.email=t@e", "-c", "user.name=t", *args],
            cwd=consumer,
            capture_output=True,
            text=True,
            check=True,
        ).stdout.strip()

    git("init", "-q")
    git("add", "-A")
    git("commit", "-q", "-m", "catalogue")
    rev = git("rev-parse", "HEAD")
    _catalog(consumer / "requirements.yaml", "REQ-PRD-001", "REQ-PRD-002")
    impact = (
        "requirements:\n  external:\n"
        f"    - {{repo: consumer, rev: {rev}, path: requirements.yaml}}\n"
    )
    code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-001")
    assert code == 0, capsys.readouterr()
    code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-002")
    assert code == 1

Activity · 14 steps
lines 77–77consumer = tmp_path / "consumer"lines 78–78consumer.mkdir()lines 79–79_catalog(consumer / "requirements.yaml", "REQ-PRD-001")lines 81–88def git(*args: str) -> str: return subprocess.run( ["git", "-c", "user.email=t@e", "-c", "user.name=t", *args], cwd=consumer, capture_output=True, text=True, check=True, ).stdout.strip()lines 90–90git("init", "-q")lines 91–91git("add", "-A")lines 92–92git("commit", "-q", "-m", "catalogue")lines 93–93rev = git("rev-parse", "HEAD")lines 94–94_catalog(consumer / "requirements.yaml", "REQ-PRD-001", "REQ-PRD-002")lines 95–98impact = ( "requirements:\n external:\n" f" - {{repo: consumer, rev: {rev}, path: requirements.yaml}}\n" )lines 99–99code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-001")lines 100–100assert code == 0, capsys.readouterr()lines 101–101code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-002")lines 102–102assert code == 1

test_a_tag_with_no_catalogue_to_check_it_is_reported

None test_guard_external_catalogs.test_a_tag_with_no_catalogue_to_check_it_is_reported(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)

No catalogue, a tag: a violation.

tests/guard/test_guard_external_catalogs.py:117

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 1 and "REQ-ANY-001" in text and "no requirements catalog" in text

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-001measured
REQ-DDB-GUARD-003measured
REQ-DDB-GUARD-004measured
REQ-DDB-GUARD-005measured
REQ-DDB-GUARD-006measured
REQ-DDB-GUARD-007measured
REQ-DDB-GUARD-011measured
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-018measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-020measured
REQ-DDB-GUARD-025measured
REQ-DDB-GUARD-026measured
REQ-DDB-GUARD-027measured
REQ-DDB-PIPE-011measured
REQ-DDB-SCHEMA-015measured
Source · 14 lines
def test_a_tag_with_no_catalogue_to_check_it_is_reported(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
    """THE GAP #68 EXPOSED: `cross_reference` on, no catalogue anywhere, a `@req` tag — reported as
    uncheckable, with how to fix it, never passed silently.

    @brief No catalogue, a tag: a violation.
    """
    code, _ = _run(tmp_path, monkeypatch, "", "REQ-ANY-001")
    out = capsys.readouterr()
    text = out.out + out.err
    assert code == 1 and "REQ-ANY-001" in text and "no requirements catalog" in text

Activity · 4 steps
lines 125–125code, _ = _run(tmp_path, monkeypatch, "", "REQ-ANY-001")lines 126–126out = capsys.readouterr()lines 127–127text = out.out + out.errlines 128–128assert code == 1 and "REQ-ANY-001" in text and "no requirements catalog" in text

test_a_url_is_refused_by_name

None test_guard_external_catalogs.test_a_url_is_refused_by_name(Path tmp_path)

A pre-commit gate never reaches the network: a URL source is refused, naming it.

tests/guard/test_guard_external_catalogs.py:105

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001inferredtest_a_url_is_refused_by_name → read_catalog_at → git_text → git_argv
REQ-DDB-GUARD-027measuredtest_a_url_is_refused_by_name → read_catalog_at
Source · 12 lines
def test_a_url_is_refused_by_name(tmp_path: Path) -> None:
    """@brief A pre-commit gate never reaches the network: a URL source is refused, naming it."""
    from clew.requirements import read_catalog_at

    with pytest.raises(ValueError, match="URL"):
        read_catalog_at(tmp_path, "https://example.invalid/requirements.yaml")
    with pytest.raises(ValueError, match="URL"):
        read_catalog_at(
            tmp_path, {"repo": "git@github.com:o/r.git", "rev": "abc", "path": "r.yaml"}
        )

Activity · 5 steps
lines 107–107from clew.requirements import read_catalog_atlines 109–109with pytest.raises(ValueError, match="URL")lines 110–110read_catalog_at(tmp_path, "https://example.invalid/requirements.yaml")lines 111–111with pytest.raises(ValueError, match="URL")lines 112–114read_catalog_at( tmp_path, {"repo": "git@github.com:o/r.git", "rev": "abc", "path": "r.yaml"} )

test_an_external_catalogue_satisfies_cross_reference_without_a_local_one

None test_guard_external_catalogs.test_an_external_catalogue_satisfies_cross_reference_without_a_local_one(Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)

A library checks its tags against its consumer's catalogue; an unknown id is named.

tests/guard/test_guard_external_catalogs.py:56

Show on the map →

Called by none

Calls _catalog, _run

Checks

  • assert code == 0, capsys.readouterr()
  • assert code == 1 and "REQ-PRD-999" in (out.out + out.err)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-001measured
REQ-DDB-GUARD-003measured
REQ-DDB-GUARD-004measured
REQ-DDB-GUARD-005measured
REQ-DDB-GUARD-006measured
REQ-DDB-GUARD-007measured
REQ-DDB-GUARD-011measured
REQ-DDB-GUARD-012measured
REQ-DDB-GUARD-013measured
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-018measured
REQ-DDB-GUARD-019measured
REQ-DDB-GUARD-020measured
REQ-DDB-GUARD-025measured
REQ-DDB-GUARD-026measured
REQ-DDB-GUARD-027measured
REQ-DDB-PIPE-011measured
REQ-DDB-SCHEMA-015measured
Source · 13 lines
def test_an_external_catalogue_satisfies_cross_reference_without_a_local_one(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
) -> None:
    """@brief A library checks its tags against its consumer's catalogue; an unknown id is named."""
    _catalog(tmp_path / "product" / "requirements.yaml", "REQ-PRD-001")
    impact = "requirements:\n  external: [product/requirements.yaml]\n"
    code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-001")
    assert code == 0, capsys.readouterr()
    code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-999")
    out = capsys.readouterr()
    assert code == 1 and "REQ-PRD-999" in (out.out + out.err)

Activity · 7 steps
lines 60–60_catalog(tmp_path / "product" / "requirements.yaml", "REQ-PRD-001")lines 61–61impact = "requirements:\n external: [product/requirements.yaml]\n"lines 62–62code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-001")lines 63–63assert code == 0, capsys.readouterr()lines 64–64code, _ = _run(tmp_path, monkeypatch, impact, "REQ-PRD-999")lines 65–65out = capsys.readouterr()lines 66–66assert code == 1 and "REQ-PRD-999" in (out.out + out.err)

test_the_wiki_and_the_gate_read_catalogues_through_one_reader

None test_guard_external_catalogs.test_the_wiki_and_the_gate_read_catalogues_through_one_reader(Path tmp_path)

The shared reader returns every id with its row, in both catalogue shapes.

tests/guard/test_guard_external_catalogs.py:131

Show on the map →

Called by none

Calls _catalog, read_catalog_at

Checks

  • assert set(read_catalog_at(tmp_path, "keyed.yaml")) == {"REQ-A-001", "REQ-A-002"}
  • assert read_catalog_at(tmp_path, "flat.yaml")["REQ-B-001"]["name"] == "B"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001inferredtest_the_wiki_and_the_gate_read_catalogues_through_one_reader → read_catalog_at → git_text → git_argv
REQ-DDB-GUARD-027measuredtest_the_wiki_and_the_gate_read_catalogues_through_one_reader → read_catalog_at
Source · 8 lines
def test_the_wiki_and_the_gate_read_catalogues_through_one_reader(tmp_path: Path) -> None:
    """@brief The shared reader returns every id with its row, in both catalogue shapes."""
    from clew.requirements import read_catalog_at

    _catalog(tmp_path / "keyed.yaml", "REQ-A-001", "REQ-A-002")
    (tmp_path / "flat.yaml").write_text("- {id: REQ-B-001, name: B}\n")
    assert set(read_catalog_at(tmp_path, "keyed.yaml")) == {"REQ-A-001", "REQ-A-002"}
    assert read_catalog_at(tmp_path, "flat.yaml")["REQ-B-001"]["name"] == "B"

1 more lines, not shown

Activity · 5 steps
lines 133–133from clew.requirements import read_catalog_atlines 135–135_catalog(tmp_path / "keyed.yaml", "REQ-A-001", "REQ-A-002")lines 136–136(tmp_path / "flat.yaml").write_text("- {id: REQ-B-001, name: B}\n")lines 137–137assert set(read_catalog_at(tmp_path, "keyed.yaml")) == {"REQ-A-001", "REQ-A-002"}lines 138–138assert read_catalog_at(tmp_path, "flat.yaml")["REQ-B-001"]["name"] == "B"