rework: AssetInfo.name is only a display name

This commit is contained in:
bigcat88
2025-09-14 21:28:31 +03:00
parent 1d970382f0
commit dda31de690
8 changed files with 79 additions and 64 deletions

View File

@@ -288,7 +288,7 @@ async def test_upload_tags_traversal_guard(http: aiohttp.ClientSession, api_base
@pytest.mark.asyncio
@pytest.mark.parametrize("root", ["input", "output"])
async def test_duplicate_upload_same_path_updates_state(
async def test_duplicate_upload_same_display_name_does_not_clobber(
root: str,
http,
api_base: str,
@@ -296,30 +296,30 @@ async def test_duplicate_upload_same_path_updates_state(
make_asset_bytes,
):
"""
Two uploads target the exact same destination path (same tags+name) with different bytes.
Expect: file on disk is from the last upload; its AssetInfo serves content; the first AssetInfo's content 404s.
This validates that AssetCacheState(file_path) remains unique and its asset_id/mtime_ns were updated.
Two uploads use the same tags and the same display name but different bytes.
With hash-based filenames, they must NOT overwrite each other. Both assets
remain accessible and serve their original content.
"""
scope = f"dup-path-{uuid.uuid4().hex[:6]}"
name = "same_path.bin"
display_name = "same_display.bin"
d1 = make_asset_bytes(scope + "-v1", 1536)
d2 = make_asset_bytes(scope + "-v2", 2048)
tags = [root, "unit-tests", scope]
first = await asset_factory(name, tags, {}, d1)
second = await asset_factory(name, tags, {}, d2)
first = await asset_factory(display_name, tags, {}, d1)
second = await asset_factory(display_name, tags, {}, d2)
# Second one must serve the new bytes
assert first["id"] != second["id"]
assert first["asset_hash"] != second["asset_hash"] # different content
assert first["name"] == second["name"] == display_name
# Both must be independently retrievable
async with http.get(f"{api_base}/api/assets/{first['id']}/content") as r1:
b1 = await r1.read()
assert r1.status == 200
assert b1 == d1
async with http.get(f"{api_base}/api/assets/{second['id']}/content") as r2:
b2 = await r2.read()
assert r2.status == 200
assert b2 == d2
# The first AssetInfo now points to an identity with no live state for that path -> 404
async with http.get(f"{api_base}/api/assets/{first['id']}/content") as r1:
try:
body = await r1.json()
except Exception:
body = {}
assert r1.status == 404, body