Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051"""The command line front end, with the build and the server stubbed out.
Only the parts that decide something are worth covering here: formatting isvisible the moment anyone runs the command, but a flag that is quietly dropped isnot."""
from __future__ import annotations
import pytest
from code_index import cli
@pytest.fixturedef stub_build(monkeypatch): """Record the build's arguments instead of indexing anything.""" calls: list[dict] = []
def fake_build(roots, threads=None, force=False): calls.append({"roots": roots, "threads": threads, "force": force}) return { "repos": 1, "files": 1, "reused": 0, "embedded_chunks": 1, "total_chunks": 1, "skipped": {}, "failed_repos": [], }
monkeypatch.setattr(cli, "build", fake_build) return calls
def test_threads_is_reported_as_ignored_when_the_server_is_up( stub_build, monkeypatch, capsys): """The server is shared, so a running one keeps the thread count it started with.""" monkeypatch.setattr(cli.embed, "is_up", lambda: True)
assert cli.main(["--threads", "4", "index", "--root", "/nowhere"]) == 0
err = capsys.readouterr().err assert "--threads 4" in err assert "stop" in err, "the message must say what to do about it"
def test_no_note_when_the_server_is_down(stub_build, monkeypatch, capsys): monkeypatch.setattr(cli.embed, "is_up", lambda: False)
assert cli.main(["--threads", "4", "index", "--root", "/nowhere"]) == 0
assert "--threads" not in capsys.readouterr().err assert stub_build[0]["threads"] == 4