test_apply_plan_backs_up_the_original_bytes

Tests › tests/test_init.py

passed Passed in the packaged run.

What this test is for

Why it exists

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.

Given

  1. target = tmp_path / REPO_CONFIG_NAME
  2. original = ( '{\n "mcpServers": {\n "entropic": {"command": "entropic-mcp"}\n },\n' ' "note": "hand written, irreplaceable"\n}\n' )
  3. target.write_text(original, encoding="utf-8")
→

When

  1. apply_plan(plan_merge(target, _expected_entry()))
  2. backup = target.with_name(target.name + BACKUP_SUFFIX)
→

Then

  1. ✓ backup.is_file() holds
  2. ✓ backup.read_text(encoding="utf-8") equals original
  3. ✓ json.loads(target.read_text(encoding="utf-8"))[SERVERS_KEY][MCP_ENTRY_NAME] equals _expected_entry()
  4. ✓ target.with_name(target.name + ".clew.tmp").exists() is false

What it exercises

The parts of the system's flows this test ran, measured by per-test coverage: lit steps ran in this test, dimmed ones did not, and ▶ marks where the test called in. Each title opens the whole flow with these steps lit.

clew — `main` (clew/cli.py) · 4 of 400 steps

… 190 earlier steps

command-line usercommand-line usercommand-line usercommand-line userclew/init_command.pyclew/init_command.pyclew/init_command.pyclew/init_command.pyother filesother filesother filesother filestry (line 683)trymain191. config_path → global_config_path191global_config_path192. _register → plan_merge192plan_merge193. plan_merge → load_document193load_document▶ test enters194–196. plan_merge → _classify194_classify +2 more197–198. _register → _execute197_execute +1 more

… 202 later steps

tests/test_init.py:493 · its file's page

What it checks (4)

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

Where the product reaches it

  • main → propose_main → _emit → apply_plan (flow)
  • main → init_main → _register → plan_merge (flow)

Call flow

test_apply_plan_backs_up_the_original_bytes→apply_plan→plan_merge→_expected_entry

What it reaches

Each row runs from this test, through the calls it makes, to the code a requirement names. If that code breaks, the test's checks are what should catch it. Reaching is not proving: a check only proves what it observes. No mutation records were given, so these rows say what the test REACHES.

test_apply_plan_backs_up_the_original_bytes · 4 checksapply_planREQ-DDB-CLI-002 · measuredplan_mergeREQ-DDB-MCP-001 · measured
Also reaches 2 requirements

Its run touches their code; that is reach, not proof.