|
5 | 5 | //! tests pin what the separate names do and do not enforce when both are |
6 | 6 | //! installed: |
7 | 7 | //! |
8 | | -//! - both install without clashing, and each owns its own domains; |
| 8 | +//! - both install without clashing, each owns its own domains, and each |
| 9 | +//! version's `lints()` stays clean with the other installed; |
9 | 10 | //! - a payload of the wrong version fails the domain CHECK on insert; |
10 | 11 | //! - the function form across versions (`eql_v3.eq(v3col, v4term)`) is |
11 | | -//! ambiguous, so it errors; |
| 12 | +//! ambiguous, so it errors, and so is `OPERATOR(public.=)` between a v3 and |
| 13 | +//! a v4 column; |
12 | 14 | //! - the operator form across versions (`v3col = v4term`) does NOT error. |
13 | 15 | //! With no operator defined for the exact pair, Postgres treats both domains |
14 | 16 | //! as `jsonb` and uses the built-in `jsonb = jsonb`, which returns no rows. |
15 | 17 | //! That is pinned here so it cannot change unnoticed. ADR-0002 defers the |
16 | 18 | //! cross-version blocker operators that would make it an error; when they |
17 | 19 | //! land, those assertions flip to expecting one. |
| 20 | +//! - `eql_v3.eq_term(v3col) = eql_v4.eq_term(v4col)` does not error either: it |
| 21 | +//! compares two text terms. |
18 | 22 | //! |
19 | 23 | //! The payloads are real cipherstash-client ciphertexts from the |
20 | 24 | //! `eql_v3_integer` fixture. A v4 payload is the same row with its envelope |
@@ -103,6 +107,22 @@ async fn v3_and_v4_install_side_by_side(pool: PgPool) -> Result<()> { |
103 | 107 | .fetch_one(&pool) |
104 | 108 | .await?; |
105 | 109 | assert_eq!(a, b, "both bundles come from one build"); |
| 110 | + |
| 111 | + // Each lint judges only its own version's public domains. Before that was |
| 112 | + // scoped, each version reported thousands of errors about the other's |
| 113 | + // blocker operators. |
| 114 | + for schema in ["eql_v3", "eql_v4"] { |
| 115 | + let errors: Vec<String> = sqlx::query_scalar(&format!( |
| 116 | + "SELECT category || ': ' || object_name FROM {schema}.lints() \ |
| 117 | + WHERE severity = 'error' ORDER BY 1 LIMIT 5" |
| 118 | + )) |
| 119 | + .fetch_all(&pool) |
| 120 | + .await?; |
| 121 | + assert!( |
| 122 | + errors.is_empty(), |
| 123 | + "{schema}.lints() reports errors with both versions installed: {errors:#?}" |
| 124 | + ); |
| 125 | + } |
106 | 126 | Ok(()) |
107 | 127 | } |
108 | 128 |
|
@@ -206,3 +226,41 @@ async fn operator_across_versions_returns_no_rows(pool: PgPool) -> Result<()> { |
206 | 226 | assert_eq!(joined, 0, "a v3 column joined to a v4 column finds nothing"); |
207 | 227 | Ok(()) |
208 | 228 | } |
| 229 | + |
| 230 | +#[sqlx::test(fixtures(path = "../fixtures", scripts("eql_v3_integer")))] |
| 231 | +async fn qualified_operator_across_versions_is_ambiguous(pool: PgPool) -> Result<()> { |
| 232 | + install_v4(&pool).await?; |
| 233 | + tables_with_one_row(&pool).await?; |
| 234 | + |
| 235 | + let err = sqlx::query("SELECT count(*) FROM t3 JOIN t4 ON t3.c OPERATOR(public.=) t4.c") |
| 236 | + .execute(&pool) |
| 237 | + .await |
| 238 | + .expect_err("OPERATOR(public.=) between a v3 and a v4 column must not resolve"); |
| 239 | + assert_eq!( |
| 240 | + sqlstate(&err).as_deref(), |
| 241 | + Some(AMBIGUOUS_FUNCTION), |
| 242 | + "t3.c OPERATOR(public.=) t4.c: {err}" |
| 243 | + ); |
| 244 | + Ok(()) |
| 245 | +} |
| 246 | + |
| 247 | +/// Pins a second silent path: see the module docs. The terms are text, so |
| 248 | +/// comparing them across versions is ordinary text equality. The fixture's v4 |
| 249 | +/// row reuses the v3 row's terms, so here it even matches; with real Stack |
| 250 | +/// Encrypt terms it finds nothing. Either way nothing refuses it. |
| 251 | +#[sqlx::test(fixtures(path = "../fixtures", scripts("eql_v3_integer")))] |
| 252 | +async fn eq_term_across_versions_compares_text(pool: PgPool) -> Result<()> { |
| 253 | + install_v4(&pool).await?; |
| 254 | + tables_with_one_row(&pool).await?; |
| 255 | + |
| 256 | + let n: i64 = sqlx::query_scalar( |
| 257 | + "SELECT count(*) FROM t3 JOIN t4 ON eql_v3.eq_term(t3.c) = eql_v4.eq_term(t4.c)", |
| 258 | + ) |
| 259 | + .fetch_one(&pool) |
| 260 | + .await?; |
| 261 | + assert_eq!( |
| 262 | + n, 1, |
| 263 | + "the cross-version term comparison runs as text equality" |
| 264 | + ); |
| 265 | + Ok(()) |
| 266 | +} |
0 commit comments