-
Notifications
You must be signed in to change notification settings - Fork 1
[Core/Budget] Money 정밀도·통화 불변식과 최종 반올림 교정 #50
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
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0a0ea3d
fix(core): enforce cost amount and currency invariants
Rigu1 67673b5
fix(core): normalize cost equality across amount scales
Rigu1 8690d45
test(core): clarify cost calculator test descriptions
Rigu1 b9efa6f
fix(core): calculate costs with decimal shift
Rigu1 e29fb61
feat(core): add explicit cost boundary rounding policy
Rigu1 3cbccd1
feat(budget): migrate budget amounts to Cost
Rigu1 6713330
fix(budget): reject currency mismatches during evaluation
Rigu1 4cffe62
chore(budget): remove unused BigDecimal imports
Rigu1 3ffaa81
test(core): cover boundary rounding after small cost accumulation
Rigu1 cedcf59
docs: clarify cost precision and boundary rounding
Rigu1 7b74887
docs(core): update Cost record parameter docs
Rigu1 0f4c515
test(core): verify Cost add rejects null operand
Rigu1 5cd6d85
docs(budget): document currency mismatch decision criteria
Rigu1 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
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
13 changes: 6 additions & 7 deletions
13
token-ledger-budget/src/main/java/io/tokenledger/budget/BudgetDecision.java
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 |
|---|---|---|
| @@ -1,18 +1,17 @@ | ||
| package io.tokenledger.budget; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import io.tokenledger.core.domain.Cost; | ||
|
|
||
|
|
||
| /** | ||
| * 예산 평가 결과를 나타내는 값 객체입니다. | ||
| * <p> | ||
| * 호출 가능 여부와 | ||
| * 판단에 필요한 최소한의 정보를 담습니다. | ||
| * 호출 가능 여부와 판단에 필요한 최소한의 정보를 담습니다. | ||
| */ | ||
|
|
||
| public record BudgetDecision( | ||
| BudgetState state, | ||
| String reason, | ||
| BigDecimal currentUsage, | ||
| BigDecimal limit | ||
| BudgetState state, | ||
| String reason, | ||
| Cost currentUsage, | ||
| Cost limit | ||
| ) {} |
28 changes: 13 additions & 15 deletions
28
token-ledger-budget/src/main/java/io/tokenledger/budget/BudgetEvaluator.java
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 |
|---|---|---|
| @@ -1,28 +1,26 @@ | ||
| package io.tokenledger.budget; | ||
|
|
||
| import java.math.BigDecimal; | ||
| import io.tokenledger.core.domain.Cost; | ||
| import java.util.Map; | ||
|
|
||
|
|
||
| /** | ||
| * AI 호출 전 예산 초과 여부를 판단하는 인터페이스입니다. | ||
| * <p> | ||
| * 구현체는 현재까지 누적된 비용과 | ||
| * 이번 호출로 발생할 비용을 기준으로 | ||
| * 호출을 허용하거나 차단하는 역할을 합니다. | ||
| * 구현체는 현재까지 누적된 비용과 이번 호출로 발생할 비용을 기준으로 호출을 허용하거나 차단하는 역할을 합니다. | ||
| */ | ||
| public interface BudgetEvaluator { | ||
|
|
||
| /** | ||
| * 단순히 현재의 누적 비용이 예산 한도를 초과했는지만 판단합니다. (부수 효과 없음) | ||
| */ | ||
| BudgetDecision evaluate(Map<String, String> tags); | ||
| /** | ||
| * 단순히 현재의 누적 비용이 예산 한도를 초과했는지만 판단합니다. (부수 효과 없음) | ||
| */ | ||
| BudgetDecision evaluate(Map<String, String> tags); | ||
|
|
||
| /** | ||
| * 이번 호출로 발생할 예상 비용을 포함하여 예산 초과 여부를 판단합니다. (부수 효과 없음) | ||
| */ | ||
| BudgetDecision evaluate( | ||
| Map<String, String> tags, | ||
| BigDecimal costAmount | ||
| ); | ||
| /** | ||
| * 이번 호출로 발생할 예상 비용을 포함하여 예산 초과 여부를 판단합니다. (부수 효과 없음) | ||
| */ | ||
| BudgetDecision evaluate( | ||
| Map<String, String> tags, | ||
| Cost cost | ||
| ); | ||
| } |
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 |
|---|---|---|
|
|
@@ -10,5 +10,6 @@ | |
| public enum BudgetState { | ||
| ALLOW, | ||
| WARN, | ||
| BLOCK | ||
| BLOCK, | ||
| CURRENCY_MISMATCH | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: tokenpliot/tokenpilot
Length of output: 8069
🏁 Script executed:
Repository: tokenpliot/tokenpilot
Length of output: 5166
🏁 Script executed:
Repository: tokenpliot/tokenpilot
Length of output: 7744
InMemoryBudgetStateStore#getAccumulatedCost/addCost(28-35)에서 통화도 상태 키에 포함하세요
key(tags)가tenant_id만 써서 같은 태그에 서로 다른 통화가 섞일 수 있습니다.getAccumulatedCost(tags, currency)가currency를 무시해 요청한 통화와 다른Cost를 그대로 반환할 수 있습니다.DefaultBudgetEvaluator.evaluate()의accumulated.add(cost)가Cost.add()의 통화 검증에서 예외를 던질 수 있습니다.addCost()만 검증해도 읽기 경로가 남으니, 통화를 키에 포함하거나 조회/추가 모두에서 동일하게 차단하세요.🤖 Prompt for AI Agents