Skip to content

Commit af8c6f8

Browse files
committed
fix(eql): keep the placeholder build's gates able to fail
Gate 1 of verify_installer_complete.sh compared the order against the rendered tree, which build.sh writes from that same order, so a dropped file could no longer fail it. It now lists the source tree and maps the paths into the rendered namespace (a truncated order fails again). The Doxygen filter read through a process substitution, whose exit status is lost, so an unreadable input passed docs_v3_grep.sh with empty output; it is a plain pipe under pipefail now. eql-codegen render refuses an absolute or .. path instead of writing over the source. build/ is anchored so tasks/build/ is not ignored, the codegen templates are build cache sources, a moved doc comment is back on its function, and the schema, JSON and pin-script comments name the rendered version (v3 output is byte-identical).
1 parent 7645673 commit af8c6f8

9 files changed

Lines changed: 81 additions & 25 deletions

File tree

‎packages/eql/.gitignore‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,5 @@ docs/handoff/2026-06-10-v3-jsonb-fixture-alignment.md
262262
.claude/
263263

264264
# Rendered SQL per EQL version, written by tasks/build.sh from the placeholder
265-
# source (ADR-0002).
266-
build/
265+
# source (ADR-0002). Anchored: tasks/build/ is tracked.
266+
/build/

‎packages/eql/crates/eql-codegen/src/bindings.rs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ fn capability_label(domain_name: &str) -> &'static str {
8383
}
8484
}
8585

86+
/// The schema-qualified `eql_v3` domain a payload struct binds, e.g.
87+
/// `public.eql_v3_integer_eq`. The bindings describe v3 payloads only, so they
88+
/// name it literally, where the SQL surface writes the `{{prefix}}` placeholder.
89+
fn v3_domain_name(full: &str) -> String {
90+
format!("public.{}{full}", eql_domains::PUBLIC_TYPNAME_PREFIX)
91+
}
92+
8693
/// Render the catalog-derived struct doc lines for a domain: a summary line
8794
/// (`` `public.<name>` — <label>. ``) and a detail line listing the supported
8895
/// SQL operators and the required payload keys. Every part is derived from data
@@ -91,13 +98,6 @@ fn capability_label(domain_name: &str) -> &'static str {
9198
/// `Term::term_json_keys`) — so it stays deterministic and cannot drift from the
9299
/// payload shape. No free-form prose and no field docs: per-field semantics live
93100
/// on the shared term newtypes (`terms.rs`) and per-family caveats in `mod.rs`.
94-
/// The schema-qualified `eql_v3` domain a payload struct binds, e.g.
95-
/// `public.eql_v3_integer_eq`. The bindings describe v3 payloads only, so they
96-
/// name it literally, where the SQL surface writes the `{{prefix}}` placeholder.
97-
fn v3_domain_name(full: &str) -> String {
98-
format!("public.{}{full}", eql_domains::PUBLIC_TYPNAME_PREFIX)
99-
}
100-
101101
fn struct_doc_lines(full: &str, domain: &Domain) -> [String; 3] {
102102
// Leading space matches the `///` doc-comment convention (`#[doc = " …"]`):
103103
// rustfmt renders it as `/// …` and ts-rs as ` * …`. Without it the emitted

‎packages/eql/crates/eql-codegen/src/render.rs‎

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
use std::fmt;
2323
use std::fs;
2424
use std::io;
25-
use std::path::{Path, PathBuf};
25+
use std::path::{Component, Path, PathBuf};
2626

2727
/// The schema-and-name prefix placeholder.
2828
pub const PREFIX: &str = "{{prefix}}";
@@ -142,8 +142,19 @@ pub fn render_str(src: &str, version: EqlVersion) -> Result<String, RenderError>
142142
/// Why a file could not be rendered.
143143
#[derive(Debug)]
144144
pub enum RenderFileError {
145-
Io { path: PathBuf, source: io::Error },
146-
Render { path: PathBuf, source: RenderError },
145+
Io {
146+
path: PathBuf,
147+
source: io::Error,
148+
},
149+
Render {
150+
path: PathBuf,
151+
source: RenderError,
152+
},
153+
/// A file path that is absolute or climbs out with `..`. `out.join` would
154+
/// put its output outside `out`, or over the source itself.
155+
NotRelative {
156+
path: PathBuf,
157+
},
147158
}
148159

149160
impl fmt::Display for RenderFileError {
@@ -153,6 +164,11 @@ impl fmt::Display for RenderFileError {
153164
RenderFileError::Render { path, source } => {
154165
write!(f, "{}: {source}", path.display())
155166
}
167+
RenderFileError::NotRelative { path } => write!(
168+
f,
169+
"{}: not a relative path inside the source root",
170+
path.display()
171+
),
156172
}
157173
}
158174
}
@@ -161,7 +177,8 @@ impl std::error::Error for RenderFileError {}
161177

