test_wiki_trace_redact.py¶
tests/test_wiki_trace_redact.py
Traced values published in the wiki carry no local paths (2.1 roadmap).
test_the_repository_and_home_paths_are_redacted
None test_wiki_trace_redact.test_the_repository_and_home_paths_are_redacted(Path tmp_path, monkeypatch)
`<repo>` for the repository, `~` for the home directory; the key untouched.
tests/test_wiki_trace_redact.py:43
Checks
assert attr["key"] == "code.return"assert attr["value"]["stringValue"] == "[PosixPath('<repo>/src/a.py'), '~/.cache/x']"assert str(home) not in json.dumps(otlp)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-WIKI-036 | measured | test_the_repository_and_home_paths_are_redacted → load_traces |
| REQ-DDB-WIKI-049 | measured | test_the_repository_and_home_paths_are_redacted → load_traces → redact_local_paths |
Source · 13 lines
def test_the_repository_and_home_paths_are_redacted(tmp_path: Path, monkeypatch) -> None: # noqa: ANN001
"""@brief `<repo>` for the repository, `~` for the home directory; the key untouched."""
home = tmp_path / "home" / "dev"
repo = home / "work" / "proj"
(repo / "traces").mkdir(parents=True)
monkeypatch.setenv("HOME", str(home))
value = f"[PosixPath('{repo}/src/a.py'), '{home}/.cache/x']"
(repo / "traces" / "t.json").write_text(json.dumps(_span(value)))
[(rel, otlp)] = load_traces(repo, ("traces/*.json",))
attr = otlp["resourceSpans"][0]["scopeSpans"][0]["spans"][0]["attributes"][0]
assert attr["key"] == "code.return"
assert attr["value"]["stringValue"] == "[PosixPath('<repo>/src/a.py'), '~/.cache/x']"
assert str(home) not in json.dumps(otlp)1 more lines, not shown