diff --git a/server/service/post-comments/guest-fields.test.ts b/server/service/post-comments/guest-fields.test.ts index 601632a..7884a4c 100644 --- a/server/service/post-comments/guest-fields.test.ts +++ b/server/service/post-comments/guest-fields.test.ts @@ -32,11 +32,11 @@ describe("resolveGuestFields", () => { ).toEqual({ guestEmail: null, guestIsAnonymous: false }); }); - test("legacy payload without guest email fields falls back to anonymous", () => { - expect( + test("guest with undefined anonymous flag defaults to non-anonymous and requires email", () => { + expect(() => resolveGuestFields({ viewerPresent: false, }), - ).toEqual({ guestEmail: null, guestIsAnonymous: true }); + ).toThrow(GuestCommentValidationError); }); }); diff --git a/server/service/post-comments/guest-fields.ts b/server/service/post-comments/guest-fields.ts index 57f13fd..3463b72 100644 --- a/server/service/post-comments/guest-fields.ts +++ b/server/service/post-comments/guest-fields.ts @@ -14,10 +14,7 @@ export function resolveGuestFields(input: { return { guestEmail: null, guestIsAnonymous: false }; } - // 兼容过渡策略:旧客户端尚未上送 guestEmail/guestIsAnonymous 时,按匿名处理,避免发布窗口内全量 400。 - // 待所有客户端完成升级后可移除此分支,恢复严格“默认非匿名且邮箱必填”语义。 - const isLegacyGuestPayload = input.guestEmail == null && input.guestIsAnonymous === undefined; - const guestIsAnonymous = input.guestIsAnonymous === true || isLegacyGuestPayload; + const guestIsAnonymous = input.guestIsAnonymous === true; const guestEmail = validateGuestCommentEmail(input.guestEmail, guestIsAnonymous); return { guestEmail, guestIsAnonymous }; }