From 857a1b02361887df30dfb9105547953ba0e8a342 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:43:22 -0500 Subject: [PATCH 1/4] Test that a missing index root fails the build --- .../binding/root_at_construction_test.py | 11 +++++ packages/rust/tests/missing_root.rs | 42 +++++++++++++++++++ .../binding/root-at-construction.test.ts | 9 ++++ 3 files changed, 62 insertions(+) create mode 100644 packages/rust/tests/missing_root.rs diff --git a/packages/python/tests/integration/binding/root_at_construction_test.py b/packages/python/tests/integration/binding/root_at_construction_test.py index dae2bd59c..101e43b3c 100644 --- a/packages/python/tests/integration/binding/root_at_construction_test.py +++ b/packages/python/tests/integration/binding/root_at_construction_test.py @@ -3,6 +3,7 @@ """ import os +import re import pytest @@ -45,3 +46,13 @@ async def it_resolves_a_relative_root_against_the_cwd_of_construction( rows = await db.query("SELECT path FROM './**'") assert rows == [{"path": "a.json"}] + + @pytest.mark.asyncio + async def it_raises_when_the_root_does_not_exist(tmp_path): + missing = tmp_path / "absent" + db = DirSQL(str(missing)) + + with pytest.raises( + Exception, match=rf"^root directory {re.escape(str(missing))} does not exist$" + ): + await db.ready() diff --git a/packages/rust/tests/missing_root.rs b/packages/rust/tests/missing_root.rs new file mode 100644 index 000000000..f15965ba9 --- /dev/null +++ b/packages/rust/tests/missing_root.rs @@ -0,0 +1,42 @@ +//! An index root that does not exist fails the build, naming the root. + +use dirsql::{DirSQL, Table}; +use tempfile::TempDir; + +fn table() -> Table { + Table::new("t", "CREATE TABLE t (x TEXT)", "*.json", |_| vec![]) +} + +fn build_error(result: dirsql::Result) -> String { + match result { + Ok(_) => panic!("the build succeeded"), + Err(e) => e.to_string(), + } +} + +#[test] +fn a_missing_root_fails_the_build() { + let dir = TempDir::new().unwrap(); + let missing = dir.path().join("absent"); + + let err = build_error(DirSQL::new(&missing, vec![table()])); + + assert_eq!( + err, + format!("root directory {} does not exist", missing.display()) + ); +} + +#[test] +fn a_missing_root_fails_the_build_with_no_tables() { + let dir = TempDir::new().unwrap(); + let missing = dir.path().join("absent"); + + let err = build_error(DirSQL::builder().root(&missing).build()); + + assert_eq!( + err, + format!("root directory {} does not exist", missing.display()) + ); +} + diff --git a/packages/ts/tests/integration/binding/root-at-construction.test.ts b/packages/ts/tests/integration/binding/root-at-construction.test.ts index b5543bec7..45c4a1a8e 100644 --- a/packages/ts/tests/integration/binding/root-at-construction.test.ts +++ b/packages/ts/tests/integration/binding/root-at-construction.test.ts @@ -45,4 +45,13 @@ describe("root at construction", () => { { path: "a.json" }, ]); }); + + it("rejects a root that does not exist, naming it", async () => { + const missing = join(dir, "absent"); + const db = new DirSQL({ root: missing }); + + await expect(db.ready).rejects.toThrow( + `root directory ${missing} does not exist`, + ); + }); }); From 406eb2434f15c9a5ab61164f553eaeb9dfb449b9 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:57:25 -0500 Subject: [PATCH 2/4] Fail the build when the index root does not exist --- .../binding/root_at_construction_test.py | 3 +- ...26-11-18-missing-index-root-fails-build.md | 3 ++ ...26-11-18-missing-index-root-fails-build.md | 23 ++++++++++++ packages/rust/src/lib.rs | 35 ++++++++++++++++--- packages/rust/tests/code_review_findings.rs | 30 +--------------- packages/rust/tests/missing_root.rs | 1 - 6 files changed, 60 insertions(+), 35 deletions(-) create mode 100644 packages/rust/changelog.d/2026-11-18-missing-index-root-fails-build.md create mode 100644 packages/rust/migrations.d/2026-11-18-missing-index-root-fails-build.md diff --git a/packages/python/tests/integration/binding/root_at_construction_test.py b/packages/python/tests/integration/binding/root_at_construction_test.py index 101e43b3c..4adc5fbb3 100644 --- a/packages/python/tests/integration/binding/root_at_construction_test.py +++ b/packages/python/tests/integration/binding/root_at_construction_test.py @@ -53,6 +53,7 @@ async def it_raises_when_the_root_does_not_exist(tmp_path): db = DirSQL(str(missing)) with pytest.raises( - Exception, match=rf"^root directory {re.escape(str(missing))} does not exist$" + Exception, + match=rf"^root directory {re.escape(str(missing))} does not exist$", ): await db.ready() diff --git a/packages/rust/changelog.d/2026-11-18-missing-index-root-fails-build.md b/packages/rust/changelog.d/2026-11-18-missing-index-root-fails-build.md new file mode 100644 index 000000000..6e4e74fbb --- /dev/null +++ b/packages/rust/changelog.d/2026-11-18-missing-index-root-fails-build.md @@ -0,0 +1,3 @@ +**Changed** + +- **An index root that does not exist now fails the build**, with `root directory does not exist`. Before, the build succeeded with no file watcher, so the instance stayed empty and later files under the root went unseen. Every SDK raises the error. diff --git a/packages/rust/migrations.d/2026-11-18-missing-index-root-fails-build.md b/packages/rust/migrations.d/2026-11-18-missing-index-root-fails-build.md new file mode 100644 index 000000000..d0d487221 --- /dev/null +++ b/packages/rust/migrations.d/2026-11-18-missing-index-root-fails-build.md @@ -0,0 +1,23 @@ +### A missing index root fails the build + +#### Summary + +Building a `DirSQL` (Rust, Python, TypeScript) whose index root does not exist now fails with `root directory does not exist`. Builds that used to succeed over a missing root now fail. The CLI always roots at the current directory, so it is unaffected. + +#### Required changes + +| Before | After | +| --- | --- | +| `DirSQL("/path/not/yet/created")` built an empty instance | Create the directory before building | + +#### Deprecations removed + +_None._ + +#### Behavior changes without code changes + +The build raises instead of succeeding. Before, it also started no file watcher, so files created under the root later went unseen. + +#### Verification + +In Python, `await DirSQL("/no/such/dir").ready()` inside a coroutine raises `RuntimeError: root directory /no/such/dir does not exist`. diff --git a/packages/rust/src/lib.rs b/packages/rust/src/lib.rs index b7c3b42c5..f9be06de8 100644 --- a/packages/rust/src/lib.rs +++ b/packages/rust/src/lib.rs @@ -215,6 +215,9 @@ pub enum DirSqlError { #[error("duplicate table name: {0}")] DuplicateTable(String), + #[error("root directory {} does not exist", .0.display())] + MissingRoot(PathBuf), + #[error("config error: {message}")] Config { message: String, @@ -568,6 +571,16 @@ impl FreshState { } } +/// Fails when `exists` says the index root is missing: nothing above it is +/// watched, so it could never be seen to appear. +fn check_root(root: &Path, exists: &dyn Fn(&Path) -> bool) -> Result<()> { + if exists(root) { + Ok(()) + } else { + Err(DirSqlError::MissingRoot(root.to_path_buf())) + } +} + /// The watcher the build keeps, given how starting it went. fn watcher_at_build(started: std::result::Result) -> Result> { match started { @@ -1824,9 +1837,10 @@ impl DirSQL { } /// Test-seam build path: identical to [`build_from_resolved`] but stores - /// the supplied [`FileSystem`] double on the resulting instance. The - /// prepare phase still uses [`RealFs`] (it has no instance yet), so - /// callers must build over an empty temp dir. + /// the supplied [`FileSystem`] double on the resulting instance, and it + /// skips the root check, so a double may stand in for a root that is not + /// on disk. The prepare phase still uses [`RealFs`] (it has no instance + /// yet), so callers must build over an empty or missing directory. #[cfg(test)] pub(crate) fn with_ignore_and_fs( root: impl Into, @@ -1851,7 +1865,7 @@ impl DirSQL { path_table_parser: None, no_ignore: false, }; - let prepared = Self::prepare_resolved(resolved)?; + let prepared = Self::prepare_resolved_with(resolved, &scan_directory_reporting)?; Self::finish_build_with_fs(prepared, fs, Progress::indexing()) } @@ -1866,6 +1880,7 @@ impl DirSQL { /// JS main thread for the napi-rs TypeScript binding). #[doc(hidden)] pub fn prepare_resolved(resolved: ResolvedBuild) -> Result { + check_root(&resolved.root, &|root| root.exists())?; Self::prepare_resolved_with(resolved, &scan_directory_reporting) } @@ -8183,6 +8198,18 @@ mod internal_tests { assert_eq!(err.to_string(), "watcher error: denied"); } + #[test] + fn check_root_names_a_missing_root() { + let err = check_root(Path::new("/gone"), &|_| false).unwrap_err(); + + assert_eq!(err.to_string(), "root directory /gone does not exist"); + } + + #[test] + fn check_root_passes_an_existing_root() { + assert!(check_root(Path::new("/here"), &|root| root == Path::new("/here")).is_ok()); + } + #[test] fn a_build_over_a_missing_anchor_starts_no_watcher() { assert_eq!( diff --git a/packages/rust/tests/code_review_findings.rs b/packages/rust/tests/code_review_findings.rs index 73a436566..8a67daf0a 100644 --- a/packages/rust/tests/code_review_findings.rs +++ b/packages/rust/tests/code_review_findings.rs @@ -1,7 +1,6 @@ //! Tests for code-review findings; each test name carries its finding ID. -use dirsql::{DirSQL, DirSqlError, Row, Table, Value}; -use std::error::Error as _; +use dirsql::{DirSQL, Row, Table, Value}; use std::time::Duration; use tempfile::TempDir; @@ -141,33 +140,6 @@ fn p7_builder_exposes_poll_interval() { .unwrap(); } -#[test] -fn i3_watch_error_exposes_underlying_source() { - let dir = TempDir::new().unwrap(); - let missing = dir.path().join("missing"); - let db = DirSQL::new( - &missing, - vec![Table::new( - "t", - "CREATE TABLE t (id TEXT)", - "*.json", - |_| vec![], - )], - ) - .unwrap(); - let err = db - .poll_events(std::time::Duration::ZERO) - .expect_err("watching a missing root must fail"); - match &err { - DirSqlError::Watch { .. } => {} - other => panic!("expected DirSqlError::Watch, got: {other:?}"), - } - assert!( - err.source().is_some(), - "DirSqlError::Watch must expose its underlying source (got None)" - ); -} - #[test] fn i6_parser_versions_json_no_longer_lists_removed_parsers() { let s = dirsql::persist::PARSER_VERSIONS_JSON; diff --git a/packages/rust/tests/missing_root.rs b/packages/rust/tests/missing_root.rs index f15965ba9..4b90517b5 100644 --- a/packages/rust/tests/missing_root.rs +++ b/packages/rust/tests/missing_root.rs @@ -39,4 +39,3 @@ fn a_missing_root_fails_the_build_with_no_tables() { format!("root directory {} does not exist", missing.display()) ); } - From afa7e58cb66543ab9d82332041997417e044dfb8 Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:57:50 -0500 Subject: [PATCH 3/4] e2e attestation for bot/1771-missing-index-root-1118 --- .../e2e-attestations/bot-1771-missing-index-root-1118.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/ts/e2e-attestations/bot-1771-missing-index-root-1118.json diff --git a/packages/ts/e2e-attestations/bot-1771-missing-index-root-1118.json b/packages/ts/e2e-attestations/bot-1771-missing-index-root-1118.json new file mode 100644 index 000000000..bdb7db404 --- /dev/null +++ b/packages/ts/e2e-attestations/bot-1771-missing-index-root-1118.json @@ -0,0 +1,7 @@ +{ + "command": "pnpm test:e2e", + "ran_at": 1795024670, + "exit_code": 0, + "commit": "406eb2434f15c9a5ab61164f553eaeb9dfb449b9", + "branch": "bot/1771-missing-index-root-1118" +} From 5391e8c15e40f8db60a406c8fcfb2ade59731e3d Mon Sep 17 00:00:00 2001 From: thekevinbot <248217931+thekevinbot@users.noreply.github.com> Date: Wed, 18 Nov 2026 13:22:08 -0500 Subject: [PATCH 4/4] e2e attestation for bot/1771-missing-index-root-1118 --- .../e2e-attestations/bot-1771-missing-index-root-1118.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 packages/python/e2e-attestations/bot-1771-missing-index-root-1118.json diff --git a/packages/python/e2e-attestations/bot-1771-missing-index-root-1118.json b/packages/python/e2e-attestations/bot-1771-missing-index-root-1118.json new file mode 100644 index 000000000..de401a973 --- /dev/null +++ b/packages/python/e2e-attestations/bot-1771-missing-index-root-1118.json @@ -0,0 +1,7 @@ +{ + "command": "uv run python -m pytest tests/e2e/fanout_test.py tests/e2e/fresh_declared_repros_test.py tests/e2e/extension_package_test.py tests/e2e/parent_then_child_test.py tests/e2e/on_file_query_test.py tests/e2e/parent_then_child_server_test.py tests/e2e/plugin_discovery_test.py tests/e2e/on_file_value_types_test.py tests/e2e/interpret_removed_test.py tests/e2e/orphan_query_test.py tests/e2e/on_file_failure_test.py tests/e2e/declared_table_name_test.py tests/e2e/use_case_dossier_test.py tests/e2e/plugin_extension_discovery_test.py tests/e2e/relative_root_chdir_test.py tests/e2e/root_at_construction_test.py tests/e2e/written_during_build_test.py tests/e2e/query_contract_test.py tests/e2e/use_case_join_test.py tests/e2e/use_case_transcripts_test.py -x -q", + "ran_at": 1795026128, + "exit_code": 0, + "commit": "4c3d8a17a12240c7e4f93321c4696ddb67365cf4", + "branch": "bot/1771-missing-index-root-1118" +}