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

Show on the map →

Called by none

Calls _span, load_traces

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

requirementlinkedpath to the implementer
REQ-DDB-WIKI-036measuredtest_the_repository_and_home_paths_are_redacted → load_traces
REQ-DDB-WIKI-049measuredtest_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

Activity · 11 steps
lines 45–45home = tmp_path / "home" / "dev"lines 46–46repo = home / "work" / "proj"lines 47–47(repo / "traces").mkdir(parents=True)lines 48–48monkeypatch.setenv("HOME", str(home))lines 49–49value = f"[PosixPath('{repo}/src/a.py'), '{home}/.cache/x']"lines 50–50(repo / "traces" / "t.json").write_text(json.dumps(_span(value)))lines 51–51[(rel, otlp)] = load_traces(repo, ("traces/*.json",))lines 52–52attr = otlp["resourceSpans"][0]["scopeSpans"][0]["spans"][0]["attributes"][0]lines 53–53assert attr["key"] == "code.return"lines 54–54assert attr["value"]["stringValue"] == "[PosixPath('<repo>/src/a.py'), '~/.cache/x']"lines 55–55assert str(home) not in json.dumps(otlp)