test(worktree-isolation): add worktree detection tests
This commit is contained in:
parent
0da53e7390
commit
643ab0a6b6
8 changed files with 125 additions and 2 deletions
|
|
@ -182,6 +182,14 @@ function handleAgentEvent(sessionId: string, event: Record<string, unknown>): vo
|
|||
const init = msg.content as InitContent;
|
||||
setAgentSdkSessionId(sessionId, init.sessionId);
|
||||
setAgentModel(sessionId, init.model);
|
||||
// CWD-based worktree detection: if init CWD contains a worktree path pattern,
|
||||
// register it for conflict suppression (agents in different worktrees don't conflict)
|
||||
if (init.cwd) {
|
||||
const wtPath = detectWorktreeFromCwd(init.cwd);
|
||||
if (wtPath) {
|
||||
setSessionWorktree(sessionId, wtPath);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -454,6 +462,22 @@ function triggerAutoAnchor(
|
|||
notify('info', `Anchored ${anchors.length} turns (${totalTokens} tokens) for context preservation`);
|
||||
}
|
||||
|
||||
// Worktree path patterns for various providers
|
||||
const WORKTREE_CWD_PATTERNS = [
|
||||
/\/\.claude\/worktrees\/([^/]+)/, // Claude Code: <repo>/.claude/worktrees/<name>/
|
||||
/\/\.codex\/worktrees\/([^/]+)/, // Codex
|
||||
/\/\.cursor\/worktrees\/([^/]+)/, // Cursor
|
||||
];
|
||||
|
||||
/** Extract worktree path from CWD if it matches a known worktree pattern */
|
||||
export function detectWorktreeFromCwd(cwd: string): string | null {
|
||||
for (const pattern of WORKTREE_CWD_PATTERNS) {
|
||||
const match = cwd.match(pattern);
|
||||
if (match) return match[0]; // Return the full worktree path segment
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function stopAgentDispatcher(): void {
|
||||
if (unlistenMsg) {
|
||||
unlistenMsg();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue