@@ -103,6 +103,45 @@ def _handle_with_many_instruction_probes(n: int) -> DlmHandle: |
| 103 | 103 | ) |
| 104 | 104 | |
| 105 | 105 | |
| 106 | +class TestPortableDlmSource: |
| 107 | + """F09 (Audit 03) — ``_portable_dlm_source`` emits a cwd-relative |
| 108 | + path when the ``.dlm`` lives inside the cwd (survives CI checkout), |
| 109 | + absolute path when it lives elsewhere. |
| 110 | + """ |
| 111 | + |
| 112 | + def test_cwd_relative_when_inside(self, tmp_path: Path, monkeypatch) -> None: # type: ignore[no-untyped-def] |
| 113 | + from dlm_sway.integrations.dlm.autogen import _portable_dlm_source |
| 114 | + |
| 115 | + # Set cwd to tmp_path; drop a .dlm inside a subdir. |
| 116 | + subdir = tmp_path / "src" |
| 117 | + subdir.mkdir() |
| 118 | + dlm_file = subdir / "demo.dlm" |
| 119 | + dlm_file.write_text("# empty\n") |
| 120 | + monkeypatch.chdir(tmp_path) |
| 121 | + source = _portable_dlm_source(dlm_file) |
| 122 | + assert source == "src/demo.dlm" |
| 123 | + # Not an absolute path — the whole point of F09. |
| 124 | + assert not Path(source).is_absolute() |
| 125 | + |
| 126 | + def test_absolute_when_outside(self, tmp_path: Path, monkeypatch) -> None: # type: ignore[no-untyped-def] |
| 127 | + """A ``.dlm`` somewhere outside the cwd falls back to its |
| 128 | + absolute path — relative-ization would point at a nonexistent |
| 129 | + parent directory on a fresh checkout.""" |
| 130 | + from dlm_sway.integrations.dlm.autogen import _portable_dlm_source |
| 131 | + |
| 132 | + # cwd inside tmp_path; .dlm lives in a sibling tree. |
| 133 | + cwd = tmp_path / "cwd" |
| 134 | + cwd.mkdir() |
| 135 | + sibling = tmp_path / "other" |
| 136 | + sibling.mkdir() |
| 137 | + dlm_file = sibling / "demo.dlm" |
| 138 | + dlm_file.write_text("# empty\n") |
| 139 | + monkeypatch.chdir(cwd) |
| 140 | + source = _portable_dlm_source(dlm_file) |
| 141 | + assert Path(source).is_absolute() |
| 142 | + assert source == str(dlm_file.resolve()) |
| 143 | + |
| 144 | + |
| 106 | 145 | class TestAutogenClusterKL: |
| 107 | 146 | """F07 — autogen emits ``cluster_kl`` when the prompt pool has |
| 108 | 147 | enough entries to clear S16's ``min_prompts=20`` floor, and omits |