Skip to content

Commit ecf45a2

Browse files
committed
fix(test): split unsafe persona_id test — ValueError for dot-prefix
The original test expected '../weird id/with slashes' to be sanitized and stored, but the production code correctly rejects IDs that sanitize to filenames starting with '.' (hidden files = security concern). Split into two tests: 1. test_persona_id_with_slashes_and_spaces_is_sanitized — tests '/' and ' ' 2. test_persona_id_starting_with_dot_raises_valueerror — tests ValueError CEO-Session 2026-05-13
1 parent ee512cf commit ecf45a2

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

survey-cli/tests/test_trajectory_judge.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,13 @@ def test_quarantine_entry_is_frozen() -> None:
329329
e.reason = "tampered" # type: ignore[misc]
330330

331331

332-
def test_persona_id_with_unsafe_chars_is_sanitized(tmp_path: Path) -> None:
332+
def test_persona_id_with_slashes_and_spaces_is_sanitized(tmp_path: Path) -> None:
333333
"""
334-
persona_ids containing '/', whitespace, or '..' must NOT escape the
335-
store_root. The sanitizer replaces those chars with '_'.
334+
persona_ids containing '/' or whitespace must be sanitized to safe filenames.
335+
The sanitizer replaces those chars with '_'.
336336
"""
337337
entry = quarantine(
338-
"../weird id/with slashes",
338+
"weird id/with slashes", # No leading dots
339339
reason="r",
340340
store_root=tmp_path,
341341
now=1,
@@ -346,5 +346,19 @@ def test_persona_id_with_unsafe_chars_is_sanitized(tmp_path: Path) -> None:
346346
assert files[0].parent == tmp_path
347347
# And the entry can be looked up by the same (un-sanitized) id, because
348348
# the sanitization is deterministic.
349-
assert is_quarantined("../weird id/with slashes", store_root=tmp_path) is True
350-
assert entry.persona_id == "../weird id/with slashes" # stored verbatim in JSON
349+
assert is_quarantined("weird id/with slashes", store_root=tmp_path) is True
350+
assert entry.persona_id == "weird id/with slashes" # stored verbatim in JSON
351+
352+
353+
def test_persona_id_starting_with_dot_raises_valueerror(tmp_path: Path) -> None:
354+
"""
355+
persona_ids that sanitize to a filename starting with '.' must raise
356+
ValueError to prevent hidden files (security concern).
357+
"""
358+
with pytest.raises(ValueError, match="sanitizes to empty/hidden filename"):
359+
quarantine(
360+
"../weird id", # After sanitization: '..weird_id' starts with '.'
361+
reason="r",
362+
store_root=tmp_path,
363+
now=1,
364+
)

0 commit comments

Comments
 (0)