test_r1_richness.py

tests/test_r1_richness.py

R1 semantic-richness tests: threads, membership, terminus, dispatch_mode, thread-boundary flags, and declared edge_triggered.

test_a_module_level_python_entry_resolves_through_its_scope

None test_r1_richness.test_a_module_level_python_entry_resolves_through_its_scope()

A MODULE-LEVEL PYTHON FUNCTION HAS NO MODULE IN ITS `definition`, and that broke this resolver for every one of them. doxygen writes the qualifier into `definition` for a CLASS method and omits it for a module-level function, recording it in `scope` instead:

tests/test_r1_richness.py:459

Show on the map →

Called by none

Calls _resolve_qualified_entry

Checks

  • assert _resolve_qualified_entry(conn, "clew.doxygen._write_doxyfile_stdin", ".") == 1
  • assert _resolve_qualified_entry(conn, "other.module._write_doxyfile_stdin", ".") == 2
  • assert _resolve_qualified_entry(conn, "third.module._write_doxyfile_stdin", ".") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 47 lines
def test_a_module_level_python_entry_resolves_through_its_scope() -> None:
    """A MODULE-LEVEL PYTHON FUNCTION HAS NO MODULE IN ITS `definition`, and that broke this
    resolver for every one of them. doxygen writes the qualifier into `definition` for a
    CLASS method and omits it for a module-level function, recording it in `scope` instead:

        pysample.spawner.Poller._run    definition ' None pysample.spawner.Poller._run'
        clew.doxygen._write_doxyfile_stdin
                                        definition ' None _write_doxyfile_stdin'
                                        scope      'clew.doxygen'

    So `threading.Thread(target=clew.doxygen._write_doxyfile_stdin)` matched no definition and
    the thread's entry stayed NULL — which drops the entry AND its whole membership closure,
    while the index plainly holds the function. Caught by this repo's own self-index test,
    which asserts the falsifiable invariant that an entry is NULL only when its tail name is
    genuinely absent.

    The scope pass is a FALLBACK, not a widening: `definition` is still tried first, so every
    boundary and collision guard above still decides the C++ cases. `scope || sep || name` is
    an exact equality rather than a LIKE, so it cannot collide the way the prefilter can — and
    it is unique across this repository's own index.
    """
    from clew.threads import _resolve_qualified_entry

    conn = sqlite3.connect(":memory:")
    conn.executescript(
        "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, "
        "definition TEXT, scope TEXT, file_id INTEGER, bodyfile_id INTEGER);"
    )
    conn.executemany(
        "INSERT INTO memberdef VALUES (?, 'function', ?, ?, ?, 1, 1)",
        [
            # The real target: doxygen left the module out of `definition`.
            (1, "_write_doxyfile_stdin", " None _write_doxyfile_stdin", "clew.doxygen"),
            # A same-named function in ANOTHER module must not be borrowed.
            (2, "_write_doxyfile_stdin", " None _write_doxyfile_stdin", "other.module"),
        ],
    )
    conn.commit()

    assert _resolve_qualified_entry(conn, "clew.doxygen._write_doxyfile_stdin", ".") == 1
    assert _resolve_qualified_entry(conn, "other.module._write_doxyfile_stdin", ".") == 2
    # An unindexed module stays NULL rather than borrowing either row — fail closed, exactly
    # as the definition-based path does for a suffix collision.
    assert _resolve_qualified_entry(conn, "third.module._write_doxyfile_stdin", ".") is None
    conn.close()

