test: provider key database test expects the fixture's f for false (BUG-1922)

The staging gate failed on this new test only: the psql fixture rewrites a
colon-joined false to f, and four expectations spelled it out.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
This commit is contained in:
2026-11-16 10:33:16 +08:00
co-authored by Claude Fable 5.2
parent c461305b36
commit ae2fe22255
@@ -16,6 +16,7 @@ const ids = {
support: "10000000-0000-4000-8000-000000000004",
};
// The psql fixture prints a colon-joined "false" as "f" (tests/helpers/postgres-fixture.ts), so expectations use "f".
test("provider keys: copy of the old key, audited writes, last-key rule and admin_runtime reads", async () => {
const fixture = startPostgresFixture();
const sql = (statement: string) => fixture.psql(statement);
@@ -83,7 +84,7 @@ test("provider keys: copy of the old key, audited writes, last-key rule and admi
// Disabling the first key moves the legacy column to the next enabled key.
sqlAsOwner(saveKey(ids.owner, provider, copied, "默认", null, false, null, "key-disable"));
assert.equal(sql(`select encrypted_api_key||':'||enabled from public.model_provider_keys where id='${copied}'`), "ciphertext-one:false", "a null key keeps the stored one");
assert.equal(sql(`select encrypted_api_key||':'||enabled from public.model_provider_keys where id='${copied}'`), "ciphertext-one:f", "a null key keeps the stored one");
assert.equal(legacyKey(provider), "ciphertext-two");
// The last enabled key of an enabled provider can be neither disabled nor deleted.
@@ -126,7 +127,7 @@ test("provider keys: copy of the old key, audited writes, last-key rule and admi
assert.equal(sql(`select string_agg(distinct action||':'||target_type||':'||permission_used, ',' order by action||':'||target_type||':'||permission_used) from audit.admin_audit_logs where action like 'models.provider_key.%'`),
"models.provider_key.delete:model_provider_key:models.write,models.provider_key.save:model_provider_key:models.write");
assert.equal(sql(`select after_value::text from audit.admin_audit_logs where request_id='key-add'`), `{"label": "二号", "enabled": true, "providerId": "${provider}", "maxConcurrency": 2, "credentialReplaced": true}`);
assert.equal(sql(`select (after_value->>'credentialReplaced')||':'||(before_value->>'enabled') from audit.admin_audit_logs where request_id='key-disable'`), "false:true");
assert.equal(sql(`select (after_value->>'credentialReplaced')||':'||(before_value->>'enabled') from audit.admin_audit_logs where request_id='key-disable'`), "f:true");
assert.equal(sql(`select count(*) from audit.admin_audit_logs where action like 'models.provider%' and (coalesce(before_value::text,'')||coalesce(after_value::text,'')) like '%ciphertext%'`), "0");
assert.equal(sql(`select count(*) from audit.admin_audit_logs where request_id in ('denied-save','denied-delete','last-disable','last-delete')`), "0");
@@ -134,9 +135,9 @@ test("provider keys: copy of the old key, audited writes, last-key rule and admi
assert.equal(sqlAsAdminRuntime(`select label from public.model_provider_keys where id='${second}'`), "主账号");
assert.equal(sql("select count(*) from pg_policies where schemaname='public' and tablename='model_provider_keys' and policyname='model_provider_keys_admin_select' and cmd='SELECT' and roles='{admin_runtime}'"), "1");
assert.equal(sql("select relrowsecurity from pg_class where oid='public.model_provider_keys'::regclass"), "t");
assert.equal(sql("select has_table_privilege('admin_runtime','public.model_provider_keys','select')||':'||has_table_privilege('admin_runtime','public.model_provider_keys','insert')||':'||has_table_privilege('admin_runtime','public.model_provider_keys','update')||':'||has_table_privilege('admin_runtime','public.model_provider_keys','delete')"), "true:false:false:false");
assert.equal(sql("select has_table_privilege('service_role','public.model_provider_keys','select')||':'||has_table_privilege('authenticated','public.model_provider_keys','select')||':'||has_table_privilege('anon','public.model_provider_keys','select')"), "true:false:false");
assert.equal(sql("select has_function_privilege('admin_runtime','public.admin_save_model_provider_key(uuid,uuid,uuid,text,text,boolean,integer,text,text)','execute')||':'||has_function_privilege('admin_runtime','public.admin_delete_model_provider_key(uuid,uuid,text,text)','execute')||':'||has_function_privilege('authenticated','public.admin_save_model_provider_key(uuid,uuid,uuid,text,text,boolean,integer,text,text)','execute')||':'||has_function_privilege('admin_runtime','public.sync_model_provider_legacy_key(uuid)','execute')"), "true:true:false:false");
assert.equal(sql("select has_table_privilege('admin_runtime','public.model_provider_keys','select')||':'||has_table_privilege('admin_runtime','public.model_provider_keys','insert')||':'||has_table_privilege('admin_runtime','public.model_provider_keys','update')||':'||has_table_privilege('admin_runtime','public.model_provider_keys','delete')"), "true:f:f:f");
assert.equal(sql("select has_table_privilege('service_role','public.model_provider_keys','select')||':'||has_table_privilege('authenticated','public.model_provider_keys','select')||':'||has_table_privilege('anon','public.model_provider_keys','select')"), "true:f:f");
assert.equal(sql("select has_function_privilege('admin_runtime','public.admin_save_model_provider_key(uuid,uuid,uuid,text,text,boolean,integer,text,text)','execute')||':'||has_function_privilege('admin_runtime','public.admin_delete_model_provider_key(uuid,uuid,text,text)','execute')||':'||has_function_privilege('authenticated','public.admin_save_model_provider_key(uuid,uuid,uuid,text,text,boolean,integer,text,text)','execute')||':'||has_function_privilege('admin_runtime','public.sync_model_provider_legacy_key(uuid)','execute')"), "true:true:f:f");
assert.throws(() => sqlAsAdminRuntime(`update public.model_provider_keys set enabled=false where id='${second}'`), /permission denied/);
const runtimeKey = sqlAsAdminRuntime(saveKey(ids.owner, provider, null, "三号", "ciphertext-three", true, 8, "runtime-add"));
// The catalog query shape: enabled keys oldest first.