@@ -26,19 +26,25 @@ from typer.testing import CliRunner |
| 26 | 26 | from dlm.cli.app import app |
| 27 | 27 | |
| 28 | 28 | |
| 29 | | -def _scaffolded_store(tmp_path: Path) -> Path: |
| 30 | | - """Init a doc, ensure_layout the store, save a manifest — return the .dlm path.""" |
| 29 | +def _scaffolded_store(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path: |
| 30 | + """Init a doc, ensure_layout the store, save a manifest — return the .dlm path. |
| 31 | + |
| 32 | + Audit-05 N11: `monkeypatch.setenv` instead of raw `os.environ[...]` |
| 33 | + so the DLM_HOME override auto-reverts at test teardown and can't |
| 34 | + leak into a later test in the same session. |
| 35 | + """ |
| 31 | 36 | from dlm.doc.parser import parse_file |
| 32 | | - from dlm.store.manifest import Manifest, save_manifest |
| 33 | 37 | from dlm.store.paths import for_dlm |
| 34 | 38 | |
| 39 | + home = tmp_path / "dlm-home" |
| 40 | + monkeypatch.setenv("DLM_HOME", str(home)) |
| 35 | 41 | runner = CliRunner() |
| 36 | 42 | doc = tmp_path / "doc.dlm" |
| 37 | 43 | result = runner.invoke( |
| 38 | 44 | app, |
| 39 | 45 | [ |
| 40 | 46 | "--home", |
| 41 | | - str(tmp_path / "dlm-home"), |
| 47 | + str(home), |
| 42 | 48 | "init", |
| 43 | 49 | str(doc), |
| 44 | 50 | "--base", |
@@ -47,17 +53,10 @@ def _scaffolded_store(tmp_path: Path) -> Path: |
| 47 | 53 | ) |
| 48 | 54 | assert result.exit_code == 0, result.output |
| 49 | 55 | |
| 50 | | - import os |
| 51 | | - |
| 52 | | - os.environ["DLM_HOME"] = str(tmp_path / "dlm-home") |
| 56 | + # Post-B2: `dlm init` already creates the store + manifest. We just |
| 57 | + # drop a marker file so round-trip tests cover non-manifest content. |
| 53 | 58 | parsed = parse_file(doc) |
| 54 | 59 | store = for_dlm(parsed.frontmatter.dlm_id) |
| 55 | | - store.ensure_layout() |
| 56 | | - save_manifest( |
| 57 | | - store.manifest, |
| 58 | | - Manifest(dlm_id=parsed.frontmatter.dlm_id, base_model="smollm2-135m"), |
| 59 | | - ) |
| 60 | | - # Drop a marker file in the store so round-trip covers non-manifest content. |
| 61 | 60 | (store.root / "marker.txt").write_text("i survived the round trip\n") |
| 62 | 61 | return doc |
| 63 | 62 | |
@@ -69,7 +68,7 @@ class TestRoundTrip: |
| 69 | 68 | from dlm.pack.packer import pack |
| 70 | 69 | from dlm.pack.unpacker import unpack |
| 71 | 70 | |
| 72 | | - doc = _scaffolded_store(tmp_path) |
| 71 | + doc = _scaffolded_store(tmp_path, monkeypatch) |
| 73 | 72 | original_dlm = doc.read_bytes() |
| 74 | 73 | |
| 75 | 74 | # Capture pre-pack store state. |
@@ -104,11 +103,13 @@ class TestRoundTrip: |
| 104 | 103 | restored_marker = (unpack_result.store_path / "marker.txt").read_bytes() |
| 105 | 104 | assert restored_marker == original_marker |
| 106 | 105 | |
| 107 | | - def test_pack_manifest_content_sha256_is_deterministic(self, tmp_path: Path) -> None: |
| 106 | + def test_pack_manifest_content_sha256_is_deterministic( |
| 107 | + self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch |
| 108 | + ) -> None: |
| 108 | 109 | """Two packs of identical input produce identical `content_sha256` rollups.""" |
| 109 | 110 | from dlm.pack.packer import pack |
| 110 | 111 | |
| 111 | | - doc = _scaffolded_store(tmp_path) |
| 112 | + doc = _scaffolded_store(tmp_path, monkeypatch) |
| 112 | 113 | a = pack(doc, out=tmp_path / "a.pack") |
| 113 | 114 | b = pack(doc, out=tmp_path / "b.pack") |
| 114 | 115 | |
@@ -136,7 +137,7 @@ class TestForceOverwrite: |
| 136 | 137 | from dlm.pack.packer import pack |
| 137 | 138 | from dlm.pack.unpacker import unpack |
| 138 | 139 | |
| 139 | | - doc = _scaffolded_store(tmp_path) |
| 140 | + doc = _scaffolded_store(tmp_path, monkeypatch) |
| 140 | 141 | pack_result = pack(doc, out=tmp_path / "out.pack") |
| 141 | 142 | |
| 142 | 143 | fresh_home = tmp_path / "fresh-home" |