Skip to content

Commit 795927b

Browse files
committed
test/docs: address review on deleteAsset delete_content removal
- Rename test_delete_upon_reference_count -> test_soft_delete_preserves_asset_identity_across_references; the old name implied last-ref cleanup, but it now verifies the opposite (soft delete preserves identity across references). - Strengthen the re-association assertion: also check asset_hash == src_hash so it proves content reuse rather than relying on the now-tautological created_new is False. - Document delete_asset_reference: the orphan-reclamation branch is intentionally internal-only; the public endpoint always soft-deletes. - Normalize the soft-delete comment phrasing.
1 parent 89aa11e commit 795927b

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

app/assets/services/asset_management.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ def delete_asset_reference(
160160
owner_id: str,
161161
delete_content_if_orphan: bool = True,
162162
) -> bool:
163+
"""Delete an asset reference.
164+
165+
With ``delete_content_if_orphan=False`` (a soft delete), the reference is
166+
hidden and the underlying content is preserved. With ``True``, the content
167+
is also removed once it becomes orphaned.
168+
169+
Note: the public DELETE /api/assets/{id} endpoint always soft-deletes
170+
(passes ``False``); the orphan-reclamation path is intentionally
171+
internal-only, retained for a future GC/admin caller.
172+
"""
163173
with create_session() as session:
164174
if not delete_content_if_orphan:
165175
# Soft delete: mark the reference as deleted but keep everything

tests-unit/assets_test/test_crud.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_get_and_delete_asset(http: requests.Session, api_base: str, seeded_asse
4545
assert "user_metadata" in detail
4646
assert "filename" in detail["user_metadata"]
4747

48-
# DELETE (soft delete; the reference is hidden, content is preserved)
48+
# Soft deletethe reference is hidden, content is preserved
4949
rd = http.delete(f"{api_base}/api/assets/{aid}", timeout=120)
5050
assert rd.status_code == 204
5151

@@ -60,7 +60,7 @@ def test_soft_delete_hides_from_get(http: requests.Session, api_base: str, seede
6060
aid = seeded_asset["id"]
6161
asset_hash = seeded_asset["asset_hash"]
6262

63-
# Soft-delete (delete is always a soft delete)
63+
# Soft delete — the reference is hidden, content is preserved
6464
rd = http.delete(f"{api_base}/api/assets/{aid}", timeout=120)
6565
assert rd.status_code == 204
6666

@@ -81,10 +81,10 @@ def test_soft_delete_hides_from_get(http: requests.Session, api_base: str, seede
8181
ids = [a["id"] for a in rl.json().get("assets", [])]
8282
assert aid not in ids
8383

84-
# The reference is already soft-deleted; content is preserved by design.
84+
# The reference is already soft-deleted; content is preserved.
8585

8686

87-
def test_delete_upon_reference_count(
87+
def test_soft_delete_preserves_asset_identity_across_references(
8888
http: requests.Session, api_base: str, seeded_asset: dict
8989
):
9090
# Create a second reference to the same asset via from-hash
@@ -118,11 +118,13 @@ def test_delete_upon_reference_count(
118118
rh2 = http.head(f"{api_base}/api/assets/hash/{src_hash}", timeout=120)
119119
assert rh2.status_code == 200 # asset identity preserved (soft delete)
120120

121-
# Re-associate via from-hash (reuses the preserved content), then
122-
# soft-delete -> content is still preserved (delete is always soft).
121+
# Re-associate via from-hash: it must reuse the same preserved content
122+
# (created_new False AND the same hash), proving the soft deletes did not
123+
# destroy the underlying asset. Then soft-delete again -> still preserved.
123124
r3 = http.post(f"{api_base}/api/assets/from-hash", json=payload, timeout=120)
124125
assert r3.status_code == 201, r3.json()
125-
assert r3.json()["created_new"] is False # content survived the soft deletes
126+
assert r3.json()["created_new"] is False
127+
assert r3.json()["asset_hash"] == src_hash # reused the surviving content
126128
aid3 = r3.json()["id"]
127129

128130
rd3 = http.delete(f"{api_base}/api/assets/{aid3}", timeout=120)

0 commit comments

Comments
 (0)