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.
Checks
assert code == 0, outassert (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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose |
| REQ-DDB-CLI-002 | measured | test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose |
| REQ-DDB-CONFIG-001 | measured | test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_client_config → global_config_evidence |
| REQ-DDB-PIPE-006 | measured | test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_a_repo_with_no_doxyfile_and_no_guard_scope_is_still_indexable → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert resolution.command == str(script)assert not resolution.portableassert "not on PATH" in resolution.origin
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | measured | test_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support → _check_doxygen → doxygen_supports_sqlite3 |
| REQ-DDB-INDEX-001 | inferred | test_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support → _check_doxygen → uses_rustdoc → discover_doxyfile |
| REQ-DDB-PIPE-006 | measured | test_an_unrunnable_doxygen_probe_warns_rather_than_claiming_no_support → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | measured | test_apply_plan_backs_up_the_original_bytes → apply_plan |
| REQ-DDB-MCP-001 | measured | test_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
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.
Checks
assert resolution.command == CONSOLE_SCRIPTassert resolution.portable
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
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_CHECKSassert init_command.CHECK_MCP_SDK not in init_command.BLOCKING_CHECKSassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog |
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
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.
Checks
assert code == 1assert (repo / REPO_CONFIG_NAME).is_file(), "the registration still lands"assert "SDK import failed" in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_broken_mcp_sdk_fails_but_still_registers → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_broken_mcp_sdk_fails_but_still_registers → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_broken_mcp_sdk_fails_but_still_registers → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_broken_mcp_sdk_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert check.status in (CHECK_OK, CHECK_WARN, CHECK_FAIL)assert check.detail, f"{check.name} reported no evidence"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_check_statuses_come_from_the_vocabulary → diagnose |
| REQ-DDB-CLI-002 | measured | test_check_statuses_come_from_the_vocabulary → diagnose |
| REQ-DDB-CONFIG-001 | measured | test_check_statuses_come_from_the_vocabulary → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_check_statuses_come_from_the_vocabulary → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_check_statuses_come_from_the_vocabulary → diagnose → _check_client_config → global_config_evidence |
| REQ-DDB-PIPE-006 | measured | test_check_statuses_come_from_the_vocabulary → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_check_statuses_come_from_the_vocabulary → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert global_config_path() == declared / ".claude.json"assert claude_state_dir() == declaredassert global_config_available(), "a declaration IS the evidence"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
Checks
assert cli.INIT_COMMAND == init_command.COMMAND == "init"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog |
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
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.
Checks
assert config_path(INIT_SCOPE_REPO, repo) == repo / REPO_CONFIG_NAMEassert config_path(INIT_SCOPE_GLOBAL, repo) == global_home / ".claude.json"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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 .
Checks
assert absent.status == CHECK_WARNassert "propose" in absent.detailassert present.status == CHECK_OKassert ".clew.yaml" in present.detail
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_declaration_check_reports_both_states → diagnose |
| REQ-DDB-CLI-002 | measured | test_declaration_check_reports_both_states → diagnose |
| REQ-DDB-CONFIG-001 | measured | test_declaration_check_reports_both_states → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_declaration_check_reports_both_states → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_declaration_check_reports_both_states → diagnose → _check_client_config → global_config_evidence |
| REQ-DDB-PIPE-006 | measured | test_declaration_check_reports_both_states → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_declaration_check_reports_both_states → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 1assert target.read_bytes() == original, "a refusal must not modify the file"assert not target.with_name(target.name + BACKUP_SUFFIX).exists()assert "--force" in outassert "/opt/wrapper/clew-mcp" in out, "the diff must show what would be lost"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_differing_entry_is_refused_without_force → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_differing_entry_is_refused_without_force → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_differing_entry_is_refused_without_force → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_differing_entry_is_refused_without_force → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert check.status == CHECK_OKassert "Doxyfile" in check.detail
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_doxyfile_makes_the_repo_indexable → diagnose |
| REQ-DDB-CLI-002 | measured | test_doxyfile_makes_the_repo_indexable → diagnose |
| REQ-DDB-CONFIG-001 | inferred | test_doxyfile_makes_the_repo_indexable → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_doxyfile_makes_the_repo_indexable → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_doxyfile_makes_the_repo_indexable → diagnose → _check_client_config → global_config_evidence |
| REQ-DDB-PIPE-006 | measured | test_doxyfile_makes_the_repo_indexable → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_doxyfile_makes_the_repo_indexable → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | test_doxygen_check_is_informational_for_a_rustdoc_repo → _check_doxygen → doxygen_supports_sqlite3 |
| REQ-DDB-INDEX-001 | measured | test_doxygen_check_is_informational_for_a_rustdoc_repo → _check_doxygen → uses_rustdoc → discover_doxyfile |
| REQ-DDB-PIPE-006 | inferred | test_doxygen_check_is_informational_for_a_rustdoc_repo → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | measured | test_doxygen_with_sqlite3_support_passes_the_doctor → _check_doxygen → doxygen_supports_sqlite3 |
| REQ-DDB-INDEX-001 | inferred | test_doxygen_with_sqlite3_support_passes_the_doctor → _check_doxygen → uses_rustdoc → discover_doxyfile |
| REQ-DDB-PIPE-006 | measured | test_doxygen_with_sqlite3_support_passes_the_doctor → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | measured | test_doxygen_without_sqlite3_support_fails_the_doctor → _check_doxygen → doxygen_supports_sqlite3 |
| REQ-DDB-INDEX-001 | inferred | test_doxygen_without_sqlite3_support_fails_the_doctor → _check_doxygen → uses_rustdoc → discover_doxyfile |
| REQ-DDB-PIPE-006 | measured | test_doxygen_without_sqlite3_support_fails_the_doctor → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_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
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.
Called by none
Calls _assert_entry_only, _disclosure_document, _expected_entry, _printed_json, _run
Checks
assert code == 0, outassert json.loads(_printed_json(out)) == _expected_entry()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_dry_run_add_shows_the_entry_and_not_the_user_document → _expected_entry → server_entry |
| REQ-DDB-PIPE-006 | measured | test_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-012 | inferred | test_dry_run_add_shows_the_entry_and_not_the_user_document → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 0, outassert target.read_text(encoding="utf-8") == originalassert not target.with_name(target.name + BACKUP_SUFFIX).exists()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_dry_run_over_an_existing_file_changes_nothing → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_dry_run_over_an_existing_file_changes_nothing → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_dry_run_over_an_existing_file_changes_nothing → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_dry_run_over_an_existing_file_changes_nothing → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Called by none
Calls _assert_entry_only, _disclosure_document, _expected_entry, _printed_json, _run
Checks
assert code == 0, outassert json.loads(_printed_json(out)) == _expected_entry()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_dry_run_repo_scope_is_entry_scoped_as_well → _expected_entry → server_entry |
| REQ-DDB-PIPE-006 | measured | test_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_dry_run_repo_scope_is_entry_scoped_as_well → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Called by none
Calls _assert_entry_only, _disclosure_document, _expected_entry, _run
Checks
assert code == 0, outassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_dry_run_unchanged_prints_no_document → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_dry_run_unchanged_prints_no_document → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_dry_run_unchanged_prints_no_document → _expected_entry → server_entry |
| REQ-DDB-PIPE-006 | measured | test_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_dry_run_unchanged_prints_no_document → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 0, outassert "/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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_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-012 | inferred | test_dry_run_update_with_force_shows_only_the_entry_diff → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 1, outassert "--force" in out, "the refusal must name the override"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_dry_run_update_without_force_refuses_without_dumping → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_dry_run_update_without_force_refuses_without_dumping → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_dry_run_update_without_force_refuses_without_dumping → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_dry_run_update_without_force_refuses_without_dumping → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 0, outassert not (repo / REPO_CONFIG_NAME).exists(), "--dry-run must not create the file"assert json.loads(_printed_json(out)) == _expected_entry()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_dry_run_writes_nothing → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_dry_run_writes_nothing → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_dry_run_writes_nothing → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_dry_run_writes_nothing → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_dry_run_writes_nothing → _expected_entry → server_entry |
| REQ-DDB-PIPE-006 | measured | test_dry_run_writes_nothing → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_dry_run_writes_nothing → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert name in out, f"the {name} check must be reported even on a refusal"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_every_check_prints_before_a_refusal → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_every_check_prints_before_a_refusal → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_every_check_prints_before_a_refusal → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_every_check_prints_before_a_refusal → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 0, outassert '\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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_existing_indentation_is_preserved → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_existing_indentation_is_preserved → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_existing_indentation_is_preserved → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_existing_indentation_is_preserved → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_existing_indentation_is_preserved → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_existing_indentation_is_preserved → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_existing_indentation_is_preserved → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 0, outassert after[SERVERS_KEY][MCP_ENTRY_NAME] == _expected_entry()assert after[SERVERS_KEY]["entropic"] == {assert INIT_ACTION_UPDATE in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_force_replaces_the_differing_entry → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_force_replaces_the_differing_entry → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_force_replaces_the_differing_entry → _expected_entry → server_entry |
| REQ-DDB-PIPE-006 | measured | test_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_force_replaces_the_differing_entry → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 0, outassert json.loads(target.read_text(encoding="utf-8")) == {assert _expected_entry()["args"] == [], "no scope may pin the server any more"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_fresh_repo_creates_the_config → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_fresh_repo_creates_the_config → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_fresh_repo_creates_the_config → _expected_entry → server_entry |
| REQ-DDB-PIPE-006 | measured | test_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_fresh_repo_creates_the_config → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert resolution.command == str(script)assert Path(resolution.command).is_absolute(), "user scope must record an absolute command"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
Checks
assert code == 0, outassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_global_scope_preserves_the_user_state_document → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_global_scope_preserves_the_user_state_document → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_global_scope_preserves_the_user_state_document → _expected_entry → server_entry |
| REQ-DDB-PIPE-006 | measured | test_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_global_scope_preserves_the_user_state_document → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert global_config_path().is_relative_to(tmp_path), "precondition: the write target is in tmp"assert not global_config_available()assert code == 1assert not (fake_home / ".claude.json").exists(), "nothing may be created on a refusal"assert str(fake_home / ".claude.json") in outassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_global_scope_refuses_without_evidence → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_global_scope_refuses_without_evidence → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_global_scope_refuses_without_evidence → global_config_path |
| REQ-DDB-PIPE-006 | measured | test_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_global_scope_refuses_without_evidence → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert first_code == 0assert second_code == 0, outassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_identical_entry_is_a_no_op_on_bytes → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_identical_entry_is_a_no_op_on_bytes → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_identical_entry_is_a_no_op_on_bytes → plan_merge |
| REQ-DDB-PIPE-006 | measured | test_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_identical_entry_is_a_no_op_on_bytes → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert "from .init_command import" in sourceassert "from .init_command import" not in inspect.getsource(cli).split("def main(")[0]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog |
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
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.
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] == entryassert after[SERVERS_KEY]["entropic"] == LIVE_LIKE_DOCUMENT[SERVERS_KEY]["entropic"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | measured | test_live_like_document_round_trips_with_only_servers_changed → apply_plan |
| REQ-DDB-MCP-001 | measured | test_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
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.
Checks
assert code == 1assert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_malformed_json_is_refused_and_left_alone → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_malformed_json_is_refused_and_left_alone → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_malformed_json_is_refused_and_left_alone → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_malformed_json_is_refused_and_left_alone → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_mcp_sdk_check_passes_when_the_server_can_be_built → build_server |
| REQ-DDB-MCP-003 | measured | |
| REQ-DDB-MCP-004 | measured | test_mcp_sdk_check_passes_when_the_server_can_be_built → build_server → _refusal_as_tool_error |
| REQ-DDB-PIPE-006 | measured | test_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-012 | inferred | test_mcp_sdk_check_passes_when_the_server_can_be_built → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-034 | measured | test_mcp_sdk_check_passes_when_the_server_can_be_built → build_server → _register_prompts |
| REQ-DDB-WIKI-054 | measured | test_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
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.
Checks
assert code == 1assert not (repo / REPO_CONFIG_NAME).exists(), "no config may name a missing command"assert CONSOLE_SCRIPT in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_missing_console_script_blocks_the_write → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_missing_console_script_blocks_the_write → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_missing_console_script_blocks_the_write → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_missing_console_script_blocks_the_write → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_missing_doxygen_fails_but_still_registers → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_missing_doxygen_fails_but_still_registers → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_missing_doxygen_fails_but_still_registers → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | inferred | test_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | measured | test_missing_doxygen_fails_but_still_registers → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert target.is_file()assert not target.with_name(target.name + BACKUP_SUFFIX).exists()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | measured | test_no_backup_is_left_when_the_file_is_created → apply_plan |
| REQ-DDB-MCP-001 | measured | test_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
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.
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
Checks
assert code == 1assert target.read_text(encoding="utf-8") == originalassert SERVERS_KEY in out
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_non_object_servers_key_is_refused → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_non_object_servers_key_is_refused → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_non_object_servers_key_is_refused → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_non_object_servers_key_is_refused → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
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.
Checks
assert code == 0, outassert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_other_servers_survive_byte_identical → _run → init_main |
| REQ-DDB-CLI-002 | measured | test_other_servers_survive_byte_identical → _run → init_main → build_parser |
| REQ-DDB-CONFIG-001 | measured | test_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_indexable → derive_scope |
| REQ-DDB-GUARD-012 | inferred | test_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-001 | measured | test_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_indexable → discover_doxyfile |
| REQ-DDB-MCP-001 | measured | test_other_servers_survive_byte_identical → _run → init_main → _register → config_path |
| REQ-DDB-PIPE-006 | measured | test_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_doxygen → doxygen_supports_sqlite3 → clean_subprocess_env |
| REQ-DDB-PIPE-012 | inferred | test_other_servers_survive_byte_identical → _run → init_main → diagnose → _check_doxygen → _needs_doxygen |
| REQ-DDB-WIKI-054 | inferred | test_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
test_parser_defaults
None test_init.test_parser_defaults()
Parser defaults are repo scope, the cwd, no force, no yes, no dry run.
Checks
assert args.scope == INIT_SCOPE_REPOassert args.repo_root == "."assert args.force is Falseassert args.dry_run is False
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-001 | measured | test_parser_defaults → build_parser |
| REQ-DDB-CLI-002 | measured | test_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
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.
Checks
assert plan_merge(target, entry).action == INIT_ACTION_CREATEassert plan_merge(target, entry).action == INIT_ACTION_ADDassert plan_merge(target, entry).action == INIT_ACTION_UNCHANGEDassert plan.action == INIT_ACTION_UPDATEassert "something-else" in plan.diff
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
Checks
assert resolution.command == f".venv/bin/{CONSOLE_SCRIPT}"assert resolution.portable
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
Checks
assert global_config_path() == fake_home / ".claude.json"assert global_config_available()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | catalog | |
| REQ-DDB-MCP-001 | measured | test_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 ──────────────────────────────────────────────────────────────