fix(uploads): ignore mention references in new upload detection
This commit is contained in:
parent
3caa2d6ce1
commit
3d472761c8
|
|
@ -168,6 +168,9 @@ class UploadsMiddleware(AgentMiddleware[UploadsMiddlewareState]):
|
||||||
for f in kwargs_files:
|
for f in kwargs_files:
|
||||||
if not isinstance(f, dict):
|
if not isinstance(f, dict):
|
||||||
continue
|
continue
|
||||||
|
# Mention references are context pointers, not newly uploaded files.
|
||||||
|
if f.get("ref_kind") == "mention":
|
||||||
|
continue
|
||||||
filename = f.get("filename") or ""
|
filename = f.get("filename") or ""
|
||||||
if not filename or Path(filename).name != filename:
|
if not filename or Path(filename).name != filename:
|
||||||
continue
|
continue
|
||||||
|
|
|
||||||
|
|
@ -143,6 +143,45 @@ class TestFilesFromKwargs:
|
||||||
assert result is not None
|
assert result is not None
|
||||||
assert result[0]["size"] == 0
|
assert result[0]["size"] == 0
|
||||||
|
|
||||||
|
def test_skips_mention_reference_entries(self, tmp_path):
|
||||||
|
mw = _middleware(tmp_path)
|
||||||
|
msg = _human(
|
||||||
|
"hi",
|
||||||
|
files=[
|
||||||
|
{
|
||||||
|
"filename": "mention.jpg",
|
||||||
|
"size": 123,
|
||||||
|
"path": "/mnt/user-data/uploads/mention.jpg",
|
||||||
|
"ref_kind": "mention",
|
||||||
|
"ref_source": "upload",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
)
|
||||||
|
assert mw._files_from_kwargs(msg) is None
|
||||||
|
|
||||||
|
def test_mixed_list_keeps_uploads_but_skips_mentions(self, tmp_path):
|
||||||
|
mw = _middleware(tmp_path)
|
||||||
|
msg = _human(
|
||||||
|
"hi",
|
||||||
|
files=[
|
||||||
|
{
|
||||||
|
"filename": "uploaded.txt",
|
||||||
|
"size": 10,
|
||||||
|
"path": "/mnt/user-data/uploads/uploaded.txt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"filename": "mentioned.txt",
|
||||||
|
"size": 8,
|
||||||
|
"path": "/mnt/user-data/uploads/mentioned.txt",
|
||||||
|
"ref_kind": "mention",
|
||||||
|
"ref_source": "upload",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
)
|
||||||
|
result = mw._files_from_kwargs(msg)
|
||||||
|
assert result is not None
|
||||||
|
assert [f["filename"] for f in result] == ["uploaded.txt"]
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# _create_files_message
|
# _create_files_message
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue