Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libCRS/libCRS/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,10 @@ def run_pov(
runner_url = self._get_service_url(builder)
data = {
"harness_name": harness_name,
"rebuild_id": rebuild_id or "OSS_CRS_BASE",
"crs_name": crs_name,
}
if rebuild_id is not None:
data["rebuild_id"] = rebuild_id
try:
with open(pov_path, "rb") as f:
files = {
Expand Down
2 changes: 1 addition & 1 deletion oss-crs-infra/runner-sidecar/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def run_pov(
"""
pov_timeout = int(os.environ.get("POV_TIMEOUT", "30"))

if rebuild_id is not None and rebuild_id != "OSS_CRS_BASE":
if rebuild_id is not None:
# Rebuild artifacts: /out/{crs_name}/{rebuild_id}/build/{harness_name}
out_dir = os.environ.get("OUT_DIR", "/out")
harness_dir = os.path.join(out_dir, crs_name, str(rebuild_id), "build")
Expand Down
27 changes: 27 additions & 0 deletions oss_crs/tests/unit/test_local_crs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,33 @@ def test_does_not_use_submit_and_poll(self, mock_requests, crs_utils, tmp_path):
# No GET calls were made (no job polling)
assert mock_requests.get.call_count == 0

@patch("libCRS.libCRS.local.http_requests")
def test_omits_rebuild_id_when_none(self, mock_requests, crs_utils, tmp_path):
"""When rebuild_id is None (base build), the client must not send a
rebuild_id field at all. The server uses Form(None) default to detect
this. Sending a sentinel string instead of omitting the field caused
a writable-overlay bug on the server side.
"""
mock_requests.post.return_value = _mock_response(
json_data={"exit_code": 0, "stderr": ""}
)
response_dir = tmp_path / "response"
pov_file = tmp_path / "crash"
pov_file.write_bytes(b"crashdata")

crs_utils.run_pov(
pov_file, "fuzzer", response_dir, rebuild_id=None, builder="test-runner"
)

call_kwargs = mock_requests.post.call_args
data = call_kwargs.kwargs.get("data") or (
call_kwargs[1].get("data", {}) if len(call_kwargs) > 1 else {}
)
assert "rebuild_id" not in data, (
f"Client must not send rebuild_id when it is None, "
f"but sent: {data.get('rebuild_id')!r}"
)


# ---------------------------------------------------------------------------
# INT-04: apply_patch_test
Expand Down
78 changes: 78 additions & 0 deletions oss_crs/tests/unit/test_runner_sidecar.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,81 @@ def test_sets_fuzzer_args_default(self, mock_exists, mock_run):
call_kwargs = mock_run.call_args[1]
assert "FUZZER_ARGS" in call_kwargs["env"]
assert "-rss_limit_mb=2560" in call_kwargs["env"]["FUZZER_ARGS"]


# ===========================================================================
# TestRunPOVDefaultRebuildId — writable overlay for base build
# ===========================================================================


class TestRunPOVDefaultRebuildId:
"""When rebuild_id is not provided (base build), the server must create a
writable temp overlay for OUT, since the base build directory is read-only.

This test exercises the client-to-server contract: the client omits
rebuild_id when it is None, and the server correctly detects this and
creates the writable overlay. The test is intentionally independent of
any sentinel value — it only checks observable behavior (the OUT env var
used by subprocess).
"""

@patch("runner_server.subprocess.run")
@patch("runner_server.os.listdir", return_value=["my_fuzzer"])
@patch("runner_server.os.symlink")
@patch("runner_server.os.path.exists", return_value=True)
def test_default_rebuild_id_uses_writable_out(
self, mock_exists, mock_symlink, mock_listdir, mock_run
):
"""No rebuild_id ⇒ OUT is a writable temp dir, not the read-only base path."""
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
client = _make_test_client()

# Client sends NO rebuild_id field — simulates what libCRS does for
# the default (base build) case.
upload = {
"files": {
"pov": ("crash.bin", b"\x00deadbeef", "application/octet-stream")
},
"data": {
"harness_name": "my_fuzzer",
"crs_name": "test-crs",
# rebuild_id intentionally absent
},
}
with patch.dict("os.environ", {"BUILD_OUT_DIR": "/build_out"}):
response = client.post("/run-pov", **upload)

assert response.status_code == 200
call_kwargs = mock_run.call_args[1]
out_env = call_kwargs["env"]["OUT"]
# OUT must NOT be the read-only base build path
assert not out_env.startswith("/build_out"), (
f"OUT should be a writable temp dir, not the read-only base path: {out_env}"
)
# OUT should be a temp directory (created by tempfile.mkdtemp)
assert "run-pov-out-" in out_env

@patch("runner_server.subprocess.run")
@patch("runner_server.os.path.exists", return_value=True)
def test_explicit_rebuild_id_uses_rebuild_path(self, mock_exists, mock_run):
"""Explicit rebuild_id ⇒ OUT points to the rebuild artifacts dir."""
mock_run.return_value = MagicMock(returncode=0, stdout="", stderr="")
client = _make_test_client()

upload = {
"files": {
"pov": ("crash.bin", b"\x00deadbeef", "application/octet-stream")
},
"data": {
"harness_name": "my_fuzzer",
"crs_name": "test-crs",
"rebuild_id": "42",
},
}
with patch.dict("os.environ", {"OUT_DIR": "/out"}):
response = client.post("/run-pov", **upload)

assert response.status_code == 200
call_kwargs = mock_run.call_args[1]
out_env = call_kwargs["env"]["OUT"]
assert out_env == "/out/test-crs/42/build"
Loading