Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/skills/fix-issue/references/platform-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ Pass `--platform windows`, which a Windows shell (Git Bash, MSYS2, Cygwin) picks
| `app` | Windows only: anything under `windows/src/TablePro.App` changed, before `ui`; the Native AOT publish CI tests |
| `ui [filter]` | Windows only: the change is visible in the app, or a flow the UI tests cover changed |

- Pick tests by what you changed: `src/<Name>` has its tests in `tests/<Name>.Tests` where that folder exists. `TablePro.Graphics` is reached through `TablePro.DataGrid.Tests`, and `TablePro.Editor` and `TablePro.App` through the UI tests. A core crate has its tests in its own folder.
- On macOS or Linux, `build`, `test`, `core` and `bindings` run. `app`, `ui` and `TablePro.DataGrid.Tests` report INCONCLUSIVE there: the pull request's `windows / Windows (x64)` and `windows / Windows (Arm64)` jobs run them.
- Pick tests by what you changed: `src/<Name>` has its tests in `tests/<Name>.Tests` where that folder exists. `TablePro.Graphics` is reached through `TablePro.DataGrid.Tests` and `TablePro.Editor.Tests`, `TablePro.Editor` through `TablePro.Editor.Tests` and the UI tests, and `TablePro.App` through the UI tests. A core crate has its tests in its own folder.
- On macOS or Linux, `build`, `test`, `core` and `bindings` run. `app`, `ui`, `TablePro.DataGrid.Tests` and `TablePro.Editor.Tests` report INCONCLUSIVE there: the pull request's `windows / Windows (x64)` and `windows / Windows (Arm64)` jobs run them.
- There is no lint step: `windows.yml` runs none. `build` is the lint, since `windows/Directory.Build.props` turns on the latest recommended analyzers and the `.editorconfig` style with warnings as errors.
- Extra review pass: none beyond the security pass.
- Traps and remedies: `references/verification-windows.md`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Read this when a `verify.sh` verdict needs interpreting for the Windows app, bef

- **A filter that matches nothing exits 8**, "Zero tests ran". The wrapper reports it as INCONCLUSIVE; check the executed count anyway.
- **A bare filter word matches part of a test's full name**, namespace and class included, through `--filter-method "*<word>*"`. xunit's own options go after `--`: `--filter-class`, `--filter-trait "Needs=Core"`, `--filter-query`.
- **`TablePro.DataGrid.Tests` runs on Windows only.** Its csproj turns `IsTestProject` off elsewhere, so the solution's run on a Mac compiles it and runs the other four projects: fewer cases than CI counts on Windows.
- **`TablePro.DataGrid.Tests` and `TablePro.Editor.Tests` run on Windows only.** Their csproj files turn `IsTestProject` off elsewhere, so the solution's run on a Mac compiles them and runs the other four projects: fewer cases than CI counts on Windows.
- **The `Needs=Core` tests load the real core** that the build copied beside the test assembly. They run on every runner.
- **Cargo exits 101 for a compile error and for a failed test.** The `core` step tells them apart by whether a test binary ran. A filter that matches nothing exits 0 with "0 passed", which the wrapper reports as INCONCLUSIVE.
- **`core` passes `--target <host triple>`**, as the csproj and `core.yml` do, so it reuses the build instead of compiling the core again into `target/debug`.
Expand Down
2 changes: 1 addition & 1 deletion .claude/skills/fix-issue/scripts/lib/platform-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ platform_step() {
else
report_dotnet_tests "$log" "$filtered" "$code"
if [ -z "$project" ] && ! on_windows; then
note "TablePro.DataGrid.Tests compiled but did not run: it runs on Windows"
note "TablePro.DataGrid.Tests and TablePro.Editor.Tests compiled but did not run: they run on Windows"
fi
fi
diagnose_environment "$log" && STATUS=INCONCLUSIVE
Expand Down
2 changes: 1 addition & 1 deletion core/crates/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub use row_edits::{
};
pub use run::{QueryRun, RunEvent, RunListener, RunOutcome, TransactionStateTag, TruncationTag};
pub use safe_mode_gate::RunGate;
pub use session::{ColumnSort, DatabaseSession, FailureCauseTag, SessionHealthTag, TablePageRead};
pub use session::{ColumnSort, DatabaseSession, FailureCauseTag, RowEstimate, SessionHealthTag, TablePageRead};
pub use statement_at::StatementSpan;
pub use structure::{StructureColumn, StructureForeignKey, StructureIndex, TableStructure};

Expand Down
42 changes: 41 additions & 1 deletion core/crates/ffi/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Instant;

use tablepro_core::browse::{PageRequest, PagingMode, SortKey, build_count, build_page, paging_mode, read_page};
use tablepro_core::filter::FilterSet;
use tablepro_core::meta::{ObjectInfo, ObjectScope, PagePosition, RowIdentity, TableRef};
use tablepro_core::meta::{ObjectInfo, ObjectScope, PagePosition, RowCountEstimate, RowIdentity, TableRef};
use tablepro_core::sql_syntax::{SortReference, sort_reference, with_order_by};
use tablepro_core::{ByteLimit, ColumnInfo, EditorSessionOptions, QueryResult, ResultEvent, ResultSink, Truncation};
use tablepro_session::runtime::{Tasks, catch_panic};
Expand Down Expand Up @@ -62,6 +62,25 @@ impl std::fmt::Debug for TablePageRead {
}
}

