Skip to content

Implement SqlitePoiStore backed by persisted R-tree#40

Merged
leynos merged 12 commits intomainfrom
codex/implement-sqlitepoistore-with-tests-wmesmn
Oct 8, 2025
Merged

Implement SqlitePoiStore backed by persisted R-tree#40
leynos merged 12 commits intomainfrom
codex/implement-sqlitepoistore-with-tests-wmesmn

Conversation

@leynos
Copy link
Copy Markdown
Owner

@leynos leynos commented Oct 4, 2025

Summary

  • add a SqlitePoiStore that loads a versioned R*-tree artefact and hydrates POIs from SQLite for fast bbox queries
  • extend the test-support module and add rstest/rstest-bdd coverage for SQLite-backed PoiStore scenarios
  • document the persisted artefact format and mark the roadmap item as complete

Testing

  • make check-fmt
  • make lint
  • make test

https://chatgpt.com/codex/tasks/task_e_68e0c62490bc8322bf665a428dc97e70

Summary by Sourcery

Implement a SqlitePoiStore that loads a versioned R*-tree spatial index and hydrates POIs from a read-only SQLite database for fast bounding box queries, along with test support, documentation updates, and required dependency additions.

New Features:

  • Add SqlitePoiStore to load a persisted R*-tree index and SQLite metadata for efficient get_pois_in_bbox operations
  • Provide write_index and write_sqlite_database/test_support helpers for serialising spatial indices and generating SQLite fixtures

Enhancements:

  • Extend test-support module with SQLite-backed POI store scenarios and fixtures
  • Export SqlitePoiStore and its error type from the crate root

Build:

  • Enable serde for rstar and add rusqlite, serde_json, bincode, and tempfile dependencies with feature flags

Documentation:

  • Document the persisted spatial index file format and update the engine design and roadmap to mark SqlitePoiStore complete

Tests:

  • Add unit tests covering valid and error cases for SqlitePoiStore
  • Introduce rstest-bdd behavioural tests under tests/features for end-to-end validation

Load a bincode-encoded R*-tree and SQLite dataset to implement PoiStore with consistent error handling. Add fixtures and BDD coverage for the new store and update docs and roadmap to reflect the feature.
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Oct 4, 2025

Reviewer's Guide

Introduce a new SqlitePoiStore that loads a persisted, versioned R*-tree index from disk and hydrates POIs from an SQLite database for efficient bounding-box queries; includes comprehensive error handling, helper functions, extended test support, dependency and export updates, and documentation.

Class diagram for SqlitePoiStore and related types

classDiagram
    class SqlitePoiStore {
        -index: RTree<IndexedPoi>
        -poi_by_id: HashMap<u64, PointOfInterest>
        +open(database_path, index_path): Result<SqlitePoiStore, SqlitePoiStoreError>
        +get_pois_in_bbox(bbox: &Rect<f64>): Iterator<PointOfInterest>
    }
    class IndexedPoi {
        +id: u64
        +location: Coord<f64>
        +from(poi: &PointOfInterest): IndexedPoi
        +envelope(): AABB<[f64; 2]>
    }
    class SqlitePoiStoreError {
        <<enum>>
        OpenDatabase
        IndexIo
        InvalidIndexMagic
        UnsupportedIndexVersion
        IndexDecode
        MissingPoi
        InvalidTags
        Database
    }
    class SpatialIndexWriteError {
        <<enum>>
        Io
        Encode
    }
    SqlitePoiStore --> IndexedPoi : uses
    SqlitePoiStore --> SqlitePoiStoreError : error
    SqlitePoiStore --> PointOfInterest : hydrates
    IndexedPoi --> Coord : location
    SqlitePoiStoreError --> PathBuf
    SqlitePoiStoreError --> rusqlite::Error
    SqlitePoiStoreError --> bincode::Error
    SqlitePoiStoreError --> serde_json::Error
    SpatialIndexWriteError --> PathBuf
    SpatialIndexWriteError --> bincode::Error
    SpatialIndexWriteError --> std::io::Error
Loading

File-Level Changes

Change Details Files
Implement SqlitePoiStore with persisted R*-tree loading and SQLite integration
  • Define IndexedPoi and implement RTreeObject for spatial index entries
  • Add load_index, write_index, and load_pois helpers for index and database I/O
  • Implement SqlitePoiStore.open() to read the index and load POIs into an in-memory map
  • Implement get_pois_in_bbox() to query the RTree then retrieve matching POIs
  • Define SqlitePoiStoreError and SpatialIndexWriteError enums for detailed error cases
wildside-core/src/store.rs
Extend test-support and add SQLite-backed store tests
  • Add write_sqlite_database and write_sqlite_spatial_index helpers
  • Add unit tests in store.rs covering happy and error paths for SqlitePoiStore
  • Add BDD scenarios and Rust fixtures for behavioural testing
  • Include a Gherkin feature file for scenario definitions
wildside-core/src/test_support.rs
wildside-core/src/store.rs
wildside-core/tests/sqlite_poi_store_behaviour.rs
wildside-core/tests/features/sqlite_poi_store.feature
Update documentation and roadmap
  • Document persisted artefact format and runtime model in wildside-engine-design.md
  • Mark the roadmap item for SqlitePoiStore as complete
docs/wildside-engine-design.md
docs/roadmap.md
Update crate exports and dependencies
  • Re-export SqlitePoiStore and its error type in lib.rs
  • Add rusqlite, serde_json, bincode, rstar/serde, and tempfile dependencies
  • Enable serde and optional features for persistence and testing
wildside-core/src/lib.rs
wildside-core/Cargo.toml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 4, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Summary by CodeRabbit

  • New Features

    • Introduces a production-grade, SQLite-backed POI store with a persisted spatial index for fast, reliable bounding-box queries and clear startup validation/errors for inconsistent or unsupported artefacts.
  • Documentation

    • Expanded engine design with artefact formats, runtime flows, error paths, and migration guidance; updated header naming and roadmap to reflect completion.
  • Tests

    • Added comprehensive BDD and behavioural tests covering successful queries, empty results, and failure when the index references missing data.

Walkthrough

Add a production Sqlite‑backed POI store with a persisted R*-tree spatial index, expose new public types and errors, update crate dependencies and default features, add test‑support utilities, introduce BDD/behavioural tests, and update documentation and roadmap to mark the feature complete.

