EA-7: повтор считается по причине, при настройке владельца вместо кнопки ссылка

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Peppa 2026-11-16 14:04:23 +05:00
parent 892991e947
commit 99a5729bc7
11 changed files with 48 additions and 8 deletions

View File

@ -0,0 +1 @@
Решение: cookie `ea_fail` хранит «причина:число» (час). Подсказка «ещё раз» — только если причина совпала и число ≥ 2. Для `setup` при повторе вместо `.button` рендерится `.link`.

View File

@ -0,0 +1,3 @@
# EA-7: причина сбоя и смена подсказки при повторе
Причины сбоя и повторная подсказка появились в EA-3. Здесь доделано: повтор считается только по той же причине; при незавершённой настройке владельца кнопка подключения заменяется скромной ссылкой «Всё равно попробовать ещё раз».

View File

@ -0,0 +1,3 @@
- [x] Счёт неудач по причине
- [x] Ссылка вместо кнопки при повторной настройке владельца
- [x] Тексты ru/kk/en, тесты, спека

View File

@ -144,6 +144,12 @@
- **GIVEN** подключение уже один раз не удалось по той же причине
- **WHEN** оно не удаётся снова
- **THEN** руководитель видит другой текст, который не предлагает просто повторить
- **AND** если причина в настройке владельца, вместо кнопки подключения остаётся скромная ссылка «Всё равно попробовать ещё раз»
#### Scenario: Другая причина не считается повтором
- **GIVEN** предыдущая неудача была по другой причине
- **WHEN** подключение не удаётся снова
- **THEN** руководитель видит обычную подсказку для новой причины, а не повторную
#### Scenario: Успешное подключение после неудачи
- **GIVEN** предыдущая попытка не удалась

View File

