test_unparsed_file_registration.py

tests/test_unparsed_file_registration.py

A FILE THE INDEX CANNOT PARSE IS STILL A FILE IT CAN NAME (C5, plan step 7).

test_a_documented_file_is_not_displaced_by_a_name_only_match

None test_unparsed_file_registration.test_a_documented_file_is_not_displaced_by_a_name_only_match(Path tmp_path)

Widening the corpus does not displace documented files.

tests/test_unparsed_file_registration.py:246

Checks

  • assert "scripts/generate_errors.pl" in names, names
  • assert "src/errors.c" in names, (f"widening the corpus must not displace a file whose DOCUMENTATION matches: {names}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measuredtest_a_documented_file_is_not_displaced_by_a_name_only_match → register_paths
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
Source · 39 lines
def test_a_documented_file_is_not_displaced_by_a_name_only_match(tmp_path: Path) -> None:
    """THE BOUND ON WIDENING THE CORPUS: the new rows must not push out the ones that already
    carried evidence. Both files must be returned.

    THIS TEST FIRST ASSERTED THE OPPOSITE RANKING AND WAS WRONG. It required a documentation
    match to outrank a bare path match, which contradicts a rule this module states and enforces
    deliberately: `_file_candidates`' own docstring says the path is scored where a symbol's name
    is scored "so a conceptual token in prose stays weaker evidence than the same token in an
    identifier — the property `_search_rank` exists to enforce." A token in a PATH is therefore
    stronger evidence than the same token in prose, by design and by one shared weight table.

    The preference I had written in was invented here rather than taken from that table, so the
    assertion is now on what the widening must not break — presence — and the ordering is left to
    the function that owns it.
    """
    import sqlite3

    from clew.query.symbols import search

    db = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db))
    conn.execute(
        "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, "
        "found INTEGER, name TEXT)"
    )
    conn.execute("CREATE TABLE file_docs (file_path TEXT NOT NULL, doc TEXT NOT NULL)")
    conn.execute(
        "INSERT INTO file_docs VALUES ('src/errors.c', "
        "'Generates the error table. See generate_errors for the generator.')"
    )
    conn.commit()
    conn.close()
    register_paths(db, ["scripts/generate_errors.pl"])

    names = [h.name for h in search(db, "generate_errors", limit=25)]
    assert "scripts/generate_errors.pl" in names, names
    assert "src/errors.c" in names, (
        f"widening the corpus must not displace a file whose DOCUMENTATION matches: {names}"
    )

1 more lines, not shown

Activity · 13 steps
lines 261–261import sqlite3lines 263–263from clew.query.symbols import searchlines 265–265db = tmp_path / "clew.db"lines 266–266conn = sqlite3.connect(str(db))lines 267–270conn.execute( "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, " "found INTEGER, name TEXT)" )lines 271–271conn.execute("CREATE TABLE file_docs (file_path TEXT NOT NULL, doc TEXT NOT NULL)")lines 272–275conn.execute( "INSERT INTO file_docs VALUES ('src/errors.c', " "'Generates the error table. See generate_errors for the generator.')" )lines 276–276conn.commit()lines 277–277conn.close()lines 278–278register_paths(db, ["scripts/generate_errors.pl"])lines 280–280names = [h.name for h in search(db, "generate_errors", limit=25)]lines 281–281assert "scripts/generate_errors.pl" in names, nameslines 282–284assert "src/errors.c" in names, ( f"widening the corpus must not displace a file whose DOCUMENTATION matches: {names}" )

test_a_registered_file_is_findable_in_the_default_corpus

None test_unparsed_file_registration.test_a_registered_file_is_findable_in_the_default_corpus(Path tmp_path)

A file registered by name is findable in the DEFAULT corpus.

tests/test_unparsed_file_registration.py:199

