test(backend): add 2 missing test cases from coderabbitai review

- test_unknown_mime_falls_through_to_extension: verifies that when an
  unrecognized MIME is present, infer_format_from_uri falls through to
  extension-based detection (e.g. text/plain + .csv → csv)
- test_bare_ref_binary_format_ignores_line_range: documents that binary
  bare refs (parquet/xlsx) silently drop the [start-end] range and parse
  full file content (line slicing is meaningless on binary bytes)
This commit is contained in:
Zamil Majdy
2026-03-15 22:58:01 +07:00
parent d10ae1f392
commit 1b7a446e97
2 changed files with 36 additions and 0 deletions

View File

@@ -1893,3 +1893,35 @@ async def test_adapt_dict_to_list_str_target_not_wrapped():
# Dict should pass through unchanged, not wrapped in [dict]
assert result["data"] == {"key": "value"}
# ---------------------------------------------------------------------------
# Binary format + line range behaviour
# ---------------------------------------------------------------------------
@pytest.mark.asyncio
async def test_bare_ref_binary_format_ignores_line_range():
"""Binary bare refs (parquet/xlsx) silently ignore line ranges and
parse the full file — line slicing on binary bytes is meaningless."""
import io
import pandas as pd
df = pd.DataFrame({"A": [1, 2], "B": [3, 4]})
buf = io.BytesIO()
df.to_parquet(buf, index=False)
parquet_bytes = buf.getvalue()
with patch(
"backend.copilot.sdk.file_ref.read_file_bytes",
new=AsyncMock(return_value=parquet_bytes),
):
# [1-1] line range is silently ignored; full parquet is parsed.
result = await expand_file_refs_in_args(
{"data": "@@agptfile:workspace:///data.parquet[1-1]"},
user_id="u1",
session=_make_session(),
)
# Full 2-row table is returned, not just row 1.
assert result["data"] == [["A", "B"], [1, 3], [2, 4]]

View File

@@ -102,6 +102,10 @@ class TestInferFormat:
def test_unknown_mime(self):
assert infer_format_from_uri("workspace://abc123#text/plain") is None
def test_unknown_mime_falls_through_to_extension(self):
# Unknown MIME (text/plain) should fall through to extension-based detection.
assert infer_format_from_uri("workspace:///data.csv#text/plain") == "csv"
# --- MIME takes precedence over extension ---
def test_mime_overrides_extension(self):