From 7420e29af0c1d314351ed89e358b27ef3709e6c7 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Tue, 29 Sep 2026 17:45:58 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=B3=B8=EB=AC=B8=EC=9D=B4=202KB?= =?UTF-8?q?=EB=A5=BC=20=EB=84=98=EB=8A=94=20=EB=AC=B8=EC=84=9C=EA=B0=80=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EB=90=98=EC=A7=80=20=EC=95=8A=EB=8D=98=20?= =?UTF-8?q?=EA=B2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 저장을 눌러도 요청이 나가지 않고 「저장하지 못했습니다.」만 떴다. 갓 만든 문서는 저장되고 글을 쓴 문서만 안 되어서 원인을 짚기 어려웠다. 명령의 신원을 만들 때 플랫폼은 `identity` 훅이 없으면 입력 전체를 쓴다. 그 신원은 `canonicalize` 를 지나고 거기에는 문자열 하나당 2KB 한도가 있다 (`contracts/query-keys.ts` 의 `maxStringBytes`). 본문이 그 한도를 넘는 순간 신원을 만들다 던지고, 명령은 `NOT_STARTED` 로 끝난다 — 전송 전이라 네트워크에도 콘솔에도 아무것도 남지 않는다. 실제로 걸린 문서의 본문은 11,222 바이트였다. 명령을 가리키는 이름은 「어느 문서에 대한 무슨 명령인가」이지 본문이 아니다. 문서 id 만 넘긴다. 같은 문서의 저장을 한 번에 하나만 돌리는 것이 `REJECT_WHILE_ACTIVE` 가 원하는 바이므로 이것으로 충분하다. 검사는 두 쪽을 같이 본다: 입력을 그대로 쓰면 실제로 던진다는 것과, 넘기는 신원은 본문 크기와 무관하다는 것. 앞의 절반이 없으면 한도가 사라져도 검사가 통과한다. (cherry picked from commit 27f2182c7da2d6c5afbcf13ae0cf4ceaf6d9638c) --- .../studio/studio-document-server-state.ts | 19 ++++++++++- .../tech-log/studio-command-identity.test.ts | 33 +++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/features/tech-log/studio-command-identity.test.ts diff --git a/src/features/tech-log/presentation/studio/studio-document-server-state.ts b/src/features/tech-log/presentation/studio/studio-document-server-state.ts index e21ef8c..95afe4d 100644 --- a/src/features/tech-log/presentation/studio/studio-document-server-state.ts +++ b/src/features/tech-log/presentation/studio/studio-document-server-state.ts @@ -221,7 +221,23 @@ function publishSnapshotQueryDefinition( }); } -function commandMutation( +/* + 명령을 가리키는 이름은 「어느 문서에 대한 무슨 명령인가」다. 본문이 아니다. + + 이 훅을 주지 않으면 플랫폼은 입력 전체를 명령의 신원으로 삼는데, 그 신원은 + `canonicalize` 를 지나고 거기 문자열 하나당 2KB 한도가 있다(`contracts/query-keys.ts`). + 본문이 2KB를 넘는 순간 신원을 만들다 던지고, 명령은 `NOT_STARTED` 로 끝난다 — 요청이 + 나가지 않으니 화면에는 이유 없는 「저장하지 못했습니다.」만 남았다. 갓 만든 문서는 본문이 + 비어 있어 통과하고 글을 쓴 문서만 저장이 안 되는, 원인을 짚기 어려운 모양이 된다. + + 같은 문서의 저장을 한 번에 하나만 돌리는 것이 `REJECT_WHILE_ACTIVE` 가 원하는 바이므로 + 문서 id 만으로 충분하다. +*/ +export function STUDIO_COMMAND_IDENTITY({ documentId }: DocumentMutationInput) { + return Object.freeze({ documentId }); +} + +function commandMutation, Value>( scope: ReturnType, definitionId: string, operationId: string, @@ -239,6 +255,7 @@ function commandMutation( owner: "tech-log", duplicatePolicy: "REJECT_WHILE_ACTIVE", scope, + identity: STUDIO_COMMAND_IDENTITY, invalidate: Object.freeze([]), execute: (input, { signal, intent }) => studioMutationResult(operationId, () => diff --git a/tests/features/tech-log/studio-command-identity.test.ts b/tests/features/tech-log/studio-command-identity.test.ts new file mode 100644 index 0000000..2581544 --- /dev/null +++ b/tests/features/tech-log/studio-command-identity.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from "vitest"; + +import { canonicalize } from "../../../src/contracts/query-keys.ts"; +import { STUDIO_COMMAND_IDENTITY } from "../../../src/features/tech-log/presentation/studio/studio-document-server-state.ts"; + +/* + 명령의 신원은 `canonicalize` 를 지나고, 거기에는 문자열 하나당 2KB 한도가 있다. 입력을 + 그대로 신원으로 쓰면 본문이 2KB를 넘는 문서에서 신원을 만들다 던지고 — 요청은 나가지 않고 + 화면에는 이유 없는 「저장하지 못했습니다.」만 남는다. 갓 만든 문서는 본문이 비어 통과하므로 + 글을 쓴 문서만 저장이 안 되는, 원인을 짚기 어려운 모양이 된다. + + 그래서 두 가지를 같이 본다: 본문을 통째로 넣으면 실제로 던진다는 것과, 우리가 넘기는 + 신원은 던지지 않는다는 것. 앞의 절반이 없으면 이 검사는 한도가 사라져도 통과한다. +*/ +const BODY = "가".repeat(4_000); // 2KB 한도를 넘기는 실제 본문 크기대 +const INPUT = Object.freeze({ + documentId: "8a9ca3d4-7d6e-4f38-862d-296b2640d288", + command: Object.freeze({ + expectedVersion: 2, + document: Object.freeze({ title: "제목", bodyMarkdown: BODY }), + }), +}); + +describe("스튜디오 문서 명령의 신원", () => { + it("입력을 그대로 쓰면 본문 크기에 걸려 명령이 시작조차 못 한다", () => { + expect(() => canonicalize(INPUT)).toThrow(/byte budget/u); + }); + + it("우리가 넘기는 신원은 문서를 가리킬 뿐이라 본문 크기와 무관하다", () => { + expect(() => canonicalize(STUDIO_COMMAND_IDENTITY(INPUT))).not.toThrow(); + expect(STUDIO_COMMAND_IDENTITY(INPUT)).toEqual({ documentId: INPUT.documentId }); + }); +});