Repository navigation
init-runtime-role.sh: pipe the owner guard's query to psql, not -c - #103
Conversation
…ixes #102) The migration-owner guard passed `:'owner'` inside `psql -c`. psql 16 sends a -c string to the server as written and interpolates a variable only in what it reads as input, so the server got a literal colon and answered a syntax error. The `if !` read that as "no such role", so every first start on a fresh data volume exited 1 with a refusal that blamed an owner which existed. The next start skipped initialization and PostgreSQL came up healthy without the runtime role. The query now goes in on stdin, where `:'owner'` is interpolated. Both copies of the script change identically and stay byte-identical. Nothing else in either file moves, so the open edits to the same files do not conflict. tests_runtime/test_runtime_role_bootstrap.py is new. Its DB-backed cases run each copy of the script against a real PostgreSQL 16 and ask the catalogue whether the runtime role, its CONNECT and USAGE grants and its default privileges are there, and that a migration owner the database lacks is still refused by name without a syntax error. Its hermetic cases hold that no `psql -c` argument carries a psql variable. The existing shape cases (test_deploy_shape.py) needed no change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 5 days and 3 hours by commenting |
|
@codex review |
Reviewer's GuideImplementationChange the migration-owner guard to send its variable-bearing query to psql on stdin, and document why it must not use -c.
TestsAdd hermetic checks against psql-variable use in command strings and PostgreSQL-backed tests of both scripts’ role bootstrap and missing-owner refusal behavior.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|



What was wrong
The migration-owner guard in
deploy/compose/init-runtime-role.shand its byte-identical copydeploy/kubernetes/base/init-runtime-role.shpassed a psql variable insidepsql -c:psql 16 hands a
-cstring to the server as written and interpolates:'owner'only in what it reads as input (stdin or-f). The server received a literal colon and answeredsyntax error at or near ":". Theif !around the pipeline read that as "no such role", so on every fresh data volume the script exited 1 with a refusal that named an owner that existed.restart: unless-stoppedstarted the container again, the entrypoint skipped initialization on the now non-empty data directory, and PostgreSQL came up healthy without theopendox_runtimerole.This was introduced with #25 and is unchanged in
v0.1.0. The reproduction and diagnosis are in #102.The fix
The query now reaches
psqlon stdin, where:'owner'is interpolated:Both copies change identically and stay byte-identical (
test_the_two_copies_of_the_role_bootstrap_are_byte_identicalholds that). A short comment above the guard says why it is not-c, so a later "simplification" does not put it back.Draft PR #99 edits other hunks of these same two files (the header comment and the table lists, not these lines). This diff touches only the guard and the comment beside it. A trial merge of this branch with #99's head merges cleanly, so the two can land in either order.
Tests
New file
tests_runtime/test_runtime_role_bootstrap.py(11 cases).tests_runtime/test_deploy_shape.pyneeded no change: none of its assertions pinned the old guard text, and its 111 cases pass as they are.DB-backed, and they run the script (
test_the_first_start_creates_the_runtime_role,test_a_migration_owner_the_database_lacks_is_refused_by_name), each over both copies, so 4 cases. Each creates a scratch database on the suite'sOPENDOX_TEST_DATABASE_URLserver, runs the unmodified script against it withpsql, then asks the catalogue:The scratch database and role are dropped afterwards. The
psqlis the one thelocalextra's bundled server ships (PostgreSQL 16, installed by.[runtime,test], whichvalidateinstalls), withPATH'spsqlonly as a fallback. The server is thevalidatejob's ownpostgres:16service, so this is a faithful run in CI even though that job does not mount the script. What it does not exercise is the image's entrypoint mechanics (docker-entrypoint-initdb.d, the temporary unix-socket server); the Docker run below covers those once, by hand.Hermetic (7 cases, no server): no
psql -cargument in either copy holds a psql variable reference, and the check itself is held to the old three-line form, because a check that cannot fail checks nothing. These keep guarding the class for a developer with no PostgreSQL.Skip count. A developer without Postgres or
psqlgets a skip with the reason printed. UnderCIthe same absence is a failure, asconftest._skip_or_faildoes for the rest of the DB-backed suite, so these cases cannot add a skip andEXPECT_SKIPPEDstays 11. The 11 new cases only raise SELECTED and PASSED, which the floors permit;validate.ymlis not touched.How it was verified
In
postgres:16containers, with the script supplied the way compose supplies it (OPENDOX_RUNTIME_PG_USER=opendox_runtime,OPENDOX_MIGRATION_PG_USERempty,OPENDOX_PG_SCHEMA=public):ERROR: syntax error at or near ":"/LINE 1: select 1 from pg_roles where rolname = :'owner', then the refusal naming'opendox'. This reproducesinit-runtime-role.shaborts every first start:psql -cdoes not expand:'owner'#102.opendox_runtimeexists (rolcanlogintrue, not a superuser), logs in with its password, has CONNECT and schema USAGE, andpg_default_aclholds{opendox_runtime=arwd/opendox}. After a container restart,pg_isreadyis accepting and the role is still there.OPENDOX_MIGRATION_PG_USER=nosuchowner): exit 1 with the intended refusal naming it, and no syntax error.sh -nandshellcheck -s share clean on the fixed script.Tests, against a
postgres:16server:python -m pytest tests_runtime/test_runtime_role_bootstrap.py: 11 passed.python -m pytest tests_runtime/test_deploy_shape.py: 111 passed.python -m pytest -q,.[runtime,test]installed under the repository's constraints file): 5921 selected, 5897 passed and 20 skipped (the skips are the test venv's missingpipand tools this machine lacks: an OMP harness and the model-provider broker binary). Four cases failed or errored for reasons of this machine's own environment: the venv had nopip(three wheel-building cases) and the shell had noLANGset (one environment-allowlist case). Withpipinstalled andLANG=C.UTF-8, all four pass. None involves this change.The Kubernetes copy is byte-identical to the compose copy and was run through the same tests, but nothing here ran on a cluster.
Fixes #102
🤖 Generated with Claude Code
Summary by Sourcery
Fix runtime-role initialization by ensuring psql interpolates the migration-owner variable before executing the guard query.
Bug Fixes:
Enhancements:
Tests: