refactor(import): 破壊的変更の判定をサービス層に出す - #40
Merged
Merged
Conversation
ガードを CLI に置いたため、インポートのサービス関数を直接呼ぶ利用者には 効いていなかった(compeito-aws の Admin API がそうで、`router.py` が自分で commit する)。判定に必要なカウンタはレポートに載っているので、あちら側で 同じ判定を組める。ただし「何を破壊的と数えるか」を二重に実装すると、いずれ 食い違う。 `_destructive_summary` を `import_issues.destructive_summary` として公開し、 CLI はそれを呼ぶだけにした。**定義はサービス層、ゲートはトランザクションを 持つ側**、という分け方である。サンプルの上限(20件)も定義側に移した。 挙動は変わらない。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
_destructive_summaryをsrc/services/import_issues.destructive_summary()として公開した。CLI はそれを呼ぶだけになる。挙動は変わらない。なぜ
B6 のガードを
cli.pyの commit ゲートに置いた。CLI がトランザクションを持っているので、そこが正しい場所である。ただし CLI が唯一の利用者ではなかった。 compeito-aws の Admin API はインポートのサービス関数を直接呼び、
router.pyが自分でsession.commit()する(compeito-aws#100)。したがってあちらの経路はガードを通らない。判定に必要な材料(
items_moved/associations_moved/lost_associations_count/lost_associations_sample)はサービス層のレポートに載っているので、あちら側で同じ判定を組める。問題は「何を破壊的と数えるか」を二重に実装することである。 正味の損失で数える、(type, origin, destination)で比較する、並び替えは含めない、といった判断がコピーされ、片方だけ変わる。分け方
destructive_summary(report)が件数と上限つきのサンプルを返すcli.pyなら CLI が、Admin API ならあちらが決めるこの境界は
import-logic.mdの EN / JP にも書いた。Test plan
uv run pytest(908 passed / ローカル)uv run ruff check ./uv run ruff format --check .🤖 Generated with Claude Code