Repository navigation
feat: 어법 노트와 분석 구간·계층 계약 정의 #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
333 changes: 333 additions & 0 deletions
333
docs/design/echo/grammar-practice-20261005/design-spec.md
Large diffs are not rendered by default.
Oops, something went wrong.
41 changes: 41 additions & 0 deletions
41
docs/design/echo/grammar-practice-20261005/implementation-plan.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # 어법 연습 구현 순서 | ||
|
|
||
| 2026-10-05 사용자 승인. 각 이슈별 브랜치·PR을 만들며 사용자가 직접 검토·병합한다. 원격 DB 마이그레이션 적용, 배포, 유료 AI 시험 호출은 이 작업에 포함하지 않는다. | ||
|
|
||
| ## 변경 계약 | ||
|
|
||
| - 문장 아래 분석 풀이, 사용자 구간 경계·계층 편집. | ||
| - 영어 문장·핵심 어법만 필수 입력. AI 제목·태그. 사전 체크 → 분석 → 저장 → 예문 생성. | ||
| - 목록 페이지네이션·스켈레톤. 실패 재시도. 저장 문장 음성 재생. | ||
| - 수정안의 암기/시험, 새 문맥 작문과 종료 후 답안별 피드백. | ||
| - 재연습 순서 변경, 완료 세션 단위 기록, 누적 횟수·날짜. | ||
| - Interface → 컴포넌트 → Storybook/유닛 통과 → 페이지 연결. Tailwind/CVA, FSD/Next.js, 작은 상태 구독. | ||
|
|
||
| ## 이슈와 의존성 | ||
|
|
||
| | 이슈 | 변경 단위 | 선행 | | ||
| | ------------------------------------------------- | -------------------------------------------- | ---------------------------------------- | | ||
| | [#149](https://github.com/Yelihi/echo/issues/149) | 어법 노트·분석 구간 계약과 검증 | main | | ||
| | [#150](https://github.com/Yelihi/echo/issues/150) | 분석 구간 경계·계층 편집 기능 | #149 | | ||
| | [#151](https://github.com/Yelihi/echo/issues/151) | 사전 체크·문장 분석 AI 서비스 | #149 | | ||
| | [#152](https://github.com/Yelihi/echo/issues/152) | 어법 노트 저장·조회 계약과 소유권 보호 | #149 | | ||
| | [#153](https://github.com/Yelihi/echo/issues/153) | 두 필수 입력·사전 체크·분석 검토 등록 화면 | #150, #151, #152 | | ||
| | [#154](https://github.com/Yelihi/echo/issues/154) | 예문 생성·검토·선택 저장과 다시 생성 | #151, #152 | | ||
| | [#155](https://github.com/Yelihi/echo/issues/155) | 어법 목록 페이지네이션·검색·스켈레톤 | #152 | | ||
| | [#156](https://github.com/Yelihi/echo/issues/156) | 저장 기준 문장·채택 예문 TTS 준비와 재생 | #152 | | ||
| | [#157](https://github.com/Yelihi/echo/issues/157) | 연습 세션·무작위 순서·완료 기록 계약 | #149, #152 | | ||
| | [#158](https://github.com/Yelihi/echo/issues/158) | 부분 완성·전체 회상 암기 UI | #157 | | ||
| | [#159](https://github.com/Yelihi/echo/issues/159) | 기존 예문·새 문맥 작문 시험과 종료 후 피드백 | #157, #151 | | ||
| | [#160](https://github.com/Yelihi/echo/issues/160) | 노트별 누적 횟수·연습 날짜·기록 상세 | #157 | | ||
| | [#161](https://github.com/Yelihi/echo/issues/161) | 홈·상세·연습·결과 라우트 연결과 회귀 | #153, #154, #155, #156, #158, #159, #160 | | ||
|
|
||
| ## 검증 | ||
|
|
||
| `npm run typecheck`, 변경 범위 ESLint, 해당 Jest 테스트. UI는 독립 Storybook 테스트 후 연결. 마지막 통합에서 전체 Jest/Storybook·빌드·실제 화면을 검증한다. 검증하지 않은 외부 AI/원격 DB는 통과로 표기하지 않는다. | ||
|
|
||
| ## 기준선 | ||
|
|
||
| - 시작 브랜치 HEAD 644cca7: TypeScript 통과, Jest 120개 suite / 406개 테스트 통과. | ||
| - 최신 origin/main 9149f9f는 PR #144 병합 커밋. 별도 worktree에서 구현. | ||
| - 첫 이슈 #149: 새 도메인 테스트 24개 통과. 화면·DB·외부 API 변경 없음. | ||
| - FS MCP가 노출되지 않아 로컬 문서와 GitHub issue/PR로 작업 기록을 유지한다. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| export type { GrammarSource, GrammarMetadata, TextRange, SyntaxRole } from "./models/value-objects"; | ||
| export type { | ||
| SentenceChunk, | ||
| SyntaxAnnotation, | ||
| ConstructionAnnotation, | ||
| SentenceAnalysis, | ||
| GrammarExample, | ||
| GrammarNoteContent, | ||
| GrammarNote, | ||
| PrecheckResult, | ||
| } from "./models/entity"; | ||
| export { | ||
| grammarSourceSchema, | ||
| grammarMetadataSchema, | ||
| sentenceAnalysisSchema, | ||
| grammarExampleSchema, | ||
| grammarNoteContentSchema, | ||
| precheckResultSchema, | ||
| } from "./models/schema"; | ||
| export { isValidTextRange, getAnalysisIssues } from "./models/validation"; |
219 changes: 219 additions & 0 deletions
219
src/entities/grammar-note/models/__tests__/schema.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,219 @@ | ||
| import { describe, expect, it } from "@jest/globals"; | ||
| import type { SentenceAnalysis } from "../entity"; | ||
| import { | ||
| grammarNoteContentSchema, | ||
| grammarSourceSchema, | ||
| precheckResultSchema, | ||
| sentenceAnalysisSchema, | ||
| } from "../schema"; | ||
| import { isValidTextRange } from "../validation"; | ||
|
|
||
| function createAnalysis(): SentenceAnalysis { | ||
| return { | ||
| sourceText: "She is not a teacher but a doctor.", | ||
| sourceRevision: 0, | ||
| chunks: [ | ||
| { id: "chunk-1", range: { start: 0, end: 4 }, literalMeaning: "그녀는", explanation: "" }, | ||
| { id: "chunk-2", range: { start: 4, end: 7 }, literalMeaning: "이다", explanation: "" }, | ||
| { | ||
| id: "chunk-3", | ||
| range: { start: 7, end: 34 }, | ||
| literalMeaning: "교사가 아니라 의사", | ||
| explanation: "", | ||
| }, | ||
| ], | ||
| syntax: [ | ||
| { | ||
| id: "clause", | ||
| ranges: [{ start: 0, end: 34 }], | ||
| parentId: null, | ||
| role: "other", | ||
| label: "절", | ||
| explanation: "", | ||
| }, | ||
| { | ||
| id: "subject", | ||
| ranges: [{ start: 0, end: 3 }], | ||
| parentId: "clause", | ||
| role: "subject", | ||
| label: "주어", | ||
| explanation: "", | ||
| }, | ||
| ], | ||
| constructions: [ | ||
| { | ||
| id: "contrast", | ||
| name: "not A but B", | ||
| ranges: [ | ||
| { start: 7, end: 10 }, | ||
| { start: 21, end: 24 }, | ||
| ], | ||
| meaning: "A가 아니라 B", | ||
| explanation: "", | ||
| }, | ||
| ], | ||
| naturalTranslation: "그녀는 교사가 아니라 의사입니다.", | ||
| reviewStatus: "needs-review", | ||
| }; | ||
| } | ||
|
|
||
| describe("grammar source", () => { | ||
| it.each(["", " ", "\n"])("rejects blank required input %j", (empty) => { | ||
| expect( | ||
| grammarSourceSchema.safeParse({ sentence: empty, learningNote: "대조", revision: 0 }).success, | ||
| ).toBe(false); | ||
| expect( | ||
| grammarSourceSchema.safeParse({ | ||
| sentence: "She is a doctor.", | ||
| learningNote: empty, | ||
| revision: 0, | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| it("preserves source whitespace and rejects user-supplied metadata", () => { | ||
| const input = { sentence: " She is a doctor. ", learningNote: "보어", revision: 0 }; | ||
| expect(grammarSourceSchema.parse(input).sentence).toBe(input.sentence); | ||
| expect(grammarSourceSchema.safeParse({ ...input, title: "내 제목", tags: [] }).success).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe("sentence analysis invariants", () => { | ||
| it("accepts nested syntax and a discontinuous construction over unchanged source", () => { | ||
| const analysis = sentenceAnalysisSchema.parse(createAnalysis()); | ||
| expect( | ||
| analysis.chunks | ||
| .map(({ range }) => analysis.sourceText.slice(range.start, range.end)) | ||
| .join(""), | ||
| ).toBe(analysis.sourceText); | ||
| }); | ||
| it.each([ | ||
| { start: -1, end: 3 }, | ||
| { start: 0, end: 35 }, | ||
| { start: 2, end: 2 }, | ||
| { start: 3, end: 2 }, | ||
| { start: 0.5, end: 3 }, | ||
| ])("rejects invalid range %j", (range) => { | ||
| const analysis = createAnalysis(); | ||
| expect( | ||
| sentenceAnalysisSchema.safeParse({ ...analysis, chunks: [{ ...analysis.chunks[0], range }] }) | ||
| .success, | ||
| ).toBe(false); | ||
| }); | ||
| it("rejects a surrogate split but allows a whole Unicode character", () => { | ||
| expect(isValidTextRange("A😀B", { start: 1, end: 2 })).toBe(false); | ||
| expect(isValidTextRange("A😀B", { start: 1, end: 3 })).toBe(true); | ||
| }); | ||
| it.each([3, 5])("rejects chunk gaps or overlap at %s", (start) => { | ||
| const a = createAnalysis(); | ||
| expect( | ||
| sentenceAnalysisSchema.safeParse({ | ||
| ...a, | ||
| chunks: [a.chunks[0], { ...a.chunks[1], range: { start, end: 7 } }, a.chunks[2]], | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| it("rejects duplicate IDs across annotation kinds", () => { | ||
| const a = createAnalysis(); | ||
| expect( | ||
| sentenceAnalysisSchema.safeParse({ | ||
| ...a, | ||
| constructions: [{ ...a.constructions[0], id: "subject" }], | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| it.each(["missing", "subject"])("rejects missing or self parent %s", (parentId) => { | ||
| const a = createAnalysis(); | ||
| expect( | ||
| sentenceAnalysisSchema.safeParse({ | ||
| ...a, | ||
| syntax: [a.syntax[0], { ...a.syntax[1], parentId }], | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| it("rejects multi-node cycles even with equal contained ranges", () => { | ||
| const a = createAnalysis(); | ||
| expect( | ||
| sentenceAnalysisSchema.safeParse({ | ||
| ...a, | ||
| syntax: [ | ||
| { ...a.syntax[0], parentId: "subject" }, | ||
| { ...a.syntax[1], ranges: a.syntax[0].ranges }, | ||
| ], | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| it("rejects a child outside its parent", () => { | ||
| const a = createAnalysis(); | ||
| expect( | ||
| sentenceAnalysisSchema.safeParse({ | ||
| ...a, | ||
| syntax: [{ ...a.syntax[0], ranges: [{ start: 4, end: 34 }] }, a.syntax[1]], | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| it("rejects overlapping ranges within one annotation", () => { | ||
| const a = createAnalysis(); | ||
| expect( | ||
| sentenceAnalysisSchema.safeParse({ | ||
| ...a, | ||
| constructions: [ | ||
| { | ||
| ...a.constructions[0], | ||
| ranges: [ | ||
| { start: 7, end: 24 }, | ||
| { start: 21, end: 24 }, | ||
| ], | ||
| }, | ||
| ], | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("note and precheck contracts", () => { | ||
| function content() { | ||
| const analysis = createAnalysis(); | ||
| return { | ||
| source: { sentence: analysis.sourceText, learningNote: "not A but B", revision: 0 }, | ||
| metadata: { | ||
| source: "ai", | ||
| title: "not A but B", | ||
| tags: ["대조"], | ||
| grammarKey: null, | ||
| sourceRevision: 0, | ||
| }, | ||
| analysis, | ||
| examples: [], | ||
| }; | ||
| } | ||
| it("accepts a note before examples exist", () => { | ||
| expect(grammarNoteContentSchema.safeParse(content()).success).toBe(true); | ||
| }); | ||
| it("rejects silent source correction", () => { | ||
| const note = content(); | ||
| expect( | ||
| grammarNoteContentSchema.safeParse({ | ||
| ...note, | ||
| source: { ...note.source, sentence: "He is a doctor." }, | ||
| }).success, | ||
| ).toBe(false); | ||
| }); | ||
| it.each(["analysis", "metadata"] as const)("rejects stale %s", (key) => { | ||
| const note = content(); | ||
| expect( | ||
| grammarNoteContentSchema.safeParse({ ...note, [key]: { ...note[key], sourceRevision: 1 } }) | ||
| .success, | ||
| ).toBe(false); | ||
| }); | ||
| it("requires explanations for a precheck that cannot pass", () => { | ||
| expect( | ||
| precheckResultSchema.safeParse({ status: "uncertain", sourceRevision: 0, issues: [] }) | ||
| .success, | ||
| ).toBe(false); | ||
| expect(precheckResultSchema.safeParse({ status: "passed", sourceRevision: 0 }).success).toBe( | ||
| true, | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import type { GrammarSource, GrammarMetadata, TextRange, SyntaxRole } from "./value-objects"; | ||
|
|
||
| export interface SentenceChunk { | ||
| readonly id: string; | ||
| readonly range: TextRange; | ||
| readonly literalMeaning: string; | ||
| readonly explanation: string; | ||
| } | ||
|
|
||
| export interface SyntaxAnnotation { | ||
| readonly id: string; | ||
| readonly ranges: readonly TextRange[]; | ||
| readonly parentId: string | null; | ||
| readonly role: SyntaxRole; | ||
| readonly label: string; | ||
| readonly explanation: string; | ||
| } | ||
|
|
||
| export interface ConstructionAnnotation { | ||
| readonly id: string; | ||
| readonly name: string; | ||
| readonly ranges: readonly TextRange[]; | ||
| readonly meaning: string; | ||
| readonly explanation: string; | ||
| } | ||
|
|
||
| export interface SentenceAnalysis { | ||
| readonly sourceText: string; | ||
| readonly sourceRevision: number; | ||
| readonly chunks: readonly SentenceChunk[]; | ||
| readonly syntax: readonly SyntaxAnnotation[]; | ||
| readonly constructions: readonly ConstructionAnnotation[]; | ||
| readonly naturalTranslation: string; | ||
| readonly reviewStatus: "needs-review" | "reviewed"; | ||
| } | ||
|
|
||
| export interface GrammarExample { | ||
| readonly id: string; | ||
| readonly sentence: string; | ||
| readonly translation: string; | ||
| readonly targetExplanation: string; | ||
| readonly reviewStatus: "needs-review" | "reviewed"; | ||
| } | ||
|
|
||
| export interface GrammarNoteContent { | ||
| readonly source: GrammarSource; | ||
| readonly metadata: GrammarMetadata; | ||
| readonly analysis: SentenceAnalysis; | ||
| readonly examples: readonly GrammarExample[]; | ||
| } | ||
|
|
||
| export interface GrammarNote extends GrammarNoteContent { | ||
| readonly id: string; | ||
| readonly ownerId: string; | ||
| readonly version: number; | ||
| readonly createdAt: string; | ||
| readonly updatedAt: string; | ||
| } | ||
|
|
||
| export type PrecheckResult = | ||
| | { readonly status: "passed"; readonly sourceRevision: number } | ||
| | { | ||
| readonly status: "needs-revision" | "uncertain"; | ||
| readonly sourceRevision: number; | ||
| readonly issues: readonly { | ||
| readonly field: "sentence" | "learningNote"; | ||
| readonly message: string; | ||
| readonly suggestion: string | null; | ||
| }[]; | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.