test_init.py

tests/test_init.py

`clew init` — the first command a new user runs, and it REWRITES A FILE.

test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable

None test_init.test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

A repo with no Doxyfile and no guard scope is INDEXABLE, and says so.

tests/test_init.py:1114

Show on the map →

Called by none

Calls _named, _run, diagnose

Checks

  • assert code == 0, out
  • assert (repo / REPO_CONFIG_NAME).is_file()
  • assert check.status == CHECK_OK, ("a repo with neither is the ordinary starting state and it indexes fine; warning here " "tells a new user their repository is unsupported when it is not" )
  • assert "whole repository" in check.detail.lower(), "and it must name the route that will run"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose
REQ-DDB-CLI-002measuredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose
REQ-DDB-CONFIG-001measuredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_client_config → global_config_evidence
REQ-DDB-PIPE-006measuredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 32 lines
def test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """THIS TEST USED TO ASSERT THE OPPOSITE AND THE PRODUCT PROVED IT WRONG. It was
    `test_unindexable_repo_warns_but_still_registers`, and it pinned a WARN saying
    "index(action='refresh') will fail until this repo has one".

    MEASURED: a git repo containing one `.c` file, no Doxyfile, no doxygen-guard config and no
    declaration BUILDS — doxygen is synthesized from the whole-repo scope and the function is
    indexed. The premise died with gh#333, which made whole-repo the DEFAULT tier rather than a
    last resort; `is_derived()` stayed true only for SOURCE_DECLARED, so the check fell to a warn
    branch that is wrong every time it fires.

    WHY THIS MATTERS MORE THAN A LABEL: it is the FIRST SCREEN a new consumer sees, on the exact
    configuration they arrive with — no Doxyfile, nothing declared. It told them the tool would
    not work on their repository.

    The suite pinned it, which is why running the product rather than the tests is what found it.

    Warnings must still not spend the exit code, so that half is kept."""
    del stub_env
    code, out = _run([], repo, capsys)
    assert code == 0, out
    assert (repo / REPO_CONFIG_NAME).is_file()
    check = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_INDEXABLE)
    assert check.status == CHECK_OK, (
        "a repo with neither is the ordinary starting state and it indexes fine; warning here "
        "tells a new user their repository is unsupported when it is not"
    )
    assert "whole repository" in check.detail.lower(), "and it must name the route that will run"

Activity · 7 steps
lines 1134–1134del stub_envlines 1135–1135code, out = _run([], repo, capsys)lines 1136–1136assert code == 0, outlines 1137–1137assert (repo / REPO_CONFIG_NAME).is_file()lines 1138–1138check = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_INDEXABLE)lines 1139–1142assert check.status == CHECK_OK, ( "a repo with neither is the ordinary starting state and it indexes fine; warning here " "tells a new user their repository is unsupported when it is not" )lines 1143–1143assert "whole repository" in check.detail.lower(), "and it must name the route that will run"

test_absolute_path_is_used_and_flagged_non_portable

None test_init.test_absolute_path_is_used_and_flagged_non_portable(Path tmp_path, Path repo)

Off PATH and outside the repo yields an absolute path, flagged.

tests/test_init.py:1008

Checks

  • assert resolution.command == str(script)
  • assert not resolution.portable
  • assert "not on PATH" in resolution.origin

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_absolute_path_is_used_and_flagged_non_portable → resolve_server_command
Source · 16 lines
def test_absolute_path_is_used_and_flagged_non_portable(tmp_path: Path, repo: Path) -> None:
    """A bare name the launching shell cannot resolve produces a server that
    silently never starts, which is strictly worse than a machine-specific path.
    So the path is written — and reported as non-portable rather than chosen
    quietly on the user's behalf."""
    script = tmp_path / "outside" / CONSOLE_SCRIPT
    script.parent.mkdir()
    script.touch()
    resolution = resolve_server_command(
        repo, INIT_SCOPE_REPO, which=lambda _cmd: None, bindir=script.parent
    )
    assert resolution.command == str(script)
    assert not resolution.portable
    assert "not on PATH" in resolution.origin

Activity · 7 steps
lines 1013–1013script = tmp_path / "outside" / CONSOLE_SCRIPTlines 1014–1014script.parent.mkdir()lines 1015–1015script.touch()lines 1016–1018resolution = resolve_server_command( repo, INIT_SCOPE_REPO, which=lambda _cmd: None, bindir=script.parent )lines 1019–1019assert resolution.command == str(script)lines 1020–1020assert not resolution.portablelines 1021–1021assert "not on PATH" in resolution.origin

test_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support

None test_init.test_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support(Path stub_env, Path repo, pytest.MonkeyPatch monkeypatch)

A probe that cannot RUN must warn, never report unsupported.

tests/test_init.py:1427

Checks

  • assert check.status == CHECK_WARN, (f"an unrunnable probe must WARN, not fail — absence of a measurement is not a " f"measurement of absence; got {check.status!r}" )
  • assert sp is not None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002measuredtest_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support → _check_doxygen → doxygen_supports_sqlite3