Activity · 9 steps
lines 480–480from clew.threads import _resolve_qualified_entrylines 482–482conn = sqlite3.connect(":memory:")lines 483–486conn.executescript( "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, " "definition TEXT, scope TEXT, file_id INTEGER, bodyfile_id INTEGER);" )lines 487–495conn.executemany( "INSERT INTO memberdef VALUES (?, 'function', ?, ?, ?, 1, 1)", [ # The real target: doxygen left the module out of `definition`. (1, "_write_doxyfile_stdin", " None _write_doxyfile_stdin", "clew.doxygen"), # A same-named function in ANOTHER module must not be borrowed. (2, "_write_doxyfile_stdin", " None _write_doxyfile_stdin", "other.module"), ], )lines 496–496conn.commit()lines 498–498assert _resolve_qualified_entry(conn, "clew.doxygen._write_doxyfile_stdin", ".") == 1lines 499–499assert _resolve_qualified_entry(conn, "other.module._write_doxyfile_stdin", ".") == 2lines 502–502assert _resolve_qualified_entry(conn, "third.module._write_doxyfile_stdin", ".") is Nonelines 503–503conn.close()

test_annotate_thread_boundaries_marks_queue_hop_crossing

None test_r1_richness.test_annotate_thread_boundaries_marks_queue_hop_crossing(Path tmp_path)

producer_task spawns thread A (entry producer_entry), consumer_task spawns thread B (entry consumer_entry). A queue hop producer_entry -> consumer_entry crosses the boundary.

tests/test_r1_richness.py:938

Checks

  • assert (writer, reader, mode) == (1, 2, "queued")
  • assert crosses == 1
  • assert to_thread == thread_for_consumer

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → shared_key_harvester → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → _log_undeclared_accessor_hint → detect_undeclared_accessor_families
REQ-DDB-INDEX-002measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest
REQ-DDB-PIPE-004measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-010measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → _build_inferred_edges
REQ-DDB-PIPE-011measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → extract_threads
REQ-DDB-SCHEMA-002measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → _writer_dispatch_map
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-005measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred
REQ-DDB-SCHEMA-007measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → import_shared_key_edges_inferred → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measuredtest_annotate_thread_boundaries_marks_queue_hop_crossing → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 53 lines
def test_annotate_thread_boundaries_marks_queue_hop_crossing(tmp_path: Path) -> None:
    """producer_task spawns thread A (entry producer_entry), consumer_task
    spawns thread B (entry consumer_entry). A queue hop producer_entry ->
    consumer_entry crosses the boundary."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void producer_entry(void) { QUEUESEND(&q, m); }\n"
        "void consumer_entry(void) { QUEUERECEIVE(&q, &m); }\n"
        "void boot(void) {\n"
        "    pthread_create(&t1, 0, producer_entry, 0);\n"
        "    pthread_create(&t2, 0, consumer_entry, 0);\n"
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [
            (1, "producer_entry", 1, 1),
            (2, "consumer_entry", 2, 2),
            (3, "boot", 3, 6),
        ],
        # no inter-entry call edges — each entry is its own closure
        call_edges=[],
    )
    # Build shared_key_edges: producer_entry -> consumer_entry over key q.
    patterns = tmp_path / "patterns.yaml"
    patterns.write_text(
        "writers:\n"
        "  - pattern: QUEUESEND\n"
        "    key_arg_index: 0\n"
        "    dispatch_mode: queued\n"
        "readers:\n"
        "  - pattern: QUEUERECEIVE\n"
        "    key_arg_index: 0\n",
    )
    import_shared_key_edges_inferred(db, tmp_path, patterns)
    extract_threads(db, tmp_path, None)
    annotate_thread_boundaries(db)

    conn = sqlite3.connect(str(db))
    row = conn.execute(
        "SELECT writer_rowid, reader_rowid, dispatch_mode, crosses_thread, "
        "to_thread_id FROM shared_key_edges",
    ).fetchone()
    thread_for_consumer = conn.execute(
        "SELECT id FROM threads WHERE entry_memberdef_rowid = 2",
    ).fetchone()[0]
    conn.close()
    writer, reader, mode, crosses, to_thread = row
    assert (writer, reader, mode) == (1, 2, "queued")
    assert crosses == 1
    # reader (consumer_entry) is unambiguously in its own thread.
    assert to_thread == thread_for_consumer

1 more lines, not shown

Activity · 17 steps
lines 942–942src = tmp_path / "src"lines 943–943src.mkdir()lines 944–951(src / "foo.c").write_text( "void producer_entry(void) { QUEUESEND(&q, m); }\n" "void consumer_entry(void) { QUEUERECEIVE(&q, &m); }\n" "void boot(void) {\n" " pthread_create(&t1, 0, producer_entry, 0);\n" " pthread_create(&t2, 0, consumer_entry, 0);\n" "}\n", )lines 952–961db = _make_db( tmp_path, [ (1, "producer_entry", 1, 1), (2, "consumer_entry", 2, 2), (3, "boot", 3, 6), ], # no inter-entry call edges — each entry is its own closure call_edges=[], )lines 963–963patterns = tmp_path / "patterns.yaml"lines 964–972patterns.write_text( "writers:\n" " - pattern: QUEUESEND\n" " key_arg_index: 0\n" " dispatch_mode: queued\n" "readers:\n" " - pattern: QUEUERECEIVE\n" " key_arg_index: 0\n", )lines 973–973import_shared_key_edges_inferred(db, tmp_path, patterns)lines 974–974extract_threads(db, tmp_path, None)lines 975–975annotate_thread_boundaries(db)lines 977–977conn = sqlite3.connect(str(db))lines 978–981row = conn.execute( "SELECT writer_rowid, reader_rowid, dispatch_mode, crosses_thread, " "to_thread_id FROM shared_key_edges", ).fetchone()lines 982–984thread_for_consumer = conn.execute( "SELECT id FROM threads WHERE entry_memberdef_rowid = 2", ).fetchone()[0]lines 985–985conn.close()lines 986–986writer, reader, mode, crosses, to_thread = rowlines 987–987assert (writer, reader, mode) == (1, 2, "queued")lines 988–988assert crosses == 1lines 990–990assert to_thread == thread_for_consumer

test_boundary_flags_logic

None test_r1_richness.test_boundary_flags_logic()

tests/test_r1_richness.py:926

Show on the map →

Called by none

Calls _boundary_flags

Checks

  • assert _boundary_flags(set(), {1}) == (None, None)
  • assert _boundary_flags({1}, set()) == (None, None)
  • assert _boundary_flags({1}, {1}) == (0, 1)
  • assert _boundary_flags({1}, {2}) == (1, 2)
  • assert _boundary_flags({1}, {2, 3}) == (1, None)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 12 lines
def test_boundary_flags_logic() -> None:
    # Insufficient data → NULL/NULL.
    assert _boundary_flags(set(), {1}) == (None, None)
    assert _boundary_flags({1}, set()) == (None, None)
    # Shared thread → not crossing; reader unambiguous → to_thread set.
    assert _boundary_flags({1}, {1}) == (0, 1)
    # Disjoint → crosses; reader unambiguous.
    assert _boundary_flags({1}, {2}) == (1, 2)
    # Reader ambiguous → crosses, to_thread NULL.
    assert _boundary_flags({1}, {2, 3}) == (1, None)

Activity · 5 steps
lines 928–928assert _boundary_flags(set(), {1}) == (None, None)lines 929–929assert _boundary_flags({1}, set()) == (None, None)lines 931–931assert _boundary_flags({1}, {1}) == (0, 1)lines 933–933assert _boundary_flags({1}, {2}) == (1, 2)lines 935–935assert _boundary_flags({1}, {2, 3}) == (1, None)

test_declared_edge_triggered_and_dispatch_mode_set

None test_r1_richness.test_declared_edge_triggered_and_dispatch_mode_set(Path tmp_path)

A declared key can assert dispatch_mode + edge_triggered.

tests/test_r1_richness.py:826

Checks

  • assert row == ("inline", 1)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_declared_edge_triggered_and_dispatch_mode_set → import_shared_key_edges_declared → _definition_preferring_name_index
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002measuredtest_declared_edge_triggered_and_dispatch_mode_set → import_shared_key_edges_declared → _load_declared_keys → _parse_data_model_toml → _declared_keys_from_doc → _coerce_edge_triggered
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-005measuredtest_declared_edge_triggered_and_dispatch_mode_set → import_shared_key_edges_declared
REQ-DDB-SCHEMA-007measuredtest_declared_edge_triggered_and_dispatch_mode_set → import_shared_key_edges_declared → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measured
Source · 21 lines
def test_declared_edge_triggered_and_dispatch_mode_set(tmp_path: Path) -> None:
    """A declared key can assert dispatch_mode + edge_triggered."""
    db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])
    manifest = tmp_path / "dm.toml"
    manifest.write_text(
        '[[keys]]\nname = "K"\nevent = true\n'
        'dispatch_mode = "inline"\nedge_triggered = true\n'
        'writers = ["w"]\nreaders = ["r"]\n',
    )
    import_shared_key_edges_declared(db, manifest)
    conn = sqlite3.connect(str(db))
    row = conn.execute(
        "SELECT dispatch_mode, edge_triggered FROM shared_key_edges",
    ).fetchone()
    conn.close()
    assert row == ("inline", 1)


# ─── keyed dispatch (MQTT) ───────────────────────────────────────────────────

Activity · 8 steps
lines 828–828db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])lines 829–829manifest = tmp_path / "dm.toml"lines 830–834manifest.write_text( '[[keys]]\nname = "K"\nevent = true\n' 'dispatch_mode = "inline"\nedge_triggered = true\n' 'writers = ["w"]\nreaders = ["r"]\n', )lines 835–835import_shared_key_edges_declared(db, manifest)lines 836–836conn = sqlite3.connect(str(db))lines 837–839row = conn.execute( "SELECT dispatch_mode, edge_triggered FROM shared_key_edges", ).fetchone()lines 840–840conn.close()lines 841–841assert row == ("inline", 1)

test_declared_edge_triggered_null_without_manifest_field

None test_r1_richness.test_declared_edge_triggered_null_without_manifest_field(Path tmp_path)

A declared key that omits edge_triggered leaves the column NULL.

tests/test_r1_richness.py:810

Checks

  • assert row == ("unknown", None)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_declared_edge_triggered_null_without_manifest_field → import_shared_key_edges_declared → _definition_preferring_name_index
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002measuredtest_declared_edge_triggered_null_without_manifest_field → import_shared_key_edges_declared → _load_declared_keys → _parse_data_model_toml → _declared_keys_from_doc → _coerce_edge_triggered
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-005measuredtest_declared_edge_triggered_null_without_manifest_field → import_shared_key_edges_declared
REQ-DDB-SCHEMA-007measuredtest_declared_edge_triggered_null_without_manifest_field → import_shared_key_edges_declared → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measured
Source · 16 lines
def test_declared_edge_triggered_null_without_manifest_field(tmp_path: Path) -> None:
    """A declared key that omits edge_triggered leaves the column NULL."""
    db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])
    manifest = tmp_path / "dm.toml"
    manifest.write_text(
        '[[keys]]\nname = "K"\nevent = true\nwriters = ["w"]\nreaders = ["r"]\n',
    )
    import_shared_key_edges_declared(db, manifest)
    conn = sqlite3.connect(str(db))
    row = conn.execute(
        "SELECT dispatch_mode, edge_triggered FROM shared_key_edges",
    ).fetchone()
    conn.close()
    assert row == ("unknown", None)

Activity · 8 steps
lines 812–812db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])lines 813–813manifest = tmp_path / "dm.toml"lines 814–816manifest.write_text( '[[keys]]\nname = "K"\nevent = true\nwriters = ["w"]\nreaders = ["r"]\n', )lines 817–817import_shared_key_edges_declared(db, manifest)lines 818–818conn = sqlite3.connect(str(db))lines 819–821row = conn.execute( "SELECT dispatch_mode, edge_triggered FROM shared_key_edges", ).fetchone()lines 822–822conn.close()lines 823–823assert row == ("unknown", None)

test_declared_manifest_invalid_dispatch_mode_fails_closed

None test_r1_richness.test_declared_manifest_invalid_dispatch_mode_fails_closed(Path tmp_path)

The data-model MANIFEST path fails closed IDENTICALLY to the accessor path.

tests/test_r1_richness.py:757

Checks

  • assert "model.yaml" in message
  • assert "'asynchronous'" in message
  • assert "inline, queued, keyed, unknown" in message

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003inferredtest_declared_manifest_invalid_dispatch_mode_fails_closed → import_shared_key_edges_declared → _definition_preferring_name_index
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalogtest_declared_manifest_invalid_dispatch_mode_fails_closed → import_shared_key_edges_declared → _load_declared_keys → _parse_data_model_toml → _declared_keys_from_doc → _coerce_edge_triggered
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-005measuredtest_declared_manifest_invalid_dispatch_mode_fails_closed → import_shared_key_edges_declared
REQ-DDB-SCHEMA-007catalogtest_declared_manifest_invalid_dispatch_mode_fails_closed → import_shared_key_edges_declared → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measured
Source · 26 lines
def test_declared_manifest_invalid_dispatch_mode_fails_closed(tmp_path: Path) -> None:
    """The data-model MANIFEST path fails closed IDENTICALLY to the accessor path.

    Before, only the accessor path validated: `_declared_keys_from_doc` read
    dispatch_mode raw and carried it to the INSERT, where the same typo surfaced
    as a bare IntegrityError with no mention of the manifest, key or token. Two
    entry points, two behaviours, for one config mistake — and via `.clew.yaml`
    `data_model:` this one is reachable through the MCP server with no CLI flag.
    """
    db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])
    manifest = tmp_path / "model.yaml"
    manifest.write_text(
        "keys:\n"
        "  - name: K\n"
        "    dispatch_mode: asynchronous\n"  # INVALID
        "    writers: [w]\n"
        "    readers: [r]\n",
    )
    with pytest.raises(DeclarationError) as exc:
        import_shared_key_edges_declared(db, manifest)
    message = str(exc.value)
    assert "model.yaml" in message
    assert "'asynchronous'" in message
    assert "inline, queued, keyed, unknown" in message

Activity · 9 steps
lines 766–766db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])lines 767–767manifest = tmp_path / "model.yaml"lines 768–774manifest.write_text( "keys:\n" " - name: K\n" " dispatch_mode: asynchronous\n" # INVALID " writers: [w]\n" " readers: [r]\n", )lines 775–775with pytest.raises(DeclarationError) as exclines 776–776import_shared_key_edges_declared(db, manifest)lines 777–777message = str(exc.value)lines 778–778assert "model.yaml" in messagelines 779–779assert "'asynchronous'" in messagelines 780–780assert "inline, queued, keyed, unknown" in message

test_default_spawn_patterns_cover_primitives

None test_r1_richness.test_default_spawn_patterns_cover_primitives()

tests/test_r1_richness.py:123

Show on the map →

Called by none

Calls none

Checks

  • assert {"pthread_create", "xTaskCreate", "osThreadNew"} <= names
  • assert pthread.entry_arg_index == 2
  • assert pthread.name_arg_index is None
  • assert pthread.kind == "pthread"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 9 lines
def test_default_spawn_patterns_cover_primitives() -> None:
    names = {p.name for p in DEFAULT_SPAWN_PATTERNS}
    assert {"pthread_create", "xTaskCreate", "osThreadNew"} <= names
    pthread = next(p for p in DEFAULT_SPAWN_PATTERNS if p.name == "pthread_create")
    assert pthread.entry_arg_index == 2
    assert pthread.name_arg_index is None
    assert pthread.kind == "pthread"

Activity · 6 steps
lines 124–124names = {p.name for p in DEFAULT_SPAWN_PATTERNS}lines 125–125assert {"pthread_create", "xTaskCreate", "osThreadNew"} <= nameslines 126–126pthread = next(p for p in DEFAULT_SPAWN_PATTERNS if p.name == "pthread_create")lines 127–127assert pthread.entry_arg_index == 2lines 128–128assert pthread.name_arg_index is Nonelines 129–129assert pthread.kind == "pthread"

test_default_spawn_patterns_cover_std_thread

None test_r1_richness.test_default_spawn_patterns_cover_std_thread()

std::thread/std::jthread are C++ language primitives → shipped defaults, entry at arg 0, no name literal.

tests/test_r1_richness.py:209

Show on the map →

Called by none

Calls none

Checks

  • assert name in by_name, f"{name} missing from defaults"
  • assert by_name[name].entry_arg_index == 0
  • assert by_name[name].name_arg_index is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 10 lines
def test_default_spawn_patterns_cover_std_thread() -> None:
    """std::thread/std::jthread are C++ language primitives → shipped defaults,
    entry at arg 0, no name literal."""
    by_name = {p.name: p for p in DEFAULT_SPAWN_PATTERNS}
    for name in ("std::thread", "std::jthread"):
        assert name in by_name, f"{name} missing from defaults"
        assert by_name[name].entry_arg_index == 0
        assert by_name[name].name_arg_index is None

Activity · 5 steps
lines 212–212by_name = {p.name: p for p in DEFAULT_SPAWN_PATTERNS}lines 213–213◇ for name in ("std::thread", "std::jthread")lines 214–214assert name in by_name, f"{name} missing from defaults"lines 215–215assert by_name[name].entry_arg_index == 0lines 216–216assert by_name[name].name_arg_index is None

test_external_boundaries_table_always_created

None test_r1_richness.test_external_boundaries_table_always_created(Path tmp_path)

Even with no registrations at all, the terminus table exists (empty).

tests/test_r1_richness.py:671

Checks

  • assert has is not None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_external_boundaries_table_always_created → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_external_boundaries_table_always_created → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_external_boundaries_table_always_created → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_external_boundaries_table_always_created → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003measuredtest_external_boundaries_table_always_created → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_external_boundaries_table_always_created → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_external_boundaries_table_always_created → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 18 lines
def test_external_boundaries_table_always_created(tmp_path: Path) -> None:
    """Even with no registrations at all, the terminus table exists (empty)."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text("void plain(void) {}\n")
    db = _make_db(tmp_path, [(1, "plain", 1, 1)], call_edges=[])
    import_callback_registration_edges(db, tmp_path)
    conn = sqlite3.connect(str(db))
    has = conn.execute(
        "SELECT 1 FROM sqlite_master WHERE type='table' AND name='external_boundaries'",
    ).fetchone()
    conn.close()
    assert has is not None


# ─── dispatch_mode (inferred) ────────────────────────────────────────────────

Activity · 9 steps
lines 673–673src = tmp_path / "src"lines 674–674src.mkdir()lines 675–675(src / "foo.c").write_text("void plain(void) {}\n")lines 676–676db = _make_db(tmp_path, [(1, "plain", 1, 1)], call_edges=[])lines 677–677import_callback_registration_edges(db, tmp_path)lines 678–678conn = sqlite3.connect(str(db))lines 679–681has = conn.execute( "SELECT 1 FROM sqlite_master WHERE type='table' AND name='external_boundaries'", ).fetchone()lines 682–682conn.close()lines 683–683assert has is not None

test_external_boundary_records_forwarded_dead_end

None test_r1_richness.test_external_boundary_records_forwarded_dead_end(Path tmp_path)

`my_cb = eventCb;` inside register_cb(param eventCb); the only in-repo caller forwards its OWN param out of repo → the callback dead-ends externally and my_cb is invoked in-repo → a terminus row (with the registering fn + param index), NOT a dropped edge.

tests/test_r1_richness.py:600

Checks

  • assert rows == [(2, "my_cb", "unresolved_callback", 1, 1, "high")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_external_boundary_records_forwarded_dead_end → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_external_boundary_records_forwarded_dead_end → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_external_boundary_records_forwarded_dead_end → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_external_boundary_records_forwarded_dead_end → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003measuredtest_external_boundary_records_forwarded_dead_end → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_external_boundary_records_forwarded_dead_end → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_external_boundary_records_forwarded_dead_end → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 42 lines
def test_external_boundary_records_forwarded_dead_end(tmp_path: Path) -> None:
    """`my_cb = eventCb;` inside register_cb(param eventCb); the only in-repo
    caller forwards its OWN param out of repo → the callback dead-ends
    externally and my_cb is invoked in-repo → a terminus row (with the
    registering fn + param index), NOT a dropped edge."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "static Cb_t my_cb = 0;\n"
        "void register_cb(int x, Cb_t eventCb) {\n"
        "    (void)x;\n"
        "    my_cb = eventCb;\n"
        "}\n"
        "void invoke_cb(int e) {\n"
        "    my_cb(e);\n"
        "}\n"
        "void app_layer(Cb_t appCb) {\n"
        "    register_cb(0, appCb);\n"
        "}\n",
    )
    # No in-repo caller ever supplies a concrete fn to app_layer(appCb) →
    # forwarding chain bottoms out externally.
    db = _make_db(
        tmp_path,
        [
            (1, "register_cb", 2, 5),
            (2, "invoke_cb", 6, 8),
            (3, "app_layer", 9, 11),
        ],
        call_edges=[],
    )
    import_callback_registration_edges(db, tmp_path)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT memberdef_rowid, global_name, kind, registered_by_rowid, "
        "registered_param_index, confidence FROM external_boundaries",
    ).fetchall()
    conn.close()
    # invoke_cb(2) invokes my_cb; registered by register_cb(1) at param index 1.
    assert rows == [(2, "my_cb", "unresolved_callback", 1, 1, "high")]

Activity · 9 steps
lines 605–605src = tmp_path / "src"lines 606–606src.mkdir()lines 607–619(src / "foo.c").write_text( "static Cb_t my_cb = 0;\n" "void register_cb(int x, Cb_t eventCb) {\n" " (void)x;\n" " my_cb = eventCb;\n" "}\n" "void invoke_cb(int e) {\n" " my_cb(e);\n" "}\n" "void app_layer(Cb_t appCb) {\n" " register_cb(0, appCb);\n" "}\n", )lines 622–630db = _make_db( tmp_path, [ (1, "register_cb", 2, 5), (2, "invoke_cb", 6, 8), (3, "app_layer", 9, 11), ], call_edges=[], )lines 631–631import_callback_registration_edges(db, tmp_path)lines 632–632conn = sqlite3.connect(str(db))lines 633–636rows = conn.execute( "SELECT memberdef_rowid, global_name, kind, registered_by_rowid, " "registered_param_index, confidence FROM external_boundaries", ).fetchall()lines 637–637conn.close()lines 639–639assert rows == [(2, "my_cb", "unresolved_callback", 1, 1, "high")]

test_external_boundary_skips_null_only_registration

None test_r1_richness.test_external_boundary_skips_null_only_registration(Path tmp_path)

A registration whose only call site passes NULL (no forwarded param) must NOT be recorded as a terminus.

tests/test_r1_richness.py:642

Checks

  • assert count == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-004inferredtest_external_boundary_skips_null_only_registration → import_callback_registration_edges → _log_branch_verdicts → _binding_branch → _guard_holds → evaluate_condition
REQ-DDB-PIPE-003measuredtest_external_boundary_skips_null_only_registration → import_callback_registration_edges
REQ-DDB-PIPE-011measuredtest_external_boundary_skips_null_only_registration → import_callback_registration_edges → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_external_boundary_skips_null_only_registration → import_callback_registration_edges → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003measuredtest_external_boundary_skips_null_only_registration → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_external_boundary_skips_null_only_registration → import_callback_registration_edges → _ensure_external_boundaries_table
REQ-DDB-SCHEMA-012measured
REQ-DDB-WIKI-054inferredtest_external_boundary_skips_null_only_registration → import_callback_registration_edges → _emit_resolved_edges → _ast_record_call_edge → _narrow_by_receiver → _one_class → all
Source · 29 lines
def test_external_boundary_skips_null_only_registration(tmp_path: Path) -> None:
    """A registration whose only call site passes NULL (no forwarded param)
    must NOT be recorded as a terminus."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "static Cb_t my_cb = 0;\n"
        "void register_cb(Cb_t eventCb) {\n"
        "    my_cb = eventCb;\n"
        "}\n"
        "void invoke_cb(int e) { my_cb(e); }\n"
        "void boot(void) { register_cb(0); }\n",
    )
    db = _make_db(
        tmp_path,
        [
            (1, "register_cb", 2, 4),
            (2, "invoke_cb", 5, 5),
            (3, "boot", 6, 6),
        ],
        call_edges=[],
    )
    import_callback_registration_edges(db, tmp_path)
    conn = sqlite3.connect(str(db))
    count = conn.execute("SELECT COUNT(*) FROM external_boundaries").fetchone()[0]
    conn.close()
    assert count == 0

Activity · 9 steps
lines 645–645src = tmp_path / "src"lines 646–646src.mkdir()lines 647–654(src / "foo.c").write_text( "static Cb_t my_cb = 0;\n" "void register_cb(Cb_t eventCb) {\n" " my_cb = eventCb;\n" "}\n" "void invoke_cb(int e) { my_cb(e); }\n" "void boot(void) { register_cb(0); }\n", )lines 655–663db = _make_db( tmp_path, [ (1, "register_cb", 2, 4), (2, "invoke_cb", 5, 5), (3, "boot", 6, 6), ], call_edges=[], )lines 664–664import_callback_registration_edges(db, tmp_path)lines 665–665conn = sqlite3.connect(str(db))lines 666–666count = conn.execute("SELECT COUNT(*) FROM external_boundaries").fetchone()[0]lines 667–667conn.close()lines 668–668assert count == 0

test_extract_threads_always_creates_empty_tables

None test_r1_richness.test_extract_threads_always_creates_empty_tables(Path tmp_path)

No spawn sites → threads/thread_membership still exist (empty).

tests/test_r1_richness.py:533

Checks

  • assert {"threads", "thread_membership"} <= tables
  • assert thread_count == 0

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_extract_threads_always_creates_empty_tables → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_always_creates_empty_tables → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004inferredtest_extract_threads_always_creates_empty_tables → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_always_creates_empty_tables → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_always_creates_empty_tables → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_always_creates_empty_tables → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_always_creates_empty_tables → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_always_creates_empty_tables → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_always_creates_empty_tables → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_always_creates_empty_tables → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 23 lines
def test_extract_threads_always_creates_empty_tables(tmp_path: Path) -> None:
    """No spawn sites → threads/thread_membership still exist (empty)."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text("void plain(void) {}\n")
    db = _make_db(tmp_path, [(1, "plain", 1, 1)], call_edges=[])
    extract_threads(db, tmp_path, None)
    conn = sqlite3.connect(str(db))
    tables = {
        r[0]
        for r in conn.execute(
            "SELECT name FROM sqlite_master WHERE type='table'",
        ).fetchall()
    }
    thread_count = conn.execute("SELECT COUNT(*) FROM threads").fetchone()[0]
    conn.close()
    assert {"threads", "thread_membership"} <= tables
    assert thread_count == 0


# ─── threads: membership closure ─────────────────────────────────────────────

Activity · 11 steps
lines 535–535src = tmp_path / "src"lines 536–536src.mkdir()lines 537–537(src / "foo.c").write_text("void plain(void) {}\n")lines 538–538db = _make_db(tmp_path, [(1, "plain", 1, 1)], call_edges=[])lines 539–539extract_threads(db, tmp_path, None)lines 540–540conn = sqlite3.connect(str(db))lines 541–546tables = { r[0] for r in conn.execute( "SELECT name FROM sqlite_master WHERE type='table'", ).fetchall() }lines 547–547thread_count = conn.execute("SELECT COUNT(*) FROM threads").fetchone()[0]lines 548–548conn.close()lines 549–549assert {"threads", "thread_membership"} <= tableslines 550–550assert thread_count == 0

test_extract_threads_pthread_uses_entry_name

None test_r1_richness.test_extract_threads_pthread_uses_entry_name(Path tmp_path)

pthread_create carries no name literal — the thread name is the entry function's own identifier, entry arg at index 2.

tests/test_r1_richness.py:151

Checks

  • assert rows == [("worker_entry", 1, "pthread", "ast_spawn", "medium")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_extract_threads_pthread_uses_entry_name → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_pthread_uses_entry_name → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_extract_threads_pthread_uses_entry_name → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_pthread_uses_entry_name → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_pthread_uses_entry_name → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_pthread_uses_entry_name → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_pthread_uses_entry_name → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_pthread_uses_entry_name → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_pthread_uses_entry_name → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_pthread_uses_entry_name → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 25 lines
def test_extract_threads_pthread_uses_entry_name(tmp_path: Path) -> None:
    """pthread_create carries no name literal — the thread name is the entry
    function's own identifier, entry arg at index 2."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void worker_entry(void *a) { (void)a; }\n"
        "void boot(void) {\n"
        "    pthread_create(&tid, 0, worker_entry, 0);\n"
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [(1, "worker_entry", 1, 1), (2, "boot", 2, 4)],
        call_edges=[],
    )
    extract_threads(db, tmp_path, None)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT name, entry_memberdef_rowid, kind, source, confidence FROM threads",
    ).fetchall()
    conn.close()
    assert rows == [("worker_entry", 1, "pthread", "ast_spawn", "medium")]

