Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,5 @@ htmlcov/
# Generated version file
src/cocoindex_code/_version.py

# CocoIndex
.cocoindex_code/
# CocoIndex Code (ccc)
/.cocoindex_code/
43 changes: 1 addition & 42 deletions src/cocoindex_code/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,35 +209,6 @@ def remove_from_gitignore(project_root: Path) -> None:
gitignore.write_text("".join(new_lines))


def auto_init_project() -> Path:
"""Auto-initialize project from CWD.

Runs core ``init`` logic without parent-directory confirmation and without
the "run ``ccc index``" prompt. Returns the project root (CWD).
"""
from .settings import project_settings_path

cwd = Path.cwd().resolve()
settings_file = project_settings_path(cwd)

if not settings_file.is_file():
# Create user settings if missing
user_path = user_settings_path()
if not user_path.is_file():
save_user_settings(default_user_settings())
_typer.echo(f"Created user settings: {user_path}")

# Create project settings
save_project_settings(cwd, default_project_settings())
_typer.echo(f"Created project settings: {settings_file}")
_typer.echo("You can edit the settings files to customize indexing behavior.")

# Update .gitignore
add_to_gitignore(cwd)

return cwd


# ---------------------------------------------------------------------------
# Commands
# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -289,19 +260,7 @@ def init(
@app.command()
def index() -> None:
"""Create/update index for the codebase."""
from .client import ensure_daemon

# Auto-init if not in an initialized project
root = find_project_root(Path.cwd())
if root is None:
root = auto_init_project()

try:
client = ensure_daemon()
except Exception as e:
_typer.echo(f"Error: Failed to connect to daemon: {e}", err=True)
raise _typer.Exit(code=1)
project_root = str(root)
client, project_root = require_daemon_for_project()

_run_index_with_progress(client, project_root)

Expand Down
22 changes: 0 additions & 22 deletions tests/test_cli_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from cocoindex_code.cli import (
add_to_gitignore,
auto_init_project,
remove_from_gitignore,
require_project_root,
resolve_default_path,
Expand Down Expand Up @@ -126,24 +125,3 @@ def test_remove_from_gitignore_no_entry(tmp_path: Path) -> None:
gitignore.write_text(original)
remove_from_gitignore(tmp_path)
assert gitignore.read_text() == original


def test_auto_init_project(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
(tmp_path / ".git").mkdir()
monkeypatch.chdir(tmp_path)
# Monkeypatch user settings dir to avoid touching real home
monkeypatch.setattr(
"cocoindex_code.cli.user_settings_path",
lambda: tmp_path / ".cocoindex_code_user" / "global_settings.yml",
)
monkeypatch.setattr(
"cocoindex_code.settings.user_settings_dir",
lambda: tmp_path / ".cocoindex_code_user",
)

result = auto_init_project()

assert result == tmp_path
assert (tmp_path / ".cocoindex_code" / "settings.yml").is_file()
assert (tmp_path / ".gitignore").is_file()
assert "/.cocoindex_code/" in (tmp_path / ".gitignore").read_text()
22 changes: 8 additions & 14 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
from pathlib import Path

import pytest
from cocoindex.connectors import sqlite as coco_sqlite
from typer.testing import CliRunner

from cocoindex.connectors import sqlite as coco_sqlite
from cocoindex_code.cli import app
from cocoindex_code.client import stop_daemon
from cocoindex_code.settings import find_parent_with_marker
Expand Down Expand Up @@ -319,8 +319,7 @@ def test_session_respects_gitignore(e2e_project: Path) -> None:
try:
with conn.readonly() as db:
file_paths = {
row[0]
for row in db.execute("SELECT DISTINCT file_path FROM code_chunks_vec")
row[0] for row in db.execute("SELECT DISTINCT file_path FROM code_chunks_vec")
}
finally:
conn.close()
Expand Down Expand Up @@ -382,17 +381,12 @@ def test_session_search_refresh() -> None:
assert "main.py" in result.output


def test_session_index_auto_init(e2e_project: Path) -> None:
"""Running ``ccc index`` from uninitialized dir auto-inits, then search works."""
# Do NOT call init — just run index directly
result = runner.invoke(app, ["index"], catch_exceptions=False)
assert result.exit_code == 0, result.output
assert (e2e_project / ".cocoindex_code" / "settings.yml").exists()

# Search should work
result = runner.invoke(app, ["search", "fibonacci"], catch_exceptions=False)
assert result.exit_code == 0
assert "main.py" in result.output
@pytest.mark.usefixtures("e2e_project")
def test_session_index_not_initialized_errors() -> None:
"""Running ``ccc index`` from uninitialized dir should error."""
result = runner.invoke(app, ["index"])
assert result.exit_code != 0
assert "ccc init" in result.output


def test_session_subdirectory_path_default(e2e_project: Path) -> None:
Expand Down
Loading