-
Notifications
You must be signed in to change notification settings - Fork 0
Canonical Spec 변경에 따른 version bump 와 reason 계산로직 구현 #26
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
5 commits
Select commit
Hold shift + click to select a range
c8d3b95
rename: 타입관련 파일 PascalCase 로 변경
toothlessdev 9022c8b
refactor: 타입 파일 PascalCase 로 변경
toothlessdev 24d557d
feature: ContentAddressableStorage 인터페이스 추가
toothlessdev 18eaecd
feature: canonical Spec 변경에 따른 version bump 와 reason 을 계산로직 구현
toothlessdev d6126e6
test: reason 에 대한 테스트케이스 추가
toothlessdev 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
191 changes: 191 additions & 0 deletions
191
packages/patchlogr-core/src/diff/__tests__/detectVersionBump.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,191 @@ | ||
| import { describe, test, expect } from "vitest"; | ||
| import { detectVersionBump } from "../detectVersionBump.js"; | ||
| import type { SpecChangeSet } from "../diffChangeSet.js"; | ||
|
|
||
| describe("detectVersionBump", () => { | ||
| describe("none", () => { | ||
| test("변경사항이 없으면 none을 반환한다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "abc", | ||
| changes: [], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.recommendedBump).toBe("none"); | ||
| expect(result.isBreaking).toBe(false); | ||
| expect(result.reasons).toHaveLength(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe("major (breaking changes)", () => { | ||
| test("removed 타입은 major를 반환한다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "def", | ||
| changes: [ | ||
| { | ||
| type: "removed", | ||
| path: [], | ||
| key: "GET /users", | ||
| baseHash: "hash1", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.recommendedBump).toBe("major"); | ||
| expect(result.isBreaking).toBe(true); | ||
| expect(result.reasons).toHaveLength(1); | ||
| }); | ||
|
|
||
| test("type_changed는 major를 반환한다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "def", | ||
| changes: [ | ||
| { | ||
| type: "type_changed", | ||
| path: [], | ||
| key: "GET /users", | ||
| baseHash: "hash1", | ||
| headHash: "hash2", | ||
| baseNodeType: "leaf", | ||
| headNodeType: "node", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.recommendedBump).toBe("major"); | ||
| expect(result.isBreaking).toBe(true); | ||
| expect(result.reasons).toHaveLength(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe("minor", () => { | ||
| test("added 타입은 minor를 반환한다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "def", | ||
| changes: [ | ||
| { | ||
| type: "added", | ||
| path: [], | ||
| key: "POST /users", | ||
| headHash: "hash1", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.recommendedBump).toBe("minor"); | ||
| expect(result.isBreaking).toBe(false); | ||
| expect(result.reasons).toHaveLength(1); | ||
| }); | ||
|
|
||
| test("modified 타입은 minor를 반환한다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "def", | ||
| changes: [ | ||
| { | ||
| type: "modified", | ||
| path: [], | ||
| key: "GET /users", | ||
| baseHash: "hash1", | ||
| headHash: "hash2", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.recommendedBump).toBe("minor"); | ||
| expect(result.isBreaking).toBe(false); | ||
toothlessdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect(result.reasons).toHaveLength(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe("patch", () => { | ||
| // TODO: Operation 내부 변경 분석 기능 추가 시 patch 케이스 개선 필요 | ||
| // (현재는 알 수 없는 ChangeType만 patch로 분류됨) | ||
| test("알 수 없는 타입은 patch를 반환한다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "def", | ||
| changes: [ | ||
| { | ||
| type: "unknown" as any, | ||
| path: [], | ||
| key: "GET /users", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.recommendedBump).toBe("patch"); | ||
| expect(result.isBreaking).toBe(false); | ||
| expect(result.reasons).toHaveLength(1); | ||
| }); | ||
| }); | ||
|
|
||
| describe("version bump 우선순위", () => { | ||
| test("major > minor: major가 있으면 major를 반환한다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "def", | ||
| changes: [ | ||
| { | ||
| type: "added", | ||
| path: [], | ||
| key: "POST /users", | ||
| headHash: "hash1", | ||
| }, | ||
| { | ||
| type: "removed", | ||
| path: [], | ||
| key: "DELETE /users", | ||
| baseHash: "hash2", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.recommendedBump).toBe("major"); | ||
| expect(result.isBreaking).toBe(true); | ||
| expect(result.reasons).toHaveLength(2); | ||
| }); | ||
|
|
||
| test("reasons에는 해당 레벨의 모든 변경 이유가 포함된다", () => { | ||
| const changeSet: SpecChangeSet = { | ||
| baseHash: "abc", | ||
| headHash: "def", | ||
| changes: [ | ||
| { | ||
| type: "removed", | ||
| path: [], | ||
| key: "DELETE /users", | ||
| baseHash: "hash1", | ||
| }, | ||
| { | ||
| type: "removed", | ||
| path: [], | ||
| key: "DELETE /posts", | ||
| baseHash: "hash2", | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const result = detectVersionBump(changeSet); | ||
|
|
||
| expect(result.reasons).toHaveLength(2); | ||
| }); | ||
| }); | ||
| }); | ||
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,48 @@ | ||
| import type { VersionBump } from "./detectVersionBump"; | ||
| import type { SpecChange } from "./diffChangeSet"; | ||
|
|
||
| export type ChangeClassification = { | ||
| level: VersionBump; | ||
| reason: string; | ||
| }; | ||
|
|
||
| export function classifyChange<K>(change: SpecChange<K>): ChangeClassification { | ||
| const pathStr = change.path.map(String).join(" > "); | ||
| const keyStr = String(change.key); | ||
|
|
||
| switch (change.type) { | ||
| case "removed": | ||
| // operation 삭제, 필드 삭제 등 | ||
| return { | ||
| level: "major", | ||
| reason: `Removed: ${pathStr} > ${keyStr}`, | ||
| }; | ||
|
|
||
| case "type_changed": | ||
| // node, leaf 타입 변경 | ||
| return { | ||
| level: "major", | ||
| reason: `Type changed at: ${pathStr} > ${keyStr} (${change.baseNodeType} → ${change.headNodeType})`, | ||
| }; | ||
|
|
||
| case "added": | ||
| // 새로운 operation, 필드 추가 | ||
| return { | ||
| level: "minor", | ||
| reason: `Added: ${pathStr} > ${keyStr}`, | ||
| }; | ||
|
|
||
| case "modified": | ||
| // TODO: required 추가 => major, description 변경 => patch ... | ||
| return { | ||
| level: "minor", | ||
| reason: `Modified: ${pathStr} > ${keyStr}`, | ||
| }; | ||
|
|
||
| default: | ||
| return { | ||
| level: "patch", | ||
| reason: `Unknown change at: ${pathStr} > ${keyStr}`, | ||
| }; | ||
| } | ||
| } | ||
toothlessdev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,44 @@ | ||
| import { classifyChange } from "./classifyChange.js"; | ||
| import type { SpecChangeSet } from "./diffChangeSet.js"; | ||
|
|
||
| export type VersionBump = "major" | "minor" | "patch" | "none"; | ||
|
|
||
| export type VersionBumpResult = { | ||
| recommendedBump: VersionBump; | ||
| isBreaking: boolean; | ||
| reasons: string[]; | ||
| }; | ||
|
|
||
| export function detectVersionBump<K>( | ||
| changeSet: SpecChangeSet<K>, | ||
| ): VersionBumpResult { | ||
| if (changeSet.changes.length === 0) { | ||
| return { | ||
| recommendedBump: "none", | ||
| isBreaking: false, | ||
| reasons: [], | ||
| }; | ||
| } | ||
|
|
||
| const reasons: string[] = []; | ||
| let maxBump: VersionBump = "none"; | ||
|
|
||
| for (const change of changeSet.changes) { | ||
| const bump = classifyChange(change); | ||
|
|
||
| if (bump.level === "major") { | ||
| maxBump = "major"; | ||
| } else if (bump.level === "minor" && maxBump !== "major") { | ||
| maxBump = "minor"; | ||
| } else if (bump.level === "patch" && maxBump === "none") { | ||
| maxBump = "patch"; | ||
| } | ||
| reasons.push(bump.reason); | ||
| } | ||
|
|
||
| return { | ||
| recommendedBump: maxBump, | ||
| isBreaking: maxBump === "major", | ||
| reasons, | ||
| }; | ||
| } |
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
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
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
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
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...re/src/partition/types/partitionedSpec.ts → ...re/src/partition/types/PartitionedSpec.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
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
10 changes: 10 additions & 0 deletions
10
packages/patchlogr-core/src/storage/ContentAddressableStorage.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,10 @@ | ||
| import type { HashObject } from "../partition/types/HashObject"; | ||
|
|
||
| export interface ContentAddressableStorage<T = string> { | ||
| get(hash: string): Promise<T | null>; | ||
|
|
||
| has(hash: string): Promise<boolean>; | ||
|
|
||
| put(entry: HashObject<T>): Promise<void>; | ||
| putMany(entries: HashObject<T>[]): Promise<void>; | ||
| } |
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.