Activity · 9 steps
lines 154–154src = tmp_path / "src"lines 155–155src.mkdir()lines 156–161(src / "foo.c").write_text( "void worker_entry(void *a) { (void)a; }\n" "void boot(void) {\n" " pthread_create(&tid, 0, worker_entry, 0);\n" "}\n", )lines 162–166db = _make_db( tmp_path, [(1, "worker_entry", 1, 1), (2, "boot", 2, 4)], call_edges=[], )lines 167–167extract_threads(db, tmp_path, None)lines 168–168conn = sqlite3.connect(str(db))lines 169–171rows = conn.execute( "SELECT name, entry_memberdef_rowid, kind, source, confidence FROM threads", ).fetchall()lines 172–172conn.close()lines 173–173assert rows == [("worker_entry", 1, "pthread", "ast_spawn", "medium")]

test_extract_threads_records_the_spawn_site_from_the_real_harvest

None test_r1_richness.test_extract_threads_records_the_spawn_site_from_the_real_harvest(Path tmp_path)

gh#346's PIPELINE HALF, and the reason it needs its own test at this tier: every query-side test of the split builds the `threads` rows by hand, so all of them would pass with the harvest completely unwired. That is this repo's own recorded failure — a fixture matching the detector rather than the world.

tests/test_r1_richness.py:244

