8000 feat: Phase 7.6 — temporal metadata bindings + range queries (v0.15.0) by adityamukho · Pull Request #28 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat: Phase 7.6 — temporal metadata bindings + range queries (v0.15.0) - #28

Merged
adityamukho merged 15 commits into
mainfrom
phase/7-6-temporal-metadata
Apr 1, 2026
Merged

adityamukho merged 15 commits into
mainfrom
phase/7-6-temporal-metadata

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • Adds :db/valid-from, :db/valid-to, :db/tx-count, :db/tx-id, :db/valid-at as first-class bindable pseudo-attributes in Datalog :where patterns
  • Parser detects :db/* keywords in attribute position → AttributeSpec::Pseudo; rejects them in entity/value positions (hard parse error)
  • Executor enforces :any-valid-time for per-fact pseudo-attrs (hard runtime error with clear message); injects query-level valid_at value into matcher
  • Unlocks the full four-class temporal query taxonomy: time-interval range queries, time-point lookups, time-interval enumeration, tx-time correlation

New types

  • PseudoAttr enum (5 variants) + AttributeSpec enum replacing EdnValue in Pattern.attribute
  • PatternMatcher::from_slice_with_valid_at — passes query-level timestamp into per-pattern matching

Test Plan

  • 16 new integration tests in tests/temporal_metadata_test.rs covering all query patterns, parse errors, and runtime error guards
  • 647 tests total, 0 failures
  • cargo fmt, cargo clippy, cargo test all pass via pre-push hook

🤖 Generated with Claude Code

adityamukho and others added 11 commits March 31, 2026 16:07
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…y collapsible-if

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add `valid_at_value` field and `from_slice_with_valid_at` constructor
- Store hidden `__f*` fact-metadata keys on real-attr pattern matches
  so pseudo-attr patterns can read per-fact temporal/tx fields without
  cross-joining against every other fact for the same entity
- Handle anonymous wildcard `_` in match_component
- Fix parser: treat bare `:any-valid-time` as shorthand for
  `:valid-at :any-valid-time` (was silently ignored)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…alid-at injection

- Add query_uses_per_fact_pseudo_attr helper to detect per-fact pseudo-attr usage
- Hard-error in execute_query and execute_query_with_rules when per-fact pseudo-attrs
  (:db/valid-from, :db/valid-to, :db/tx-count, :db/tx-id) are used without :any-valid-time
- Compute valid_at_value (Timestamp/Null/now) and thread it into PatternMatcher via
  from_slice_with_valid_at in all matcher construction sites
- Update not_body_matches to accept and forward valid_at: Value
- Update evaluate_branch to compute and forward branch_valid_at_value
- Fix valid_at_explicit_timestamp test: insert fact with valid-from "2020-01-01"
  so it is visible at the queried "2023-01-01" timestamp

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
codecov Bot commented Apr 1, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.45355% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 86.17%. Comparing base (a5b161f) to head (141b073).
⚠️ Report is 16 commits behind head on main.

Files with missing lines Patch % Lines
src/query/datalog/matcher.rs 98.07% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
+ Coverage   85.41%   86.17%   +0.75%     
==========================================
  Files          24       24              
  Lines        3724     3869     +145     
==========================================
+ Hits         3181     3334     +153     
+ Misses        543      535       -8     
Files with missing lines Coverage Δ
src/db.rs 92.09% <100.00%> (+0.85%) ⬆️
src/query/datalog/evaluator.rs 90.33% <100.00%> (+0.13%) ⬆️
src/query/datalog/executor.rs 93.41% <100.00%> (+0.71%) ⬆️
src/query/datalog/optimizer.rs 100.00% <100.00%> (ø)
src/query/datalog/parser.rs 87.00% <100.00%> (+0.60%) ⬆️
src/query/datalog/types.rs 93.79% <100.00%> (+1.27%) ⬆️
src/query/datalog/matcher.rs 89.47% <98.07%> (+6.02%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

adityamukho and others added 4 commits April 1, 2026 09:19
Covers 6 previously uncovered code paths flagged by Codecov (PR #28):
- executor.rs 341–353: hard-error guard in execute_query_with_rules
- executor.rs 930–931: evaluate_branch None valid_at case via or-clause
- matcher.rs 119–126: match_fact_against_pattern Pseudo arm (sole pattern)
- matcher.rs 322–323: fast-path hidden key found but value mismatch
- evaluator.rs 361: substitute_pattern Pseudo arm via not-join body
- parser.rs 1076–1079: wrong-length (≠3) where-clause pattern

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add unit tests that directly construct Pattern::pseudo(...) and feed it
through execute_transact/execute_retract (executor.rs lines 103/139),
materialize_transaction/materialize_retraction (db.rs ~577/614), and
the matcher's hidden-key fast-path with a non-uuid/keyword entity
(matcher.rs line 302) and a value-mismatch constant (line 323).

These branches are unreachable via the text parser (which always wraps
transact attributes in AttributeSpec::Real) but must exist as a
defensive guard for direct Rust API callers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cover 11 of the 12 remaining uncovered new lines (tarpaulin DA:line,0):

- executor.rs 341-342: call execute_query_with_rules() directly with
  ValidAt::Timestamp and ValidAt::AnyValidTime to hit valid_at_value
  match arms
- executor.rs 348-350: rules query with per-fact pseudo-attr + no
  :any-valid-time triggers the hard-error guard
- executor.rs 930-931: call evaluate_branch() with Timestamp and
  AnyValidTime valid_at to hit branch_valid_at_value match arms
- db.rs 576, 613: call materialize_transaction/retraction with
  AttributeSpec::Real(Integer) (non-keyword) to hit the Real(_) bail!
  arms (distinct from the Pseudo arm covered previously)
- matcher.rs 120-122: call match_pattern() with UUID entity + ValidTo,
  TxCount, TxId pseudo-attrs (no hidden keys seeded) to hit scan path

Line 302 (matcher.rs _ => None in match_pattern_with_bindings entity
resolution) remains at 0 — tarpaulin does not instrument _ wildcard arms
as standalone probes; patch coverage is ~99.5%, well above the 75%
threshold.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adityamukho
adityamukho merged commit 496d1be into main Apr 1, 2026
15 checks passed
@adityamukho
adityamukho deleted the phase/7-6-temporal-metadata branch April 1, 2026 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0