Changes

Cohort / File(s) Summary of Changes
Docs updates
docs/roadmap.md, docs/wildside-engine-design.md
Mark roadmap item complete; document SqlitePoiStore artefacts and binary index format (WSPI header, versioning, bincode payload); describe startup hydration (read SQLite, bulk‑load R*-tree), migration subcommand, and runtime error flows.
Core crate configuration
wildside-core/Cargo.toml
Add rusqlite (bundled); add optional serde_json and bincode; add tempfile dev-dependency; change default features to include serde; enable rstar serde and extend serde feature to include serde-related crates.
Public re‑exports
wildside-core/src/lib.rs
Re‑export PoiStore, SqlitePoiStore, and SqlitePoiStoreError from the store module, expanding the crate's public API surface.
Sqlite store and spatial index
wildside-core/src/store.rs
Add persisted spatial index constants (SPATIAL_INDEX_MAGIC, SPATIAL_INDEX_VERSION); introduce IndexedPoi (serialisable, RTreeObject); implement SqlitePoiStore with open and PoiStore impl; add load_index_entries, write_index, load_pois, ensure_index_pois_exist; add SqlitePoiStoreError and SpatialIndexWriteError; add unit tests covering success and multiple failure cases (corrupt magic, missing POI, invalid tags, unsupported version).
Test support utilities
wildside-core/src/test_support.rs
Add write_sqlite_database and write_sqlite_spatial_index helpers and extend test imports to support SQLite artefact creation.
BDD & behavioural tests
wildside-core/tests/features/sqlite_poi_store.feature, wildside-core/tests/sqlite_poi_store_behaviour.rs
Add feature file and rstest‑bdd behavioural tests covering bbox queries, empty results outside range, index referencing missing POIs, and multi‑POI queries.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Test as Test/Caller
  participant Store as SqlitePoiStore
  participant SQLite as SQLite (read-only)
  participant FS as File System (index file)
  participant RTree as In-memory R*-tree
  participant Cache as In-memory POI Map

  rect rgb(240,248,255)
    note over Test,Store: Open store (startup hydration)
    Test->>Store: open(db_path, index_path)
    Store->>SQLite: Connect (read-only)
    Store->>FS: Read index file (WSPI header, version, payload)
    FS-->>Store: Return entries or error
    Store->>Store: validate magic & version
    Store->>SQLite: SELECT ids for validation and POI rows
    SQLite-->>Store: Rows (id, lon, lat, tags_json) or errors
    Store->>RTree: Bulk-load IndexedPoi entries
    Store->>Cache: Build in-memory POI map
    Store-->>Test: Ok(SqlitePoiStore) or Err(SqlitePoiStoreError)
  end

  rect rgb(245,255,245)
    note over Test,Store: Query path
    Test->>Store: get_pois_in_bbox(bbox)
    Store->>RTree: Query indexed envelopes intersecting bbox
    RTree-->>Store: IndexedPoi[]
    Store->>Cache: Map ids -> PointOfInterest, deduplicate
    Store-->>Test: Vec<PointOfInterest>
  end

  rect rgb(255,245,245)
    note over Store,FS: Error scenarios
    FS-->>Store: Corrupt magic/version -> SqlitePoiStoreError::InvalidMagic/Version
    SQLite-->>Store: Missing POI rows -> SqlitePoiStoreError::MissingPoi(id)
    SQLite-->>Store: JSON parse failure -> SqlitePoiStoreError::TagParse
  end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Poem

A tree of bytes that maps the land,
With lats and lons at each command.
SQLite hums a steady tune,
The index wakes to seek by noon.
Tests dance round the bounding box, 🎯

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 64.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed Recognise that the title succinctly conveys the main change by naming the implementation of SqlitePoiStore backed by a persisted R-tree without extraneous detail.
Description Check ✅ Passed Affirm that the description directly relates to the changeset by outlining the added SqlitePoiStore, test extensions, documentation updates, dependency changes and testing steps.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/implement-sqlitepoistore-with-tests-wmesmn

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c6b7cf and 21beae4.

📒 Files selected for processing (2)
  • docs/wildside-engine-design.md (3 hunks)
  • wildside-core/src/store.rs (3 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Name variables and functions precisely; boolean names should use is/has/should.
Each file should encapsulate a coherent module; group related code close together.
Use en-GB-oxendict spelling/grammar in code comments (except external API names).
Function documentation must include clear usage examples; omit redundant examples in test docs.
No single Rust file should exceed 400 lines; split long switches/dispatch tables; move large test data to external files.
Fix warnings emitted during tests in code rather than silencing them.
Extract helper functions when a function becomes too long, maintaining separation of concerns and CQRS.
Group many related parameters into meaningfully named structs.
If returning a large error type, consider using Arc to reduce returned data size.
Every module must begin with a module-level //! comment explaining purpose and utility.
Document public APIs using Rustdoc comments (///) for cargo doc generation.
Prefer immutable data; avoid unnecessary mut bindings.
Use Result for error handling instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Do not silence lints except as a last resort.
Scope lint suppressions tightly and include a clear reason.
Prefer #[expect(...)] over #[allow(...)] for lint exceptions.
Where a function is unused under specific features, use #[cfg]/#[cfg_attr] for conditional compilation.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines.
Prefer single-line function definitions where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) }).
Prefer semantic error enums deriving std::error::Error via thiserror for inspectable conditions.

Files:

  • wildside-core/src/store.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -yse / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in...

Files:

  • wildside-core/src/store.rs
docs/**/*.{md,rs}

📄 CodeRabbit inference engine (docs/documentation-style-guide.md)

docs/**/*.{md,rs}: Use British English based on the Oxford English Dictionary (en-oxendict) in documentation and Rust doc comments
The word “outwith” is acceptable in documentation and Rust doc comments
Keep US spelling for API terms (e.g., color) even when using British English elsewhere
Use the Oxford comma
Treat company names as collective nouns (e.g., “Lille Industries are …”)
Expand uncommon acronyms on first use (e.g., Continuous Integration (CI))
Wrap paragraphs at 80 columns

Files:

  • docs/wildside-engine-design.md
docs/**/*.md