Checks

  • assert "scripts/generate_errors.pl" in names, (f"the default corpus cannot find a file the index holds a path row for: {names}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measuredtest_a_registered_file_is_findable_in_the_default_corpus → register_paths
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
Source · 45 lines
def test_a_registered_file_is_findable_in_the_default_corpus(tmp_path: Path) -> None:
    """REGISTRATION IS NOT REACH, AND THE 1.1.0 TRANSCRIPTS SHOW THE DIFFERENCE. mbedtls Q4's
    `set` mark wants `scripts/generate_errors.pl` as a name in a list. The agent asked for it
    three ways, in this order:

        search("generate_errors")                   <- the DEFAULT corpus, tried FIRST
        search("generate_errors", corpus="files")
        search("generate_errors", corpus="prose")

    Replayed against an index rebuilt with C5 in place, the middle one answers and the other two
    return nothing. So the file is registered, and the corpus a reader reaches for first still
    says there is no such thing.

    THE CAUSE IS NARROW. `symbols._file_candidates` builds its file rows from
    `corpus.file_doc_rows`, which reads `file_docs` — so only a DOCUMENTED file can appear in the
    default corpus. A file the index knows by name and harvested nothing from has no such row by
    construction, which is exactly the class of file C5 exists to make nameable.

    The path is already the searchable unit here: `_search_rank(path, doc, ...)` scores a file's
    PATH where a symbol's name is scored. Only the row's source was too narrow.

    @brief The default corpus matches a registered path with no documentation.
    @return None.
    @version 1
    """
    import sqlite3

    from clew.query.symbols import search

    db = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db))
    conn.execute(
        "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, "
        "found INTEGER, name TEXT)"
    )
    conn.commit()
    conn.close()
    register_paths(db, ["scripts/generate_errors.pl", "src/app.ts"])

    names = [h.name for h in search(db, "generate_errors", limit=25)]
    assert "scripts/generate_errors.pl" in names, (
        f"the default corpus cannot find a file the index holds a path row for: {names}"
    )

Activity · 10 steps
lines 224–224import sqlite3lines 226–226from clew.query.symbols import searchlines 228–228db = tmp_path / "clew.db"lines 229–229conn = sqlite3.connect(str(db))lines 230–233conn.execute( "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, " "found INTEGER, name TEXT)" )lines 234–234conn.commit()lines 235–235conn.close()lines 236–236register_paths(db, ["scripts/generate_errors.pl", "src/app.ts"])lines 238–238names = [h.name for h in search(db, "generate_errors", limit=25)]lines 239–241assert "scripts/generate_errors.pl" in names, ( f"the default corpus cannot find a file the index holds a path row for: {names}" )

test_an_unparsed_file_is_registered_as_known_but_unread

None test_unparsed_file_registration.test_an_unparsed_file_is_registered_as_known_but_unread(Path tmp_path)

A no-grammar file is registered, and says it was not read.

tests/test_unparsed_file_registration.py:92

Checks

  • assert inserted == 2, "both the unparsed file and the claimed TS file must be registered"
  • assert rows["scripts/generate_errors.pl"] == 0, ("a file no grammar reads must report that it was NOT resolved to content; found=1 would " "claim it was parsed" )
  • assert rows["src/app.ts"] == 1, ("C5 must not change what a file the parse front end DOES read reports" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measuredtest_an_unparsed_file_is_registered_as_known_but_unread → register_paths
Source · 34 lines
def test_an_unparsed_file_is_registered_as_known_but_unread(tmp_path: Path) -> None:
    """RED BEFORE THE FIX: `claims()` returns False for `.pl`, so `register_paths` inserts no
    row and the file is not in the file set at all.

    The assertion is on `found = 0` rather than merely on the row existing, because a row with
    `found = 1` claims the file resolved to content — which would make a Perl script
    indistinguishable from a C file clew actually parsed, on the one surface whose job is saying
    what is in here.
    """
    db = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db))
    conn.execute(
        "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, "
        "found INTEGER, name TEXT)"
    )
    conn.commit()
    conn.close()

    inserted = register_paths(db, ["scripts/generate_errors.pl", "src/app.ts"])
    assert inserted == 2, "both the unparsed file and the claimed TS file must be registered"

    conn = sqlite3.connect(str(db))
    rows = dict(conn.execute("SELECT name, found FROM path"))
    conn.close()

    assert rows["scripts/generate_errors.pl"] == 0, (
        "a file no grammar reads must report that it was NOT resolved to content; found=1 would "
        "claim it was parsed"
    )
    assert rows["src/app.ts"] == 1, (
        "C5 must not change what a file the parse front end DOES read reports"
    )