@ -19,7 +19,7 @@ export type AppDeps = {
const CONNECTION_COOKIE = "ea_conn";
const STATE_COOKIE = "ea_state";
const LANG_COOKIE = "ea_lang";
/** Сколько раз подряд подключение не удалось (час): после второго раза подсказка другая. */
/** Причина и число неудач подряд, «setup:2» (час): после второго раза по той же причине подсказка другая. */
const FAIL_COOKIE = "ea_fail";
const HOUR_SECONDS = 60 * 60;
const YEAR_SECONDS = 365 * 24 * 60 * 60;
@ -28,6 +28,11 @@ const CALLBACK_PATH = "/auth/google/callback";
type Env = { Variables: { locale: Locale } };
function readFailures(raw: string | undefined): { notice: string | null; count: number } {
const [notice, count] = (raw ?? "").split(":");
return { notice: notice || null, count: Number.parseInt(count ?? "", 10) || 0 };
}
function firstHeaderValue(value: string | undefined): string | undefined {
return value?.split(",")[0]?.trim() || undefined;
}
@ -112,14 +117,14 @@ export function createApp(deps: AppDeps) {
if (!connection) {
const param = c.req.query("notice");
const notice = NOTICES.find((name) => name === param) ?? null;
const failures = Number.parseInt(getCookie(c, FAIL_COOKIE) ?? "", 10) || 0;
const last = readFailures(getCookie(c, FAIL_COOKIE));
const sample = isMock ? await loadSample() : null;
return c.html(
<ConnectPage
locale={locale}
isMock={isMock}
notice={notice}
repeated={failures >= 2}
repeated={notice !== null && last.notice === notice && last.count >= 2}
sample={sample}
/>,
);
@ -175,8 +180,9 @@ export function createApp(deps: AppDeps) {
/** Запоминает неудачу и ведёт на главную с причиной; счёт нужен для другой подсказки. */
const fail = (notice: Notice) => {
const failures = (Number.parseInt(getCookie(c, FAIL_COOKIE) ?? "", 10) || 0) + 1;
setCookie(c, FAIL_COOKIE, String(failures), cookieOptions(c, HOUR_SECONDS));
const last = readFailures(getCookie(c, FAIL_COOKIE));
const count = last.notice === notice ? last.count + 1 : 1;
setCookie(c, FAIL_COOKIE, `${notice}:${count}`, cookieOptions(c, HOUR_SECONDS));
return c.redirect(`/?notice=${notice}`);
};

View File

@ -10,6 +10,7 @@
"connect.readonly": "EA only reads your calendar and never changes anything in it.",
"connect.button": "Connect Google Calendar",
"reconnect.button": "Connect the calendar again",
"reconnect.anyway": "Try again anyway",
"notice.denied": "The calendar is not connected. To see your plans, allow EA to read your calendar.",
"notice.failed": "The calendar could not be connected. Please try connecting it again.",
"notice.failed.again": "The calendar still could not be connected. Wait a few minutes and try again; if that does not help, tell the product owner.",

View File

@ -10,6 +10,7 @@
"connect.readonly": "EA күнтізбені тек оқиды және онда ештеңені өзгертпейді.",
"connect.button": "Google күнтізбесін қосу",
"reconnect.button": "Күнтізбені қайта қосу",
"reconnect.anyway": "Бәрібір қайталап көру",
"notice.denied": "Күнтізбе қосылмады. Істерді көру үшін EA-ға күнтізбені оқуға рұқсат беріңіз.",
"notice.failed": "Күнтізбені қосу мүмкін болмады. Оны қайта қосып көріңіз.",
"notice.failed.again": "Күнтізбені қайта қосу мүмкін болмады. Бірнеше минут күтіп, қайталап көріңіз; көмектеспесе, өнім иесіне хабарлаңыз.",

View File

@ -10,6 +10,7 @@
"connect.readonly": "EA только читает календарь и ничего в нём не меняет.",
"connect.button": "Подключить календарь Google",
"reconnect.button": "Подключить календарь заново",
"reconnect.anyway": "Всё равно попробовать ещё раз",
"notice.denied": "Календарь не подключён. Чтобы видеть дела, разрешите EA чтение календаря.",
"notice.failed": "Не удалось подключить календарь. Попробуйте подключить его заново.",
"notice.failed.again": "Подключить календарь снова не получилось. Подождите несколько минут и попробуйте ещё раз; если не поможет, сообщите владельцу продукта.",

View File

@ -38,6 +38,7 @@ p { margin: 0 0 12px; }
.note.error { background: var(--err-bg); color: var(--err-text); }
.note.error.inline { margin: 20px 0 0; border-left: 4px solid currentColor; font-weight: 600; }
.note.error.inline + .button { margin-top: 12px; }
.link { display: inline-block; margin-top: 4px; color: var(--accent); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
section.sample { margin-top: 32px; padding-top: 20px; border-top: 1px dashed var(--line); }
section.sample > h2 { font-size: 18px; margin: 0 0 4px; }

View File

@ -70,9 +70,15 @@ export function ConnectPage(props: {
{t(locale, props.repeated ? `notice.${notice}.again` : `notice.${notice}`)}
</p>
)}
<a class="button" href="/connect">
{t(locale, notice ? "reconnect.button" : "connect.button")}
</a>
{notice && props.repeated && notice === "setup" ? (
<a class="link" href="/connect" data-testid="retry-link">
{t(locale, "reconnect.anyway")}
</a>
) : (
<a class="button" href="/connect">
{t(locale, notice ? "reconnect.button" : "connect.button")}
</a>
)}
</div>
{props.sample && (
<section class="sample" data-testid="sample" aria-label={t(locale, "sample.title")}>

View File

@ -209,6 +209,17 @@ describe("calendar-connection / Понятная причина неудачи",
expect(first).toContain("ещё не настроено до конца");
expect(second).toContain("Повторные попытки не помогут");
expect(second).not.toBe(first);
expect(second).toContain("Всё равно попробовать ещё раз");
expect(second).not.toContain("Подключить календарь заново");
});
it("Scenario: Другая причина не считается повтором", async () => {
const { client } = stubGoogle();
const visitor = browser(appWith(client));
await failOnce(visitor, client, new GoogleError("invalid_client", { kind: "setup" }));
const text = await failOnce(visitor, client, new GoogleError("no token", { kind: "consent" }));
expect(text).toContain("Google не передал нужное разрешение");
expect(text).not.toContain("по-прежнему");
});
it("Scenario: Успешное подключение после неудачи", async () => {