Skip to content

[#778] fix-source-review-issues#779

Merged
nrslib merged 3 commits into
mainfrom
takt/778/fix-source-review-issues
Jun 3, 2026
Merged

[#778] fix-source-review-issues#779
nrslib merged 3 commits into
mainfrom
takt/778/fix-source-review-issues

Conversation

@nrslib

@nrslib nrslib commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

確認範囲

  • /home/opa/work/takt
  • 静的レビューのみ。テストや実行確認はしていません。
  • 主に clone/exec と repertoire import 周辺を確認しました。

Findings

  1. High: worktree の .git relative gitdir: を process cwd 基準で解決しています。

    • 対象: src/infra/task/clone-exec.ts:42
    • Git の gitdir: 相対パスは .git ファイルのあるディレクトリ基準です。現在は path.resolve(worktreePath, '..', '..') と cwd 依存の解決になり、別ディレクトリから実行すると main repo を誤認して --reference clone が壊れます。path.dirname(gitPath) 基準で解決してください。
  2. Medium: root 配下判定が / 固定で Windows path を壊します。

    • 対象: src/features/repertoire/takt-repertoire-config.ts:194
    • realPath.startsWith(realRoot + '/') は Windows の \ separator で valid child path を拒否します。既存の path boundary helper か path.sep/path.relative ベースにしてください。
  3. Medium: repertoire add の temp path が時刻ベースで予測可能です。

    • 対象: src/commands/repertoire/add.ts:71
    • shared temp dir に takt-import-${Date.now()} を作るため、衝突や symlink race の余地があります。fs.mkdtempSync(path.join(tmpdir(), 'takt-import-')) を使ってください。

Execution Report

Workflow takt-default completed successfully.

Closes #778

Summary by CodeRabbit

  • テスト

    • ワークツリー参照解決や参照クローンのフォールバック・abortable 挙動を検証するテストを追加
    • レポジトリ追加処理の一時展開・後片付けを検証するテストを追加
    • Windows パス境界の検証ロジックテストを追加
    • クローン隔離と内部パス露出防止を確認するテストを追加
  • バグ修正

    • 一時ファイルのクリーンアップ処理を改善
    • フェッチ/クローン失敗時のエラーメッセージをサニタイズ・統一し、内部パスが露出しないよう修正
  • 変更

    • 実体パス検証ロジックをより堅牢な判定へ改善

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7aca3855-2459-4e43-b7d3-7d9b85cdb009

📥 Commits

Reviewing files that changed from the base of the PR and between c659988 and badedcc.

📒 Files selected for processing (1)
  • src/__tests__/clone-isolation.test.ts

📝 Walkthrough

Walkthrough

Git worktreeのlinked-worktree判定で参照クローン戦略を切り替え、シャロー参照のフォールバックと中断メッセージを整理しました。repertoire add は mkdtempSync ベースの安全な一時ディレクトリへ移行し、パス包含判定を isPathInside に置き換え、関連テストを追加・拡張しています。

Changes

Worktree gitdir解決とclone参照パス修正

Layer / File(s) Summary
Clone execution flow and abort handling
src/infra/task/clone-exec.ts, src/infra/task/clone-errors.ts
Linked worktree検出を導入し、隔離されたGit実行経路に切替。参照クローンを試行し、"reference repository is shallow" 検出時に部分クローンを削除して再試行するフォールバック制御を整理。abortable実行にenvオプションを追加し、中断メッセージを定数化。
Shared clone fetch wiring and sanitized failures
src/infra/task/clone.ts
createSharedClone*/prefetchのフェッチ分岐を isolated-clone 向けの fetchRemoteBranchIntoIsolatedClone* 呼び出しへ置換し、prefetch失敗時に例外文字列をログへ直接出力しないように変更。
Worktree resolution and sanitization tests
src/__tests__/clone.test.ts
worktreeのgitdir相対解決、shallow/referenceフォールバック、fetch/prefetch失敗時のログと例外からソースパスが露出しないことを検証するテストを追加・拡張。
Clone metadata isolation integration tests
src/__tests__/clone-isolation.test.ts
実ファイルシステム上でソース/ワークツリーを構築し、生成されたクローンの .git メタデータにソースパスが含まれないことと FETCH_HEAD が作成されないことを検証する統合テストを追加。

セキュアな一時ディレクトリ処理

Layer / File(s) Summary
Temporary directory implementation
src/commands/repertoire/add.ts
mkdtempSync(join(tmpdir(), 'takt-import-'))tmpBase を作成し、その配下にアーカイブ・展開・includeファイルを置く構成に変更。finallyで rmSync(tmpBase, { recursive: true, force: true }) により一括削除するようにした。
Temporary directory test coverage
src/__tests__/repertoire/add.test.ts
fs/child_processほかをモック化したVitestでmkdtemp呼び出し、extract ディレクトリ作成、archive.tar.gzinclude.txt の書き込み、resolveRepertoireConfigPath 呼び出し、ならびに単一の rmSync クリーンアップを検証。

パス境界検証のWindows対応化

Layer / File(s) Summary
Path containment validation refactor
src/features/repertoire/takt-repertoire-config.ts
validateRealpathInsideRoot の実体化後判定を手作業の startsWith から isPathInside(realRoot, realPath) へ差し替え、プラットフォーム依存の判定を委譲。
Windows path boundary tests
src/__tests__/repertoire/takt-repertoire-config-windows-boundary.test.ts
node:path を win32 モードで差し替え、子パス許可と兄弟パス拒否のケースを検証するテストを追加。

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning PR は issue #778 の 3 つの要件(worktree gitdir 解決、Windows パス対応、mkdtemp)にはおおむね対応しているが、レビュアーから「main repository の絶対パスを log/prompt/error 出力に含めないこと」が要求され、この重要な要件への適合性が不確定です。 clone-exec.ts と clone.ts の変更で main repo paths が log/error に露出しないこと、および追加テストで paths 非露出を検証することを確認してください。
Docstring Coverage ⚠️ Warning Docstring coverage is 3.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive タイトルは issue #778 の fix を指していますが、主な変更内容(worktree gitdir 解決、Windows パス対応、mkdtemp 移行)が具体的に示されておらず、抽象的な表現になっています。 変更の主要な内容を具体的に反映したタイトルに変更してください。例:「Fix worktree gitdir resolution, Windows path checks, and temp dir creation"
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Out of Scope Changes check ✅ Passed テスト追加(clone.test.ts、add.test.ts、clone-isolation.test.ts、windows-boundary.test.ts)はすべて #778 の要件に関連しており、scope 外の変更は見当たりません。

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch takt/778/fix-source-review-issues

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nrslib

nrslib commented Jun 3, 2026

Copy link
Copy Markdown
Owner Author

レビューしました。今回の3件のうち、Windows パス境界チェックと Date.now() ベースの一時ファイル修正は妥当で、この方向で問題ありません。

一方で、worktree の gitdir: 解決修正については、このままマージせず追加修正したいです。

相対 gitdir: を cwd 基準で解決していた元の指摘自体は妥当です。ただし今回の修正は、worktree 側の .git から main repository の実パスを復元し、mainRepo として debug log に出しています。

TAKT の shared clone 隔離では、AI エージェントに元 repo / 親 repo のパスを見せないことが重要です。実運用上、元 repo のパス情報がログや文脈に少しでも混ざると、AI がそちらを探索・修正対象にしてしまう事故が起きます。docs/task-management.md でも「Agents work entirely within the clone directory, unaware of the main repository」という前提になっているため、main repo の実パスを TAKT 側で復元して露出する方向は避けたいです。

マージ前に以下を対応してください。

  • mainRepo / referenceRepo の実パスをログに出さない
  • gitdir: から復元したパスを、編集対象 root やプロンプト材料と誤解されない名前・スコープに限定する
  • 可能なら main repo path を TAKT 側で復元せず、Git に reference 解決を委ねる実装を検討する
  • テストは「正しい main repo path を使う」だけでなく、「main repo path がログや生成物に露出しない」ことも確認する

結論として、この PR は現時点では Request changes です。worktree 部分の隔離方針を直した上で再確認したいです。

@nrslib

nrslib commented Jun 3, 2026

Copy link
Copy Markdown
Owner Author

Summary

タスク指示書: PR #779 の worktree shared clone 隔離方針を修正する

目的

PR #779[#778] fix-source-review-issues)のうち、worktree の gitdir: 解決修正が main repository / parent repository の実パスをログや文脈に露出しないように追加修正する。
Windows パス境界チェック修正と Date.now() ベースの一時ディレクトリ修正は妥当とされているため、既存の方向性を維持しつつリグレッションがないことを確認する。

参照資料

  • PR [#778] fix-source-review-issues #779 の差分・コメント
  • docs/task-management.md
    • shared clone 隔離の前提として、AI エージェントが clone directory 内だけで作業し、main repository を認識しないことを確認する。

高優先度

src/infra/task/clone-exec.ts

  • worktree の .git ファイルに含まれる相対 gitdir: を process cwd 基準で解決しないようにする。
  • 相対 gitdir: を扱う場合は .git ファイルが存在するディレクトリ基準で扱う。
  • mainRepo / referenceRepo / 元 repo / 親 repo の実パスを debug log、通常ログ、エラー出力、プロンプト材料、生成物に露出しないよう修正する。
  • gitdir: から復元または解決したパスを、編集対象 root や AI エージェント向けコンテキストと誤解されない名前・スコープに限定する。
  • 可能であれば main repo path を TAKT 側で復元して保持・露出する実装ではなく、Git の clone/reference 解決に委ねる実装へ寄せる。
  • 既存の shared clone 作成機能、worktree 由来の clone 作成機能、abortable clone 作成機能を壊さない。

src/__tests__/clone.test.ts

  • worktree の .gitgitdir: ../... のような相対参照を持つケースをテストする。
  • process cwd が worktree の親や main repo ではない場合でも、clone/reference 処理が壊れないことを確認する。
  • mainRepo / referenceRepo / 元 repo / 親 repo の実パスがログ、生成物、AI エージェントに渡る文字列に含まれないことをテストする。
  • 既存テストが「正しい main repo path を使う」だけを検証している場合は、隔離方針に沿って期待値を見直す。

中優先度

src/features/repertoire/takt-repertoire-config.ts

  • PR [#778] fix-source-review-issues #779 で入っている Windows path boundary 修正を維持する。
  • / 固定の startsWith(realRoot + '/') 判定へ戻さない。
  • Windows の \ separator でも root 配下の正当な path を許可し、同じ prefix を持つ sibling path を拒否する挙動を維持する。

src/__tests__/repertoire/takt-repertoire-config-windows-boundary.test.ts

  • Windows path boundary の既存テストが通ることを確認する。
  • 今回の clone 修正に伴って不要な変更を加えない。

src/commands/repertoire/add.ts

  • PR [#778] fix-source-review-issues #779 で入っている fs.mkdtempSync(path.join(tmpdir(), 'takt-import-')) ベースの一時ディレクトリ修正を維持する。
  • Date.now() ベースの予測可能な temp path 生成へ戻さない。

src/__tests__/repertoire/add.test.ts

  • mkdtemp ベースの一時ディレクトリ生成と cleanup の既存テストが通ることを確認する。
  • 今回の clone 修正に伴って不要な変更を加えない。

低優先度

docs/task-management.md

  • 実装と既存ドキュメントの shared clone 隔離前提が矛盾していないことを確認する。
  • ドキュメント更新が必要な場合のみ、main repository を AI エージェントに見せない前提が明確になる範囲で最小限更新する。

確認方法

  • gh pr view 779gh pr diff 779 で PR の現状とコメント対象を確認する。
  • npm test -- src/__tests__/clone.test.ts
  • npm test -- src/__tests__/repertoire/add.test.ts
  • npm test -- src/__tests__/repertoire/takt-repertoire-config-windows-boundary.test.ts
  • 可能であれば npm test を実行する。
  • 変更後の差分に main repository / parent repository の絶対パスをログ出力する処理が残っていないことを確認する。
  • clone/worktree 関連のテストログや生成物に main repository / parent repository の実パスが含まれないことを確認する。

完了条件

  • PR [#778] fix-source-review-issues #779 の worktree gitdir: 修正が cwd 依存でなくなる。
  • shared clone 隔離に反して main repository / parent repository の実パスがログや生成物に露出しない。
  • clone 関連テストで、worktree 相対 gitdir: とパス非露出の両方が検証されている。
  • Windows path boundary 修正と mkdtemp temp path 修正が維持されている。
  • 対象テストが成功した証跡を残す。

Execution Report

Workflow review-fix-takt-default completed successfully.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/infra/task/clone.ts`:
- Around line 190-196: Prefetch aborts are being swallowed, allowing execution
to continue after the AbortSignal fires; update the catch after
runGitCommandAbortable(projectDir, ['fetch', 'origin', branch], abortSignal) to
rethrow when the operation was aborted (check abortSignal.aborted or detect an
AbortError from the caught error) and only log non-abort failures, so that
aborts stop execution and do not proceed to subsequent branch checks or clone
logic.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: fc6ea326-bcbe-4137-821f-3b89d7023b3b

📥 Commits

Reviewing files that changed from the base of the PR and between 563dd4a and c659988.

📒 Files selected for processing (5)
  • src/__tests__/clone-isolation.test.ts
  • src/__tests__/clone.test.ts
  • src/infra/task/clone-errors.ts
  • src/infra/task/clone-exec.ts
  • src/infra/task/clone.ts

Comment thread src/infra/task/clone.ts
Comment on lines 190 to 196
try {
await runGitCommandAbortable(projectDir, ['fetch', 'origin', branch], abortSignal);
} catch (err) {
} catch {
log.info('Failed to prefetch branch from origin, continuing', {
branch,
error: String(err),
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

中断された prefetch を握りつぶさないでください。

ここは runGitCommandAbortable() の中断エラーまで通常の prefetch 失敗として扱ってしまうので、AbortSignal 発火後も後続の branch 判定や clone が続行されます。abort は先に再送出しないと、キャンセル済みタスクが clone を作り始める経路が残ります。

修正案
 import {
   cloneAndIsolate,
   cloneAndIsolateAbortable,
   fetchRemoteBranchIntoIsolatedClone,
   fetchRemoteBranchIntoIsolatedCloneAbortable,
   resolveCloneSubmoduleOptions,
   runGitCommandAbortable,
 } from './clone-exec.js';
+import { isTaskAbortError } from './clone-errors.js';

 ...

     try {
       await runGitCommandAbortable(projectDir, ['fetch', 'origin', branch], abortSignal);
-    } catch {
+    } catch (err) {
+      if (isTaskAbortError(err)) {
+        throw err;
+      }
       log.info('Failed to prefetch branch from origin, continuing', {
         branch,
       });
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/infra/task/clone.ts` around lines 190 - 196, Prefetch aborts are being
swallowed, allowing execution to continue after the AbortSignal fires; update
the catch after runGitCommandAbortable(projectDir, ['fetch', 'origin', branch],
abortSignal) to rethrow when the operation was aborted (check
abortSignal.aborted or detect an AbortError from the caught error) and only log
non-abort failures, so that aborts stop execution and do not proceed to
subsequent branch checks or clone logic.

@nrslib nrslib merged commit 056b3fb into main Jun 3, 2026
4 checks passed
@nrslib nrslib deleted the takt/778/fix-source-review-issues branch June 3, 2026 10:53
@nrslib nrslib mentioned this pull request Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ソースレビュー指摘 (2026-05-30)

1 participant