Checks

  • assert rows == [("worker_fn", 3, "src/foo.cpp")], ("the spawn CALL is on line 3; worker_fn is DEFINED on line 1, and recording the " "definition's line would answer where the thread runs rather than where it is created" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_records_the_spawn_site_from_the_real_harvest → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 43 lines
def test_extract_threads_records_the_spawn_site_from_the_real_harvest(tmp_path: Path) -> None:
    """gh#346's PIPELINE HALF, and the reason it needs its own test at this tier: every query-side
    test of the split builds the `threads` rows by hand, so all of them would pass with the
    harvest completely unwired. That is this repo's own recorded failure — a fixture matching the
    detector rather than the world.

    THE PATH ROWID IS THE PART THAT COULD SILENTLY GO MISSING. `run_harvest` always yielded it
    and `_harvest_all_spawn_sites` always discarded it, so the spawning file was computed on every
    build and thrown away. The per-file AST walk CANNOT supply it — it is handed only a tree and
    its bytes — so if the flattener stops passing it through, the line still lands and the file
    goes NULL. Both are asserted.

    The line is the SPAWN CALL's, not the entry function's: `worker_fn` is defined on line 1 and
    spawned on line 3, so a test asserting only "some line" would not tell the two apart."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.cpp").write_text(
        "void worker_fn(int a) { (void)a; }\n"
        "void boot() {\n"
        "    auto t = std::thread(worker_fn, 0);\n"
        "    (void)t;\n"
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [(1, "worker_fn", 1, 1), (2, "boot", 2, 5)],
        rel_path="src/foo.cpp",
        call_edges=[],
    )
    extract_threads(db, tmp_path, None)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT t.name, t.spawn_line, p.name FROM threads t "
        "LEFT JOIN path p ON p.rowid = t.spawn_path_rowid"
    ).fetchall()
    conn.close()

    assert rows == [("worker_fn", 3, "src/foo.cpp")], (
        "the spawn CALL is on line 3; worker_fn is DEFINED on line 1, and recording the "
        "definition's line would answer where the thread runs rather than where it is created"
    )

Activity · 9 steps
lines 258–258src = tmp_path / "src"lines 259–259src.mkdir()lines 260–266(src / "foo.cpp").write_text( "void worker_fn(int a) { (void)a; }\n" "void boot() {\n" " auto t = std::thread(worker_fn, 0);\n" " (void)t;\n" "}\n", )lines 267–272db = _make_db( tmp_path, [(1, "worker_fn", 1, 1), (2, "boot", 2, 5)], rel_path="src/foo.cpp", call_edges=[], )lines 273–273extract_threads(db, tmp_path, None)lines 274–274conn = sqlite3.connect(str(db))lines 275–278rows = conn.execute( "SELECT t.name, t.spawn_line, p.name FROM threads t " "LEFT JOIN path p ON p.rowid = t.spawn_path_rowid" ).fetchall()lines 279–279conn.close()lines 281–284assert rows == [("worker_fn", 3, "src/foo.cpp")], ( "the spawn CALL is on line 3; worker_fn is DEFINED on line 1, and recording the " "definition's line would answer where the thread runs rather than where it is created" )

test_extract_threads_std_thread_free_function

None test_r1_richness.test_extract_threads_std_thread_free_function(Path tmp_path)

std::thread(entry, arg) with a free-function entry: the qualified callee (`std::thread`) matches and the entry resolves at arg 0.

tests/test_r1_richness.py:219

Checks

  • assert rows == [("worker_fn", 1, "pthread")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_extract_threads_std_thread_free_function → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_std_thread_free_function → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_extract_threads_std_thread_free_function → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_std_thread_free_function → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_std_thread_free_function → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_std_thread_free_function → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_std_thread_free_function → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_std_thread_free_function → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_std_thread_free_function → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_std_thread_free_function → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 25 lines
def test_extract_threads_std_thread_free_function(tmp_path: Path) -> None:
    """std::thread(entry, arg) with a free-function entry: the qualified callee
    (`std::thread`) matches and the entry resolves at arg 0."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.cpp").write_text(
        "void worker_fn(int a) { (void)a; }\n"
        "void boot() {\n"
        "    auto t = std::thread(worker_fn, 0);\n"
        "    (void)t;\n"
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [(1, "worker_fn", 1, 1), (2, "boot", 2, 5)],
        rel_path="src/foo.cpp",
        call_edges=[],
    )
    extract_threads(db, tmp_path, None)
    conn = sqlite3.connect(str(db))
    rows = conn.execute("SELECT name, entry_memberdef_rowid, kind FROM threads").fetchall()
    conn.close()
    assert rows == [("worker_fn", 1, "pthread")]

Activity · 9 steps
lines 222–222src = tmp_path / "src"lines 223–223src.mkdir()lines 224–230(src / "foo.cpp").write_text( "void worker_fn(int a) { (void)a; }\n" "void boot() {\n" " auto t = std::thread(worker_fn, 0);\n" " (void)t;\n" "}\n", )lines 231–236db = _make_db( tmp_path, [(1, "worker_fn", 1, 1), (2, "boot", 2, 5)], rel_path="src/foo.cpp", call_edges=[], )lines 237–237extract_threads(db, tmp_path, None)lines 238–238conn = sqlite3.connect(str(db))lines 239–239rows = conn.execute("SELECT name, entry_memberdef_rowid, kind FROM threads").fetchall()lines 240–240conn.close()lines 241–241assert rows == [("worker_fn", 1, "pthread")]

test_extract_threads_std_thread_member_pointer_qualified

None test_r1_richness.test_extract_threads_std_thread_member_pointer_qualified(Path tmp_path)

std::thread(&amp;Class::method, this): the entry is a member-function pointer. The thread is named by its QUALIFIED entry and the rowid resolves against `definition` — so two classes sharing a method name stay distinct.

tests/test_r1_richness.py:360

Checks

  • assert rows == [("Owner::run", 1, "pthread")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_std_thread_member_pointer_qualified → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 49 lines
def test_extract_threads_std_thread_member_pointer_qualified(tmp_path: Path) -> None:
    """std::thread(&Class::method, this): the entry is a member-function
    pointer. The thread is named by its QUALIFIED entry and the rowid resolves
    against `definition` — so two classes sharing a method name stay distinct."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.cpp").write_text(
        "struct Owner { void run(); void start(); };\n"
        "void Owner::run() {}\n"
        "void Owner::start() {\n"
        "    worker_ = std::thread(&Owner::run, this);\n"
        "}\n",
    )
    # Minimal DB WITH a `definition` column so qualified resolution can match.
    db_path = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db_path))
    conn.executescript(
        """
        CREATE TABLE path (name TEXT);
        CREATE TABLE memberdef (
            rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, definition TEXT,
            file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER
        );
        CREATE TABLE call_edges (
            caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, confidence TEXT
        );
        """,
    )
    conn.execute("INSERT INTO path (rowid, name) VALUES (1, 'src/foo.cpp')")
    conn.executemany(
        "INSERT INTO memberdef (rowid, kind, name, definition, file_id, bodyfile_id, "
        "bodystart, bodyend) VALUES (?, 'function', ?, ?, 1, 1, ?, ?)",
        [
            (1, "run", "void Owner::run", 2, 2),
            (2, "start", "void Owner::start", 3, 5),
            # A decoy `run` on another class — the qualified match must NOT pick it.
            (3, "run", "void Other::run", 6, 6),
        ],
    )
    conn.commit()
    conn.close()
    extract_threads(db_path, tmp_path, None)
    conn = sqlite3.connect(str(db_path))
    rows = conn.execute("SELECT name, entry_memberdef_rowid, kind FROM threads").fetchall()
    conn.close()
    # Named by qualified entry; entry resolves to Owner::run (rowid 1), NOT the decoy.
    assert rows == [("Owner::run", 1, "pthread")]

Activity · 15 steps
lines 364–364src = tmp_path / "src"lines 365–365src.mkdir()lines 366–372(src / "foo.cpp").write_text( "struct Owner { void run(); void start(); };\n" "void Owner::run() {}\n" "void Owner::start() {\n" " worker_ = std::thread(&Owner::run, this);\n" "}\n", )lines 374–374db_path = tmp_path / "clew.db"lines 375–375conn = sqlite3.connect(str(db_path))lines 376–387conn.executescript( """ CREATE TABLE path (name TEXT); CREATE TABLE memberdef ( rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, definition TEXT, file_id INTEGER, bodyfile_id INTEGER, bodystart INTEGER, bodyend INTEGER ); CREATE TABLE call_edges ( caller_rowid INTEGER, callee_rowid INTEGER, source TEXT, confidence TEXT ); """, )lines 388–388conn.execute("INSERT INTO path (rowid, name) VALUES (1, 'src/foo.cpp')")lines 389–398conn.executemany( "INSERT INTO memberdef (rowid, kind, name, definition, file_id, bodyfile_id, " "bodystart, bodyend) VALUES (?, 'function', ?, ?, 1, 1, ?, ?)", [ (1, "run", "void Owner::run", 2, 2), (2, "start", "void Owner::start", 3, 5), # A decoy `run` on another class — the qualified match must NOT pick it. (3, "run", "void Other::run", 6, 6), ], )lines 399–399conn.commit()lines 400–400conn.close()lines 401–401extract_threads(db_path, tmp_path, None)lines 402–402conn = sqlite3.connect(str(db_path))lines 403–403rows = conn.execute("SELECT name, entry_memberdef_rowid, kind FROM threads").fetchall()lines 404–404conn.close()lines 406–406assert rows == [("Owner::run", 1, "pthread")]

test_extract_threads_std_thread_multicall_lambda_fail_closed

None test_r1_richness.test_extract_threads_std_thread_multicall_lambda_fail_closed(Path tmp_path)

A lambda body with MORE THAN ONE call is ambiguous (which is the loop?) and must fail closed — no thread attributed to an arbitrary helper.

tests/test_r1_richness.py:311

Checks

  • assert len(rows) == 1, f"the thread exists and must be recorded: {rows}"
  • assert entry is None, (f"an ambiguous lambda body attributed an entry ({entry}) — that is the arbitrary-helper " f"attribution this test exists to refuse" )
  • assert name not in ("setup", "serve"), (f"the row borrowed a helper's name ({name!r}) instead of the assignment target" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004inferredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_std_thread_multicall_lambda_fail_closed → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 49 lines
def test_extract_threads_std_thread_multicall_lambda_fail_closed(tmp_path: Path) -> None:
    """A lambda body with MORE THAN ONE call is ambiguous (which is the loop?)
    and must fail closed — no thread attributed to an arbitrary helper.

    **THE ASSERTION USED TO BE `count == 0` AND THAT OVERREACHED ITS OWN RATIONALE.** Failing
    closed on WHICH FUNCTION the thread runs is right, and this test still enforces it: the row
    below carries `entry_memberdef_rowid IS NULL` and does not borrow `setup` or `serve` as a
    name. Refusing the ROW ENTIRELY is a different claim — it says no thread exists — and that
    was measured wrong: the entropic index held 5 of 9 thread sites, all four missing ones were
    multi-statement lambdas, and the graded answer reported 5 threads and was scored against 9.
    Its own caveat named the cause.

    `insert_threads` has always documented a NULL entry as "thread present, no closure", so the
    row had somewhere to go the whole time. The name comes from the assignment target (`t_`),
    which is also what keeps several such spawns from collapsing into one row under
    UNIQUE(name, entry, kind).

    So the specification narrowed from "no row" to "a row with no entry", on evidence. The
    ambiguity itself is still refused."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.cpp").write_text(
        "void setup() {}\n"
        "void serve() {}\n"
        "void start() {\n"
        "    t_ = std::thread([this] { setup(); serve(); });\n"
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [(1, "setup", 1, 1), (2, "serve", 2, 2), (3, "start", 3, 5)],
        rel_path="src/foo.cpp",
        call_edges=[],
    )
    extract_threads(db, tmp_path, None)
    conn = sqlite3.connect(str(db))
    rows = conn.execute("SELECT name, entry_memberdef_rowid FROM threads").fetchall()
    conn.close()
    assert len(rows) == 1, f"the thread exists and must be recorded: {rows}"
    name, entry = rows[0]
    assert entry is None, (
        f"an ambiguous lambda body attributed an entry ({entry}) — that is the arbitrary-helper "
        f"attribution this test exists to refuse"
    )
    assert name not in ("setup", "serve"), (
        f"the row borrowed a helper's name ({name!r}) instead of the assignment target"
    )

