fix: make transform.sh patches fail loudly#292
Draft
NikolayS wants to merge 1 commit into
Draft
Conversation
Build-pipeline integrity fixes for build/transform.sh: - C1: critical exact-string sed patches (batch_event_sql xid8 quoting, batch_retry NULL::xid8, upgrade_schema return cnt, annotations) now go through a sedi_must helper that fails the build when the expression changes nothing, instead of printing PASS unconditionally. - C2: missing input files are hard errors everywhere -- transform loop, FUNCTION_FILES assembly, pgque-additions, and the previously silent pgque-api loop -- so a submodule bump can no longer ship a truncated install file. - C3: the ticker/create_queue awk injections count their insertions and fail on zero; the vacuous whole-file pg_notify grep is replaced by a per-ticker-function-body check that cannot be satisfied by hardening.sql's own pg_notify. - C5: inline "PgQue transformation" annotations now run before Sections 6/7 are appended, so the external-ticker override from hardening.sql no longer gets a bogus "not in original PgQ" comment; the embedded chunk is byte-identical to its source. - C8: the install-file header version is derived from pgque.version() in lifecycle.sql (same extraction the pg_tle registration uses, done once), removing the hardcoded 0.2.0. Regenerated sql/pgque.sql and sql/pgque-tle.sql: the only change is the dropped annotation on the hardening.sql pg_notify line. Addresses findings C1, C2, C3, C5, C8 of #283. https://claude.ai/code/session_01KAaEGkQZmey1D1xCsVGmqv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Build-pipeline integrity fixes (transform.sh)
Addresses findings C1, C2, C3, C5, C8 of #283.
Bugs and fixes
C1 — silent no-op sed patches (medium)
The critical correctness patches (batch_event_sql xid8 quoting,
batch_retryNULL::int8 → NULL::xid8,upgrade_schemareturn 0 → return cnt, sqltriga header fix, annotation seds) were plainsedicalls: sed exits 0 whether or not it matched, and the script printedPASS: ...unconditionally. If upstream PgQ reworded an anchored line, the build would report success while the generatedbatch_event_sqlemits unquoted txids → runtimeoperator does not exist: xid8 = integeron every batch fetch.Fix: new
sedi_musthelper (cmp before/after; exits 1 with the failing expression and file when nothing changed). Every must-matchsedinow goes through it. Theupgrade_schemarole-grant andinsert_event_rawguard awk patches now count their substitutions/injections and fail on a count mismatch, matching the standard already set by the get_batch_cursor patch.C2 — missing source files only warned (medium)
WARNING ... continue→ hard error (exit 1).FUNCTION_FILESassembly loop:WARNING→ hard error.pgque-apifiles: previously silently skipped with no message → hard error; a missingsql/pgque-api/directory is also a hard error.pgque-additionsfiles: explicit hard error with a clear message.A submodule bump that renames/drops a file can no longer ship a truncated install file that passes the CI drift check after regenerate-and-commit.
C3 — vacuous pg_notify check + unverified ticker injection (medium)
return i_tick_id;,return currval(q.queue_tick_seq);) and fails the build unless each fired exactly once. Same for the create_queue length-check injection.grep -q 'pg_notify' "$INSTALL_FILE"was vacuous — Section 6 (hardening.sql) contains its own pg_notify, so it passed even if BOTH ticker injections missed. Replaced with an awk that extracts each tick-emittingpgque.tickerdefinition from the generated file and requiresperform pg_notify(inside each body.C5 — bogus annotation on hardening.sql's pg_notify line (low, changes generated files)
The
-- PgQue transformation: LISTEN/NOTIFY wakeup (not in original PgQ)annotation sed ran against the whole assembled file and also tagged the pg_notify line inside hardening.sql's external-ticker override — a line that was never in PgQ — making the embedded chunk differ fromsql/pgque-additions/hardening.sql.Fix: the annotation block now runs before Sections 6/7 are appended, so only the transformed-PgQ portion is annotated. Regenerated files: the only change to
sql/pgque.sqlandsql/pgque-tle.sqlis that line losing the bogus trailing comment, making the embedded hardening chunk byte-identical to its source (verified with a chunk diff, see below).C8 — hardcoded header version (low)
The generated header hardcoded
-- Version: 0.2.0while the pg_tle registration version was extracted dynamically frompgque.version()inlifecycle.sql. A version bump in lifecycle.sql would leave the header stale with no check.Fix: the version is extracted once, early (same anchored awk + semver validation), into
PGQUE_VERSIONand reused for both the header and the pg_tle registration. Current version is 0.2.0, so regeneration does not change the version text.Verification
1. Build on this branch: exit 0, expected diff only
The full generated-file diff (the single C5 annotation line, once per file):
2. Negative tests (submodule restored with
git -C pgq checkout .after each; nothing committed)C1 — reword the batch_event_sql anchor line:
C2 — delete an expected source file:
C2 — remove a pgque-api file (previously silently skipped):
C3 — break the ticker-injection anchor indentation:
C3b — the new post-assembly check is non-vacuous. Against a doctored copy of
sql/pgque.sqlwith the two injected ticker pg_notify lines stripped (hardening.sql's own pg_notify still present — this fooled the old whole-file grep,grep -c 'perform pg_notify'= 1):C8 — version propagation (temporary bump of lifecycle.sql to 9.9.9, then restored):
3. Fresh install + full test suite
4. Hardening chunk byte-identity
Manual verification command
Note: other branches from #283 also regenerate
sql/pgque.sql/sql/pgque-tle.sql; merge conflicts there are expected and should be resolved by re-runningbuild/transform.sh. The TLE header wording about client compatibility (finding C7) is intentionally untouched here.https://claude.ai/code/session_01KAaEGkQZmey1D1xCsVGmqv
Generated by Claude Code