CI and images / lint (push) Successful in 2s
CI and images / extension-version (push) Successful in 2s
CI and images / frontend-build (push) Successful in 20s
CI and images / backend-lint-and-test (push) Successful in 30s
CI and images / integration (push) Successful in 2m18s
CI and images / sign-extension (push) Successful in 3s
CI and images / build-agent (push) Successful in 6s
CI and images / build-web (push) Successful in 1m44s
CI and images / smoke-web (push) Successful in 56s
CI and images / promote (push) Skipped
tests/factories.py holds image_row/make_image/make_image_async/make_tag. The 17 byte-identical _img/_tag helpers (15 modules) now import them under their old names, so no call site changed. frontend/test/support/stubFetch.js replaces 15 copies that differed only in formatting. Copies whose bodies differ (other defaults, other columns, a url-only stub) are left as they are; folding those needs a look at each caller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LVjrnpQjRgHdvq95rASoiR
54 lines
2.1 KiB
Python
54 lines
2.1 KiB
Python
"""Soft auto-apply (milestone 139): unconfirmed auto-applied tags do NOT train a
|
|
head. _ids_with_tag (positives) + _eligible_tag_ids (graduation count) count
|
|
human-applied + operator-confirmed tags only. Sklearn-free, so tested via
|
|
db_sync."""
|
|
import pytest
|
|
|
|
from backend.app.models import ImageRecord, Tag, TagKind, TagPositiveConfirmation
|
|
from backend.app.models.tag import image_tag
|
|
from backend.app.services.ml.heads import _eligible_tag_ids
|
|
from backend.app.services.ml.training_data import _ids_with_tag
|
|
from tests.factories import make_image as _img
|
|
from tests.factories import make_tag as _tag
|
|
|
|
pytestmark = pytest.mark.integration
|
|
|
|
|
|
def _apply(db, image_id: int, tag_id: int, source: str) -> None:
|
|
db.execute(image_tag.insert().values(
|
|
image_record_id=image_id, tag_id=tag_id, source=source,
|
|
))
|
|
|
|
|
|
def test_positives_exclude_unconfirmed_auto(db_sync):
|
|
tag = _tag(db_sync, "glasses")
|
|
man = _img(db_sync, "a" * 64)
|
|
auto = _img(db_sync, "b" * 64)
|
|
conf = _img(db_sync, "c" * 64)
|
|
acc = _img(db_sync, "d" * 64)
|
|
_apply(db_sync, man.id, tag.id, "manual")
|
|
_apply(db_sync, auto.id, tag.id, "head_auto") # unconfirmed → excluded
|
|
_apply(db_sync, conf.id, tag.id, "head_auto") # confirmed → included
|
|
_apply(db_sync, acc.id, tag.id, "ml_accepted")
|
|
db_sync.add(TagPositiveConfirmation(image_record_id=conf.id, tag_id=tag.id))
|
|
db_sync.commit()
|
|
|
|
pos = set(_ids_with_tag(db_sync, tag.id))
|
|
assert pos == {man.id, conf.id, acc.id}
|
|
assert auto.id not in pos
|
|
|
|
|
|
def test_eligibility_counts_positives_only(db_sync):
|
|
# A concept whose only tags are unconfirmed auto-applies does NOT graduate.
|
|
tag = _tag(db_sync, "autotag")
|
|
for i in range(3):
|
|
_apply(db_sync, _img(db_sync, f"e{i}" * 32).id, tag.id, "head_auto")
|
|
db_sync.commit()
|
|
assert tag.id not in _eligible_tag_ids(db_sync, min_pos=2)
|
|
|
|
# Two human positives → now eligible at min_pos=2.
|
|
for i in range(2):
|
|
_apply(db_sync, _img(db_sync, f"h{i}" * 32).id, tag.id, "manual")
|
|
db_sync.commit()
|
|
assert tag.id in _eligible_tag_ids(db_sync, min_pos=2)
|