Activity · 12 steps
lines 330–330src = tmp_path / "src"lines 331–331src.mkdir()lines 332–338(src / "foo.cpp").write_text( "void setup() {}\n" "void serve() {}\n" "void start() {\n" " t_ = std::thread([this] { setup(); serve(); });\n" "}\n", )lines 339–344db = _make_db( tmp_path, [(1, "setup", 1, 1), (2, "serve", 2, 2), (3, "start", 3, 5)], rel_path="src/foo.cpp", call_edges=[], )lines 345–345extract_threads(db, tmp_path, None)lines 346–346conn = sqlite3.connect(str(db))lines 347–347rows = conn.execute("SELECT name, entry_memberdef_rowid FROM threads").fetchall()lines 348–348conn.close()lines 349–349assert len(rows) == 1, f"the thread exists and must be recorded: {rows}"lines 350–350name, entry = rows[0]lines 351–354assert entry is None, ( f"an ambiguous lambda body attributed an entry ({entry}) — that is the arbitrary-helper " f"attribution this test exists to refuse" )lines 355–357assert name not in ("setup", "serve"), ( f"the row borrowed a helper's name ({name!r}) instead of the assignment target" )

test_extract_threads_std_thread_single_call_lambda

None test_r1_richness.test_extract_threads_std_thread_single_call_lambda(Path tmp_path)

std::thread([this]{ poll_loop(); }) — the ubiquitous modern-C++ idiom. A lambda body with EXACTLY ONE call resolves to that callee as the entry.

tests/test_r1_richness.py:287

Checks

  • assert rows == [("poll_loop", 1, "pthread")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_extract_threads_std_thread_single_call_lambda → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_std_thread_single_call_lambda → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_std_thread_single_call_lambda → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 24 lines
def test_extract_threads_std_thread_single_call_lambda(tmp_path: Path) -> None:
    """std::thread([this]{ poll_loop(); }) — the ubiquitous modern-C++ idiom.
    A lambda body with EXACTLY ONE call resolves to that callee as the entry."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.cpp").write_text(
        "void poll_loop() {}\n"
        "void start() {\n"
        "    poll_thread_ = std::thread([this] { poll_loop(); });\n"
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [(1, "poll_loop", 1, 1), (2, "start", 2, 4)],
        rel_path="src/foo.cpp",
        call_edges=[],
    )
    extract_threads(db, tmp_path, None)
    conn = sqlite3.connect(str(db))
    rows = conn.execute("SELECT name, entry_memberdef_rowid, kind FROM threads").fetchall()
    conn.close()
    assert rows == [("poll_loop", 1, "pthread")]

Activity · 9 steps
lines 290–290src = tmp_path / "src"lines 291–291src.mkdir()lines 292–297(src / "foo.cpp").write_text( "void poll_loop() {}\n" "void start() {\n" " poll_thread_ = std::thread([this] { poll_loop(); });\n" "}\n", )lines 298–303db = _make_db( tmp_path, [(1, "poll_loop", 1, 1), (2, "start", 2, 4)], rel_path="src/foo.cpp", call_edges=[], )lines 304–304extract_threads(db, tmp_path, None)lines 305–305conn = sqlite3.connect(str(db))lines 306–306rows = conn.execute("SELECT name, entry_memberdef_rowid, kind FROM threads").fetchall()lines 307–307conn.close()lines 308–308assert rows == [("poll_loop", 1, "pthread")]

test_extract_threads_taskcreate_name_literal_and_entry

None test_r1_richness.test_extract_threads_taskcreate_name_literal_and_entry(Path tmp_path)

A declared TASKCREATE wrapper (entry@0, name@1) yields the name string literal + the resolved entry rowid.

tests/test_r1_richness.py:176

Checks

  • assert rows == [("pumpCycle", 1, "task")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_extract_threads_taskcreate_name_literal_and_entry → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 33 lines
def test_extract_threads_taskcreate_name_literal_and_entry(tmp_path: Path) -> None:
    """A declared TASKCREATE wrapper (entry@0, name@1) yields the name string
    literal + the resolved entry rowid."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void pumpCycle(void) {}\n"
        "void app_start(void) {\n"
        '    SYSTEM_TASKCREATE(pumpCycle, "pumpCycle", 4096, 0, 5, &h);\n'
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [(1, "pumpCycle", 1, 1), (2, "app_start", 2, 4)],
        call_edges=[],
    )
    manifest = tmp_path / "spawns.yaml"
    manifest.write_text(
        "spawns:\n"
        "  - name: SYSTEM_TASKCREATE\n"
        "    entry_arg_index: 0\n"
        "    name_arg_index: 1\n"
        "    kind: task\n",
    )
    extract_threads(db, tmp_path, manifest)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT name, entry_memberdef_rowid, kind FROM threads",
    ).fetchall()
    conn.close()
    assert rows == [("pumpCycle", 1, "task")]

Activity · 11 steps
lines 179–179src = tmp_path / "src"lines 180–180src.mkdir()lines 181–186(src / "foo.c").write_text( "void pumpCycle(void) {}\n" "void app_start(void) {\n" ' SYSTEM_TASKCREATE(pumpCycle, "pumpCycle", 4096, 0, 5, &h);\n' "}\n", )lines 187–191db = _make_db( tmp_path, [(1, "pumpCycle", 1, 1), (2, "app_start", 2, 4)], call_edges=[], )lines 192–192manifest = tmp_path / "spawns.yaml"lines 193–199manifest.write_text( "spawns:\n" " - name: SYSTEM_TASKCREATE\n" " entry_arg_index: 0\n" " name_arg_index: 1\n" " kind: task\n", )lines 200–200extract_threads(db, tmp_path, manifest)lines 201–201conn = sqlite3.connect(str(db))lines 202–204rows = conn.execute( "SELECT name, entry_memberdef_rowid, kind FROM threads", ).fetchall()lines 205–205conn.close()lines 206–206assert rows == [("pumpCycle", 1, "task")]

test_inferred_dispatch_mode_defaults_unknown

None test_r1_richness.test_inferred_dispatch_mode_defaults_unknown(Path tmp_path)

A writer pattern with no dispatch_mode defaults to 'unknown'.

tests/test_r1_richness.py:783

Checks

  • assert mode == "unknown"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → shared_key_harvester → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → _log_undeclared_accessor_hint → detect_undeclared_accessor_families
