From 90c489c31a80ad207c233aa44b71d3285b1acbc7 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 5 Nov 2026 22:29:11 +0900 Subject: [PATCH] =?UTF-8?q?fix(scaffold):=20=EC=83=9D=EC=84=B1=20=ED=8F=BC?= =?UTF-8?q?=EC=9D=B4=20"=EB=B3=80=EA=B2=BD=EB=90=A8=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=ED=99=95=EC=9D=B8"=20=EB=92=A4=20=EB=AA=A9=EB=A1=9D=EC=9D=84?= =?UTF-8?q?=20=EC=97=B0=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제 create:feature --with-create가 만드는 작성 폼의 feedback은 form.failure와 결과 불명 두 가지뿐이다. 저장 성공은 상세로 이동해서 알리는데, "변경됨으로 확인"은 reconcileUnknownEffect(...).then(form.settleApplied)이고 이동하지 않는다. settleApplied가 결과를 success로 바꾸고 기본값 resetOnSuccess로 입력을 비우므로, 결과 불명 화면이 사라진 뒤 빈 폼만 남는다. 짝 백엔드 기본(NEVER)에서는 이것이 화면 안의 유일한 행동이다. 사용자는 확인이 받아들여졌는지 모르고, 다시 입력해 저장하면 키 없는 생성이 한 번 더 나간다(실제로 저장됐던 경우 중복). 참조 폼은 같은 경우 "저장했습니다."를 보인다. 고른 방법 확인 뒤 폼을 정리하고(settleApplied, flushSync라 이동 전에 dirty 가드가 풀린다) 목록으로 이동한다. 목록은 항목이 실제로 저장됐는지를 보여 주는 화면이고, reconcileUnknownEffect가 이미 목록 topic을 무효화한다. 라우터가 목록 제목으로 포커스를 옮기므로 08-01의 포커스 문제도 이 폼에서는 생기지 않는다. 생성 기능 테스트에 "응답을 잃은 생성 → 변경됨으로 확인 → 목록 제목과 항목"을 한 행 더했다 (NEVER·KEYED 공통). 매뉴얼 02의 생성 테스트 행에 적었다. 버린 대안 참조 폼처럼 success 가지에 확인 문구를 둔다: 생성 catalog에 키가 하나 늘고, 항목이 실제로 있는지는 여전히 보이지 않는다. 위험·한계 - 짝 백엔드 생성기에는 목록 GET이 아직 없다(1103/03-07 결정 대기). 실제 짝 백엔드에서는 이동한 목록이 405를 받는다(생성 목록 페이지가 지금 그렇다). 생성 테스트는 MSW로 목록을 답한다. - 생성 결과 파일은 단위 테스트가 문자열로만 보고, 동작은 test:feature-scaffold (KEYED, FE-GATE-020)와 test:sample-removal(NEVER)에서 생성한 테스트가 본다. 검증 desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/create-feature.test.ts corepack pnpm test:feature-scaffold corepack pnpm test:sample-removal Refs: 1105/08-02 --- docs/manual/02-decision-tables.md | 2 +- scripts/create-feature-write-slice.ts | 39 +++++++++++++++++++++++++-- tests/unit/create-feature.test.ts | 17 ++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/docs/manual/02-decision-tables.md b/docs/manual/02-decision-tables.md index 7a8ae6b3..6f764c45 100644 --- a/docs/manual/02-decision-tables.md +++ b/docs/manual/02-decision-tables.md @@ -122,7 +122,7 @@ context는 URL 앞부분 하나(라우트 루트)를 가진다. 그 아래 기 | `commandEffect.refusedBeforeWrite` | `["_INVALID"]` | 같다 | 이름 규칙을 트랜잭션 전에 검사한다(4절) | | `acceptedStatuses` | `[201]` | `[201]` | `ResponseEntity.created`. 같은 키 재생도 첫 요청과 같은 201이다 | | 결과 불명 화면 | 확인만. 다시 보내기 버튼 없음 | "같은 요청으로 다시 보내기"가 같은 키로 보낸다 | 키 없는 재전송은 서버가 새 요청으로 본다 | -| 생성 테스트 | 응답 유실 → 결과 불명, 다시 보내기 없음, 키 헤더 없음 | 응답 유실 → 같은 키로 다시 보내기. 503 `IDEMPOTENCY_UNAVAILABLE` → 같은 키로 1회 자동 재전송 | `tests/features//-create-page.test.tsx`, `-http-gateway.test.ts` | +| 생성 테스트 | 응답 유실 → 결과 불명, 다시 보내기 없음, 키 헤더 없음. "변경됨으로 확인" → 목록 화면 | 응답 유실 → 같은 키로 다시 보내기. 503 `IDEMPOTENCY_UNAVAILABLE` → 같은 키로 1회 자동 재전송. "변경됨으로 확인" → 목록 화면 | `tests/features//-create-page.test.tsx`, `-http-gateway.test.ts` | - 테스트 하네스의 재시도 상한: 생성된 gateway 테스트는 앱 기본값(`maxRetryAttempts: 2`)으로 돈다. 그래야 `retryBudget: 1`의 재전송이 보인다. 페이지 테스트(`-test-app.tsx`)는 실패를 바로 보이려고 `MAX_RETRY_ATTEMPTS: 0`이다. diff --git a/scripts/create-feature-write-slice.ts b/scripts/create-feature-write-slice.ts index 83e147eb..45f20b1d 100644 --- a/scripts/create-feature-write-slice.ts +++ b/scripts/create-feature-write-slice.ts @@ -617,7 +617,8 @@ import { use${pascal}Create } from "./use-${base}-create.ts"; * of the name (400 ${write.invalidCode}, refused before the write) shows on * the field and the form saves again. A save whose result is unknown (the * response was lost) keeps the form: the user checks, or, for a KEYED - * command, resends the same request with the same key. + * command, resends the same request with the same key. Confirming it was + * applied opens the list, which shows whether the item is there. */ export default function ${pascal}CreatePage() { const navigate = useNavigate(); @@ -714,8 +715,13 @@ export default function ${pascal}CreatePage() { { - void mutation.reconcileUnknownEffect(resolution).then(form.settleApplied); + void mutation.reconcileUnknownEffect(resolution).then(() => { + form.settleApplied(); + void navigate(${camel}RouteUrl("${routeId}")); + }); }} // Drawn only for a request with a key (a KEYED command). onResendUnknownEffect={() => { @@ -842,6 +848,14 @@ function answerItem(body: JsonBodyType = { id: ITEM_ID, name: "First item" }) { ); } +function answerList() { + api.use( + http.get(\`\${API}${apiPath}\`, () => + HttpResponse.json({ success: true, data: [{ id: ITEM_ID, name: "First item" }], meta: META }), + ), + ); +} + async function openForm() { const user = await openSignedIn(${camel}RouteUrl("${write.create.routeId}")); expect( @@ -890,6 +904,27 @@ describe("${names.id} create form on the paired backend", () => { }); ${unknownTest} + + // 1105/08-02. Confirming an unknown create opens the list, which shows + // whether the item was saved; the form alone showed nothing. + it("opens the list after the user confirms a create whose response was lost", async () => { + const posts = answerCreate(() => HttpResponse.error()); + answerList(); + const user = await openForm(); + await user.type(await nameField(), "First item"); + await user.click(saveButton()); + expect(await screen.findByText(KO_MESSAGES["async.mutationEffectUnknown"])).toBeVisible(); + + await user.click( + screen.getByRole("button", { name: KO_MESSAGES["action.confirmMutationApplied"] }), + ); + + expect( + await screen.findByRole("heading", { level: 1, name: MESSAGES["${camel}.list.title"] }), + ).toBeVisible(); + expect(await screen.findByText("First item")).toBeVisible(); + expect(posts).toHaveLength(1); + }); }); `; } diff --git a/tests/unit/create-feature.test.ts b/tests/unit/create-feature.test.ts index 51e50a56..2e291100 100644 --- a/tests/unit/create-feature.test.ts +++ b/tests/unit/create-feature.test.ts @@ -282,6 +282,23 @@ describe("create:feature --with-create", () => { expect(page).toContain(""); }); + // 1105/08-02. Confirming an unknown create used to leave an emptied form + // that said nothing. It opens the list, which shows whether the item is + // there, and the generated page test walks that path. + it.each(["NEVER", "KEYED"] as const)( + "opens the list after the user confirms an unknown %s create", + (write) => { + const { files } = plan({ id: "invoice-feature", write }); + + expect( + files.get("src/features/invoice-feature/presentation/invoice-create-page.tsx"), + ).toContain('void navigate(invoiceRouteUrl("INVOICE_LIST"));'); + expect( + files.get("tests/features/invoice-feature/invoice-create-page.test.tsx"), + ).toContain('it("opens the list after the user confirms a create whose response was lost"'); + }, + ); + // 1103/16-07. A backend create made KEYED (IdempotencyExecutor) takes these. it("writes the KEYED values for a backend create made KEYED", () => { const { files } = plan({ id: "invoice-feature", write: "KEYED" });