Activity · 12 steps
lines 101–101db = tmp_path / "clew.db"lines 102–102conn = sqlite3.connect(str(db))lines 103–106conn.execute( "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, " "found INTEGER, name TEXT)" )lines 107–107conn.commit()lines 108–108conn.close()lines 110–110inserted = register_paths(db, ["scripts/generate_errors.pl", "src/app.ts"])lines 111–111assert inserted == 2, "both the unparsed file and the claimed TS file must be registered"lines 113–113conn = sqlite3.connect(str(db))lines 114–114rows = dict(conn.execute("SELECT name, found FROM path"))lines 115–115conn.close()lines 117–120assert rows["scripts/generate_errors.pl"] == 0, ( "a file no grammar reads must report that it was NOT resolved to content; found=1 would " "claim it was parsed" )lines 121–123assert rows["src/app.ts"] == 1, ( "C5 must not change what a file the parse front end DOES read reports" )

test_the_registered_file_answers_as_a_file_subject

None test_unparsed_file_registration.test_the_registered_file_answers_as_a_file_subject(Path tmp_path)

The registered file is reachable by name through the file subject.

tests/test_unparsed_file_registration.py:128

Checks

  • assert built is not None, "the mark wants this name findable; a miss is the old answer"
  • assert built.symbol_count == 0
  • assert built.harvested is False, ("`I know of this file and could not read it` is the claim; `harvested=True` would " "say it was read and declares nothing, which is a different and wrong fact" )
  • assert "scripts/generate_errors.pl" in {f.path for f in list_files(db, "*.pl")}, ("the file must also be enumerable, since `search(corpus='files')` is the route a reader " "takes when they do not already know the path" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-012measuredtest_the_registered_file_answers_as_a_file_subject → register_paths
REQ-DDB-QUERY-001measuredtest_the_registered_file_answers_as_a_file_subject → list_files
REQ-DDB-QUERY-003measuredtest_the_registered_file_answers_as_a_file_subject → list_files → table_exists
REQ-DDB-QUERY-004measuredtest_the_registered_file_answers_as_a_file_subject → file_subject
Source · 36 lines
def test_the_registered_file_answers_as_a_file_subject(tmp_path: Path) -> None:
    """THE END THE MARK IS GRADED ON. Registration is the mechanism; being nameable is the
    outcome. C1 made a path a `dossier` subject, so the two changes together turn
    `scripts/generate_errors.pl` from a definitive negative into a reply that names the file and
    states plainly that nothing was harvested from it.
    """
    from clew.query.corpus import file_subject, list_files

    db = tmp_path / "clew.db"
    conn = sqlite3.connect(str(db))
    conn.execute(
        "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, "
        "found INTEGER, name TEXT)"
    )
    conn.commit()
    conn.close()
    register_paths(db, ["scripts/generate_errors.pl"])

    conn = sqlite3.connect(str(db))
    try:
        built = file_subject(conn, "scripts/generate_errors.pl")
        assert built is not None, "the mark wants this name findable; a miss is the old answer"
        assert built.symbol_count == 0
        assert built.harvested is False, (
            "`I know of this file and could not read it` is the claim; `harvested=True` would "
            "say it was read and declares nothing, which is a different and wrong fact"
        )
    finally:
        conn.close()

    assert "scripts/generate_errors.pl" in {f.path for f in list_files(db, "*.pl")}, (
        "the file must also be enumerable, since `search(corpus='files')` is the route a reader "
        "takes when they do not already know the path"
    )

Activity · 14 steps
lines 134–134from clew.query.corpus import file_subject, list_fileslines 136–136db = tmp_path / "clew.db"lines 137–137conn = sqlite3.connect(str(db))lines 138–141conn.execute( "CREATE TABLE path (rowid INTEGER PRIMARY KEY, type INTEGER, local INTEGER, " "found INTEGER, name TEXT)" )lines 142–142conn.commit()lines 143–143conn.close()lines 144–144register_paths(db, ["scripts/generate_errors.pl"])lines 146–146conn = sqlite3.connect(str(db))lines 147–147trylines 148–148built = file_subject(conn, "scripts/generate_errors.pl")lines 149–149assert built is not None, "the mark wants this name findable; a miss is the old answer"lines 150–150assert built.symbol_count == 0lines 151–154assert built.harvested is False, ( "`I know of this file and could not read it` is the claim; `harvested=True` would " "say it was read and declares nothing, which is a different and wrong fact" )lines 158–161assert "scripts/generate_errors.pl" in {f.path for f in list_files(db, "*.pl")}, ( "the file must also be enumerable, since `search(corpus='files')` is the route a reader " "takes when they do not already know the path" )