From 59dd76a7ccf82faed4c167fc87b851ea438800ff Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 12:31:10 +0700 Subject: [PATCH 1/8] test(windows): connect to MySQL, SQL Server, DuckDB, ClickHouse, Cassandra, MongoDB and Redis through the FFI --- .github/workflows/windows.yml | 59 ++++ Cargo.lock | 2 + .../tests/integration/value_corpus.rs | 73 +---- .../tests/integration/value_corpus.rs | 77 +---- .../duckdb/tests/integration/value_corpus.rs | 135 +------- .../mssql/tests/integration/value_corpus.rs | 112 +------ .../mssql/tests/windows/sql-server.ps1 | 9 +- .../mysql/tests/integration/value_corpus.rs | 130 +------- .../tests/integration/value_corpus.rs | 194 +----------- .../sqlite/tests/integration/value_corpus.rs | 53 +--- core/crates/test-support/Cargo.toml | 2 + .../crates/test-support/corpus/cassandra.json | 161 ++++++++++ .../test-support/corpus/clickhouse.json | 170 ++++++++++ core/crates/test-support/corpus/duckdb.json | 229 ++++++++++++++ core/crates/test-support/corpus/mssql.json | 178 +++++++++++ core/crates/test-support/corpus/mysql.json | 216 +++++++++++++ core/crates/test-support/corpus/postgres.json | 261 +++++++++++++++ core/crates/test-support/corpus/sqlite.json | 98 ++++++ .../src/conformance/cases/round_trip.rs | 6 +- .../src/conformance/cases/value_corpus.rs | 28 +- .../src/conformance/corpus_column.rs | 166 +++++++--- .../test-support/src/conformance/mod.rs | 2 +- .../src/conformance/value_corpus_engine.rs | 5 +- windows/ci/live-servers.ps1 | 144 +++++++++ .../Live/CassandraTests.cs | 34 ++ .../Live/ClickHouseTests.cs | 33 ++ .../Live/DuckDbTests.cs | 19 ++ .../TablePro.Interop.Tests/Live/LiveServer.cs | 32 ++ .../Live/MongoDbTests.cs | 198 ++++++++++++ .../TablePro.Interop.Tests/Live/MySqlTests.cs | 29 ++ .../TablePro.Interop.Tests/Live/RedisTests.cs | 119 +++++++ .../Live/SqlEngineTests.cs | 297 ++++++++++++++++++ .../Live/SqlServerTests.cs | 62 ++++ .../Live/ValueCorpus.cs | 23 ++ .../TablePro.Interop.Tests.csproj | 1 + 35 files changed, 2544 insertions(+), 813 deletions(-) create mode 100644 core/crates/test-support/corpus/cassandra.json create mode 100644 core/crates/test-support/corpus/clickhouse.json create mode 100644 core/crates/test-support/corpus/duckdb.json create mode 100644 core/crates/test-support/corpus/mssql.json create mode 100644 core/crates/test-support/corpus/mysql.json create mode 100644 core/crates/test-support/corpus/postgres.json create mode 100644 core/crates/test-support/corpus/sqlite.json create mode 100644 windows/ci/live-servers.ps1 create mode 100644 windows/tests/TablePro.Interop.Tests/Live/CassandraTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/ClickHouseTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/DuckDbTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/MySqlTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs create mode 100644 windows/tests/TablePro.Interop.Tests/Live/ValueCorpus.cs diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index e298071914..1ca8a57a47 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -193,3 +193,62 @@ jobs: exit 1 fi + live: + name: Windows live servers (x64) + # The engines the interop tests reach on a server, beside the x64 job so the budget holds + # (windows/docs/decisions/0013-live-server-tests.md). + runs-on: windows-2025 + timeout-minutes: 60 + env: + RUSTFLAGS: -D warnings + AWS_LC_SYS_PREBUILT_NASM: "1" + DOTNET_CLI_TELEMETRY_OPTOUT: "1" + DOTNET_NOLOGO: "1" + defaults: + run: + shell: pwsh + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + - uses: dtolnay/rust-toolchain@683b588c487a69d01f6c6ddf40f036ff682cc2c8 # master + with: + toolchain: "1.98" + targets: x86_64-pc-windows-msvc + # The x64 test job's cache, which builds the same core: its key is its key input and job id, and this job only reads it. + - uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2.9.3 + with: + shared-key: windows-x86_64-pc-windows-msvc-test + save-if: false + - name: Drop the emptied DuckDB sources + shell: bash + run: rm -rf target/x86_64-pc-windows-msvc/duckdb-sources target/duckdb-sources + - uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 + with: + dotnet-version: 10.0.x + - name: Start MySQL + run: windows/ci/live-servers.ps1 -Server MySql + - name: Start MongoDB + run: windows/ci/live-servers.ps1 -Server MongoDb + - name: Start Redis + run: windows/ci/live-servers.ps1 -Server Redis + - name: Start Cassandra + run: windows/ci/live-servers.ps1 -Server Cassandra + - name: Import a WSL 1 distribution + run: windows/ci/live-servers.ps1 -Server Wsl + - name: Start ClickHouse + run: windows/ci/live-servers.ps1 -Server ClickHouse + - name: Install SQL Server 2022 Express + run: windows/ci/live-servers.ps1 -Server SqlServer + # A missing server fails its tests rather than skipping them. + - name: Live-server tests + working-directory: windows + shell: bash + run: dotnet test --project tests/TablePro.Interop.Tests -- --filter-namespace TablePro.Interop.Tests.Live --fail-skips on + - name: The servers' logs + if: failure() + run: | + Get-Content (Join-Path $env:RUNNER_TEMP 'mysqld.log') -Tail 60 -ErrorAction Continue + Get-Content (Join-Path $env:RUNNER_TEMP 'cassandra.log') -Tail 80 -ErrorAction Continue + wsl --distribution tablepro --user root -- tail -n 80 /var/lib/clickhouse/server.log + Get-Content "$env:ProgramFiles\MongoDB\Server\7.0\log\mongod.log" -Tail 40 -ErrorAction Continue diff --git a/Cargo.lock b/Cargo.lock index eac7c32deb..3b315fee1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8187,6 +8187,8 @@ dependencies = [ "async-trait", "futures", "secrecy", + "serde", + "serde_json", "tablepro-core", "tablepro-net", "tempfile", diff --git a/core/crates/drivers/cassandra/tests/integration/value_corpus.rs b/core/crates/drivers/cassandra/tests/integration/value_corpus.rs index e7d0b4a7dc..8494730826 100644 --- a/core/crates/drivers/cassandra/tests/integration/value_corpus.rs +++ b/core/crates/drivers/cassandra/tests/integration/value_corpus.rs @@ -1,78 +1,11 @@ -//! The CQL value corpus: every native type at its extremes, the -//! collections, and the text the grid shows for each. - -use tablepro_test_support::conformance::{CorpusColumn, ValueCorpusEngine}; +use tablepro_test_support::conformance::{ValueCorpus, ValueCorpusEngine}; use crate::conformance_engine::CqlEngine; use crate::support::Server; impl ValueCorpusEngine for CqlEngine { - fn value_corpus(&self) -> Vec { - vec![ - CorpusColumn::new("v int") - .shows("-2147483648", "-2147483648") - .shows("2147483647", "2147483647") - .null(), - CorpusColumn::new("v bigint") - .shows("-9223372036854775808", "-9223372036854775808") - .shows("9223372036854775807", "9223372036854775807"), - CorpusColumn::new("v smallint").shows("-32768", "-32768"), - CorpusColumn::new("v tinyint").shows("127", "127"), - CorpusColumn::new("v varint").shows( - "-123456789012345678901234567890123456789", - "-123456789012345678901234567890123456789", - ), - CorpusColumn::new("v decimal") - .shows("-12345.6789", "-12345.6789") - .shows("0.10", "0.10") - .null(), - CorpusColumn::new("v float").shows("1.5", "1.5"), - CorpusColumn::new("v double") - .shows("0.1", "0.1") - .shows("NaN", "NaN") - .shows("-Infinity", "-Infinity"), - CorpusColumn::new("v boolean") - .shows("true", "true") - .shows("false", "false"), - CorpusColumn::new("v text") - .shows("'naïve café'", "naïve café") - .shows("'日本語のテキスト'", "日本語のテキスト") - .shows("'🦀 emoji 👩‍💻'", "🦀 emoji 👩‍💻") - .shows("''", "") - .shows("'it''s'", "it's") - .null(), - CorpusColumn::new("v ascii").shows("'plain'", "plain"), - CorpusColumn::new("v blob") - .shows("0xff00fe", "0xff00fe") - .shows("0x", "0x"), - CorpusColumn::new("v uuid") - .shows( - "123e4567-e89b-12d3-a456-426614174000", - "123e4567-e89b-12d3-a456-426614174000", - ) - .null(), - CorpusColumn::new("v timeuuid").shows( - "50554d6e-29bb-11e5-b345-feff819cdc9f", - "50554d6e-29bb-11e5-b345-feff819cdc9f", - ), - CorpusColumn::new("v inet") - .shows("'192.168.0.1'", "192.168.0.1") - .shows("'2001:db8::1'", "2001:db8::1"), - CorpusColumn::new("v date") - .shows("'1970-01-01'", "1970-01-01") - .shows("'2024-02-29'", "2024-02-29"), - CorpusColumn::new("v time") - .shows("'00:00:00'", "00:00:00.000000000") - .shows("'23:59:59.999999999'", "23:59:59.999999999"), - CorpusColumn::new("v timestamp") - .shows("'2024-02-29 12:00:00.123+0000'", "2024-02-29 12:00:00.123+00:00") - .shows("'1970-01-01 00:00:00+0000'", "1970-01-01 00:00:00.000+00:00"), - CorpusColumn::new("v duration").shows("1y2mo3d4h5m6s7ms", "P1Y2M3DT4H5M6.007S"), - CorpusColumn::new("v list").shows("[1, 2, 3]", r#"["1","2","3"]"#), - CorpusColumn::new("v set").shows("{'b', 'a'}", r#"["a","b"]"#), - CorpusColumn::new("v map").shows("{'a': 1}", "{'a': 1}"), - CorpusColumn::new("v frozen>").shows("(1, 'x')", r#"["1","x"]"#), - ] + fn value_corpus(&self) -> ValueCorpus { + ValueCorpus::Cassandra } } diff --git a/core/crates/drivers/clickhouse/tests/integration/value_corpus.rs b/core/crates/drivers/clickhouse/tests/integration/value_corpus.rs index 65b387a1bc..9cf5baa516 100644 --- a/core/crates/drivers/clickhouse/tests/integration/value_corpus.rs +++ b/core/crates/drivers/clickhouse/tests/integration/value_corpus.rs @@ -1,81 +1,10 @@ -//! ClickHouse's value corpus: the types a real schema holds, at their -//! extremes, and the text the grid shows for each. - -use tablepro_test_support::conformance::{CorpusColumn, ValueCorpusEngine}; +use tablepro_test_support::conformance::{ValueCorpus, ValueCorpusEngine}; use crate::conformance_engine::ClickHouseEngine; impl ValueCorpusEngine for ClickHouseEngine { - fn value_corpus(&self) -> Vec { - vec![ - // A DateTime prints the wall time of its column's zone. - CorpusColumn::new("COLUMN v Nullable(DateTime('Asia/Kolkata'))") - .shows("'2024-03-10 02:30:00'", "2024-03-10 02:30:00") - .shows("'1970-01-01 05:30:00'", "1970-01-01 05:30:00") - .null(), - // Nanoseconds in an Int64 end in 2262. - CorpusColumn::new("COLUMN v DateTime64(9, 'UTC')") - .shows("'1900-01-01 00:00:00.000000001'", "1900-01-01 00:00:00.000000001") - .shows("'2262-04-11 23:47:16.854775807'", "2262-04-11 23:47:16.854775807") - .shows("'2024-02-29 12:00:00'", "2024-02-29 12:00:00.000000000"), - CorpusColumn::new("COLUMN v DateTime64(3)") - .shows("'2024-01-01 00:00:00.5'", "2024-01-01 00:00:00.500") - .shows("'2299-12-31 23:59:59.999'", "2299-12-31 23:59:59.999"), - CorpusColumn::new("COLUMN v Date") - .shows("'1970-01-01'", "1970-01-01") - .shows("'2149-06-06'", "2149-06-06"), - CorpusColumn::new("COLUMN v Date32") - .shows("'1900-01-01'", "1900-01-01") - .shows("'2299-12-31'", "2299-12-31"), - CorpusColumn::new("COLUMN v Decimal(76, 38)") - .shows( - "toDecimal256('-12345678901234567890123456789012345678.12345678901234567890123456789012345678', 38)", - "-12345678901234567890123456789012345678.12345678901234567890123456789012345678", - ) - .shows("0", "0.00000000000000000000000000000000000000"), - CorpusColumn::new("COLUMN v Nullable(Decimal(9, 2))") - .shows("-1.5", "-1.50") - .null(), - CorpusColumn::new("COLUMN v Int128").shows( - "-170141183460469231731687303715884105728", - "-170141183460469231731687303715884105728", - ), - CorpusColumn::new("COLUMN v UInt256").shows( - "'115792089237316195423570985008687907853269984665640564039457584007913129639935'", - "115792089237316195423570985008687907853269984665640564039457584007913129639935", - ), - CorpusColumn::new("COLUMN v UInt64").shows("18446744073709551615", "18446744073709551615"), - CorpusColumn::new("COLUMN v Float64") - .shows("0.1", "0.1") - .shows("nan", "NaN") - .shows("-inf", "-Infinity"), - CorpusColumn::new("COLUMN v Float32").shows("1.5", "1.5"), - CorpusColumn::new("COLUMN v Bool").shows("true", "true").shows("false", "false"), - CorpusColumn::new("COLUMN v Nullable(UUID)") - .shows( - "'123e4567-e89b-12d3-a456-426614174000'", - "123e4567-e89b-12d3-a456-426614174000", - ) - .null(), - CorpusColumn::new("COLUMN v IPv4").shows("'192.168.0.1'", "192.168.0.1"), - CorpusColumn::new("COLUMN v IPv6").shows("'2001:db8::1'", "2001:db8::1"), - CorpusColumn::new("COLUMN v Enum8('a' = 1, 'b c' = 2)").shows("'b c'", "b c"), - CorpusColumn::new("COLUMN v Nullable(String)") - .shows("'naïve café'", "naïve café") - .shows("'日本語のテキスト'", "日本語のテキスト") - .shows("'🦀 emoji 👩‍💻'", "🦀 emoji 👩‍💻") - .shows("''", "") - .shows("'it\\'s'", "it's") - .shows("'line\\nbreak'", "line\nbreak") - .null(), - CorpusColumn::new("COLUMN v LowCardinality(String)").shows("'low'", "low"), - CorpusColumn::new("COLUMN v FixedString(4)").shows("'ab'", "ab\0\0"), - // A String holds bytes; ones that are not UTF-8 stay bytes. - CorpusColumn::new("COLUMN v String").shows("unhex('FF00FE')", "0xff00fe"), - CorpusColumn::new("COLUMN v Array(Nullable(Int32))").shows("[1, NULL, 3]", r#"["1",null,"3"]"#), - CorpusColumn::new("COLUMN v Map(String, UInt8)").shows("map('a', 1)", r#"{"a":1}"#), - CorpusColumn::new("COLUMN v Tuple(String, Int8)").shows("('x', -1)", r#"["x",-1]"#), - ] + fn value_corpus(&self) -> ValueCorpus { + ValueCorpus::Clickhouse } } diff --git a/core/crates/drivers/duckdb/tests/integration/value_corpus.rs b/core/crates/drivers/duckdb/tests/integration/value_corpus.rs index 874ceb145f..02ff6723be 100644 --- a/core/crates/drivers/duckdb/tests/integration/value_corpus.rs +++ b/core/crates/drivers/duckdb/tests/integration/value_corpus.rs @@ -1,142 +1,13 @@ -//! DuckDB's value corpus: its integers to 128 bits, decimals at their -//! scale, temporal values at their extremes, and the nested types a -//! table tab and an editor run read as DuckDB's own text. A UNION is not -//! here: its text names no member, so it has no SQL literal to export, -//! and `decode.rs` reads it. - -use tablepro_test_support::conformance::{CorpusColumn, ValueCorpusEngine}; +use tablepro_test_support::conformance::{ValueCorpus, ValueCorpusEngine}; use crate::duckdb_engine::DuckDbEngine; impl ValueCorpusEngine for DuckDbEngine { - fn value_corpus(&self) -> Vec { - let mut corpus = numbers(); - corpus.extend(texts()); - corpus.extend(temporal()); - corpus.extend(nested()); - corpus + fn value_corpus(&self) -> ValueCorpus { + ValueCorpus::Duckdb } } -fn numbers() -> Vec { - vec![ - CorpusColumn::new("v BOOLEAN") - .shows("true", "true") - .shows("false", "false") - .null(), - CorpusColumn::new("v TINYINT").shows("-128", "-128").shows("127", "127"), - CorpusColumn::new("v UTINYINT").shows("255", "255"), - CorpusColumn::new("v INTEGER") - .shows("2147483647", "2147483647") - .shows("-2147483648", "-2147483648"), - CorpusColumn::new("v BIGINT") - .shows("9223372036854775807", "9223372036854775807") - .shows("-9223372036854775808", "-9223372036854775808"), - CorpusColumn::new("v UBIGINT").shows("18446744073709551615", "18446744073709551615"), - CorpusColumn::new("v HUGEINT") - .shows( - "170141183460469231731687303715884105727", - "170141183460469231731687303715884105727", - ) - .shows( - "-170141183460469231731687303715884105728", - "-170141183460469231731687303715884105728", - ), - CorpusColumn::new("v UHUGEINT").shows( - "340282366920938463463374607431768211455", - "340282366920938463463374607431768211455", - ), - CorpusColumn::new("v FLOAT").shows("1.5", "1.5").shows("0.1", "0.1"), - CorpusColumn::new("v DOUBLE") - .shows("0.1", "0.1") - .shows("-2.5e-5", "-0.000025") - .shows("'nan'::DOUBLE", "NaN") - .shows("'-inf'::DOUBLE", "-Infinity"), - CorpusColumn::new("v DECIMAL(18,3)") - .shows("1.5", "1.500") - .shows("-0.001", "-0.001") - .null(), - CorpusColumn::new("v DECIMAL(38,10)") - .shows( - "1234567890123456789012345678.1234567890", - "1234567890123456789012345678.1234567890", - ) - .shows("-12.5", "-12.5000000000"), - ] -} - -fn texts() -> Vec { - vec![ - CorpusColumn::new("v VARCHAR") - .shows("'naïve café'", "naïve café") - .shows("'日本語のテキスト'", "日本語のテキスト") - .shows("'🦀 emoji 👩‍💻'", "🦀 emoji 👩‍💻") - .shows("''", "") - .shows("'it''s'", "it's") - .shows("'line' || chr(10) || 'break'", "line\nbreak") - .null(), - CorpusColumn::new("v BLOB") - .shows("'\\xDE\\xAD\\xBE\\xEF'::BLOB", "0xdeadbeef") - .shows("''::BLOB", "0x"), - CorpusColumn::new("v UUID").shows( - "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'", - "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", - ), - CorpusColumn::new("v JSON").shows(r#"'{"b": 1, "a": [1, 2.50]}'"#, r#"{"b": 1, "a": [1, 2.50]}"#), - CorpusColumn::new("v BIT").shows("'10101'", "10101").shows("'0'", "0"), - CorpusColumn::new("v ENUM('sad', 'ok', 'happy')").shows("'happy'", "happy"), - ] -} - -fn temporal() -> Vec { - vec![ - CorpusColumn::new("v DATE") - .shows("'2024-02-29'", "2024-02-29") - .shows("'0044-03-15 (BC)'", "0044-03-15 BC") - .shows("'infinity'", "infinity") - .shows("'-infinity'", "-infinity"), - CorpusColumn::new("v TIME") - .shows("'12:30:00.123456'", "12:30:00.123456") - .shows("'00:00:00'", "00:00:00"), - CorpusColumn::new("v TIMESTAMP") - .shows("'2024-02-29 12:00:00.123'", "2024-02-29 12:00:00.123") - .shows("'1999-12-31 23:59:59'", "1999-12-31 23:59:59") - .shows("'infinity'", "infinity"), - CorpusColumn::new("v TIMESTAMP_NS").shows("'2024-01-01 00:00:00.123456789'", "2024-01-01 00:00:00.123456789"), - CorpusColumn::new("v TIMESTAMP_S").shows("'2024-01-01 00:00:01'", "2024-01-01 00:00:01"), - CorpusColumn::new("v TIMESTAMPTZ") - .shows("'2024-03-10 10:30:00+02'", "2024-03-10 08:30:00+00:00") - .shows("'2024-07-01 00:00:00.5+00'", "2024-07-01 00:00:00.5+00:00"), - CorpusColumn::new("v INTERVAL") - .shows("INTERVAL '1 year 2 months 3 days 04:05:06.789'", "P1Y2M3DT4H5M6.789S") - .shows("INTERVAL '-1 day'", "P-1D"), - // Arrow carries the time alone, so an editor run cannot read it. - CorpusColumn::new("v TIMETZ").shows_apart( - "'12:30:00+05:30'", - "12:30:00+05:30", - "", - ), - ] -} - -fn nested() -> Vec { - vec![ - CorpusColumn::new("v INTEGER[]") - .shows("[1, 2, NULL]", "[1, 2, NULL]") - .shows("[]", "[]"), - CorpusColumn::new("v VARCHAR[]").shows("['a', 'b c', '', 'it''s', 'x,y']", "[a, b c, '', 'it\\'s', 'x,y']"), - CorpusColumn::new("v INTEGER[3]").shows("[1, 2, 3]", "[1, 2, 3]"), - CorpusColumn::new("v STRUCT(a INTEGER, b VARCHAR)") - .shows("{'a': 1, 'b': 'x y'}", "{'a': 1, 'b': x y}") - .null(), - CorpusColumn::new("v MAP(VARCHAR, INTEGER)").shows("MAP {'k1': 1, 'k 2': NULL}", "{k1=1, k 2=NULL}"), - CorpusColumn::new("v STRUCT(d DECIMAL(10,2), t TIMESTAMP, l DOUBLE[])").shows( - "{'d': 1.5, 't': TIMESTAMP '2024-01-01 10:00:00', 'l': [1.0, 0.1]}", - "{'d': 1.50, 't': '2024-01-01 10:00:00', 'l': [1.0, 0.1]}", - ), - ] -} - tablepro_test_support::value_corpus_suite! { engine: DuckDbEngine, docker: false, diff --git a/core/crates/drivers/mssql/tests/integration/value_corpus.rs b/core/crates/drivers/mssql/tests/integration/value_corpus.rs index 94ec342229..6f93745e0c 100644 --- a/core/crates/drivers/mssql/tests/integration/value_corpus.rs +++ b/core/crates/drivers/mssql/tests/integration/value_corpus.rs @@ -1,116 +1,10 @@ -//! SQL Server's value corpus: the types a real schema holds, at their -//! extremes, and the text the grid shows for each. -//! -//! tiberius describes a result column by its wire type alone, with no -//! scale, so an editor run shows the fraction a time value has. A -//! browse page takes the scale from the catalogue. - -use tablepro_test_support::conformance::{CorpusColumn, ValueCorpusEngine}; +use tablepro_test_support::conformance::{ValueCorpus, ValueCorpusEngine}; use crate::conformance_engine::MssqlEngine; impl ValueCorpusEngine for MssqlEngine { - fn value_corpus(&self) -> Vec { - vec![ - CorpusColumn::new("v datetime2(7)") - .shows_apart( - "'0001-01-01 00:00:00'", - "0001-01-01 00:00:00.0000000", - "0001-01-01 00:00:00", - ) - .shows("'9999-12-31 23:59:59.9999999'", "9999-12-31 23:59:59.9999999") - .shows_apart( - "'2024-02-29 12:00:00.5'", - "2024-02-29 12:00:00.5000000", - "2024-02-29 12:00:00.5", - ) - .null(), - // The offset a value was written with is the one it shows. The - // server keeps the instant in UTC, which has to stay in range. - CorpusColumn::new("v datetimeoffset(3)") - .shows_apart( - "'2024-03-10 02:30:00 -08:00'", - "2024-03-10 02:30:00.000-08:00", - "2024-03-10 02:30:00-08:00", - ) - .shows_apart( - "'0001-01-01 00:00:00 -14:00'", - "0001-01-01 00:00:00.000-14:00", - "0001-01-01 00:00:00-14:00", - ) - .shows("'9999-12-31 23:59:59.999 +14:00'", "9999-12-31 23:59:59.999+14:00"), - CorpusColumn::new("v datetime") - .shows_apart( - "'1753-01-01 00:00:00'", - "1753-01-01 00:00:00.000", - "1753-01-01 00:00:00", - ) - .shows("'9999-12-31 23:59:59.997'", "9999-12-31 23:59:59.997") - .shows("'2024-01-01 12:00:00.123'", "2024-01-01 12:00:00.123"), - CorpusColumn::new("v smalldatetime").shows("'2079-06-06 23:59:00'", "2079-06-06 23:59:00"), - CorpusColumn::new("v date") - .shows("'0001-01-01'", "0001-01-01") - .shows("'9999-12-31'", "9999-12-31"), - CorpusColumn::new("v time(7)") - .shows("'23:59:59.9999999'", "23:59:59.9999999") - .shows_apart("'00:00:00'", "00:00:00.0000000", "00:00:00"), - CorpusColumn::new("v decimal(38, 38)").shows( - "0.99999999999999999999999999999999999999", - "0.99999999999999999999999999999999999999", - ), - CorpusColumn::new("v decimal(38, 0)") - .shows( - "99999999999999999999999999999999999999", - "99999999999999999999999999999999999999", - ) - .shows( - "-99999999999999999999999999999999999999", - "-99999999999999999999999999999999999999", - ), - CorpusColumn::new("v decimal(10, 4)") - .shows("-1.5", "-1.5000") - .shows("0", "0.0000") - .null(), - // A table tab reads MONEY cast to a decimal. tiberius hands an - // editor run a float, exact only to about 5.5 * 10^11, past - // which the cell says it cannot read the value. - CorpusColumn::new("v money") - .shows("-12.34", "-12.3400") - .shows("123456789.1234", "123456789.1234") - .shows_apart("922337203685477.5807", "922337203685477.5807", "") - .shows_apart("-922337203685477.5808", "-922337203685477.5808", ""), - CorpusColumn::new("v smallmoney").shows("-214748.3648", "-214748.3648"), - // SQL Server keeps the first three groups little-endian, so a - // reader that takes the bytes in order scrambles them. - CorpusColumn::new("v uniqueidentifier") - .shows( - "'6F9619FF-8B86-D011-B42D-00C04FC964FF'", - "6f9619ff-8b86-d011-b42d-00c04fc964ff", - ) - .null(), - CorpusColumn::new("v nvarchar(100)") - .shows("N'naïve café'", "naïve café") - .shows("N'日本語のテキスト'", "日本語のテキスト") - .shows("N'🦀 emoji 👩‍💻'", "🦀 emoji 👩‍💻") - .shows("N''", "") - .shows("N'it''s'", "it's") - .null(), - CorpusColumn::new("v varchar(50) COLLATE Latin1_General_CI_AS").shows("'café'", "café"), - CorpusColumn::new("v nchar(5)").shows("N'ab'", "ab "), - CorpusColumn::new("v nvarchar(max)").shows("N'line' + NCHAR(10) + N'break'", "line\nbreak"), - CorpusColumn::new("v varbinary(max)") - .shows("0xDEADBEEF", "0xdeadbeef") - .shows("0x", "0x"), - CorpusColumn::new("v binary(4)").shows("0x01", "0x01000000"), - CorpusColumn::new("v bit").shows("1", "true").shows("0", "false").null(), - CorpusColumn::new("v tinyint").shows("255", "255"), - CorpusColumn::new("v bigint").shows("-9223372036854775808", "-9223372036854775808"), - CorpusColumn::new("v real").shows("1.5", "1.5").shows("-0.1", "-0.1"), - CorpusColumn::new("v float") - .shows("0.1", "0.1") - .shows("-2.5e-5", "-0.000025"), - CorpusColumn::new("v xml").shows("'1'", "1"), - ] + fn value_corpus(&self) -> ValueCorpus { + ValueCorpus::Mssql } } diff --git a/core/crates/drivers/mssql/tests/windows/sql-server.ps1 b/core/crates/drivers/mssql/tests/windows/sql-server.ps1 index 67a7b0b259..d7aba5655a 100644 --- a/core/crates/drivers/mssql/tests/windows/sql-server.ps1 +++ b/core/crates/drivers/mssql/tests/windows/sql-server.ps1 @@ -1,8 +1,10 @@ -# SQL Server 2022 Express CU1 for tests/integration/windows_server.rs. -Install: TCP 1433, Windows logins, the -# current account as sysadmin, a self-signed certificate written as PEM to TABLEPRO_TEST_MSSQL_WINDOWS_CA and -# trusted by no Windows store. -ForceStrict: only TDS 8.0 logins get in. +# SQL Server 2022 Express CU1 for tests/integration/windows_server.rs and windows/ci/live-servers.ps1. -Install: TCP 1433, +# Windows logins, the current account as sysadmin, a self-signed certificate written as PEM to +# TABLEPRO_TEST_MSSQL_WINDOWS_CA and trusted by no Windows store; -SaPassword adds SQL logins, sa with that password. +# -ForceStrict: only TDS 8.0 logins get in. param( [switch]$Install, + [string]$SaPassword, [switch]$ForceStrict ) @@ -38,6 +40,7 @@ if ($Install) { "/SQLSYSADMINACCOUNTS=$account", '/TCPENABLED=1', '/UPDATEENABLED=0', '/IACCEPTSQLSERVERLICENSETERMS', '/SUPPRESSPRIVACYSTATEMENTNOTICE' ) + if ($SaPassword) { $setup += '/SECURITYMODE=SQL', "/SAPWD=$SaPassword" } $process = Start-Process (Join-Path $extract 'setup.exe') -ArgumentList $setup -Wait -PassThru -NoNewWindow if ($process.ExitCode -ne 0) { Get-Content 'C:\Program Files\Microsoft SQL Server\160\Setup Bootstrap\Log\Summary.txt' diff --git a/core/crates/drivers/mysql/tests/integration/value_corpus.rs b/core/crates/drivers/mysql/tests/integration/value_corpus.rs index d99389fa7a..861fbadc8c 100644 --- a/core/crates/drivers/mysql/tests/integration/value_corpus.rs +++ b/core/crates/drivers/mysql/tests/integration/value_corpus.rs @@ -1,135 +1,17 @@ -//! The value corpus on MySQL and MariaDB: the types a real schema holds, -//! at their extremes, and the text the grid shows for each. -//! -//! sqlx gives a result column no fractional digits and no BIT length, -//! so an editor run shows the fraction a value has and a BIT in the -//! whole bytes it arrived in. A browse page takes both from the -//! catalogue. - use tablepro_test_fixtures::MysqlFlavour; -use tablepro_test_support::conformance::{CorpusColumn, ValueCorpusEngine}; +use tablepro_test_support::conformance::{ValueCorpus, ValueCorpusEngine}; use crate::conformance_engine::{MySqlEngine, Server}; impl ValueCorpusEngine for MySqlEngine { - fn value_corpus(&self) -> Vec { - let flavoured = match S::FLAVOUR { - // MySQL keeps JSON in a binary form of its own, so it prints - // the document again, keys sorted and numbers normalised, as - // the mysql client shows it. - MysqlFlavour::Mysql => vec![ - CorpusColumn::new("v JSON") - .shows( - r#"'{"b": 1, "a": [1, 2.50, "x"], "ü": null}'"#, - r#"{"a": [1, 2.5, "x"], "b": 1, "ü": null}"#, - ) - .shows("'[]'", "[]") - .null(), - CorpusColumn::new("v BINARY(16)").shows( - "UUID_TO_BIN('123e4567-e89b-12d3-a456-426614174000')", - "0x123e4567e89b12d3a456426614174000", - ), - ], - // MariaDB's JSON is LONGTEXT with a check, kept as written. - MysqlFlavour::Mariadb => vec![ - CorpusColumn::new("v JSON") - .shows(r#"'{"b": 1, "a": [1, 2.50, "x"]}'"#, r#"{"b": 1, "a": [1, 2.50, "x"]}"#) - .null(), - CorpusColumn::new("v UUID") - .shows( - "'123e4567-e89b-12d3-a456-426614174000'", - "123e4567-e89b-12d3-a456-426614174000", - ) - .null(), - CorpusColumn::new("v INET6").shows("'::ffff:192.0.2.1'", "::ffff:192.0.2.1"), - ], - }; - [common(), flavoured].concat() + fn value_corpus(&self) -> ValueCorpus { + match S::FLAVOUR { + MysqlFlavour::Mysql => ValueCorpus::Mysql, + MysqlFlavour::Mariadb => ValueCorpus::Mariadb, + } } } -fn common() -> Vec { - vec![ - CorpusColumn::new("v DATETIME(6)") - .shows_apart( - "'1000-01-01 00:00:00'", - "1000-01-01 00:00:00.000000", - "1000-01-01 00:00:00", - ) - .shows("'9999-12-31 23:59:59.999999'", "9999-12-31 23:59:59.999999") - .shows_apart( - "'2024-02-29 12:00:00.5'", - "2024-02-29 12:00:00.500000", - "2024-02-29 12:00:00.5", - ) - .null(), - CorpusColumn::new("v DATETIME").shows("'2024-03-10 02:30:00'", "2024-03-10 02:30:00"), - // Browse pins its session to UTC and reads an instant; the - // editor reads the wall time in the server's zone, UTC here. - CorpusColumn::new("v TIMESTAMP(3) NULL") - .shows_apart( - "'1970-01-01 00:00:01'", - "1970-01-01 00:00:01.000+00:00", - "1970-01-01 00:00:01", - ) - .shows_apart( - "'2038-01-19 03:14:07.999'", - "2038-01-19 03:14:07.999+00:00", - "2038-01-19 03:14:07.999", - ) - .null(), - CorpusColumn::new("v DATE") - .shows("'1000-01-01'", "1000-01-01") - .shows("'9999-12-31'", "9999-12-31") - .shows("'2024-02-29'", "2024-02-29"), - CorpusColumn::new("v TIME(6)") - .shows_apart("'-838:59:59'", "-838:59:59.000000", "-838:59:59") - .shows_apart("'838:59:59'", "838:59:59.000000", "838:59:59") - .shows("'00:00:00.000001'", "00:00:00.000001"), - CorpusColumn::new("v YEAR").shows("1901", "1901").shows("2155", "2155"), - CorpusColumn::new("v DECIMAL(65, 30)") - .shows( - "12345678901234567890123456789012345.123456789012345678901234567890", - "12345678901234567890123456789012345.123456789012345678901234567890", - ) - .shows("-0.000000000000000000000000000001", "-0.000000000000000000000000000001") - .shows("0", "0.000000000000000000000000000000"), - CorpusColumn::new("v DECIMAL(10, 2)") - .shows("-12345678.9", "-12345678.90") - .shows("0.5", "0.50") - .null(), - CorpusColumn::new("v BIGINT UNSIGNED").shows("18446744073709551615", "18446744073709551615"), - CorpusColumn::new("v BIGINT").shows("-9223372036854775808", "-9223372036854775808"), - CorpusColumn::new("v TINYINT UNSIGNED").shows("255", "255"), - CorpusColumn::new("v FLOAT").shows("1.5", "1.5").shows("-0.25", "-0.25"), - CorpusColumn::new("v DOUBLE") - .shows("0.1", "0.1") - .shows("-2.5e-5", "-0.000025"), - CorpusColumn::new("v VARCHAR(100)") - .shows("'naïve café'", "naïve café") - .shows("'日本語のテキスト'", "日本語のテキスト") - .shows("'🦀 emoji 👩‍💻'", "🦀 emoji 👩‍💻") - .shows("''", "") - .shows("'it''s'", "it's") - .shows("'back\\\\slash'", "back\\slash") - .null(), - CorpusColumn::new("v VARCHAR(20) CHARACTER SET latin1").shows("'café'", "café"), - CorpusColumn::new("v CHAR(5)").shows("'ab'", "ab"), - CorpusColumn::new("v TEXT").shows("'line\\nbreak'", "line\nbreak"), - CorpusColumn::new("v VARBINARY(8)") - .shows("X'DEADBEEF'", "0xdeadbeef") - .shows("X''", "0x"), - CorpusColumn::new("v BINARY(4)").shows("X'01'", "0x01000000"), - CorpusColumn::new("v BLOB").shows("X'00FF'", "0x00ff"), - CorpusColumn::new("v BIT(10)").shows_apart("b'1010101010'", "1010101010", "0000001010101010"), - CorpusColumn::new("v BIT(1)") - .shows_apart("b'1'", "1", "00000001") - .shows_apart("b'0'", "0", "00000000"), - CorpusColumn::new("v ENUM('a', 'b c')").shows("'b c'", "b c").null(), - CorpusColumn::new("v SET('x', 'y', 'z')").shows("'x,z'", "x,z"), - ] -} - mod mysql_suite { use crate::conformance_engine::{MySqlEngine, MysqlServer}; diff --git a/core/crates/drivers/postgres/tests/integration/value_corpus.rs b/core/crates/drivers/postgres/tests/integration/value_corpus.rs index a275dbbbee..f8f2c1bc4b 100644 --- a/core/crates/drivers/postgres/tests/integration/value_corpus.rs +++ b/core/crates/drivers/postgres/tests/integration/value_corpus.rs @@ -1,201 +1,13 @@ -//! PostgreSQL's value corpus: the types a real schema holds, at their -//! extremes, and the text the grid shows for each. -//! -//! A browse page reads values in binary and the grid writes them out; an -//! editor run uses the simple query protocol, so it shows the server's -//! own text, as psql does. Where the two spell a value differently, the -//! value names both. - -use tablepro_test_support::conformance::{CorpusColumn, ValueCorpusEngine}; +use tablepro_test_support::conformance::{ValueCorpus, ValueCorpusEngine}; use crate::conformance_engine::PgEngine; impl ValueCorpusEngine for PgEngine { - fn value_corpus(&self) -> Vec { - [temporal(), numbers(), documents(), other_types()].concat() + fn value_corpus(&self) -> ValueCorpus { + ValueCorpus::Postgres } } -fn temporal() -> Vec { - vec![ - // An instant reads back in UTC whatever offset it was written - // with; the server's zone is UTC too. - CorpusColumn::new("v timestamptz") - .shows_apart( - "'2024-03-10 02:30:00-08'", - "2024-03-10 10:30:00+00:00", - "2024-03-10 10:30:00+00", - ) - .shows_apart( - "'2024-06-15 12:00:00.5+05:45'", - "2024-06-15 06:15:00.5+00:00", - "2024-06-15 06:15:00.5+00", - ) - .shows_apart( - "'1969-12-31 23:59:59.999999+00'", - "1969-12-31 23:59:59.999999+00:00", - "1969-12-31 23:59:59.999999+00", - ) - .shows_apart( - "'0001-01-01 00:00:00+00'", - "0001-01-01 00:00:00+00:00", - "0001-01-01 00:00:00+00", - ) - .shows_apart( - "'4713-01-01 00:00:00+00 BC'", - "4713-01-01 00:00:00+00:00 BC", - "4713-01-01 00:00:00+00 BC", - ) - .shows("'infinity'", "infinity") - .shows("'-infinity'", "-infinity") - .null(), - CorpusColumn::new("v timestamp(3)") - .shows("'2024-02-29 23:59:59.999'", "2024-02-29 23:59:59.999") - .shows_apart( - "'2000-01-01 00:00:00'", - "2000-01-01 00:00:00.000", - "2000-01-01 00:00:00", - ) - .shows("'1900-01-01 00:00:00.001'", "1900-01-01 00:00:00.001"), - CorpusColumn::new("v timestamp") - .shows("'294276-12-31 23:59:59.999999'", "294276-12-31 23:59:59.999999") - .shows("'1999-12-31 23:59:59.5'", "1999-12-31 23:59:59.5"), - CorpusColumn::new("v date") - .shows("'2024-02-29'", "2024-02-29") - .shows("'0001-01-01'", "0001-01-01") - .shows("'4713-01-01 BC'", "4713-01-01 BC") - .shows("'10000-01-01'", "10000-01-01") - .shows("'5874897-12-31'", "5874897-12-31") - .shows("'infinity'", "infinity") - .null(), - CorpusColumn::new("v time(6)") - .shows_apart("'00:00:00'", "00:00:00.000000", "00:00:00") - .shows("'23:59:59.999999'", "23:59:59.999999") - .shows_apart("'24:00:00'", "24:00:00.000000", "24:00:00"), - CorpusColumn::new("v timetz") - .shows("'12:34:56+05:30'", "12:34:56+05:30") - .shows("'00:00:00.25-15:59'", "00:00:00.25-15:59"), - CorpusColumn::new("v interval") - .shows_apart( - "'1 year 2 mons 3 days 04:05:06.789'", - "P1Y2M3DT4H5M6.789S", - "1 year 2 mons 3 days 04:05:06.789", - ) - .shows_apart("'-1 day +02:00:00'", "P-1DT2H", "-1 days +02:00:00") - .shows_apart("'0'", "PT0S", "00:00:00"), - ] -} - -fn numbers() -> Vec { - vec![ - CorpusColumn::new("v numeric(38, 10)") - .shows("12345678901234567890.1234567890", "12345678901234567890.1234567890") - .shows("-0.0000000001", "-0.0000000001") - .shows("1.5", "1.5000000000") - .shows("0", "0.0000000000") - .null(), - CorpusColumn::new("v numeric") - .shows( - "-123456789012345678901234567890.123456789", - "-123456789012345678901234567890.123456789", - ) - .shows("0.000000000000000000000000000001", "0.000000000000000000000000000001") - .shows("2.50", "2.50") - .shows("'NaN'", "NaN") - .shows("'Infinity'", "Infinity") - .shows("'-Infinity'", "-Infinity"), - CorpusColumn::new("v money") - .shows_apart("-12.34", "-12.34", "-$12.34") - .shows_apart( - "92233720368547758.07", - "92233720368547758.07", - "$92,233,720,368,547,758.07", - ), - CorpusColumn::new("v bigint") - .shows("-9223372036854775808", "-9223372036854775808") - .shows("9223372036854775807", "9223372036854775807"), - CorpusColumn::new("v smallint").shows("-32768", "-32768").null(), - CorpusColumn::new("v real") - .shows("1.5", "1.5") - .shows("-0.1", "-0.1") - .shows("'NaN'", "NaN") - .shows("'-Infinity'", "-Infinity"), - CorpusColumn::new("v double precision") - .shows("0.1", "0.1") - .shows_apart("-2.5e-5", "-0.000025", "-2.5e-05") - .shows("'Infinity'", "Infinity"), - CorpusColumn::new("v boolean") - .shows_apart("true", "true", "t") - .shows_apart("false", "false", "f") - .null(), - ] -} - -fn documents() -> Vec { - vec![ - CorpusColumn::new("v jsonb") - .shows( - r#"'{"b": 1, "a": [1, 2.50, "x"], "ü": null}'"#, - r#"{"a": [1, 2.50, "x"], "b": 1, "ü": null}"#, - ) - .shows("'[]'", "[]") - .shows(r#"'"just text"'"#, r#""just text""#), - CorpusColumn::new("v json").shows(r#"'{"b":1, "a":2}'"#, r#"{"b":1, "a":2}"#), - CorpusColumn::new("v uuid") - .shows( - "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'", - "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11", - ) - .shows( - "'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A12'", - "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12", - ) - .null(), - CorpusColumn::new("v text") - .shows("'naïve café'", "naïve café") - .shows("'日本語のテキスト'", "日本語のテキスト") - .shows("'🦀 emoji 👩‍💻'", "🦀 emoji 👩‍💻") - .shows("'עברית RTL'", "עברית RTL") - .shows("'e\u{301}'", "e\u{301}") - .shows("''", "") - .shows("E'tab\\there\\nnew line'", "tab\there\nnew line") - .shows("'it''s'", "it's") - .null(), - CorpusColumn::new("v char(5)").shows("'ab'", "ab "), - CorpusColumn::new("v varchar(10)").shows("'ünïcödé'", "ünïcödé"), - CorpusColumn::new("v bytea") - .shows_apart("'\\xdeadbeef'", "0xdeadbeef", "\\xdeadbeef") - .shows_apart("''", "0x", "\\x") - .null(), - CorpusColumn::new("v integer[]").shows_apart("'{1,NULL,3}'", r#"["1",null,"3"]"#, "{1,NULL,3}"), - CorpusColumn::new("v text[]").shows_apart( - r#"'{"a b","c,d",NULL,""}'"#, - r#"["a b","c,d",null,""]"#, - r#"{"a b","c,d",NULL,""}"#, - ), - ] -} - -fn other_types() -> Vec { - vec![ - CorpusColumn::new("v inet") - .shows("'192.168.0.1/24'", "192.168.0.1/24") - .shows("'::1'", "::1"), - CorpusColumn::new("v cidr").shows("'10.0.0.0/8'", "10.0.0.0/8"), - CorpusColumn::new("v macaddr").shows("'08:00:2B:01:02:03'", "08:00:2b:01:02:03"), - CorpusColumn::new("v corpus_mood") - .after("CREATE TYPE corpus_mood AS ENUM ('sad', 'ok', 'happy')") - .shows("'happy'", "happy"), - CorpusColumn::new("v int4range") - .shows("'[1,10)'", "[1,10)") - .shows("'empty'", "empty"), - CorpusColumn::new("v bit(4)").shows("B'1010'", "1010"), - CorpusColumn::new("v varbit(8)").shows("B'101'", "101"), - CorpusColumn::new("v point").shows("'(1.5,-2)'", "(1.5,-2)"), - CorpusColumn::new("v xml").shows("'1'", "1"), - ] -} - mod suite { use crate::conformance_engine::PgEngine; diff --git a/core/crates/drivers/sqlite/tests/integration/value_corpus.rs b/core/crates/drivers/sqlite/tests/integration/value_corpus.rs index 48490f893d..c1519130d9 100644 --- a/core/crates/drivers/sqlite/tests/integration/value_corpus.rs +++ b/core/crates/drivers/sqlite/tests/integration/value_corpus.rs @@ -1,57 +1,10 @@ -//! SQLite's value corpus. A value reads as the storage class SQLite -//! keeps it in, whatever the column declares, so the declared types -//! here are the ones real schemas use. - -use tablepro_test_support::conformance::{CorpusColumn, ValueCorpusEngine}; +use tablepro_test_support::conformance::{ValueCorpus, ValueCorpusEngine}; use crate::sqlite_engine::SqliteEngine; impl ValueCorpusEngine for SqliteEngine { - fn value_corpus(&self) -> Vec { - vec![ - CorpusColumn::new("v INTEGER") - .shows("9223372036854775807", "9223372036854775807") - .shows("-9223372036854775808", "-9223372036854775808") - .null(), - CorpusColumn::new("v REAL") - .shows("0.1", "0.1") - .shows("-2.5e-5", "-0.000025") - .shows("1", "1"), - CorpusColumn::new("v TEXT") - .shows("'naïve café'", "naïve café") - .shows("'日本語のテキスト'", "日本語のテキスト") - .shows("'🦀 emoji 👩‍💻'", "🦀 emoji 👩‍💻") - .shows("''", "") - .shows("'it''s'", "it's") - .shows("'line' || char(10) || 'break'", "line\nbreak") - .null(), - CorpusColumn::new("v BLOB") - .shows("X'DEADBEEF'", "0xdeadbeef") - .shows("X''", "0x"), - CorpusColumn::new("v NUMERIC") - .shows("'1.50'", "1.5") - .shows("'12'", "12"), - CorpusColumn::new("v DECIMAL(10, 2)").shows("-12.5", "-12.5"), - CorpusColumn::new("v DATETIME") - .shows("'2024-02-29 12:00:00.123'", "2024-02-29 12:00:00.123") - .shows("'2024-03-10T02:30:00-08:00'", "2024-03-10T02:30:00-08:00") - .shows("'2024-03-10 10:30:00Z'", "2024-03-10 10:30:00Z"), - // SQLite gives DATE, TIME and DATETIME one affinity, so each - // holds any form its date and time functions read. - CorpusColumn::new("v DATE") - .shows("'2024-02-29'", "2024-02-29") - .shows("'2024-03-10 02:30:00'", "2024-03-10 02:30:00"), - CorpusColumn::new("v TIME") - .shows("'12:30:00'", "12:30:00") - .shows("'12:30:00+05:30'", "12:30:00+05:30"), - CorpusColumn::new("v BOOLEAN").shows("1", "1").shows("0", "0"), - CorpusColumn::new("v JSON").shows(r#"'{"b": 1, "a": [1, 2.50]}'"#, r#"{"b": 1, "a": [1, 2.50]}"#), - CorpusColumn::new("v") - .shows("42", "42") - .shows("'text'", "text") - .shows("X'01'", "0x01") - .shows("1.5", "1.5"), - ] + fn value_corpus(&self) -> ValueCorpus { + ValueCorpus::Sqlite } } diff --git a/core/crates/test-support/Cargo.toml b/core/crates/test-support/Cargo.toml index 119657e5c8..0f0babcd3d 100644 --- a/core/crates/test-support/Cargo.toml +++ b/core/crates/test-support/Cargo.toml @@ -10,6 +10,8 @@ tablepro-core.workspace = true tablepro-net.workspace = true async-trait.workspace = true secrecy.workspace = true +serde.workspace = true +serde_json.workspace = true tempfile.workspace = true uuid.workspace = true futures.workspace = true diff --git a/core/crates/test-support/corpus/cassandra.json b/core/crates/test-support/corpus/cassandra.json new file mode 100644 index 0000000000..94b8d77d8e --- /dev/null +++ b/core/crates/test-support/corpus/cassandra.json @@ -0,0 +1,161 @@ +{ + "columns": [ + { + "column": "v int", + "values": [ + { "sql": "-2147483648", "shows": "-2147483648" }, + { "sql": "2147483647", "shows": "2147483647" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v bigint", + "values": [ + { "sql": "-9223372036854775808", "shows": "-9223372036854775808" }, + { "sql": "9223372036854775807", "shows": "9223372036854775807" } + ] + }, + { + "column": "v smallint", + "values": [ + { "sql": "-32768", "shows": "-32768" } + ] + }, + { + "column": "v tinyint", + "values": [ + { "sql": "127", "shows": "127" } + ] + }, + { + "column": "v varint", + "values": [ + { "sql": "-123456789012345678901234567890123456789", "shows": "-123456789012345678901234567890123456789" } + ] + }, + { + "column": "v decimal", + "values": [ + { "sql": "-12345.6789", "shows": "-12345.6789" }, + { "sql": "0.10", "shows": "0.10" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v float", + "values": [ + { "sql": "1.5", "shows": "1.5" } + ] + }, + { + "column": "v double", + "values": [ + { "sql": "0.1", "shows": "0.1" }, + { "sql": "NaN", "shows": "NaN" }, + { "sql": "-Infinity", "shows": "-Infinity" } + ] + }, + { + "column": "v boolean", + "values": [ + { "sql": "true", "shows": "true" }, + { "sql": "false", "shows": "false" } + ] + }, + { + "column": "v text", + "values": [ + { "sql": "'naïve café'", "shows": "naïve café" }, + { "sql": "'日本語のテキスト'", "shows": "日本語のテキスト" }, + { "sql": "'🦀 emoji 👩‍💻'", "shows": "🦀 emoji 👩‍💻" }, + { "sql": "''", "shows": "" }, + { "sql": "'it''s'", "shows": "it's" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v ascii", + "values": [ + { "sql": "'plain'", "shows": "plain" } + ] + }, + { + "column": "v blob", + "values": [ + { "sql": "0xff00fe", "shows": "0xff00fe" }, + { "sql": "0x", "shows": "0x" } + ] + }, + { + "column": "v uuid", + "values": [ + { "sql": "123e4567-e89b-12d3-a456-426614174000", "shows": "123e4567-e89b-12d3-a456-426614174000" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v timeuuid", + "values": [ + { "sql": "50554d6e-29bb-11e5-b345-feff819cdc9f", "shows": "50554d6e-29bb-11e5-b345-feff819cdc9f" } + ] + }, + { + "column": "v inet", + "values": [ + { "sql": "'192.168.0.1'", "shows": "192.168.0.1" }, + { "sql": "'2001:db8::1'", "shows": "2001:db8::1" } + ] + }, + { + "column": "v date", + "values": [ + { "sql": "'1970-01-01'", "shows": "1970-01-01" }, + { "sql": "'2024-02-29'", "shows": "2024-02-29" } + ] + }, + { + "column": "v time", + "values": [ + { "sql": "'00:00:00'", "shows": "00:00:00.000000000" }, + { "sql": "'23:59:59.999999999'", "shows": "23:59:59.999999999" } + ] + }, + { + "column": "v timestamp", + "values": [ + { "sql": "'2024-02-29 12:00:00.123+0000'", "shows": "2024-02-29 12:00:00.123+00:00" }, + { "sql": "'1970-01-01 00:00:00+0000'", "shows": "1970-01-01 00:00:00.000+00:00" } + ] + }, + { + "column": "v duration", + "values": [ + { "sql": "1y2mo3d4h5m6s7ms", "shows": "P1Y2M3DT4H5M6.007S" } + ] + }, + { + "column": "v list", + "values": [ + { "sql": "[1, 2, 3]", "shows": "[\"1\",\"2\",\"3\"]" } + ] + }, + { + "column": "v set", + "values": [ + { "sql": "{'b', 'a'}", "shows": "[\"a\",\"b\"]" } + ] + }, + { + "column": "v map", + "values": [ + { "sql": "{'a': 1}", "shows": "{'a': 1}" } + ] + }, + { + "column": "v frozen>", + "values": [ + { "sql": "(1, 'x')", "shows": "[\"1\",\"x\"]" } + ] + } + ] +} diff --git a/core/crates/test-support/corpus/clickhouse.json b/core/crates/test-support/corpus/clickhouse.json new file mode 100644 index 0000000000..def2e7b822 --- /dev/null +++ b/core/crates/test-support/corpus/clickhouse.json @@ -0,0 +1,170 @@ +{ + "columns": [ + { + "why": "A DateTime prints the wall time of its column's zone.", + "column": "COLUMN v Nullable(DateTime('Asia/Kolkata'))", + "values": [ + { "sql": "'2024-03-10 02:30:00'", "shows": "2024-03-10 02:30:00" }, + { "sql": "'1970-01-01 05:30:00'", "shows": "1970-01-01 05:30:00" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "why": "Nanoseconds in an Int64 end in 2262.", + "column": "COLUMN v DateTime64(9, 'UTC')", + "values": [ + { "sql": "'1900-01-01 00:00:00.000000001'", "shows": "1900-01-01 00:00:00.000000001" }, + { "sql": "'2262-04-11 23:47:16.854775807'", "shows": "2262-04-11 23:47:16.854775807" }, + { "sql": "'2024-02-29 12:00:00'", "shows": "2024-02-29 12:00:00.000000000" } + ] + }, + { + "column": "COLUMN v DateTime64(3)", + "values": [ + { "sql": "'2024-01-01 00:00:00.5'", "shows": "2024-01-01 00:00:00.500" }, + { "sql": "'2299-12-31 23:59:59.999'", "shows": "2299-12-31 23:59:59.999" } + ] + }, + { + "column": "COLUMN v Date", + "values": [ + { "sql": "'1970-01-01'", "shows": "1970-01-01" }, + { "sql": "'2149-06-06'", "shows": "2149-06-06" } + ] + }, + { + "column": "COLUMN v Date32", + "values": [ + { "sql": "'1900-01-01'", "shows": "1900-01-01" }, + { "sql": "'2299-12-31'", "shows": "2299-12-31" } + ] + }, + { + "column": "COLUMN v Decimal(76, 38)", + "values": [ + { "sql": "toDecimal256('-12345678901234567890123456789012345678.12345678901234567890123456789012345678', 38)", "shows": "-12345678901234567890123456789012345678.12345678901234567890123456789012345678" }, + { "sql": "0", "shows": "0.00000000000000000000000000000000000000" } + ] + }, + { + "column": "COLUMN v Nullable(Decimal(9, 2))", + "values": [ + { "sql": "-1.5", "shows": "-1.50" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "COLUMN v Int128", + "values": [ + { "sql": "-170141183460469231731687303715884105728", "shows": "-170141183460469231731687303715884105728" } + ] + }, + { + "column": "COLUMN v UInt256", + "values": [ + { "sql": "'115792089237316195423570985008687907853269984665640564039457584007913129639935'", "shows": "115792089237316195423570985008687907853269984665640564039457584007913129639935" } + ] + }, + { + "column": "COLUMN v UInt64", + "values": [ + { "sql": "18446744073709551615", "shows": "18446744073709551615" } + ] + }, + { + "column": "COLUMN v Float64", + "values": [ + { "sql": "0.1", "shows": "0.1" }, + { "sql": "nan", "shows": "NaN" }, + { "sql": "-inf", "shows": "-Infinity" } + ] + }, + { + "column": "COLUMN v Float32", + "values": [ + { "sql": "1.5", "shows": "1.5" } + ] + }, + { + "column": "COLUMN v Bool", + "values": [ + { "sql": "true", "shows": "true" }, + { "sql": "false", "shows": "false" } + ] + }, + { + "column": "COLUMN v Nullable(UUID)", + "values": [ + { "sql": "'123e4567-e89b-12d3-a456-426614174000'", "shows": "123e4567-e89b-12d3-a456-426614174000" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "COLUMN v IPv4", + "values": [ + { "sql": "'192.168.0.1'", "shows": "192.168.0.1" } + ] + }, + { + "column": "COLUMN v IPv6", + "values": [ + { "sql": "'2001:db8::1'", "shows": "2001:db8::1" } + ] + }, + { + "column": "COLUMN v Enum8('a' = 1, 'b c' = 2)", + "values": [ + { "sql": "'b c'", "shows": "b c" } + ] + }, + { + "column": "COLUMN v Nullable(String)", + "values": [ + { "sql": "'naïve café'", "shows": "naïve café" }, + { "sql": "'日本語のテキスト'", "shows": "日本語のテキスト" }, + { "sql": "'🦀 emoji 👩‍💻'", "shows": "🦀 emoji 👩‍💻" }, + { "sql": "''", "shows": "" }, + { "sql": "'it\\'s'", "shows": "it's" }, + { "sql": "'line\\nbreak'", "shows": "line\nbreak" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "COLUMN v LowCardinality(String)", + "values": [ + { "sql": "'low'", "shows": "low" } + ] + }, + { + "column": "COLUMN v FixedString(4)", + "values": [ + { "sql": "'ab'", "shows": "ab\u0000\u0000" } + ] + }, + { + "why": "A String holds bytes; ones that are not UTF-8 stay bytes.", + "column": "COLUMN v String", + "values": [ + { "sql": "unhex('FF00FE')", "shows": "0xff00fe" } + ] + }, + { + "column": "COLUMN v Array(Nullable(Int32))", + "values": [ + { "sql": "[1, NULL, 3]", "shows": "[\"1\",null,\"3\"]" } + ] + }, + { + "column": "COLUMN v Map(String, UInt8)", + "values": [ + { "sql": "map('a', 1)", "shows": "{\"a\":1}" } + ] + }, + { + "column": "COLUMN v Tuple(String, Int8)", + "values": [ + { "sql": "('x', -1)", "shows": "[\"x\",-1]" } + ] + } + ] +} diff --git a/core/crates/test-support/corpus/duckdb.json b/core/crates/test-support/corpus/duckdb.json new file mode 100644 index 0000000000..b654972455 --- /dev/null +++ b/core/crates/test-support/corpus/duckdb.json @@ -0,0 +1,229 @@ +{ + "why": "A UNION is not here: its text names no member, so it has no SQL literal to export, and decode.rs reads it.", + "columns": [ + { + "column": "v BOOLEAN", + "values": [ + { "sql": "true", "shows": "true" }, + { "sql": "false", "shows": "false" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v TINYINT", + "values": [ + { "sql": "-128", "shows": "-128" }, + { "sql": "127", "shows": "127" } + ] + }, + { + "column": "v UTINYINT", + "values": [ + { "sql": "255", "shows": "255" } + ] + }, + { + "column": "v INTEGER", + "values": [ + { "sql": "2147483647", "shows": "2147483647" }, + { "sql": "-2147483648", "shows": "-2147483648" } + ] + }, + { + "column": "v BIGINT", + "values": [ + { "sql": "9223372036854775807", "shows": "9223372036854775807" }, + { "sql": "-9223372036854775808", "shows": "-9223372036854775808" } + ] + }, + { + "column": "v UBIGINT", + "values": [ + { "sql": "18446744073709551615", "shows": "18446744073709551615" } + ] + }, + { + "column": "v HUGEINT", + "values": [ + { "sql": "170141183460469231731687303715884105727", "shows": "170141183460469231731687303715884105727" }, + { "sql": "-170141183460469231731687303715884105728", "shows": "-170141183460469231731687303715884105728" } + ] + }, + { + "column": "v UHUGEINT", + "values": [ + { "sql": "340282366920938463463374607431768211455", "shows": "340282366920938463463374607431768211455" } + ] + }, + { + "column": "v FLOAT", + "values": [ + { "sql": "1.5", "shows": "1.5" }, + { "sql": "0.1", "shows": "0.1" } + ] + }, + { + "column": "v DOUBLE", + "values": [ + { "sql": "0.1", "shows": "0.1" }, + { "sql": "-2.5e-5", "shows": "-0.000025" }, + { "sql": "'nan'::DOUBLE", "shows": "NaN" }, + { "sql": "'-inf'::DOUBLE", "shows": "-Infinity" } + ] + }, + { + "column": "v DECIMAL(18,3)", + "values": [ + { "sql": "1.5", "shows": "1.500" }, + { "sql": "-0.001", "shows": "-0.001" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v DECIMAL(38,10)", + "values": [ + { "sql": "1234567890123456789012345678.1234567890", "shows": "1234567890123456789012345678.1234567890" }, + { "sql": "-12.5", "shows": "-12.5000000000" } + ] + }, + { + "column": "v VARCHAR", + "values": [ + { "sql": "'naïve café'", "shows": "naïve café" }, + { "sql": "'日本語のテキスト'", "shows": "日本語のテキスト" }, + { "sql": "'🦀 emoji 👩‍💻'", "shows": "🦀 emoji 👩‍💻" }, + { "sql": "''", "shows": "" }, + { "sql": "'it''s'", "shows": "it's" }, + { "sql": "'line' || chr(10) || 'break'", "shows": "line\nbreak" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v BLOB", + "values": [ + { "sql": "'\\xDE\\xAD\\xBE\\xEF'::BLOB", "shows": "0xdeadbeef" }, + { "sql": "''::BLOB", "shows": "0x" } + ] + }, + { + "column": "v UUID", + "values": [ + { "sql": "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'", "shows": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11" } + ] + }, + { + "column": "v JSON", + "values": [ + { "sql": "'{\"b\": 1, \"a\": [1, 2.50]}'", "shows": "{\"b\": 1, \"a\": [1, 2.50]}" } + ] + }, + { + "column": "v BIT", + "values": [ + { "sql": "'10101'", "shows": "10101" }, + { "sql": "'0'", "shows": "0" } + ] + }, + { + "column": "v ENUM('sad', 'ok', 'happy')", + "values": [ + { "sql": "'happy'", "shows": "happy" } + ] + }, + { + "column": "v DATE", + "values": [ + { "sql": "'2024-02-29'", "shows": "2024-02-29" }, + { "sql": "'0044-03-15 (BC)'", "shows": "0044-03-15 BC" }, + { "sql": "'infinity'", "shows": "infinity" }, + { "sql": "'-infinity'", "shows": "-infinity" } + ] + }, + { + "column": "v TIME", + "values": [ + { "sql": "'12:30:00.123456'", "shows": "12:30:00.123456" }, + { "sql": "'00:00:00'", "shows": "00:00:00" } + ] + }, + { + "column": "v TIMESTAMP", + "values": [ + { "sql": "'2024-02-29 12:00:00.123'", "shows": "2024-02-29 12:00:00.123" }, + { "sql": "'1999-12-31 23:59:59'", "shows": "1999-12-31 23:59:59" }, + { "sql": "'infinity'", "shows": "infinity" } + ] + }, + { + "column": "v TIMESTAMP_NS", + "values": [ + { "sql": "'2024-01-01 00:00:00.123456789'", "shows": "2024-01-01 00:00:00.123456789" } + ] + }, + { + "column": "v TIMESTAMP_S", + "values": [ + { "sql": "'2024-01-01 00:00:01'", "shows": "2024-01-01 00:00:01" } + ] + }, + { + "column": "v TIMESTAMPTZ", + "values": [ + { "sql": "'2024-03-10 10:30:00+02'", "shows": "2024-03-10 08:30:00+00:00" }, + { "sql": "'2024-07-01 00:00:00.5+00'", "shows": "2024-07-01 00:00:00.5+00:00" } + ] + }, + { + "column": "v INTERVAL", + "values": [ + { "sql": "INTERVAL '1 year 2 months 3 days 04:05:06.789'", "shows": "P1Y2M3DT4H5M6.789S" }, + { "sql": "INTERVAL '-1 day'", "shows": "P-1D" } + ] + }, + { + "why": "Arrow carries the time alone, so an editor run cannot read it.", + "column": "v TIMETZ", + "values": [ + { "sql": "'12:30:00+05:30'", "shows": "12:30:00+05:30", "edited": "" } + ] + }, + { + "column": "v INTEGER[]", + "values": [ + { "sql": "[1, 2, NULL]", "shows": "[1, 2, NULL]" }, + { "sql": "[]", "shows": "[]" } + ] + }, + { + "column": "v VARCHAR[]", + "values": [ + { "sql": "['a', 'b c', '', 'it''s', 'x,y']", "shows": "[a, b c, '', 'it\\'s', 'x,y']" } + ] + }, + { + "column": "v INTEGER[3]", + "values": [ + { "sql": "[1, 2, 3]", "shows": "[1, 2, 3]" } + ] + }, + { + "column": "v STRUCT(a INTEGER, b VARCHAR)", + "values": [ + { "sql": "{'a': 1, 'b': 'x y'}", "shows": "{'a': 1, 'b': x y}" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v MAP(VARCHAR, INTEGER)", + "values": [ + { "sql": "MAP {'k1': 1, 'k 2': NULL}", "shows": "{k1=1, k 2=NULL}" } + ] + }, + { + "column": "v STRUCT(d DECIMAL(10,2), t TIMESTAMP, l DOUBLE[])", + "values": [ + { "sql": "{'d': 1.5, 't': TIMESTAMP '2024-01-01 10:00:00', 'l': [1.0, 0.1]}", "shows": "{'d': 1.50, 't': '2024-01-01 10:00:00', 'l': [1.0, 0.1]}" } + ] + } + ] +} diff --git a/core/crates/test-support/corpus/mssql.json b/core/crates/test-support/corpus/mssql.json new file mode 100644 index 0000000000..f59537ee7a --- /dev/null +++ b/core/crates/test-support/corpus/mssql.json @@ -0,0 +1,178 @@ +{ + "why": "tiberius describes a result column by its wire type alone, with no scale, so an editor run shows the fraction a time value has. A browse page takes the scale from the catalogue.", + "columns": [ + { + "column": "v datetime2(7)", + "values": [ + { "sql": "'0001-01-01 00:00:00'", "shows": "0001-01-01 00:00:00.0000000", "edited": "0001-01-01 00:00:00" }, + { "sql": "'9999-12-31 23:59:59.9999999'", "shows": "9999-12-31 23:59:59.9999999" }, + { "sql": "'2024-02-29 12:00:00.5'", "shows": "2024-02-29 12:00:00.5000000", "edited": "2024-02-29 12:00:00.5" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "why": "The offset a value was written with is the one it shows. The server keeps the instant in UTC, which has to stay in range.", + "column": "v datetimeoffset(3)", + "values": [ + { "sql": "'2024-03-10 02:30:00 -08:00'", "shows": "2024-03-10 02:30:00.000-08:00", "edited": "2024-03-10 02:30:00-08:00" }, + { "sql": "'0001-01-01 00:00:00 -14:00'", "shows": "0001-01-01 00:00:00.000-14:00", "edited": "0001-01-01 00:00:00-14:00" }, + { "sql": "'9999-12-31 23:59:59.999 +14:00'", "shows": "9999-12-31 23:59:59.999+14:00" } + ] + }, + { + "column": "v datetime", + "values": [ + { "sql": "'1753-01-01 00:00:00'", "shows": "1753-01-01 00:00:00.000", "edited": "1753-01-01 00:00:00" }, + { "sql": "'9999-12-31 23:59:59.997'", "shows": "9999-12-31 23:59:59.997" }, + { "sql": "'2024-01-01 12:00:00.123'", "shows": "2024-01-01 12:00:00.123" } + ] + }, + { + "column": "v smalldatetime", + "values": [ + { "sql": "'2079-06-06 23:59:00'", "shows": "2079-06-06 23:59:00" } + ] + }, + { + "column": "v date", + "values": [ + { "sql": "'0001-01-01'", "shows": "0001-01-01" }, + { "sql": "'9999-12-31'", "shows": "9999-12-31" } + ] + }, + { + "column": "v time(7)", + "values": [ + { "sql": "'23:59:59.9999999'", "shows": "23:59:59.9999999" }, + { "sql": "'00:00:00'", "shows": "00:00:00.0000000", "edited": "00:00:00" } + ] + }, + { + "column": "v decimal(38, 38)", + "values": [ + { "sql": "0.99999999999999999999999999999999999999", "shows": "0.99999999999999999999999999999999999999" } + ] + }, + { + "column": "v decimal(38, 0)", + "values": [ + { "sql": "99999999999999999999999999999999999999", "shows": "99999999999999999999999999999999999999" }, + { "sql": "-99999999999999999999999999999999999999", "shows": "-99999999999999999999999999999999999999" } + ] + }, + { + "column": "v decimal(10, 4)", + "values": [ + { "sql": "-1.5", "shows": "-1.5000" }, + { "sql": "0", "shows": "0.0000" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "why": "A table tab reads MONEY cast to a decimal. tiberius hands an editor run a float, exact only to about 5.5 * 10^11, past which the cell says it cannot read the value.", + "column": "v money", + "values": [ + { "sql": "-12.34", "shows": "-12.3400" }, + { "sql": "123456789.1234", "shows": "123456789.1234" }, + { "sql": "922337203685477.5807", "shows": "922337203685477.5807", "edited": "" }, + { "sql": "-922337203685477.5808", "shows": "-922337203685477.5808", "edited": "" } + ] + }, + { + "column": "v smallmoney", + "values": [ + { "sql": "-214748.3648", "shows": "-214748.3648" } + ] + }, + { + "why": "SQL Server keeps the first three groups little-endian, so a reader that takes the bytes in order scrambles them.", + "column": "v uniqueidentifier", + "values": [ + { "sql": "'6F9619FF-8B86-D011-B42D-00C04FC964FF'", "shows": "6f9619ff-8b86-d011-b42d-00c04fc964ff" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v nvarchar(100)", + "values": [ + { "sql": "N'naïve café'", "shows": "naïve café" }, + { "sql": "N'日本語のテキスト'", "shows": "日本語のテキスト" }, + { "sql": "N'🦀 emoji 👩‍💻'", "shows": "🦀 emoji 👩‍💻" }, + { "sql": "N''", "shows": "" }, + { "sql": "N'it''s'", "shows": "it's" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v varchar(50) COLLATE Latin1_General_CI_AS", + "values": [ + { "sql": "'café'", "shows": "café" } + ] + }, + { + "column": "v nchar(5)", + "values": [ + { "sql": "N'ab'", "shows": "ab " } + ] + }, + { + "column": "v nvarchar(max)", + "values": [ + { "sql": "N'line' + NCHAR(10) + N'break'", "shows": "line\nbreak" } + ] + }, + { + "column": "v varbinary(max)", + "values": [ + { "sql": "0xDEADBEEF", "shows": "0xdeadbeef" }, + { "sql": "0x", "shows": "0x" } + ] + }, + { + "column": "v binary(4)", + "values": [ + { "sql": "0x01", "shows": "0x01000000" } + ] + }, + { + "column": "v bit", + "values": [ + { "sql": "1", "shows": "true" }, + { "sql": "0", "shows": "false" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v tinyint", + "values": [ + { "sql": "255", "shows": "255" } + ] + }, + { + "column": "v bigint", + "values": [ + { "sql": "-9223372036854775808", "shows": "-9223372036854775808" } + ] + }, + { + "column": "v real", + "values": [ + { "sql": "1.5", "shows": "1.5" }, + { "sql": "-0.1", "shows": "-0.1" } + ] + }, + { + "column": "v float", + "values": [ + { "sql": "0.1", "shows": "0.1" }, + { "sql": "-2.5e-5", "shows": "-0.000025" } + ] + }, + { + "column": "v xml", + "values": [ + { "sql": "'1'", "shows": "1" } + ] + } + ] +} diff --git a/core/crates/test-support/corpus/mysql.json b/core/crates/test-support/corpus/mysql.json new file mode 100644 index 0000000000..4d5a830e0e --- /dev/null +++ b/core/crates/test-support/corpus/mysql.json @@ -0,0 +1,216 @@ +{ + "why": "sqlx gives a result column no fractional digits and no BIT length, so an editor run shows the fraction a value has and a BIT in the whole bytes it arrived in. A browse page takes both from the catalogue. A column marked only is for that flavour.", + "columns": [ + { + "column": "v DATETIME(6)", + "values": [ + { "sql": "'1000-01-01 00:00:00'", "shows": "1000-01-01 00:00:00.000000", "edited": "1000-01-01 00:00:00" }, + { "sql": "'9999-12-31 23:59:59.999999'", "shows": "9999-12-31 23:59:59.999999" }, + { "sql": "'2024-02-29 12:00:00.5'", "shows": "2024-02-29 12:00:00.500000", "edited": "2024-02-29 12:00:00.5" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v DATETIME", + "values": [ + { "sql": "'2024-03-10 02:30:00'", "shows": "2024-03-10 02:30:00" } + ] + }, + { + "why": "Browse pins its session to UTC and reads an instant; the editor reads the wall time in the server's zone, UTC here.", + "column": "v TIMESTAMP(3) NULL", + "values": [ + { "sql": "'1970-01-01 00:00:01'", "shows": "1970-01-01 00:00:01.000+00:00", "edited": "1970-01-01 00:00:01" }, + { "sql": "'2038-01-19 03:14:07.999'", "shows": "2038-01-19 03:14:07.999+00:00", "edited": "2038-01-19 03:14:07.999" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v DATE", + "values": [ + { "sql": "'1000-01-01'", "shows": "1000-01-01" }, + { "sql": "'9999-12-31'", "shows": "9999-12-31" }, + { "sql": "'2024-02-29'", "shows": "2024-02-29" } + ] + }, + { + "column": "v TIME(6)", + "values": [ + { "sql": "'-838:59:59'", "shows": "-838:59:59.000000", "edited": "-838:59:59" }, + { "sql": "'838:59:59'", "shows": "838:59:59.000000", "edited": "838:59:59" }, + { "sql": "'00:00:00.000001'", "shows": "00:00:00.000001" } + ] + }, + { + "column": "v YEAR", + "values": [ + { "sql": "1901", "shows": "1901" }, + { "sql": "2155", "shows": "2155" } + ] + }, + { + "column": "v DECIMAL(65, 30)", + "values": [ + { "sql": "12345678901234567890123456789012345.123456789012345678901234567890", "shows": "12345678901234567890123456789012345.123456789012345678901234567890" }, + { "sql": "-0.000000000000000000000000000001", "shows": "-0.000000000000000000000000000001" }, + { "sql": "0", "shows": "0.000000000000000000000000000000" } + ] + }, + { + "column": "v DECIMAL(10, 2)", + "values": [ + { "sql": "-12345678.9", "shows": "-12345678.90" }, + { "sql": "0.5", "shows": "0.50" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v BIGINT UNSIGNED", + "values": [ + { "sql": "18446744073709551615", "shows": "18446744073709551615" } + ] + }, + { + "column": "v BIGINT", + "values": [ + { "sql": "-9223372036854775808", "shows": "-9223372036854775808" } + ] + }, + { + "column": "v TINYINT UNSIGNED", + "values": [ + { "sql": "255", "shows": "255" } + ] + }, + { + "column": "v FLOAT", + "values": [ + { "sql": "1.5", "shows": "1.5" }, + { "sql": "-0.25", "shows": "-0.25" } + ] + }, + { + "column": "v DOUBLE", + "values": [ + { "sql": "0.1", "shows": "0.1" }, + { "sql": "-2.5e-5", "shows": "-0.000025" } + ] + }, + { + "column": "v VARCHAR(100)", + "values": [ + { "sql": "'naïve café'", "shows": "naïve café" }, + { "sql": "'日本語のテキスト'", "shows": "日本語のテキスト" }, + { "sql": "'🦀 emoji 👩‍💻'", "shows": "🦀 emoji 👩‍💻" }, + { "sql": "''", "shows": "" }, + { "sql": "'it''s'", "shows": "it's" }, + { "sql": "'back\\\\slash'", "shows": "back\\slash" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v VARCHAR(20) CHARACTER SET latin1", + "values": [ + { "sql": "'café'", "shows": "café" } + ] + }, + { + "column": "v CHAR(5)", + "values": [ + { "sql": "'ab'", "shows": "ab" } + ] + }, + { + "column": "v TEXT", + "values": [ + { "sql": "'line\\nbreak'", "shows": "line\nbreak" } + ] + }, + { + "column": "v VARBINARY(8)", + "values": [ + { "sql": "X'DEADBEEF'", "shows": "0xdeadbeef" }, + { "sql": "X''", "shows": "0x" } + ] + }, + { + "column": "v BINARY(4)", + "values": [ + { "sql": "X'01'", "shows": "0x01000000" } + ] + }, + { + "column": "v BLOB", + "values": [ + { "sql": "X'00FF'", "shows": "0x00ff" } + ] + }, + { + "column": "v BIT(10)", + "values": [ + { "sql": "b'1010101010'", "shows": "1010101010", "edited": "0000001010101010" } + ] + }, + { + "column": "v BIT(1)", + "values": [ + { "sql": "b'1'", "shows": "1", "edited": "00000001" }, + { "sql": "b'0'", "shows": "0", "edited": "00000000" } + ] + }, + { + "column": "v ENUM('a', 'b c')", + "values": [ + { "sql": "'b c'", "shows": "b c" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v SET('x', 'y', 'z')", + "values": [ + { "sql": "'x,z'", "shows": "x,z" } + ] + }, + { + "why": "MySQL keeps JSON in a binary form of its own, so it prints the document again, keys sorted and numbers normalised, as the mysql client shows it.", + "only": "mysql", + "column": "v JSON", + "values": [ + { "sql": "'{\"b\": 1, \"a\": [1, 2.50, \"x\"], \"ü\": null}'", "shows": "{\"a\": [1, 2.5, \"x\"], \"b\": 1, \"ü\": null}" }, + { "sql": "'[]'", "shows": "[]" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "only": "mysql", + "column": "v BINARY(16)", + "values": [ + { "sql": "UUID_TO_BIN('123e4567-e89b-12d3-a456-426614174000')", "shows": "0x123e4567e89b12d3a456426614174000" } + ] + }, + { + "why": "MariaDB's JSON is LONGTEXT with a check, kept as written.", + "only": "mariadb", + "column": "v JSON", + "values": [ + { "sql": "'{\"b\": 1, \"a\": [1, 2.50, \"x\"]}'", "shows": "{\"b\": 1, \"a\": [1, 2.50, \"x\"]}" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "only": "mariadb", + "column": "v UUID", + "values": [ + { "sql": "'123e4567-e89b-12d3-a456-426614174000'", "shows": "123e4567-e89b-12d3-a456-426614174000" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "only": "mariadb", + "column": "v INET6", + "values": [ + { "sql": "'::ffff:192.0.2.1'", "shows": "::ffff:192.0.2.1" } + ] + } + ] +} diff --git a/core/crates/test-support/corpus/postgres.json b/core/crates/test-support/corpus/postgres.json new file mode 100644 index 0000000000..36a4f8c0ad --- /dev/null +++ b/core/crates/test-support/corpus/postgres.json @@ -0,0 +1,261 @@ +{ + "why": "A browse page reads values in binary and the grid writes them out; an editor run uses the simple query protocol, so it shows the server's own text, as psql does.", + "columns": [ + { + "why": "An instant reads back in UTC whatever offset it was written with; the server's zone is UTC too.", + "column": "v timestamptz", + "values": [ + { "sql": "'2024-03-10 02:30:00-08'", "shows": "2024-03-10 10:30:00+00:00", "edited": "2024-03-10 10:30:00+00" }, + { "sql": "'2024-06-15 12:00:00.5+05:45'", "shows": "2024-06-15 06:15:00.5+00:00", "edited": "2024-06-15 06:15:00.5+00" }, + { "sql": "'1969-12-31 23:59:59.999999+00'", "shows": "1969-12-31 23:59:59.999999+00:00", "edited": "1969-12-31 23:59:59.999999+00" }, + { "sql": "'0001-01-01 00:00:00+00'", "shows": "0001-01-01 00:00:00+00:00", "edited": "0001-01-01 00:00:00+00" }, + { "sql": "'4713-01-01 00:00:00+00 BC'", "shows": "4713-01-01 00:00:00+00:00 BC", "edited": "4713-01-01 00:00:00+00 BC" }, + { "sql": "'infinity'", "shows": "infinity" }, + { "sql": "'-infinity'", "shows": "-infinity" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v timestamp(3)", + "values": [ + { "sql": "'2024-02-29 23:59:59.999'", "shows": "2024-02-29 23:59:59.999" }, + { "sql": "'2000-01-01 00:00:00'", "shows": "2000-01-01 00:00:00.000", "edited": "2000-01-01 00:00:00" }, + { "sql": "'1900-01-01 00:00:00.001'", "shows": "1900-01-01 00:00:00.001" } + ] + }, + { + "column": "v timestamp", + "values": [ + { "sql": "'294276-12-31 23:59:59.999999'", "shows": "294276-12-31 23:59:59.999999" }, + { "sql": "'1999-12-31 23:59:59.5'", "shows": "1999-12-31 23:59:59.5" } + ] + }, + { + "column": "v date", + "values": [ + { "sql": "'2024-02-29'", "shows": "2024-02-29" }, + { "sql": "'0001-01-01'", "shows": "0001-01-01" }, + { "sql": "'4713-01-01 BC'", "shows": "4713-01-01 BC" }, + { "sql": "'10000-01-01'", "shows": "10000-01-01" }, + { "sql": "'5874897-12-31'", "shows": "5874897-12-31" }, + { "sql": "'infinity'", "shows": "infinity" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v time(6)", + "values": [ + { "sql": "'00:00:00'", "shows": "00:00:00.000000", "edited": "00:00:00" }, + { "sql": "'23:59:59.999999'", "shows": "23:59:59.999999" }, + { "sql": "'24:00:00'", "shows": "24:00:00.000000", "edited": "24:00:00" } + ] + }, + { + "column": "v timetz", + "values": [ + { "sql": "'12:34:56+05:30'", "shows": "12:34:56+05:30" }, + { "sql": "'00:00:00.25-15:59'", "shows": "00:00:00.25-15:59" } + ] + }, + { + "column": "v interval", + "values": [ + { "sql": "'1 year 2 mons 3 days 04:05:06.789'", "shows": "P1Y2M3DT4H5M6.789S", "edited": "1 year 2 mons 3 days 04:05:06.789" }, + { "sql": "'-1 day +02:00:00'", "shows": "P-1DT2H", "edited": "-1 days +02:00:00" }, + { "sql": "'0'", "shows": "PT0S", "edited": "00:00:00" } + ] + }, + { + "column": "v numeric(38, 10)", + "values": [ + { "sql": "12345678901234567890.1234567890", "shows": "12345678901234567890.1234567890" }, + { "sql": "-0.0000000001", "shows": "-0.0000000001" }, + { "sql": "1.5", "shows": "1.5000000000" }, + { "sql": "0", "shows": "0.0000000000" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v numeric", + "values": [ + { "sql": "-123456789012345678901234567890.123456789", "shows": "-123456789012345678901234567890.123456789" }, + { "sql": "0.000000000000000000000000000001", "shows": "0.000000000000000000000000000001" }, + { "sql": "2.50", "shows": "2.50" }, + { "sql": "'NaN'", "shows": "NaN" }, + { "sql": "'Infinity'", "shows": "Infinity" }, + { "sql": "'-Infinity'", "shows": "-Infinity" } + ] + }, + { + "column": "v money", + "values": [ + { "sql": "-12.34", "shows": "-12.34", "edited": "-$12.34" }, + { "sql": "92233720368547758.07", "shows": "92233720368547758.07", "edited": "$92,233,720,368,547,758.07" } + ] + }, + { + "column": "v bigint", + "values": [ + { "sql": "-9223372036854775808", "shows": "-9223372036854775808" }, + { "sql": "9223372036854775807", "shows": "9223372036854775807" } + ] + }, + { + "column": "v smallint", + "values": [ + { "sql": "-32768", "shows": "-32768" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v real", + "values": [ + { "sql": "1.5", "shows": "1.5" }, + { "sql": "-0.1", "shows": "-0.1" }, + { "sql": "'NaN'", "shows": "NaN" }, + { "sql": "'-Infinity'", "shows": "-Infinity" } + ] + }, + { + "column": "v double precision", + "values": [ + { "sql": "0.1", "shows": "0.1" }, + { "sql": "-2.5e-5", "shows": "-0.000025", "edited": "-2.5e-05" }, + { "sql": "'Infinity'", "shows": "Infinity" } + ] + }, + { + "column": "v boolean", + "values": [ + { "sql": "true", "shows": "true", "edited": "t" }, + { "sql": "false", "shows": "false", "edited": "f" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v jsonb", + "values": [ + { "sql": "'{\"b\": 1, \"a\": [1, 2.50, \"x\"], \"ü\": null}'", "shows": "{\"a\": [1, 2.50, \"x\"], \"b\": 1, \"ü\": null}" }, + { "sql": "'[]'", "shows": "[]" }, + { "sql": "'\"just text\"'", "shows": "\"just text\"" } + ] + }, + { + "column": "v json", + "values": [ + { "sql": "'{\"b\":1, \"a\":2}'", "shows": "{\"b\":1, \"a\":2}" } + ] + }, + { + "column": "v uuid", + "values": [ + { "sql": "'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'", "shows": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11" }, + { "sql": "'A0EEBC99-9C0B-4EF8-BB6D-6BB9BD380A12'", "shows": "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v text", + "values": [ + { "sql": "'naïve café'", "shows": "naïve café" }, + { "sql": "'日本語のテキスト'", "shows": "日本語のテキスト" }, + { "sql": "'🦀 emoji 👩‍💻'", "shows": "🦀 emoji 👩‍💻" }, + { "sql": "'עברית RTL'", "shows": "עברית RTL" }, + { "sql": "'é'", "shows": "é" }, + { "sql": "''", "shows": "" }, + { "sql": "E'tab\\there\\nnew line'", "shows": "tab\there\nnew line" }, + { "sql": "'it''s'", "shows": "it's" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v char(5)", + "values": [ + { "sql": "'ab'", "shows": "ab " } + ] + }, + { + "column": "v varchar(10)", + "values": [ + { "sql": "'ünïcödé'", "shows": "ünïcödé" } + ] + }, + { + "column": "v bytea", + "values": [ + { "sql": "'\\xdeadbeef'", "shows": "0xdeadbeef", "edited": "\\xdeadbeef" }, + { "sql": "''", "shows": "0x", "edited": "\\x" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v integer[]", + "values": [ + { "sql": "'{1,NULL,3}'", "shows": "[\"1\",null,\"3\"]", "edited": "{1,NULL,3}" } + ] + }, + { + "column": "v text[]", + "values": [ + { "sql": "'{\"a b\",\"c,d\",NULL,\"\"}'", "shows": "[\"a b\",\"c,d\",null,\"\"]", "edited": "{\"a b\",\"c,d\",NULL,\"\"}" } + ] + }, + { + "column": "v inet", + "values": [ + { "sql": "'192.168.0.1/24'", "shows": "192.168.0.1/24" }, + { "sql": "'::1'", "shows": "::1" } + ] + }, + { + "column": "v cidr", + "values": [ + { "sql": "'10.0.0.0/8'", "shows": "10.0.0.0/8" } + ] + }, + { + "column": "v macaddr", + "values": [ + { "sql": "'08:00:2B:01:02:03'", "shows": "08:00:2b:01:02:03" } + ] + }, + { + "column": "v corpus_mood", + "setup": ["CREATE TYPE corpus_mood AS ENUM ('sad', 'ok', 'happy')"], + "values": [ + { "sql": "'happy'", "shows": "happy" } + ] + }, + { + "column": "v int4range", + "values": [ + { "sql": "'[1,10)'", "shows": "[1,10)" }, + { "sql": "'empty'", "shows": "empty" } + ] + }, + { + "column": "v bit(4)", + "values": [ + { "sql": "B'1010'", "shows": "1010" } + ] + }, + { + "column": "v varbit(8)", + "values": [ + { "sql": "B'101'", "shows": "101" } + ] + }, + { + "column": "v point", + "values": [ + { "sql": "'(1.5,-2)'", "shows": "(1.5,-2)" } + ] + }, + { + "column": "v xml", + "values": [ + { "sql": "'1'", "shows": "1" } + ] + } + ] +} diff --git a/core/crates/test-support/corpus/sqlite.json b/core/crates/test-support/corpus/sqlite.json new file mode 100644 index 0000000000..19aa6fa426 --- /dev/null +++ b/core/crates/test-support/corpus/sqlite.json @@ -0,0 +1,98 @@ +{ + "why": "A value reads as the storage class SQLite keeps it in, whatever the column declares, so the declared types here are the ones real schemas use.", + "columns": [ + { + "column": "v INTEGER", + "values": [ + { "sql": "9223372036854775807", "shows": "9223372036854775807" }, + { "sql": "-9223372036854775808", "shows": "-9223372036854775808" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v REAL", + "values": [ + { "sql": "0.1", "shows": "0.1" }, + { "sql": "-2.5e-5", "shows": "-0.000025" }, + { "sql": "1", "shows": "1" } + ] + }, + { + "column": "v TEXT", + "values": [ + { "sql": "'naïve café'", "shows": "naïve café" }, + { "sql": "'日本語のテキスト'", "shows": "日本語のテキスト" }, + { "sql": "'🦀 emoji 👩‍💻'", "shows": "🦀 emoji 👩‍💻" }, + { "sql": "''", "shows": "" }, + { "sql": "'it''s'", "shows": "it's" }, + { "sql": "'line' || char(10) || 'break'", "shows": "line\nbreak" }, + { "sql": "NULL", "shows": null } + ] + }, + { + "column": "v BLOB", + "values": [ + { "sql": "X'DEADBEEF'", "shows": "0xdeadbeef" }, + { "sql": "X''", "shows": "0x" } + ] + }, + { + "column": "v NUMERIC", + "values": [ + { "sql": "'1.50'", "shows": "1.5" }, + { "sql": "'12'", "shows": "12" } + ] + }, + { + "column": "v DECIMAL(10, 2)", + "values": [ + { "sql": "-12.5", "shows": "-12.5" } + ] + }, + { + "column": "v DATETIME", + "values": [ + { "sql": "'2024-02-29 12:00:00.123'", "shows": "2024-02-29 12:00:00.123" }, + { "sql": "'2024-03-10T02:30:00-08:00'", "shows": "2024-03-10T02:30:00-08:00" }, + { "sql": "'2024-03-10 10:30:00Z'", "shows": "2024-03-10 10:30:00Z" } + ] + }, + { + "why": "SQLite gives DATE, TIME and DATETIME one affinity, so each holds any form its date and time functions read.", + "column": "v DATE", + "values": [ + { "sql": "'2024-02-29'", "shows": "2024-02-29" }, + { "sql": "'2024-03-10 02:30:00'", "shows": "2024-03-10 02:30:00" } + ] + }, + { + "column": "v TIME", + "values": [ + { "sql": "'12:30:00'", "shows": "12:30:00" }, + { "sql": "'12:30:00+05:30'", "shows": "12:30:00+05:30" } + ] + }, + { + "column": "v BOOLEAN", + "values": [ + { "sql": "1", "shows": "1" }, + { "sql": "0", "shows": "0" } + ] + }, + { + "column": "v JSON", + "values": [ + { "sql": "'{\"b\": 1, \"a\": [1, 2.50]}'", "shows": "{\"b\": 1, \"a\": [1, 2.50]}" } + ] + }, + { + "column": "v", + "values": [ + { "sql": "42", "shows": "42" }, + { "sql": "'text'", "shows": "text" }, + { "sql": "X'01'", "shows": "0x01" }, + { "sql": "1.5", "shows": "1.5" } + ] + } + ] +} diff --git a/core/crates/test-support/src/conformance/cases/round_trip.rs b/core/crates/test-support/src/conformance/cases/round_trip.rs index 31939d490d..3ed3417a2b 100644 --- a/core/crates/test-support/src/conformance/cases/round_trip.rs +++ b/core/crates/test-support/src/conformance/cases/round_trip.rs @@ -81,7 +81,7 @@ const LISTED_IDS: usize = 10; pub async fn csv_export_imports_back_as_the_same_rows( engine: E, ) -> Result<(), ConformanceFailure> { - let corpus = engine.value_corpus(); + let corpus = engine.value_corpus().columns()?; expect(CSV_CASE, !corpus.is_empty(), || "the engine lists no corpus".to_owned())?; let connection = connect(CSV_CASE, &engine, writable()).await?; let mut wrong = Vec::new(); @@ -141,7 +141,7 @@ pub async fn csv_export_imports_back_as_the_same_rows( /// paste leaves an id the server numbers, such as SQLite's row id, to /// the server. pub async fn tsv_copy_pastes_back_as_the_same_rows(engine: E) -> Result<(), ConformanceFailure> { - let corpus = engine.value_corpus(); + let corpus = engine.value_corpus().columns()?; expect(PASTE_CASE, !corpus.is_empty(), || { "the engine lists no corpus".to_owned() })?; @@ -334,7 +334,7 @@ fn order_differences(what: &str, source: &[Vec], copy: &[Vec]) - pub async fn sql_insert_export_runs_back_as_the_same_rows( engine: E, ) -> Result<(), ConformanceFailure> { - let corpus = engine.value_corpus(); + let corpus = engine.value_corpus().columns()?; expect(SQL_CASE, !corpus.is_empty(), || "the engine lists no corpus".to_owned())?; let connection = connect(SQL_CASE, &engine, writable()).await?; let session = connection diff --git a/core/crates/test-support/src/conformance/cases/value_corpus.rs b/core/crates/test-support/src/conformance/cases/value_corpus.rs index 5b614f31fb..d27d414c4d 100644 --- a/core/crates/test-support/src/conformance/cases/value_corpus.rs +++ b/core/crates/test-support/src/conformance/cases/value_corpus.rs @@ -36,7 +36,7 @@ struct Read { /// tab's page, a table export and an editor run, as the text its entry /// names. A wrong text is a decoder bug, and every one is listed at once. pub async fn value_corpus_reads_as_the_grid_shows(engine: E) -> Result<(), ConformanceFailure> { - let corpus = engine.value_corpus(); + let corpus = engine.value_corpus().columns()?; expect(CASE, !corpus.is_empty(), || "the engine lists no corpus".to_owned())?; let connection = connect(CASE, &engine, writable()).await?; let session = connection @@ -314,6 +314,7 @@ mod tests { use tablepro_core::value::{SqlDecimal, UndecodableReason, UndecodedValue}; use super::*; + use crate::conformance::CorpusValue; fn decimal(precision: u32, scale: u32) -> ColumnType { let mut column_type = ColumnType::unknown(); @@ -331,11 +332,26 @@ mod tests { } } + fn corpus_column(declaration: &str, values: &[(&str, Option<&str>, Option<&str>)]) -> CorpusColumn { + CorpusColumn { + setup_sql: Vec::new(), + declaration: declaration.to_owned(), + values: values + .iter() + .map(|(sql, shown, edited)| CorpusValue { + sql: (*sql).to_owned(), + shown: shown.map(str::to_owned), + edited: edited.map(str::to_owned), + }) + .collect(), + } + } + fn column() -> CorpusColumn { - CorpusColumn::new("v numeric(10, 2)") - .shows("1.5", "1.50") - .shows_apart("2", "2.00", "2") - .null() + corpus_column( + "v numeric(10, 2)", + &[("1.5", Some("1.50"), None), ("2", Some("2.00"), Some("2")), ("NULL", None, None)], + ) } #[test] @@ -398,7 +414,7 @@ mod tests { type_name: "money".to_owned(), reason: UndecodableReason::OutOfRange, })); - let column = CorpusColumn::new("v money").shows_apart("1", "1", ""); + let column = corpus_column("v money", &[("1", Some("1"), Some(""))]); compare( Path::Editor, diff --git a/core/crates/test-support/src/conformance/corpus_column.rs b/core/crates/test-support/src/conformance/corpus_column.rs index 7cc06a3edb..3cb1622630 100644 --- a/core/crates/test-support/src/conformance/corpus_column.rs +++ b/core/crates/test-support/src/conformance/corpus_column.rs @@ -1,70 +1,142 @@ -/// One column of an engine's value corpus: a type, and values of it the -/// way a real table holds them. +use serde::Deserialize; + +use crate::conformance::ConformanceFailure; + +// One column of an engine's value corpus: the clause `ALTER TABLE ... ADD` takes, naming the column `v`, the +// statements run before it, and values of it the way a real table holds them. #[derive(Debug, Clone, PartialEq, Eq)] pub struct CorpusColumn { - /// Statements run first, such as creating the enum the column uses. pub setup_sql: Vec, - /// The clause `ALTER TABLE ... ADD` takes, naming the column `v`, as - /// in `UnsupportedTypeCase`. pub declaration: String, pub values: Vec, } -/// A value written as SQL, and the text the grid shows for it. -#[derive(Debug, Clone, PartialEq, Eq)] +// A value written as SQL and the text the grid shows for it, `None` for NULL. `edited` is what an editor run shows +// where it differs from a browse page. +#[derive(Debug, Clone, PartialEq, Eq, Deserialize)] +#[serde(deny_unknown_fields)] pub struct CorpusValue { pub sql: String, - /// `None` for NULL. + #[serde(rename = "shows")] pub shown: Option, - /// What an editor run shows where it differs from a browse page, - /// such as a MySQL TIMESTAMP, which browse reads as an instant and - /// the editor in the server's zone. + #[serde(default)] pub edited: Option, } -impl CorpusColumn { - pub fn new(declaration: impl Into) -> Self { - Self { - setup_sql: Vec::new(), - declaration: declaration.into(), - values: Vec::new(), - } +// The corpora live in `corpus/` as JSON, which the Windows interop tests read too (`windows/tests/TablePro.Interop.Tests`). +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum ValueCorpus { + Cassandra, + Clickhouse, + Duckdb, + Mariadb, + Mssql, + Mysql, + Postgres, + Sqlite, +} + +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +struct CorpusFile { + #[serde(default, rename = "why")] + _why: Option, + columns: Vec, +} + +#[derive(Deserialize)] +#[serde(deny_unknown_fields)] +struct CorpusEntry { + #[serde(default, rename = "why")] + _why: Option, + #[serde(default)] + only: Option, + column: String, + #[serde(default)] + setup: Vec, + values: Vec, +} + +impl ValueCorpus { + pub fn columns(self) -> Result, ConformanceFailure> { + let file: CorpusFile = serde_json::from_str(self.file()) + .map_err(|error| ConformanceFailure::setup(format!("the {self:?} corpus: {error}")))?; + Ok(file + .columns + .into_iter() + .filter(|entry| entry.only.as_deref().is_none_or(|only| Some(only) == self.flavour())) + .map(|entry| CorpusColumn { + setup_sql: entry.setup, + declaration: entry.column, + values: entry.values, + }) + .collect()) } - pub fn after(mut self, setup_sql: impl Into) -> Self { - self.setup_sql.push(setup_sql.into()); - self + fn file(self) -> &'static str { + match self { + Self::Cassandra => include_str!("../../corpus/cassandra.json"), + Self::Clickhouse => include_str!("../../corpus/clickhouse.json"), + Self::Duckdb => include_str!("../../corpus/duckdb.json"), + Self::Mariadb | Self::Mysql => include_str!("../../corpus/mysql.json"), + Self::Mssql => include_str!("../../corpus/mssql.json"), + Self::Postgres => include_str!("../../corpus/postgres.json"), + Self::Sqlite => include_str!("../../corpus/sqlite.json"), + } } - pub fn shows(mut self, sql: impl Into, shown: impl Into) -> Self { - self.values.push(CorpusValue { - sql: sql.into(), - shown: Some(shown.into()), - edited: None, - }); - self + // A column marked `only` belongs to one flavour of a file two engines share. + fn flavour(self) -> Option<&'static str> { + match self { + Self::Mariadb => Some("mariadb"), + Self::Mysql => Some("mysql"), + _ => None, + } } +} - pub fn shows_apart( - mut self, - sql: impl Into, - browsed: impl Into, - edited: impl Into, - ) -> Self { - self.values.push(CorpusValue { - sql: sql.into(), - shown: Some(browsed.into()), - edited: Some(edited.into()), - }); - self +#[cfg(test)] +mod tests { + use super::ValueCorpus; + + const EVERY: [ValueCorpus; 8] = [ + ValueCorpus::Cassandra, + ValueCorpus::Clickhouse, + ValueCorpus::Duckdb, + ValueCorpus::Mariadb, + ValueCorpus::Mssql, + ValueCorpus::Mysql, + ValueCorpus::Postgres, + ValueCorpus::Sqlite, + ]; + + #[test] + fn every_corpus_parses_and_names_its_column_v() { + for corpus in EVERY { + let columns = corpus.columns().unwrap(); + assert!(!columns.is_empty(), "{corpus:?} lists no column"); + for column in columns { + assert!( + column.declaration.starts_with("v ") || column.declaration.starts_with("COLUMN v ") || column.declaration == "v", + "{corpus:?}: `{}` does not add `v`", + column.declaration + ); + assert!(!column.values.is_empty(), "{corpus:?}: `{}` has no value", column.declaration); + } + } } - pub fn null(mut self) -> Self { - self.values.push(CorpusValue { - sql: "NULL".to_owned(), - shown: None, - edited: None, - }); - self + #[test] + fn mysql_and_mariadb_share_the_common_columns_and_keep_their_own() { + let declarations = |corpus: ValueCorpus| -> Vec { + corpus.columns().unwrap().into_iter().map(|column| column.declaration).collect() + }; + let (mysql, mariadb) = (declarations(ValueCorpus::Mysql), declarations(ValueCorpus::Mariadb)); + + assert_eq!(mysql.first(), mariadb.first()); + assert!(mysql.contains(&"v BINARY(16)".to_owned())); + assert!(!mariadb.contains(&"v BINARY(16)".to_owned())); + assert!(mariadb.contains(&"v INET6".to_owned())); + assert!(!mysql.contains(&"v INET6".to_owned())); } } diff --git a/core/crates/test-support/src/conformance/mod.rs b/core/crates/test-support/src/conformance/mod.rs index 85e77bc618..5896f99db2 100644 --- a/core/crates/test-support/src/conformance/mod.rs +++ b/core/crates/test-support/src/conformance/mod.rs @@ -55,7 +55,7 @@ pub use client_identity_engine::ClientIdentityEngine; pub use conformance_engine::ConformanceEngine; pub use conformance_failure::ConformanceFailure; pub use connection_suite_flags::ConnectionSuiteFlags; -pub use corpus_column::{CorpusColumn, CorpusValue}; +pub use corpus_column::{CorpusColumn, CorpusValue, ValueCorpus}; pub use ddl_conformance_engine::ConformanceDdlEngine; pub use document_engine::DocumentEngine; pub use dump_engine::{DumpEngine, NativeDump}; diff --git a/core/crates/test-support/src/conformance/value_corpus_engine.rs b/core/crates/test-support/src/conformance/value_corpus_engine.rs index 22aef61708..d034be8eed 100644 --- a/core/crates/test-support/src/conformance/value_corpus_engine.rs +++ b/core/crates/test-support/src/conformance/value_corpus_engine.rs @@ -1,6 +1,5 @@ -use crate::conformance::{ConformanceEngine, CorpusColumn}; +use crate::conformance::{ConformanceEngine, ValueCorpus}; -/// An engine with a corpus of real values for the value corpus case. pub trait ValueCorpusEngine: ConformanceEngine { - fn value_corpus(&self) -> Vec; + fn value_corpus(&self) -> ValueCorpus; } diff --git a/windows/ci/live-servers.ps1 b/windows/ci/live-servers.ps1 new file mode 100644 index 0000000000..4d93ab949c --- /dev/null +++ b/windows/ci/live-servers.ps1 @@ -0,0 +1,144 @@ +# Starts one database server on the x64 runner for tests/TablePro.Interop.Tests/Live and names it to them in +# TABLEPRO_TEST_LIVE__PORT, _USER and _PASSWORD. How each one runs: docs/decisions/0013-live-server-tests.md. +param( + [Parameter(Mandatory)] + [ValidateSet('MySql', 'SqlServer', 'MongoDb', 'Redis', 'Cassandra', 'Wsl', 'ClickHouse')] + [string]$Server +) + +$ErrorActionPreference = 'Stop' +$ProgressPreference = 'SilentlyContinue' + +$Distribution = 'tablepro' + +function Wait-Listening([int]$Port, [int]$Minutes, [scriptblock]$Log) { + $deadline = (Get-Date).AddMinutes($Minutes) + while ($true) { + $client = [System.Net.Sockets.TcpClient]::new() + try { + if ($client.ConnectAsync('127.0.0.1', $Port).Wait(1000)) { return } + } catch { + } finally { + $client.Dispose() + } + if ((Get-Date) -gt $deadline) { + & $Log + throw "nothing listens on $Port after $Minutes minutes" + } + Start-Sleep -Milliseconds 500 + } +} + +function Get-Pinned([string]$Url, [string]$Sha256) { + $file = Join-Path $env:RUNNER_TEMP ([uri]$Url).Segments[-1] + Invoke-WebRequest $Url -OutFile $file + $actual = (Get-FileHash $file -Algorithm SHA256).Hash + if ($actual -ne $Sha256) { throw "$Url has SHA-256 $actual" } + $file +} + +function Set-Live([string]$Engine, [int]$Port, [string]$User = '', [string]$Password = '') { + $lines = @("TABLEPRO_TEST_LIVE_${Engine}_PORT=$Port", "TABLEPRO_TEST_LIVE_${Engine}_USER=$User") + if ($Password) { + "::add-mask::$Password" + $lines += "TABLEPRO_TEST_LIVE_${Engine}_PASSWORD=$Password" + } + $lines | Add-Content -Encoding utf8 $env:GITHUB_ENV +} + +function New-Password { 'Tp-' + [guid]::NewGuid().ToString('N') } + +function Invoke-Wsl([string]$Command) { + wsl --distribution $Distribution --user root -- sh -c $Command + if ($LASTEXITCODE -ne 0) { throw "``$Command`` exited $LASTEXITCODE in WSL" } +} + +function ConvertTo-WslPath([string]$Path) { + '/mnt/' + $Path.Substring(0, 1).ToLowerInvariant() + $Path.Substring(2).Replace('\', '/') +} + +switch ($Server) { + # The image ships MySQL 8.4 without a data folder or a running service. + 'MySql' { + $mysqld = (Get-Command mysqld).Source + $data = Join-Path $env:RUNNER_TEMP 'mysql-data' + $log = Join-Path $env:RUNNER_TEMP 'mysqld.log' + & $mysqld --initialize-insecure "--datadir=$data" --console + if ($LASTEXITCODE -ne 0) { throw "mysqld --initialize-insecure exited $LASTEXITCODE" } + Start-Process $mysqld -ArgumentList "--datadir=$data", '--port=3306', '--bind-address=127.0.0.1', "--log-error=$log" -WindowStyle Hidden + Wait-Listening 3306 2 { Get-Content $log } + $password = New-Password + mysql --user=root --host=127.0.0.1 --execute="CREATE DATABASE tablepro; CREATE USER 'tablepro'@'%' IDENTIFIED BY '$password'; GRANT ALL ON tablepro.* TO 'tablepro'@'%'" + if ($LASTEXITCODE -ne 0) { throw 'Creating the MySQL test user failed.' } + Set-Live MYSQL 3306 tablepro $password + } + 'SqlServer' { + $password = New-Password + & (Join-Path $PSScriptRoot '../../core/crates/drivers/mssql/tests/windows/sql-server.ps1') -Install -SaPassword $password + Set-Live MSSQL 1433 sa $password + } + # The image ships MongoDB 7.0 as a disabled service. + 'MongoDb' { + Set-Service MongoDB -StartupType Manual + Start-Service MongoDB + Wait-Listening 27017 2 { Get-Content "$env:ProgramFiles\MongoDB\Server\7.0\log\mongod.log" -Tail 50 } + Set-Live MONGODB 27017 + } + 'Redis' { + $zip = Get-Pinned 'https://github.com/redis-windows/redis-windows/releases/download/8.10.3/Redis-8.10.3-Windows-x64-msys2.zip' ` + 'AF16DF340525B431E9EC8DABFD625D5E7A233F82805B5418819904EA909C447F' + Expand-Archive $zip -DestinationPath $env:RUNNER_TEMP + $folder = Join-Path $env:RUNNER_TEMP 'Redis-8.10.3-Windows-x64-msys2' + Start-Process (Join-Path $folder 'redis-server.exe') -ArgumentList '--port', '6379', '--bind', '127.0.0.1' -WorkingDirectory $folder -WindowStyle Hidden + Wait-Listening 6379 1 { } + Set-Live REDIS 6379 + } + # Cassandra 4.1 and later refuse to start on Windows; 4.0 still runs there on the image's Java 11. Its launch script is + # for Unix, so this is the java command it builds. + 'Cassandra' { + $archive = Get-Pinned 'https://archive.apache.org/dist/cassandra/4.0.21/apache-cassandra-4.0.21-bin.tar.gz' ` + 'B5916619A0F64A414F838BC99A90540B60D057FE028C84C575A05F7D0A9CE15F' + tar -xzf $archive -C $env:RUNNER_TEMP + $root = Join-Path $env:RUNNER_TEMP 'apache-cassandra-4.0.21' + $conf = Join-Path $root 'conf' + # Windows cannot delete a file while it is mapped, and dropping a table deletes its files. + Add-Content (Join-Path $conf 'cassandra.yaml') 'disk_access_mode: standard' + $options = @('jvm-server.options', 'jvm11-server.options') | + ForEach-Object { Get-Content (Join-Path $conf $_) } | + ForEach-Object { $_.Trim() } | + Where-Object { $_ -match '^-' -and $_ -ne '-XX:+UseNUMA' } | + ForEach-Object { $_ -replace '^(--add-(exports|opens)) ', '$1=' } + $arguments = @($options) + @( + '-Xms1g', '-Xmx1g', + '-Dlogback.configurationFile=logback.xml', + "-Dcassandra.logdir=$root\logs", + "-Dcassandra.storagedir=$root\data", + '-Dcassandra-foreground=yes', + '-cp', "`"$conf;$root\lib\*`"", + 'org.apache.cassandra.service.CassandraDaemon' + ) + $out = Join-Path $env:RUNNER_TEMP 'cassandra.log' + Start-Process (Join-Path $env:JAVA_HOME_11_X64 'bin\java.exe') -ArgumentList $arguments -WorkingDirectory $root ` + -RedirectStandardOutput $out -RedirectStandardError (Join-Path $env:RUNNER_TEMP 'cassandra.err') -WindowStyle Hidden + Wait-Listening 9042 5 { Get-Content $out -Tail 80 } + Set-Live CASSANDRA 9042 + } + # ClickHouse has no Windows build. WSL 1 runs its Linux binary on the runner, which cannot nest a WSL 2 VM. + 'Wsl' { + $rootfs = Get-Pinned 'https://cdimage.ubuntu.com/ubuntu-base/releases/24.04/release/ubuntu-base-24.04.5-base-amd64.tar.gz' ` + 'E77B6F10C2590CEF872B33EE9F635A0E3FD1F57FB074C0E52B5C7F56147A0C86' + $folder = Join-Path $env:RUNNER_TEMP 'wsl' + New-Item -ItemType Directory -Force $folder | Out-Null + wsl --import $Distribution $folder $rootfs --version 1 + if ($LASTEXITCODE -ne 0) { throw "wsl --import exited $LASTEXITCODE" } + } + 'ClickHouse' { + $archive = Get-Pinned 'https://github.com/ClickHouse/ClickHouse/releases/download/v26.8.39.19-lts/clickhouse-common-static-26.8.39.19-amd64.tgz' ` + 'EA26B63D9C533513F27D5D92A43BA054C6A05DFBB1D58B86B7A96920184082B6' + Invoke-Wsl "mkdir -p /opt/clickhouse /var/lib/clickhouse && tar -xzf $(ConvertTo-WslPath $archive) -C /opt/clickhouse --strip-components=1" + Start-Process wsl -ArgumentList '--distribution', $Distribution, '--user', 'root', '--', 'sh', '-c', ` + '"cd /var/lib/clickhouse && exec /opt/clickhouse/usr/bin/clickhouse server > /var/lib/clickhouse/server.log 2>&1"' -WindowStyle Hidden + Wait-Listening 8123 3 { wsl --distribution $Distribution --user root -- tail -n 80 /var/lib/clickhouse/server.log } + Set-Live CLICKHOUSE 8123 default + } +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/CassandraTests.cs b/windows/tests/TablePro.Interop.Tests/Live/CassandraTests.cs new file mode 100644 index 0000000000..7b3d39ed95 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/CassandraTests.cs @@ -0,0 +1,34 @@ +namespace TablePro.Interop.Tests.Live; + +public sealed class CassandraTests : SqlEngineTests +{ + private const string Keyspace = "tablepro"; + + protected override string CorpusFile => "cassandra"; + + protected override async Task OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken) + { + var server = LiveServer.Require("CASSANDRA"); + await using (var start = await ConnectAsync(core, Connection(server, "system"), server.Secrets, cancellationToken)) + { + await using var editor = await start.OpenEditorAsync(cancellationToken); + await ExecuteAsync( + editor, + $"CREATE KEYSPACE IF NOT EXISTS {Keyspace} WITH replication = {{'class': 'SimpleStrategy', 'replication_factor': 1}}", + cancellationToken); + } + + return await ConnectAsync(core, Connection(server, Keyspace), server.Secrets, cancellationToken); + } + + protected override TableName Table(string name) => new(Keyspace, name); + + protected override string Qualified(string name) => $"{Keyspace}.{name}"; + + protected override string CorpusTableSql(string table) => $"CREATE TABLE {table} (id int PRIMARY KEY, label text)"; + + protected override string PeopleTableSql(string table) => $"CREATE TABLE {table} (id int PRIMARY KEY, name text, note text)"; + + private static SavedConnection Connection(LiveServer server, string keyspace) => + new(null, "Cassandra", "cassandra", LiveServer.Host, server.Port, keyspace, server.UserName, TlsSettings.Disabled); +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/ClickHouseTests.cs b/windows/tests/TablePro.Interop.Tests/Live/ClickHouseTests.cs new file mode 100644 index 0000000000..afc3928c2b --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/ClickHouseTests.cs @@ -0,0 +1,33 @@ +namespace TablePro.Interop.Tests.Live; + +public sealed class ClickHouseTests : SqlEngineTests +{ + private const string Database = "tablepro"; + + protected override string CorpusFile => "clickhouse"; + + protected override async Task OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken) + { + var server = LiveServer.Require("CLICKHOUSE"); + await using (var start = await ConnectAsync(core, Connection(server, "default"), server.Secrets, cancellationToken)) + { + await using var editor = await start.OpenEditorAsync(cancellationToken); + await ExecuteAsync(editor, $"CREATE DATABASE IF NOT EXISTS {Database}", cancellationToken); + } + + return await ConnectAsync(core, Connection(server, Database), server.Secrets, cancellationToken); + } + + protected override TableName Table(string name) => new(Database, name); + + protected override string Qualified(string name) => $"`{Database}`.`{name}`"; + + protected override string CorpusTableSql(string table) => + $"CREATE TABLE {table} (id Int32, label String) ENGINE = MergeTree ORDER BY id"; + + protected override string PeopleTableSql(string table) => + $"CREATE TABLE {table} (id Int32, name String, note Nullable(String)) ENGINE = MergeTree ORDER BY id"; + + private static SavedConnection Connection(LiveServer server, string database) => + new(null, "ClickHouse", "clickhouse", LiveServer.Host, server.Port, database, server.UserName, TlsSettings.Disabled); +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/DuckDbTests.cs b/windows/tests/TablePro.Interop.Tests/Live/DuckDbTests.cs new file mode 100644 index 0000000000..68e372c984 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/DuckDbTests.cs @@ -0,0 +1,19 @@ +namespace TablePro.Interop.Tests.Live; + +// In process, so it runs wherever the tests do. +public sealed class DuckDbTests : SqlEngineTests +{ + protected override string CorpusFile => "duckdb"; + + protected override Task OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken) => + core.OpenFileAsync(new FileOpenOptions(Path.Combine(directory, "live.duckdb"), "duckdb", Create: true), cancellationToken); + + protected override TableName Table(string name) => new("main", name); + + protected override string Qualified(string name) => $"\"{name}\""; + + protected override string CorpusTableSql(string table) => $"CREATE TABLE {table} (id integer PRIMARY KEY, label text NOT NULL)"; + + protected override string PeopleTableSql(string table) => + $"CREATE TABLE {table} (id integer PRIMARY KEY, name text NOT NULL, note text)"; +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs b/windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs new file mode 100644 index 0000000000..e7a9df3c94 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs @@ -0,0 +1,32 @@ +using System.Globalization; + +namespace TablePro.Interop.Tests.Live; + +// A server windows/ci/live-servers.ps1 started on this machine, from its TABLEPRO_TEST_LIVE__* variables. +internal sealed record LiveServer(int Port, string UserName, string? Password) +{ + public const string Host = "127.0.0.1"; + + public static LiveServer? Find(string engine) + { + var prefix = $"TABLEPRO_TEST_LIVE_{engine}_"; + if (Environment.GetEnvironmentVariable(prefix + "PORT") is not { Length: > 0 } port) + { + return null; + } + + return new LiveServer( + int.Parse(port, CultureInfo.InvariantCulture), + Environment.GetEnvironmentVariable(prefix + "USER") ?? string.Empty, + Environment.GetEnvironmentVariable(prefix + "PASSWORD")); + } + + public static LiveServer Require(string engine) + { + var server = Find(engine); + Assert.SkipWhen(server is null, $"Requires the live {engine} server that windows/ci/live-servers.ps1 starts."); + return server!; + } + + public ConnectionSecrets Secrets => new(DatabasePassword: Password); +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs b/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs new file mode 100644 index 0000000000..83ccc145d0 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs @@ -0,0 +1,198 @@ +namespace TablePro.Interop.Tests.Live; + +public sealed class MongoDbTests : IDisposable +{ + private const string Database = "tablepro"; + + // The document of every BSON type the grid shows that core/crates/drivers/mongodb/tests/integration/statements.rs reads. + private const string EveryType = "{_id: 1, oid: ObjectId('5f1d7a0c9b1e8b2a3c4d5e6f'), " + + "at: ISODate('2024-05-06T07:08:09.010Z'), price: NumberDecimal('12.50'), big: NumberLong('9007199254740993'), " + + "ratio: 0.5, flag: true, nothing: null, nested: {a: [1, 2]}, " + + "uid: UUID('0e3f6f0e-8a3b-4b8e-9a7c-2f1d1b3c4d5e'), blob: BinData(0, 'AAEC'), " + + "stamp: Timestamp({t: 1700000000, i: 3})}"; + + private static readonly Dictionary EveryTypeShows = new() + { + ["_id"] = "1", + ["oid"] = "5f1d7a0c9b1e8b2a3c4d5e6f", + ["at"] = "2024-05-06 07:08:09.01+00:00", + ["price"] = "12.50", + ["big"] = "9007199254740993", + ["ratio"] = "0.5", + ["flag"] = "true", + ["nothing"] = null, + ["nested"] = """{"a": [1, 2]}""", + ["uid"] = "0e3f6f0e-8a3b-4b8e-9a7c-2f1d1b3c4d5e", + ["blob"] = "0x000102", + ["stamp"] = """{"$timestamp": {"t": 1700000000, "i": 3}}""", + }; + + private readonly string _directory = Directory.CreateTempSubdirectory("tablepro-live-").FullName; + private readonly string _unique = Guid.NewGuid().ToString("N")[..8]; + private readonly TableProCore _core; + + public MongoDbTests() + { + _core = TableProCore.Create(new HostConfiguration("live-test", _directory), new MemorySecretStore()); + } + + [Fact] + public async Task ACollectionIsListedPagedAndCounted() + { + var cancellationToken = TestContext.Current.CancellationToken; + await using var session = await ConnectAsync(cancellationToken); + await using var editor = await session.OpenEditorAsync(cancellationToken); + var collection = await PeopleAsync(session, editor, cancellationToken); + + using var page = await PageAsync(session, collection, cancellationToken); + var count = await session.CountRowsAsync(collection, cancellationToken: cancellationToken); + + Assert.Equal( + new Dictionary { ["1"] = "Ada", ["2"] = "Grace", ["3"] = "Zoë 👋" }, + Texts(page.Set, "name")); + Assert.Equal(3, count); + } + + [Fact] + public async Task EveryBsonTypeReadsBackAsTheGridShowsIt() + { + var cancellationToken = TestContext.Current.CancellationToken; + await using var session = await ConnectAsync(cancellationToken); + await using var editor = await session.OpenEditorAsync(cancellationToken); + var name = $"types_{_unique}"; + await ExecuteAsync(editor, $"db.getCollection('{name}').insertOne({EveryType})", cancellationToken); + + using var browsed = await PageAsync(session, new TableName(Database, name), cancellationToken); + using var found = await RowsAsync(editor.Run($"db.getCollection('{name}').find()", cancellationToken: cancellationToken)); + + var wrong = Wrong("browse", browsed.Set).Concat(Wrong("editor", found.Set)).ToList(); + Assert.True(wrong.Count == 0, string.Join('\n', wrong)); + } + + [Fact] + public async Task ADocumentSaveWritesAnUpdateAnInsertAndADelete() + { + var cancellationToken = TestContext.Current.CancellationToken; + await using var session = await ConnectAsync(cancellationToken); + await using var editor = await session.OpenEditorAsync(cancellationToken); + var collection = await PeopleAsync(session, editor, cancellationToken); + using var tableEditor = await session.OpenTableEditorAsync(collection, refresh: false, cancellationToken); + using var page = await PageAsync(session, collection, cancellationToken); + var rows = RowsById(page.Set); + var columns = tableEditor.Columns.Select(column => column.Name).ToList(); + CellEdit NewCell(string column) => column switch + { + "_id" => new CellEdit.Text("4"), + "name" => new CellEdit.Text("Edsger"), + _ => CellEdit.Null.Instance, + }; + + using var save = tableEditor.Plan(page.Set, + [ + new RowEdit.Update(rows["1"], [new CellChange(columns.IndexOf("note"), new CellEdit.Text("first"))]), + new RowEdit.Insert([.. columns.Select(NewCell)]), + new RowEdit.Delete(rows["2"]), + ]); + var outcome = await save.RunAsync(confirmed: false, cancellationToken); + using var after = await RowsAsync(editor.Run($"db.getCollection('{collection.Name}').find()", cancellationToken: cancellationToken)); + + Assert.True(outcome is RowSaveOutcome.Saved, $"the save ended {outcome}"); + Assert.Equal( + new Dictionary { ["1"] = "Ada", ["3"] = "Zoë 👋", ["4"] = "Edsger" }, + Texts(after.Set, "name")); + Assert.Equal( + new Dictionary { ["1"] = "first", ["3"] = "中文", ["4"] = null }, + Texts(after.Set, "note")); + } + + public void Dispose() + { + _core.Dispose(); + Directory.Delete(_directory, recursive: true); + } + + private async Task ConnectAsync(CancellationToken cancellationToken) + { + var server = LiveServer.Require("MONGODB"); + var saved = await _core.Library.SaveAsync( + new SavedConnection(null, "MongoDB", "mongodb", LiveServer.Host, server.Port, Database, server.UserName, TlsSettings.Disabled), + server.Secrets); + return await _core.ConnectAsync(saved.Id!.Value, cancellationToken: cancellationToken); + } + + private async Task PeopleAsync(DatabaseSession session, QueryEditor editor, CancellationToken cancellationToken) + { + var name = $"people_{_unique}"; + await ExecuteAsync( + editor, + $"db.getCollection('{name}').insertMany([{{_id: 1, name: 'Ada', note: null}}, " + + "{_id: 2, name: 'Grace', note: 'note'}, {_id: 3, name: 'Zoë 👋', note: '中文'}])", + cancellationToken); + var objects = await session.RefreshObjectsAsync(ObjectScope.DefaultSchema, cancellationToken); + var entry = Assert.Single(objects, item => item.Name == name); + Assert.Equal(ObjectKind.Table, entry.Kind); + return new TableName(entry.Schema, entry.Name); + } + + private static async Task ExecuteAsync(QueryEditor editor, string statement, CancellationToken cancellationToken) + { + using var run = editor.Run(statement, cancellationToken: cancellationToken); + var outcome = await run.Completion; + Assert.True(outcome is QueryOutcome.Completed, $"`{statement}` ended {outcome}"); + } + + private static async Task PageAsync(DatabaseSession session, TableName collection, CancellationToken cancellationToken) + { + var page = await session.ReadTablePageAsync(collection, null, null, 1_000, cancellationToken: cancellationToken); + return await RowsAsync(page.Run); + } + + private static async Task RowsAsync(QueryRun run) + { + var outcome = await run.Completion; + if (outcome is not QueryOutcome.Completed) + { + run.Dispose(); + Assert.Fail($"the read ended {outcome}"); + } + + return new Rows(run, run.GetResultSet(0) ?? throw new InvalidOperationException("The read held no set.")); + } + + private static IEnumerable Wrong(string path, ResultSet set) + { + var columns = set.GetColumns().Select(column => column.Name).ToList(); + foreach (var (field, expected) in EveryTypeShows) + { + var index = columns.IndexOf(field); + var shown = index < 0 ? "" : set.GetCellText(0, index); + if (shown != expected) + { + yield return $"{path}: `{field}` shows {shown ?? "NULL"}, expected {expected ?? "NULL"}"; + } + } + } + + private static Dictionary RowsById(ResultSet set) + { + var id = set.GetColumns().ToList().FindIndex(column => column.Name == "_id"); + return Enumerable.Range(0, (int)set.RowCount).ToDictionary(row => set.GetCellText(row, id)!, row => (long)row); + } + + private static Dictionary Texts(ResultSet set, string column) + { + var index = set.GetColumns().ToList().FindIndex(item => item.Name == column); + return RowsById(set).ToDictionary(pair => pair.Key, pair => set.GetCellText(pair.Value, index)); + } + + private sealed class Rows(QueryRun run, ResultSet set) : IDisposable + { + public ResultSet Set { get; } = set; + + public void Dispose() + { + Set.Dispose(); + run.Dispose(); + } + } +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/MySqlTests.cs b/windows/tests/TablePro.Interop.Tests/Live/MySqlTests.cs new file mode 100644 index 0000000000..4ca0da10eb --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/MySqlTests.cs @@ -0,0 +1,29 @@ +namespace TablePro.Interop.Tests.Live; + +public sealed class MySqlTests : SqlEngineTests +{ + private const string Database = "tablepro"; + + protected override string CorpusFile => "mysql"; + + protected override string? CorpusFlavour => "mysql"; + + protected override Task OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken) + { + var server = LiveServer.Require("MYSQL"); + return ConnectAsync( + core, + new SavedConnection(null, "MySQL", "mysql", LiveServer.Host, server.Port, Database, server.UserName, new TlsSettings(TlsMode.Require)), + server.Secrets, + cancellationToken); + } + + protected override TableName Table(string name) => new(Database, name); + + protected override string Qualified(string name) => $"`{Database}`.`{name}`"; + + protected override string CorpusTableSql(string table) => $"CREATE TABLE {table} (id integer PRIMARY KEY, label text NOT NULL)"; + + protected override string PeopleTableSql(string table) => + $"CREATE TABLE {table} (id integer PRIMARY KEY, name varchar(100) NOT NULL, note text)"; +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs b/windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs new file mode 100644 index 0000000000..d3ac5792b6 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs @@ -0,0 +1,119 @@ +namespace TablePro.Interop.Tests.Live; + +public sealed class RedisTests : IDisposable +{ + private readonly string _directory = Directory.CreateTempSubdirectory("tablepro-live-").FullName; + private readonly string _prefix = $"tp:{Guid.NewGuid().ToString("N")[..8]}:"; + private readonly TableProCore _core; + + public RedisTests() + { + _core = TableProCore.Create(new HostConfiguration("live-test", _directory), new MemorySecretStore()); + } + + [Fact] + public async Task EveryKeyTypeIsListedAndReadsBackAsTheGridShowsIt() + { + var cancellationToken = TestContext.Current.CancellationToken; + await using var session = await ConnectAsync(cancellationToken); + await using var editor = await session.OpenEditorAsync(cancellationToken); + foreach (var command in new[] + { + $"SET {_prefix}text \"naïve café 🦀\"", + $"SET {_prefix}bytes \"\\xff\\x00\\xfe\"", + $"HSET {_prefix}hash f1 v1 f2 \"two words\"", + $"RPUSH {_prefix}list a b c", + $"SADD {_prefix}set x y", + $"ZADD {_prefix}zset 1.5 m1 -0.25 m2", + $"XADD {_prefix}stream 1-1 a 1 b 2", + }) + { + await ExecuteAsync(editor, command, cancellationToken); + } + + var keys = await session.RefreshObjectsAsync(ObjectScope.DefaultSchema, cancellationToken); + var ours = keys.Where(key => key.Name.StartsWith(_prefix, StringComparison.Ordinal)).ToList(); + + Assert.All(ours, key => Assert.Equal(ObjectKind.Key, key.Kind)); + Assert.Equal( + ["bytes", "hash", "list", "set", "stream", "text", "zset"], + ours.Select(key => key.Name[_prefix.Length..]).Order(StringComparer.Ordinal)); + Assert.Equal((KeyKind.Text, Rows(["naïve café 🦀"])), await ReadAsync(session, "text", cancellationToken)); + Assert.Equal((KeyKind.Text, Rows(["0xff00fe"])), await ReadAsync(session, "bytes", cancellationToken)); + Assert.Equal((KeyKind.Hash, Rows(["f1", "v1"], ["f2", "two words"])), await ReadAsync(session, "hash", cancellationToken, sorted: true)); + Assert.Equal((KeyKind.List, Rows(["0", "a"], ["1", "b"], ["2", "c"])), await ReadAsync(session, "list", cancellationToken)); + Assert.Equal((KeyKind.Set, Rows(["x"], ["y"])), await ReadAsync(session, "set", cancellationToken, sorted: true)); + Assert.Equal((KeyKind.SortedSet, Rows(["m2", "-0.25"], ["m1", "1.5"])), await ReadAsync(session, "zset", cancellationToken)); + Assert.Equal((KeyKind.Stream, Rows(["1-1", """{"a":"1","b":"2"}"""])), await ReadAsync(session, "stream", cancellationToken)); + } + + [Fact] + public async Task AWriteFromTheEditorReadsBackAndADeletedKeyIsGone() + { + var cancellationToken = TestContext.Current.CancellationToken; + await using var session = await ConnectAsync(cancellationToken); + await using var editor = await session.OpenEditorAsync(cancellationToken); + await ExecuteAsync(editor, $"HSET {_prefix}hash f1 v1", cancellationToken); + await ExecuteAsync(editor, $"SET {_prefix}gone x EX 3600", cancellationToken); + var before = await ReadWindowAsync(session, "gone", cancellationToken); + + await ExecuteAsync(editor, $"HSET {_prefix}hash f1 changed", cancellationToken); + await ExecuteAsync(editor, $"DEL {_prefix}gone", cancellationToken); + var hash = await ReadAsync(session, "hash", cancellationToken); + var after = await ReadWindowAsync(session, "gone", cancellationToken); + + var ttl = Assert.IsType(before?.Ttl); + Assert.InRange(ttl.Left, TimeSpan.FromMinutes(55), TimeSpan.FromHours(1)); + Assert.Equal((KeyKind.Hash, Rows(["f1", "changed"])), hash); + Assert.Null(after); + } + + public void Dispose() + { + _core.Dispose(); + Directory.Delete(_directory, recursive: true); + } + + private async Task ConnectAsync(CancellationToken cancellationToken) + { + var server = LiveServer.Require("REDIS"); + var saved = await _core.Library.SaveAsync( + new SavedConnection(null, "Redis", "redis", LiveServer.Host, server.Port, "0", server.UserName, TlsSettings.Disabled), + server.Secrets); + return await _core.ConnectAsync(saved.Id!.Value, cancellationToken: cancellationToken); + } + + private static async Task ExecuteAsync(QueryEditor editor, string command, CancellationToken cancellationToken) + { + using var run = editor.Run(command, cancellationToken: cancellationToken); + var outcome = await run.Completion; + Assert.True(outcome is QueryOutcome.Completed, $"`{command}` ended {outcome}"); + } + + private async Task ReadWindowAsync(DatabaseSession session, string key, CancellationToken cancellationToken) + { + using var reader = session.OpenKey(_prefix + key); + return await reader.ReadMoreAsync(cancellationToken); + } + + private async Task<(KeyKind, string)> ReadAsync( + DatabaseSession session, + string key, + CancellationToken cancellationToken, + bool sorted = false) + { + using var reader = session.OpenKey(_prefix + key); + var window = await reader.ReadMoreAsync(cancellationToken); + Assert.NotNull(window); + Assert.False(window.HasMore); + using var set = reader.GetRows(); + Assert.NotNull(set); + var columns = set.GetColumns().Count; + var rows = Enumerable.Range(0, (int)set.RowCount) + .Select(row => string.Join(" | ", Enumerable.Range(0, columns).Select(column => set.GetCellText(row, column) ?? "NULL"))) + .ToList(); + return (window.Kind, string.Join('\n', sorted ? rows.Order(StringComparer.Ordinal) : rows)); + } + + private static string Rows(params string[][] rows) => string.Join('\n', rows.Select(row => string.Join(" | ", row))); +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs b/windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs new file mode 100644 index 0000000000..c2a005443b --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs @@ -0,0 +1,297 @@ +using System.Globalization; +using System.Text.Encodings.Web; +using System.Text.Json; + +namespace TablePro.Interop.Tests.Live; + +// What every SQL engine is checked for through the core: a table listed, paged, counted and described; each value of the +// engine's corpus read back as a table tab and a query tab show it; and a save of an update, an insert and a delete. +public abstract class SqlEngineTests : IAsyncDisposable +{ + private static readonly (int Id, string Name, string? Note)[] People = + [ + (1, "Ada", null), + (2, "Grace", "note"), + (3, "Zoë 👋", "中文"), + ]; + + private static readonly JsonSerializerOptions Readable = new() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; + + private readonly string _directory = Directory.CreateTempSubdirectory("tablepro-live-").FullName; + private readonly List _open = []; + private TableProCore? _core; + + protected string Unique { get; } = Guid.NewGuid().ToString("N")[..8]; + + protected abstract string CorpusFile { get; } + + protected virtual string? CorpusFlavour => null; + + protected abstract Task OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken); + + protected abstract TableName Table(string name); + + protected abstract string Qualified(string name); + + protected abstract string CorpusTableSql(string table); + + protected abstract string PeopleTableSql(string table); + + protected virtual string Text(string value) => $"'{value.Replace("'", "''", StringComparison.Ordinal)}'"; + + [Fact] + public async Task ATableIsListedPagedCountedAndDescribed() + { + var cancellationToken = TestContext.Current.CancellationToken; + var (session, editor) = await StartAsync(cancellationToken); + var table = await PeopleAsync(session, editor, cancellationToken); + + using var rows = await PageAsync(session, table, cancellationToken); + var count = await session.CountRowsAsync(table, cancellationToken: cancellationToken); + var structure = await session.GetStructureAsync(table, ObjectKind.Table, cancellationToken); + + Assert.Equal( + People.ToDictionary(person => (long)person.Id, person => (string?)person.Name), + TextsById(rows.Set, "name")); + Assert.Equal(People.Length, count); + Assert.Equal(["id", "name", "note"], structure.Columns.Select(column => column.Name)); + } + + [Fact] + public async Task EveryCorpusValueReadsBackAsTheGridShowsIt() + { + var cancellationToken = TestContext.Current.CancellationToken; + var (session, editor) = await StartAsync(cancellationToken); + var corpus = ValueCorpus.Load(CorpusFile, CorpusFlavour); + var wrong = new List(); + + for (var index = 0; index < corpus.Count; index++) + { + var column = corpus[index]; + var name = $"corpus_{index}_{Unique}"; + var table = Qualified(name); + List statements = [CorpusTableSql(table), .. column.Setup ?? [], $"ALTER TABLE {table} ADD {column.Column}"]; + statements.AddRange(column.Values.Select( + (value, row) => $"INSERT INTO {table} (id, label, v) VALUES ({row}, 'corpus', {value.Sql})")); + if (await FirstRefusalAsync(editor, statements, cancellationToken) is { } refusal) + { + wrong.Add($"`{column.Column}`: {refusal}"); + continue; + } + + using (var browsed = await PageAsync(session, Table(name), cancellationToken)) + { + Compare("browse", column, TextsById(browsed.Set, "v"), wrong); + } + + using var edited = await SelectAsync(editor, $"SELECT id, v FROM {table}", cancellationToken); + Compare("editor", column, TextsById(edited.Set, "v"), wrong); + } + + Assert.True(wrong.Count == 0, $"{wrong.Count} values did not read back as written:\n{string.Join('\n', wrong)}"); + } + + [Fact] + public async Task ARowSaveWritesAnUpdateAnInsertAndADelete() + { + var cancellationToken = TestContext.Current.CancellationToken; + var (session, editor) = await StartAsync(cancellationToken); + var table = await PeopleAsync(session, editor, cancellationToken); + using var tableEditor = await session.OpenTableEditorAsync(table, refresh: false, cancellationToken); + using var page = await PageAsync(session, table, cancellationToken); + var rows = RowsById(page.Set); + var columns = tableEditor.Columns.Select(column => column.Name).ToList(); + CellEdit NewCell(string column) => column switch + { + "id" => new CellEdit.Text("4"), + "name" => new CellEdit.Text("Edsger"), + _ => CellEdit.Null.Instance, + }; + + using var save = tableEditor.Plan(page.Set, + [ + new RowEdit.Update(rows[1], [new CellChange(columns.IndexOf("note"), new CellEdit.Text("first"))]), + new RowEdit.Insert([.. columns.Select(NewCell)]), + new RowEdit.Delete(rows[2]), + ]); + var outcome = await save.RunAsync(confirmed: false, cancellationToken); + using var after = await SelectAsync(editor, $"SELECT id, name, note FROM {Qualified(table.Name)}", cancellationToken); + + Assert.Null(tableEditor.LockFor(page.Set)); + Assert.True(outcome is RowSaveOutcome.Saved, $"the save ended {outcome}"); + Assert.Equal( + new Dictionary { [1] = "Ada", [3] = "Zoë 👋", [4] = "Edsger" }, + TextsById(after.Set, "name")); + Assert.Equal( + new Dictionary { [1] = "first", [3] = "中文", [4] = null }, + TextsById(after.Set, "note")); + } + + public async ValueTask DisposeAsync() + { + for (var index = _open.Count - 1; index >= 0; index--) + { + await _open[index].DisposeAsync(); + } + + _core?.Dispose(); + try + { + Directory.Delete(_directory, recursive: true); + } + catch (IOException) + { + // A file engine closes on the core's own threads, which can still hold the file here on Windows. + } + + GC.SuppressFinalize(this); + } + + protected static async Task ConnectAsync( + TableProCore core, + SavedConnection connection, + ConnectionSecrets secrets, + CancellationToken cancellationToken) + { + var saved = await core.Library.SaveAsync(connection, secrets); + return await core.ConnectAsync(saved.Id!.Value, cancellationToken: cancellationToken); + } + + protected static async Task ExecuteAsync(QueryEditor editor, string sql, CancellationToken cancellationToken) + { + if (await RefusalAsync(editor, sql, cancellationToken) is { } refusal) + { + Assert.Fail(refusal); + } + } + + private async Task<(DatabaseSession Session, QueryEditor Editor)> StartAsync(CancellationToken cancellationToken) + { + _core = TableProCore.Create(new HostConfiguration("live-test", _directory), new MemorySecretStore()); + var session = await OpenAsync(_core, _directory, cancellationToken); + _open.Add(session); + var editor = await session.OpenEditorAsync(cancellationToken); + _open.Add(editor); + return (session, editor); + } + + private async Task PeopleAsync(DatabaseSession session, QueryEditor editor, CancellationToken cancellationToken) + { + var name = $"people_{Unique}"; + var table = Qualified(name); + await ExecuteAsync(editor, PeopleTableSql(table), cancellationToken); + foreach (var (id, person, note) in People) + { + var noteSql = note is null ? "NULL" : Text(note); + await ExecuteAsync( + editor, + $"INSERT INTO {table} (id, name, note) VALUES ({id}, {Text(person)}, {noteSql})", + cancellationToken); + } + + var objects = await session.RefreshObjectsAsync(ObjectScope.DefaultSchema, cancellationToken); + var entry = Assert.Single(objects, item => item.Name == name); + Assert.Equal(ObjectKind.Table, entry.Kind); + Assert.Equal(Table(name), new TableName(entry.Schema, entry.Name)); + return Table(name); + } + + private static async Task FirstRefusalAsync( + QueryEditor editor, + IEnumerable statements, + CancellationToken cancellationToken) + { + foreach (var sql in statements) + { + if (await RefusalAsync(editor, sql, cancellationToken) is { } refusal) + { + return refusal; + } + } + + return null; + } + + private static async Task RefusalAsync(QueryEditor editor, string sql, CancellationToken cancellationToken) + { + using var run = editor.Run(sql, cancellationToken: cancellationToken); + return await run.Completion switch + { + QueryOutcome.Completed => null, + QueryOutcome.Failed failed => $"`{sql}` failed: {failed.Error.Code} {failed.Error.Message}", + var other => $"`{sql}` ended {other}", + }; + } + + private static async Task PageAsync(DatabaseSession session, TableName table, CancellationToken cancellationToken) + { + var page = await session.ReadTablePageAsync(table, null, null, 1_000, cancellationToken: cancellationToken); + return await RowsAsync(page.Run, $"the page of {table}"); + } + + private static Task SelectAsync(QueryEditor editor, string sql, CancellationToken cancellationToken) => + RowsAsync(editor.Run(sql, cancellationToken: cancellationToken), $"`{sql}`"); + + private static async Task RowsAsync(QueryRun run, string what) + { + var outcome = await run.Completion; + if (outcome is not QueryOutcome.Completed) + { + run.Dispose(); + Assert.Fail($"{what} ended {(outcome is QueryOutcome.Failed failed ? failed.Error.Message : outcome)}"); + } + + return new Rows(run, run.GetResultSet(0) ?? throw new InvalidOperationException($"{what} read no set.")); + } + + private static Dictionary RowsById(ResultSet set) + { + var id = ColumnIndex(set, "id"); + return Enumerable.Range(0, (int)set.RowCount) + .ToDictionary(row => long.Parse(set.GetCellText(row, id)!, CultureInfo.InvariantCulture), row => (long)row); + } + + private static Dictionary TextsById(ResultSet set, string column) + { + var index = ColumnIndex(set, column); + return RowsById(set).ToDictionary(pair => pair.Key, pair => set.GetCellText(pair.Value, index)); + } + + private static int ColumnIndex(ResultSet set, string name) + { + var columns = set.GetColumns(); + var index = columns.ToList().FindIndex(column => column.Name == name); + Assert.True(index >= 0, $"no `{name}` column in {string.Join(", ", columns.Select(column => column.Name))}"); + return index; + } + + private static void Compare(string path, CorpusColumn column, Dictionary read, List wrong) + { + for (var row = 0; row < column.Values.Count; row++) + { + var value = column.Values[row]; + var expected = path == "editor" && value.Edited is not null ? value.Edited : value.Shows; + if (!read.TryGetValue(row, out var shown)) + { + wrong.Add($"{path}: `{column.Column}` lost the row holding {value.Sql}"); + } + else if (shown != expected) + { + wrong.Add($"{path}: `{column.Column}` holding {value.Sql} shows {Quoted(shown)}, expected {Quoted(expected)}"); + } + } + } + + private static string Quoted(string? text) => text is null ? "NULL" : JsonSerializer.Serialize(text, Readable); + + private sealed class Rows(QueryRun run, ResultSet set) : IDisposable + { + public ResultSet Set { get; } = set; + + public void Dispose() + { + Set.Dispose(); + run.Dispose(); + } + } +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs b/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs new file mode 100644 index 0000000000..339e69d04d --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs @@ -0,0 +1,62 @@ +namespace TablePro.Interop.Tests.Live; + +public sealed class SqlServerTests : SqlEngineTests +{ + private const string Database = "tablepro"; + + protected override string CorpusFile => "mssql"; + + [Fact] + public async Task AWindowsLoginSignsInAsTheAccountRunningTheTests() + { + var cancellationToken = TestContext.Current.CancellationToken; + var server = LiveServer.Require("MSSQL"); + using var core = TableProCore.Create(new HostConfiguration("live-test"), new MemorySecretStore()); + await using var session = await ConnectAsync( + core, + Connection(server) with { UserName = string.Empty, IntegratedAuth = true }, + ConnectionSecrets.None, + cancellationToken); + await using var editor = await session.OpenEditorAsync(cancellationToken); + using var run = editor.Run("SELECT SUSER_SNAME()", cancellationToken: cancellationToken); + + Assert.IsType(await run.Completion); + using var set = run.GetResultSet(0); + Assert.NotNull(set); + Assert.Equal($@"{Environment.UserDomainName}\{Environment.UserName}", set.GetCellText(0, 0), ignoreCase: true); + } + + protected override async Task OpenAsync(TableProCore core, string directory, CancellationToken cancellationToken) + { + var server = LiveServer.Require("MSSQL"); + await using (var master = await ConnectAsync(core, Connection(server) with { Database = "master" }, server.Secrets, cancellationToken)) + { + await using var editor = await master.OpenEditorAsync(cancellationToken); + await ExecuteAsync(editor, $"IF DB_ID(N'{Database}') IS NULL CREATE DATABASE {Database}", cancellationToken); + } + + return await ConnectAsync(core, Connection(server), server.Secrets, cancellationToken); + } + + protected override TableName Table(string name) => new("dbo", name); + + protected override string Qualified(string name) => $"[dbo].[{name}]"; + + protected override string Text(string value) => "N" + base.Text(value); + + protected override string CorpusTableSql(string table) => $"CREATE TABLE {table} (id int PRIMARY KEY, label nvarchar(200) NOT NULL)"; + + protected override string PeopleTableSql(string table) => + $"CREATE TABLE {table} (id int PRIMARY KEY, name nvarchar(100) NOT NULL, note nvarchar(max))"; + + // core/crates/drivers/mssql/tests/windows/sql-server.ps1 gives the server a self-signed certificate for localhost. + private static SavedConnection Connection(LiveServer server) => new( + null, + "SQL Server", + "mssql", + "localhost", + server.Port, + Database, + server.UserName, + new TlsSettings(TlsMode.VerifyFull, CaFile: Environment.GetEnvironmentVariable("TABLEPRO_TEST_MSSQL_WINDOWS_CA"))); +} diff --git a/windows/tests/TablePro.Interop.Tests/Live/ValueCorpus.cs b/windows/tests/TablePro.Interop.Tests/Live/ValueCorpus.cs new file mode 100644 index 0000000000..20f64f6891 --- /dev/null +++ b/windows/tests/TablePro.Interop.Tests/Live/ValueCorpus.cs @@ -0,0 +1,23 @@ +using System.Text.Json; + +namespace TablePro.Interop.Tests.Live; + +internal sealed record CorpusValue(string Sql, string? Shows, string? Edited); + +internal sealed record CorpusColumn(string Column, IReadOnlyList? Setup, IReadOnlyList Values, string? Only); + +// The value corpus the core's conformance suites read, in core/crates/test-support/corpus, copied beside the tests. +internal static class ValueCorpus +{ + private static readonly JsonSerializerOptions Options = new(JsonSerializerDefaults.Web); + + public static IReadOnlyList Load(string file, string? flavour = null) + { + var path = Path.Combine(AppContext.BaseDirectory, "corpus", file + ".json"); + var corpus = JsonSerializer.Deserialize(File.ReadAllText(path), Options) + ?? throw new InvalidDataException($"{path} holds no corpus."); + return [.. corpus.Columns.Where(column => column.Only is null || column.Only == flavour)]; + } + + private sealed record CorpusFile(IReadOnlyList Columns); +} diff --git a/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj b/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj index e95b80ca7f..673081d8c6 100644 --- a/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj +++ b/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj @@ -15,6 +15,7 @@ + From 8fd52f451165e8fddb1e25ef8e552f31ebe0f54c Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 12:33:41 +0700 Subject: [PATCH 2/8] docs(windows): name the live-server tests and their job --- .claude/rules/ci.md | 3 ++- .../src/conformance/cases/value_corpus.rs | 6 +++++- .../src/conformance/corpus_column.rs | 17 ++++++++++++++--- windows/AGENTS.md | 5 +++-- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/.claude/rules/ci.md b/.claude/rules/ci.md index edd57b351d..47ca7dc79d 100644 --- a/.claude/rules/ci.md +++ b/.claude/rules/ci.md @@ -40,6 +40,7 @@ paths: - macOS Tests runs the Unit and UI plans in full, with no shard, parallel, iteration or retry flag. - `core.yml` runs the core on Windows x64 and Arm64 and on macOS, where the same job builds and tests the Swift bindings, and SQL Server's integrated login on Windows x64. The SSH tunnel tests through Windows' OpenSSH Server run on x64; Arm64, whose image installs the server in about 20 minutes, runs them nightly. - A `v*` tag runs only `release.yml`, a `linux-v*` tag only `release-linux.yml`, a `windows-v*` tag only `release-windows.yml`. The last two also run by dispatch: `release-windows.yml` then publishes nothing (`windows/RELEASING.md`), and `release-linux.yml` publishes nothing with `dry-run` and otherwise uploads a packaging fix (`linux/docs/releasing.md`). +- `windows.yml`'s live job runs the interop tests against MySQL, SQL Server, ClickHouse, Cassandra, MongoDB and Redis on `windows-2025`, beside the x64 job (`windows/docs/decisions/0013-live-server-tests.md`). - `windows-grid-gate.yml` runs only by dispatch: the Windows data grid's timing and behavior gate on `windows-2025` and `windows-11-arm`, whose numbers vary too much between hosted runners to gate a merge (`windows/docs/decisions/0003-data-grid-control.md`, Gate). `windows.yml` runs the grid's tests on every change. ## Change detector @@ -61,7 +62,7 @@ paths: ## Caches - `~/.spm-cache`, keyed on the app's `Package.resolved`. macOS Tests saves it on a push or nightly miss; Release and the Release Build job only restore it. `~/.spm-cache-ios`, keyed on the iOS project's, is the same for iOS and Package Tests. -- `build-linux.yml`, `core.yml` and `windows.yml` cache Cargo through `Swatinem/rust-cache`, saved from main only (pushes and the nightly), since a pull request's cache serves that pull request alone and evicts main's. They build with line tables only (`CARGO_PROFILE_DEV_DEBUG`), about 30% less cache than full debug info, since every cache shares the repository's 10 GB and the least recently used goes first. A Docker suite's cache is the package's, whichever server release the job runs. `windows.yml` also caches the pinned uniffi-bindgen-cs. `release-windows.yml` restores no cache. No libs or DerivedData cache: the libs download takes about 16 seconds. +- `build-linux.yml`, `core.yml` and `windows.yml` cache Cargo through `Swatinem/rust-cache`, saved from main only (pushes and the nightly), since a pull request's cache serves that pull request alone and evicts main's. They build with line tables only (`CARGO_PROFILE_DEV_DEBUG`), about 30% less cache than full debug info, since every cache shares the repository's 10 GB and the least recently used goes first. A Docker suite's cache is the package's, whichever server release the job runs. `windows.yml`'s live job reads the x64 job's cache and saves none, and the macOS job caches the pinned uniffi-bindgen-cs. `release-windows.yml` restores no cache. No libs or DerivedData cache: the libs download takes about 16 seconds. ## Writing workflow and lint code diff --git a/core/crates/test-support/src/conformance/cases/value_corpus.rs b/core/crates/test-support/src/conformance/cases/value_corpus.rs index d27d414c4d..5b583f9cf1 100644 --- a/core/crates/test-support/src/conformance/cases/value_corpus.rs +++ b/core/crates/test-support/src/conformance/cases/value_corpus.rs @@ -350,7 +350,11 @@ mod tests { fn column() -> CorpusColumn { corpus_column( "v numeric(10, 2)", - &[("1.5", Some("1.50"), None), ("2", Some("2.00"), Some("2")), ("NULL", None, None)], + &[ + ("1.5", Some("1.50"), None), + ("2", Some("2.00"), Some("2")), + ("NULL", None, None), + ], ) } diff --git a/core/crates/test-support/src/conformance/corpus_column.rs b/core/crates/test-support/src/conformance/corpus_column.rs index 3cb1622630..851c319364 100644 --- a/core/crates/test-support/src/conformance/corpus_column.rs +++ b/core/crates/test-support/src/conformance/corpus_column.rs @@ -117,11 +117,17 @@ mod tests { assert!(!columns.is_empty(), "{corpus:?} lists no column"); for column in columns { assert!( - column.declaration.starts_with("v ") || column.declaration.starts_with("COLUMN v ") || column.declaration == "v", + column.declaration.starts_with("v ") + || column.declaration.starts_with("COLUMN v ") + || column.declaration == "v", "{corpus:?}: `{}` does not add `v`", column.declaration ); - assert!(!column.values.is_empty(), "{corpus:?}: `{}` has no value", column.declaration); + assert!( + !column.values.is_empty(), + "{corpus:?}: `{}` has no value", + column.declaration + ); } } } @@ -129,7 +135,12 @@ mod tests { #[test] fn mysql_and_mariadb_share_the_common_columns_and_keep_their_own() { let declarations = |corpus: ValueCorpus| -> Vec { - corpus.columns().unwrap().into_iter().map(|column| column.declaration).collect() + corpus + .columns() + .unwrap() + .into_iter() + .map(|column| column.declaration) + .collect() }; let (mysql, mariadb) = (declarations(ValueCorpus::Mysql), declarations(ValueCorpus::Mariadb)); diff --git a/windows/AGENTS.md b/windows/AGENTS.md index d626c7d626..9f2591552e 100644 --- a/windows/AGENTS.md +++ b/windows/AGENTS.md @@ -15,7 +15,7 @@ This is the guide for work under `windows/`. The root `AGENTS.md` holds the rule - `TablePro.slnx`: the solution. `global.json`: the .NET 10 SDK, and Microsoft.Testing.Platform as the runner `dotnet test` uses. `Directory.Build.props`: nullable, warnings as errors and the latest recommended analyzers for every project. `Directory.Packages.props`: every package version. `.editorconfig`: the C# style. - `src/TablePro.Interop`: the library the app calls. Its public API is hand-written; `Generated/` holds the uniffi-bindgen-cs and csbindgen output, all `internal`, so a generator upgrade cannot change what the app sees. The project is AOT and trim compatible, and its analyzers fail the build otherwise. -- `tests/TablePro.Interop.Tests`: xunit v3 tests against the real core and real SQLite files. +- `tests/TablePro.Interop.Tests`: xunit v3 tests against the real core and real SQLite files. `Live/` reads a table, the core's value corpus (`core/crates/test-support/corpus`) and a save on each engine's server, or in process for DuckDB; a server's tests skip where `ci/live-servers.ps1` did not start it (`docs/decisions/0013-live-server-tests.md`). - `src/TablePro.Editor.Model`: the editor's text, carets, undo history, find and line-state highlighter. Plain `net10.0` with no WinUI, so `tests/TablePro.Editor.Model.Tests` runs anywhere. - `src/TablePro.Graphics`: the one text and drawing stack the controls share: Direct3D, Direct2D and DirectWrite through TerraFX, the editor's swap chain and line layouts, theme colors, and the font fallback warm-up. Its types are internal to the controls. - `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`. @@ -26,6 +26,7 @@ This is the guide for work under `windows/`. The root `AGENTS.md` holds the rule - `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. - `tests/TablePro.App.UITests`: UI Automation tests (FlaUI) that launch the built app with a data folder of their own, and the installed MSIX once `TABLEPRO_PACKAGE` names its family. +- `ci/live-servers.ps1`: starts one server the `Live/` interop tests reach on the x64 runner, for `windows.yml`. - `ci/desktop.ps1`: readies a hosted runner's desktop for UI work (privacy settings window, WSL console, display size, window dragging), for `windows.yml`, `release-windows.yml` and the grid gate. - `ci/winget-manifest.py`: writes a release's winget manifest, for `release-windows.yml`. - `scripts/engine-glyphs.py`: writes `src/TablePro.App/Resources/EngineGlyphs.xaml` from the macOS app's engine artwork. Run it after that artwork changes or an engine is added. @@ -101,4 +102,4 @@ Pass `-p:UniffiBindgenCs=` when it is not on `PATH`; the target refuses an ## CI -`.github/workflows/windows.yml`, which `ci.yml` calls when the `windows` suite changed (`.claude/rules/ci.md`). It builds the core and runs the tests on x64, Arm64 and macOS runners, publishes the app with Native AOT and runs its UI tests on the Windows runners with their screenshots as an artifact, and on macOS checks the committed bindings. CI's Lint job runs zizmor on every workflow. `.github/workflows/release-windows.yml` builds and ships a release (`RELEASING.md`). +`.github/workflows/windows.yml`, which `ci.yml` calls when the `windows` suite changed (`.claude/rules/ci.md`). It builds the core and runs the tests on x64, Arm64 and macOS runners, the `Live/` tests against their servers on a second x64 runner, publishes the app with Native AOT and runs its UI tests on the Windows runners with their screenshots as an artifact, and on macOS checks the committed bindings. CI's Lint job runs zizmor on every workflow. `.github/workflows/release-windows.yml` builds and ships a release (`RELEASING.md`). From f9613bbf36c42664da1aa6f88ada0d72ccfc5808 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 13:12:27 +0700 Subject: [PATCH 3/8] fix(windows): say a value the driver could not read is unreadable, as the Linux grid does --- core/crates/ffi/src/results/cell_text.rs | 13 ++++++++ core/crates/ffi/src/results/column_cells.rs | 20 ++++++++++++- .../src/TablePro.DataGrid.Model/CellBlock.cs | 16 ++++++++++ .../src/TablePro.DataGrid.Model/GridCopy.cs | 2 +- .../TablePro.DataGrid.Model/ResultSetData.cs | 4 +++ windows/src/TablePro.DataGrid/CellPainter.cs | 6 ++++ .../DataGridView.Interaction.cs | 3 +- .../CoreDataTests.cs | 30 +++++++++++++++++-- .../TablePro.Interop.Tests/Live/LiveServer.cs | 3 +- .../Live/SqlEngineTests.cs | 18 +++++++++-- .../Live/SqlServerTests.cs | 3 +- .../TablePro.Interop.Tests.csproj | 1 + 12 files changed, 107 insertions(+), 12 deletions(-) diff --git a/core/crates/ffi/src/results/cell_text.rs b/core/crates/ffi/src/results/cell_text.rs index 4659f51ab6..a41a11e211 100644 --- a/core/crates/ffi/src/results/cell_text.rs +++ b/core/crates/ffi/src/results/cell_text.rs @@ -2,6 +2,7 @@ use super::ValueKind; const HEX: &[u8; 16] = b"0123456789abcdef"; +// An unreadable value has no text of its own: its bytes name its type, which only the grid's window carries. pub(super) fn full(kind: ValueKind, bytes: &[u8]) -> String { match kind { ValueKind::Bytes => { @@ -9,6 +10,7 @@ pub(super) fn full(kind: ValueKind, bytes: &[u8]) -> String { push_hex(bytes, bytes.len(), &mut out); String::from_utf8_lossy(&out).into_owned() } + ValueKind::Undecodable => String::new(), _ => String::from_utf8_lossy(bytes).into_owned(), } } @@ -21,6 +23,7 @@ pub(super) fn head(kind: ValueKind, bytes: &[u8], max_chars: usize) -> (String, let cut = push_hex(bytes, max_chars.saturating_sub(2) / 2, &mut out); (String::from_utf8_lossy(&out).into_owned(), cut) } + ValueKind::Undecodable => (String::new(), false), _ => { let end = char_boundary_after(bytes, max_chars); (String::from_utf8_lossy(&bytes[..end]).into_owned(), end < bytes.len()) @@ -86,6 +89,16 @@ mod tests { (String::from_utf8(out).unwrap(), cut) } + #[test] + fn an_unreadable_value_shows_its_type_to_the_grid_and_has_no_text() { + assert_eq!( + shown(ValueKind::Undecodable, b"money", 100), + ("money".to_owned(), false) + ); + assert_eq!(full(ValueKind::Undecodable, b"money"), ""); + assert_eq!(head(ValueKind::Undecodable, b"money", 100), (String::new(), false)); + } + #[test] fn text_is_cut_at_a_character_and_kept_on_one_line() { assert_eq!( diff --git a/core/crates/ffi/src/results/column_cells.rs b/core/crates/ffi/src/results/column_cells.rs index 2e0ad6c039..c29e309b7d 100644 --- a/core/crates/ffi/src/results/column_cells.rs +++ b/core/crates/ffi/src/results/column_cells.rs @@ -64,6 +64,8 @@ impl ColumnCells { Value::Text(text) => self.keep(text.as_bytes()), Value::Json(json) => self.keep(json.as_str().as_bytes()), Value::Bytes(bytes) => self.keep(bytes), + // No text reads it back; the type's name lets the grid say what it could not read, as Linux's does. + Value::Undecodable(undecoded) => self.keep(undecoded.type_name.as_bytes()), other => { if let Some(text) = value_text(other, column) { self.bytes.extend_from_slice(text.as_bytes()); @@ -176,7 +178,7 @@ pub(super) fn cell_value(cell: Cell<'_>) -> Value { ValueKind::Interval => SqlInterval::from_str(&text()).ok().map(Value::Interval), ValueKind::Bits => bits_of(cell.bytes).map(Value::Bits), ValueKind::Undecodable => Some(Value::Undecodable(Box::new(UndecodedValue { - type_name: String::new(), + type_name: text().into_owned(), reason: UndecodableReason::UnsupportedType, }))), ValueKind::Array | ValueKind::Network | ValueKind::Spatial | ValueKind::Other => None, @@ -350,6 +352,22 @@ mod tests { assert_eq!(cells.cell(8).kind, Some(ValueKind::Text)); } + #[test] + fn an_unreadable_value_keeps_the_name_of_its_type() { + let undecoded = Value::Undecodable(Box::new(UndecodedValue { + type_name: "money".to_owned(), + reason: UndecodableReason::OutOfRange, + })); + let cells = cells(&[undecoded]); + + assert_eq!(cells.cell(0).kind, Some(ValueKind::Undecodable)); + assert_eq!(text(cells.cell(0)), "money"); + assert!(matches!( + cell_value(cells.cell(0)), + Value::Undecodable(read) if read.type_name == "money" + )); + } + #[test] fn a_cell_reads_back_as_a_value_that_orders_as_the_one_it_was_made_from() { use std::cmp::Ordering; diff --git a/windows/src/TablePro.DataGrid.Model/CellBlock.cs b/windows/src/TablePro.DataGrid.Model/CellBlock.cs index 7e7dc84293..0bec7f90e1 100644 --- a/windows/src/TablePro.DataGrid.Model/CellBlock.cs +++ b/windows/src/TablePro.DataGrid.Model/CellBlock.cs @@ -30,6 +30,9 @@ public enum CellState : ushort // The server's value, with no text: the grid draws its DefaultText. Default = 256, + + // A value the driver could not read: the text says so, from its type's name, and a copy leaves it out. + Unreadable = 512, } public readonly ref struct CellText(ReadOnlySpan text, CellState state) @@ -95,6 +98,19 @@ public void Reset(int firstRow, int rowCount, int firstColumn, int columnCount, public void AddDefault(CellState marks = CellState.None) => Close(CellState.Default | marks); + // Worded as the Linux grid words it. + public void AddUnreadable(ReadOnlySpan typeName) + { + const string Start = " Reserve(characters - _length, exact: true); diff --git a/windows/src/TablePro.DataGrid.Model/GridCopy.cs b/windows/src/TablePro.DataGrid.Model/GridCopy.cs index 351a849fdb..ce75681f52 100644 --- a/windows/src/TablePro.DataGrid.Model/GridCopy.cs +++ b/windows/src/TablePro.DataGrid.Model/GridCopy.cs @@ -43,7 +43,7 @@ public static void Write(IGridReader reader, CellRange range, StringBuilder outp output.Append('\t'); } var cell = block.Get(row, column); - if (cell.IsNull || (cell.State & CellState.Missing) != 0) + if (cell.IsNull || (cell.State & (CellState.Missing | CellState.Unreadable)) != 0) { continue; } diff --git a/windows/src/TablePro.DataGrid.Model/ResultSetData.cs b/windows/src/TablePro.DataGrid.Model/ResultSetData.cs index 95ff2f26e9..9af1ae1e69 100644 --- a/windows/src/TablePro.DataGrid.Model/ResultSetData.cs +++ b/windows/src/TablePro.DataGrid.Model/ResultSetData.cs @@ -52,6 +52,10 @@ public void Read(int firstRow, int rowCount, int firstColumn, int columnCount, i { block.AddNull(); } + else if (window.GetKind(row, column) == ValueKind.Undecodable) + { + block.AddUnreadable(window.GetUtf8(row, column)); + } else { var text = window.GetUtf8(row, column); diff --git a/windows/src/TablePro.DataGrid/CellPainter.cs b/windows/src/TablePro.DataGrid/CellPainter.cs index 6b58c77513..ee6d93beaf 100644 --- a/windows/src/TablePro.DataGrid/CellPainter.cs +++ b/windows/src/TablePro.DataGrid/CellPainter.cs @@ -222,6 +222,12 @@ public void EnsureBrushes() layout = Create(_nullText, _null, width, height); length = _nullText.Length; } + else if ((state & CellState.Unreadable) != 0) + { + ink = deleted ? CellInk.Deleted : CellInk.Placeholder; + layout = Create(text, _null, width, height); + length = text.Length; + } else if ((state & CellState.Default) != 0) { if (_defaultText.Length == 0) diff --git a/windows/src/TablePro.DataGrid/DataGridView.Interaction.cs b/windows/src/TablePro.DataGrid/DataGridView.Interaction.cs index 5ad1a46232..8ccc8a2162 100644 --- a/windows/src/TablePro.DataGrid/DataGridView.Interaction.cs +++ b/windows/src/TablePro.DataGrid/DataGridView.Interaction.cs @@ -259,7 +259,8 @@ private double ContentWidth(int column, int firstRow, int lastRow, int maxCharac var cell = Cell(row, column); widest = Math.Max(widest, cell.IsNull ? painter.Measure(_nullText, placeholder: true) - : cell.IsDefault ? painter.MeasureDefault() : painter.Measure(Head(cell.Text, maxCharacters))); + : cell.IsDefault ? painter.MeasureDefault() + : painter.Measure(Head(cell.Text, maxCharacters), placeholder: (cell.State & CellState.Unreadable) != 0)); } return Math.Ceiling(widest + (CellPainter.Padding * 2) + 2); } diff --git a/windows/tests/TablePro.DataGrid.Model.Tests/CoreDataTests.cs b/windows/tests/TablePro.DataGrid.Model.Tests/CoreDataTests.cs index a6d2ed3930..d2ba2179fd 100644 --- a/windows/tests/TablePro.DataGrid.Model.Tests/CoreDataTests.cs +++ b/windows/tests/TablePro.DataGrid.Model.Tests/CoreDataTests.cs @@ -55,6 +55,23 @@ public async Task ACopyHasTheWholeValuesBack() Assert.Equal("", lines[5]); } + // DuckDB hands an editor run a TIMETZ as the time alone, which the driver cannot read back. + [Fact] + public async Task AValueTheDriverCouldNotReadSaysSoAndCopiesAsNothing() + { + await using var database = await CoreDatabase.CreateAsync("grid.duckdb"); + using var data = await database.QueryAsync("SELECT 1 AS id, TIMETZ '12:30:00+05:30' AS at"); + using var cache = new CellCache(data.Data.OpenReader()); + using var reader = data.Data.OpenReader(); + + var cell = cache.Get(0, 1, 64); + var tsv = GridCopy.Tsv(reader, new CellRange(0, 0, 0, 1), TestContext.Current.CancellationToken); + + Assert.Equal("", cell.Text.ToString()); + Assert.Equal(CellState.Unreadable, cell.State); + Assert.Equal("1\t\r\n", tsv); + } + // The grid's fetch path over the real core allocates nothing once its blocks are loaded. [Fact] public async Task ScrollingAMillionRowsAllocatesNothingOnceTheCacheIsFull() @@ -104,11 +121,11 @@ private CoreDatabase(string directory, TableProCore core, DatabaseSession sessio _editor = editor; } - public static async Task CreateAsync() + public static async Task CreateAsync(string file = "grid.sqlite") { var directory = Directory.CreateTempSubdirectory("tablepro-grid-").FullName; var core = TableProCore.Create(new HostConfiguration("test"), new NoSecrets()); - var session = await core.OpenFileAsync(new FileOpenOptions(Path.Combine(directory, "grid.sqlite"), Create: true)); + var session = await core.OpenFileAsync(new FileOpenOptions(Path.Combine(directory, file), Create: true)); var editor = await session.OpenEditorAsync(); return new CoreDatabase(directory, core, session, editor); } @@ -126,7 +143,14 @@ public async ValueTask DisposeAsync() await _editor.DisposeAsync(); await _session.DisposeAsync(); _core.Dispose(); - Directory.Delete(_directory, recursive: true); + try + { + Directory.Delete(_directory, recursive: true); + } + catch (IOException) + { + // A DuckDB file closes on the core's own threads, which can still hold it here on Windows. + } } private sealed class NoSecrets : ISecretStore diff --git a/windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs b/windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs index e7a9df3c94..e16d96df2e 100644 --- a/windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs +++ b/windows/tests/TablePro.Interop.Tests/Live/LiveServer.cs @@ -28,5 +28,6 @@ public static LiveServer Require(string engine) return server!; } - public ConnectionSecrets Secrets => new(DatabasePassword: Password); + // An empty password for a server that takes none, as the connection form saves one. + public ConnectionSecrets Secrets => new(DatabasePassword: Password ?? string.Empty); } diff --git a/windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs b/windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs index c2a005443b..f520505d32 100644 --- a/windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs +++ b/windows/tests/TablePro.Interop.Tests/Live/SqlEngineTests.cs @@ -1,6 +1,7 @@ using System.Globalization; using System.Text.Encodings.Web; using System.Text.Json; +using TablePro.DataGrid.Model; namespace TablePro.Interop.Tests.Live; @@ -23,6 +24,8 @@ private static readonly (int Id, string Name, string? Note)[] People = protected string Unique { get; } = Guid.NewGuid().ToString("N")[..8]; + protected TableProCore Core => _core ??= TableProCore.Create(new HostConfiguration("live-test", _directory), new MemorySecretStore()); + protected abstract string CorpusFile { get; } protected virtual string? CorpusFlavour => null; @@ -167,8 +170,7 @@ protected static async Task ExecuteAsync(QueryEditor editor, string sql, Cancell private async Task<(DatabaseSession Session, QueryEditor Editor)> StartAsync(CancellationToken cancellationToken) { - _core = TableProCore.Create(new HostConfiguration("live-test", _directory), new MemorySecretStore()); - var session = await OpenAsync(_core, _directory, cancellationToken); + var session = await OpenAsync(Core, _directory, cancellationToken); _open.Add(session); var editor = await session.OpenEditorAsync(cancellationToken); _open.Add(editor); @@ -254,7 +256,17 @@ private static Dictionary RowsById(ResultSet set) private static Dictionary TextsById(ResultSet set, string column) { var index = ColumnIndex(set, column); - return RowsById(set).ToDictionary(pair => pair.Key, pair => set.GetCellText(pair.Value, index)); + using var reader = new ResultSetData(set, set.GetColumns()).OpenReader(); + var block = new CellBlock(); + reader.Read(0, (int)set.RowCount, index, 1, 256, block); + return RowsById(set).ToDictionary(pair => pair.Key, pair => Shown(set, block, (int)pair.Value, index)); + } + + // The whole value, or what the grid says in place of one the driver could not read. + private static string? Shown(ResultSet set, CellBlock block, int row, int column) + { + var cell = block.Get(row, column); + return (cell.State & CellState.Unreadable) != 0 ? cell.Text.ToString() : set.GetCellText(row, column); } private static int ColumnIndex(ResultSet set, string name) diff --git a/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs b/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs index 339e69d04d..e803cc0da3 100644 --- a/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs +++ b/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs @@ -11,9 +11,8 @@ public async Task AWindowsLoginSignsInAsTheAccountRunningTheTests() { var cancellationToken = TestContext.Current.CancellationToken; var server = LiveServer.Require("MSSQL"); - using var core = TableProCore.Create(new HostConfiguration("live-test"), new MemorySecretStore()); await using var session = await ConnectAsync( - core, + Core, Connection(server) with { UserName = string.Empty, IntegratedAuth = true }, ConnectionSecrets.None, cancellationToken); diff --git a/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj b/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj index 673081d8c6..b42468bd8f 100644 --- a/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj +++ b/windows/tests/TablePro.Interop.Tests/TablePro.Interop.Tests.csproj @@ -20,6 +20,7 @@ + From e34f77c69560b4bee752e454896b5b119d2e8cd6 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 13:13:24 +0700 Subject: [PATCH 4/8] docs(windows): record how the live servers run --- .../docs/decisions/0003-data-grid-control.md | 4 +- .../docs/decisions/0013-live-server-tests.md | 56 +++++++++++++++++++ windows/docs/decisions/README.md | 1 + 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 windows/docs/decisions/0013-live-server-tests.md diff --git a/windows/docs/decisions/0003-data-grid-control.md b/windows/docs/decisions/0003-data-grid-control.md index a5c9653ffd..c1de2c663a 100644 --- a/windows/docs/decisions/0003-data-grid-control.md +++ b/windows/docs/decisions/0003-data-grid-control.md @@ -27,7 +27,7 @@ - `GridColumns` keeps widths and positions for two panes: the row numbers with the frozen columns, and the scrolling columns from x = 0. - `GridSelection` is an anchor and a focused cell, as cells, whole rows or everything, so a selection of any size is two numbers. - `GridNavigation` moves as Excel does in a block with no empty cells: arrows, Page Up and Down, Home and End, Ctrl to the edges, Shift to extend. -- `GridCopy` writes Excel's TSV: tabs, CRLF, values with a tab, line break or quote quoted with quotes doubled, NULL as an empty cell. It streams blocks of 16,384 cells from a reader of its own, at a 4,096-character cap, and reads a cut value whole. The core shows control characters as spaces, so a text value with a space is read whole too. +- `GridCopy` writes Excel's TSV: tabs, CRLF, values with a tab, line break or quote quoted with quotes doubled, NULL and a value the driver could not read as an empty cell. It streams blocks of 16,384 cells from a reader of its own, at a 4,096-character cap, and reads a cut value whole. The core shows control characters as spaces, so a text value with a space is read whole too. - `EditedGridData` lays the host's `GridEdits` over the data: the data's rows, then the new rows. `GridEdits` is immutable, and a reader keeps the edits it opened with. A copy takes the edits on the UI thread with its range and opens its reader over them on the pool thread. - Its reader reads the data's rows into a block of its own, then copies each cell on, a pending one in its place. Pending text is cut and its control characters shown as spaces, as the core shows a value. New rows are never asked of the data. - A cell's state carries Modified, Inserted, Deleted or Default. A deleted row keeps the data's text. `ReadWhole` gives the pending text, null for NULL and empty for DEFAULT, so a copy takes what the user typed. @@ -50,7 +50,7 @@ - Each row is one element with a `SpriteVisual` painted from a `CompositionDrawingSurface` the width of the pane's visible columns. `TablePro.Graphics.SurfaceDevice` makes the composition graphics device from a Direct2D device through Windows App SDK's `ICompositorInterop`, whose IIDs and layout differ from the system's; a draw gets the surface's own device context through `ICompositionDrawingSurfaceInterop::BeginDraw`. - A row keeps an `IDWriteTextLayout` per visible cell while it stays on screen, and lays out only the columns that come into view. Layouts are made from the block's spans: no string, wrapper or closure per cell. - The font is what a TextBlock cell would use: Segoe UI Variable Text at the content size (Segoe UI before Windows 11), one line, cut with an ellipsis, centered, grayscale antialiased on a clear surface, unless the host names another (`CellFontFamily`, a family not installed keeping the default) or size (`CellFontSize`, 8 to 36); rows and the header grow with the size as they do with text scale, and the app sets both from Settings, Data grid. The locale is the UI language's, so Han glyphs follow it. -- NULL is the host's `NullText`, the word NULL unless Settings, Data grid, NULL display names another, in italic in the tertiary text color; its accessible name follows it, and a copy still writes NULL as an empty cell. A value the core cut ends with an ellipsis in the tertiary color. +- NULL is the host's `NullText`, the word NULL unless Settings, Data grid, NULL display names another, in italic in the tertiary text color; its accessible name follows it, and a copy still writes NULL as an empty cell. A value the driver could not read shows as `` in the same style, as the Linux grid words it from the type the core names in the cell (`CellState.Unreadable`). A value the core cut ends with an ellipsis in the tertiary color. - Pending changes, as on macOS. A changed cell has underlined text on `SystemFillColorCautionBackground`, and a new row underlined text on `SystemFillColorSuccessBackground`. A row marked for delete, its number too, has struck-through text in `SystemFillColorCritical` on `SystemFillColorCriticalBackground`. DEFAULT is `DefaultText` in semibold `AccentTextFillColorPrimary`. - Underline and strike-through are the layout's own, over the whole text. A wash covers the selection rectangle beneath the row, so a row with one draws the selection's tint over it and redraws when the selection moves. - High contrast draws no washes; underline and strike-through stay. diff --git a/windows/docs/decisions/0013-live-server-tests.md b/windows/docs/decisions/0013-live-server-tests.md new file mode 100644 index 0000000000..18eaecd1a1 --- /dev/null +++ b/windows/docs/decisions/0013-live-server-tests.md @@ -0,0 +1,56 @@ +# 0013: Live-server tests on the Windows runner + +- **Status**: Accepted +- **Date**: 2026-11-18 + +## Context + +The interop tests reached a server only for PostgreSQL (`NoticeTests` and the SSH tests over `ci/ssh-postgres.ps1`). MySQL, SQL Server, ClickHouse, Cassandra, MongoDB and Redis ran on Windows only through the core's unit tests, and DuckDB through SQLite-shaped file tests, so nothing showed that the FFI connects to them, pages a table, shows their values as the Linux grid does and saves a row on Windows. The core's value corpus, the values each engine's suite reads back with the text the grid shows, was Rust code inside each driver's integration target, which the .NET tests could not read. Hosted Windows runners run no Linux containers, so the core's Docker fixtures do not start there. + +## Decision + +### Tests + +- `tests/TablePro.Interop.Tests/Live` holds one class per engine, through the public interop API only. A SQL engine's class (`SqlEngineTests`) lists a new table in the catalog, pages it, counts it and reads its structure; writes each corpus column into a table of its own and reads every value back through `ReadTablePageAsync`, as a table tab does, and a plain `SELECT` in a `QueryEditor`, as a query tab does, comparing `GetCellText` with the text the corpus names, every wrong value in one failure; and saves an update, an insert and a delete through `TableEditor` and reads the rows back. +- MongoDB's class does the same with a collection and the document of every BSON type the driver's own tests read. Redis's lists a key of each type, reads each through `KeyReader`, and writes and deletes keys from the editor, with a key's expiry. +- The corpus is one home for both sides: `core/crates/test-support/corpus/.json`, which the Rust conformance cases read through `ValueCorpus` and the test project copies beside its assembly. A column marked `only` belongs to one flavour of a file two engines share (MySQL and MariaDB). +- A class whose server is not there skips. `ci/live-servers.ps1` names each server in `TABLEPRO_TEST_LIVE__PORT`, `_USER` and `_PASSWORD`. + +### Servers + +Each one is set up the way that measured fastest and held on `windows-2025`: + +| Engine | How it runs | Setup | +| --- | --- | --- | +| MySQL 8.4 | The image's install, a new data folder (`--initialize-insecure`), a password user | 10 s | +| SQL Server 2022 Express CU1 | `core/crates/drivers/mssql/tests/windows/sql-server.ps1 -Install -SaPassword`, its certificate verified with the CA file the script writes | 4 min 39 s | +| MongoDB 7.0 | The image's service, started | 9 s | +| Redis 8.10.3 | The redis-windows msys2 build, pinned by SHA-256 | 2 s | +| Cassandra 4.0.21 | The Apache tarball on the image's Java 11, its java command written out with `disk_access_mode: standard` | 50 s | +| ClickHouse 26.8 LTS | Its Linux binary in a WSL 1 distribution imported from the Ubuntu base tarball | 14 s | +| DuckDB | In process: no server, so it runs in every Windows job and on macOS | none | + +- The `live` job in `windows.yml` runs them on `windows-2025` beside the x64 test job, one step per server, then `dotnet test --filter-namespace TablePro.Interop.Tests.Live --fail-skips on`, so a server that did not start fails its tests rather than skipping them. It reads the x64 job's Cargo cache and saves none. `ci.yml` calls `windows.yml` only when the `windows` suite changed. +- Arm64 runs DuckDB only. Its image has no PostgreSQL, MongoDB or SQL Server, SQL Server installs on x64 alone, and every driver is the same Rust code on both. + +## What the runner showed + +Probes on `windows-2025` (runs 44241847132, 44242839754 and 44243471366): + +- Cassandra 5.0.9 stops at its startup check on Windows ("The native library could not be initialized properly"): it links the C library as on Linux, and 4.1's source has no Windows native library either. 4.0.21, which still has one, starts in about 40 s. +- WSL 1 runs a Linux binary on the runner and its listener answers on 127.0.0.1. ClickHouse's `clickhouse-common-static` binary needs glibc's loader, so it runs in the Ubuntu base distribution (a 4 s import) and not in Alpine's minirootfs; the full Ubuntu WSL image took 71 s to fetch and import. +- SQL Server 2022 Express RTM installed in 2 min 36 s with SQL logins; with CU1, as the core's script installs it, 4 min 39 s. +- MySQL's `--initialize-insecure` took 5 s and its start 2 s. The Redis build started in under a second. +- The first live run (44244847194) found the grid showing an unreadable value as an empty cell, where the Linux grid shows ``: the FFI kept no text for it. The core now keeps the type's name for the grid's window ([0003](0003-data-grid-control.md)). + +## Rationale + +- One corpus file read by both sides: a copy in C# would drift from the one the Linux suites fix decoders against. +- Native servers where they exist, WSL 1 only for ClickHouse: no VM, no image pull, and the runner reaches a WSL 1 listener on 127.0.0.1. +- A separate job keeps the x64 job's time and its UI tests as they were, and costs one runner when Windows changed: about 7 minutes of servers, then the build, which the x64 job's cache shortens. + +## Consequences + +- Cassandra on Windows is 4.0, the older of the two releases the core's fixtures run; 5.0 stays covered on Linux. +- The Linux suites' guide (`linux/docs/testing.md`, Value corpus) still names the corpus as Rust builders; it moves to the JSON files after Linux 0.1.0. +- A new engine with a corpus adds its file to `corpus/`, a `ValueCorpus` variant, a class here and a step in `live-servers.ps1`. diff --git a/windows/docs/decisions/README.md b/windows/docs/decisions/README.md index 888b5594c7..0c959bb7c0 100644 --- a/windows/docs/decisions/README.md +++ b/windows/docs/decisions/README.md @@ -20,3 +20,4 @@ The format, the statuses and how a later ADR changes an earlier one follow [the | [0010](0010-data-masking.md) | Masking a shared result | Accepted | The share sheet's Keep, Mask or Remove per column, detected columns masked by default, the core's preview and summary of what a link sends, and the Hide SQL suggestion; nothing else masks (core 0028). | | [0011](0011-saved-queries-csv-import-and-connection-copies.md) | Saved queries, history pins, CSV import and connection copies | Accepted | Query > Save query... and a Saved queries pane with folders where the history pane sits, Insert in editor as macOS; Pin on a history run; Import CSV... on a table with a field per column under the save's Safe Mode gate; Duplicate a connection with its passwords and Export the connections file without them. | | [0012](0012-catalog-operations-table-filters-and-export-progress.md) | Catalog operations, filters kept per table, filter by a cell and export progress | Accepted | Truncate and Drop in the tree, New and Drop schema and database, each showing the core's statements under Safe Mode; a table's last filter comes back when it opens again; a cell's Filter menu; SQL INSERT of a query result and a running row count while an export writes. | +| [0013](0013-live-server-tests.md) | Live-server tests on the Windows runner | Accepted | `tests/TablePro.Interop.Tests/Live` pages, reads the core's value corpus from `core/crates/test-support/corpus` and saves on MySQL, SQL Server, DuckDB, ClickHouse, Cassandra, MongoDB and Redis; `windows.yml`'s live job starts each server natively on `windows-2025`, ClickHouse in WSL 1, Cassandra 4.0 since later releases refuse Windows; DuckDB runs in every job. | From f7baf1a9d63b8c9fced5427b1b4b3fbfeb46efe0 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 13:20:39 +0700 Subject: [PATCH 5/8] test(windows): read the typed collection's name from the catalog --- windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs b/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs index 83ccc145d0..2a3f97cfa7 100644 --- a/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs +++ b/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs @@ -61,8 +61,9 @@ public async Task EveryBsonTypeReadsBackAsTheGridShowsIt() await using var editor = await session.OpenEditorAsync(cancellationToken); var name = $"types_{_unique}"; await ExecuteAsync(editor, $"db.getCollection('{name}').insertOne({EveryType})", cancellationToken); + var collection = await ListedAsync(session, name, cancellationToken); - using var browsed = await PageAsync(session, new TableName(Database, name), cancellationToken); + using var browsed = await PageAsync(session, collection, cancellationToken); using var found = await RowsAsync(editor.Run($"db.getCollection('{name}').find()", cancellationToken: cancellationToken)); var wrong = Wrong("browse", browsed.Set).Concat(Wrong("editor", found.Set)).ToList(); @@ -128,6 +129,11 @@ await ExecuteAsync( $"db.getCollection('{name}').insertMany([{{_id: 1, name: 'Ada', note: null}}, " + "{_id: 2, name: 'Grace', note: 'note'}, {_id: 3, name: 'Zoë 👋', note: '中文'}])", cancellationToken); + return await ListedAsync(session, name, cancellationToken); + } + + private static async Task ListedAsync(DatabaseSession session, string name, CancellationToken cancellationToken) + { var objects = await session.RefreshObjectsAsync(ObjectScope.DefaultSchema, cancellationToken); var entry = Assert.Single(objects, item => item.Name == name); Assert.Equal(ObjectKind.Table, entry.Kind); From e307e8e1b14c76513ee28bb186c1cf883a626a56 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 14:05:03 +0700 Subject: [PATCH 6/8] test(windows): keep Cassandra running past its step, list Redis keys from the editor --- .github/workflows/windows.yml | 2 +- windows/ci/live-servers.ps1 | 11 +++++------ .../TablePro.Interop.Tests/Live/MongoDbTests.cs | 12 ++++++++++-- .../tests/TablePro.Interop.Tests/Live/RedisTests.cs | 13 ++++++++----- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 1ca8a57a47..9ee4013683 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -249,6 +249,6 @@ jobs: if: failure() run: | Get-Content (Join-Path $env:RUNNER_TEMP 'mysqld.log') -Tail 60 -ErrorAction Continue - Get-Content (Join-Path $env:RUNNER_TEMP 'cassandra.log') -Tail 80 -ErrorAction Continue + Get-Content (Join-Path $env:RUNNER_TEMP 'cassandra-logs\system.log') -Tail 80 -ErrorAction Continue wsl --distribution tablepro --user root -- tail -n 80 /var/lib/clickhouse/server.log Get-Content "$env:ProgramFiles\MongoDB\Server\7.0\log\mongod.log" -Tail 40 -ErrorAction Continue diff --git a/windows/ci/live-servers.ps1 b/windows/ci/live-servers.ps1 index 4d93ab949c..0ec416efb0 100644 --- a/windows/ci/live-servers.ps1 +++ b/windows/ci/live-servers.ps1 @@ -108,19 +108,18 @@ switch ($Server) { ForEach-Object { $_.Trim() } | Where-Object { $_ -match '^-' -and $_ -ne '-XX:+UseNUMA' } | ForEach-Object { $_ -replace '^(--add-(exports|opens)) ', '$1=' } + $logs = Join-Path $env:RUNNER_TEMP 'cassandra-logs' $arguments = @($options) + @( '-Xms1g', '-Xmx1g', '-Dlogback.configurationFile=logback.xml', - "-Dcassandra.logdir=$root\logs", + "-Dcassandra.logdir=$logs", "-Dcassandra.storagedir=$root\data", - '-Dcassandra-foreground=yes', '-cp', "`"$conf;$root\lib\*`"", 'org.apache.cassandra.service.CassandraDaemon' ) - $out = Join-Path $env:RUNNER_TEMP 'cassandra.log' - Start-Process (Join-Path $env:JAVA_HOME_11_X64 'bin\java.exe') -ArgumentList $arguments -WorkingDirectory $root ` - -RedirectStandardOutput $out -RedirectStandardError (Join-Path $env:RUNNER_TEMP 'cassandra.err') -WindowStyle Hidden - Wait-Listening 9042 5 { Get-Content $out -Tail 80 } + # Redirected output would tie java to this step's console, whose close at the step's end stops it. + Start-Process (Join-Path $env:JAVA_HOME_11_X64 'bin\java.exe') -ArgumentList $arguments -WorkingDirectory $root -WindowStyle Hidden + Wait-Listening 9042 5 { Get-Content (Join-Path $logs 'system.log') -Tail 80 } Set-Live CASSANDRA 9042 } # ClickHouse has no Windows build. WSL 1 runs its Linux binary on the runner, which cannot nest a WSL 2 VM. diff --git a/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs b/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs index 2a3f97cfa7..0679f414b2 100644 --- a/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs +++ b/windows/tests/TablePro.Interop.Tests/Live/MongoDbTests.cs @@ -11,11 +11,18 @@ public sealed class MongoDbTests : IDisposable + "uid: UUID('0e3f6f0e-8a3b-4b8e-9a7c-2f1d1b3c4d5e'), blob: BinData(0, 'AAEC'), " + "stamp: Timestamp({t: 1700000000, i: 3})}"; + // A table tab edits a binary field and a field that holds only null as extended JSON, so it shows them as such. + private static readonly Dictionary BrowseShows = new() + { + ["nothing"] = "null", + ["blob"] = """{"$binary": {"base64": "AAEC", "subType": "00"}}""", + }; + private static readonly Dictionary EveryTypeShows = new() { ["_id"] = "1", ["oid"] = "5f1d7a0c9b1e8b2a3c4d5e6f", - ["at"] = "2024-05-06 07:08:09.01+00:00", + ["at"] = "2024-05-06 07:08:09.010+00:00", ["price"] = "12.50", ["big"] = "9007199254740993", ["ratio"] = "0.5", @@ -168,8 +175,9 @@ private static async Task RowsAsync(QueryRun run) private static IEnumerable Wrong(string path, ResultSet set) { var columns = set.GetColumns().Select(column => column.Name).ToList(); - foreach (var (field, expected) in EveryTypeShows) + foreach (var (field, shows) in EveryTypeShows) { + var expected = path == "browse" && BrowseShows.TryGetValue(field, out var browsed) ? browsed : shows; var index = columns.IndexOf(field); var shown = index < 0 ? "" : set.GetCellText(0, index); if (shown != expected) diff --git a/windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs b/windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs index d3ac5792b6..1d19c335ff 100644 --- a/windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs +++ b/windows/tests/TablePro.Interop.Tests/Live/RedisTests.cs @@ -31,13 +31,16 @@ public async Task EveryKeyTypeIsListedAndReadsBackAsTheGridShowsIt() await ExecuteAsync(editor, command, cancellationToken); } - var keys = await session.RefreshObjectsAsync(ObjectScope.DefaultSchema, cancellationToken); - var ours = keys.Where(key => key.Name.StartsWith(_prefix, StringComparison.Ordinal)).ToList(); + // The core lists no keys through the FFI yet (the Linux sidebar's listing), so the editor lists them. + using var listed = editor.Run($"KEYS {_prefix}*", cancellationToken: cancellationToken); + Assert.IsType(await listed.Completion); + using var keys = listed.GetResultSet(0); + Assert.NotNull(keys); + var value = keys.GetColumns().ToList().FindIndex(column => column.Name == "value"); - Assert.All(ours, key => Assert.Equal(ObjectKind.Key, key.Kind)); Assert.Equal( ["bytes", "hash", "list", "set", "stream", "text", "zset"], - ours.Select(key => key.Name[_prefix.Length..]).Order(StringComparer.Ordinal)); + Enumerable.Range(0, (int)keys.RowCount).Select(row => keys.GetCellText(row, value)![_prefix.Length..]).Order(StringComparer.Ordinal)); Assert.Equal((KeyKind.Text, Rows(["naïve café 🦀"])), await ReadAsync(session, "text", cancellationToken)); Assert.Equal((KeyKind.Text, Rows(["0xff00fe"])), await ReadAsync(session, "bytes", cancellationToken)); Assert.Equal((KeyKind.Hash, Rows(["f1", "v1"], ["f2", "two words"])), await ReadAsync(session, "hash", cancellationToken, sorted: true)); @@ -112,7 +115,7 @@ private static async Task ExecuteAsync(QueryEditor editor, string command, Cance var rows = Enumerable.Range(0, (int)set.RowCount) .Select(row => string.Join(" | ", Enumerable.Range(0, columns).Select(column => set.GetCellText(row, column) ?? "NULL"))) .ToList(); - return (window.Kind, string.Join('\n', sorted ? rows.Order(StringComparer.Ordinal) : rows)); + return (window.Kind, string.Join('\n', sorted ? [.. rows.Order(StringComparer.Ordinal)] : rows)); } private static string Rows(params string[][] rows) => string.Join('\n', rows.Select(row => string.Join(" | ", row))); From 67e995751550625d4193cc1ee726c928f6823825 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 14:14:59 +0700 Subject: [PATCH 7/8] test(windows): sign in with a Windows login to master, which every server has --- windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs b/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs index e803cc0da3..c62f266aa9 100644 --- a/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs +++ b/windows/tests/TablePro.Interop.Tests/Live/SqlServerTests.cs @@ -13,7 +13,7 @@ public async Task AWindowsLoginSignsInAsTheAccountRunningTheTests() var server = LiveServer.Require("MSSQL"); await using var session = await ConnectAsync( Core, - Connection(server) with { UserName = string.Empty, IntegratedAuth = true }, + Connection(server) with { Database = "master", UserName = string.Empty, IntegratedAuth = true }, ConnectionSecrets.None, cancellationToken); await using var editor = await session.OpenEditorAsync(cancellationToken); From 55ccc35aa305441a913e84575e23c1a4cf02c7ca Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Wed, 18 Nov 2026 14:20:11 +0700 Subject: [PATCH 8/8] docs(windows): record the green live run and what it showed --- windows/docs/decisions/0013-live-server-tests.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/windows/docs/decisions/0013-live-server-tests.md b/windows/docs/decisions/0013-live-server-tests.md index 18eaecd1a1..79f46a661a 100644 --- a/windows/docs/decisions/0013-live-server-tests.md +++ b/windows/docs/decisions/0013-live-server-tests.md @@ -12,7 +12,7 @@ The interop tests reached a server only for PostgreSQL (`NoticeTests` and the SS ### Tests - `tests/TablePro.Interop.Tests/Live` holds one class per engine, through the public interop API only. A SQL engine's class (`SqlEngineTests`) lists a new table in the catalog, pages it, counts it and reads its structure; writes each corpus column into a table of its own and reads every value back through `ReadTablePageAsync`, as a table tab does, and a plain `SELECT` in a `QueryEditor`, as a query tab does, comparing `GetCellText` with the text the corpus names, every wrong value in one failure; and saves an update, an insert and a delete through `TableEditor` and reads the rows back. -- MongoDB's class does the same with a collection and the document of every BSON type the driver's own tests read. Redis's lists a key of each type, reads each through `KeyReader`, and writes and deletes keys from the editor, with a key's expiry. +- MongoDB's class does the same with a collection and the document of every BSON type the driver's own tests read, where a table tab shows a binary field and a field of nulls as the extended JSON it edits them as. Redis's writes a key of each type from the editor, lists them there, reads each through `KeyReader` as a key tab does, and changes and deletes keys, with a key's expiry. - The corpus is one home for both sides: `core/crates/test-support/corpus/.json`, which the Rust conformance cases read through `ValueCorpus` and the test project copies beside its assembly. A column marked `only` belongs to one flavour of a file two engines share (MySQL and MariaDB). - A class whose server is not there skips. `ci/live-servers.ps1` names each server in `TABLEPRO_TEST_LIVE__PORT`, `_USER` and `_PASSWORD`. @@ -26,7 +26,7 @@ Each one is set up the way that measured fastest and held on `windows-2025`: | SQL Server 2022 Express CU1 | `core/crates/drivers/mssql/tests/windows/sql-server.ps1 -Install -SaPassword`, its certificate verified with the CA file the script writes | 4 min 39 s | | MongoDB 7.0 | The image's service, started | 9 s | | Redis 8.10.3 | The redis-windows msys2 build, pinned by SHA-256 | 2 s | -| Cassandra 4.0.21 | The Apache tarball on the image's Java 11, its java command written out with `disk_access_mode: standard` | 50 s | +| Cassandra 4.0.21 | The Apache tarball on the image's Java 11, its java command written out with `disk_access_mode: standard` | 46 s | | ClickHouse 26.8 LTS | Its Linux binary in a WSL 1 distribution imported from the Ubuntu base tarball | 14 s | | DuckDB | In process: no server, so it runs in every Windows job and on macOS | none | @@ -42,6 +42,9 @@ Probes on `windows-2025` (runs 44241847132, 44242839754 and 44243471366): - SQL Server 2022 Express RTM installed in 2 min 36 s with SQL logins; with CU1, as the core's script installs it, 4 min 39 s. - MySQL's `--initialize-insecure` took 5 s and its start 2 s. The Redis build started in under a second. - The first live run (44244847194) found the grid showing an unreadable value as an empty cell, where the Linux grid shows ``: the FFI kept no text for it. The core now keeps the type's name for the grid's window ([0003](0003-data-grid-control.md)). +- Java started with its output redirected shares the step's console and stopped when the step ended, so Cassandra refused the tests' connections (run 44249651260); started on a console of its own it runs to the end of the job. +- The core lists no Redis keys through the FFI (the Linux sidebar's listing lives in the Linux app), so the Redis test lists them with `KEYS` in the editor. +- Run 44256128478 passed all 21 live tests in 48 s, after 7 min of server setup. ## Rationale