From 38207494d7f6a89f1aaad32fe88110a684782a0a Mon Sep 17 00:00:00 2001 From: wangbo Date: Fri, 31 Jul 2026 19:26:25 +0800 Subject: [PATCH] =?UTF-8?q?fix(acceptance):=20=E4=BF=AE=E5=A4=8D=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BA=AB=E4=BB=BD=E6=A0=87?= =?UTF-8?q?=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过 psql 标准输入执行变量替换,并校验本地集群标识格式,确保安全标记在导入生产脱敏快照前可靠写入,避免验收编排因 -c 参数不展开变量而退出。\n\n验证:bash -n;ShellCheck;本地 CNPG 双实例实际写入与查询标记通过。 --- scripts/acceptance/local-cluster.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/scripts/acceptance/local-cluster.sh b/scripts/acceptance/local-cluster.sh index ac22726..a28fc60 100755 --- a/scripts/acceptance/local-cluster.sh +++ b/scripts/acceptance/local-cluster.sh @@ -263,13 +263,14 @@ mark_local_database() { local primary primary=$(kubectl --context "$context" -n "$namespace" get cluster easyai-postgres \ -o 'jsonpath={.status.currentPrimary}') - kubectl --context "$context" -n "$namespace" exec "$primary" -c postgres -- \ - psql -X -v ON_ERROR_STOP=1 -U postgres -d easyai_ai_gateway \ - -v cluster_id="$LOCAL_CLUSTER_ID" -c \ - "INSERT INTO system_settings(setting_key,value) - VALUES('acceptance_local_cluster_id',jsonb_build_object('clusterId', :'cluster_id')) - ON CONFLICT(setting_key) DO UPDATE SET value=excluded.value,updated_at=now();" \ - >/dev/null + [[ $LOCAL_CLUSTER_ID =~ ^easyai-local-[0-9a-f]{24}$ ]] + printf '%s\n' \ + "INSERT INTO system_settings(setting_key,value) + VALUES('acceptance_local_cluster_id',jsonb_build_object('clusterId', :'cluster_id')) + ON CONFLICT(setting_key) DO UPDATE SET value=excluded.value,updated_at=now();" | + kubectl --context "$context" -n "$namespace" exec -i "$primary" -c postgres -- \ + psql -X -v ON_ERROR_STOP=1 -U postgres -d easyai_ai_gateway \ + -v cluster_id="$LOCAL_CLUSTER_ID" >/dev/null } import_snapshot() {