test(integration): take the suite's ports from the environment - #434
test(integration): take the suite's ports from the environment#434freshtonic wants to merge 1 commit into
Conversation
The four ports the integration suite connects to were hardcoded, so only one copy of the suite could run at a time. Several agents each working on a different Proxy defect need their own Proxy and PostgreSQL, which means their own ports. Each port now reads an environment variable and falls back to the current value, so an unconfigured run behaves exactly as before. A malformed value panics rather than falling back: silently retargeting the whole suite at whatever else is listening on 6432 is the one failure that looks like a pass.
📝 WalkthroughWalkthroughIntegration-test ports now resolve from environment variables with defaults, and all affected proxy/Postgres connection helpers and tests dereference the new lazy port values. ChangesRuntime integration test port configuration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/cipherstash-proxy-integration/src/common.rs`:
- Around line 67-72: Update the environment-variable parsing match around
std::env::var in the port configuration logic to distinguish
VarError::NotPresent from VarError::NotUnicode. Return the default only for
NotPresent, and panic with a clear misconfiguration message for NotUnicode
instead of silently using the default port.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 57d425b3-424d-411d-9b31-8cd230844ffb
📒 Files selected for processing (49)
packages/cipherstash-proxy-integration/src/common.rspackages/cipherstash-proxy-integration/src/connection_resilience.rspackages/cipherstash-proxy-integration/src/decrypt/insert_returning.rspackages/cipherstash-proxy-integration/src/diagnostics.rspackages/cipherstash-proxy-integration/src/disable_mapping.rspackages/cipherstash-proxy-integration/src/empty_result.rspackages/cipherstash-proxy-integration/src/encryption_sanity.rspackages/cipherstash-proxy-integration/src/eql_regression.rspackages/cipherstash-proxy-integration/src/extended_protocol_error_messages.rspackages/cipherstash-proxy-integration/src/insert/insert_domain_type.rspackages/cipherstash-proxy-integration/src/insert/insert_with_params.rspackages/cipherstash-proxy-integration/src/map_concat.rspackages/cipherstash-proxy-integration/src/map_literals.rspackages/cipherstash-proxy-integration/src/map_match_index.rspackages/cipherstash-proxy-integration/src/map_nulls.rspackages/cipherstash-proxy-integration/src/map_ope_index_order.rspackages/cipherstash-proxy-integration/src/map_ope_index_where.rspackages/cipherstash-proxy-integration/src/map_ore_index_order.rspackages/cipherstash-proxy-integration/src/map_ore_index_where.rspackages/cipherstash-proxy-integration/src/map_params.rspackages/cipherstash-proxy-integration/src/map_unique_index.rspackages/cipherstash-proxy-integration/src/migrate/mod.rspackages/cipherstash-proxy-integration/src/multitenant/contention.rspackages/cipherstash-proxy-integration/src/multitenant/ore_order.rspackages/cipherstash-proxy-integration/src/multitenant/set_keyset_id.rspackages/cipherstash-proxy-integration/src/multitenant/set_keyset_name.rspackages/cipherstash-proxy-integration/src/passthrough.rspackages/cipherstash-proxy-integration/src/pipeline.rspackages/cipherstash-proxy-integration/src/schema_change.rspackages/cipherstash-proxy-integration/src/select/distinct_order_by.rspackages/cipherstash-proxy-integration/src/select/indexing.rspackages/cipherstash-proxy-integration/src/select/jsonb_array_elements.rspackages/cipherstash-proxy-integration/src/select/jsonb_containment_index.rspackages/cipherstash-proxy-integration/src/select/jsonb_fusion_gaps.rspackages/cipherstash-proxy-integration/src/select/jsonb_path_query.rspackages/cipherstash-proxy-integration/src/select/jsonb_selector_param_types.rspackages/cipherstash-proxy-integration/src/select/operator_backed_predicates.rspackages/cipherstash-proxy-integration/src/select/operator_class_shapes.rspackages/cipherstash-proxy-integration/src/select/pg_catalog.rspackages/cipherstash-proxy-integration/src/select/select_where_in.rspackages/cipherstash-proxy-integration/src/select/select_where_jsonb.rspackages/cipherstash-proxy-integration/src/select/unmappable.rspackages/cipherstash-proxy-integration/src/set_keyset_error.rspackages/cipherstash-proxy-integration/src/simple_protocol/error_handling.rspackages/cipherstash-proxy-integration/src/simple_protocol/map_literals.rspackages/cipherstash-proxy-integration/src/simple_protocol/map_nulls.rspackages/cipherstash-proxy-integration/src/simple_protocol/multiple_statements.rspackages/cipherstash-proxy-integration/src/update/update_domain_type.rspackages/cipherstash-proxy-integration/src/update/update_with_reused_param.rs
| match std::env::var(var) { | ||
| Ok(value) => value | ||
| .parse() | ||
| .unwrap_or_else(|_| panic!("{var} must be a port number, got: {value:?}")), | ||
| Err(_) => default, | ||
| } |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== locate file =="
git ls-files | rg '(^|/)common\.rs$' || true
echo "== target file context =="
if [ -f packages/cipherstash-proxy-integration/src/common.rs ]; then
nl -ba packages/cipherstash-proxy-integration/src/common.rs | sed -n '1,140p'
fi
echo "== env var usage in proxy integration =="
rg -n 'port_from_env|PORT|DEFAULT|LazyLock' packages/cipherstash-proxy-integration/src packages/cipherstash-proxy-integration -S || true
echo "== rust compiler availability =="
command -v rustc && rustc --version || trueRepository: cipherstash/proxy
Length of output: 324
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "== target file context =="
cat -n packages/cipherstash-proxy-integration/src/common.rs | sed -n '1,140p'
echo "== env var usage in proxy integration =="
rg -n 'port_from_env|PORT|DEFAULT|LazyLock|std::env::var' packages/cipherstash-proxy-integration/src packages/cipherstash-proxy-integration -S || true
echo "== deterministic VarError text check from Rust std source on installed SDK if available =="
if command -v rustc >/dev/null 2>&1; then
rustc --version
else
echo "rustc unavailable"
fi
echo "== local source VarError matches if Rust toolchain source is reachable =="
for d in /usr/local/rustup/toolchains/*/lib/rustlib/src/rust/library/std/src/sys/unix/uw8.rs /usr/local/rustup/toolchains/*/lib/rustlib/src/rust/library/std/src/env.rs; do
[ -d "$d" ] && { echo "FOUND $d"; find "$d" -maxdepth 2 -type f | head -20; } || true
done
rg -n 'enum VarError|VarError::NotUnicode|NotUnicode|std::env::var' /usr/local/rustup/toolchains/*/lib/rustlib/src/rust/library/std/src 2>/dev/null | head -80 || trueRepository: cipherstash/proxy
Length of output: 22363
🌐 Web query:
Rust std::env::var VarError NotUnicode documentation
💡 Result:
In Rust, std::env::VarError is an enum used to represent errors that occur when interacting with environment variables, particularly when using the std::env::var function [1][2]. The VarError::NotUnicode variant specifically indicates that while the requested environment variable was found, its value does not contain valid Unicode data [1][3]. The NotUnicode variant carries an OsString payload, which allows the program to access the original, non-Unicode data [1][4]. For scenarios where you need to handle environment variables that may contain non-Unicode data without triggering this error, the standard library provides the std::env::var_os function, which returns an Option instead of a Result<String, VarError> [5][6].
Citations:
- 1: https://doc.rust-lang.org/stable/std/env/enum.VarError.html
- 2: https://doc.rust-lang.org/std/env/enum.VarError.html
- 3: https://docs.rust-lang.org/std/env/enum.VarError.html
- 4: https://doc.rust-lang.org/nightly/std/env/enum.VarError.html?gotosrc=2826
- 5: https://doc.rust-lang.org/stable/std/env/fn.var.html
- 6: https://doc.rust-lang.org/std/env/fn.var.html
Do not treat non-UTF-8 environment values as unset.
std::env::var returns VarError::NotUnicode(_) when the variable is present but contains invalid UTF-8, and Err(_) => default silently selects the default port. Match VarError::NotPresent separately and panic for NotUnicode so this explicit misconfiguration fails instead of connecting to the wrong instance.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/cipherstash-proxy-integration/src/common.rs` around lines 67 - 72,
Update the environment-variable parsing match around std::env::var in the port
configuration logic to distinguish VarError::NotPresent from
VarError::NotUnicode. Return the default only for NotPresent, and panic with a
clear misconfiguration message for NotUnicode instead of silently using the
default port.
Prerequisite for the three plaintext-leak fixes stacked on top of this branch (CIP-3680, CIP-3682, CIP-3688). Small and standalone.
Why
The four ports the integration suite connects to were hardcoded (
pub const PROXY: u16 = 6432), so only one copy of the suite could run at a time. Fixing three separate Proxy defects in parallel needs three Proxy instances against three databases, which needs three sets of ports.What
PROXY,PROXY_METRICS_PORT,PG_PORTandPG_TLS_PORTbecomeLazyLock<u16>readingCS_TEST_PROXY_PORT,CS_TEST_PROXY_METRICS_PORT,CS_TEST_PG_PORTandCS_TEST_PG_TLS_PORT, each falling back to its current value. An unconfigured run behaves exactly as before.A malformed value panics rather than falling back to the default. Silently retargeting the whole suite at whatever else happens to be listening on 6432 is the one failure mode that looks like a pass.
Note for anyone running the suite on custom ports
mise execoverridesCS_DATABASE__PORTfrom the parent shell, becausemise.tomlsets it to5532:Re-assert it inside:
mise exec -- env CS_DATABASE__PORT=5541 cargo …. TheCS_TEST_*variables introduced here are not set inmise.toml, so they pass through fine. Tests that run the migrate CLI in-process also needCS_SERVER__PORTset, since that CLI reads it to find Proxy.Testing
cargo check -p cipherstash-proxy-integration --testsclean;cargo fmtclean. Behaviour with no environment variables set is unchanged by construction.Acknowledgment
By submitting this pull request, I confirm that CipherStash can use, modify, copy, and redistribute this contribution, under the terms of CipherStash's choice.
Summary by CodeRabbit