test_requirements_declared.py

tests/test_requirements_declared.py

Declaration-driven requirements handling (no hardcoded @req/catalog format).

test_a_declared_pattern_that_ends_in_punctuation_is_matched_before_stripping

None test_requirements_declared.test_a_declared_pattern_that_ends_in_punctuation_is_matched_before_stripping()

THE LINE THE RETRY MUST NOT CROSS. Stripping punctuation unconditionally would corrupt an id for a repo whose DECLARED pattern legitimately contains dots — the permissive default has none, but a declared one is the target's to choose, and this extractor's one hard guarantee is that every id matching today still matches.

tests/test_requirements_declared.py:345

Checks

  • assert _extract_req_tags("@req REQ-1.2.3 ", dotted) == ["REQ-1.2.3"], ("a dotted id matches greedily and must survive untouched" )
  • assert _extract_req_tags("@req REQ-1.2.3. ", dotted) == ["REQ-1.2.3"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-SCHEMA-006measuredtest_a_declared_pattern_that_ends_in_punctuation_is_matched_before_stripping → _extract_req_tags
Source · 19 lines
def test_a_declared_pattern_that_ends_in_punctuation_is_matched_before_stripping() -> None:
    """THE LINE THE RETRY MUST NOT CROSS. Stripping punctuation unconditionally would
    corrupt an id for a repo whose DECLARED pattern legitimately contains dots — the
    permissive default has none, but a declared one is the target's to choose, and this
    extractor's one hard guarantee is that every id matching today still matches.

    So the greedy token is tried FIRST and only a failure retries with one trailing
    character removed: a dotted id matches on the first attempt and is never touched.
    """
    import re

    dotted = re.compile(r"^REQ-[0-9]+(?:\.[0-9]+)*$")
    assert _extract_req_tags("@req REQ-1.2.3 ", dotted) == ["REQ-1.2.3"], (
        "a dotted id matches greedily and must survive untouched"
    )
    # And the same id still recovers when doxygen punctuates it.
    assert _extract_req_tags("@req REQ-1.2.3. ", dotted) == ["REQ-1.2.3"]

Activity · 4 steps
lines 354–354import relines 356–356dotted = re.compile(r"^REQ-[0-9]+(?:\.[0-9]+)*$")lines 357–359assert _extract_req_tags("@req REQ-1.2.3 ", dotted) == ["REQ-1.2.3"], ( "a dotted id matches greedily and must survive untouched" )lines 361–361assert _extract_req_tags("@req REQ-1.2.3. ", dotted) == ["REQ-1.2.3"]

test_an_invalid_guard_section_is_survived

None test_requirements_declared.test_an_invalid_guard_section_is_survived(Path tmp_path, caplog)

An invalid `guard:` section must cost the index its declared values, loudly, and never the build. This loader runs AFTER the doxygen run and every edge-import stage, so a target repo with one stray key used to burn an entire build and then die at exit 1 with a message from a different tool.

tests/test_requirements_declared.py:272

Checks

  • assert result is None, "a rejected config must degrade to defaults, not propagate"
  • assert any("INVALID" in rec.message for rec in caplog.records), ("falling back to built-in defaults silently is the failure mode being fixed" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_invalid_guard_section_is_survived → load_guard_config
REQ-DDB-GUARD-012measuredtest_an_invalid_guard_section_is_survived → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-014measured
REQ-DDB-GUARD-024inferredtest_an_invalid_guard_section_is_survived → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
Source · 35 lines
def test_an_invalid_guard_section_is_survived(tmp_path: Path, caplog) -> None:
    """An invalid `guard:` section must cost the index its declared values, loudly, and
    never the build. This loader runs AFTER the doxygen run and every edge-import stage,
    so a target repo with one stray key used to burn an entire build and then die at
    exit 1 with a message from a different tool.

    Both halves are asserted. Returning None is the "never fatal" contract. The WARNING
    is the other half and matters just as much: the declared `@req` pattern is now
    unavailable and the build falls back to the permissive default, which is the "runs
    on built-in defaults without saying so" outcome the no-hardcoding mandate exists to
    prevent."""
    import logging

    from clew import requirements as requirements_module

    (tmp_path / ".clew.yaml").write_text("guard:\n  stray_top_level_key: true\n", encoding="utf-8")

    with caplog.at_level(logging.WARNING):
        result = requirements_module.load_guard_config(tmp_path)

    assert result is None, "a rejected config must degrade to defaults, not propagate"
    assert any("INVALID" in rec.message for rec in caplog.records), (
        "falling back to built-in defaults silently is the failure mode being fixed"
    )


# ─── #62: a tag that ENDS a doc block (no space before `</para>`) ────────────
#
# `@req` is an unknown command to doxygen, so it is absorbed into whatever
# paragraph command precedes it. When the tag is the LAST line of the block there
# is no separating space and the stored text ends `...-001</para>`. Both strings
# below are VERBATIM from a built clew.db. Nothing pinned this, and the whole
# suite passed while 104 tagged functions in this repo produced 20 edges.

Activity · 7 steps
lines 283–283import logginglines 285–285from clew import requirements as requirements_modulelines 287–287(tmp_path / ".clew.yaml").write_text("guard:\n stray_top_level_key: true\n", encoding="utf-8")lines 289–289with caplog.at_level(logging.WARNING)lines 290–290result = requirements_module.load_guard_config(tmp_path)lines 292–292assert result is None, "a rejected config must degrade to defaults, not propagate"lines 293–295assert any("INVALID" in rec.message for rec in caplog.records), ( "falling back to built-in defaults silently is the failure mode being fixed" )

test_declared_catalog_columns_read_from_guard_config

None test_requirements_declared.test_declared_catalog_columns_read_from_guard_config(Path tmp_path)

tests/test_requirements_declared.py:145

Show on the map →

Called by none

Calls _write_guard_config, load_guard_config, resolve_catalog_columns

Checks

  • assert resolve_catalog_columns(cfg) == ("req_id", "summary")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_declared_catalog_columns_read_from_guard_config → load_guard_config
REQ-DDB-GUARD-012measuredtest_declared_catalog_columns_read_from_guard_config → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-024measuredtest_declared_catalog_columns_read_from_guard_config → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
Source · 5 lines
def test_declared_catalog_columns_read_from_guard_config(tmp_path: Path) -> None:
    cfg = load_guard_config(_write_guard_config(tmp_path, "requirements.yaml"))
    assert resolve_catalog_columns(cfg) == ("req_id", "summary")

Activity · 2 steps
lines 146–146cfg = load_guard_config(_write_guard_config(tmp_path, "requirements.yaml"))lines 147–147assert resolve_catalog_columns(cfg) == ("req_id", "summary")

test_declared_columns_default_when_no_config

None test_requirements_declared.test_declared_columns_default_when_no_config()

tests/test_requirements_declared.py:150

Checks

  • assert resolve_catalog_columns(None) == ("id", "name")
  • assert (REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULT) == ("id", "name")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_declared_columns_default_when_no_config → resolve_catalog_columns
Source · 10 lines
def test_declared_columns_default_when_no_config() -> None:
    ## 2.0.0 (R5-CFG F8): ONE default pair for the index and the gate, `id` / `name`. The index
    ## still reads `name` or `title` for an undeclared name column (`_first`), so a `{id, title}`
    ## catalog ingests as before.
    from clew.guard.config import REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULT

    assert resolve_catalog_columns(None) == ("id", "name")
    assert (REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULT) == ("id", "name")

Activity · 3 steps
lines 154–154from clew.guard.config import REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULTlines 156–156assert resolve_catalog_columns(None) == ("id", "name")lines 157–157assert (REQUIREMENTS_ID_COLUMN_DEFAULT, REQUIREMENTS_NAME_COLUMN_DEFAULT) == ("id", "name")

test_declared_pattern_read_from_guard_config

None test_requirements_declared.test_declared_pattern_read_from_guard_config(Path tmp_path)

tests/test_requirements_declared.py:134

Checks

  • assert pattern.pattern == "^REQ-X-[A-Z]+-[0-9]{3}$"
  • assert _extract_req_tags("@req REQ-X-FOO-001", pattern) == [
  • assert _extract_req_tags("@req REQ-0621", pattern) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_declared_pattern_read_from_guard_config → load_guard_config
REQ-DDB-GUARD-012measuredtest_declared_pattern_read_from_guard_config → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-024measuredtest_declared_pattern_read_from_guard_config → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
REQ-DDB-SCHEMA-006measuredtest_declared_pattern_read_from_guard_config → _extract_req_tags
Source · 11 lines
def test_declared_pattern_read_from_guard_config(tmp_path: Path) -> None:
    cfg = load_guard_config(_write_guard_config(tmp_path, "requirements.yaml"))
    pattern = resolve_req_id_pattern(cfg)
    assert pattern.pattern == "^REQ-X-[A-Z]+-[0-9]{3}$"
    # Declared pattern matches its ids and rejects demobot-style REQ-0621.
    assert _extract_req_tags("@req REQ-X-FOO-001", pattern) == [
        "REQ-X-FOO-001",
    ]
    assert _extract_req_tags("@req REQ-0621", pattern) == []

Activity · 5 steps
lines 135–135cfg = load_guard_config(_write_guard_config(tmp_path, "requirements.yaml"))lines 136–136pattern = resolve_req_id_pattern(cfg)lines 137–137assert pattern.pattern == "^REQ-X-[A-Z]+-[0-9]{3}$"lines 139–141assert _extract_req_tags("@req REQ-X-FOO-001", pattern) == [ "REQ-X-FOO-001", ]lines 142–142assert _extract_req_tags("@req REQ-0621", pattern) == []

test_extract_req_tags_from_xrefdescription_alias_form

None test_requirements_declared.test_extract_req_tags_from_xrefdescription_alias_form()

a C++ codebase uses ALIASES 'req=@xrefitem req_trace ...', so doxygen stores the id inside an &lt;xrefsect&gt;/&lt;xrefdescription&gt; block, not a literal

tests/test_requirements_declared.py:200

Checks

  • assert _extract_req_tags(text, pattern) == ["REQ-PROJ-HAL-004"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-SCHEMA-006measuredtest_extract_req_tags_from_xrefdescription_alias_form → _extract_req_tags
Source · 14 lines
def test_extract_req_tags_from_xrefdescription_alias_form() -> None:
    """a C++ codebase uses ALIASES 'req=@xrefitem req_trace ...', so doxygen stores the id
    inside an <xrefsect>/<xrefdescription> block, not a literal @req token.
    """
    pattern = re.compile(r"^REQ-PROJ-(HAL|SLAM)-[0-9]{3}$")
    text = (
        '<para><simplesect kind="version"><para>1.0.0 </para></simplesect>'
        '<xrefsect id="req_trace_1_req_trace000189"><xreftitle>Requirement'
        "</xreftitle><xrefdescription><para>REQ-PROJ-HAL-004 </para>"
        "</xrefdescription></xrefsect></para>"
    )
    assert _extract_req_tags(text, pattern) == ["REQ-PROJ-HAL-004"]

Activity · 3 steps
lines 204–204pattern = re.compile(r"^REQ-PROJ-(HAL|SLAM)-[0-9]{3}$")lines 205–210text = ( '<para><simplesect kind="version"><para>1.0.0 </para></simplesect>' '<xrefsect id="req_trace_1_req_trace000189"><xreftitle>Requirement' "</xreftitle><xrefdescription><para>REQ-PROJ-HAL-004 </para>" "</xrefdescription></xrefsect></para>" )lines 211–211assert _extract_req_tags(text, pattern) == ["REQ-PROJ-HAL-004"]

test_extract_req_tags_id_terminated_by_markup_not_just_whitespace

None test_requirements_declared.test_extract_req_tags_id_terminated_by_markup_not_just_whitespace()

tests/test_requirements_declared.py:307

Checks

  • assert _extract_req_tags(glued, pattern) == ["REQ-DDB-PIPE-004"], ("an id glued to its closing tag used to be captured as " "'REQ-DDB-PIPE-004</para>', fail the declared pattern, and be dropped silently" )
  • assert _extract_req_tags(spaced, pattern) == ["REQ-DDB-PIPE-005"], ("the spaced form already worked and must keep working" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_extract_req_tags_id_terminated_by_markup_not_just_whitespace → resolve_req_id_pattern
REQ-DDB-SCHEMA-006measuredtest_extract_req_tags_id_terminated_by_markup_not_just_whitespace → _extract_req_tags
Source · 13 lines
def test_extract_req_tags_id_terminated_by_markup_not_just_whitespace() -> None:
    pattern = resolve_req_id_pattern(None)
    glued = '<simplesect kind="version"><para>6 @req REQ-DDB-PIPE-004</para>\n'
    assert _extract_req_tags(glued, pattern) == ["REQ-DDB-PIPE-004"], (
        "an id glued to its closing tag used to be captured as "
        "'REQ-DDB-PIPE-004</para>', fail the declared pattern, and be dropped silently"
    )
    spaced = '<simplesect kind="version"><para>3 @req REQ-DDB-PIPE-005 </para>\n'
    assert _extract_req_tags(spaced, pattern) == ["REQ-DDB-PIPE-005"], (
        "the spaced form already worked and must keep working"
    )

Activity · 5 steps
lines 308–308pattern = resolve_req_id_pattern(None)lines 309–309glued = '<simplesect kind="version"><para>6 @req REQ-DDB-PIPE-004</para>\n'lines 310–313assert _extract_req_tags(glued, pattern) == ["REQ-DDB-PIPE-004"], ( "an id glued to its closing tag used to be captured as " "'REQ-DDB-PIPE-004</para>', fail the declared pattern, and be dropped silently" )lines 314–314spaced = '<simplesect kind="version"><para>3 @req REQ-DDB-PIPE-005 </para>\n'lines 315–317assert _extract_req_tags(spaced, pattern) == ["REQ-DDB-PIPE-005"], ( "the spaced form already worked and must keep working" )

test_extract_req_tags_keeps_inferred_when_marker_abuts_markup

None test_requirements_declared.test_extract_req_tags_keeps_inferred_when_marker_abuts_markup()

tests/test_requirements_declared.py:390

Checks

  • assert _extract_req_tags("@req REQ-0621 [inferred]</para>", pattern) == [
  • assert _extract_req_tags("@req REQ-0621 [inferred] </para>", pattern) == [

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_extract_req_tags_keeps_inferred_when_marker_abuts_markup → resolve_req_id_pattern
REQ-DDB-SCHEMA-006measuredtest_extract_req_tags_keeps_inferred_when_marker_abuts_markup → _extract_req_tags
Source · 14 lines
def test_extract_req_tags_keeps_inferred_when_marker_abuts_markup() -> None:
    pattern = resolve_req_id_pattern(None)
    # The terminator lookahead was satisfied by the space BEFORE `[inferred]`, so
    # the marker group backtracked away and an inference was recorded as a stated
    # fact — the worse of the two failures, because confidence is exactly what
    # tells a reader whether an author asserted the link or a tool guessed it.
    assert _extract_req_tags("@req REQ-0621 [inferred]</para>", pattern) == [
        "REQ-0621",
    ]
    assert _extract_req_tags("@req REQ-0621 [inferred] </para>", pattern) == [
        "REQ-0621",
    ]

Activity · 3 steps
lines 391–391pattern = resolve_req_id_pattern(None)lines 396–398assert _extract_req_tags("@req REQ-0621 [inferred]</para>", pattern) == [ "REQ-0621", ]lines 399–401assert _extract_req_tags("@req REQ-0621 [inferred] </para>", pattern) == [ "REQ-0621", ]

test_extract_req_tags_survives_doxygens_own_sentence_period

None test_requirements_declared.test_extract_req_tags_survives_doxygens_own_sentence_period()

Does the thing.

tests/test_requirements_declared.py:320

Checks

  • assert _extract_req_tags(punctuated, pattern) == ["REQ-PROBE-001"], ("doxygen's own sentence period must not cost the author their traceability edge" )
  • assert _extract_req_tags(f"@req REQ-PROBE-001{trailing} ", pattern) == ["REQ-PROBE-001"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_extract_req_tags_survives_doxygens_own_sentence_period → resolve_req_id_pattern
REQ-DDB-SCHEMA-006measuredtest_extract_req_tags_survives_doxygens_own_sentence_period → _extract_req_tags
Source · 25 lines
def test_extract_req_tags_survives_doxygens_own_sentence_period() -> None:
    """gh#20. A `@req` that follows `@brief` with no blank line continues the brief
    paragraph, and doxygen APPENDS ITS OWN PERIOD when it closes that paragraph. The author
    wrote a clean tag; the punctuation is doxygen's:

        /** @brief Does the thing.
         *  @req REQ-PROBE-001            ->  '<para>Does the thing. @req REQ-PROBE-001. </para>'
         */                                                                        ^ added

    The id terminator was whitespace / `<` / end-of-text, so the token was
    `REQ-PROBE-001.` and the full match failed. Total, silent drop — no edge, no warning —
    and `dossier("REQ-PROBE-001")` then answers with the definitive-negative wording.

    This repository does not hit it because its own convention puts `@req` in a `##` block
    after `@version`, which is a separate paragraph. That is exactly why it survived.
    """
    pattern = resolve_req_id_pattern(None)
    punctuated = "<para>Does the thing. @req REQ-PROBE-001. </para>\n"
    assert _extract_req_tags(punctuated, pattern) == ["REQ-PROBE-001"], (
        "doxygen's own sentence period must not cost the author their traceability edge"
    )
    for trailing in (",", ";", ":"):
        assert _extract_req_tags(f"@req REQ-PROBE-001{trailing} ", pattern) == ["REQ-PROBE-001"]

Activity · 5 steps
lines 336–336pattern = resolve_req_id_pattern(None)lines 337–337punctuated = "<para>Does the thing. @req REQ-PROBE-001. </para>\n"lines 338–340assert _extract_req_tags(punctuated, pattern) == ["REQ-PROBE-001"], ( "doxygen's own sentence period must not cost the author their traceability edge" )lines 341–341◇ for trailing in (",", ";", ":")lines 342–342assert _extract_req_tags(f"@req REQ-PROBE-001{trailing} ", pattern) == ["REQ-PROBE-001"]

test_flat_catalog_declared_columns_ingest

None test_requirements_declared.test_flat_catalog_declared_columns_ingest(Path tmp_path)

tests/test_requirements_declared.py:227

Show on the map →

Called by none

Calls _write_guard_config, ingest_requirements_yaml, load_guard_config

Checks

  • assert rows == [("REQ-X-FOO-001", "foo", "Foo works", "foo emits", "P0")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_flat_catalog_declared_columns_ingest → load_guard_config
REQ-DDB-CONFIG-003measuredtest_flat_catalog_declared_columns_ingest → ingest_requirements_yaml → _is_flat_req_list
REQ-DDB-GUARD-012measuredtest_flat_catalog_declared_columns_ingest → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-024measuredtest_flat_catalog_declared_columns_ingest → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
REQ-DDB-SCHEMA-006measuredtest_flat_catalog_declared_columns_ingest → ingest_requirements_yaml
REQ-DDB-SCHEMA-015measuredtest_flat_catalog_declared_columns_ingest → ingest_requirements_yaml
REQ-DDB-WIKI-054inferredtest_flat_catalog_declared_columns_ingest → ingest_requirements_yaml → _is_flat_req_list → all
Source · 25 lines
def test_flat_catalog_declared_columns_ingest(tmp_path: Path) -> None:
    catalog = tmp_path / "requirements.yaml"
    catalog.write_text(
        "- req_id: REQ-X-FOO-001\n"
        "  summary: Foo works\n"
        "  block: foo\n"
        "  acceptance: foo emits\n"
        "  priority: P0\n",
        encoding="utf-8",
    )
    cfg = load_guard_config(_write_guard_config(tmp_path, str(catalog)))
    db = tmp_path / "clew.db"
    sqlite3.connect(str(db)).close()
    ingest_requirements_yaml(db, catalog, cfg)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT id, block, title, acceptance, priority FROM requirements",
    ).fetchall()
    conn.close()
    assert rows == [("REQ-X-FOO-001", "foo", "Foo works", "foo emits", "P0")]


# ─── _is_flat_req_list unit coverage ────────────────────────────────────────

Activity · 10 steps
lines 228–228catalog = tmp_path / "requirements.yaml"lines 229–236catalog.write_text( "- req_id: REQ-X-FOO-001\n" " summary: Foo works\n" " block: foo\n" " acceptance: foo emits\n" " priority: P0\n", encoding="utf-8", )lines 237–237cfg = load_guard_config(_write_guard_config(tmp_path, str(catalog)))lines 238–238db = tmp_path / "clew.db"lines 239–239sqlite3.connect(str(db)).close()lines 240–240ingest_requirements_yaml(db, catalog, cfg)lines 241–241conn = sqlite3.connect(str(db))lines 242–244rows = conn.execute( "SELECT id, block, title, acceptance, priority FROM requirements", ).fetchall()lines 245–245conn.close()lines 246–246assert rows == [("REQ-X-FOO-001", "foo", "Foo works", "foo emits", "P0")]

test_import_req_edges_permissive_default_populates

None test_requirements_declared.test_import_req_edges_permissive_default_populates(Path tmp_path)

tests/test_requirements_declared.py:91

Show on the map →

Called by none

Calls _make_tagged_db, import_req_edges

Checks

  • assert rows == [("REQ-0621", 1), ("REQ-0900", 2)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-SCHEMA-006measuredtest_import_req_edges_permissive_default_populates → import_req_edges
Source · 15 lines
def test_import_req_edges_permissive_default_populates(tmp_path: Path) -> None:
    # No pattern argument → permissive fallback; demobot-style ids populate.
    db = _make_tagged_db(tmp_path, "REQ-0621", "REQ-0900")
    import_req_edges(db)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT req_id, memberdef_rowid FROM req_edges ORDER BY memberdef_rowid",
    ).fetchall()
    conn.close()
    assert rows == [("REQ-0621", 1), ("REQ-0900", 2)]


# ─── declared pattern (C++-style nested repo) ───────────────────────────────

Activity · 6 steps
lines 93–93db = _make_tagged_db(tmp_path, "REQ-0621", "REQ-0900")lines 94–94import_req_edges(db)lines 95–95conn = sqlite3.connect(str(db))lines 96–98rows = conn.execute( "SELECT req_id, memberdef_rowid FROM req_edges ORDER BY memberdef_rowid", ).fetchall()lines 99–99conn.close()lines 100–100assert rows == [("REQ-0621", 1), ("REQ-0900", 2)]

test_is_flat_req_list_honors_declared_id_column

None test_requirements_declared.test_is_flat_req_list_honors_declared_id_column()

tests/test_requirements_declared.py:265

Checks

  • assert _is_flat_req_list([{"req_id": "REQ-1"}], "req_id") is True

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-CONFIG-003measuredtest_is_flat_req_list_honors_declared_id_column → _is_flat_req_list
REQ-DDB-WIKI-054inferredtest_is_flat_req_list_honors_declared_id_column → _is_flat_req_list → all
Source · 7 lines
def test_is_flat_req_list_honors_declared_id_column() -> None:
    assert _is_flat_req_list([{"req_id": "REQ-1"}], "req_id") is True


# ─── a rejected guard config must not kill the build ─────────────────────────

Activity · 1 steps
lines 266–266assert _is_flat_req_list([{"req_id": "REQ-1"}], "req_id") is True

test_is_flat_req_list_recognizes_flat

None test_requirements_declared.test_is_flat_req_list_recognizes_flat()

tests/test_requirements_declared.py:252

Checks

  • assert _is_flat_req_list([{"id": "REQ-1"}], "id") is True

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-CONFIG-003measuredtest_is_flat_req_list_recognizes_flat → _is_flat_req_list
REQ-DDB-WIKI-054inferredtest_is_flat_req_list_recognizes_flat → _is_flat_req_list → all
Source · 4 lines
def test_is_flat_req_list_recognizes_flat() -> None:
    assert _is_flat_req_list([{"id": "REQ-1"}], "id") is True

Activity · 1 steps
lines 253–253assert _is_flat_req_list([{"id": "REQ-1"}], "id") is True

test_is_flat_req_list_rejects_empty_and_scalar

None test_requirements_declared.test_is_flat_req_list_rejects_empty_and_scalar()

tests/test_requirements_declared.py:260

Checks

  • assert _is_flat_req_list([], "id") is False
  • assert _is_flat_req_list("nope", "id") is False

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-CONFIG-003measuredtest_is_flat_req_list_rejects_empty_and_scalar → _is_flat_req_list
REQ-DDB-WIKI-054inferredtest_is_flat_req_list_rejects_empty_and_scalar → _is_flat_req_list → all
Source · 5 lines
def test_is_flat_req_list_rejects_empty_and_scalar() -> None:
    assert _is_flat_req_list([], "id") is False
    assert _is_flat_req_list("nope", "id") is False

Activity · 2 steps
lines 261–261assert _is_flat_req_list([], "id") is Falselines 262–262assert _is_flat_req_list("nope", "id") is False

test_is_flat_req_list_rejects_nested_dict

None test_requirements_declared.test_is_flat_req_list_rejects_nested_dict()

tests/test_requirements_declared.py:256

Checks

  • assert _is_flat_req_list({"domains": {}}, "id") is False

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-CONFIG-003measuredtest_is_flat_req_list_rejects_nested_dict → _is_flat_req_list
REQ-DDB-WIKI-054inferredtest_is_flat_req_list_rejects_nested_dict → _is_flat_req_list → all
Source · 4 lines
def test_is_flat_req_list_rejects_nested_dict() -> None:
    assert _is_flat_req_list({"domains": {}}, "id") is False

Activity · 1 steps
lines 257–257assert _is_flat_req_list({"domains": {}}, "id") is False

test_nested_domains_catalog_ingests_zero_but_tags_populate

None test_requirements_declared.test_nested_domains_catalog_ingests_zero_but_tags_populate(Path tmp_path)

C++-shaped repo: nested `domains:` catalog yields 0 rows gracefully, while req_edges still populate from tags matched by the declared pattern.

tests/test_requirements_declared.py:160

Checks

  • assert catalog_count == 0
  • assert rows == [("REQ-X-BAR-002",), ("REQ-X-FOO-001",)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_nested_domains_catalog_ingests_zero_but_tags_populate → load_guard_config
REQ-DDB-CONFIG-003measuredtest_nested_domains_catalog_ingests_zero_but_tags_populate → ingest_requirements_yaml → _is_flat_req_list
REQ-DDB-GUARD-012measuredtest_nested_domains_catalog_ingests_zero_but_tags_populate → load_guard_config → read_guard_config → read_requirements_section
REQ-DDB-GUARD-024measuredtest_nested_domains_catalog_ingests_zero_but_tags_populate → load_guard_config → read_guard_config → load_config → apply_opt_in_languages
REQ-DDB-SCHEMA-006measuredtest_nested_domains_catalog_ingests_zero_but_tags_populate → ingest_requirements_yaml
REQ-DDB-SCHEMA-015measuredtest_nested_domains_catalog_ingests_zero_but_tags_populate → ingest_requirements_yaml
REQ-DDB-WIKI-054inferredtest_nested_domains_catalog_ingests_zero_but_tags_populate → ingest_requirements_yaml → _is_flat_req_list → all
Source · 40 lines
def test_nested_domains_catalog_ingests_zero_but_tags_populate(
    tmp_path: Path,
) -> None:
    """C++-shaped repo: nested `domains:` catalog yields 0 rows gracefully,
    while req_edges still populate from tags matched by the declared pattern.
    """
    # Nested-domains catalog (a C++ codebase shape) — NOT a flat id-bearing list.
    catalog = tmp_path / "requirements.yaml"
    catalog.write_text(
        "domains:\n"
        "  slam:\n"
        "    requirements:\n"
        "      - id: REQ-X-BAZ-003\n"
        "        summary: Localize\n",
        encoding="utf-8",
    )
    cfg = load_guard_config(_write_guard_config(tmp_path, str(catalog)))

    db = _make_tagged_db(tmp_path, "REQ-X-FOO-001", "REQ-X-BAR-002")

    # Catalog ingestion must NOT crash and must ingest 0 rows.
    ingest_requirements_yaml(db, catalog, cfg)
    conn = sqlite3.connect(str(db))
    catalog_count = conn.execute("SELECT COUNT(*) FROM requirements").fetchone()[0]
    conn.close()
    assert catalog_count == 0

    # req_edges populate from the declared-pattern tags regardless.
    import_req_edges(db, resolve_req_id_pattern(cfg))
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT req_id FROM req_edges ORDER BY req_id",
    ).fetchall()
    conn.close()
    assert rows == [("REQ-X-BAR-002",), ("REQ-X-FOO-001",)]


# ─── xrefitem-alias form (a C++ codebase real-firmware shape) ──────────────────────────

Activity · 14 steps
lines 167–167catalog = tmp_path / "requirements.yaml"lines 168–175catalog.write_text( "domains:\n" " slam:\n" " requirements:\n" " - id: REQ-X-BAZ-003\n" " summary: Localize\n", encoding="utf-8", )lines 176–176cfg = load_guard_config(_write_guard_config(tmp_path, str(catalog)))lines 178–178db = _make_tagged_db(tmp_path, "REQ-X-FOO-001", "REQ-X-BAR-002")lines 181–181ingest_requirements_yaml(db, catalog, cfg)lines 182–182conn = sqlite3.connect(str(db))lines 183–183catalog_count = conn.execute("SELECT COUNT(*) FROM requirements").fetchone()[0]lines 184–184conn.close()lines 185–185assert catalog_count == 0lines 188–188import_req_edges(db, resolve_req_id_pattern(cfg))lines 189–189conn = sqlite3.connect(str(db))lines 190–192rows = conn.execute( "SELECT req_id FROM req_edges ORDER BY req_id", ).fetchall()lines 193–193conn.close()lines 194–194assert rows == [("REQ-X-BAR-002",), ("REQ-X-FOO-001",)]

test_only_ONE_trailing_character_is_retried

None test_requirements_declared.test_only_ONE_trailing_character_is_retried()

A retry is a concession to punctuation, not a licence to keep chewing. `REQ-X...` is not a tag with three periods to peel — it is text this extractor should decline, and peeling until something matches is how a scanner starts inventing ids out of prose.

tests/test_requirements_declared.py:381

Checks

  • assert _extract_req_tags("@req REQ-PROBE-001... ", pattern) == []
  • assert _extract_req_tags("@req REQ-PROBE-001.. ", pattern) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_only_ONE_trailing_character_is_retried → resolve_req_id_pattern
REQ-DDB-SCHEMA-006measuredtest_only_ONE_trailing_character_is_retried → _extract_req_tags
Source · 9 lines
def test_only_ONE_trailing_character_is_retried() -> None:
    """A retry is a concession to punctuation, not a licence to keep chewing. `REQ-X...`
    is not a tag with three periods to peel — it is text this extractor should decline, and
    peeling until something matches is how a scanner starts inventing ids out of prose."""
    pattern = resolve_req_id_pattern(None)
    assert _extract_req_tags("@req REQ-PROBE-001... ", pattern) == []
    assert _extract_req_tags("@req REQ-PROBE-001.. ", pattern) == []

Activity · 3 steps
lines 385–385pattern = resolve_req_id_pattern(None)lines 386–386assert _extract_req_tags("@req REQ-PROBE-001... ", pattern) == []lines 387–387assert _extract_req_tags("@req REQ-PROBE-001.. ", pattern) == []

test_permissive_fallback_matches_req_rejects_non_req

None test_requirements_declared.test_permissive_fallback_matches_req_rejects_non_req()

tests/test_requirements_declared.py:72

Checks

  • assert pattern is _PERMISSIVE_REQ_ID_RE
  • assert _extract_req_tags("@req REQ-0621", pattern) == ["REQ-0621"]
  • assert _extract_req_tags("@req REQ-PROJ-NAV-002", pattern) == [
  • assert _extract_req_tags("@req TICKET-42", pattern) == []
  • assert _extract_req_tags("@req notareq", pattern) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_permissive_fallback_matches_req_rejects_non_req → resolve_req_id_pattern
REQ-DDB-SCHEMA-006measuredtest_permissive_fallback_matches_req_rejects_non_req → _extract_req_tags
Source · 12 lines
def test_permissive_fallback_matches_req_rejects_non_req() -> None:
    pattern = resolve_req_id_pattern(None)
    assert pattern is _PERMISSIVE_REQ_ID_RE
    # A reasonable REQ id matches; a non-REQ token does not.
    assert _extract_req_tags("@req REQ-0621", pattern) == ["REQ-0621"]
    assert _extract_req_tags("@req REQ-PROJ-NAV-002", pattern) == [
        "REQ-PROJ-NAV-002",
    ]
    assert _extract_req_tags("@req TICKET-42", pattern) == []
    assert _extract_req_tags("@req notareq", pattern) == []

Activity · 6 steps
lines 73–73pattern = resolve_req_id_pattern(None)lines 74–74assert pattern is _PERMISSIVE_REQ_ID_RElines 76–76assert _extract_req_tags("@req REQ-0621", pattern) == ["REQ-0621"]lines 77–79assert _extract_req_tags("@req REQ-PROJ-NAV-002", pattern) == [ "REQ-PROJ-NAV-002", ]lines 80–80assert _extract_req_tags("@req TICKET-42", pattern) == []lines 81–81assert _extract_req_tags("@req notareq", pattern) == []

test_permissive_fallback_preserves_inferred_confidence

None test_requirements_declared.test_permissive_fallback_preserves_inferred_confidence()

tests/test_requirements_declared.py:84

Checks

  • assert _extract_req_tags("@req REQ-0621 [inferred]", pattern) == [

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_permissive_fallback_preserves_inferred_confidence → resolve_req_id_pattern
REQ-DDB-SCHEMA-006measuredtest_permissive_fallback_preserves_inferred_confidence → _extract_req_tags
Source · 7 lines
def test_permissive_fallback_preserves_inferred_confidence() -> None:
    pattern = resolve_req_id_pattern(None)
    assert _extract_req_tags("@req REQ-0621 [inferred]", pattern) == [
        "REQ-0621",
    ]

Activity · 2 steps
lines 85–85pattern = resolve_req_id_pattern(None)lines 86–88assert _extract_req_tags("@req REQ-0621 [inferred]", pattern) == [ "REQ-0621", ]

test_the_guard_s_KEYED_catalog_vocabulary_populates_every_column

None test_requirements_declared.test_the_guard_s_KEYED_catalog_vocabulary_populates_every_column()

One catalog, two vocabularies — and reading only ours emptied the metadata.

tests/test_requirements_declared.py:438

Show on the map →

Called by none

Calls none

Checks

  • assert _first(keyed, "block", "subsystem") == "schema"
  • assert _first(keyed, "title", "name", "title") == "Lock layer"
  • assert (_first(keyed, "acceptance", "acceptance_criteria") == "locks + lock_acquisitions populate" )
  • assert _first(keyed, "priority", "x-priority") == "P2"
  • assert _first(flat, "block", "subsystem") == "query"
  • assert _first(flat, "title", "name", "title") == "Dossier"
  • assert _first(flat, "acceptance", "acceptance_criteria") == "returns rows"
  • assert _first(flat, "priority", "x-priority") == "P1"
  • assert _first({}, "title", "name") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
Source · 38 lines
def test_the_guard_s_KEYED_catalog_vocabulary_populates_every_column() -> None:
    """One catalog, two vocabularies — and reading only ours emptied the metadata.

    Our flat shape says `{block, title, acceptance, priority}`. doxygen-guard's keyed YAML
    catalog says `{subsystem, name, acceptance_criteria}`, with `name` its only required
    field, and our own extras move behind the `x-` passthrough prefix. Converting this repo's
    catalog to the keyed shape (so the GATE could read the same file the INDEX reads) left all
    36 `requirements` rows with a NULL title, block, acceptance and priority.

    The failure hid in the usual place: `req_edges` come from TAGS, not the catalog, so
    coverage still read 32/36 while every row's metadata was gone. Same shape as the catalog
    that would not load at all — whichever surface is easy to check kept working.
    """
    from clew.requirements import _first

    keyed = {
        "subsystem": "schema",
        "name": "Lock layer",
        "acceptance_criteria": "locks + lock_acquisitions populate",
        "x-priority": "P2",
    }
    assert _first(keyed, "block", "subsystem") == "schema"
    assert _first(keyed, "title", "name", "title") == "Lock layer"
    assert (
        _first(keyed, "acceptance", "acceptance_criteria") == "locks + lock_acquisitions populate"
    )
    assert _first(keyed, "priority", "x-priority") == "P2"

    # Our own flat vocabulary must keep working — the aliases are additive, not a swap.
    flat = {"block": "query", "title": "Dossier", "acceptance": "returns rows", "priority": "P1"}
    assert _first(flat, "block", "subsystem") == "query"
    assert _first(flat, "title", "name", "title") == "Dossier"
    assert _first(flat, "acceptance", "acceptance_criteria") == "returns rows"
    assert _first(flat, "priority", "x-priority") == "P1"

    # An absent key must be None, not the empty string: NULL is what says "not declared",
    # and "" would read as a declared-but-blank title in every consumer.
    assert _first({}, "title", "name") is None

1 more lines, not shown

Activity · 12 steps
lines 451–451from clew.requirements import _firstlines 453–458keyed = { "subsystem": "schema", "name": "Lock layer", "acceptance_criteria": "locks + lock_acquisitions populate", "x-priority": "P2", }lines 459–459assert _first(keyed, "block", "subsystem") == "schema"lines 460–460assert _first(keyed, "title", "name", "title") == "Lock layer"lines 461–463assert ( _first(keyed, "acceptance", "acceptance_criteria") == "locks + lock_acquisitions populate" )lines 464–464assert _first(keyed, "priority", "x-priority") == "P2"lines 467–467flat = {"block": "query", "title": "Dossier", "acceptance": "returns rows", "priority": "P1"}lines 468–468assert _first(flat, "block", "subsystem") == "query"lines 469–469assert _first(flat, "title", "name", "title") == "Dossier"lines 470–470assert _first(flat, "acceptance", "acceptance_criteria") == "returns rows"lines 471–471assert _first(flat, "priority", "x-priority") == "P1"lines 475–475assert _first({}, "title", "name") is None

test_the_xrefitem_form_stores_the_TRIMMED_id_not_the_raw_token

None test_requirements_declared.test_the_xrefitem_form_stores_the_TRIMMED_id_not_the_raw_token()

The alias path (a repo that declares `ALIASES += req=...`) renders the tag into an `&lt;xrefdescription&gt;`, and it ends a sentence just as often as the literal form. It gets the same tolerance — but it must store the MATCHED id, not the token that was tested.

tests/test_requirements_declared.py:364

Checks

  • assert _extract_req_tags(punctuated, pattern) == ["REQ-DDB-PIPE-004"], ("the stored id must be the trimmed one, or it joins to no catalog row" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_xrefitem_form_stores_the_TRIMMED_id_not_the_raw_token → resolve_req_id_pattern
REQ-DDB-SCHEMA-006measuredtest_the_xrefitem_form_stores_the_TRIMMED_id_not_the_raw_token → _extract_req_tags
Source · 17 lines
def test_the_xrefitem_form_stores_the_TRIMMED_id_not_the_raw_token() -> None:
    """The alias path (a repo that declares `ALIASES += req=...`) renders the tag into an
    `<xrefdescription>`, and it ends a sentence just as often as the literal form. It gets the
    same tolerance — but it must store the MATCHED id, not the token that was tested.

    Appending the raw token would write `REQ-DDB-PIPE-004.` into `req_edges.req_id`, which
    joins to nothing in the catalog: the edge exists, the requirement resolves to no title or
    status, and the traceability looks present while being broken. Worse than the drop it
    replaced, which is why this is pinned separately from the literal form.
    """
    pattern = resolve_req_id_pattern(None)
    punctuated = "<xrefdescription><para>REQ-DDB-PIPE-004.</para></xrefdescription>"
    assert _extract_req_tags(punctuated, pattern) == ["REQ-DDB-PIPE-004"], (
        "the stored id must be the trimmed one, or it joins to no catalog row"
    )

Activity · 3 steps
lines 374–374pattern = resolve_req_id_pattern(None)lines 375–375punctuated = "<xrefdescription><para>REQ-DDB-PIPE-004.</para></xrefdescription>"lines 376–378assert _extract_req_tags(punctuated, pattern) == ["REQ-DDB-PIPE-004"], ( "the stored id must be the trimmed one, or it joins to no catalog row" )

test_this_repo_DECLARES_where_its_own_requirements_catalog_lives

None test_requirements_declared.test_this_repo_DECLARES_where_its_own_requirements_catalog_lives()

Dogfooding, pinned — and it was NOT true when this test was written.

tests/test_requirements_declared.py:404

Show on the map →

Called by none

Calls none

Checks

  • assert SECTION_GUARD in doc
  • assert declared, (f"{DECLARATION_NAME} must declare requirements.file, or our own index " "silently ingests no catalog — the exact hole bd2d34e closed for other repos" )
  • assert catalog.exists(), f"declared catalog {declared} does not exist"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
Source · 34 lines
def test_this_repo_DECLARES_where_its_own_requirements_catalog_lives() -> None:
    """Dogfooding, pinned — and it was NOT true when this test was written.

    `bd2d34e` taught the index to honour `impact.requirements.file` because a repo that
    declares its catalog had the declaration read by the gate and ignored by the index. We
    shipped that fix for other repos and never applied it to ourselves: this repo's
    guard config had no `impact:` section, so a bare `--scope from-guard` build
    ingested ZERO catalog rows.

    The failure was invisible from the side anyone looks at. `req_edges` populate from TAGS,
    independently of the catalog, so coverage read 30/34 while every one of those 34
    requirements came back with no title, status or acceptance. The MCP server passes no
    flags at all, so through the product's actual interface the catalog could never load.

    Asserting the declaration rather than a built database keeps this a fast unit test and
    pins the thing that broke: not "does ingestion work" (it always did, given a path) but
    "does the path reach it without a human typing a flag".
    """
    import yaml

    from clew.declaration import DECLARATION_NAME, SECTION_GUARD

    doc = yaml.safe_load(Path(__file__).resolve().parents[1].joinpath(DECLARATION_NAME).read_text())
    ## 2.0.0 (R5-CFG F7): the catalog is the top-level `requirements:` section.
    declared = (doc.get("requirements") or {}).get("file")
    assert SECTION_GUARD in doc
    assert declared, (
        f"{DECLARATION_NAME} must declare requirements.file, or our own index "
        "silently ingests no catalog — the exact hole bd2d34e closed for other repos"
    )
    catalog = Path(__file__).resolve().parents[1] / str(declared)
    assert catalog.exists(), f"declared catalog {declared} does not exist"

Activity · 8 steps
lines 422–422import yamllines 424–424from clew.declaration import DECLARATION_NAME, SECTION_GUARDlines 426–426doc = yaml.safe_load(Path(__file__).resolve().parents[1].joinpath(DECLARATION_NAME).read_text())lines 428–428declared = (doc.get("requirements") or {}).get("file")lines 429–429assert SECTION_GUARD in doclines 430–433assert declared, ( f"{DECLARATION_NAME} must declare requirements.file, or our own index " "silently ingests no catalog — the exact hole bd2d34e closed for other repos" )lines 434–434catalog = Path(__file__).resolve().parents[1] / str(declared)lines 435–435assert catalog.exists(), f"declared catalog {declared} does not exist"

test_xrefdescription_ignores_non_matching_tokens

None test_requirements_declared.test_xrefdescription_ignores_non_matching_tokens()

tests/test_requirements_declared.py:214

Checks

  • assert _extract_req_tags(text, pattern) == ["REQ-PROJ-NAV-002"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001catalog
REQ-DDB-SCHEMA-006measuredtest_xrefdescription_ignores_non_matching_tokens → _extract_req_tags
Source · 13 lines
def test_xrefdescription_ignores_non_matching_tokens() -> None:
    # Only tokens matching the declared pattern survive; version/prose don't.
    pattern = re.compile(r"^REQ-PROJ-[A-Z]+-[0-9]{3}$")
    text = (
        "<xrefdescription><para>REQ-PROJ-NAV-002 localizes the robot 1.0.0"
        " </para></xrefdescription>"
    )
    assert _extract_req_tags(text, pattern) == ["REQ-PROJ-NAV-002"]


# ─── flat catalog + declared column mapping ─────────────────────────────────

Activity · 3 steps
lines 216–216pattern = re.compile(r"^REQ-PROJ-[A-Z]+-[0-9]{3}$")lines 217–220text = ( "<xrefdescription><para>REQ-PROJ-NAV-002 localizes the robot 1.0.0" " </para></xrefdescription>" )lines 221–221assert _extract_req_tags(text, pattern) == ["REQ-PROJ-NAV-002"]