From d8469613ce989cd13a81101b2e96007cf4dcbab0 Mon Sep 17 00:00:00 2001 From: "russell@unturf.com" Date: Sun, 31 May 2026 11:37:39 -0400 Subject: [PATCH] test_doc_counts: AUTOCOUNT db-where supports *: glob for corpus-wide claims MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The three "92 claim_pack docs" tags were drifting against shard 000.db's 21 rows because the harness only counted one shard, but the doc prose ("#000031 closed at 92") meant the corpus total (21+16+38+17 across genesis shards 000-003). Two-line fix path: extend the harness to sum across all ???.db shards via a `*:` prefix (e.g. `*:documents?source_type=claim_pack`), then prefix the three drifted tags. Aligns the harness scope with the semantic scope of the claim instead of forcing the claim to shrink to one shard. The `*:` glob: - Matches `[0-9][0-9][0-9].db` basenames only (operator sidecars qa.db / snapshots.db / selfmodel-chain.db skipped) - Skips shards lacking the named table (schema-version tolerance) - Returns _DB_MISSING when no genesis shard exists (CI / fresh- checkout skip semantic preserved) - Returns _TABLE_MISSING when no contributing shard has the table Documented in ticket-000044 §3.4 + a third example showing the new syntax. Diagnosis credit to a sub-agent investigation that confirmed zero eviction/falsification audit events on claim_packs — the data is intact; the harness was just single-shard. --- ...igma-recursive-falsification-controller.md | 2 +- ...t-000044-autocount-doc-drift-discipline.md | 13 ++++- docs/warrant-substrate-cookbook.md | 4 +- tests/test_doc_counts.py | 56 ++++++++++++++++++- 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/docs/tickets/ticket-000037-prometheus-sigma-recursive-falsification-controller.md b/docs/tickets/ticket-000037-prometheus-sigma-recursive-falsification-controller.md index ab6b53b..db3a856 100644 --- a/docs/tickets/ticket-000037-prometheus-sigma-recursive-falsification-controller.md +++ b/docs/tickets/ticket-000037-prometheus-sigma-recursive-falsification-controller.md @@ -1030,7 +1030,7 @@ These are the right guardrails for the pure-function layer. ### 17.1 Warrant-promotion integration (#000031) -#000031 closed at 92 +#000031 closed at 92 atomic claim-pack records (started at 78, reached 92 by 2026-05-09 under Phase 2.5). All 92 records now resolve to at least one textbook substrate via the 74 citation-aliases (#000041) + 13 diff --git a/docs/tickets/ticket-000044-autocount-doc-drift-discipline.md b/docs/tickets/ticket-000044-autocount-doc-drift-discipline.md index 54b0278..cd0b9f0 100644 --- a/docs/tickets/ticket-000044-autocount-doc-drift-discipline.md +++ b/docs/tickets/ticket-000044-autocount-doc-drift-discipline.md @@ -115,8 +115,9 @@ query. SQLite connection opens `mode=ro` URI. ### 3.4 `db-where` ```markdown -92 +21 867695 +92 ``` Live value: `SELECT COUNT(*) FROM WHERE = ?` @@ -124,6 +125,16 @@ with `` bound as a SQL parameter (not string-interpolated). Single-column equality predicate only — anything more complex is out of scope for v1 (write a custom assertion test instead). +The `*:` prefix sums across every `???.db` shard (basename glob +`[0-9][0-9][0-9].db`) in `~/.arborist/shards/`. Use this when the +claim is corpus-wide rather than scoped to one shard — e.g. "92 +claim_pack docs across the corpus" (21+16+38+17 across genesis +shards 000-003). Operator sidecar dbs (qa.db, snapshots.db, +selfmodel-chain.db) are skipped. Shards lacking the named table +contribute zero (different schema versions don't fail the assert); +if NO shard has the table, the metric returns `_TABLE_MISSING` +(skipped, like the single-shard case). + --- ## 4. Skip semantics (CI / fresh-checkout safety) diff --git a/docs/warrant-substrate-cookbook.md b/docs/warrant-substrate-cookbook.md index b5fca32..3c5b29d 100644 --- a/docs/warrant-substrate-cookbook.md +++ b/docs/warrant-substrate-cookbook.md @@ -34,7 +34,7 @@ patterns that keep the chains audit-clean. ## Pillar-by-pillar substrate map Eight pillars in the claim-pack source (`#000029`); -92 +92 records total. As of 2026-05-10, every record resolves to at least one substrate in `~/.arborist/crawl/textbook_*.db`. @@ -346,7 +346,7 @@ Full cascade order, tightest → loosest: ## Honest tier breakdown -The 92 chains have three quality tiers: +The 92 chains have three quality tiers: - **Direct primary (~25 records)** — citation matches the literal textbook ingested. Hilbert pillar IV (18), Goldstein → Newton diff --git a/tests/test_doc_counts.py b/tests/test_doc_counts.py index 2fd37e1..681cb94 100644 --- a/tests/test_doc_counts.py +++ b/tests/test_doc_counts.py @@ -173,8 +173,14 @@ def _live_db_where(target: str) -> int: Target syntax:: -
?= - :
?= +
?= # default shard 000.db + :
?= # one named shard + *:
?= # sum across ALL ???.db shards + + The ``*`` form is for claims that span the corpus (e.g. "92 + claim_pack docs" is 21+16+38+17 across genesis shards 000-003). + Globs match basenames ``[0-9][0-9][0-9].db`` only — operator + sidecar dbs (qa.db, snapshots.db) aren't summed. Same sentinel returns as ``_live_db_rows``. ```` is bound as a SQL parameter (no string interpolation), so even author- @@ -195,6 +201,8 @@ def _live_db_where(target: str) -> int: if ":" in head: shard_name, table = head.split(":", 1) + if shard_name == "*": + return _live_db_where_sum_shards(table, column, value) db = _DEFAULT_SHARDS_DIR / shard_name else: db = _DEFAULT_SHARD @@ -225,6 +233,50 @@ def _live_db_where(target: str) -> int: return _DB_ERROR +def _live_db_where_sum_shards(table: str, column: str, value: str) -> int: + """Sum rows matching ``=`` across all genesis shards + (``???.db`` basename pattern) in ``_DEFAULT_SHARDS_DIR``. + + Skips shards where the table is absent (different schema versions); + returns _DB_MISSING when no shard matches the glob at all (operator + state, not source state). Identifier validation matches the single- + shard path. + """ + import sqlite3 + + if not re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", table): + return _DB_ERROR + shards = sorted(_DEFAULT_SHARDS_DIR.glob("[0-9][0-9][0-9].db")) + if not shards: + return _DB_MISSING + total = 0 + saw_any_table = False + for db in shards: + try: + c = sqlite3.connect(f"file:{db}?mode=ro", uri=True) + try: + row = c.execute( + f"SELECT COUNT(*) FROM {table} WHERE {column} = ?", + (value,), + ).fetchone() + if row: + total += int(row[0]) + saw_any_table = True + finally: + c.close() + except sqlite3.OperationalError as exc: + if "no such table" in str(exc).lower(): + continue # shard predates the table — skip, don't fail + if "no such column" in str(exc).lower(): + return _DB_ERROR + return _DB_ERROR + except sqlite3.Error: + return _DB_ERROR + if not saw_any_table: + return _TABLE_MISSING + return total + + def _strip_fenced_code_blocks(text: str) -> str: """Replace contents of triple-backtick fenced code blocks with newlines.