REQ-DDB-INDEX-002measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → shared_key_harvester → _inferred_cache_key → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest
REQ-DDB-PIPE-010measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → _build_inferred_edges
REQ-DDB-PIPE-011measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → _writer_dispatch_map
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-005measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred
REQ-DDB-SCHEMA-007measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measuredtest_inferred_dispatch_mode_defaults_unknown → import_shared_key_edges_inferred → shared_key_harvester → resolve_shared_key_patterns → load_shared_key_patterns → declaration_origin
Source · 27 lines
def test_inferred_dispatch_mode_defaults_unknown(tmp_path: Path) -> None:
    """A writer pattern with no dispatch_mode defaults to 'unknown'."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        'void w(void) { set("K"); }\nvoid r(void) { get("K"); }\n',
    )
    db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])
    patterns = tmp_path / "patterns.yaml"
    patterns.write_text(
        "writers:\n"
        "  - pattern: set\n"
        "    key_arg_index: 0\n"
        "readers:\n"
        "  - pattern: get\n"
        "    key_arg_index: 0\n",
    )
    import_shared_key_edges_inferred(db, tmp_path, patterns)
    conn = sqlite3.connect(str(db))
    mode = conn.execute("SELECT dispatch_mode FROM shared_key_edges").fetchone()[0]
    conn.close()
    assert mode == "unknown"


# ─── edge_triggered (declared) ───────────────────────────────────────────────

Activity · 11 steps
lines 785–785src = tmp_path / "src"lines 786–786src.mkdir()lines 787–789(src / "foo.c").write_text( 'void w(void) { set("K"); }\nvoid r(void) { get("K"); }\n', )lines 790–790db = _make_db(tmp_path, [(1, "w", 1, 1), (2, "r", 2, 2)])lines 791–791patterns = tmp_path / "patterns.yaml"lines 792–799patterns.write_text( "writers:\n" " - pattern: set\n" " key_arg_index: 0\n" "readers:\n" " - pattern: get\n" " key_arg_index: 0\n", )lines 800–800import_shared_key_edges_inferred(db, tmp_path, patterns)lines 801–801conn = sqlite3.connect(str(db))lines 802–802mode = conn.execute("SELECT dispatch_mode FROM shared_key_edges").fetchone()[0]lines 803–803conn.close()lines 804–804assert mode == "unknown"

test_inferred_dispatch_mode_from_writer_pattern

None test_r1_richness.test_inferred_dispatch_mode_from_writer_pattern(Path tmp_path)

A writer pattern declaring dispatch_mode='queued' stamps it on the inferred edge; the reader pattern's mode is irrelevant.

tests/test_r1_richness.py:689

Checks

  • assert rows == [(1, 2, "q", "queued", None)]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → shared_key_harvester → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → _log_undeclared_accessor_hint → detect_undeclared_accessor_families
REQ-DDB-INDEX-002measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → shared_key_harvester → _inferred_cache_key → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest
REQ-DDB-PIPE-010measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → _build_inferred_edges
REQ-DDB-PIPE-011measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → _writer_dispatch_map
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-005measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred
REQ-DDB-SCHEMA-007measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measuredtest_inferred_dispatch_mode_from_writer_pattern → import_shared_key_edges_inferred → shared_key_harvester → resolve_shared_key_patterns → load_shared_key_patterns → declaration_origin
Source · 31 lines
def test_inferred_dispatch_mode_from_writer_pattern(tmp_path: Path) -> None:
    """A writer pattern declaring dispatch_mode='queued' stamps it on the
    inferred edge; the reader pattern's mode is irrelevant."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void producer(void) { QUEUESEND(&q, m); }\n"
        "void consumer(void) { QUEUERECEIVE(&q, &m); }\n",
    )
    db = _make_db(tmp_path, [(1, "producer", 1, 1), (2, "consumer", 2, 2)])
    patterns = tmp_path / "patterns.yaml"
    patterns.write_text(
        "writers:\n"
        "  - pattern: QUEUESEND\n"
        "    key_arg_index: 0\n"
        "    dispatch_mode: queued\n"
        "readers:\n"
        "  - pattern: QUEUERECEIVE\n"
        "    key_arg_index: 0\n",
    )
    import_shared_key_edges_inferred(db, tmp_path, patterns)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT writer_rowid, reader_rowid, key_name, dispatch_mode, "
        "edge_triggered FROM shared_key_edges",
    ).fetchall()
    conn.close()
    # dispatch_mode='queued' from provenance; edge_triggered stays NULL.
    assert rows == [(1, 2, "q", "queued", None)]

Activity · 11 steps
lines 692–692src = tmp_path / "src"lines 693–693src.mkdir()lines 694–697(src / "foo.c").write_text( "void producer(void) { QUEUESEND(&q, m); }\n" "void consumer(void) { QUEUERECEIVE(&q, &m); }\n", )lines 698–698db = _make_db(tmp_path, [(1, "producer", 1, 1), (2, "consumer", 2, 2)])lines 699–699patterns = tmp_path / "patterns.yaml"lines 700–708patterns.write_text( "writers:\n" " - pattern: QUEUESEND\n" " key_arg_index: 0\n" " dispatch_mode: queued\n" "readers:\n" " - pattern: QUEUERECEIVE\n" " key_arg_index: 0\n", )lines 709–709import_shared_key_edges_inferred(db, tmp_path, patterns)lines 710–710conn = sqlite3.connect(str(db))lines 711–714rows = conn.execute( "SELECT writer_rowid, reader_rowid, key_name, dispatch_mode, " "edge_triggered FROM shared_key_edges", ).fetchall()lines 715–715conn.close()lines 717–717assert rows == [(1, 2, "q", "queued", None)]

test_inferred_invalid_dispatch_mode_fails_closed

None test_r1_richness.test_inferred_invalid_dispatch_mode_fails_closed(Path tmp_path)

An invalid declared dispatch_mode REFUSES the build with a DeclarationError naming the file, the token and the allowed set.

tests/test_r1_richness.py:720

Checks

  • assert "patterns.yaml" in message
  • assert "'sync'" in message
  • assert "inline, queued, keyed, unknown" in message

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → shared_key_harvester → resolve_shared_key_patterns
REQ-DDB-CONFIG-007inferredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → _log_undeclared_accessor_hint → detect_undeclared_accessor_families
REQ-DDB-INDEX-002inferredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → shared_key_harvester → _inferred_cache_key → manifest_key → hash_file
REQ-DDB-PIPE-003inferredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest
REQ-DDB-PIPE-010inferredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → _build_inferred_edges
REQ-DDB-PIPE-011inferredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → _walk_all_files_for_shared_keys → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalogtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → _writer_dispatch_map
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-005measuredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred
REQ-DDB-SCHEMA-007catalogtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measuredtest_inferred_invalid_dispatch_mode_fails_closed → import_shared_key_edges_inferred → shared_key_harvester → resolve_shared_key_patterns → load_shared_key_patterns → declaration_origin
Source · 37 lines
def test_inferred_invalid_dispatch_mode_fails_closed(tmp_path: Path) -> None:
    """An invalid declared dispatch_mode REFUSES the build with a DeclarationError
    naming the file, the token and the allowed set.

    This replaces the old normalize-to-'unknown' behaviour. dispatch_mode is the
    synchrony axis a consumer reasons about: relabelling the typo 'sync' as
    'unknown' produces a database that asserts "we could not determine how this
    hand-off happens", which is indistinguishable from a genuinely undetermined
    edge and survives the build with returncode 0. The declared value comes from
    the owner's own manifest, so a load-time refusal naming the file is both the
    loudest and the most fixable signal.
    """
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void producer(void) { QUEUESEND(&q, m); }\n"
        "void consumer(void) { QUEUERECEIVE(&q, &m); }\n",
    )
    db = _make_db(tmp_path, [(1, "producer", 1, 1), (2, "consumer", 2, 2)])
    patterns = tmp_path / "patterns.yaml"
    patterns.write_text(
        "writers:\n"
        "  - pattern: QUEUESEND\n"
        "    key_arg_index: 0\n"
        "    dispatch_mode: sync\n"  # INVALID — not in the CHECK set
        "readers:\n"
        "  - pattern: QUEUERECEIVE\n"
        "    key_arg_index: 0\n",
    )
    with pytest.raises(DeclarationError) as exc:
        import_shared_key_edges_inferred(db, tmp_path, patterns)
    message = str(exc.value)
    assert "patterns.yaml" in message
    assert "'sync'" in message
    assert "inline, queued, keyed, unknown" in message

Activity · 12 steps
lines 732–732src = tmp_path / "src"lines 733–733src.mkdir()lines 734–737(src / "foo.c").write_text( "void producer(void) { QUEUESEND(&q, m); }\n" "void consumer(void) { QUEUERECEIVE(&q, &m); }\n", )lines 738–738db = _make_db(tmp_path, [(1, "producer", 1, 1), (2, "consumer", 2, 2)])lines 739–739patterns = tmp_path / "patterns.yaml"lines 740–748patterns.write_text( "writers:\n" " - pattern: QUEUESEND\n" " key_arg_index: 0\n" " dispatch_mode: sync\n" # INVALID — not in the CHECK set "readers:\n" " - pattern: QUEUERECEIVE\n" " key_arg_index: 0\n", )lines 749–749with pytest.raises(DeclarationError) as exclines 750–750import_shared_key_edges_inferred(db, tmp_path, patterns)lines 751–751message = str(exc.value)lines 752–752assert "patterns.yaml" in messagelines 753–753assert "'sync'" in messagelines 754–754assert "inline, queued, keyed, unknown" in message

test_load_thread_patterns_merges_overrides

None test_r1_richness.test_load_thread_patterns_merges_overrides(Path tmp_path)

tests/test_r1_richness.py:132

Checks

  • assert "pthread_create" in by_name
  • assert tc.entry_arg_index == 0
  • assert tc.name_arg_index == 1
  • assert tc.kind == "task"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001measuredtest_load_thread_patterns_merges_overrides → load_thread_patterns
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
REQ-DDB-SCHEMA-012measuredtest_load_thread_patterns_merges_overrides → load_thread_patterns → declaration_origin
Source · 19 lines
def test_load_thread_patterns_merges_overrides(tmp_path: Path) -> None:
    manifest = tmp_path / "spawns.yaml"
    manifest.write_text(
        "spawns:\n"
        "  - name: SYSTEM_TASKCREATE\n"
        "    entry_arg_index: 0\n"
        "    name_arg_index: 1\n"
        "    kind: task\n",
    )
    patterns = load_thread_patterns(manifest)
    by_name = {p.name: p for p in patterns}
    # Built-in primitives still present + the declared wrapper added.
    assert "pthread_create" in by_name
    tc = by_name["SYSTEM_TASKCREATE"]
    assert tc.entry_arg_index == 0
    assert tc.name_arg_index == 1
    assert tc.kind == "task"

Activity · 9 steps
lines 133–133manifest = tmp_path / "spawns.yaml"lines 134–140manifest.write_text( "spawns:\n" " - name: SYSTEM_TASKCREATE\n" " entry_arg_index: 0\n" " name_arg_index: 1\n" " kind: task\n", )lines 141–141patterns = load_thread_patterns(manifest)lines 142–142by_name = {p.name: p for p in patterns}lines 144–144assert "pthread_create" in by_namelines 145–145tc = by_name["SYSTEM_TASKCREATE"]lines 146–146assert tc.entry_arg_index == 0lines 147–147assert tc.name_arg_index == 1lines 148–148assert tc.kind == "task"

test_mqtt_dispatch_accepts_an_inline_document_not_only_a_path

None test_r1_richness.test_mqtt_dispatch_accepts_an_inline_document_not_only_a_path(Path tmp_path)

@req REQ-DDB-SCHEMA-004 @req REQ-DDB-CONFIG-001

tests/test_r1_richness.py:883

Checks

  • assert rows == [(2, 1, "cmd/req", "event", "keyed", 1, "shared_key_declared")]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001tag
REQ-DDB-INDEX-002inferredtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges → subscribe_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges → subscribe_harvester → manifest_key
REQ-DDB-PIPE-011measuredtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges → _harvest_subscribe_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges → _harvest_subscribe_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges → _definition_preferring_name_index
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004tagtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges
REQ-DDB-SCHEMA-005measuredtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges → subscribe_harvester
REQ-DDB-SCHEMA-007measuredtest_mqtt_dispatch_accepts_an_inline_document_not_only_a_path → import_mqtt_dispatch_edges → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measured
Source · 43 lines
def test_mqtt_dispatch_accepts_an_inline_document_not_only_a_path(tmp_path: Path) -> None:
    """A LIVE DEFECT, not only groundwork for gh#360's inline statement form.
    `cli._declared_or_flag` has always handed the `.clew.yaml` `mqtt_dispatch:`
    SECTION down as a parsed mapping — every sibling loader takes `Path | dict` for exactly
    that reason — while `_load_subscribe_patterns` called `.read_text` on it. So a repository
    declaring that section in its own tree crashed its own build with an `AttributeError`,
    and the suite could not see it because the one test above covers only the flag route.

    Asserted against the SAME expected row as the path test, so the two routes are pinned to
    one another rather than each to its own idea of correct.
    """
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void topic_handler(void) {}\n"
        "void wire_up(void) {\n"
        '    MqttSubscribe(ctx, "cmd/req", topic_handler);\n'
        "}\n",
    )
    db = _make_db(tmp_path, [(1, "topic_handler", 1, 1), (2, "wire_up", 2, 4)])

    import_mqtt_dispatch_edges(
        db,
        tmp_path,
        {
            "subscribe_functions": [
                {"fn_name": "MqttSubscribe", "topic_arg_index": 1, "handler_arg_index": 2}
            ]
        },
    )

    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT writer_rowid, reader_rowid, key_name, edge_kind, dispatch_mode, "
        "declared, source FROM shared_key_edges",
    ).fetchall()
    conn.close()
    assert rows == [(2, 1, "cmd/req", "event", "keyed", 1, "shared_key_declared")]


