feat(cli): read EQL v3 install SQL from @cipherstash/eql at runtime (CIP-3518)#692
Conversation
…CIP-3518) The v3 install SQL was vendored into packages/cli/src/sql/cipherstash-encrypt-v3.sql (~44k lines) by a build script (gen:eql-v3-sql), sha256-verified against the pinned @cipherstash/eql. That copy defeats the point of depending on @cipherstash/eql: it drifts from the pin on every bump (re-vendor required) and — as ~44k lines of plpgsql in the tree — made GitHub classify the whole repo as plpgsql (CIP-3518). Read it from the package at runtime instead: - `readV3InstallSql()` calls `@cipherstash/eql/sql` `readInstallSql()` (the same source the stack + prisma-next consume); the v3 branches of `loadBundledEqlSql` and `EQLInstaller` route to it, so `resolveBundledFilename` is now v2-only. - `@cipherstash/eql` moves devDependency → dependency, externalized in tsup so the real package (and its `dist/sql/*.sql`) resolves at runtime. - Delete `cipherstash-encrypt-v3.sql` + `scripts/build-eql-v3-sql.mjs` + the `gen:eql-v3-sql` script and its CI drift-check (tests.yml). No behaviour change: same one-artifact v3 bundle (self-adapts to non-superuser / Supabase via the DO-block privilege catch), v2 path untouched. A `@cipherstash/eql` bump now flows straight through. 557 cli unit green; bundle read verified via the bin from an external cwd. Claude-Session: https://claude.ai/code/session_01MxTTPaPP16m6br7Hoab94w
🦋 Changeset detectedLatest commit: 8d46579 The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
💤 Files with no reviewable changes (2)
📝 WalkthroughWalkthroughChangesEQL v3 runtime source
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant EQLInstaller
participant readV3InstallSql
participant EQLPackage as `@cipherstash/eql`
EQLInstaller->>readV3InstallSql: request v3 install SQL
readV3InstallSql->>EQLPackage: readInstallSql()
EQLPackage-->>readV3InstallSql: return SQL bundle
readV3InstallSql-->>EQLInstaller: return SQL or wrapped error
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates the stash CLI’s EQL v3 installer path to load the v3 install SQL at runtime from the pinned @cipherstash/eql package, removing the previously vendored ~44k-line SQL artifact and its drift-checking machinery. This keeps @cipherstash/eql as the single source of truth and avoids repo-language misclassification caused by the generated plpgsql file.
Changes:
- Switch EQL v3 install SQL loading to
@cipherstash/eql/sql’sreadInstallSql()at runtime, with improved error messaging and v3 routing that bypasses v2-only filename resolution. - Promote
@cipherstash/eqlto a runtime dependency and ensure it stays external in thestashlibrary bundle so its packageddist/sql/*.sqlassets resolve correctly at runtime. - Remove the v3 SQL vendoring script and the CI drift-check step; add a patch changeset for
stash.
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pnpm-lock.yaml | Moves @cipherstash/eql@3.0.0 from devDependency to dependency for stash. |
| packages/cli/tsup.config.ts | Externalizes @cipherstash/eql / @cipherstash/eql/sql in the library bundle so runtime SQL resolution works. |
| packages/cli/src/installer/index.ts | Adds readV3InstallSql() and routes v3 bundled SQL reads through @cipherstash/eql/sql; makes resolveBundledFilename explicitly v2-only. |
| packages/cli/scripts/build-eql-v3-sql.mjs | Removes the v3 vendoring script. |
| packages/cli/package.json | Adds @cipherstash/eql as a dependency and removes the gen:eql-v3-sql script and devDependency entry. |
| .github/workflows/tests.yml | Removes the CI step that regenerated and diff-checked the vendored v3 SQL bundle. |
| .changeset/eql-v3-source-from-package.md | Adds a stash patch changeset documenting the runtime sourcing change and removal of vendored SQL. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Differential Review: cipherstash/stack PR 692Executive Summary
Overall Risk: Low No correctness or security defects were found in the reviewed change. The new runtime SQL source is byte-identical to the deleted vendored artifact, the dependency is present in the packed manifest, and the packed ESM and CJS entry points both resolve and read the SQL from an external working directory. Key metrics:
What ChangedThe PR replaces the CLI's vendored EQL v3 SQL file with a runtime read from the exact-pinned
Total: 65 additions and 44,130 deletions across 8 files, in one commit dated 2026-07-17. FindingsNo actionable defects found. Non-blocking hardeningAdd a packed-artifact regression test that builds and packs Test Coverage AnalysisExisting tests cover the important behavior even though this PR does not add or modify a test file:
The deleted SQL and This proves the PR changes the source and packaging of the SQL, not its contents. Blast Radius Analysis
Failure of the new dependency resolution would prevent v3 installation and could prevent importing the public package entry. That failure mode is handled with an actionable error at Historical ContextThe vendoring path was introduced in July 2026 and subsequently strengthened with a drift gate and hash/version checks. Git history did not show removal of code introduced for a vulnerability, CVE, authentication boundary, or authorization fix. The removed checks protected synchronization of two copies; after this PR there is only one copy, so the synchronization check has no remaining invariant to enforce. The old generator compared the vendored file against RecommendationsImmediate
Before a future packaging refactor
Analysis MethodologyStrategy: Surgical. The repository contains approximately 777 relevant source files, while this PR changes 8 files and one runtime dependency boundary. Techniques applied:
Limitations:
Confidence: High for the PR's changed behavior and package-resolution contract. Appendix: Verification Results |
Why
The v3 install SQL was vendored into
packages/cli/src/sql/cipherstash-encrypt-v3.sql(~44k lines) by a build script (gen:eql-v3-sql), sha256-verified against the pinned@cipherstash/eql. That copy defeats the point of depending on@cipherstash/eql:What
Read it from the package at runtime instead —
@cipherstash/eqlis the single source of truth (the samereadInstallSql()the@cipherstash/stackinstaller and prisma-next already consume):readV3InstallSql()calls@cipherstash/eql/sqlreadInstallSql(); the v3 branches ofloadBundledEqlSqlandEQLInstallerroute to it, soresolveBundledFilenameis now v2-only.@cipherstash/eqlmoves devDependency → dependency, externalized intsupso the real package (and itsdist/sql/*.sql) resolves at runtime (the bin already externalizes all deps viaskipNodeModulesBundle).cipherstash-encrypt-v3.sql+scripts/build-eql-v3-sql.mjs+ thegen:eql-v3-sqlscript and its CI drift-check.Net: −44,130 lines. A
@cipherstash/eqlbump now flows straight through.No behaviour change
Same one-artifact v3 bundle. There is no Supabase/no-operator-family variant for v3 — the bundle self-adapts to non-superuser environments (its operator-class statements run inside a
DOblock that catchesinsufficient_privilegeand skips, then disables the ORE domains if absent). The v2 path (vendored.sql, variant selection) is untouched.Verified
readInstallSql()returns the v3 bundle (1.67 MB, correct content) resolved from the installed package.eql migrationdry-run on the stacked branch, which shares this installer code).pnpm install --frozen-lockfileconsistent.Changeset:
stashpatch.Follow-ups (separate): the v2 vendored files (~22k more plpgsql lines) still sit in the tree — fully closing CIP-3518 means dropping v2 or sourcing it likewise; and a repo-wide
@cipherstash/eql3.0.0 → 3.0.1 bump (npmlatest) with a prisma-next re-emit.https://claude.ai/code/session_01MxTTPaPP16m6br7Hoab94w
Summary by CodeRabbit
--latestoption.