// The engine's own idea of a table's rows, read from its statistics with no scan. Exact where it keeps the count.
#[derive(Debug, Clone, Copy, PartialEq, Eq, uniffi::Enum)]
pub enum RowEstimate {
Exact { rows: u64 },
Approximate { rows: u64 },
// No statistics for the table, as SQLite before ANALYZE.
Unknown,
}

impl From<RowCountEstimate> for RowEstimate {
fn from(estimate: RowCountEstimate) -> Self {
match estimate {
RowCountEstimate::Exact(rows) => Self::Exact { rows },
RowCountEstimate::Approximate(rows) => Self::Approximate { rows },
RowCountEstimate::Unknown => Self::Unknown,
}
}
}

// How the session's connection is doing. A reconnect replaces it on its own; a failed one waits for reconnect().
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
pub enum SessionHealthTag {
Expand Down Expand Up @@ -263,6 +282,27 @@ impl DatabaseSession {
.await
}

// Of the whole table, so it says nothing exact about a filtered view; the app decides from it whether to count.
pub async fn table_row_estimate(
&self,
table: TableName,
cancel: Option<Arc<CancelToken>>,
) -> Result<RowEstimate, CoreError> {
let session = self.session.clone();
let cancel = token(cancel);
on_runtime(&self.tasks, async move {
let table: TableRef = table.into();
let estimate = session
.run_cancellable(OperationKind::Metadata, &cancel, |lease, options| {
let table = table.clone();
async move { Ok(lease.table_estimate(&table, options).await?) }
})
.await?;
Ok(RowEstimate::from(estimate.rows))
})
.await
}

// The table as the server defines it now. `kind` decides whether a CREATE script belongs: a view gets none.
pub async fn table_structure(
&self,
Expand Down
28 changes: 24 additions & 4 deletions core/crates/ffi/tests/browse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::time::{Duration, Instant};
use secrecy::SecretString;
use tablepro_ffi::{
ColumnSort, CombinatorTag, Core, CoreError, DatabaseSession, FileOpenRequest, FilterOpTag, FilterRuleArg,
FilterValueArg, HostConfig, HostSecretError, HostSecrets, ObjectEntry, ObjectKindTag, ObjectScopeArg, RunEvent,
RunListener, RunOutcome, RunSettings, SecretItemTag, SecretKindTag, TableFilterArg, TableName, TablePageRead,
TransactionStateTag, TruncationTag,
FilterValueArg, HostConfig, HostSecretError, HostSecrets, ObjectEntry, ObjectKindTag, ObjectScopeArg, RowEstimate,
RunEvent, RunListener, RunOutcome, RunSettings, SecretItemTag, SecretKindTag, TableFilterArg, TableName,
TablePageRead, TransactionStateTag, TruncationTag,
};

struct NoSecrets;
Expand Down Expand Up @@ -86,12 +86,17 @@ async fn fixture(dir: &Path, sql: &str) -> (Arc<Core>, Arc<DatabaseSession>) {
create: true,
};
let session = core.open_file(request, None).await.unwrap();
execute(&session, sql).await;
(core, session)
}

// On an editor of its own, closed before the test reads through the session.
async fn execute(session: &DatabaseSession, sql: &str) {
let editor = session.open_editor(None).await.unwrap();
let run = editor.run(sql.to_owned(), RunSettings::default(), Box::new(Quiet));
let outcome = run.outcome().await.unwrap();
assert!(matches!(outcome, RunOutcome::Completed { .. }), "{outcome:?}");
editor.close().await.unwrap();
(core, session)
}

fn table(name: &str) -> TableName {
Expand Down Expand Up @@ -229,6 +234,21 @@ async fn contains_finds_a_percent_sign_as_typed_and_like_keeps_the_users_wildcar
assert_eq!(liked, texts(&["50% off", "500 units"]));
}

#[tokio::test]
async fn a_tables_estimate_is_unknown_until_analyze_writes_its_statistics() {
let dir = tempfile::tempdir().unwrap();
let (_core, session) = fixture(dir.path(), PEOPLE).await;

let before = session.table_row_estimate(table("people"), None).await.unwrap();
// ANALYZE writes sqlite_stat1, whose row for the index starts with the table's row count.
execute(&session, "CREATE INDEX people_by_age ON people (age); ANALYZE").await;
let after = session.table_row_estimate(table("people"), None).await.unwrap();
session.close().await.unwrap();

assert_eq!(before, RowEstimate::Unknown);
assert_eq!(after, RowEstimate::Approximate { rows: 7 });
}

#[tokio::test]
async fn a_filter_on_a_column_the_table_lacks_is_refused_before_any_read() {
let dir = tempfile::tempdir().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion core/docs/decisions/0022-browsing-through-the-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The Windows app reaches the core only through `crates/ffi`. A table tab read its
The FFI exposes what the Linux app calls, and does the work the Linux app does, so an app on it builds no SQL and keeps no store of its own.

- `DatabaseSession::read_table_page` reads the catalog's columns and the row identity, builds the page once with the filter so a value the column cannot take or a column the table lacks fails the call before anything is sent, then reads it with `browse::read_page` on a pooled connection (`OperationKind::Page`). The rows arrive as the run events an editor run gives (`ResultSetStarted`, `RowsAppended`, `ResultSetFinished`, `Finished` with an idle transaction), so a host shows a page and a query result the same way. `table_query` is gone, and a table tab no longer holds an editor connection.
- `table_row_count` takes the same filter. `filter_choices` gives each column's operators from `SqlDialect::filter_operators`, the engine's combinators, and whether it takes a raw SQL predicate, which `validate_raw_predicate` reads as exactly one expression. MongoDB's raw filter is a query document, not SQL, so it is not offered there yet, and raw text for an engine that is not SQL is refused (`filter.raw_unsupported`).
- `table_row_count` takes the same filter. `table_row_estimate` gives the whole table's rows from `Connection::table_estimate` as `RowEstimate` (exact, approximate or unknown), on a pooled connection (`OperationKind::Metadata`), so a host decides whether to count as the Linux pager does. `filter_choices` gives each column's operators from `SqlDialect::filter_operators`, the engine's combinators, and whether it takes a raw SQL predicate, which `validate_raw_predicate` reads as exactly one expression. MongoDB's raw filter is a query document, not SQL, so it is not offered there yet, and raw text for an engine that is not SQL is refused (`filter.raw_unsupported`).
- A refused filter carries the codes of each layer: `operation.browse`, `browse.filter`, the rule's `filter.*`, and for a value the column cannot take, the parse's `edit.*` (`BrowseSqlError::codes`, `BuildFilterError::codes`).
- `table_structure` reads `fetch_table_definition` and gives its columns, indexes and foreign keys as display text, and the CREATE script from `DdlDialect::create_table_script` only for a table or a partitioned table, by the kind the catalog lists it under where it has one: on some engines the script for a view would be a CREATE TABLE made from its columns.
- `QueryEditor::use_database` moves an editor's connection to a database, for a definition whose text names none (MySQL's), as the Linux app opens such a definition.
Expand Down
4 changes: 2 additions & 2 deletions windows/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This is the guide for work under `windows/`. The root `AGENTS.md` holds the rule
- `src/TablePro.Editor`: the `SqlEditor` control over that model: Direct2D and DirectWrite in a SwapChainPanel, TSF, the UIA text provider, and the core's lexer through `CoreSqlLexer`.
- `src/TablePro.DataGrid.Model`: the grid's columns, selection, keys, cell blocks read from the core (`ResultSetData`), pending edits laid over them (`EditedGridData`) and Excel-style copy. Plain `net10.0`, so `tests/TablePro.DataGrid.Model.Tests` runs anywhere; its `Needs=Core` tests load the real core.
- `src/TablePro.DataGrid`: the `DataGridView` control: ItemsRepeater rows that draw their cells with DirectWrite into composition surfaces, frozen columns, the header row, in-place cell editing with pending-change marks, and UIA peers.
- `tests/TablePro.DataGrid.Tests`: the control in a real WinUI window on a thread of its own. It runs on Windows and only compiles elsewhere.
- `tests/TablePro.DataGrid.Tests` and `tests/TablePro.Editor.Tests`: each control in a real WinUI window on a thread of its own, the app and window from `tests/Shared/WinUiApp.cs`. They run on Windows and only compile elsewhere.
- `tests/TablePro.DataGrid.Gate` and `tests/TablePro.DataGrid.Gate.Uia`: the grid's timing and behavior gate, outside the solution. `ci/run-gate.ps1` builds and runs it; `.github/workflows/windows-grid-gate.yml` runs it by dispatch.
- `src/TablePro.App`: the WinUI app: one window, the rail, the Connections page, the connection form window, Settings and a workspace per connection (`docs/decisions/0004-app-shell.md`). Strings are in `Strings/en-US/Resources.resw`.
- `src/TablePro.App.Model`: the app's settings and session files, the library tree, the connection form's fields, the object folders, the tab and connection lifecycles over small session, editor and run interfaces, and a table tab's pending edits. Plain `net10.0`, so `tests/TablePro.App.Model.Tests` runs anywhere.
Expand All @@ -41,7 +41,7 @@ This is the guide for work under `windows/`. The root `AGENTS.md` holds the rule
- `QueryEditor.Run` returns at once. Read the run's events with `ReadEventsAsync` on the UI thread; rows that arrive while it is busy come as one event.
- A grid reads a `ResultSet` through `ResultCursor.Fetch`, one window per visible range. A cursor belongs to one thread, and a window cannot be read after the cursor's next fetch.
- `DataGridView.SetData(new ResultSetData(set, columns))` shows a set. Call the grid's `RowsChanged` after each `RowsAppended`. Sorting is the host's: the grid raises `SortRequested` and shows `Sort`.
- The core writes every sorted statement: `ReadTablePageAsync` reads a table's page with its sort and filter on a pooled connection and returns its run, `SortedQuery` writes a query result's, null when the statement cannot run again or the engine cannot name the column. `ResultSet.SortedAsync` then sorts the rows held (`core/docs/decisions/0007-sorting-a-result.md`). `ReadTablePageAsync` takes the page's offset, and `CanSeek` says whether the engine has later pages; `CountRowsAsync` counts the rows the filter picks. The filter's values are bound by the core, never written into SQL here (`core/docs/decisions/0022-browsing-through-the-ffi.md`).
- The core writes every sorted statement: `ReadTablePageAsync` reads a table's page with its sort and filter on a pooled connection and returns its run, `SortedQuery` writes a query result's, null when the statement cannot run again or the engine cannot name the column. `ResultSet.SortedAsync` then sorts the rows held (`core/docs/decisions/0007-sorting-a-result.md`). `ReadTablePageAsync` takes the page's offset, and `CanSeek` says whether the engine has later pages; `CountRowsAsync` counts the rows the filter picks, and `EstimateRowsAsync` gives the whole table's count from the engine's statistics, null where it keeps none. The filter's values are bound by the core, never written into SQL here (`core/docs/decisions/0022-browsing-through-the-ffi.md`).
- `GetStructureAsync` gives a table's columns, indexes, foreign keys and CREATE script, `GetObjectDefinitionAsync` a routine's, trigger's or sequence's source, `ExportRowsAsync` and `ExportTableAsync` write a file through the core's encoders, and `TableProCore.OpenHistoryAsync` the query history, which withholds what the engine says holds a secret.
- A table tab edits through `DatabaseSession.OpenTableEditorAsync`: the app sends what was typed (`CellEdit`) per row of the page's `ResultSet`, and `TableEditor.Plan` gives a `RowSave` with its statements and Safe Mode gate, which `RunAsync` saves (`core/docs/decisions/0019-row-edits-through-the-ffi.md`).
- `QueryEvent.Finished.Transaction` is the transaction the editor's connection is left in. A session's `Health` is waited on with `WaitForHealthChangeAsync`, which returns once it differs from the one passed in.
Expand Down
7 changes: 6 additions & 1 deletion windows/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<!-- The app's PrunePackageReference reads it too, so a bump cannot bring the metapackage back. -->
<WindowsAppSdkVersion>2.6.4</WindowsAppSdkVersion>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.2.251219" />
<PackageVersion Include="CommunityToolkit.WinUI.Controls.Sizers" Version="8.2.251219" />
<PackageVersion Include="FlaUI.UIA3" Version="5.0.0" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.28000.2957" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="2.6.4" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools.MSIX" Version="1.7.251221100" />
<!-- The test hosts only, which ship nothing; the app and its libraries take the WinUI component (docs/decisions/0005-distribution.md). -->
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="$(WindowsAppSdkVersion)" />
<PackageVersion Include="Microsoft.WindowsAppSDK.WinUI" Version="$(WindowsAppSdkVersion)" />
<PackageVersion Include="TerraFX.Interop.Windows" Version="10.0.26100.6" />
<PackageVersion Include="xunit.v3" Version="4.0.2" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions windows/TablePro.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Project Path="tests/TablePro.DataGrid.Model.Tests/TablePro.DataGrid.Model.Tests.csproj" />
<Project Path="tests/TablePro.DataGrid.Tests/TablePro.DataGrid.Tests.csproj" />
<Project Path="tests/TablePro.Editor.Model.Tests/TablePro.Editor.Model.Tests.csproj" />
<Project Path="tests/TablePro.Editor.Tests/TablePro.Editor.Tests.csproj" />
<Project Path="tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj" />
</Folder>
</Solution>
Loading
Loading