REQ-DDB-INDEX-001inferredtest_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support → _check_doxygen → uses_rustdoc → discover_doxyfile
REQ-DDB-PIPE-006measuredtest_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support → _check_doxygen → _needs_doxygen
Source · 31 lines
def test_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support(
    stub_env: Path, repo: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """FAIL OPEN ON THE MEASUREMENT, FAIL CLOSED ON THE ANSWER. A timeout or an OSError is not
    evidence that sqlite3 support is missing, and reporting it as missing would send someone
    rebuilding doxygen to fix what is actually a PATH or permissions problem. This is the same
    discipline as `source_fingerprint` returning "" for "cannot tell" rather than a digest of
    zero files.

    @brief An unrunnable probe warns instead of asserting absence.
    @return None.
    @version 1
    """
    import subprocess as sp

    from clew import doxygen as dox

    def boom(*_args: object, **_kwargs: object) -> object:
        raise OSError("cannot exec")

    monkeypatch.setattr(dox.subprocess, "run", boom)

    check = init_command._check_doxygen(repo)

    assert check.status == CHECK_WARN, (
        f"an unrunnable probe must WARN, not fail — absence of a measurement is not a "
        f"measurement of absence; got {check.status!r}"
    )
    assert sp is not None

Activity · 7 steps
lines 1440–1440import subprocess as splines 1442–1442from clew import doxygen as doxlines 1444–1445def boom(*_args: object, **_kwargs: object) -> object: raise OSError("cannot exec")lines 1447–1447monkeypatch.setattr(dox.subprocess, "run", boom)lines 1449–1449check = init_command._check_doxygen(repo)lines 1451–1454assert check.status == CHECK_WARN, ( f"an unrunnable probe must WARN, not fail — absence of a measurement is not a " f"measurement of absence; got {check.status!r}" )lines 1455–1455assert sp is not None

test_apply_plan_backs_up_the_original_bytes

None test_init.test_apply_plan_backs_up_the_original_bytes(Path tmp_path)

The backup holds the ORIGINAL bytes, not the new ones.

tests/test_init.py:493

Show on the map →

Called by none

Calls _expected_entry, apply_plan, plan_merge

Checks

  • assert backup.is_file(), "an existing target must be backed up before it is replaced"
  • assert backup.read_text(encoding="utf-8") == original, "the backup must hold the ORIGINAL bytes"
  • assert json.loads(target.read_text(encoding="utf-8"))[SERVERS_KEY][MCP_ENTRY_NAME] == (_expected_entry() )
  • assert not target.with_name(target.name + ".clew.tmp").exists(), ("the atomic-swap temp file must not survive" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002measuredtest_apply_plan_backs_up_the_original_bytes → apply_plan
REQ-DDB-MCP-001measuredtest_apply_plan_backs_up_the_original_bytes → plan_merge
Source · 27 lines
def test_apply_plan_backs_up_the_original_bytes(tmp_path: Path) -> None:
    """The single most consequential write in the tool, so it is tested directly
    rather than through the command. `os.replace` guarantees the target is never
    half-written; it guarantees NOTHING about the content being right, and the
    content has been through a full parse → mutate → re-serialise round-trip. A
    defect anywhere in that round-trip destroys the file perfectly atomically.

    The assertion that matters is which bytes the `.bak` holds: a backup taken
    AFTER the swap would exist, be the same size, and be worthless."""
    target = tmp_path / REPO_CONFIG_NAME
    original = (
        '{\n  "mcpServers": {\n    "entropic": {"command": "entropic-mcp"}\n  },\n'
        '  "note": "hand written, irreplaceable"\n}\n'
    )
    target.write_text(original, encoding="utf-8")
    apply_plan(plan_merge(target, _expected_entry()))
    backup = target.with_name(target.name + BACKUP_SUFFIX)
    assert backup.is_file(), "an existing target must be backed up before it is replaced"
    assert backup.read_text(encoding="utf-8") == original, "the backup must hold the ORIGINAL bytes"
    assert json.loads(target.read_text(encoding="utf-8"))[SERVERS_KEY][MCP_ENTRY_NAME] == (
        _expected_entry()
    )
    assert not target.with_name(target.name + ".clew.tmp").exists(), (
        "the atomic-swap temp file must not survive"
    )

Activity · 9 steps
lines 502–502target = tmp_path / REPO_CONFIG_NAMElines 503–506original = ( '{\n "mcpServers": {\n "entropic": {"command": "entropic-mcp"}\n },\n' ' "note": "hand written, irreplaceable"\n}\n' )lines 507–507target.write_text(original, encoding="utf-8")lines 508–508apply_plan(plan_merge(target, _expected_entry()))lines 509–509backup = target.with_name(target.name + BACKUP_SUFFIX)lines 510–510assert backup.is_file(), "an existing target must be backed up before it is replaced"lines 511–511assert backup.read_text(encoding="utf-8") == original, "the backup must hold the ORIGINAL bytes"lines 512–514assert json.loads(target.read_text(encoding="utf-8"))[SERVERS_KEY][MCP_ENTRY_NAME] == ( _expected_entry() )lines 515–517assert not target.with_name(target.name + ".clew.tmp").exists(), ( "the atomic-swap temp file must not survive" )

test_bare_console_script_when_on_path

None test_init.test_bare_console_script_when_on_path(Path tmp_path, Path repo)

The bare console-script name is used when PATH resolves it.

tests/test_init.py:973

Checks

  • assert resolution.command == CONSOLE_SCRIPT
  • assert resolution.portable

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_bare_console_script_when_on_path → resolve_server_command
Source · 14 lines
def test_bare_console_script_when_on_path(tmp_path: Path, repo: Path) -> None:
    """The `pip install clew` case, and the right answer for it: the bare
    name is the interface the package publishes, it survives the checkout moving,
    and it is what every other installed MCP server looks like in a config."""
    found = tmp_path / "bin" / CONSOLE_SCRIPT
    found.parent.mkdir()
    found.touch()
    resolution = resolve_server_command(
        repo, INIT_SCOPE_REPO, which=lambda _cmd: str(found), bindir=tmp_path / "bin"
    )
    assert resolution.command == CONSOLE_SCRIPT
    assert resolution.portable

Activity · 6 steps
lines 977–977found = tmp_path / "bin" / CONSOLE_SCRIPTlines 978–978found.parent.mkdir()lines 979–979found.touch()lines 980–982resolution = resolve_server_command( repo, INIT_SCOPE_REPO, which=lambda _cmd: str(found), bindir=tmp_path / "bin" )lines 983–983assert resolution.command == CONSOLE_SCRIPTlines 984–984assert resolution.portable

test_blocking_checks_are_only_the_write_invalidating_ones

None test_init.test_blocking_checks_are_only_the_write_invalidating_ones()

Only the two write-invalidating checks are blocking.

tests/test_init.py:1272

Show on the map →

Called by none

Calls none

Checks

  • assert init_command.BLOCKING_CHECKS == frozenset({init_command.CHECK_CLIENT_CONFIG, init_command.CHECK_SERVER_COMMAND} )
  • assert init_command.CHECK_DOXYGEN not in init_command.BLOCKING_CHECKS
  • assert init_command.CHECK_MCP_SDK not in init_command.BLOCKING_CHECKS
  • assert init_command.CHECK_DECLARATION not in init_command.BLOCKING_CHECKS, ("an undeclared repo is the ordinary starting state and must never withhold the registration" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
Source · 15 lines
def test_blocking_checks_are_only_the_write_invalidating_ones() -> None:
    """Pinned because the set is the whole three-tier design in one constant.
    Adding `doxygen` here would make a missing binary withhold the registration —
    the "run it twice" outcome the tiers exist to avoid — and removing
    `server-command` would let a config name a command that does not exist."""
    assert init_command.BLOCKING_CHECKS == frozenset(
        {init_command.CHECK_CLIENT_CONFIG, init_command.CHECK_SERVER_COMMAND}
    )
    assert init_command.CHECK_DOXYGEN not in init_command.BLOCKING_CHECKS
    assert init_command.CHECK_MCP_SDK not in init_command.BLOCKING_CHECKS
    assert init_command.CHECK_DECLARATION not in init_command.BLOCKING_CHECKS, (
        "an undeclared repo is the ordinary starting state and must never withhold the registration"
    )

Activity · 4 steps
lines 1277–1279assert init_command.BLOCKING_CHECKS == frozenset( {init_command.CHECK_CLIENT_CONFIG, init_command.CHECK_SERVER_COMMAND} )lines 1280–1280assert init_command.CHECK_DOXYGEN not in init_command.BLOCKING_CHECKSlines 1281–1281assert init_command.CHECK_MCP_SDK not in init_command.BLOCKING_CHECKSlines 1282–1284assert init_command.CHECK_DECLARATION not in init_command.BLOCKING_CHECKS, ( "an undeclared repo is the ordinary starting state and must never withhold the registration" )

test_broken_mcp_sdk_fails_but_still_registers

None test_init.test_broken_mcp_sdk_fails_but_still_registers(Path repo, Path stub_env, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)

A broken MCP SDK fails the run but still registers the server.

tests/test_init.py:1224

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 1
  • assert (repo / REPO_CONFIG_NAME).is_file(), "the registration still lands"
  • assert "SDK import failed" in out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main
REQ-DDB-CLI-002measuredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 22 lines
def test_broken_mcp_sdk_fails_but_still_registers(
    repo: Path,
    stub_env: Path,
    monkeypatch: pytest.MonkeyPatch,
    capsys: pytest.CaptureFixture[str],
) -> None:
    """Breaks the IMPORT, not a name lookup, because the check now performs the
    server's own import rather than probing a string that stands in for it.

    `sys.modules[name] = None` is the documented way to make a subsequent
    `from name import ...` raise: CPython treats a None entry as a poisoned module
    and raises ImportError rather than re-importing. That reaches the real failure
    path without needing a broken interpreter.
    """
    del stub_env
    monkeypatch.setitem(sys.modules, "clew.mcp_server._sdk", None)
    code, out = _run([], repo, capsys)
    assert code == 1
    assert (repo / REPO_CONFIG_NAME).is_file(), "the registration still lands"
    assert "SDK import failed" in out

Activity · 6 steps
lines 1238–1238del stub_envlines 1239–1239monkeypatch.setitem(sys.modules, "clew.mcp_server._sdk", None)lines 1240–1240code, out = _run([], repo, capsys)lines 1241–1241assert code == 1lines 1242–1242assert (repo / REPO_CONFIG_NAME).is_file(), "the registration still lands"lines 1243–1243assert "SDK import failed" in out

test_check_statuses_come_from_the_vocabulary

None test_init.test_check_statuses_come_from_the_vocabulary(Path repo, Path stub_env)

A failed check that is not blocking still exits non-zero.

tests/test_init.py:1291

Show on the map →

Called by none

Calls diagnose

Checks

  • assert check.status in (CHECK_OK, CHECK_WARN, CHECK_FAIL)
  • assert check.detail, f"{check.name} reported no evidence"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_check_statuses_come_from_the_vocabulary → diagnose
REQ-DDB-CLI-002measuredtest_check_statuses_come_from_the_vocabulary → diagnose
REQ-DDB-CONFIG-001measuredtest_check_statuses_come_from_the_vocabulary → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_check_statuses_come_from_the_vocabulary → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_check_statuses_come_from_the_vocabulary → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_check_statuses_come_from_the_vocabulary → diagnose → _check_client_config → global_config_evidence
REQ-DDB-PIPE-006measuredtest_check_statuses_come_from_the_vocabulary → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_check_statuses_come_from_the_vocabulary → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_check_statuses_come_from_the_vocabulary → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 13 lines
def test_check_statuses_come_from_the_vocabulary(repo: Path, stub_env: Path) -> None:
    """Every status the doctor emits has to be a registered `check_status` value,
    or the report's own legend (printed from `CHECK_STATUS.means`) describes
    something else."""
    del stub_env
    for check in init_command.diagnose(repo, INIT_SCOPE_REPO):
        assert check.status in (CHECK_OK, CHECK_WARN, CHECK_FAIL)
        assert check.detail, f"{check.name} reported no evidence"


# ─── CLI wiring ──────────────────────────────────────────────────────────────

Activity · 4 steps
lines 1295–1295del stub_envlines 1296–1296◇ for check in init_command.diagnose(repo, INIT_SCOPE_REPO)lines 1297–1297assert check.status in (CHECK_OK, CHECK_WARN, CHECK_FAIL)lines 1298–1298assert check.detail, f"{check.name} reported no evidence"

test_claude_config_dir_relocates_both_paths

None test_init.test_claude_config_dir_relocates_both_paths(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A declared CLAUDE_CONFIG_DIR relocates both the file and the state dir.

tests/test_init.py:952

Checks

  • assert global_config_path() == declared / ".claude.json"
  • assert claude_state_dir() == declared
  • assert global_config_available(), "a declaration IS the evidence"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_claude_config_dir_relocates_both_paths → claude_state_dir
Source · 17 lines
def test_claude_config_dir_relocates_both_paths(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """Both, and the state directory is that directory ITSELF rather than a
    `.claude` child of it — the asymmetry against the default layout (where the
    file and the state directory are siblings) is exactly what an assumption gets
    wrong, and it is why this project's rule is to read declarations."""
    declared = tmp_path / "elsewhere"
    monkeypatch.setenv(CLAUDE_CONFIG_DIR_ENV, str(declared))
    assert global_config_path() == declared / ".claude.json"
    assert claude_state_dir() == declared
    assert global_config_available(), "a declaration IS the evidence"


# ─── command resolution ──────────────────────────────────────────────────────

Activity · 5 steps
lines 959–959declared = tmp_path / "elsewhere"lines 960–960monkeypatch.setenv(CLAUDE_CONFIG_DIR_ENV, str(declared))lines 961–961assert global_config_path() == declared / ".claude.json"lines 962–962assert claude_state_dir() == declaredlines 963–963assert global_config_available(), "a declaration IS the evidence"

test_cli_command_word_matches_the_command

None test_init.test_cli_command_word_matches_the_command()

The dispatch word and the command's own name are the same string.

tests/test_init.py:1306

Show on the map →

Called by none

Calls none

Checks

  • assert cli.INIT_COMMAND == init_command.COMMAND == "init"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
Source · 7 lines
def test_cli_command_word_matches_the_command() -> None:
    """`cli.py` spells the word rather than importing the module, so that a build
    invocation never drags `init`'s import graph in. That duplication is only safe
    while something pins the two together."""
    assert cli.INIT_COMMAND == init_command.COMMAND == "init"

Activity · 1 steps
lines 1310–1310assert cli.INIT_COMMAND == init_command.COMMAND == "init"

test_config_path_selects_by_scope

None test_init.test_config_path_selects_by_scope(Path repo, Path global_home)

config_path selects the file by scope.

tests/test_init.py:883

Show on the map →

Called by none

Calls config_path

Checks

  • assert config_path(INIT_SCOPE_REPO, repo) == repo / REPO_CONFIG_NAME
  • assert config_path(INIT_SCOPE_GLOBAL, repo) == global_home / ".claude.json"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_config_path_selects_by_scope → config_path
Source · 11 lines
def test_config_path_selects_by_scope(repo: Path, global_home: Path) -> None:
    """@brief Each scope resolves to its own documented file.

    @param repo Target repo.
    @param global_home Isolated Claude config directory.
    @version 1
    """
    assert config_path(INIT_SCOPE_REPO, repo) == repo / REPO_CONFIG_NAME
    assert config_path(INIT_SCOPE_GLOBAL, repo) == global_home / ".claude.json"

Activity · 2 steps
lines 890–890assert config_path(INIT_SCOPE_REPO, repo) == repo / REPO_CONFIG_NAMElines 891–891assert config_path(INIT_SCOPE_GLOBAL, repo) == global_home / ".claude.json"

test_declaration_check_reports_both_states

None test_init.test_declaration_check_reports_both_states(Path repo, Path stub_env)

The declaration check reports both states, and points at propose .

tests/test_init.py:1150

Show on the map →

Called by none

Calls _named, diagnose

Checks

  • assert absent.status == CHECK_WARN
  • assert "propose" in absent.detail
  • assert present.status == CHECK_OK
  • assert ".clew.yaml" in present.detail

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_declaration_check_reports_both_states → diagnose
REQ-DDB-CLI-002measuredtest_declaration_check_reports_both_states → diagnose
REQ-DDB-CONFIG-001measuredtest_declaration_check_reports_both_states → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_declaration_check_reports_both_states → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_declaration_check_reports_both_states → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_declaration_check_reports_both_states → diagnose → _check_client_config → global_config_evidence
REQ-DDB-PIPE-006measuredtest_declaration_check_reports_both_states → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_declaration_check_reports_both_states → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_declaration_check_reports_both_states → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 17 lines
def test_declaration_check_reports_both_states(repo: Path, stub_env: Path) -> None:
    """Absent is the norm rather than a defect, so it is a warning — but a SAID
    one: an empty causal layer on a repo whose accessors the built-in defaults
    cannot see is the commonest "this database is useless" report, and `propose`
    is the answer."""
    del stub_env
    absent = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_DECLARATION)
    assert absent.status == CHECK_WARN
    assert "propose" in absent.detail
    ## FIXTURE CHANGED (2.0.0, R5-CFG F1): a list under a mapping section was never read and is now
    ## refused; the property under test does not depend on the section's contents.
    (repo / ".clew.yaml").write_text("shared_key_patterns: {}\n", encoding="utf-8")
    present = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_DECLARATION)
    assert present.status == CHECK_OK
    assert ".clew.yaml" in present.detail

Activity · 8 steps
lines 1155–1155del stub_envlines 1156–1156absent = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_DECLARATION)lines 1157–1157assert absent.status == CHECK_WARNlines 1158–1158assert "propose" in absent.detaillines 1161–1161(repo / ".clew.yaml").write_text("shared_key_patterns: {}\n", encoding="utf-8")lines 1162–1162present = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_DECLARATION)lines 1163–1163assert present.status == CHECK_OKlines 1164–1164assert ".clew.yaml" in present.detail

test_differing_entry_is_refused_without_force

None test_init.test_differing_entry_is_refused_without_force(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

A differing existing entry is refused, and the file is untouched.

tests/test_init.py:426

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 1
  • assert target.read_bytes() == original, "a refusal must not modify the file"
  • assert not target.with_name(target.name + BACKUP_SUFFIX).exists()
  • assert "--force" in out
  • assert "/opt/wrapper/clew-mcp" in out, "the diff must show what would be lost"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_differing_entry_is_refused_without_force → _run → init_main
REQ-DDB-CLI-002measuredtest_differing_entry_is_refused_without_force → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_differing_entry_is_refused_without_force → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 27 lines
def test_differing_entry_is_refused_without_force(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """A user who hand-tuned their entry — extra args, a wrapper command, a
    different pinned repo — must not lose it to a doctor being helpful. The
    refusal has to carry the DIFF, or "it differs" is not actionable."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    hand_tuned = {
        SERVERS_KEY: {
            MCP_ENTRY_NAME: {
                "type": "stdio",
                "command": "/opt/wrapper/clew-mcp",
                "args": ["--repo", "/elsewhere", "--verbose"],
            }
        }
    }
    target.write_text(json.dumps(hand_tuned, indent=2) + "\n", encoding="utf-8")
    original = target.read_bytes()
    code, out = _run([], repo, capsys)
    assert code == 1
    assert target.read_bytes() == original, "a refusal must not modify the file"
    assert not target.with_name(target.name + BACKUP_SUFFIX).exists()
    assert "--force" in out
    assert "/opt/wrapper/clew-mcp" in out, "the diff must show what would be lost"

Activity · 11 steps
lines 432–432del stub_envlines 433–433target = repo / REPO_CONFIG_NAMElines 434–442hand_tuned = { SERVERS_KEY: { MCP_ENTRY_NAME: { "type": "stdio", "command": "/opt/wrapper/clew-mcp", "args": ["--repo", "/elsewhere", "--verbose"], } } }lines 443–443target.write_text(json.dumps(hand_tuned, indent=2) + "\n", encoding="utf-8")lines 444–444original = target.read_bytes()lines 445–445code, out = _run([], repo, capsys)lines 446–446assert code == 1lines 447–447assert target.read_bytes() == original, "a refusal must not modify the file"lines 448–448assert not target.with_name(target.name + BACKUP_SUFFIX).exists()lines 449–449assert "--force" in outlines 450–450assert "/opt/wrapper/clew-mcp" in out, "the diff must show what would be lost"

test_doxyfile_makes_the_repo_indexable

None test_init.test_doxyfile_makes_the_repo_indexable(Path repo, Path stub_env)

A Doxyfile makes the repo indexable.

tests/test_init.py:1095

Show on the map →

Called by none

Calls _named, diagnose

Checks

  • assert check.status == CHECK_OK
  • assert "Doxyfile" in check.detail

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_doxyfile_makes_the_repo_indexable → diagnose
REQ-DDB-CLI-002measuredtest_doxyfile_makes_the_repo_indexable → diagnose
REQ-DDB-CONFIG-001inferredtest_doxyfile_makes_the_repo_indexable → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_doxyfile_makes_the_repo_indexable → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_doxyfile_makes_the_repo_indexable → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_doxyfile_makes_the_repo_indexable → diagnose → _check_client_config → global_config_evidence
REQ-DDB-PIPE-006measuredtest_doxyfile_makes_the_repo_indexable → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_doxyfile_makes_the_repo_indexable → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_doxyfile_makes_the_repo_indexable → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 14 lines
def test_doxyfile_makes_the_repo_indexable(repo: Path, stub_env: Path) -> None:
    """@brief A repo shipping a Doxyfile reports `indexable: ok` naming it.

    @param repo Target repo.
    @param stub_env Stubbed executables.
    @version 1
    """
    del stub_env
    (repo / "Doxyfile").write_text("INPUT = .\n", encoding="utf-8")
    check = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_INDEXABLE)
    assert check.status == CHECK_OK
    assert "Doxyfile" in check.detail

Activity · 5 steps
lines 1102–1102del stub_envlines 1103–1103(repo / "Doxyfile").write_text("INPUT = .\n", encoding="utf-8")lines 1104–1104check = _named(init_command.diagnose(repo, INIT_SCOPE_REPO), init_command.CHECK_INDEXABLE)lines 1105–1105assert check.status == CHECK_OKlines 1106–1106assert "Doxyfile" in check.detail

test_doxygen_check_is_informational_for_a_rustdoc_repo

None test_init.test_doxygen_check_is_informational_for_a_rustdoc_repo(Path repo)

A pure-Rust repo's doctor must not fail on a broken/absent doxygen.

tests/test_init.py:1462

Checks

  • assert check.status == CHECK_OK, (f"a repo with no C/C++ build path must not fail on doxygen; got {check.status!r}: " f"{check.detail}" )
  • assert "rustdoc" in check.detail.lower()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalogtest_doxygen_check_is_informational_for_a_rustdoc_repo → _check_doxygen → doxygen_supports_sqlite3
REQ-DDB-INDEX-001measuredtest_doxygen_check_is_informational_for_a_rustdoc_repo → _check_doxygen → uses_rustdoc → discover_doxyfile
REQ-DDB-PIPE-006inferredtest_doxygen_check_is_informational_for_a_rustdoc_repo → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_doxygen_check_is_informational_for_a_rustdoc_repo → _check_doxygen → _needs_doxygen
Source · 21 lines
def test_doxygen_check_is_informational_for_a_rustdoc_repo(repo: Path) -> None:
    """RUSTDOC_INTEGRATION_FEEDBACK.md, finding 4: `clew init` against a pure-Rust repo
    (no Doxyfile) reported `[fail] doxygen ... built WITHOUT sqlite3 support` and exited 1,
    even though that repo's build path (`run_rustdoc`) never shells out to doxygen at all.
    Confirmed live against `knots` before this fix — no doxygen binary needs to be present,
    broken, or even on PATH for the false failure to fire, since a `Cargo.toml` with no
    Doxyfile is enough to select `run_rustdoc` regardless of what `_check_doxygen` finds.

    @brief A Cargo.toml with no Doxyfile downgrades the doxygen check to OK, not fail.
    @return None.
    @version 1
    """
    (repo / "Cargo.toml").write_text('[package]\nname = "x"\n', encoding="utf-8")

    check = init_command._check_doxygen(repo)

    assert check.status == CHECK_OK, (
        f"a repo with no C/C++ build path must not fail on doxygen; got {check.status!r}: "
        f"{check.detail}"
    )
    assert "rustdoc" in check.detail.lower()

1 more lines, not shown

Activity · 4 steps
lines 1474–1474(repo / "Cargo.toml").write_text('[package]\nname = "x"\n', encoding="utf-8")lines 1476–1476check = init_command._check_doxygen(repo)lines 1478–1481assert check.status == CHECK_OK, ( f"a repo with no C/C++ build path must not fail on doxygen; got {check.status!r}: " f"{check.detail}" )lines 1482–1482assert "rustdoc" in check.detail.lower()

test_doxygen_with_sqlite3_support_passes_the_doctor

None test_init.test_doxygen_with_sqlite3_support_passes_the_doctor(Path stub_env, Path repo)

A capable doxygen still passes, and says so.

tests/test_init.py:1404

Checks

  • assert check.status == CHECK_OK, (f"the fixture's doxygen advertises GENERATE_SQLITE3 and must pass; got " f"{check.status!r}: {check.detail}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002measuredtest_doxygen_with_sqlite3_support_passes_the_doctor → _check_doxygen → doxygen_supports_sqlite3
REQ-DDB-INDEX-001inferredtest_doxygen_with_sqlite3_support_passes_the_doctor → _check_doxygen → uses_rustdoc → discover_doxyfile
REQ-DDB-PIPE-006measuredtest_doxygen_with_sqlite3_support_passes_the_doctor → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_doxygen_with_sqlite3_support_passes_the_doctor → _check_doxygen → _needs_doxygen
Source · 18 lines
def test_doxygen_with_sqlite3_support_passes_the_doctor(stub_env: Path, repo: Path) -> None:
    """THE POSITIVE HALF, and the half whose absence has shipped a broken check in this repo
    before: a suite with a test for the failure path and none for the success path let a
    completely broken install path stay green. Without this, narrowing the probe until it
    rejected everything would pass the test above.

    @brief A doxygen implementing GENERATE_SQLITE3 passes.
    @return None.
    @version 1
    """
    check = init_command._check_doxygen(repo)

    assert check.status == CHECK_OK, (
        f"the fixture's doxygen advertises GENERATE_SQLITE3 and must pass; got "
        f"{check.status!r}: {check.detail}"
    )

Activity · 2 steps
lines 1414–1414check = init_command._check_doxygen(repo)lines 1416–1419assert check.status == CHECK_OK, ( f"the fixture's doxygen advertises GENERATE_SQLITE3 and must pass; got " f"{check.status!r}: {check.detail}" )

test_doxygen_without_sqlite3_support_fails_the_doctor

None test_init.test_doxygen_without_sqlite3_support_fails_the_doctor(Path stub_env, Path repo)

A doxygen present but built WITHOUT sqlite3 must FAIL the doctor, not pass it.

tests/test_init.py:1361

Checks

  • assert check.status == CHECK_FAIL, (f"a doxygen that cannot write the database must not report {check.status!r} — the doctor " f"would then certify an environment in which every build fails" )
  • assert "sqlite3" in check.detail, "the message must name sqlite3, which is the actual cause"
  • assert "build" in check.detail.lower(), ("the message must say this is a BUILD option; telling someone to upgrade the version " "does not necessarily fix it and 22.04's 1.9.1 is not a version problem" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002measuredtest_doxygen_without_sqlite3_support_fails_the_doctor → _check_doxygen → doxygen_supports_sqlite3
REQ-DDB-INDEX-001inferredtest_doxygen_without_sqlite3_support_fails_the_doctor → _check_doxygen → uses_rustdoc → discover_doxyfile
REQ-DDB-PIPE-006measuredtest_doxygen_without_sqlite3_support_fails_the_doctor → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_doxygen_without_sqlite3_support_fails_the_doctor → _check_doxygen → _needs_doxygen
Source · 39 lines
def test_doxygen_without_sqlite3_support_fails_the_doctor(stub_env: Path, repo: Path) -> None:
    """gh#3, REPORTED FROM A STOCK UBUNTU 22.04 BOX. The distro's doxygen 1.9.1 is built without
    sqlite3 output; `apt install doxygen` therefore satisfies a `which()` check and every build
    still fails. doxygen IGNORES the unsupported tag rather than refusing it — it warns, buries
    that among thousands of suppressed warnings, exits ZERO and writes nothing — so the first
    observable symptom was "Expected database not found: <path>", naming neither doxygen nor
    sqlite3 nor anything the reader could act on.

    A DOCTOR THAT REPORTS [ok] HERE IS WORSE THAN NO DOCTOR, because it certifies the broken
    environment. That is what this pins.

    A BUILD OPTION, NOT A VERSION: the generator is gated behind `-Dbuild_sqlite3=ON`, so the
    message must not tell anyone to upgrade — the same version exists both ways. Asserted below,
    because "install a newer doxygen" is the advice a reader would otherwise infer and it does
    not necessarily work.

    @brief An incapable doxygen fails the check and the message names the real cause.
    @return None.
    @version 1
    """
    ## An `exit 0` binary that prints no config template — exactly what the probe reads as
    ## unsupported, and what the real 1.9.1 does (the tag is absent from its own template).
    incapable = stub_env / "doxygen"
    incapable.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
    incapable.chmod(0o755)

    check = init_command._check_doxygen(repo)

    assert check.status == CHECK_FAIL, (
        f"a doxygen that cannot write the database must not report {check.status!r} — the doctor "
        f"would then certify an environment in which every build fails"
    )
    assert "sqlite3" in check.detail, "the message must name sqlite3, which is the actual cause"
    assert "build" in check.detail.lower(), (
        "the message must say this is a BUILD option; telling someone to upgrade the version "
        "does not necessarily fix it and 22.04's 1.9.1 is not a version problem"
    )

Activity · 7 steps
lines 1383–1383incapable = stub_env / "doxygen"lines 1384–1384incapable.write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")lines 1385–1385incapable.chmod(0o755)lines 1387–1387check = init_command._check_doxygen(repo)lines 1389–1392assert check.status == CHECK_FAIL, ( f"a doxygen that cannot write the database must not report {check.status!r} — the doctor " f"would then certify an environment in which every build fails" )lines 1393–1393assert "sqlite3" in check.detail, "the message must name sqlite3, which is the actual cause"lines 1394–1397assert "build" in check.detail.lower(), ( "the message must say this is a BUILD option; telling someone to upgrade the version " "does not necessarily fix it and 22.04's 1.9.1 is not a version problem" )

test_dry_run_add_shows_the_entry_and_not_the_user_document

None test_init.test_dry_run_add_shows_the_entry_and_not_the_user_document(Path repo, Path stub_env, Path global_home, pytest.CaptureFixture[str] capsys)

add : dry-run over a live-like document prints the entry, not the document.

tests/test_init.py:637

Show on the map →

Called by none

Calls _assert_entry_only, _disclosure_document, _expected_entry, _printed_json, _run

Checks

  • assert code == 0, out
  • assert json.loads(_printed_json(out)) == _expected_entry()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main
REQ-DDB-CLI-002measuredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _expected_entry → server_entry
REQ-DDB-PIPE-006measuredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 18 lines
def test_dry_run_add_shows_the_entry_and_not_the_user_document(
    repo: Path,
    stub_env: Path,
    global_home: Path,
    capsys: pytest.CaptureFixture[str],
) -> None:
    """Run against USER scope on purpose, because that is the file with something to
    disclose. The document already holds two other servers, so the merge is an `add`
    and the old code path printed all of it."""
    del stub_env
    target = global_home / ".claude.json"
    target.write_text(json.dumps(_disclosure_document(), indent=2) + "\n", encoding="utf-8")
    code, out = _run(["--dry-run", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)
    assert code == 0, out
    _assert_entry_only(out)
    assert json.loads(_printed_json(out)) == _expected_entry()

Activity · 7 steps
lines 646–646del stub_envlines 647–647target = global_home / ".claude.json"lines 648–648target.write_text(json.dumps(_disclosure_document(), indent=2) + "\n", encoding="utf-8")lines 649–649code, out = _run(["--dry-run", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)lines 650–650assert code == 0, outlines 651–651_assert_entry_only(out)lines 652–652assert json.loads(_printed_json(out)) == _expected_entry()

test_dry_run_over_an_existing_file_changes_nothing

None test_init.test_dry_run_over_an_existing_file_changes_nothing(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

--dry-run over an existing config leaves its bytes alone.

tests/test_init.py:614

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 0, out
  • assert target.read_text(encoding="utf-8") == original
  • assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main
REQ-DDB-CLI-002measuredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 17 lines
def test_dry_run_over_an_existing_file_changes_nothing(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """The riskier half of the dry run: here there IS something to destroy."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    original = json.dumps({SERVERS_KEY: {"entropic": {"command": "entropic-mcp"}}}, indent=2) + "\n"
    target.write_text(original, encoding="utf-8")
    code, out = _run(["--dry-run"], repo, capsys)
    assert code == 0, out
    assert target.read_text(encoding="utf-8") == original
    assert not target.with_name(target.name + BACKUP_SUFFIX).exists()


# ─── gh#27: --dry-run must not publish the document it merges into ────────────

Activity · 8 steps
lines 618–618del stub_envlines 619–619target = repo / REPO_CONFIG_NAMElines 620–620original = json.dumps({SERVERS_KEY: {"entropic": {"command": "entropic-mcp"}}}, indent=2) + "\n"lines 621–621target.write_text(original, encoding="utf-8")lines 622–622code, out = _run(["--dry-run"], repo, capsys)lines 623–623assert code == 0, outlines 624–624assert target.read_text(encoding="utf-8") == originallines 625–625assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

test_dry_run_repo_scope_is_entry_scoped_as_well

None test_init.test_dry_run_repo_scope_is_entry_scoped_as_well(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

Repo scope shares the code path, so it shares the fix.

tests/test_init.py:744

Show on the map →

Called by none

Calls _assert_entry_only, _disclosure_document, _expected_entry, _printed_json, _run

Checks

  • assert code == 0, out
  • assert json.loads(_printed_json(out)) == _expected_entry()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main
REQ-DDB-CLI-002measuredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_dry_run_repo_scope_is_entry_scoped_as_well → _expected_entry → server_entry
REQ-DDB-PIPE-006measuredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 16 lines
def test_dry_run_repo_scope_is_entry_scoped_as_well(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """`_emit` takes a plan, not a scope, so `<repo>/.mcp.json` went through the exact
    same dump. The symptom is invisible there only because the file is small — which is
    a property of the FILE, not of the code, and the next `.mcp.json` this runs against
    may not be small."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    target.write_text(json.dumps(_disclosure_document(), indent=2) + "\n", encoding="utf-8")
    code, out = _run(["--dry-run"], repo, capsys)
    assert code == 0, out
    _assert_entry_only(out)
    assert json.loads(_printed_json(out)) == _expected_entry()

Activity · 7 steps
lines 751–751del stub_envlines 752–752target = repo / REPO_CONFIG_NAMElines 753–753target.write_text(json.dumps(_disclosure_document(), indent=2) + "\n", encoding="utf-8")lines 754–754code, out = _run(["--dry-run"], repo, capsys)lines 755–755assert code == 0, outlines 756–756_assert_entry_only(out)lines 757–757assert json.loads(_printed_json(out)) == _expected_entry()

test_dry_run_unchanged_prints_no_document

None test_init.test_dry_run_unchanged_prints_no_document(Path repo, Path stub_env, Path global_home, pytest.CaptureFixture[str] capsys)

unchanged : dry-run says so in one line and prints no payload.

tests/test_init.py:661

Show on the map →

Called by none

Calls _assert_entry_only, _disclosure_document, _expected_entry, _run

Checks

  • assert code == 0, out
  • assert INIT_ACTION_UNCHANGED in out, "the no-op action must be reported"
  • assert "{" not in out, "a no-op dry run must print no JSON payload whatsoever"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_dry_run_unchanged_prints_no_document → _run → init_main
REQ-DDB-CLI-002measuredtest_dry_run_unchanged_prints_no_document → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_dry_run_unchanged_prints_no_document → _expected_entry → server_entry
REQ-DDB-PIPE-006measuredtest_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 21 lines
def test_dry_run_unchanged_prints_no_document(
    repo: Path,
    stub_env: Path,
    global_home: Path,
    capsys: pytest.CaptureFixture[str],
) -> None:
    """THE CASE THAT PRODUCED gh#27. The entry is already registered and identical, so
    the run is a verified no-op — and it still dumped ~150KB of user state. A no-op
    must print no payload at all, not a smaller one."""
    del stub_env
    document = _disclosure_document()
    document[SERVERS_KEY] = {**document[SERVERS_KEY], MCP_ENTRY_NAME: _expected_entry()}
    target = global_home / ".claude.json"
    target.write_text(json.dumps(document, indent=2) + "\n", encoding="utf-8")
    code, out = _run(["--dry-run", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)
    assert code == 0, out
    _assert_entry_only(out)
    assert INIT_ACTION_UNCHANGED in out, "the no-op action must be reported"
    assert "{" not in out, "a no-op dry run must print no JSON payload whatsoever"

Activity · 10 steps
lines 670–670del stub_envlines 671–671document = _disclosure_document()lines 672–672document[SERVERS_KEY] = {**document[SERVERS_KEY], MCP_ENTRY_NAME: _expected_entry()}lines 673–673target = global_home / ".claude.json"lines 674–674target.write_text(json.dumps(document, indent=2) + "\n", encoding="utf-8")lines 675–675code, out = _run(["--dry-run", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)lines 676–676assert code == 0, outlines 677–677_assert_entry_only(out)lines 678–678assert INIT_ACTION_UNCHANGED in out, "the no-op action must be reported"lines 679–679assert "{" not in out, "a no-op dry run must print no JSON payload whatsoever"

test_dry_run_update_with_force_shows_only_the_entry_diff

None test_init.test_dry_run_update_with_force_shows_only_the_entry_diff(Path repo, Path stub_env, Path global_home, pytest.CaptureFixture[str] capsys)

update --force : dry-run shows the entry-scoped diff and nothing wider.

tests/test_init.py:688

Show on the map →

Called by none

Calls _assert_entry_only, _disclosure_document, _run

Checks

  • assert code == 0, out
  • assert "/old/path/clew-mcp" in out, "the diff must show what would be replaced"
  • assert "+++ proposed" in out, "the entry-level unified diff must be shown"
  • assert target.read_text(encoding="utf-8") == original, "--dry-run must not write"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main
REQ-DDB-CLI-002measuredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 24 lines
def test_dry_run_update_with_force_shows_only_the_entry_diff(
    repo: Path,
    stub_env: Path,
    global_home: Path,
    capsys: pytest.CaptureFixture[str],
) -> None:
    """The useful half of the dry run, which the fix must NOT cost: someone about to
    `--force` over a hand-tuned entry needs to see what changes. They get `plan.diff`,
    which is rendered over the entry alone."""
    del stub_env
    document = _disclosure_document()
    stale = {"type": "stdio", "command": "/old/path/clew-mcp", "args": ["--repo", "/old"]}
    document[SERVERS_KEY] = {**document[SERVERS_KEY], MCP_ENTRY_NAME: stale}
    target = global_home / ".claude.json"
    original = json.dumps(document, indent=2) + "\n"
    target.write_text(original, encoding="utf-8")
    code, out = _run(["--dry-run", "--force", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)
    assert code == 0, out
    _assert_entry_only(out)
    assert "/old/path/clew-mcp" in out, "the diff must show what would be replaced"
    assert "+++ proposed" in out, "the entry-level unified diff must be shown"
    assert target.read_text(encoding="utf-8") == original, "--dry-run must not write"

Activity · 13 steps
lines 697–697del stub_envlines 698–698document = _disclosure_document()lines 699–699stale = {"type": "stdio", "command": "/old/path/clew-mcp", "args": ["--repo", "/old"]}lines 700–700document[SERVERS_KEY] = {**document[SERVERS_KEY], MCP_ENTRY_NAME: stale}lines 701–701target = global_home / ".claude.json"lines 702–702original = json.dumps(document, indent=2) + "\n"lines 703–703target.write_text(original, encoding="utf-8")lines 704–704code, out = _run(["--dry-run", "--force", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)lines 705–705assert code == 0, outlines 706–706_assert_entry_only(out)lines 707–707assert "/old/path/clew-mcp" in out, "the diff must show what would be replaced"lines 708–708assert "+++ proposed" in out, "the entry-level unified diff must be shown"lines 709–709assert target.read_text(encoding="utf-8") == original, "--dry-run must not write"

test_dry_run_update_without_force_refuses_without_dumping

None test_init.test_dry_run_update_without_force_refuses_without_dumping(Path repo, Path stub_env, Path global_home, pytest.CaptureFixture[str] capsys)

update without --force : the refusal is entry-scoped too.

tests/test_init.py:718

Show on the map →

Called by none

Calls _assert_entry_only, _disclosure_document, _run

Checks

  • assert code == 1, out
  • assert "--force" in out, "the refusal must name the override"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main
REQ-DDB-CLI-002measuredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 21 lines
def test_dry_run_update_without_force_refuses_without_dumping(
    repo: Path,
    stub_env: Path,
    global_home: Path,
    capsys: pytest.CaptureFixture[str],
) -> None:
    """A different code path from the three above: `_execute` refuses before `_emit` is
    reached, so this pins the OTHER exit that prints a diff. It was already
    entry-scoped; this stops it regressing to match what `_emit` used to do."""
    del stub_env
    document = _disclosure_document()
    stale = {"type": "stdio", "command": "/old/path/clew-mcp", "args": []}
    document[SERVERS_KEY] = {**document[SERVERS_KEY], MCP_ENTRY_NAME: stale}
    target = global_home / ".claude.json"
    target.write_text(json.dumps(document, indent=2) + "\n", encoding="utf-8")
    code, out = _run(["--dry-run", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)
    assert code == 1, out
    _assert_entry_only(out)
    assert "--force" in out, "the refusal must name the override"

Activity · 10 steps
lines 727–727del stub_envlines 728–728document = _disclosure_document()lines 729–729stale = {"type": "stdio", "command": "/old/path/clew-mcp", "args": []}lines 730–730document[SERVERS_KEY] = {**document[SERVERS_KEY], MCP_ENTRY_NAME: stale}lines 731–731target = global_home / ".claude.json"lines 732–732target.write_text(json.dumps(document, indent=2) + "\n", encoding="utf-8")lines 733–733code, out = _run(["--dry-run", "--scope", INIT_SCOPE_GLOBAL], repo, capsys)lines 734–734assert code == 1, outlines 735–735_assert_entry_only(out)lines 736–736assert "--force" in out, "the refusal must name the override"

test_dry_run_writes_nothing

None test_init.test_dry_run_writes_nothing(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

--dry-run prints the ENTRY it would write, and writes nothing at all.

tests/test_init.py:591

Show on the map →

Called by none

Calls _expected_entry, _printed_json, _run

Checks

  • assert code == 0, out
  • assert not (repo / REPO_CONFIG_NAME).exists(), "--dry-run must not create the file"
  • assert json.loads(_printed_json(out)) == _expected_entry()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_dry_run_writes_nothing → _run → init_main
REQ-DDB-CLI-002measuredtest_dry_run_writes_nothing → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_dry_run_writes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_dry_run_writes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_dry_run_writes_nothing → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_dry_run_writes_nothing → _expected_entry → server_entry
REQ-DDB-PIPE-006measuredtest_dry_run_writes_nothing → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_dry_run_writes_nothing → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_dry_run_writes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 18 lines
def test_dry_run_writes_nothing(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """SPEC CHANGED BY gh#27, deliberately. This used to assert the printed JSON was
    the whole re-serialised document (`plan.text`), which is the defect: on
    `--scope global` that document is the user's entire `~/.claude.json`. The dry run
    now prints the entry under review, so the assertion parses that instead.

    Nothing reviewable was lost here even though this is the `create` case — the
    document the old version printed was this entry wrapped in `mcpServers` and
    nothing else."""
    del stub_env
    code, out = _run(["--dry-run"], repo, capsys)
    assert code == 0, out
    assert not (repo / REPO_CONFIG_NAME).exists(), "--dry-run must not create the file"
    assert json.loads(_printed_json(out)) == _expected_entry()

Activity · 5 steps
lines 602–602del stub_envlines 603–603code, out = _run(["--dry-run"], repo, capsys)lines 604–604assert code == 0, outlines 605–605assert not (repo / REPO_CONFIG_NAME).exists(), "--dry-run must not create the file"lines 606–606assert json.loads(_printed_json(out)) == _expected_entry()

test_every_check_prints_before_a_refusal

None test_init.test_every_check_prints_before_a_refusal(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

Every check is printed even on a run that refuses to write.

tests/test_init.py:1251

Show on the map →

Called by none

Calls _run

Checks

  • assert name in out, f"the {name} check must be reported even on a refusal"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_every_check_prints_before_a_refusal → _run → init_main
REQ-DDB-CLI-002measuredtest_every_check_prints_before_a_refusal → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_every_check_prints_before_a_refusal → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 19 lines
def test_every_check_prints_before_a_refusal(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """On a refusing run the REPORT is the product. A user whose doxygen is also
    missing needs to learn that on the same run that told them the entry
    conflicts, not one re-run later."""
    (stub_env / CONSOLE_SCRIPT).unlink()
    _code, out = _run([], repo, capsys)
    for name in (
        init_command.CHECK_CLIENT_CONFIG,
        init_command.CHECK_SERVER_COMMAND,
        init_command.CHECK_MCP_SDK,
        init_command.CHECK_DOXYGEN,
        init_command.CHECK_INDEXABLE,
        init_command.CHECK_DECLARATION,
    ):
        assert name in out, f"the {name} check must be reported even on a refusal"

Activity · 4 steps
lines 1257–1257(stub_env / CONSOLE_SCRIPT).unlink()lines 1258–1258_code, out = _run([], repo, capsys)lines 1259–1259◇ for name in (lines 1267–1267assert name in out, f"the {name} check must be reported even on a refusal"

test_existing_indentation_is_preserved

None test_init.test_existing_indentation_is_preserved(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

A file's own indentation survives the merge.

tests/test_init.py:765

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 0, out
  • assert '\n "mcpServers"' in text, "4-space indentation must be preserved"
  • assert '\n "mcpServers"' not in text, f"reformatted to {DEFAULT_INDENT} spaces"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_existing_indentation_is_preserved → _run → init_main
REQ-DDB-CLI-002measuredtest_existing_indentation_is_preserved → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_existing_indentation_is_preserved → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_existing_indentation_is_preserved → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_existing_indentation_is_preserved → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_existing_indentation_is_preserved → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_existing_indentation_is_preserved → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_existing_indentation_is_preserved → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_existing_indentation_is_preserved → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 18 lines
def test_existing_indentation_is_preserved(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """A config the user maintains by hand must not be reformatted to register a
    server: a diff that is 90% whitespace hides the one line that matters."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    target.write_text(
        json.dumps({SERVERS_KEY: {"entropic": {"command": "entropic-mcp"}}}, indent=4) + "\n",
        encoding="utf-8",
    )
    code, out = _run([], repo, capsys)
    assert code == 0, out
    text = target.read_text(encoding="utf-8")
    assert '\n    "mcpServers"' in text, "4-space indentation must be preserved"
    assert '\n  "mcpServers"' not in text, f"reformatted to {DEFAULT_INDENT} spaces"

Activity · 8 steps
lines 770–770del stub_envlines 771–771target = repo / REPO_CONFIG_NAMElines 772–775target.write_text( json.dumps({SERVERS_KEY: {"entropic": {"command": "entropic-mcp"}}}, indent=4) + "\n", encoding="utf-8", )lines 776–776code, out = _run([], repo, capsys)lines 777–777assert code == 0, outlines 778–778text = target.read_text(encoding="utf-8")lines 779–779assert '\n "mcpServers"' in text, "4-space indentation must be preserved"lines 780–780assert '\n "mcpServers"' not in text, f"reformatted to {DEFAULT_INDENT} spaces"

test_force_replaces_the_differing_entry

None test_init.test_force_replaces_the_differing_entry(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

--force replaces the differing entry and keeps the neighbours.

tests/test_init.py:458

Show on the map →

Called by none

Calls _expected_entry, _run

Checks

  • assert code == 0, out
  • assert after[SERVERS_KEY][MCP_ENTRY_NAME] == _expected_entry()
  • assert after[SERVERS_KEY]["entropic"] == {
  • assert INIT_ACTION_UPDATE in out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_force_replaces_the_differing_entry → _run → init_main
REQ-DDB-CLI-002measuredtest_force_replaces_the_differing_entry → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_force_replaces_the_differing_entry → _expected_entry → server_entry
REQ-DDB-PIPE-006measuredtest_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 32 lines
def test_force_replaces_the_differing_entry(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """`--force` is scoped to OUR key. Overriding the conflict rule must not turn
    into permission to rewrite the document."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    target.write_text(
        json.dumps(
            {
                SERVERS_KEY: {
                    "entropic": {"type": "stdio", "command": "entropic-mcp", "args": []},
                    MCP_ENTRY_NAME: {"type": "stdio", "command": "stale", "args": []},
                }
            },
            indent=2,
        )
        + "\n",
        encoding="utf-8",
    )
    code, out = _run(["--force"], repo, capsys)
    assert code == 0, out
    after = json.loads(target.read_text(encoding="utf-8"))
    assert after[SERVERS_KEY][MCP_ENTRY_NAME] == _expected_entry()
    assert after[SERVERS_KEY]["entropic"] == {
        "type": "stdio",
        "command": "entropic-mcp",
        "args": [],
    }
    assert INIT_ACTION_UPDATE in out

Activity · 9 steps
lines 463–463del stub_envlines 464–464target = repo / REPO_CONFIG_NAMElines 465–477target.write_text( json.dumps( { SERVERS_KEY: { "entropic": {"type": "stdio", "command": "entropic-mcp", "args": []}, MCP_ENTRY_NAME: {"type": "stdio", "command": "stale", "args": []}, } }, indent=2, ) + "\n", encoding="utf-8", )lines 478–478code, out = _run(["--force"], repo, capsys)lines 479–479assert code == 0, outlines 480–480after = json.loads(target.read_text(encoding="utf-8"))lines 481–481assert after[SERVERS_KEY][MCP_ENTRY_NAME] == _expected_entry()lines 482–486assert after[SERVERS_KEY]["entropic"] == { "type": "stdio", "command": "entropic-mcp", "args": [], }lines 487–487assert INIT_ACTION_UPDATE in out

test_fresh_repo_creates_the_config

None test_init.test_fresh_repo_creates_the_config(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

A fresh repo gets a .mcp.json holding exactly this server.

tests/test_init.py:335

Show on the map →

Called by none

Calls _expected_entry, _run

Checks

  • assert code == 0, out
  • assert json.loads(target.read_text(encoding="utf-8")) == {
  • assert _expected_entry()["args"] == [], "no scope may pin the server any more"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_fresh_repo_creates_the_config → _run → init_main
REQ-DDB-CLI-002measuredtest_fresh_repo_creates_the_config → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_fresh_repo_creates_the_config → _expected_entry → server_entry
REQ-DDB-PIPE-006measuredtest_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 21 lines
def test_fresh_repo_creates_the_config(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """The baseline. NEITHER scope passes `--repo` any more (gh#22).

    Repo scope used to write `--repo .`, which pinned the server: it refused to
    retarget, so a session could not index a second repository (gh#19). And the pin
    was not even reliable at the job it was for — a stale one invalidated a 36-cell
    benchmark run. The server now DERIVES its target from `$CLAUDE_PROJECT_DIR`, which
    resolves to the project the config is committed in, whereas `--repo .` resolved
    against the LAUNCHING process's cwd."""
    del stub_env
    code, out = _run([], repo, capsys)
    target = repo / REPO_CONFIG_NAME
    assert code == 0, out
    assert json.loads(target.read_text(encoding="utf-8")) == {
        SERVERS_KEY: {MCP_ENTRY_NAME: _expected_entry()}
    }
    assert _expected_entry()["args"] == [], "no scope may pin the server any more"

Activity · 6 steps
lines 346–346del stub_envlines 347–347code, out = _run([], repo, capsys)lines 348–348target = repo / REPO_CONFIG_NAMElines 349–349assert code == 0, outlines 350–352assert json.loads(target.read_text(encoding="utf-8")) == { SERVERS_KEY: {MCP_ENTRY_NAME: _expected_entry()} }lines 353–353assert _expected_entry()["args"] == [], "no scope may pin the server any more"

test_global_scope_never_uses_a_relative_command

None test_init.test_global_scope_never_uses_a_relative_command(Path repo)

Global scope never records a relative command.

tests/test_init.py:1027

Checks

  • assert resolution.command == str(script)
  • assert Path(resolution.command).is_absolute(), "user scope must record an absolute command"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_global_scope_never_uses_a_relative_command → resolve_server_command
Source · 13 lines
def test_global_scope_never_uses_a_relative_command(repo: Path) -> None:
    """A user-scope config loads from every directory the user works in, so a
    relative command there resolves against whatever the cwd happens to be."""
    script = repo / ".venv" / "bin" / CONSOLE_SCRIPT
    script.parent.mkdir(parents=True)
    script.touch()
    resolution = resolve_server_command(
        repo, INIT_SCOPE_GLOBAL, which=lambda _cmd: None, bindir=script.parent
    )
    assert resolution.command == str(script)
    assert Path(resolution.command).is_absolute(), "user scope must record an absolute command"

Activity · 6 steps
lines 1030–1030script = repo / ".venv" / "bin" / CONSOLE_SCRIPTlines 1031–1031script.parent.mkdir(parents=True)lines 1032–1032script.touch()lines 1033–1035resolution = resolve_server_command( repo, INIT_SCOPE_GLOBAL, which=lambda _cmd: None, bindir=script.parent )lines 1036–1036assert resolution.command == str(script)lines 1037–1037assert Path(resolution.command).is_absolute(), "user scope must record an absolute command"

test_global_scope_preserves_the_user_state_document

None test_init.test_global_scope_preserves_the_user_state_document(Path repo, Path stub_env, Path global_home, pytest.CaptureFixture[str] capsys)

Global scope writes top-level mcpServers and preserves the rest.

tests/test_init.py:853

Show on the map →

Called by none

Calls _expected_entry, _run, list

Checks

  • assert code == 0, out
  • assert list(after) == list(LIVE_LIKE_DOCUMENT)
  • assert after["userID"] == LIVE_LIKE_DOCUMENT["userID"]
  • assert after["projects"] == LIVE_LIKE_DOCUMENT["projects"]
  • assert after[SERVERS_KEY][MCP_ENTRY_NAME] == _expected_entry()
  • assert after[SERVERS_KEY][MCP_ENTRY_NAME]["args"] == [], "user scope must stay dynamic"
  • assert not (repo / REPO_CONFIG_NAME).exists(), "global scope must not touch the repo"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_global_scope_preserves_the_user_state_document → _run → init_main
REQ-DDB-CLI-002measuredtest_global_scope_preserves_the_user_state_document → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_global_scope_preserves_the_user_state_document → _expected_entry → server_entry
REQ-DDB-PIPE-006measuredtest_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 26 lines
def test_global_scope_preserves_the_user_state_document(
    repo: Path,
    stub_env: Path,
    global_home: Path,
    capsys: pytest.CaptureFixture[str],
) -> None:
    """The stakes case, run against a stand-in for the real file.

    `args == []` is no longer a SCOPE asymmetry — both scopes are unpinned now — but it
    is still worth pinning here, because a user-scope config follows the user between
    projects and a `--repo` of any kind in it would freeze every session onto one
    repository."""
    del stub_env
    target = global_home / ".claude.json"
    target.write_text(json.dumps(LIVE_LIKE_DOCUMENT, indent=2) + "\n", encoding="utf-8")
    code, out = _run(["--scope", INIT_SCOPE_GLOBAL], repo, capsys)
    assert code == 0, out
    after = json.loads(target.read_text(encoding="utf-8"))
    assert list(after) == list(LIVE_LIKE_DOCUMENT)
    assert after["userID"] == LIVE_LIKE_DOCUMENT["userID"]
    assert after["projects"] == LIVE_LIKE_DOCUMENT["projects"]
    assert after[SERVERS_KEY][MCP_ENTRY_NAME] == _expected_entry()
    assert after[SERVERS_KEY][MCP_ENTRY_NAME]["args"] == [], "user scope must stay dynamic"
    assert not (repo / REPO_CONFIG_NAME).exists(), "global scope must not touch the repo"

Activity · 12 steps
lines 865–865del stub_envlines 866–866target = global_home / ".claude.json"lines 867–867target.write_text(json.dumps(LIVE_LIKE_DOCUMENT, indent=2) + "\n", encoding="utf-8")lines 868–868code, out = _run(["--scope", INIT_SCOPE_GLOBAL], repo, capsys)lines 869–869assert code == 0, outlines 870–870after = json.loads(target.read_text(encoding="utf-8"))lines 871–871assert list(after) == list(LIVE_LIKE_DOCUMENT)lines 872–872assert after["userID"] == LIVE_LIKE_DOCUMENT["userID"]lines 873–873assert after["projects"] == LIVE_LIKE_DOCUMENT["projects"]lines 874–874assert after[SERVERS_KEY][MCP_ENTRY_NAME] == _expected_entry()lines 875–875assert after[SERVERS_KEY][MCP_ENTRY_NAME]["args"] == [], "user scope must stay dynamic"lines 876–876assert not (repo / REPO_CONFIG_NAME).exists(), "global scope must not touch the repo"

test_global_scope_refuses_without_evidence

None test_init.test_global_scope_refuses_without_evidence(Path repo, Path stub_env, Path tmp_path, pytest.MonkeyPatch monkeypatch, pytest.CaptureFixture[str] capsys)

With no declaration and no evidence, global scope refuses and creates nothing.

tests/test_init.py:901

Checks

  • assert global_config_path().is_relative_to(tmp_path), "precondition: the write target is in tmp"
  • assert not global_config_available()
  • assert code == 1
  • assert not (fake_home / ".claude.json").exists(), "nothing may be created on a refusal"
  • assert str(fake_home / ".claude.json") in out
  • assert CLAUDE_CONFIG_DIR_ENV in out, "the refusal must name the override that fixes it"
  • assert INIT_SCOPE_REPO in out, "and the scope that needs no evidence"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_global_scope_refuses_without_evidence → _run → init_main
REQ-DDB-CLI-002measuredtest_global_scope_refuses_without_evidence → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_global_scope_refuses_without_evidence → global_config_path
REQ-DDB-PIPE-006measuredtest_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 30 lines
def test_global_scope_refuses_without_evidence(
    repo: Path,
    stub_env: Path,
    tmp_path: Path,
    monkeypatch: pytest.MonkeyPatch,
    capsys: pytest.CaptureFixture[str],
) -> None:
    """The ONE test that unsets `CLAUDE_CONFIG_DIR`, so it patches `Path.home` in
    the same breath and asserts the resolved path is under tmp BEFORE running
    anything — with the variable gone, an unpatched `Path.home` would point the
    write at the developer's real config.

    The behaviour under test: writing a config to a location that was GUESSED is
    worse than writing none, so with no evidence of a Claude Code install the
    command refuses and names every place it looked."""
    del stub_env
    fake_home = tmp_path / "empty-home"
    fake_home.mkdir()
    monkeypatch.delenv(CLAUDE_CONFIG_DIR_ENV, raising=False)
    monkeypatch.setattr(Path, "home", classmethod(lambda cls: fake_home))
    assert global_config_path().is_relative_to(tmp_path), "precondition: the write target is in tmp"
    assert not global_config_available()
    code, out = _run(["--scope", INIT_SCOPE_GLOBAL], repo, capsys)
    assert code == 1
    assert not (fake_home / ".claude.json").exists(), "nothing may be created on a refusal"
    assert str(fake_home / ".claude.json") in out
    assert CLAUDE_CONFIG_DIR_ENV in out, "the refusal must name the override that fixes it"
    assert INIT_SCOPE_REPO in out, "and the scope that needs no evidence"

Activity · 13 steps
lines 916–916del stub_envlines 917–917fake_home = tmp_path / "empty-home"lines 918–918fake_home.mkdir()lines 919–919monkeypatch.delenv(CLAUDE_CONFIG_DIR_ENV, raising=False)lines 920–920monkeypatch.setattr(Path, "home", classmethod(lambda cls: fake_home))lines 921–921assert global_config_path().is_relative_to(tmp_path), "precondition: the write target is in tmp"lines 922–922assert not global_config_available()lines 923–923code, out = _run(["--scope", INIT_SCOPE_GLOBAL], repo, capsys)lines 924–924assert code == 1lines 925–925assert not (fake_home / ".claude.json").exists(), "nothing may be created on a refusal"lines 926–926assert str(fake_home / ".claude.json") in outlines 927–927assert CLAUDE_CONFIG_DIR_ENV in out, "the refusal must name the override that fixes it"lines 928–928assert INIT_SCOPE_REPO in out, "and the scope that needs no evidence"

test_identical_entry_is_a_no_op_on_bytes

None test_init.test_identical_entry_is_a_no_op_on_bytes(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

Re-running against an identical entry rewrites nothing.

tests/test_init.py:397

Show on the map →

Called by none

Calls _expected_entry, _run, list, plan_merge

Checks

  • assert first_code == 0
  • assert second_code == 0, out
  • assert target.read_bytes() == original, "an identical entry must not rewrite the file"
  • assert not target.with_name(target.name + BACKUP_SUFFIX).exists(), ("no write happened, so there is nothing to back up" )
  • assert "already registered and identical" in out, "the no-op must be reported as one"
  • assert list(json.loads(original)[SERVERS_KEY]) == [MCP_ENTRY_NAME], "no duplicate entry"
  • assert plan_merge(target, _expected_entry()).action == INIT_ACTION_UNCHANGED

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main
REQ-DDB-CLI-002measuredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_identical_entry_is_a_no_op_on_bytes → plan_merge
REQ-DDB-PIPE-006measuredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 24 lines
def test_identical_entry_is_a_no_op_on_bytes(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """Asserted on bytes AND on the absence of a backup, because those catch
    different mistakes: identical CONTENT could still have been produced by a
    rewrite (which would leave a `.bak` and churn the file's mtime), and this
    repo's own committed `.mcp.json` is supposed to make `init` here a genuine
    no-op rather than a re-write that happens to match."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    first_code, _ = _run([], repo, capsys)
    assert first_code == 0
    original = target.read_bytes()
    second_code, out = _run([], repo, capsys)
    assert second_code == 0, out
    assert target.read_bytes() == original, "an identical entry must not rewrite the file"
    assert not target.with_name(target.name + BACKUP_SUFFIX).exists(), (
        "no write happened, so there is nothing to back up"
    )
    assert "already registered and identical" in out, "the no-op must be reported as one"
    assert list(json.loads(original)[SERVERS_KEY]) == [MCP_ENTRY_NAME], "no duplicate entry"
    assert plan_merge(target, _expected_entry()).action == INIT_ACTION_UNCHANGED

Activity · 12 steps
lines 405–405del stub_envlines 406–406target = repo / REPO_CONFIG_NAMElines 407–407first_code, _ = _run([], repo, capsys)lines 408–408assert first_code == 0lines 409–409original = target.read_bytes()lines 410–410second_code, out = _run([], repo, capsys)lines 411–411assert second_code == 0, outlines 412–412assert target.read_bytes() == original, "an identical entry must not rewrite the file"lines 413–415assert not target.with_name(target.name + BACKUP_SUFFIX).exists(), ( "no write happened, so there is nothing to back up" )lines 416–416assert "already registered and identical" in out, "the no-op must be reported as one"lines 417–417assert list(json.loads(original)[SERVERS_KEY]) == [MCP_ENTRY_NAME], "no duplicate entry"lines 418–418assert plan_merge(target, _expected_entry()).action == INIT_ACTION_UNCHANGED

test_init_is_imported_lazily_inside_main

None test_init.test_init_is_imported_lazily_inside_main()

The init import stays inside main() , not at module scope.

tests/test_init.py:1315

Show on the map →

Called by none

Calls none

Checks

  • assert "from .init_command import" in source
  • assert "from .init_command import" not in inspect.getsource(cli).split("def main(")[0]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
Source · 11 lines
def test_init_is_imported_lazily_inside_main() -> None:
    """`init` must stay runnable on an install missing the pipeline's heavier
    optional dependencies — it is the command that DIAGNOSES a broken install, so
    it cannot be the command that needs a whole one to start."""
    import inspect

    source = inspect.getsource(cli.main)
    assert "from .init_command import" in source
    assert "from .init_command import" not in inspect.getsource(cli).split("def main(")[0]

Activity · 4 steps
lines 1319–1319import inspectlines 1321–1321source = inspect.getsource(cli.main)lines 1322–1322assert "from .init_command import" in sourcelines 1323–1323assert "from .init_command import" not in inspect.getsource(cli).split("def main(")[0]

test_live_like_document_round_trips_with_only_servers_changed

None test_init.test_live_like_document_round_trips_with_only_servers_changed(Path tmp_path)

A realistic multi-key document round-trips with one key changed.

tests/test_init.py:807

Show on the map →

Called by none

Calls _expected_entry, apply_plan, list, plan_merge

Checks

  • assert list(after) == list(LIVE_LIKE_DOCUMENT), "top-level key ORDER must be preserved"
  • assert after[key] == value, f"unrelated key {key} was altered"
  • assert list(after[SERVERS_KEY]) == ["entropic", "other-tool", MCP_ENTRY_NAME]
  • assert after[SERVERS_KEY][MCP_ENTRY_NAME] == entry
  • assert after[SERVERS_KEY]["entropic"] == LIVE_LIKE_DOCUMENT[SERVERS_KEY]["entropic"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002measuredtest_live_like_document_round_trips_with_only_servers_changed → apply_plan
REQ-DDB-MCP-001measuredtest_live_like_document_round_trips_with_only_servers_changed → plan_merge
Source · 22 lines
def test_live_like_document_round_trips_with_only_servers_changed(tmp_path: Path) -> None:
    """Shaped like the real user-scope file, which is the one this tool can do
    irreversible damage to. Every other top-level key must come back deep-equal
    AND in its original position — `mcpServers` sits in the middle here on purpose,
    because a merge that rebuilt the document would move it to the end."""
    target = tmp_path / "claude-like.json"
    target.write_text(json.dumps(LIVE_LIKE_DOCUMENT, indent=2) + "\n", encoding="utf-8")
    entry = _expected_entry()
    apply_plan(plan_merge(target, entry))
    after = json.loads(target.read_text(encoding="utf-8"))
    assert list(after) == list(LIVE_LIKE_DOCUMENT), "top-level key ORDER must be preserved"
    for key, value in LIVE_LIKE_DOCUMENT.items():
        if key != SERVERS_KEY:
            assert after[key] == value, f"unrelated key {key} was altered"
    assert list(after[SERVERS_KEY]) == ["entropic", "other-tool", MCP_ENTRY_NAME]
    assert after[SERVERS_KEY][MCP_ENTRY_NAME] == entry
    assert after[SERVERS_KEY]["entropic"] == LIVE_LIKE_DOCUMENT[SERVERS_KEY]["entropic"]


# ─── global scope, and the isolation that makes testing it safe ──────────────

Activity · 12 steps
lines 812–812target = tmp_path / "claude-like.json"lines 813–813target.write_text(json.dumps(LIVE_LIKE_DOCUMENT, indent=2) + "\n", encoding="utf-8")lines 814–814entry = _expected_entry()lines 815–815apply_plan(plan_merge(target, entry))lines 816–816after = json.loads(target.read_text(encoding="utf-8"))lines 817–817assert list(after) == list(LIVE_LIKE_DOCUMENT), "top-level key ORDER must be preserved"lines 818–818◇ for key, value in LIVE_LIKE_DOCUMENT.items()lines 819–819◇ if key != SERVERS_KEYlines 820–820assert after[key] == value, f"unrelated key {key} was altered"lines 821–821assert list(after[SERVERS_KEY]) == ["entropic", "other-tool", MCP_ENTRY_NAME]lines 822–822assert after[SERVERS_KEY][MCP_ENTRY_NAME] == entrylines 823–823assert after[SERVERS_KEY]["entropic"] == LIVE_LIKE_DOCUMENT[SERVERS_KEY]["entropic"]

test_malformed_json_is_refused_and_left_alone

None test_init.test_malformed_json_is_refused_and_left_alone(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

Malformed JSON is refused, and the file is not rewritten or truncated.

tests/test_init.py:537

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 1
  • assert target.read_text(encoding="utf-8") == broken, "a malformed file must not be rewritten"
  • assert str(target) in out, "the refusal must name the file to fix"
  • assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_malformed_json_is_refused_and_left_alone → _run → init_main
REQ-DDB-CLI-002measuredtest_malformed_json_is_refused_and_left_alone → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_malformed_json_is_refused_and_left_alone → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 18 lines
def test_malformed_json_is_refused_and_left_alone(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """The only way to "handle" an unparseable config is to overwrite it, which
    destroys entries the user wrote by hand. A half-finished edit is the normal
    reason a config does not parse, so this is a state a real user is in — and the
    file has to still be there afterwards for them to finish fixing it."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    broken = '{\n  "mcpServers": {\n    "entropic": {"command": "entropic-mcp",\n'
    target.write_text(broken, encoding="utf-8")
    code, out = _run([], repo, capsys)
    assert code == 1
    assert target.read_text(encoding="utf-8") == broken, "a malformed file must not be rewritten"
    assert str(target) in out, "the refusal must name the file to fix"
    assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

Activity · 9 steps
lines 544–544del stub_envlines 545–545target = repo / REPO_CONFIG_NAMElines 546–546broken = '{\n "mcpServers": {\n "entropic": {"command": "entropic-mcp",\n'lines 547–547target.write_text(broken, encoding="utf-8")lines 548–548code, out = _run([], repo, capsys)lines 549–549assert code == 1lines 550–550assert target.read_text(encoding="utf-8") == broken, "a malformed file must not be rewritten"lines 551–551assert str(target) in out, "the refusal must name the file to fix"lines 552–552assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

test_mcp_sdk_check_passes_when_the_server_can_be_built

None test_init.test_mcp_sdk_check_passes_when_the_server_can_be_built(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

The SDK check passes on an environment whose server can actually start.

tests/test_init.py:1192

Show on the map →

Called by none

Calls _run, build_server

Checks

  • assert "[fail] mcp-sdk" not in out, (f"the server builds under this SDK, so the doctor must not fail it:\n{out}" )
  • assert code == 0, f"a working environment must exit clean:\n{out}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main
REQ-DDB-CLI-002measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-006measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-034measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → build_server → _register_prompts
REQ-DDB-WIKI-054measuredtest_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 26 lines
def test_mcp_sdk_check_passes_when_the_server_can_be_built(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """THE TEST THAT WAS MISSING, and its absence shipped a broken install path.

    `_check_mcp_sdk` had a test for its FAIL path and none for its OK path, so the
    whole suite stayed green while `init` hard-failed every environment holding the
    only SDK version a fresh `pip install` resolves. The probe named
    `mcp.server.fastmcp` — deleted in 2.x — and described it as "the server's own
    import line", which stopped being true when `_sdk` took over that import.

    So this asserts against the real environment rather than a stub: if
    `build_server()` works here, the doctor must say so. A check that disagrees with
    the thing it checks is the defect, whichever way it disagrees.
    """
    del stub_env
    from clew.mcp_server.server import build_server

    build_server()  # the ground truth: the server constructs under this SDK
    code, out = _run([], repo, capsys)
    assert "[fail] mcp-sdk" not in out, (
        f"the server builds under this SDK, so the doctor must not fail it:\n{out}"
    )
    assert code == 0, f"a working environment must exit clean:\n{out}"

Activity · 6 steps
lines 1207–1207del stub_envlines 1208–1208from clew.mcp_server.server import build_serverlines 1210–1210build_server()lines 1211–1211code, out = _run([], repo, capsys)lines 1212–1214assert "[fail] mcp-sdk" not in out, ( f"the server builds under this SDK, so the doctor must not fail it:\n{out}" )lines 1215–1215assert code == 0, f"a working environment must exit clean:\n{out}"

test_missing_console_script_blocks_the_write

None test_init.test_missing_console_script_blocks_the_write(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

No script anywhere blocks the write entirely.

tests/test_init.py:1045

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 1
  • assert not (repo / REPO_CONFIG_NAME).exists(), "no config may name a missing command"
  • assert CONSOLE_SCRIPT in out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_missing_console_script_blocks_the_write → _run → init_main
REQ-DDB-CLI-002measuredtest_missing_console_script_blocks_the_write → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_missing_console_script_blocks_the_write → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 13 lines
def test_missing_console_script_blocks_the_write(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """Writing a `command` that does not exist is the worst outcome available: the
    client reports "failed to connect" with no cause, and the config LOOKS right.
    So this is one of only two blocking checks."""
    (stub_env / CONSOLE_SCRIPT).unlink()
    code, out = _run([], repo, capsys)
    assert code == 1
    assert not (repo / REPO_CONFIG_NAME).exists(), "no config may name a missing command"
    assert CONSOLE_SCRIPT in out

Activity · 5 steps
lines 1051–1051(stub_env / CONSOLE_SCRIPT).unlink()lines 1052–1052code, out = _run([], repo, capsys)lines 1053–1053assert code == 1lines 1054–1054assert not (repo / REPO_CONFIG_NAME).exists(), "no config may name a missing command"lines 1055–1055assert CONSOLE_SCRIPT in out

test_missing_doxygen_fails_but_still_registers

None test_init.test_missing_doxygen_fails_but_still_registers(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

Missing doxygen fails the run but still registers the server.

tests/test_init.py:1172

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 1, "a missing doxygen is a real failure and must be reported as one"
  • assert (repo / REPO_CONFIG_NAME).is_file(), "but the registration still lands"
  • assert json.loads((repo / REPO_CONFIG_NAME).read_text(encoding="utf-8"))[SERVERS_KEY]
  • assert "doxygen is not on PATH" in out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_missing_doxygen_fails_but_still_registers → _run → init_main
REQ-DDB-CLI-002measuredtest_missing_doxygen_fails_but_still_registers → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_missing_doxygen_fails_but_still_registers → _run → init_main → _register → config_path
REQ-DDB-PIPE-006inferredtest_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012measuredtest_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 15 lines
def test_missing_doxygen_fails_but_still_registers(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """doxygen is a SUBPROCESS dependency, invisible to pip, so nothing else in
    the install path notices it is gone — the first build does. The fix is a
    package install, not a config edit, so withholding the registration would only
    make the user run `init` twice."""
    (stub_env / "doxygen").unlink()
    code, out = _run([], repo, capsys)
    assert code == 1, "a missing doxygen is a real failure and must be reported as one"
    assert (repo / REPO_CONFIG_NAME).is_file(), "but the registration still lands"
    assert json.loads((repo / REPO_CONFIG_NAME).read_text(encoding="utf-8"))[SERVERS_KEY]
    assert "doxygen is not on PATH" in out

Activity · 6 steps
lines 1179–1179(stub_env / "doxygen").unlink()lines 1180–1180code, out = _run([], repo, capsys)lines 1181–1181assert code == 1, "a missing doxygen is a real failure and must be reported as one"lines 1182–1182assert (repo / REPO_CONFIG_NAME).is_file(), "but the registration still lands"lines 1183–1183assert json.loads((repo / REPO_CONFIG_NAME).read_text(encoding="utf-8"))[SERVERS_KEY]lines 1184–1184assert "doxygen is not on PATH" in out

test_no_backup_is_left_when_the_file_is_created

None test_init.test_no_backup_is_left_when_the_file_is_created(Path tmp_path)

Creating a file leaves no backup — there was nothing to lose.

tests/test_init.py:523

Show on the map →

Called by none

Calls _expected_entry, apply_plan, plan_merge

Checks

  • assert target.is_file()
  • assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002measuredtest_no_backup_is_left_when_the_file_is_created → apply_plan
REQ-DDB-MCP-001measuredtest_no_backup_is_left_when_the_file_is_created → plan_merge
Source · 9 lines
def test_no_backup_is_left_when_the_file_is_created(tmp_path: Path) -> None:
    """A stray `.bak` next to a file that never existed is misleading rather than
    protective — it invites the reader to believe something was overwritten."""
    target = tmp_path / REPO_CONFIG_NAME
    apply_plan(plan_merge(target, _expected_entry()))
    assert target.is_file()
    assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

Activity · 4 steps
lines 526–526target = tmp_path / REPO_CONFIG_NAMElines 527–527apply_plan(plan_merge(target, _expected_entry()))lines 528–528assert target.is_file()lines 529–529assert not target.with_name(target.name + BACKUP_SUFFIX).exists()

test_non_object_document_is_refused

None test_init.test_non_object_document_is_refused(Path tmp_path)

A JSON document that is not an object is refused.

tests/test_init.py:578

Show on the map →

Called by none

Calls _expected_entry, plan_merge

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_non_object_document_is_refused → plan_merge
Source · 8 lines
def test_non_object_document_is_refused(tmp_path: Path) -> None:
    """`json.loads("[]")` succeeds; `document.get(...)` on a list does not."""
    target = tmp_path / REPO_CONFIG_NAME
    target.write_text("[1, 2, 3]\n", encoding="utf-8")
    with pytest.raises(ConfigError):
        plan_merge(target, _expected_entry())

Activity · 4 steps
lines 580–580target = tmp_path / REPO_CONFIG_NAMElines 581–581target.write_text("[1, 2, 3]\n", encoding="utf-8")lines 582–582with pytest.raises(ConfigError)lines 583–583plan_merge(target, _expected_entry())

test_non_object_servers_key_is_refused

None test_init.test_non_object_servers_key_is_refused(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

A non-object mcpServers is refused rather than replaced.

tests/test_init.py:560

Show on the map →

Called by none

Calls _run

Checks

  • assert code == 1
  • assert target.read_text(encoding="utf-8") == original
  • assert SERVERS_KEY in out

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_non_object_servers_key_is_refused → _run → init_main
REQ-DDB-CLI-002measuredtest_non_object_servers_key_is_refused → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_non_object_servers_key_is_refused → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 15 lines
def test_non_object_servers_key_is_refused(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """Parses as JSON, so `load_document` accepts it, and the merge would happily
    replace a list with a dict — silently discarding whatever the user meant."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    original = '{"mcpServers": ["entropic"]}\n'
    target.write_text(original, encoding="utf-8")
    code, out = _run([], repo, capsys)
    assert code == 1
    assert target.read_text(encoding="utf-8") == original
    assert SERVERS_KEY in out

Activity · 8 steps
lines 565–565del stub_envlines 566–566target = repo / REPO_CONFIG_NAMElines 567–567original = '{"mcpServers": ["entropic"]}\n'lines 568–568target.write_text(original, encoding="utf-8")lines 569–569code, out = _run([], repo, capsys)lines 570–570assert code == 1lines 571–571assert target.read_text(encoding="utf-8") == originallines 572–572assert SERVERS_KEY in out

test_other_servers_survive_byte_identical

None test_init.test_other_servers_survive_byte_identical(Path repo, Path stub_env, pytest.CaptureFixture[str] capsys)

Every unrelated server in an existing config survives byte-identical.

tests/test_init.py:361

Show on the map →

Called by none

Calls _run, list

Checks

  • assert code == 0, out
  • assert json.dumps(after[SERVERS_KEY][name], sort_keys=True) == json.dumps(entry, sort_keys=True ), f"unrelated server {name} was altered"
  • assert list(after[SERVERS_KEY]) == ["entropic", "chrome", MCP_ENTRY_NAME], ("existing servers must keep their order, ours appended" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_other_servers_survive_byte_identical → _run → init_main
REQ-DDB-CLI-002measuredtest_other_servers_survive_byte_identical → _run → init_main → build_parser
REQ-DDB-CONFIG-001measuredtest_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_indexable → derive_scope
REQ-DDB-GUARD-012inferredtest_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-001measuredtest_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_indexable → discover_doxyfile
REQ-DDB-MCP-001measuredtest_other_servers_survive_byte_identical → _run → init_main → _register → config_path
REQ-DDB-PIPE-006measuredtest_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env
REQ-DDB-PIPE-012inferredtest_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_doxygen → _needs_doxygen
REQ-DDB-WIKI-054inferredtest_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_indexable → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 31 lines
def test_other_servers_survive_byte_identical(
    repo: Path, stub_env: Path, capsys: pytest.CaptureFixture[str]
) -> None:
    """THE failure mode this command's design exists to prevent. A doctor that
    registers itself by writing a fresh one-server document has destroyed the
    user's other servers, and the result still looks like a valid config — the
    damage is invisible until something they rely on stops connecting.

    Compared as re-serialised subtrees rather than by `==` so a changed nesting or
    a dropped key inside an entry cannot pass."""
    del stub_env
    target = repo / REPO_CONFIG_NAME
    before = {
        SERVERS_KEY: {
            "entropic": {"type": "stdio", "command": "entropic-mcp", "args": ["--flag"]},
            "chrome": {"type": "sse", "url": "http://127.0.0.1:1234/sse", "env": {"A": "b"}},
        }
    }
    target.write_text(json.dumps(before, indent=2) + "\n", encoding="utf-8")
    code, out = _run([], repo, capsys)
    assert code == 0, out
    after = json.loads(target.read_text(encoding="utf-8"))
    for name, entry in before[SERVERS_KEY].items():
        assert json.dumps(after[SERVERS_KEY][name], sort_keys=True) == json.dumps(
            entry, sort_keys=True
        ), f"unrelated server {name} was altered"
    assert list(after[SERVERS_KEY]) == ["entropic", "chrome", MCP_ENTRY_NAME], (
        "existing servers must keep their order, ours appended"
    )

Activity · 10 steps
lines 371–371del stub_envlines 372–372target = repo / REPO_CONFIG_NAMElines 373–378before = { SERVERS_KEY: { "entropic": {"type": "stdio", "command": "entropic-mcp", "args": ["--flag"]}, "chrome": {"type": "sse", "url": "http://127.0.0.1:1234/sse", "env": {"A": "b"}}, } }lines 379–379target.write_text(json.dumps(before, indent=2) + "\n", encoding="utf-8")lines 380–380code, out = _run([], repo, capsys)lines 381–381assert code == 0, outlines 382–382after = json.loads(target.read_text(encoding="utf-8"))lines 383–383◇ for name, entry in before[SERVERS_KEY].items()lines 384–386assert json.dumps(after[SERVERS_KEY][name], sort_keys=True) == json.dumps( entry, sort_keys=True ), f"unrelated server {name} was altered"lines 387–389assert list(after[SERVERS_KEY]) == ["entropic", "chrome", MCP_ENTRY_NAME], ( "existing servers must keep their order, ours appended" )

test_parser_defaults

None test_init.test_parser_defaults()

Parser defaults are repo scope, the cwd, no force, no yes, no dry run.

tests/test_init.py:1328

Checks

  • assert args.scope == INIT_SCOPE_REPO
  • assert args.repo_root == "."
  • assert args.force is False
  • assert args.dry_run is False

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measuredtest_parser_defaults → build_parser
REQ-DDB-CLI-002measuredtest_parser_defaults → build_parser
Source · 11 lines
def test_parser_defaults() -> None:
    """`--force`, `--yes` and `--dry-run` default off in the safe direction: nothing
    is replaced, nothing is written to a curated file unasked, and nothing is
    hidden."""
    args = init_command.build_parser().parse_args([])
    assert args.scope == INIT_SCOPE_REPO
    assert args.repo_root == "."
    assert args.force is False
    assert args.dry_run is False

Activity · 5 steps
lines 1332–1332args = init_command.build_parser().parse_args([])lines 1333–1333assert args.scope == INIT_SCOPE_REPOlines 1334–1334assert args.repo_root == "."lines 1335–1335assert args.force is Falselines 1336–1336assert args.dry_run is False

test_plan_merge_classifies_every_action

None test_init.test_plan_merge_classifies_every_action(Path tmp_path)

plan_merge classifies all four merge actions.

tests/test_init.py:786

Show on the map →

Called by none

Calls _expected_entry, plan_merge

Checks

  • assert plan_merge(target, entry).action == INIT_ACTION_CREATE
  • assert plan_merge(target, entry).action == INIT_ACTION_ADD
  • assert plan_merge(target, entry).action == INIT_ACTION_UNCHANGED
  • assert plan.action == INIT_ACTION_UPDATE
  • assert "something-else" in plan.diff

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_plan_merge_classifies_every_action → plan_merge
Source · 18 lines
def test_plan_merge_classifies_every_action(tmp_path: Path) -> None:
    """The action drives the exit path — `unchanged` skips the write entirely and
    `update` is the only one the conflict rule gates — so a misclassification is
    either a silent overwrite or a refusal to do anything."""
    target = tmp_path / REPO_CONFIG_NAME
    entry = _expected_entry()
    assert plan_merge(target, entry).action == INIT_ACTION_CREATE
    target.write_text(json.dumps({SERVERS_KEY: {"entropic": {}}}) + "\n", encoding="utf-8")
    assert plan_merge(target, entry).action == INIT_ACTION_ADD
    target.write_text(json.dumps({SERVERS_KEY: {MCP_ENTRY_NAME: entry}}) + "\n", encoding="utf-8")
    assert plan_merge(target, entry).action == INIT_ACTION_UNCHANGED
    other = {**entry, "command": "something-else"}
    target.write_text(json.dumps({SERVERS_KEY: {MCP_ENTRY_NAME: other}}) + "\n", encoding="utf-8")
    plan = plan_merge(target, entry)
    assert plan.action == INIT_ACTION_UPDATE
    assert "something-else" in plan.diff

Activity · 12 steps
lines 790–790target = tmp_path / REPO_CONFIG_NAMElines 791–791entry = _expected_entry()lines 792–792assert plan_merge(target, entry).action == INIT_ACTION_CREATElines 793–793target.write_text(json.dumps({SERVERS_KEY: {"entropic": {}}}) + "\n", encoding="utf-8")lines 794–794assert plan_merge(target, entry).action == INIT_ACTION_ADDlines 795–795target.write_text(json.dumps({SERVERS_KEY: {MCP_ENTRY_NAME: entry}}) + "\n", encoding="utf-8")lines 796–796assert plan_merge(target, entry).action == INIT_ACTION_UNCHANGEDlines 797–797other = {**entry, "command": "something-else"}lines 798–798target.write_text(json.dumps({SERVERS_KEY: {MCP_ENTRY_NAME: other}}) + "\n", encoding="utf-8")lines 799–799plan = plan_merge(target, entry)lines 800–800assert plan.action == INIT_ACTION_UPDATElines 801–801assert "something-else" in plan.diff

test_repo_relative_when_the_script_lives_inside_the_repo

None test_init.test_repo_relative_when_the_script_lives_inside_the_repo(Path repo)

A script inside the repo is recorded repo-relative.

tests/test_init.py:990

Checks

  • assert resolution.command == f".venv/bin/{CONSOLE_SCRIPT}"
  • assert resolution.portable

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_repo_relative_when_the_script_lives_inside_the_repo → resolve_server_command
Source · 14 lines
def test_repo_relative_when_the_script_lives_inside_the_repo(repo: Path) -> None:
    """The developer-checkout case: `.venv/bin/clew-mcp` is real and
    usable but invisible to `which` unless the venv is activated. Relative keeps
    the committed config portable across clones of the same repo."""
    script = repo / ".venv" / "bin" / CONSOLE_SCRIPT
    script.parent.mkdir(parents=True)
    script.touch()
    resolution = resolve_server_command(
        repo, INIT_SCOPE_REPO, which=lambda _cmd: None, bindir=script.parent
    )
    assert resolution.command == f".venv/bin/{CONSOLE_SCRIPT}"
    assert resolution.portable

Activity · 6 steps
lines 994–994script = repo / ".venv" / "bin" / CONSOLE_SCRIPTlines 995–995script.parent.mkdir(parents=True)lines 996–996script.touch()lines 997–999resolution = resolve_server_command( repo, INIT_SCOPE_REPO, which=lambda _cmd: None, bindir=script.parent )lines 1000–1000assert resolution.command == f".venv/bin/{CONSOLE_SCRIPT}"lines 1001–1001assert resolution.portable

test_state_directory_alone_is_sufficient_evidence

None test_init.test_state_directory_alone_is_sufficient_evidence(Path tmp_path, pytest.MonkeyPatch monkeypatch)

The state directory alone evidences an install.

tests/test_init.py:935

Checks

  • assert global_config_path() == fake_home / ".claude.json"
  • assert global_config_available()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_state_directory_alone_is_sufficient_evidence → global_config_path
Source · 13 lines
def test_state_directory_alone_is_sufficient_evidence(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """A user who installed Claude Code but has not accumulated a config yet is a
    real state, and refusing them would be refusing the very case `init` is for."""
    fake_home = tmp_path / "fresh-home"
    (fake_home / ".claude").mkdir(parents=True)
    monkeypatch.delenv(CLAUDE_CONFIG_DIR_ENV, raising=False)
    monkeypatch.setattr(Path, "home", classmethod(lambda cls: fake_home))
    assert global_config_path() == fake_home / ".claude.json"
    assert global_config_available()

Activity · 6 steps
lines 940–940fake_home = tmp_path / "fresh-home"lines 941–941(fake_home / ".claude").mkdir(parents=True)lines 942–942monkeypatch.delenv(CLAUDE_CONFIG_DIR_ENV, raising=False)lines 943–943monkeypatch.setattr(Path, "home", classmethod(lambda cls: fake_home))lines 944–944assert global_config_path() == fake_home / ".claude.json"lines 945–945assert global_config_available()

test_the_global_config_path_is_inside_the_pytest_tmp_tree

None test_init.test_the_global_config_path_is_inside_the_pytest_tmp_tree(pytest.TempPathFactory tmp_path_factory)

The user-scope target resolves inside pytest's temp tree, never at home.

tests/test_init.py:832

Checks

  • assert resolved.is_relative_to(tmp_path_factory.getbasetemp())
  • assert resolved != Path.home() / ".claude.json"
  • assert claude_state_dir().is_relative_to(tmp_path_factory.getbasetemp())

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_the_global_config_path_is_inside_the_pytest_tmp_tree → claude_state_dir
Source · 15 lines
def test_the_global_config_path_is_inside_the_pytest_tmp_tree(
    tmp_path_factory: pytest.TempPathFactory,
) -> None:
    """The safety gate for this whole module, asserted rather than assumed.

    `conftest.py`'s autouse fixture points `CLAUDE_CONFIG_DIR` at a throwaway
    directory; this proves the fixture actually reaches the function that
    `apply_plan` writes to. A test that CAN touch `~/.claude.json` is unacceptable
    even while it happens to pass, because the failure is unrecoverable."""
    resolved = global_config_path()
    assert resolved.is_relative_to(tmp_path_factory.getbasetemp())
    assert resolved != Path.home() / ".claude.json"
    assert claude_state_dir().is_relative_to(tmp_path_factory.getbasetemp())

Activity · 4 steps
lines 841–841resolved = global_config_path()lines 842–842assert resolved.is_relative_to(tmp_path_factory.getbasetemp())lines 843–843assert resolved != Path.home() / ".claude.json"lines 844–844assert claude_state_dir().is_relative_to(tmp_path_factory.getbasetemp())

test_the_written_entry_is_shaped_like_a_registration

None test_init.test_the_written_entry_is_shaped_like_a_registration()

The entry init writes is shaped the way a registration must be.

tests/test_init.py:1060

Checks

  • assert entry["command"].endswith(CONSOLE_SCRIPT)
  • assert entry["type"] == "stdio", "a local server is launched over stdio"
  • assert entry["args"] == [], "a written entry must not pin a target"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-002catalog
REQ-DDB-MCP-001measuredtest_the_written_entry_is_shaped_like_a_registration → server_entry
Source · 31 lines
def test_the_written_entry_is_shaped_like_a_registration() -> None:
    """REPLACES "the dogfood pin", which compared this repo's own committed
    `.mcp.json` against what `init` produces. That file is gone: it registered the
    same server, under the same name, pointed at the same place, as the user-scope
    entry already did — a second registration and no capability.

    What the old test bought was drift detection: if the entry shape changed, it
    failed here on a committed file rather than a year later on a user's machine.
    That guarantee is worth keeping and does not need a checked-in artifact to hold
    it, so it is asserted directly against `server_entry` instead.

    What is genuinely lost with the file: a clone of this repo no longer
    auto-registers the server, and this repo no longer proves by example that
    running `init` on it is a no-op rather than a rewrite that happens to match.
    Both are real and both were judged smaller than carrying a duplicate.

    @brief The generated entry has the shape a client can launch.
    @version 2
    """
    entry = server_entry(CONSOLE_SCRIPT)
    assert entry["command"].endswith(CONSOLE_SCRIPT)
    assert entry["type"] == "stdio", "a local server is launched over stdio"
    ## No `--repo`. The target is DERIVED (from $CLAUDE_PROJECT_DIR, else the
    ## client's roots), so an entry that pinned one would defeat the resolution the
    ## server exists to perform.
    assert entry["args"] == [], "a written entry must not pin a target"


# ─── the doctor ──────────────────────────────────────────────────────────────

Activity · 4 steps
lines 1079–1079entry = server_entry(CONSOLE_SCRIPT)lines 1080–1080assert entry["command"].endswith(CONSOLE_SCRIPT)lines 1081–1081assert entry["type"] == "stdio", "a local server is launched over stdio"lines 1085–1085assert entry["args"] == [], "a written entry must not pin a target"