162178
/// Render each of `files` (relative to `root`) as `version`, writing it to the
163179
/// same relative path under `out`. Every file is rendered before any is
164-
/// written, so a source error leaves `out` as it was.
180+
/// written, so a source error leaves `out` as it was. A path that is absolute
181+
/// or contains `..` is refused, since its output would land outside `out`.
165182
pub fn render_files(
166183
root: &Path,
167184
files: &[PathBuf],
@@ -170,6 +187,12 @@ pub fn render_files(
170187
) -> Result<(), RenderFileError> {
171188
let mut rendered = Vec::with_capacity(files.len());
172189
for rel in files {
190+
if !rel
191+
.components()
192+
.all(|c| matches!(c, Component::Normal(_) | Component::CurDir))
193+
{
194+
return Err(RenderFileError::NotRelative { path: rel.clone() });
195+
}
173196
let path = root.join(rel);
174197
let src = fs::read_to_string(&path).map_err(|source| RenderFileError::Io {
175198
path: path.clone(),
@@ -287,4 +310,29 @@ mod tests {
287310
);
288311
fs::remove_dir_all(&dir).unwrap();
289312
}
313+
314+
#[test]
315+
fn render_files_refuses_paths_outside_out() {
316+
let dir = std::env::temp_dir().join(format!("eql-render-abs-{}", std::process::id()));
317+
let root = dir.join("root");
318+
let out = dir.join("out");
319+
fs::create_dir_all(root.join("src")).unwrap();
320+
let src = root.join("src/a.sql");
321+
fs::write(&src, "SELECT {{prefix}}.f();\n").unwrap();
322+
323+
for rel in [src.clone(), PathBuf::from("src/../src/a.sql")] {
324+
let err =
325+
render_files(&root, std::slice::from_ref(&rel), &out, EqlVersion::V4).unwrap_err();
326+
assert!(
327+
matches!(&err, RenderFileError::NotRelative { path } if *path == rel),
328+
"{err}"
329+
);
330+
}
331+
assert_eq!(
332+
fs::read_to_string(&src).unwrap(),
333+
"SELECT {{prefix}}.f();\n"
334+
);
335+
assert!(!out.exists());
336+
fs::remove_dir_all(&dir).unwrap();
337+
}
290338
}

‎packages/eql/src/v3/json/types.sql‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ $$;
8585
--! @internal
8686
--! @param val jsonb Candidate document payload.
8787
--! @return boolean True when `val` is an encrypted document envelope with
88-
--! `v = 3`, `i`, a string key header `h`, an `sv` array, and valid
88+
--! `v = {{eql_version}}`, `i`, a string key header `h`, an `sv` array, and valid
8989
--! sv entry elements. `h` carries the document's key-retrieval
9090
--! material once (every entry encrypts under the document's single
9191
--! data key; entry `c` values are raw AEAD output whose nonces are
@@ -117,7 +117,7 @@ $$;
117117

118118
--! @brief Storage/root domain for an encrypted JSONB column.
119119
--!
120-
--! CHECK: a JSON object carrying the EQL envelope (`v = 3` version, `i` index
120+
--! CHECK: a JSON object carrying the EQL envelope (`v = {{eql_version}}` version, `i` index
121121
--! metadata, and the key header `h`). Root `c` is intentionally NOT required —
122122
--! an sv-array root payload is `{i, v, h, sv}` with no root ciphertext (the
123123
--! root document ciphertext lives on the root sv entry). The CHECK also

‎packages/eql/src/v3/schema.sql‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--! @file v3/schema.sql
2-
--! @brief EQL v3 schema creation
2+
--! @brief EQL v{{eql_version}} schema creation
33
--!
44
--! Creates the {{prefix}} and {{prefix}}_internal schemas. User-column encrypted
55
--! domains (public.{{prefix}}_integer, public.{{prefix}}_bigint, and future scalar domains) live in
@@ -34,19 +34,19 @@
3434
--! reaches an internal object indirectly (a public operator/aggregate
3535
--! whose backing state-fn/blocker lives there), grant it deliberately.
3636

37-
--! @brief Drop existing EQL v3 schema
37+
--! @brief Drop existing EQL v{{eql_version}} schema
3838
--! @warning CASCADE will drop all dependent objects
3939
DROP SCHEMA IF EXISTS {{prefix}} CASCADE;
4040

41-
--! @brief Create EQL v3 schema
41+
--! @brief Create EQL v{{eql_version}} schema
4242
--! @note Houses the encrypted-domain type families
4343
CREATE SCHEMA {{prefix}};
4444

45-
--! @brief Drop existing EQL v3 internal schema
45+
--! @brief Drop existing EQL v{{eql_version}} internal schema
4646
--! @warning CASCADE will drop all dependent objects
4747
DROP SCHEMA IF EXISTS {{prefix}}_internal CASCADE;
4848

49-
--! @brief Create EQL v3 internal implementation schema
49+
--! @brief Create EQL v{{eql_version}} internal implementation schema
5050
--! @note Houses INTERNAL {{prefix}} objects only: SEM index-term TYPES + their
5151
--! support/constructor/comparator functions, the unsupported-operator
5252
--! blockers (which only raise), the aggregate state functions, and the

‎packages/eql/tasks/build.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
#MISE description="Build SQL into single release file"
33
#MISE alias="b"
4-
#MISE sources=["src/v3/**/*.sql", "src/v3/version.template", "tasks/pin_search_path_v3.sql", "tasks/uninstall-v3.sql", "crates/eql-domains/src/**/*.rs", "crates/eql-codegen/src/**/*.rs", "Cargo.toml", "Cargo.lock", "crates/eql-codegen/Cargo.toml", "crates/eql-domains/Cargo.toml", "tasks/build/ordering.sh", "tasks/test/verify_symbol_order_v3.sh", "tasks/test/verify_installer_complete.sh", "tasks/test/symbol_order_allowlist.txt"]
4+
#MISE sources=["src/v3/**/*.sql", "src/v3/version.template", "tasks/pin_search_path_v3.sql", "tasks/uninstall-v3.sql", "crates/eql-domains/src/**/*.rs", "crates/eql-codegen/src/**/*.rs", "crates/eql-codegen/templates/**", "Cargo.toml", "Cargo.lock", "crates/eql-codegen/Cargo.toml", "crates/eql-domains/Cargo.toml", "tasks/build/ordering.sh", "tasks/test/verify_symbol_order_v3.sh", "tasks/test/verify_installer_complete.sh", "tasks/test/symbol_order_allowlist.txt"]
55
#MISE outputs=["release/cipherstash-encrypt.sql","release/cipherstash-encrypt-uninstall.sql","src/deps-ordered-v3.txt","build/render/eql_v3/deps-ordered.txt"]
66
#USAGE flag "--version <version>" help="Specify release version of EQL" default="DEV"
77

‎packages/eql/tasks/docs/doxygen-filter.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ fi
4343
#
4444
# Reducing each to a single `CREATE AGGREGATE name(argtype);` declaration
4545
# recovers the name in both cases and leaves a clean argument list.
46-
awk '
46+
#
47+
# A real pipe, not `awk … < <(sed …)`: pipefail covers a pipe, so a `sed` that
48+
# cannot read its input fails the filter, and docs_v3_grep.sh relies on that
49+
# status. A process substitution's exit status is lost.
50+
sed -e 's/{{prefix}}/eql_v3/g' -e 's/{{eql_version}}/3/g' "$1" | awk '
4751
/^--![[:space:]]+@cond[[:space:]]+deprecated_compatibility[[:space:]]*$/ {
4852
inhidden = 1
4953
print ""
@@ -104,4 +108,4 @@ awk '
104108
gsub(/--/, "//", out)
105109
print out
106110
}
107-
' < <(sed -e 's/{{prefix}}/eql_v3/g' -e 's/{{eql_version}}/3/g' "$1")
111+
'

‎packages/eql/tasks/pin_search_path_v3.sql‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
--! @file pin_search_path_v3.sql
22
--! @brief Post-install: pin search_path on every {{prefix}}.* function.
33
--!
4-
--! Appended verbatim by `tasks/build.sh` to the end of the v3-only release
4+
--! Appended verbatim by `tasks/build.sh` to the end of the v{{eql_version}}-only release
55
--! artifact, AFTER all src/v3/**/*.sql files have been concatenated. It lives
66
--! outside src/ so it stays out of the dependency graph.
77
--!

‎packages/eql/tasks/test/verify_installer_complete.sh‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ fail=0
7676
echo "==> Non-vacuity gate: the order names every src/v3 SQL file"
7777
work="$(mktemp -d)"
7878
trap 'rm -rf "$work"' EXIT
79-
find "$ROOT/src/v3" -type f -name '*.sql' ! -name '*_test.sql' | LC_ALL=C sort > "$work/disk"
79+
# The disk side reads the SOURCE tree, not the rendered one: build.sh renders
80+
# exactly the files the order names, so the rendered tree always agrees with the
81+
# order and a comparison against it could never fail. Map the source paths into
82+
# the rendered namespace the order uses.
83+
find src/v3 -type f -name '*.sql' ! -name '*_test.sql' | sed "s|^|$ROOT/|" | LC_ALL=C sort > "$work/disk"
8084
grep -v '^[[:space:]]*$' "$ORDERED" | LC_ALL=C sort > "$work/order" || true
8185
n_disk=$(count_lines "$work/disk")
8286

0 commit comments

Comments
 (0)