Commit 1dc15d8
authored
feat(vnext): authenticate CTE main query sites (#190)
## Summary
- authenticate bounded CTE main-query entrypoints before the relation
query-site recognizer consumes them
- unify source, statement-index, slot, layout, and built-in runtime
provenance so mixed or stale evidence fails closed
- keep the low-level query-site recognizer independent of CTE and
aggregate runtime modules through a one-way orchestration layer
- preserve independent old/new statement contexts when incremental
indexes reuse immutable slot identities
- validate real ready paths in the CTE/query-site benchmarks
## Correctness and trust boundaries
- package-created sources, statement indexes, exact slots, CTE layouts,
and coherent dialect runtimes are authenticated by identity
- each statement index privately owns its exact analysis text, frozen
lexical-profile scalar snapshot, and bounded slot membership
- foreign sources, indexes, slots, profiles, layouts, mixed runtimes,
mutable structural copies, and hostile proxies return unavailable
- incomplete and invalid CTE headers remain fail-closed while valid main
queries work across PostgreSQL, DuckDB, BigQuery, and Dremio
## Verification
- 1,671 tests passed and 1 expected failure remained expected
- changed coverage: 96.99% statements, 95.95% branches, 100% functions,
96.96% lines
- all five TypeScript configurations passed
- oxlint passed with zero warnings or errors
- test-integrity and diff checks passed
- exact tarball package smoke, SSR import, strict CSP, worker placement,
and bundle budgets passed
- Chromium browser suite passed: 4 files / 7 tests
- statement-index, CTE-layout, and query-site benchmarks passed
- exact SHA c096a16 received three
independent adversarial approvals after five review/fix loops
Part of #169.
<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Authenticate CTE main‑query entrypoints and only recognize relation
query sites when the source, statement index, slot, and dialect all
match. Ambiguous evidence fails closed, keeping the core recognizer
independent; part of #169.
- **New Features**
- Authenticated CTE layouts: `analyzeSqlCteLayout(source, index, slot,
dialect)` records provenance and binds main‑query entrypoints to the
exact source/index/slot/dialect;
`resolveAuthenticatedSqlCteEntrypoints(...)` exposes them safely.
- Orchestration: `recognizeSqlRelationQuerySiteWithCteLayout(...)`
validates runtime/source/slot via `isSqlRelationDialectRuntime`,
`isSqlSourceSnapshot`, and `isSqlStatementSlotSnapshot`, then feeds
authenticated entrypoints into the query‑site recognizer; runtimes are
registered with `registerSqlRelationDialectRuntime`.
- Entrypoint‑aware query‑site:
`recognizeSqlRelationQuerySiteWithEntrypoints(...)` matches SELECTs at
the exact depth/offset for nested CTEs.
- Statement index provenance: `buildSqlStatementIndex` snapshots the
lexical profile; `isExactSqlStatementSlotSnapshot(For)` ensures slots
belong to the index and text/profile; `updateSqlStatementIndex` rebuilds
when text or lexical profile changes.
- **Migration**
- Pass the statement index into `analyzeSqlCteLayout` (new signature:
`(source, index, slot, dialect)`).
- Use `recognizeSqlRelationQuerySiteWithCteLayout` when combining CTE
layout with relation query‑site; keep `recognizeSqlRelationQuerySite`
for non‑CTE cases.
- Use built‑in registered runtimes from `relation-dialect` and authentic
sources/slots produced by our builders.
<sup>Written for commit 9ca185f.
Summary will update on new commits.</sup>
<a
href="https://cubic.dev/pr/marimo-team/codemirror-sql/pull/190?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>
<!-- End of auto-generated description by cubic. -->1 parent 19bbded commit 1dc15d8
15 files changed
Lines changed: 1379 additions & 43 deletions
File tree
- src/vnext
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | | - | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
30 | | - | |
| 32 | + | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| |||
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| 67 | + | |
65 | 68 | | |
66 | 69 | | |
67 | 70 | | |
| |||
70 | 73 | | |
71 | 74 | | |
72 | 75 | | |
| 76 | + | |
73 | 77 | | |
74 | 78 | | |
75 | 79 | | |
| |||
81 | 85 | | |
82 | 86 | | |
83 | 87 | | |
| 88 | + | |
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
| |||
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
| 97 | + | |
92 | 98 | | |
93 | 99 | | |
94 | 100 | | |
| |||
97 | 103 | | |
98 | 104 | | |
99 | 105 | | |
| 106 | + | |
100 | 107 | | |
101 | 108 | | |
102 | 109 | | |
| |||
105 | 112 | | |
106 | 113 | | |
107 | 114 | | |
| 115 | + | |
108 | 116 | | |
109 | 117 | | |
110 | 118 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| 73 | + | |
71 | 74 | | |
72 | 75 | | |
73 | | - | |
| 76 | + | |
74 | 77 | | |
75 | | - | |
76 | | - | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
77 | 81 | | |
78 | 82 | | |
79 | 83 | | |
| 84 | + | |
80 | 85 | | |
81 | 86 | | |
82 | 87 | | |
| |||
400 | 405 | | |
401 | 406 | | |
402 | 407 | | |
| 408 | + | |
403 | 409 | | |
404 | 410 | | |
405 | 411 | | |
| |||
1022 | 1028 | | |
1023 | 1029 | | |
1024 | 1030 | | |
1025 | | - | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
1026 | 1034 | | |
1027 | 1035 | | |
1028 | 1036 | | |
1029 | 1037 | | |
1030 | 1038 | | |
1031 | 1039 | | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
1032 | 1085 | | |
1033 | 1086 | | |
1034 | 1087 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
358 | 359 | | |
359 | 360 | | |
360 | 361 | | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
361 | 420 | | |
362 | 421 | | |
363 | 422 | | |
364 | 423 | | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
373 | 449 | | |
374 | 450 | | |
375 | 451 | | |
| |||
0 commit comments