# ─── thread-boundary annotation ──────────────────────────────────────────────

Activity · 9 steps
lines 894–894src = tmp_path / "src"lines 895–895src.mkdir()lines 896–901(src / "foo.c").write_text( "void topic_handler(void) {}\n" "void wire_up(void) {\n" ' MqttSubscribe(ctx, "cmd/req", topic_handler);\n' "}\n", )lines 902–902db = _make_db(tmp_path, [(1, "topic_handler", 1, 1), (2, "wire_up", 2, 4)])lines 904–912import_mqtt_dispatch_edges( db, tmp_path, { "subscribe_functions": [ {"fn_name": "MqttSubscribe", "topic_arg_index": 1, "handler_arg_index": 2} ] }, )lines 914–914conn = sqlite3.connect(str(db))lines 915–918rows = conn.execute( "SELECT writer_rowid, reader_rowid, key_name, edge_kind, dispatch_mode, " "declared, source FROM shared_key_edges", ).fetchall()lines 919–919conn.close()lines 920–920assert rows == [(2, 1, "cmd/req", "event", "keyed", 1, "shared_key_declared")]

test_mqtt_dispatch_topic_literal_keyed_edge

None test_r1_richness.test_mqtt_dispatch_topic_literal_keyed_edge(Path tmp_path)

@req REQ-DDB-SCHEMA-004

tests/test_r1_richness.py:848

Checks

  • assert rows == [

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges → subscribe_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges → subscribe_harvester → manifest_key
REQ-DDB-PIPE-011measuredtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges → _harvest_subscribe_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges → _harvest_subscribe_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges → _definition_preferring_name_index
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004tagtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges
REQ-DDB-SCHEMA-005measuredtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges → subscribe_harvester
REQ-DDB-SCHEMA-007measuredtest_mqtt_dispatch_topic_literal_keyed_edge → import_mqtt_dispatch_edges → _ensure_shared_key_edges_table
REQ-DDB-SCHEMA-012measured
Source · 33 lines
def test_mqtt_dispatch_topic_literal_keyed_edge(tmp_path: Path) -> None:
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void topic_handler(void) {}\n"
        "void wire_up(void) {\n"
        '    MqttSubscribe(ctx, "cmd/req", topic_handler);\n'
        "}\n",
    )
    db = _make_db(
        tmp_path,
        [(1, "topic_handler", 1, 1), (2, "wire_up", 2, 4)],
    )
    manifest = tmp_path / "mqtt.yaml"
    manifest.write_text(
        "subscribe_functions:\n"
        "  - fn_name: MqttSubscribe\n"
        "    topic_arg_index: 1\n"
        "    handler_arg_index: 2\n",
    )
    import_mqtt_dispatch_edges(db, tmp_path, manifest)
    conn = sqlite3.connect(str(db))
    rows = conn.execute(
        "SELECT writer_rowid, reader_rowid, key_name, edge_kind, dispatch_mode, "
        "declared, source FROM shared_key_edges",
    ).fetchall()
    conn.close()
    # writer = registrar wire_up(2); reader = handler(1); key = topic literal.
    assert rows == [
        (2, 1, "cmd/req", "event", "keyed", 1, "shared_key_declared"),
    ]

Activity · 11 steps
lines 849–849src = tmp_path / "src"lines 850–850src.mkdir()lines 851–856(src / "foo.c").write_text( "void topic_handler(void) {}\n" "void wire_up(void) {\n" ' MqttSubscribe(ctx, "cmd/req", topic_handler);\n' "}\n", )lines 857–860db = _make_db( tmp_path, [(1, "topic_handler", 1, 1), (2, "wire_up", 2, 4)], )lines 861–861manifest = tmp_path / "mqtt.yaml"lines 862–867manifest.write_text( "subscribe_functions:\n" " - fn_name: MqttSubscribe\n" " topic_arg_index: 1\n" " handler_arg_index: 2\n", )lines 868–868import_mqtt_dispatch_edges(db, tmp_path, manifest)lines 869–869conn = sqlite3.connect(str(db))lines 870–873rows = conn.execute( "SELECT writer_rowid, reader_rowid, key_name, edge_kind, dispatch_mode, " "declared, source FROM shared_key_edges", ).fetchall()lines 874–874conn.close()lines 876–878assert rows == [ (2, 1, "cmd/req", "event", "keyed", 1, "shared_key_declared"), ]

test_qualified_at_boundary_rejects_prefix_and_suffix_collisions

None test_r1_richness.test_qualified_at_boundary_rejects_prefix_and_suffix_collisions()

_qualified_at_boundary accepts only real token matches, both sides.

tests/test_r1_richness.py:39

Show on the map →

Called by none

Calls _qualified_at_boundary

Checks

  • assert _qualified_at_boundary(defn, q) is True, (defn, q)
  • assert _qualified_at_boundary(defn, q) is False, (defn, q)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 28 lines
def test_qualified_at_boundary_rejects_prefix_and_suffix_collisions() -> None:
    """Guards the qualified thread-entry resolver against borrowing another
    class's rowid. A match must be delimited on BOTH sides — rejecting a bad
    prefix (`Owner::run` inside `CoOwner::run`) AND a bad suffix (inside a param
    type `Owner::run_t`), while still accepting the real method (even when its
    own def also mentions the qualified name in a param).

    @brief Both-sided boundary check rejects prefix/suffix collisions.
    @version 1
    """
    accept = [
        ("void LinkOwner::rx_loop()", "LinkOwner::rx_loop"),
        ("void Owner::run(Owner::run_t x)", "Owner::run"),  # real method + param mention
        ("auto Owner::run<int>()", "Owner::run"),  # template
        ("void Owner::run", "Owner::run"),  # end-of-string decl
        ("void CoOwner::run(Owner::run x)", "Owner::run"),  # a real Owner::run param exists
    ]
    reject = [
        ("void CoOwner::run()", "Owner::run"),  # prefix collision
        ("void CoOwner::run(Owner::run_t x)", "Owner::run"),  # the fixed bug: suffix in param type
        ("void Owner::running()", "Owner::run"),  # suffix collision
    ]
    for defn, q in accept:
        assert _qualified_at_boundary(defn, q) is True, (defn, q)
    for defn, q in reject:
        assert _qualified_at_boundary(defn, q) is False, (defn, q)

