8Validate path containment (OI-405) and ``.octrc.json`` size cap (OI-414)
9logic in ``oct.core.project_root``.
13- Confirm ``validate_path_containment`` accepts paths within the project.
14- Confirm it rejects paths outside unless ``allow_outside=True``.
15- Confirm oversized ``.octrc.json`` files are skipped during root
16 discovery and a warning is emitted.
27Inputs: tmp_path fixture
28Outputs: pass/fail assertions
36from oct.core
import project_root
40 root = tmp_path /
"proj"
42 inner = root /
"src" /
"mod"
43 inner.mkdir(parents=
True)
45 assert result == inner.resolve()
49 root = tmp_path /
"proj"
51 outside = tmp_path /
"other"
53 with pytest.raises(click.ClickException)
as exc:
55 assert "outside project root" in str(exc.value.message)
59 root = tmp_path /
"proj"
61 outside = tmp_path /
"other"
64 outside, root, allow_outside=
True
66 assert result == outside.resolve()
70 """A ``.octrc.json`` larger than MAX_OCTRC_SIZE is skipped with a warning."""
72 proj = tmp_path /
"proj"
73 (proj /
"docs").mkdir(parents=
True)
74 (proj /
"tests").mkdir()
75 (proj /
"oc_diagnostics").mkdir()
78 octrc = proj /
".octrc.json"
80 padding =
"x" * (project_root.MAX_OCTRC_SIZE + 1024)
81 octrc.write_text(json.dumps({
"root_marker":
True,
"_pad": padding}))
86 captured = capsys.readouterr()
87 assert "skipping" in captured.err
88 assert str(project_root.MAX_OCTRC_SIZE)
in captured.err
90 assert result == proj.resolve()
94 """A small ``.octrc.json`` with root_marker=True wins over structural detection."""
95 proj = tmp_path /
"proj"
97 (proj /
".octrc.json").write_text(
'{"root_marker": true}')
99 sub = proj /
"a" /
"b"
100 sub.mkdir(parents=
True)
102 assert result == proj.resolve()
Path validate_path_containment(Path path, Path project_root, bool allow_outside=False)
Path find_project_root(Path start)
test_validate_path_containment_inside_passes(tmp_path)
test_validate_path_containment_allow_outside_passes(tmp_path)
test_octrc_size_cap_skipped(tmp_path, capsys)
test_validate_path_containment_outside_raises(tmp_path)
test_small_octrc_with_root_marker_found(tmp_path)