From 3b47f8afa95f47fda4e3a22de3290cd9e38fd3e3 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 00:57:35 +0800 Subject: [PATCH] test: signup-abuse DB tests read the last psql line; business schema lists the two new tables (BUG-2402 follow-up) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8 --- docs/BUG_HISTORY.md | 2 ++ frontend/tests/database-local-business.test.ts | 8 ++++++++ frontend/tests/database-signup-abuse-2402.test.ts | 11 +++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 677a303a6..295e980d3 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -32663,3 +32663,5 @@ - 防复发:上述测试;`deploy/README.md`「注册防薅」一节写明环境变量和开通 Turnstile 的步骤。 - 关联记录:BUG-1355(聊天按用户限流)、BUG-2395(验证码邮箱后缀检查)、BUG-2348(花费告警兜底)。 - 修复版本:分支 `claude/signup-abuse-2402`。 + +- **BUG-2402 跟进(2026-11-26)**:staging 门禁 8731 两条数据库测试失败:① `database-local-business` 的 public 表清单没加新表 `first_consult_free_claims`、`request_rate_counters`;② `database-signup-abuse-2402` 用 `set role …; select …` 时 psql 第一行输出 `SET`,断言拿到 `SET\ngranted`。修复:清单按原值/新值/原因补上两张表;测试取输出最后一行。本机没有 docker,这两条只能在 CI 跑。 diff --git a/frontend/tests/database-local-business.test.ts b/frontend/tests/database-local-business.test.ts index 6d515d1ae..7e5930c7b 100644 --- a/frontend/tests/database-local-business.test.ts +++ b/frontend/tests/database-local-business.test.ts @@ -416,6 +416,10 @@ test("local PostgreSQL applies the reviewed business schema and serves authentic "feature_flags", // This migration intentionally adds the server-owned feature pricing table. "feature_pricing", + // 原值: feature_pricing 之后直接是 model_config_versions + // 新值: 加入 first_consult_free_claims + // 原因: BUG-2402 注册防薅,免费第一问按设备/网络摘要登记 + "first_consult_free_claims", "model_config_versions", "model_configs", "model_connection_test_evidence", @@ -454,6 +458,10 @@ test("local PostgreSQL applies the reviewed business schema and serves authentic // 原因: 「更新说明」(issue #331,20261122130000_release_notes.sql) "release_note_reads", "release_notes", + // 原值: release_notes 之后直接是 reply_quality_snapshots + // 新值: 加入 request_rate_counters + // 原因: BUG-2402 聊天限额计数存数据库,重启不清零 + "request_rate_counters", "reply_quality_snapshots", "reply_ratings", // 原值: reply_ratings 之后直接是 synastry_reports diff --git a/frontend/tests/database-signup-abuse-2402.test.ts b/frontend/tests/database-signup-abuse-2402.test.ts index 4afecdcd3..1a2b4859f 100644 --- a/frontend/tests/database-signup-abuse-2402.test.ts +++ b/frontend/tests/database-signup-abuse-2402.test.ts @@ -15,6 +15,9 @@ const IDENTITY = ["identity_runtime", "identity-runtime-test-password"] as const const users = Array.from({ length: 7 }, (_, index) => `78000000-0000-4000-8000-00000000000${index + 1}`); const digest = (char: string) => char.repeat(64); +// 原值:直接 .trim() 取 psql 输出 新值:取最后一行 原因:「set role …; select …」的输出第一行是 SET(CI run 8731) +const lastLine = (out: string): string => out.trim().split("\n").pop()!.trim(); + test("free-question screening, durable counters and the login-code table", () => { const fixture = startPostgresFixture(); try { @@ -29,8 +32,8 @@ test("free-question screening, durable counters and the login-code table", () => users.map((id, index) => `('${id}','u${index}@example.com',0)`).join(",")} on conflict (id) do nothing`); const screen = (user: string, device: string | null, address: string | null, disposable = false) => - fixture.psqlAs(...SERVICE, `set role service_role; select public.screen_first_consult_free('${user}'::uuid, ${ - device ? `'${device}'` : "null"}, ${address ? `'${address}'` : "null"}, ${disposable}, 3);`).trim(); + lastLine(fixture.psqlAs(...SERVICE, `set role service_role; select public.screen_first_consult_free('${user}'::uuid, ${ + device ? `'${device}'` : "null"}, ${address ? `'${address}'` : "null"}, ${disposable}, 3);`)); // Device: the first account on a device gets it, the second does not. assert.equal(screen(users[0]!, digest("a"), digest("1")), "granted"); @@ -59,8 +62,8 @@ test("free-question screening, durable counters and the login-code table", () => assert.throws(() => fixture.psqlAs("app_runtime", "app-runtime-test-password", "select count(*) from public.first_consult_free_claims")); // Durable counters: 2 per minute → the third is refused and nothing is written for it. - const consume = () => fixture.psqlAs(...SERVICE, - "set role service_role; select public.consume_request_rate_limits(array['consultMinute:x','consultHour:x'], array[60,3600], array[2,120]);").trim(); + const consume = () => lastLine(fixture.psqlAs(...SERVICE, + "set role service_role; select public.consume_request_rate_limits(array['consultMinute:x','consultHour:x'], array[60,3600], array[2,120]);")); assert.equal(consume(), "0"); assert.equal(consume(), "0"); assert.ok(Number(consume()) >= 1);