Activity · 6 steps
lines 49–55accept = [ ("void LinkOwner::rx_loop()", "LinkOwner::rx_loop"), ("void Owner::run(Owner::run_t x)", "Owner::run"), # real method + param mention ("auto Owner::run<int>()", "Owner::run"), # template ("void Owner::run", "Owner::run"), # end-of-string decl ("void CoOwner::run(Owner::run x)", "Owner::run"), # a real Owner::run param exists ]lines 56–60reject = [ ("void CoOwner::run()", "Owner::run"), # prefix collision ("void CoOwner::run(Owner::run_t x)", "Owner::run"), # the fixed bug: suffix in param type ("void Owner::running()", "Owner::run"), # suffix collision ]lines 61–61◇ for defn, q in acceptlines 62–62assert _qualified_at_boundary(defn, q) is True, (defn, q)lines 63–63◇ for defn, q in rejectlines 64–64assert _qualified_at_boundary(defn, q) is False, (defn, q)

test_resolve_qualified_entry_rejects_param_type_collision

None test_r1_richness.test_resolve_qualified_entry_rejects_param_type_collision()

The subtle case the boundary helper was hardened against, at the RESOLVER level: a different method whose definition merely mentions the qualified name inside a parameter TYPE (`void ns::CoOwner::run(Owner::run_t x)`) must not lend its rowid to `Owner::run`. The SQL prefilter DOES match it (`CoOwner::run(` contains `Owner::run(`), so `_qualified_at_boundary` is the only guard — this exercises the prefilter+boundary interaction, which the classic-collision test above does not. Would have resolved to rowid 1 before the both-sided fix.

tests/test_r1_richness.py:434

Show on the map →

Called by none

Calls _resolve_qualified_entry

Checks

  • assert _resolve_qualified_entry(conn, "Owner::run") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 25 lines
def test_resolve_qualified_entry_rejects_param_type_collision() -> None:
    """The subtle case the boundary helper was hardened against, at the RESOLVER
    level: a different method whose definition merely mentions the qualified name
    inside a parameter TYPE (`void ns::CoOwner::run(Owner::run_t x)`) must not
    lend its rowid to `Owner::run`. The SQL prefilter DOES match it (`CoOwner::run(`
    contains `Owner::run(`), so `_qualified_at_boundary` is the only guard — this
    exercises the prefilter+boundary interaction, which the classic-collision test
    above does not. Would have resolved to rowid 1 before the both-sided fix.
    """
    from clew.threads import _resolve_qualified_entry

    conn = sqlite3.connect(":memory:")
    conn.executescript(
        "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, "
        "definition TEXT, file_id INTEGER, bodyfile_id INTEGER);",
    )
    conn.execute(
        "INSERT INTO memberdef VALUES "
        "(1, 'function', 'run', 'void ns::CoOwner::run(Owner::run_t x)', 1, 1)"
    )
    conn.commit()
    assert _resolve_qualified_entry(conn, "Owner::run") is None
    conn.close()

Activity · 7 steps
lines 443–443from clew.threads import _resolve_qualified_entrylines 445–445conn = sqlite3.connect(":memory:")lines 446–449conn.executescript( "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, " "definition TEXT, file_id INTEGER, bodyfile_id INTEGER);", )lines 450–453conn.execute( "INSERT INTO memberdef VALUES " "(1, 'function', 'run', 'void ns::CoOwner::run(Owner::run_t x)', 1, 1)" )lines 454–454conn.commit()lines 455–455assert _resolve_qualified_entry(conn, "Owner::run") is Nonelines 456–456conn.close()

test_resolve_qualified_entry_rejects_suffix_collision

None test_r1_richness.test_resolve_qualified_entry_rejects_suffix_collision()

`Owner::run` must NOT resolve to `CoOwner::run` — a bare `%Class::method` LIKE matches any class whose NAME ends with `Class`, so the resolver anchors the match to a token boundary. Guards a silent mis-attribution of a thread's entry (and thus its whole membership closure) to the wrong class.

tests/test_r1_richness.py:409

Show on the map →

Called by none

Calls _resolve_qualified_entry

Checks

  • assert _resolve_qualified_entry(conn, "Owner::run") is None
  • assert _resolve_qualified_entry(conn, "Owner::run") == 2

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 25 lines
def test_resolve_qualified_entry_rejects_suffix_collision() -> None:
    """`Owner::run` must NOT resolve to `CoOwner::run` — a bare `%Class::method`
    LIKE matches any class whose NAME ends with `Class`, so the resolver anchors
    the match to a token boundary. Guards a silent mis-attribution of a thread's
    entry (and thus its whole membership closure) to the wrong class."""
    from clew.threads import _resolve_qualified_entry

    conn = sqlite3.connect(":memory:")
    conn.executescript(
        "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, "
        "definition TEXT, file_id INTEGER, bodyfile_id INTEGER);",
    )
    # Only the suffix-colliding class is indexed; the real Owner::run is not.
    conn.execute(
        "INSERT INTO memberdef VALUES (1, 'function', 'run', 'void ns::CoOwner::run', 1, 1)"
    )
    conn.commit()
    assert _resolve_qualified_entry(conn, "Owner::run") is None
    # Once the real class IS indexed, it resolves — and to the exact class.
    conn.execute("INSERT INTO memberdef VALUES (2, 'function', 'run', 'void ns::Owner::run', 1, 1)")
    conn.commit()
    assert _resolve_qualified_entry(conn, "Owner::run") == 2
    conn.close()

Activity · 10 steps
lines 414–414from clew.threads import _resolve_qualified_entrylines 416–416conn = sqlite3.connect(":memory:")lines 417–420conn.executescript( "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, " "definition TEXT, file_id INTEGER, bodyfile_id INTEGER);", )lines 422–424conn.execute( "INSERT INTO memberdef VALUES (1, 'function', 'run', 'void ns::CoOwner::run', 1, 1)" )lines 425–425conn.commit()lines 426–426assert _resolve_qualified_entry(conn, "Owner::run") is Nonelines 428–428conn.execute("INSERT INTO memberdef VALUES (2, 'function', 'run', 'void ns::Owner::run', 1, 1)")lines 429–429conn.commit()lines 430–430assert _resolve_qualified_entry(conn, "Owner::run") == 2lines 431–431conn.close()

test_the_scope_fallback_does_not_disturb_the_definition_match

None test_r1_richness.test_the_scope_fallback_does_not_disturb_the_definition_match()

THE CONTROL. The fallback must run only when `definition` yielded nothing, or it could overturn a decision the boundary guards already made correctly. Here `definition` names `ns::Owner::run` and a DIFFERENT row carries a scope that would also match — the definition answer has to win.

tests/test_r1_richness.py:506

Show on the map →

Called by none

Calls _resolve_qualified_entry

Checks

  • assert _resolve_qualified_entry(conn, "Owner::run") == 1, ("the definition match is decided by the boundary guards and the fallback must not " "overturn it" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-SCHEMA-001catalog
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007catalog
Source · 27 lines
def test_the_scope_fallback_does_not_disturb_the_definition_match() -> None:
    """THE CONTROL. The fallback must run only when `definition` yielded nothing, or it could
    overturn a decision the boundary guards already made correctly. Here `definition` names
    `ns::Owner::run` and a DIFFERENT row carries a scope that would also match — the
    definition answer has to win."""
    from clew.threads import _resolve_qualified_entry

    conn = sqlite3.connect(":memory:")
    conn.executescript(
        "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, "
        "definition TEXT, scope TEXT, file_id INTEGER, bodyfile_id INTEGER);"
    )
    conn.executemany(
        "INSERT INTO memberdef VALUES (?, 'function', ?, ?, ?, 1, 1)",
        [
            (1, "run", "void ns::Owner::run", ""),
            (2, "run", " None run", "Owner"),
        ],
    )
    conn.commit()
    assert _resolve_qualified_entry(conn, "Owner::run") == 1, (
        "the definition match is decided by the boundary guards and the fallback must not "
        "overturn it"
    )
    conn.close()

Activity · 7 steps
lines 511–511from clew.threads import _resolve_qualified_entrylines 513–513conn = sqlite3.connect(":memory:")lines 514–517conn.executescript( "CREATE TABLE memberdef (rowid INTEGER PRIMARY KEY, kind TEXT, name TEXT, " "definition TEXT, scope TEXT, file_id INTEGER, bodyfile_id INTEGER);" )lines 518–524conn.executemany( "INSERT INTO memberdef VALUES (?, 'function', ?, ?, ?, 1, 1)", [ (1, "run", "void ns::Owner::run", ""), (2, "run", " None run", "Owner"), ], )lines 525–525conn.commit()lines 526–529assert _resolve_qualified_entry(conn, "Owner::run") == 1, ( "the definition match is decided by the boundary guards and the fallback must not " "overturn it" )lines 530–530conn.close()

test_thread_membership_is_call_closure

None test_r1_richness.test_thread_membership_is_call_closure(Path tmp_path)

Membership = forward BFS over non-fuzzy call_edges from the entry. Graph: worker_entry -&gt; step_a -&gt; step_b; unrelated() is NOT reachable.

tests/test_r1_richness.py:556

Checks

  • assert members == {1, 2, 3}
  • assert sources == {"call_closure"}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_thread_membership_is_call_closure → extract_threads → spawn_harvester → manifest_key → hash_file
REQ-DDB-PIPE-003measuredtest_thread_membership_is_call_closure → extract_threads → spawn_harvester → manifest_key
REQ-DDB-PIPE-004measuredtest_thread_membership_is_call_closure → extract_threads → _populate_membership → _bfs_live_set
REQ-DDB-PIPE-011measuredtest_thread_membership_is_call_closure → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _parseable_file
REQ-DDB-PIPE-012inferredtest_thread_membership_is_call_closure → extract_threads → _harvest_all_spawn_sites → run_harvest → _harvest_one_file → _ts_language_for → _grammar_available → has_language
REQ-DDB-QUERY-003measuredtest_thread_membership_is_call_closure → extract_threads → _definition_preferring_name_index
REQ-DDB-QUERY-011measuredtest_thread_membership_is_call_closure → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-001measuredtest_thread_membership_is_call_closure → extract_threads
REQ-DDB-SCHEMA-002catalog
REQ-DDB-SCHEMA-003catalog
REQ-DDB-SCHEMA-004catalog
REQ-DDB-SCHEMA-007measuredtest_thread_membership_is_call_closure → extract_threads → _ensure_threads_tables
REQ-DDB-SCHEMA-012measuredtest_thread_membership_is_call_closure → extract_threads → spawn_harvester → load_thread_patterns → declaration_origin
Source · 44 lines
def test_thread_membership_is_call_closure(tmp_path: Path) -> None:
    """Membership = forward BFS over non-fuzzy call_edges from the entry.
    Graph: worker_entry -> step_a -> step_b; unrelated() is NOT reachable."""
    src = tmp_path / "src"
    src.mkdir()
    (src / "foo.c").write_text(
        "void step_b(void) {}\n"
        "void step_a(void) { step_b(); }\n"
        "void worker_entry(void *a) { (void)a; step_a(); }\n"
        "void unrelated(void) {}\n"
        "void boot(void) { pthread_create(&t, 0, worker_entry, 0); }\n",
    )
    db = _make_db(
        tmp_path,
        [
            (1, "step_b", 1, 1),
            (2, "step_a", 2, 2),
            (3, "worker_entry", 3, 3),
            (4, "unrelated", 4, 4),
            (5, "boot", 5, 5),
        ],
        # worker_entry(3) -> step_a(2) -> step_b(1)
        call_edges=[(3, 2), (2, 1)],
    )
    extract_threads(db, tmp_path, None)
    conn = sqlite3.connect(str(db))
    thread_id = conn.execute("SELECT id FROM threads").fetchone()[0]
    members = {
        r[0]
        for r in conn.execute(
            "SELECT memberdef_rowid FROM thread_membership WHERE thread_id = ?",
            (thread_id,),
        ).fetchall()
    }
    sources = {r[0] for r in conn.execute("SELECT DISTINCT source FROM thread_membership")}
    conn.close()
    # Entry + everything reachable; unrelated(4) and boot(5) excluded.
    assert members == {1, 2, 3}
    assert sources == {"call_closure"}


# ─── external_boundaries: the terminus ───────────────────────────────────────

Activity · 12 steps
lines 559–559src = tmp_path / "src"lines 560–560src.mkdir()lines 561–567(src / "foo.c").write_text( "void step_b(void) {}\n" "void step_a(void) { step_b(); }\n" "void worker_entry(void *a) { (void)a; step_a(); }\n" "void unrelated(void) {}\n" "void boot(void) { pthread_create(&t, 0, worker_entry, 0); }\n", )lines 568–579db = _make_db( tmp_path, [ (1, "step_b", 1, 1), (2, "step_a", 2, 2), (3, "worker_entry", 3, 3), (4, "unrelated", 4, 4), (5, "boot", 5, 5), ], # worker_entry(3) -> step_a(2) -> step_b(1) call_edges=[(3, 2), (2, 1)], )lines 580–580extract_threads(db, tmp_path, None)lines 581–581conn = sqlite3.connect(str(db))lines 582–582thread_id = conn.execute("SELECT id FROM threads").fetchone()[0]lines 583–589members = { r[0] for r in conn.execute( "SELECT memberdef_rowid FROM thread_membership WHERE thread_id = ?", (thread_id,), ).fetchall() }lines 590–590sources = {r[0] for r in conn.execute("SELECT DISTINCT source FROM thread_membership")}lines 591–591conn.close()lines 593–593assert members == {1, 2, 3}lines 594–594assert sources == {"call_closure"}