Skip to content

fix: break 3-file import cycle in cli/project-files - #1170

Open
AbhijitK20 wants to merge 1 commit into
CodebuffAI:mainfrom
AbhijitK20:fix-import-cycle-v2
Open

fix: break 3-file import cycle in cli/project-files#1170
AbhijitK20 wants to merge 1 commit into
CodebuffAI:mainfrom
AbhijitK20:fix-import-cycle-v2

Conversation

@AbhijitK20

Copy link
Copy Markdown

Summary

Breaks the circular import dependency between project-files.ts, auth.ts, and logger.ts.

The cycle:

project-files.ts → auth.ts → logger.ts → project-files.ts

project-files.ts imported getConfigDir from ./utils/auth, which imports logger, which imports getCurrentChatDir and getProjectRoot back from ../project-files — creating a 3-file circular dependency.

The fix: Import getConfigDir directly from ./utils/config-dir, which has no dependency on auth.ts, logger.ts, or project-files.ts.

Maintainer Feedback Addressed

  1. Same signature? Yes — config-dir.ts:14 exports the identical getConfigDir function. auth.ts:37 is a thin wrapper: export const getConfigDir = (): string => getConfigDirBase(). No behavior change.

  2. Does the cycle cause a real problem? Yes — circular dependencies can cause undefined values at import time depending on module load order, especially in bundlers or when tree-shaking.

  3. Test coverage — Added two tests for getProjectDataDir in project-files-chat-id.test.ts to exercise the fixed import path.

Notes

  • anonymous-id.ts already imports getConfigDir directly from config-dir (this PR aligns project-files.ts with that pattern)
  • No functional change — getConfigDir returns the same value either way
project-files.ts -> auth.ts -> logger.ts -> project-files.ts

Import getConfigDir directly from config-dir instead of auth to
break the circular dependency. config-dir.ts exports the identical
function (auth.ts just wraps it). anonymous-id.ts already imports
from config-dir directly.

Add getProjectDataDir tests to exercise the fixed import path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant