fix: ruff linting errors and add comprehensive test coverage for asset queries

- Fix unused imports in routes.py, asset.py, manager.py, asset_management.py, ingest.py
- Fix whitespace issues in upload.py, asset_info.py, ingest.py
- Fix typo in manager.py (stray character after result["asset"])
- Fix broken import in test_metadata.py (project_kv moved to asset_info.py)
- Add fixture override in queries/conftest.py for unit test isolation

Add 48 new tests covering all previously untested query functions:
- asset.py: upsert_asset, bulk_insert_assets
- cache_state.py: upsert_cache_state, delete_cache_states_outside_prefixes,
  get_orphaned_seed_asset_ids, delete_assets_by_ids, get_cache_states_for_prefixes,
  bulk_set_needs_verify, delete_cache_states_by_ids, delete_orphaned_seed_asset,
  bulk_insert_cache_states_ignore_conflicts, get_cache_states_by_paths_and_asset_ids
- asset_info.py: insert_asset_info, get_or_create_asset_info,
  update_asset_info_timestamps, replace_asset_info_metadata_projection,
  bulk_insert_asset_infos_ignore_conflicts, get_asset_info_ids_by_ids
- tags.py: bulk_insert_tags_and_meta

Total: 119 tests pass (up from 71)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Luke Mino-Altherr
2026-02-03 13:21:12 -08:00
parent 7c854e5ca0
commit c546e9315b
13 changed files with 749 additions and 20 deletions

View File

@@ -2,7 +2,6 @@ import logging
import uuid
import urllib.parse
import os
import contextlib
from aiohttp import web
from pydantic import ValidationError
@@ -20,7 +19,6 @@ from app.assets.api.upload import parse_multipart_upload
from app.assets.services.scanner import seed_assets
from typing import Any
import folder_paths
ROUTES = web.RouteTableDef()
USER_MANAGER: user_manager.UserManager | None = None

View File

@@ -16,7 +16,7 @@ from app.assets.api.schemas_in import ParsedUpload, UploadError
def validate_hash_format(s: str) -> str:
"""
Validate and normalize a hash string.
Returns canonical 'blake3:<hex>' or raises UploadError.
"""
s = s.strip().lower()

View File

@@ -1,4 +1,3 @@
from typing import Iterable
import sqlalchemy as sa
from sqlalchemy import select

View File

@@ -1,7 +1,7 @@
"""
Pure atomic database queries for AssetInfo operations.
This module contains only atomic DB operations - no business logic,
This module contains only atomic DB operations - no business logic,
no filesystem operations, no orchestration across multiple tables.
"""
from collections import defaultdict
@@ -246,7 +246,7 @@ def get_or_create_asset_info(
)
if info:
return info, True
existing = session.execute(
select(AssetInfo)
.where(

View File

@@ -28,9 +28,7 @@ from app.assets.api.upload import _cleanup_temp
from app.assets.database.queries import (
asset_exists_by_hash,
fetch_asset_info_and_asset,
fetch_asset_info_asset_and_tags,
get_asset_by_hash,
get_asset_info_by_id,
get_asset_tags,
list_asset_infos_page,
list_cache_states_by_asset_id,
@@ -417,7 +415,7 @@ def set_asset_preview(
owner_id=owner_id,
)
info = result["info"]
asset = result["asset"]T
asset = result["asset"]
tags = result["tags"]
return schemas_out.AssetDetail(

View File

@@ -18,7 +18,6 @@ from app.assets.services.path_utils import compute_relative_filename
from app.assets.database.queries import (
asset_info_exists_for_asset_id,
delete_asset_info_by_id,
fetch_asset_info_and_asset,
fetch_asset_info_asset_and_tags,
get_asset_info_by_id,
list_cache_states_by_asset_id,

View File

@@ -13,7 +13,7 @@ from sqlalchemy import select
from app.assets.database.models import Asset, Tag
from app.database.db import create_session
from app.assets.helpers import normalize_tags, pick_best_live_path, utcnow
from app.assets.helpers import normalize_tags, pick_best_live_path
from app.assets.services.path_utils import compute_relative_filename
from app.assets.database.queries import (
get_asset_by_hash,
@@ -26,7 +26,6 @@ from app.assets.database.queries import (
upsert_asset,
upsert_cache_state,
add_tags_to_asset_info,
ensure_tags_exist,
get_asset_tags,
)
@@ -147,7 +146,7 @@ def register_existing_asset(
) -> dict:
"""
Create or return existing AssetInfo for an asset that already exists by hash.
Returns dict with asset and info details, or raises ValueError if hash not found.
"""
with create_session() as session: