fix(query): 재전송 거절의 결과 불명 해제를 짝 백엔드 표 code로만 정한다
문제: 80e7f1d의 isRefusedOnEveryAttempt는 kind가 VALIDATION_REJECTED면 code를 보지 않고 참을 돌려준다. 그 kind는 기능의 mapProblem이 정한다. 생성기는 선언한 <FEATURE>_INVALID를 VALIDATION_REJECTED로 옮기고 (scripts/create-feature-write-slice.ts mapProblem), 참조 기능 gateway는 code와 상관없이 모든 422를 그렇게 옮긴다(reference-http-gateway.ts). 그래서 기능이 선언한 code나 422 IDEMPOTENT_REQUEST_MISMATCH로 끝난 같은 키 재전송이 결과 불명을 푼다. 함수 주석, CHANGELOG, 런북 6.3-4는 이것들이 결과 불명으로 남는다고 적는다. 기존 테스트는 mapProblem 없이 실패를 만들어 이 길을 타지 않았다(최종 리뷰 FR-01). 고른 방법(메인 세션 결정 "D10 보완 2"): 재전송 거절은 짝 백엔드 표의 code일 때만 결과 불명을 푼다. 지금은 400 VALIDATION_FAILED와 400 IDEMPOTENCY_KEY_INVALID다(REFUSALS_OF_EVERY_ATTEMPT, code와 status 함께). kind 줄을 지우고 kind로 입력 검증을 말하던 주석과 런북 6.3-4를 고쳤다. 기능 code는 상태 규칙일 수 있어 mapProblem이 정한 kind를 믿지 않는다. 400 VALIDATION_FAILED는 필드 목록이 있든 없든 전처럼 푼다. 테스트: 훅의 결과 불명 유지 it.each에 mapProblem 모양(VALIDATION_REJECTED + 선언 code, VALIDATION_REJECTED + 422 IDEMPOTENT_REQUEST_MISMATCH) 두 행을 더했다. 참조 페이지에서 422 재전송이 필드 오류와 다시 저장을 보인다던 테스트를, 결과 불명이 남고 확인이 보이는 테스트로 바꿨다. 리뷰가 요청한 대로 다시 마운트한 폼이 다른 값을 보이는 채 재전송해 422 IDEMPOTENT_REQUEST_MISMATCH를 받으면 결과 불명과 확인 버튼이 남는 테스트를 더했다. 버린 대안: kind 줄을 남기고 기능 선언 code만 빼기(실행기는 code가 선언인지 폼과 훅에 알리지 않는다). 위험·한계: 참조 기능처럼 problem details를 읽는 기능의 422 입력 검증은 재전송 뒤 결과 불명으로 남는다. 출구는 결과 불명 화면의 확인이다. 리뷰 실험 03-R1 X1~X3·X5는 그대로 키가 모두 key-1이어야 한다. CHANGELOG는 다음 커밋이 적는다. 검증: desktop batch에서 확인. node scripts/run-vitest.ts run tests/component/application-mutation-admission.test.tsx tests/features/reference-feature/reference-page.test.tsx tests/component/form-foundation.test.tsx tests/unit/backend-envelope.test.ts, 리뷰 실험 03-R1 패치를 이 커밋에 적용 Refs: 1106/03-01 (final review FR-01)
This commit is contained in:
@@ -260,10 +260,12 @@ diagnostics에만 남고 `api.request.failed`에는 세지 않는다(03-07). 그
|
||||
`IDEMPOTENT_REQUEST_MISMATCH`, 기능이 선언한 code) 보내지 못하면(`NOT_STARTED`) 그
|
||||
시도만 적용되지 않은 것이다. 결과 불명과 key는 그대로다. 폼은 "잠시 뒤 같은 요청으로
|
||||
다시 보내 주세요"와 결과 불명 화면(확인, 다시 보내기)을 보이고 저장을 받지 않는다.
|
||||
401은 다시 로그인 안내가 먼저다. 예외는 같은 요청이 매번 받는 거절이다. 입력 검증
|
||||
(`VALIDATION_REJECTED`, 400 `VALIDATION_FAILED`)과 400 `IDEMPOTENCY_KEY_INVALID`는 첫
|
||||
요청도 거절됐다는 뜻이라 결과 불명을 풀고, 폼은 필드 오류를 보이고 저장을 다시
|
||||
받는다(1106/03-01, `src/contracts/errors.ts` `isRefusedOnEveryAttempt`).
|
||||
401은 다시 로그인 안내가 먼저다. 예외는 같은 요청이 매번 받는 거절이다. 짝 백엔드 표의
|
||||
400 `VALIDATION_FAILED`(필드 목록이 있든 없든)와 400 `IDEMPOTENCY_KEY_INVALID`만 첫
|
||||
요청도 거절됐다는 뜻으로 읽어 결과 불명을 풀고, 폼은 필드 오류를 보이고 저장을 다시
|
||||
받는다. 기능의 `mapProblem`이 정한 kind(`VALIDATION_REJECTED`)는 보지 않는다. 기능
|
||||
code는 상태 규칙일 수 있다(1106/03-01, `src/contracts/errors.ts`
|
||||
`isRefusedOnEveryAttempt`).
|
||||
키가 없는 command(`NEVER`)는 서버가 두 번째 요청을 가려내지 못하므로 재전송 버튼을
|
||||
그리지 않는다(`canResendUnknownEffect`, 0929/03-03). 같은 canonical input의 재저장도
|
||||
보내지 않는다. 훅의 `submit`이 `NOT_STARTED` `DUPLICATE_IN_FLIGHT`(code
|
||||
|
||||
@@ -260,17 +260,18 @@ export const REFUSALS_OF_EVERY_ATTEMPT: Readonly<Record<string, number>> =
|
||||
});
|
||||
|
||||
/**
|
||||
* 1106/03-01 (D10 supplement). A `NOT_APPLIED` refusal the same request gets
|
||||
* on every attempt: input validation (`VALIDATION_REJECTED`) or a row above.
|
||||
* A resend of an unknown request that meets one shows the first attempt was
|
||||
* refused too, so the request is settled. Not one: a refusal before the
|
||||
* idempotency check or one that changes over time (429, 401, 403, 503
|
||||
* RATE_LIMIT_*), a code a feature declared refused before its write (it may
|
||||
* be a rule on changing state), any other code, and `NOT_STARTED`.
|
||||
* 1106/03-01 (D10 supplement and its second fix). A `NOT_APPLIED` refusal
|
||||
* the same request gets on every attempt: a row above, code and status
|
||||
* together. A resend of an unknown request that meets one shows the first
|
||||
* attempt was refused too, so the request is settled. Not one: a refusal
|
||||
* before the idempotency check or one that changes over time (429, 401,
|
||||
* 403, 503 RATE_LIMIT_*), a code a feature declared refused before its
|
||||
* write (it may be a rule on changing state), any other code, and
|
||||
* `NOT_STARTED`. The kind is not read: a feature's `mapProblem` sets it, and
|
||||
* it maps its own codes, or every 422, to `VALIDATION_REJECTED`.
|
||||
*/
|
||||
export function isRefusedOnEveryAttempt(failure: AppFailure): boolean {
|
||||
if (failure.effect !== "NOT_APPLIED") return false;
|
||||
if (failure.kind === "VALIDATION_REJECTED") return true;
|
||||
return (
|
||||
Object.hasOwn(REFUSALS_OF_EVERY_ATTEMPT, failure.code) &&
|
||||
REFUSALS_OF_EVERY_ATTEMPT[failure.code] === failure.httpStatus
|
||||
|
||||
@@ -636,10 +636,10 @@ export function useApplicationMutation<Input, Value>(
|
||||
// that this attempt did not apply; the first may have. The request
|
||||
// stays unknown with its intent, so the next save or resend carries
|
||||
// the same key, never a new one (backend http-contract.md §2). A
|
||||
// refusal every attempt of the request gets (input validation, a key
|
||||
// the server's rule rejects) shows the first was refused too, so the
|
||||
// request is settled and the form can take a corrected save
|
||||
// (isRefusedOnEveryAttempt, D10 supplement).
|
||||
// refusal every attempt of the request gets (the paired backend's 400
|
||||
// VALIDATION_FAILED and IDEMPOTENCY_KEY_INVALID) shows the first was
|
||||
// refused too, so the request is settled and the form can take a
|
||||
// corrected save (isRefusedOnEveryAttempt, D10 supplement).
|
||||
const resendLeavesUnknown = (failure: AppFailure): boolean =>
|
||||
replayed !== undefined &&
|
||||
(!scope || scope.isCurrent()) &&
|
||||
|
||||
@@ -759,6 +759,26 @@ describe("application mutation intent admission", () => {
|
||||
effect: "NOT_APPLIED",
|
||||
}),
|
||||
],
|
||||
// Final review FR-01. The kind is the feature's mapProblem: the
|
||||
// scaffold maps its declared code to a field error, and the reference
|
||||
// gateway maps every 422 to one, whatever the code.
|
||||
[
|
||||
"refused with a declared code the feature maps to a field error",
|
||||
createFailure("VALIDATION_REJECTED", "CREATE_REPLAYED", 0, {
|
||||
code: "WORKLOG_INVALID",
|
||||
httpStatus: 400,
|
||||
effect: "NOT_APPLIED",
|
||||
validationIssues: [{ path: "name", code: "INVALID" }],
|
||||
}),
|
||||
],
|
||||
[
|
||||
"refused with 422 IDEMPOTENT_REQUEST_MISMATCH read as a field error",
|
||||
createFailure("VALIDATION_REJECTED", "CREATE_REPLAYED", 0, {
|
||||
code: "IDEMPOTENT_REQUEST_MISMATCH",
|
||||
httpStatus: 422,
|
||||
effect: "NOT_APPLIED",
|
||||
}),
|
||||
],
|
||||
])("keeps the request unknown with its key when the resend is %s", async (_label, refusal) => {
|
||||
const { hook, intents } = renderKeyedCreate([
|
||||
unknown,
|
||||
|
||||
@@ -415,9 +415,10 @@ describe("reference feature page states", () => {
|
||||
/**
|
||||
* 1106/03-01 (D10 supplement). The form is never held for good after a
|
||||
* same-key resend. A refusal that may change (429) keeps the result
|
||||
* unknown and the confirm and resend actions on screen. A field error the
|
||||
* request gets on every attempt settles it: the field shows the error and
|
||||
* the save is on again.
|
||||
* unknown and the confirm and resend actions on screen. So does a 422
|
||||
* (final review FR-01): this feature's gateway reads every 422 as a field
|
||||
* error whatever its code, and only the paired backend's own table codes
|
||||
* settle a resent request.
|
||||
*/
|
||||
async function resendAnUnknownCreate(resendAnswer: ReferenceResult<ReferenceResourceView>) {
|
||||
const user = userEvent.setup();
|
||||
@@ -467,30 +468,26 @@ describe("reference feature page states", () => {
|
||||
expect(await screen.findByText("저장했습니다.")).toBeVisible();
|
||||
});
|
||||
|
||||
it("shows the field error and saves again when the resend is refused on its input", async () => {
|
||||
const { user, name, createResource } = await resendAnUnknownCreate({
|
||||
it("keeps the confirm on screen when the resend is refused with a 422", async () => {
|
||||
const { user, name } = await resendAnUnknownCreate({
|
||||
ok: false,
|
||||
error: createFailure("VALIDATION_REJECTED", "CREATE_REFERENCE_RESOURCE", 0, {
|
||||
code: "REFERENCE_RESOURCE_REJECTED",
|
||||
effect: "NOT_APPLIED",
|
||||
httpStatus: 422,
|
||||
validationIssues: [{ path: "name", code: "REQUIRED" }],
|
||||
}),
|
||||
});
|
||||
|
||||
await waitFor(() => expect(name).toHaveAttribute("aria-invalid", "true"));
|
||||
expect(screen.queryByText("변경 결과를 확인할 수 없습니다.")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "저장" })).toBeEnabled();
|
||||
await user.clear(name);
|
||||
await user.type(name, "Corrected");
|
||||
await user.click(screen.getByRole("button", { name: "저장" }));
|
||||
expect(
|
||||
await screen.findByText(KO_MESSAGES["form.resendLater"]),
|
||||
).toBeVisible();
|
||||
expect(screen.getByText("변경 결과를 확인할 수 없습니다.")).toBeVisible();
|
||||
expect(name).not.toHaveAttribute("aria-invalid");
|
||||
expect(screen.getByRole("button", { name: "저장" })).toBeDisabled();
|
||||
await user.click(screen.getByRole("button", { name: "변경됨으로 확인" }));
|
||||
|
||||
expect(await screen.findByText("저장했습니다.")).toBeVisible();
|
||||
const keys = createResource.mock.calls.map(([, context]) => context?.intent?.idempotencyKey);
|
||||
expect(keys).toEqual([
|
||||
"reference-page-key-1",
|
||||
"reference-page-key-1",
|
||||
"reference-page-key-2",
|
||||
]);
|
||||
});
|
||||
|
||||
it.each([
|
||||
@@ -729,7 +726,9 @@ describe("reference feature page states", () => {
|
||||
* 1106/08-01. The form the user came back to did not start the save
|
||||
* still running, and holds none of its result (review probe 08-R1).
|
||||
*/
|
||||
async function leaveDuringSaveAndComeBack() {
|
||||
async function leaveDuringSaveAndComeBack(
|
||||
...laterAnswers: readonly ReferenceResult<ReferenceResourceView>[]
|
||||
) {
|
||||
const user = userEvent.setup();
|
||||
let release:
|
||||
| ((result: ReferenceResult<ReferenceResourceView>) => void)
|
||||
@@ -742,6 +741,7 @@ describe("reference feature page states", () => {
|
||||
release = resolve;
|
||||
}),
|
||||
);
|
||||
for (const answer of laterAnswers) createResource.mockResolvedValueOnce(answer);
|
||||
renderReference(
|
||||
inputWith({ createResource }),
|
||||
"/examples/reference-resources/new",
|
||||
@@ -761,12 +761,56 @@ describe("reference feature page states", () => {
|
||||
expect(await screen.findByText("변경 사항을 저장하고 있습니다.")).toBeVisible();
|
||||
return {
|
||||
user,
|
||||
createResource,
|
||||
release(result: ReferenceResult<ReferenceResourceView>) {
|
||||
release?.(result);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// 1106/03-01 (final review FR-01). The remounted form shows other values
|
||||
// than the save it did not start; its resend sends that save, with its
|
||||
// key. A 422 IDEMPOTENT_REQUEST_MISMATCH there says the key already
|
||||
// reached the server, so the first request may have applied: it stays
|
||||
// unknown and the confirm stays on screen.
|
||||
it("keeps a resent request unknown on a remounted form when the server answers 422 IDEMPOTENT_REQUEST_MISMATCH", async () => {
|
||||
const { user, createResource, release } = await leaveDuringSaveAndComeBack({
|
||||
ok: false,
|
||||
error: createFailure("VALIDATION_REJECTED", "CREATE_REFERENCE_RESOURCE", 0, {
|
||||
code: "IDEMPOTENT_REQUEST_MISMATCH",
|
||||
effect: "NOT_APPLIED",
|
||||
httpStatus: 422,
|
||||
}),
|
||||
});
|
||||
release({
|
||||
ok: false,
|
||||
error: createFailure("SERVER_FAILURE", "CREATE_REFERENCE_RESOURCE", 0, {
|
||||
effect: "MAYBE_APPLIED",
|
||||
}),
|
||||
});
|
||||
await screen.findByRole("button", { name: "같은 요청으로 다시 보내기" });
|
||||
await user.type(
|
||||
screen.getByRole("textbox", { name: /새 항목 이름/ }),
|
||||
"Second item",
|
||||
);
|
||||
|
||||
await user.click(
|
||||
screen.getByRole("button", { name: "같은 요청으로 다시 보내기" }),
|
||||
);
|
||||
await waitFor(() => expect(createResource).toHaveBeenCalledTimes(2));
|
||||
|
||||
expect(
|
||||
await screen.findByText(KO_MESSAGES["form.resendLater"]),
|
||||
).toBeVisible();
|
||||
expect(screen.getByText("변경 결과를 확인할 수 없습니다.")).toBeVisible();
|
||||
expect(screen.getByRole("button", { name: "변경됨으로 확인" })).toBeVisible();
|
||||
const [first, second] = createResource.mock.calls;
|
||||
expect(second?.[0]).toEqual(first?.[0]);
|
||||
expect(second?.[1]?.intent?.idempotencyKey).toBe(
|
||||
first?.[1]?.intent?.idempotencyKey,
|
||||
);
|
||||
});
|
||||
|
||||
// 1106/08-01 (A). Confirming that save from the remounted form used to
|
||||
// show nothing and drop focus to the body: the form had no submitted
|
||||
// values to settle.
|
||||
|
||||
Reference in New Issue
Block a user