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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_an_invalid_guard_section_is_survived → load_guard_config |
| REQ-DDB-GUARD-012 | measured | test_an_invalid_guard_section_is_survived → load_guard_config → read_guard_config → read_requirements_section |
| REQ-DDB-GUARD-014 | measured | |
| REQ-DDB-GUARD-024 | inferred | test_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
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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_declared_catalog_columns_read_from_guard_config → load_guard_config |
| REQ-DDB-GUARD-012 | measured | test_declared_catalog_columns_read_from_guard_config → load_guard_config → read_guard_config → read_requirements_section |
| REQ-DDB-GUARD-024 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_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
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
Called by none
Calls _extract_req_tags, _write_guard_config, load_guard_config, resolve_req_id_pattern
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_declared_pattern_read_from_guard_config → load_guard_config |
| REQ-DDB-GUARD-012 | measured | test_declared_pattern_read_from_guard_config → load_guard_config → read_guard_config → read_requirements_section |
| REQ-DDB-GUARD-024 | measured | test_declared_pattern_read_from_guard_config → load_guard_config → read_guard_config → load_config → apply_opt_in_languages |
| REQ-DDB-SCHEMA-006 | measured | test_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
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 <xrefsect>/<xrefdescription> block, not a literal
tests/test_requirements_declared.py:200
Checks
assert _extract_req_tags(text, pattern) == ["REQ-PROJ-HAL-004"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_extract_req_tags_id_terminated_by_markup_not_just_whitespace → resolve_req_id_pattern |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_extract_req_tags_keeps_inferred_when_marker_abuts_markup → resolve_req_id_pattern |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_extract_req_tags_survives_doxygens_own_sentence_period → resolve_req_id_pattern |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_flat_catalog_declared_columns_ingest → load_guard_config |
| REQ-DDB-CONFIG-003 | measured | test_flat_catalog_declared_columns_ingest → ingest_requirements_yaml → _is_flat_req_list |
| REQ-DDB-GUARD-012 | measured | test_flat_catalog_declared_columns_ingest → load_guard_config → read_guard_config → read_requirements_section |
| REQ-DDB-GUARD-024 | measured | test_flat_catalog_declared_columns_ingest → load_guard_config → read_guard_config → load_config → apply_opt_in_languages |
| REQ-DDB-SCHEMA-006 | measured | test_flat_catalog_declared_columns_ingest → ingest_requirements_yaml |
| REQ-DDB-SCHEMA-015 | measured | test_flat_catalog_declared_columns_ingest → ingest_requirements_yaml |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Checks
assert rows == [("REQ-0621", 1), ("REQ-0900", 2)]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-CONFIG-003 | measured | test_is_flat_req_list_honors_declared_id_column → _is_flat_req_list |
| REQ-DDB-WIKI-054 | inferred | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-CONFIG-003 | measured | test_is_flat_req_list_recognizes_flat → _is_flat_req_list |
| REQ-DDB-WIKI-054 | inferred | test_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
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 Falseassert _is_flat_req_list("nope", "id") is False
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-CONFIG-003 | measured | test_is_flat_req_list_rejects_empty_and_scalar → _is_flat_req_list |
| REQ-DDB-WIKI-054 | inferred | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-CONFIG-003 | measured | test_is_flat_req_list_rejects_nested_dict → _is_flat_req_list |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Called by none
Calls _make_tagged_db, _write_guard_config, import_req_edges, ingest_requirements_yaml, load_guard_config, resolve_req_id_pattern
Checks
assert catalog_count == 0assert rows == [("REQ-X-BAR-002",), ("REQ-X-FOO-001",)]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_nested_domains_catalog_ingests_zero_but_tags_populate → load_guard_config |
| REQ-DDB-CONFIG-003 | measured | test_nested_domains_catalog_ingests_zero_but_tags_populate → ingest_requirements_yaml → _is_flat_req_list |
| REQ-DDB-GUARD-012 | measured | test_nested_domains_catalog_ingests_zero_but_tags_populate → load_guard_config → read_guard_config → read_requirements_section |
| REQ-DDB-GUARD-024 | measured | test_nested_domains_catalog_ingests_zero_but_tags_populate → load_guard_config → read_guard_config → load_config → apply_opt_in_languages |
| REQ-DDB-SCHEMA-006 | measured | test_nested_domains_catalog_ingests_zero_but_tags_populate → ingest_requirements_yaml |
| REQ-DDB-SCHEMA-015 | measured | test_nested_domains_catalog_ingests_zero_but_tags_populate → ingest_requirements_yaml |
| REQ-DDB-WIKI-054 | inferred | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_only_ONE_trailing_character_is_retried → resolve_req_id_pattern |
| REQ-DDB-SCHEMA-006 | measured | test_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
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_REassert _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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_permissive_fallback_matches_req_rejects_non_req → resolve_req_id_pattern |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_permissive_fallback_preserves_inferred_confidence → resolve_req_id_pattern |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog |
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 None1 more lines, not shown
Activity · 12 steps
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 `<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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_xrefitem_form_stores_the_TRIMMED_id_not_the_raw_token → resolve_req_id_pattern |
| REQ-DDB-SCHEMA-006 | measured | test_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
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
Checks
assert SECTION_GUARD in docassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog |
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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | catalog | |
| REQ-DDB-SCHEMA-006 | measured | test_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 ─────────────────────────────────