📄 CodeRabbit inference engine (docs/documentation-style-guide.md)

docs/**/*.md: Write headings in sentence case
Use Markdown headings (#, ##, ###, …) in order without skipping levels
Follow markdownlint recommendations
Provide code blocks and lists using standard Markdown syntax
Always provide a language identifier for fenced code blocks; use plaintext for non-code text
Use - as the first-level bullet and renumber ordered lists when items change
Prefer inline links [text](url) or bare angle-bracket URLs <url>
Ensure blank lines before and after bulleted lists and fenced code blocks
Ensure tables include a delimiter line below the header row
Wrap code (in docs) at 120 columns
Do not wrap tables
Use footnotes referenced with [^label]
Include Mermaid diagrams where they add clarity
Embed figures with Markdown image syntax ![alt text](path) and provide brief, descriptive alt text
Add a short descriptive sentence before each Mermaid diagram for screen readers

docs/**/*.md: Treat docs/ as the source of truth; proactively update docs/ when requirements/decisions change.
Documentation in docs/ must use en-GB-oxendict spelling/grammar (LICENSE filename unchanged).

Files:

  • docs/wildside-engine-design.md
**/*.md

📄 CodeRabbit inference engine (AGENTS.md)

Wrap Markdown paragraphs and bullets at 80 columns; code blocks at 120; do not wrap tables/headings; use dashes for bullets; use GFM footnotes.

Files:

  • docs/wildside-engine-design.md

⚙️ CodeRabbit configuration file

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -yse / -our) spelling and grammar
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/wildside-engine-design.md
🧬 Code graph analysis (1)
wildside-core/src/store.rs (2)
wildside-core/src/poi.rs (2)
  • envelope (46-48)
  • new (134-136)
wildside-core/src/test_support.rs (2)
  • write_sqlite_database (65-88)
  • write_sqlite_spatial_index (92-98)
🔍 Remote MCP

Additional Context for Reviewing PR #40

1. Roadmap Update

The PR marks the SqlitePoiStore roadmap item as complete in docs/roadmap.md, confirming intended feature delivery without impact on existing logic or control flow.
[Citation: Ref::ref_read_url]

2. Storage Format & Design Details

The design doc outlines the persisted R*-tree artifact and SQLite hydration process:

  • Artifact header “WSPI” (was “WSID”), 2‐byte version, followed by Bincode‐encoded IndexedPoi entries.
  • On startup, SqlitePoiStore::open reads the artifact, validates magic/version, bulk‐loads an in‐memory RTree, then verifies POI existence via chunked SELECT id FROM pois WHERE id IN (…) queries (chunks respect SQLite’s parameter limit).
  • Query API converts bounding‐box to an envelope, fetches matching IndexedPoi IDs, deduplicates, then loads POIs from SQLite via JSON‐deserialized tags.
    [Citation: Ref::ref_read_url]

3. Public API Surface

  • Exports added to lib.rs:
    pub use store::{PoiStore, SqlitePoiStore, SqlitePoiStoreError};
  • New public types in store.rs:
    SqlitePoiStore, SqlitePoiStoreError, SpatialIndexWriteError, and IndexedPoi.
    [Citation: Ref::ref_read_url]

4. Dependency & Feature Changes

  • Added dependencies: rusqlite (bundled), optional serde_json, bincode, tempfile.
  • Default feature set now includes "serde", enabling serialization support for rstar and geo types.
    [Citation: Ref::ref_read_url]

5. Testing Infrastructure

  • Unit tests cover:
    • Successful/empty queries, missing-POI and unsupported-version errors, invalid magic/tag scenarios.
  • BDD tests using rstest-bdd invoke feature file scenarios under tests/features/sqlite_poi_store.feature, exercising end-to-end store open and query behaviors.
  • New test-support helpers:
    write_sqlite_database & write_sqlite_spatial_index for fixture setup.
    [Citation: Ref::ref_read_url]

6. Known Lint/Refactor Suggestions

Several refactor suggestions have been addressed or remain under discussion:

  • Extract common helper for bbox queries in BDD tests.
  • Simplify argument count by using tuple parameters.
  • Refactor ensure_index_pois_exist to reduce nesting via find_missing_poi_in_chunk.
    No outstanding logical issues detected; all structural and lint concerns have corresponding code or AI-agent snippets noted in PR comments.
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review

Comment @coderabbitai help to get the list of available commands and usage tips.

codescene-delta-analysis[bot]

This comment was marked as outdated.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Instead of loading the entire POI table then filtering in memory, consider querying only the IDs returned by the R*-tree (SELECT … WHERE id IN …) to reduce startup I/O and memory use on large datasets.
  • Add a test for the unsupported index version path (when the file header version doesn’t match SPATIAL_INDEX_VERSION) to verify that load_index returns the correct error.
  • Consider making SqlitePoiStore (and its rusqlite/serde/bincode dependencies) an optional feature so consumers who don’t need it aren’t forced to pull in extra crates.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Instead of loading the entire POI table then filtering in memory, consider querying only the IDs returned by the R*-tree (SELECT … WHERE id IN …) to reduce startup I/O and memory use on large datasets.
- Add a test for the unsupported index version path (when the file header version doesn’t match SPATIAL_INDEX_VERSION) to verify that load_index returns the correct error.
- Consider making SqlitePoiStore (and its rusqlite/serde/bincode dependencies) an optional feature so consumers who don’t need it aren’t forced to pull in extra crates.

## Individual Comments

### Comment 1
<location> `wildside-core/tests/sqlite_poi_store_behaviour.rs:14` </location>
<code_context>
+    test_support::{write_sqlite_database, write_sqlite_spatial_index},
+};
+
+fn bbox(x1: f64, y1: f64, x2: f64, y2: f64) -> Rect<f64> {
+    Rect::new(Coord { x: x1, y: y1 }, Coord { x: x2, y: y2 })
+}
</code_context>

<issue_to_address>
**suggestion (testing):** Consider adding a scenario for a bbox that partially overlaps multiple POIs.

Adding this scenario will help ensure the store correctly returns all POIs when a bbox overlaps multiple entries, improving test coverage for multi-result queries.
</issue_to_address>

### Comment 2
<location> `wildside-core/src/store.rs:31` </location>
<code_context>
+
+/// Entry stored inside the persisted spatial index.
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub(crate) struct IndexedPoi {
+    id: u64,
+    location: Coord<f64>,
</code_context>

<issue_to_address>
**issue (complexity):** Consider storing PointOfInterest directly in the RTree and using a single Serde container for the index file to eliminate manual header handling and redundant HashMap usage.

Here are a few targeted ways to collapse almost all of your “wrapper + HashMap + manual header” boilerplate, without changing any external behavior:

1) Store your full `PointOfInterest` directly in the R\*-tree (so you don’t need `IndexedPoi` + a separate `HashMap`).  
   - derive `RTreeObject` on `PointOfInterest`  
   - use `RTree<PointOfInterest>` throughout  

2) Push header/version handling into your `Serde` container (so you don’t have to read/write bytes by hand or error‐map each I/O call).

3) Collapse your `Io`/`Encode` error variants using `#[from]` and `#[error(transparent)]`.

Below is a minimal sketch:

```rust
// 1) Derive RTreeObject on the real struct
use rstar::{RTreeObject, AABB};
use serde::{Serialize, Deserialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PointOfInterest {
    pub id: u64,
    pub location: Coord<f64>,
    pub tags: Tags,
}

impl RTreeObject for PointOfInterest {
    type Envelope = AABB<[f64;2]>;
    fn envelope(&self) -> Self::Envelope {
        let [x,y] = [self.location.x, self.location.y];
        AABB::from_point([x, y])
    }
}

// 2) One serde container for header + entries
#[derive(Serialize, Deserialize)]
struct SpatialIndexFile {
    version: u16,
    pois: Vec<PointOfInterest>,
}

// 3) Simplified store
pub struct SqlitePoiStore {
    index: RTree<PointOfInterest>,
}

impl SqlitePoiStore {
    pub fn open<P: AsRef<Path>, Q: AsRef<Path>>(
        db_path: P,
        idx_path: Q,
    ) -> Result<Self, StoreError> {
        let conn = Connection::open(db_path)?;
        let mut buf = std::fs::read(idx_path)?;
        let file: SpatialIndexFile = bincode::deserialize(&buf)?;
        assert_eq!(file.version, CURRENT_VERSION);

        let tree = RTree::bulk_load(file.pois);
        Ok(SqlitePoiStore { index: tree })
    }
}

// 4) Collapsed error type via `#[from]` and `transparent`
#[derive(Debug, thiserror::Error)]
pub enum StoreError {
    #[error(transparent)]
    Sqlite(#[from] rusqlite::Error),

    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    #[error("serialization error: {0}")]
    Serde(#[from] bincode::Error),
}
```

What this gives you:

- No `IndexedPoi` + `HashMap<u64, Poi>`, just one `RTree<PointOfInterest>`.  
- No manual `read_exact`/`write_all` or per‐call error mapping—everything flows through `bincode` + a single version check.  
- One small, obvious error enum.  

All of your existing tests, public API, and on‐disk format (aside from dropping the 4‐byte magic, which you can keep in the `SpatialIndexFile` if you really need it) remain exactly the same.
</issue_to_address>

### Comment 3
<location> `docs/wildside-engine-design.md:63` </location>
<code_context>
+- `SqlitePoiStore` is the first production-grade implementation of that
+  interface. It expects two artefacts produced by the offline ETL pipeline:
+  `pois.db` (an SQLite database whose `pois` table stores POI ids, coordinates,
+  and JSON-encoded tags) and `pois.rstar` (a binary R\*-tree serialisation).
+  The binary artefact uses a fixed `WSPI` magic number, a little-endian `u16`
+  version (currently `1`), followed by a `bincode` payload of `IndexedPoi`
</code_context>

<issue_to_address>
**suggestion (review_instructions):** The word 'serialisation' should use en-oxendic spelling: 'serialization'.

Please update 'serialisation' to 'serialization' to match en-oxendic spelling conventions.

<details>
<summary>Review instructions:</summary>

**Path patterns:** `**/*.md`

**Instructions:**
Use en-oxendic (-ize / -yse / -our) spelling and grammar.

</details>
</issue_to_address>

### Comment 4
<location> `docs/wildside-engine-design.md:152` </location>
<code_context>

+At runtime the `SqlitePoiStore` provides the fast-path for spatial lookups. The
+R\*-tree keeps query latency sub-millisecond for bounding boxes, while the
+in-memory cache of POIs—populated from SQLite during initialisation—ensures that
+`get_pois_in_bbox` remains infallible at the trait level. The header on the
+`pois.rstar` artefact gives us room for future evolution (e.g., switching to a
</code_context>

<issue_to_address>
**suggestion (review_instructions):** The word 'initialisation' should use en-oxendic spelling: 'initialization'.

Please update 'initialisation' to 'initialization' for consistency with en-oxendic spelling.

<details>
<summary>Review instructions:</summary>

**Path patterns:** `**/*.md`

**Instructions:**
Use en-oxendic (-ize / -yse / -our) spelling and grammar.

</details>
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread wildside-core/tests/sqlite_poi_store_behaviour.rs

/// Entry stored inside the persisted spatial index.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct IndexedPoi {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider storing PointOfInterest directly in the RTree and using a single Serde container for the index file to eliminate manual header handling and redundant HashMap usage.

Here are a few targeted ways to collapse almost all of your “wrapper + HashMap + manual header” boilerplate, without changing any external behavior:

  1. Store your full PointOfInterest directly in the R*-tree (so you don’t need IndexedPoi + a separate HashMap).

    • derive RTreeObject on PointOfInterest
    • use RTree<PointOfInterest> throughout
  2. Push header/version handling into your Serde container (so you don’t have to read/write bytes by hand or error‐map each I/O call).

  3. Collapse your Io/Encode error variants using #[from] and #[error(transparent)].

Below is a minimal sketch:

// 1) Derive RTreeObject on the real struct
use rstar::{RTreeObject, AABB};
use serde::{Serialize, Deserialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct PointOfInterest {
    pub id: u64,
    pub location: Coord<f64>,
    pub tags: Tags,
}

impl RTreeObject for PointOfInterest {
    type Envelope = AABB<[f64;2]>;
    fn envelope(&self) -> Self::Envelope {
        let [x,y] = [self.location.x, self.location.y];
        AABB::from_point([x, y])
    }
}

// 2) One serde container for header + entries
#[derive(Serialize, Deserialize)]
struct SpatialIndexFile {
    version: u16,
    pois: Vec<PointOfInterest>,
}

// 3) Simplified store
pub struct SqlitePoiStore {
    index: RTree<PointOfInterest>,
}

impl SqlitePoiStore {
    pub fn open<P: AsRef<Path>, Q: AsRef<Path>>(
        db_path: P,
        idx_path: Q,
    ) -> Result<Self, StoreError> {
        let conn = Connection::open(db_path)?;
        let mut buf = std::fs::read(idx_path)?;
        let file: SpatialIndexFile = bincode::deserialize(&buf)?;
        assert_eq!(file.version, CURRENT_VERSION);

        let tree = RTree::bulk_load(file.pois);
        Ok(SqlitePoiStore { index: tree })
    }
}

// 4) Collapsed error type via `#[from]` and `transparent`
#[derive(Debug, thiserror::Error)]
pub enum StoreError {
    #[error(transparent)]
    Sqlite(#[from] rusqlite::Error),

    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),

    #[error("serialization error: {0}")]
    Serde(#[from] bincode::Error),
}

What this gives you:

  • No IndexedPoi + HashMap<u64, Poi>, just one RTree<PointOfInterest>.
  • No manual read_exact/write_all or per‐call error mapping—everything flows through bincode + a single version check.
  • One small, obvious error enum.

All of your existing tests, public API, and on‐disk format (aside from dropping the 4‐byte magic, which you can keep in the SpatialIndexFile if you really need it) remain exactly the same.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this now been resolved?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Based on the current code, the suggestions I made earlier (about collapsing the IndexedPoi/HashMap/manual header boilerplate) have not yet been fully implemented in this PR. The code still uses the IndexedPoi wrapper, a separate SpatialIndexFile struct with manual magic/version handling, and a custom error enum with multiple variants for I/O, decode, and header validation.

If you would like to refactor towards the simpler approach I described (storing PointOfInterest directly in the RTree, using a single Serde container for the index file, and streamlining error handling), that work remains to be done. However, the current implementation is correct and functional, and the more complex structure may be intentional for future extensibility or strict format validation.

Let me know if you'd like more specific guidance or a step-by-step on how to refactor to the simpler pattern, or if you have other questions about the current design!

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sourcery-ai Please create a new GitHub issue for this

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created an issue for your comment: #44

Comment thread docs/wildside-engine-design.md Outdated
Comment thread docs/wildside-engine-design.md Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment thread wildside-core/src/store.rs Outdated
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8efd851 and 94ec005.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • docs/roadmap.md (1 hunks)
  • docs/wildside-engine-design.md (2 hunks)
  • wildside-core/Cargo.toml (1 hunks)
  • wildside-core/src/lib.rs (1 hunks)
  • wildside-core/src/store.rs (3 hunks)
  • wildside-core/src/test_support.rs (2 hunks)
  • wildside-core/tests/features/sqlite_poi_store.feature (1 hunks)
  • wildside-core/tests/sqlite_poi_store_behaviour.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
docs/**/*.{md,rs}

📄 CodeRabbit inference engine (docs/documentation-style-guide.md)

docs/**/*.{md,rs}: Use British English based on the Oxford English Dictionary (en-oxendict) in documentation and Rust doc comments
The word “outwith” is acceptable in documentation and Rust doc comments
Keep US spelling for API terms (e.g., color) even when using British English elsewhere
Use the Oxford comma
Treat company names as collective nouns (e.g., “Lille Industries are …”)
Expand uncommon acronyms on first use (e.g., Continuous Integration (CI))
Wrap paragraphs at 80 columns

Files:

  • docs/roadmap.md
  • docs/wildside-engine-design.md
docs/**/*.md

📄 CodeRabbit inference engine (docs/documentation-style-guide.md)

docs/**/*.md: Write headings in sentence case
Use Markdown headings (#, ##, ###, …) in order without skipping levels
Follow markdownlint recommendations
Provide code blocks and lists using standard Markdown syntax
Always provide a language identifier for fenced code blocks; use plaintext for non-code text
Use - as the first-level bullet and renumber ordered lists when items change
Prefer inline links [text](url) or bare angle-bracket URLs <url>
Ensure blank lines before and after bulleted lists and fenced code blocks
Ensure tables include a delimiter line below the header row
Wrap code (in docs) at 120 columns
Do not wrap tables
Use footnotes referenced with [^label]
Include Mermaid diagrams where they add clarity
Embed figures with Markdown image syntax ![alt text](path) and provide brief, descriptive alt text
Add a short descriptive sentence before each Mermaid diagram for screen readers

docs/**/*.md: Treat docs/ as the source of truth; proactively update docs/ when requirements/decisions change.
Documentation in docs/ must use en-GB-oxendict spelling/grammar (LICENSE filename unchanged).

Files:

  • docs/roadmap.md
  • docs/wildside-engine-design.md
**/*.md

📄 CodeRabbit inference engine (AGENTS.md)

Wrap Markdown paragraphs and bullets at 80 columns; code blocks at 120; do not wrap tables/headings; use dashes for bullets; use GFM footnotes.

Files:

  • docs/roadmap.md
  • docs/wildside-engine-design.md

⚙️ CodeRabbit configuration file

**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")

  • Use en-GB-oxendict (-ize / -yse / -our) spelling and grammar
  • Headings must not be wrapped.
  • Documents must start with a level 1 heading
  • Headings must correctly increase or decrease by no more than one level at a time
  • Use GitHub-flavoured Markdown style for footnotes and endnotes.
  • Numbered footnotes must be numbered by order of appearance in the document.

Files:

  • docs/roadmap.md
  • docs/wildside-engine-design.md
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Name variables and functions precisely; boolean names should use is/has/should.
Each file should encapsulate a coherent module; group related code close together.
Use en-GB-oxendict spelling/grammar in code comments (except external API names).
Function documentation must include clear usage examples; omit redundant examples in test docs.
No single Rust file should exceed 400 lines; split long switches/dispatch tables; move large test data to external files.
Fix warnings emitted during tests in code rather than silencing them.
Extract helper functions when a function becomes too long, maintaining separation of concerns and CQRS.
Group many related parameters into meaningfully named structs.
If returning a large error type, consider using Arc to reduce returned data size.
Every module must begin with a module-level //! comment explaining purpose and utility.
Document public APIs using Rustdoc comments (///) for cargo doc generation.
Prefer immutable data; avoid unnecessary mut bindings.
Use Result for error handling instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Do not silence lints except as a last resort.
Scope lint suppressions tightly and include a clear reason.
Prefer #[expect(...)] over #[allow(...)] for lint exceptions.
Where a function is unused under specific features, use #[cfg]/#[cfg_attr] for conditional compilation.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines.
Prefer single-line function definitions where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) }).
Prefer semantic error enums deriving std::error::Error via thiserror for inspectable conditions.

Files:

  • wildside-core/src/lib.rs
  • wildside-core/src/store.rs
  • wildside-core/tests/sqlite_poi_store_behaviour.rs
  • wildside-core/src/test_support.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -yse / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in...

Files:

  • wildside-core/src/lib.rs
  • wildside-core/src/store.rs
  • wildside-core/tests/sqlite_poi_store_behaviour.rs
  • wildside-core/src/test_support.rs
🧬 Code graph analysis (3)
wildside-core/src/store.rs (2)
wildside-core/src/poi.rs (1)
  • new (134-136)
wildside-core/src/test_support.rs (2)
  • write_sqlite_database (65-84)
  • write_sqlite_spatial_index (88-94)
wildside-core/tests/sqlite_poi_store_behaviour.rs (3)
wildside-core/src/test_support.rs (2)
  • write_sqlite_database (65-84)
  • write_sqlite_spatial_index (88-94)
wildside-core/src/store.rs (2)
  • poi (369-375)
  • open (155-185)
wildside-core/src/poi.rs (1)
  • with_empty_tags (148-150)
wildside-core/src/test_support.rs (1)
wildside-core/src/store.rs (3)
  • write_index (255-277)
  • poi (369-375)
  • from (37-42)
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review
🔇 Additional comments (8)
wildside-core/src/test_support.rs (1)

86-94: LGTM!

The implementation correctly converts POIs to IndexedPoi entries and delegates to write_index. The function signature and error handling are appropriate.

wildside-core/src/store.rs (7)

23-27: LGTM!

The magic bytes and version constant provide a versioned binary format for the persisted spatial index. The pub(crate) visibility is appropriate for use in test-support utilities.


29-51: LGTM!

The IndexedPoi struct is appropriately minimal for spatial indexing. The From implementation correctly extracts id and location from PointOfInterest, and the RTreeObject implementation properly converts coordinates to an AABB point.


53-144: LGTM!

The error enums comprehensively cover all failure modes with descriptive messages and proper error chaining via thiserror. The SqlitePoiStoreError variants appropriately distinguish between different failure scenarios (missing POI, invalid tags, corrupted magic, etc.).


146-186: LGTM!

The SqlitePoiStore implementation correctly loads the spatial index, hydrates POIs from SQLite, and validates that all indexed POIs exist in the database. The use of HashMap::with_capacity based on index size is a good optimisation.

Note: The validation is one-directional (index → database) and doesn't verify whether the database contains POIs not present in the index. This is appropriate since the index is the source of truth for spatial queries.


209-253: LGTM!

The load_index function correctly validates the file header (magic bytes and version) before deserializing entries. Using BufReader and bulk_load is appropriate for performance. Error handling is comprehensive with proper error chaining.

Note: The code uses bincode 1.x. According to the retrieved learnings, bincode 2.x is available with a new configuration model. The current usage is correct for 1.x, but consider documenting why 1.x is chosen or evaluating an upgrade in future work.

Based on learnings.


279-299: LGTM!

The load_pois function correctly loads POIs from SQLite and parses JSON tags with appropriate error handling. Loading all POIs from the database is acceptable since the calling code (SqlitePoiStore::open) immediately filters to only those present in the spatial index.


443-526: LGTM!

The tests comprehensively cover SqlitePoiStore functionality including successful spatial queries, empty results, and error scenarios (missing POI, corrupted magic, invalid tags). The use of rstest fixtures and temporary directories is appropriate.

Comment thread docs/wildside-engine-design.md Outdated
Comment thread wildside-core/src/store.rs
Comment thread wildside-core/src/store.rs
Comment thread wildside-core/src/test_support.rs
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Oct 5, 2025

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix:

wildside-core/tests/sqlite_poi_store_behaviour.rs

Comment on lines +108 to +118

fn query_origin(
    store_holder: &RefCell<Option<SqlitePoiStore>>,
    query_results: &RefCell<Vec<PointOfInterest>>,
) {
    let binding = store_holder.borrow();
    let store = binding
        .as_ref()
        .expect("store should be available for querying");
    let bbox = bbox(-0.5, -0.5, 0.5, 0.5);
    query_results.replace(store.get_pois_in_bbox(&bbox).collect());
}

❌ New issue: Code Duplication
The module contains 2 functions with similar structure: query_origin,query_outside

@coderabbitai

This comment was marked as resolved.

codescene-delta-analysis[bot]

This comment was marked as outdated.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
wildside-core/tests/sqlite_poi_store_behaviour.rs (1)

107-137: Code duplication eliminated successfully.

The helper function correctly extracts the common bbox query logic, and both query functions now delegate appropriately. This addresses the past review comment about duplication.

However, improve the variable name at line 115:

-    let binding = store_holder.borrow();
-    let store = binding
+    let borrowed_store = store_holder.borrow();
+    let store = borrowed_store
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 94ec005 and 1a06b8f.

📒 Files selected for processing (1)
  • wildside-core/tests/sqlite_poi_store_behaviour.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Name variables and functions precisely; boolean names should use is/has/should.
Each file should encapsulate a coherent module; group related code close together.
Use en-GB-oxendict spelling/grammar in code comments (except external API names).
Function documentation must include clear usage examples; omit redundant examples in test docs.
No single Rust file should exceed 400 lines; split long switches/dispatch tables; move large test data to external files.
Fix warnings emitted during tests in code rather than silencing them.
Extract helper functions when a function becomes too long, maintaining separation of concerns and CQRS.
Group many related parameters into meaningfully named structs.
If returning a large error type, consider using Arc to reduce returned data size.
Every module must begin with a module-level //! comment explaining purpose and utility.
Document public APIs using Rustdoc comments (///) for cargo doc generation.
Prefer immutable data; avoid unnecessary mut bindings.
Use Result for error handling instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Do not silence lints except as a last resort.
Scope lint suppressions tightly and include a clear reason.
Prefer #[expect(...)] over #[allow(...)] for lint exceptions.
Where a function is unused under specific features, use #[cfg]/#[cfg_attr] for conditional compilation.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines.
Prefer single-line function definitions where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) }).
Prefer semantic error enums deriving std::error::Error via thiserror for inspectable conditions.

Files:

  • wildside-core/tests/sqlite_poi_store_behaviour.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -yse / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in...

Files:

  • wildside-core/tests/sqlite_poi_store_behaviour.rs
🧬 Code graph analysis (1)
wildside-core/tests/sqlite_poi_store_behaviour.rs (3)
wildside-core/src/test_support.rs (2)
  • write_sqlite_database (65-84)
  • write_sqlite_spatial_index (88-94)
wildside-core/src/store.rs (2)
  • poi (369-375)
  • open (155-185)
wildside-core/src/poi.rs (1)
  • with_empty_tags (148-150)
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review

Comment thread wildside-core/tests/sqlite_poi_store_behaviour.rs Outdated
@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Oct 5, 2025

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix:

wildside-core/tests/sqlite_poi_store_behaviour.rs

Comment on lines +107 to +121

fn query_bbox_helper(
    store_holder: &RefCell<Option<SqlitePoiStore>>,
    query_results: &RefCell<Vec<PointOfInterest>>,
    x1: f64,
    y1: f64,
    x2: f64,
    y2: f64,
) {
    let binding = store_holder.borrow();
    let store = binding
        .as_ref()
        .expect("store should be available for querying");
    let bbox = bbox(x1, y1, x2, y2);
    query_results.replace(store.get_pois_in_bbox(&bbox).collect());
}

❌ New issue: Excess Number of Function Arguments
query_bbox_helper has 6 arguments, max arguments = 4

@coderabbitai

This comment was marked as resolved.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1a06b8f and 4ce25f6.

📒 Files selected for processing (1)
  • wildside-core/tests/sqlite_poi_store_behaviour.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs

📄 CodeRabbit inference engine (AGENTS.md)

**/*.rs: Name variables and functions precisely; boolean names should use is/has/should.
Each file should encapsulate a coherent module; group related code close together.
Use en-GB-oxendict spelling/grammar in code comments (except external API names).
Function documentation must include clear usage examples; omit redundant examples in test docs.
No single Rust file should exceed 400 lines; split long switches/dispatch tables; move large test data to external files.
Fix warnings emitted during tests in code rather than silencing them.
Extract helper functions when a function becomes too long, maintaining separation of concerns and CQRS.
Group many related parameters into meaningfully named structs.
If returning a large error type, consider using Arc to reduce returned data size.
Every module must begin with a module-level //! comment explaining purpose and utility.
Document public APIs using Rustdoc comments (///) for cargo doc generation.
Prefer immutable data; avoid unnecessary mut bindings.
Use Result for error handling instead of panicking where feasible.
Avoid unsafe code unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not use return in single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Do not silence lints except as a last resort.
Scope lint suppressions tightly and include a clear reason.
Prefer #[expect(...)] over #[allow(...)] for lint exceptions.
Where a function is unused under specific features, use #[cfg]/#[cfg_attr] for conditional compilation.
Prefer .expect() over .unwrap().
Use concat!() to combine long string literals rather than escaping newlines.
Prefer single-line function definitions where appropriate (e.g., pub fn new(id: u64) -> Self { Self(id) }).
Prefer semantic error enums deriving std::error::Error via thiserror for inspectable conditions.

Files:

  • wildside-core/tests/sqlite_poi_store_behaviour.rs

⚙️ CodeRabbit configuration file

**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.

  • Adhere to single responsibility and CQRS

  • Place function attributes after doc comments.

  • Do not use return in single-line functions.

  • Move conditionals with >2 branches into a predicate function.

  • Avoid unsafe unless absolutely necessary.

  • Every module must begin with a //! doc comment that explains the module's purpose and utility.

  • Comments and docs must follow en-GB-oxendict (-ize / -yse / -our) spelling and grammar

  • Lints must not be silenced except as a last resort.

    • #[allow] is forbidden.
    • Only narrowly scoped #[expect(lint, reason = "...")] is allowed.
    • No lint groups, no blanket or file-wide suppression.
    • Include FIXME: with link if a fix is expected.
  • Where code is only used by specific features, it must be conditionally compiled or a conditional expectation for unused_code applied.

  • Use rstest fixtures for shared setup and to avoid repetition between tests.

  • Replace duplicated tests with #[rstest(...)] parameterised cases.

  • Prefer mockall for mocks/stubs.

  • Prefer .expect() over .unwrap()

  • Ensure that any API or behavioural changes are reflected in the documentation in docs/

  • Ensure that any completed roadmap steps are recorded in the appropriate roadmap in docs/

  • Files must not exceed 400 lines in length

    • Large modules must be decomposed
    • Long match statements or dispatch tables should be decomposed by domain and collocated with targets
    • Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
  • Environment access (env::set_var and env::remove_var) are always unsafe in Rust 2024 and MUST be marked as such

    • For testing of functionality depending upon environment variables, dependency injection and the mockable crate are the preferred option.
    • If mockable cannot be used, env mutations in...

Files:

  • wildside-core/tests/sqlite_poi_store_behaviour.rs
🧬 Code graph analysis (1)
wildside-core/tests/sqlite_poi_store_behaviour.rs (3)
wildside-core/src/test_support.rs (2)
  • write_sqlite_database (65-84)
  • write_sqlite_spatial_index (88-94)
wildside-core/src/store.rs (2)
  • poi (369-375)
  • open (155-185)
wildside-core/src/poi.rs (1)
  • with_empty_tags (148-150)
🔍 Remote MCP

Additional Context for Reviewing PR #40

  1. PoiStore Trait Definition
    The PoiStore trait defines the core interface that SqlitePoiStore implements. It includes:

    • fn get_pois_in_bbox(&self, bbox: [f64; 4]) -> Vec<PointOfInterest>
      (Derived from reading wildside-core/src/store.rs – requires confirming in source)
  2. R-Tree Persistence Format*

    • Magic header: SPATIAL_INDEX_MAGIC ([u8; 4])
    • Version: SPATIAL_INDEX_VERSION (u16)
    • Entries: a sequence of serialized IndexedPoi (via bincode)
      (See load_index / write_index implementations in store.rs)
  3. SQL Schema for POIs
    Table pois created by write_sqlite_database:

    CREATE TABLE pois (
      id INTEGER PRIMARY KEY,
      lon REAL NOT NULL,
      lat REAL NOT NULL,
      tags TEXT NOT NULL
    );
    • Tags are serialized JSON strings ([serde_json])
      (From test_support.rs)
  4. Feature Flags and Dependencies

    • serde is now a default feature, pulling in serde_json, bincode, geo/use-serde, rstar/serde.
    • rusqlite (with bundled SQLite) enables database I/O.
    • tempfile used for test fixtures.
      (From Cargo.toml diffs)
  5. Test Coverage Highlights

    • Unit tests for: valid index load, missing POI errors, corrupted magic/version, invalid JSON tags.
    • BDD tests (rstest-bdd) cover:
      • Query inside bbox returns a POI
      • Outside bbox returns empty
      • Missing POI in index errors at open
        (See tests/features/sqlite_poi_store.feature and tests/sqlite_poi_store_behaviour.rs)

Citations:

  • Source code references: wildside-core/src/store.rs, wildside-core/src/test_support.rs, wildside-core/Cargo.toml
  • BDD scenarios: wildside-core/tests/features/sqlite_poi_store.feature
⏰ Context from checks skipped due to timeout of 120000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Sourcery review
🔇 Additional comments (1)
wildside-core/tests/sqlite_poi_store_behaviour.rs (1)

107-119: LGTM: Helper function successfully addresses code duplication.

The query_bbox_helper function correctly eliminates duplication between query_origin and query_outside by extracting common logic and accepting coordinates as a tuple parameter. This addresses the previous static analysis concern about excessive arguments.

Comment thread wildside-core/tests/sqlite_poi_store_behaviour.rs Outdated
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

- reuse the serde container for header inspection before validating the version
- surface invalid magic bytes even when the payload is truncated
codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

codescene-delta-analysis[bot]

This comment was marked as outdated.

Load the spatial index into an R*-tree of IDs, validate referenced rows in batches, and fetch bounding-box matches with chunked id queries. Update the design blueprint to describe the streaming hydration and revised sequence diagram.
Copy link
Copy Markdown

@codescene-delta-analysis codescene-delta-analysis Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gates Failed
Enforce critical code health rules (1 file with Deep, Nested Complexity)

Gates Passed
4 Quality Gates Passed

See analysis details in CodeScene

Reason for failure
Enforce critical code health rules Violations Code Health Impact
store.rs 1 critical rule 10.00 → 9.39 Suppress

Quality Gate Profile: Pay Down Tech Debt
Want more control? Customize Code Health rules or catch issues early with our IDE extension and CLI tool.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Oct 7, 2025

@coderabbitai have the following now been resolved?

  • Instead of loading the entire POI table then filtering in memory, consider querying only the IDs returned by the R*-tree (SELECT … WHERE id IN …) to reduce startup I/O and memory use on large datasets.
  • Add a test for the unsupported index version path (when the file header version doesn’t match SPATIAL_INDEX_VERSION) to verify that load_index returns the correct error.

@leynos
Copy link
Copy Markdown
Owner Author

leynos commented Oct 7, 2025

@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix:

wildside-core/src/store.rs

Comment on lines +226 to +252

fn ensure_index_pois_exist(
    connection: &Connection,
    entries: &[IndexedPoi],
) -> Result<(), SqlitePoiStoreError> {
    if entries.is_empty() {
        return Ok(());
    }

    let mut ids: Vec<u64> = entries.iter().map(|entry| entry.id).collect();
    ids.sort_unstable();
    ids.dedup();

    let max_parameters = max_variable_limit(connection);
    for chunk in ids.chunks(max_parameters) {
        let pois = load_pois_chunk(connection, chunk)?;
        if pois.len() != chunk.len() {
            for id in chunk {
                if pois.binary_search_by_key(id, |poi| poi.id).is_err() {
                    return Err(SqlitePoiStoreError::MissingPoi { id: *id });
                }
            }
            debug_assert!(false, "chunk length mismatch should reveal missing id");
        }
    }

    Ok(())
}

❌ New issue: Deep, Nested Complexity
ensure_index_pois_exist has a nested complexity depth of 4, threshold = 4

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 7, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check the load_pois implementation to see if it filters by IDs or loads everything
cat wildside-core/src/store.rs | grep -A 30 "fn load_pois"

Length of output: 1484


🏁 Script executed:

#!/bin/bash
# Search for tests related to unsupported index version
rg -n "unsupported.*version|version.*unsupport" wildside-core/src/store.rs wildside-core/tests/

Length of output: 471


🏁 Script executed:

#!/bin/bash
# Check for test functions that might test version errors
rg -n "fn.*test.*version|SPATIAL_INDEX_VERSION" wildside-core/src/store.rs

Length of output: 353


@leynos: Yes, both issues have been resolved:

  1. Querying by ID instead of loading entire table: ✅ Resolved

    • The load_pois function (line ~203) now accepts ids: &[u64] and uses SELECT ... WHERE id IN (...) to fetch only the POIs referenced by the R*-tree index
    • The implementation chunks large ID lists to respect SQLite's parameter limits
  2. Test for unsupported index version: ✅ Resolved

    • Test sqlite_store_errors_on_unsupported_version added at line 582
    • It writes an index with SPATIAL_INDEX_VERSION + 1, attempts to open the store, and verifies that SqlitePoiStoreError::UnsupportedVersion is returned with the correct version numbers

Both recommendations have been implemented in the current PR state.

@coderabbitai

This comment was marked as resolved.

@leynos leynos merged commit ce4820a into main Oct 8, 2025
4 checks passed
@leynos leynos deleted the codex/implement-sqlitepoistore-with-tests-wmesmn branch October 8, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant