549 行
20 KiB
Python
549 行
20 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import json
|
||
|
|
import sqlite3
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from backend.services.cost_service import CostService
|
||
|
|
from backend.services.data_backup_service import (
|
||
|
|
PROMPT_BACKUP_PLACEHOLDER,
|
||
|
|
_sanitize_sqlite_backup,
|
||
|
|
)
|
||
|
|
from backend.services.material_analytics_service import MaterialAnalyticsService
|
||
|
|
from backend.services.orphan_media_service import OrphanMediaService
|
||
|
|
from database.db_helper import Database, DatabaseSettings, SqliteSettings
|
||
|
|
|
||
|
|
|
||
|
|
def _database(path: Path) -> Database:
|
||
|
|
return Database(
|
||
|
|
DatabaseSettings(
|
||
|
|
backend="sqlite",
|
||
|
|
sqlite=SqliteSettings(path=str(path)),
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_prompt_redaction_preserves_not_null_advanced_material_columns(tmp_path: Path) -> None:
|
||
|
|
path = tmp_path / "backup-redaction.sqlite3"
|
||
|
|
with sqlite3.connect(path) as connection:
|
||
|
|
connection.executescript(
|
||
|
|
"""
|
||
|
|
CREATE TABLE advanced_material_imports (
|
||
|
|
import_id TEXT PRIMARY KEY,
|
||
|
|
recognition_prompt TEXT,
|
||
|
|
recognition_negative_prompt TEXT,
|
||
|
|
recognition_result_json TEXT,
|
||
|
|
error_json TEXT,
|
||
|
|
metadata_json TEXT
|
||
|
|
);
|
||
|
|
CREATE TABLE advanced_material_validation_attempts (
|
||
|
|
attempt_id TEXT PRIMARY KEY,
|
||
|
|
prompt TEXT NOT NULL,
|
||
|
|
negative_prompt TEXT,
|
||
|
|
adjustment_text TEXT,
|
||
|
|
decision_notes TEXT,
|
||
|
|
usage_json TEXT,
|
||
|
|
error_json TEXT,
|
||
|
|
metadata_json TEXT
|
||
|
|
);
|
||
|
|
CREATE TABLE advanced_materials (
|
||
|
|
material_id TEXT PRIMARY KEY,
|
||
|
|
prompt TEXT NOT NULL,
|
||
|
|
negative_prompt TEXT,
|
||
|
|
capsule_json TEXT,
|
||
|
|
metadata_json TEXT
|
||
|
|
);
|
||
|
|
CREATE TABLE advanced_style_sources (
|
||
|
|
source_id TEXT PRIMARY KEY,
|
||
|
|
recognition_prompt TEXT,
|
||
|
|
recognition_negative_prompt TEXT,
|
||
|
|
recognition_tags_json TEXT,
|
||
|
|
recognition_result_json TEXT,
|
||
|
|
error_json TEXT,
|
||
|
|
metadata_json TEXT
|
||
|
|
);
|
||
|
|
CREATE TABLE advanced_style_consensus_runs (
|
||
|
|
consensus_id TEXT PRIMARY KEY,
|
||
|
|
prompt TEXT,
|
||
|
|
negative_prompt TEXT,
|
||
|
|
source_ids_json TEXT,
|
||
|
|
tags_json TEXT,
|
||
|
|
result_json TEXT,
|
||
|
|
error_json TEXT,
|
||
|
|
metadata_json TEXT
|
||
|
|
);
|
||
|
|
CREATE TABLE advanced_style_validation_cases (
|
||
|
|
case_id TEXT PRIMARY KEY,
|
||
|
|
content_prompt TEXT NOT NULL,
|
||
|
|
final_prompt TEXT NOT NULL,
|
||
|
|
negative_prompt TEXT,
|
||
|
|
usage_json TEXT,
|
||
|
|
style_review_json TEXT,
|
||
|
|
error_json TEXT,
|
||
|
|
metadata_json TEXT
|
||
|
|
);
|
||
|
|
"""
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_material_imports VALUES (?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"import-1",
|
||
|
|
"recognition prompt",
|
||
|
|
"recognition negative",
|
||
|
|
json.dumps({"prompt": "nested recognition prompt"}),
|
||
|
|
None,
|
||
|
|
None,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_material_validation_attempts VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"attempt-1",
|
||
|
|
"validation prompt",
|
||
|
|
"validation negative",
|
||
|
|
"make it redder",
|
||
|
|
"review notes",
|
||
|
|
None,
|
||
|
|
None,
|
||
|
|
json.dumps({"expanded_prompt": "nested validation prompt"}),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_materials VALUES (?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"advmat-1",
|
||
|
|
"sealed prompt",
|
||
|
|
"sealed negative",
|
||
|
|
json.dumps({"prompt": "nested sealed prompt"}),
|
||
|
|
None,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_sources VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"source-1",
|
||
|
|
"source recognition",
|
||
|
|
"source negative",
|
||
|
|
json.dumps(["watercolor"]),
|
||
|
|
json.dumps({"prompt": "nested source prompt"}),
|
||
|
|
None,
|
||
|
|
None,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_consensus_runs VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"consensus-1",
|
||
|
|
"consensus prompt",
|
||
|
|
"consensus negative",
|
||
|
|
json.dumps(["source-1"]),
|
||
|
|
json.dumps(["watercolor"]),
|
||
|
|
json.dumps({"prompt": "nested consensus prompt"}),
|
||
|
|
None,
|
||
|
|
None,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_validation_cases VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"case-1",
|
||
|
|
"new character",
|
||
|
|
"watercolor, new character",
|
||
|
|
"photorealistic",
|
||
|
|
None,
|
||
|
|
json.dumps({"expanded_prompt": "reviewed prompt"}),
|
||
|
|
None,
|
||
|
|
None,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.commit()
|
||
|
|
|
||
|
|
_sanitize_sqlite_backup(
|
||
|
|
path,
|
||
|
|
include_prompt_records=False,
|
||
|
|
include_moderation_records=True,
|
||
|
|
)
|
||
|
|
|
||
|
|
with sqlite3.connect(path) as connection:
|
||
|
|
import_row = connection.execute(
|
||
|
|
"SELECT recognition_prompt, recognition_negative_prompt, recognition_result_json "
|
||
|
|
"FROM advanced_material_imports"
|
||
|
|
).fetchone()
|
||
|
|
attempt_row = connection.execute(
|
||
|
|
"SELECT prompt, negative_prompt, adjustment_text, decision_notes, metadata_json "
|
||
|
|
"FROM advanced_material_validation_attempts"
|
||
|
|
).fetchone()
|
||
|
|
material_row = connection.execute(
|
||
|
|
"SELECT prompt, negative_prompt, capsule_json FROM advanced_materials"
|
||
|
|
).fetchone()
|
||
|
|
source_row = connection.execute(
|
||
|
|
"SELECT recognition_prompt, recognition_negative_prompt, recognition_result_json "
|
||
|
|
"FROM advanced_style_sources"
|
||
|
|
).fetchone()
|
||
|
|
consensus_row = connection.execute(
|
||
|
|
"SELECT prompt, negative_prompt, result_json FROM advanced_style_consensus_runs"
|
||
|
|
).fetchone()
|
||
|
|
case_row = connection.execute(
|
||
|
|
"SELECT content_prompt, final_prompt, negative_prompt, style_review_json "
|
||
|
|
"FROM advanced_style_validation_cases"
|
||
|
|
).fetchone()
|
||
|
|
|
||
|
|
assert import_row[:2] == (None, None)
|
||
|
|
assert json.loads(import_row[2])["prompt"] == PROMPT_BACKUP_PLACEHOLDER
|
||
|
|
assert attempt_row[:4] == (PROMPT_BACKUP_PLACEHOLDER, None, None, None)
|
||
|
|
assert json.loads(attempt_row[4])["expanded_prompt"] == PROMPT_BACKUP_PLACEHOLDER
|
||
|
|
assert material_row[:2] == (PROMPT_BACKUP_PLACEHOLDER, None)
|
||
|
|
assert json.loads(material_row[2])["prompt"] == PROMPT_BACKUP_PLACEHOLDER
|
||
|
|
assert source_row[:2] == (None, None)
|
||
|
|
assert json.loads(source_row[2])["prompt"] == PROMPT_BACKUP_PLACEHOLDER
|
||
|
|
assert consensus_row[:2] == (None, None)
|
||
|
|
assert json.loads(consensus_row[2])["prompt"] == PROMPT_BACKUP_PLACEHOLDER
|
||
|
|
assert case_row[:3] == (
|
||
|
|
PROMPT_BACKUP_PLACEHOLDER,
|
||
|
|
PROMPT_BACKUP_PLACEHOLDER,
|
||
|
|
None,
|
||
|
|
)
|
||
|
|
assert json.loads(case_row[3])["expanded_prompt"] == PROMPT_BACKUP_PLACEHOLDER
|
||
|
|
|
||
|
|
|
||
|
|
def test_cost_summary_counts_failed_or_cancelled_attempts_with_billable_evidence(
|
||
|
|
tmp_path: Path,
|
||
|
|
) -> None:
|
||
|
|
path = tmp_path / "advanced-material-cost.sqlite3"
|
||
|
|
database = _database(path)
|
||
|
|
database.initialize()
|
||
|
|
|
||
|
|
with database.connect() as connection:
|
||
|
|
connection.execute(
|
||
|
|
"""
|
||
|
|
INSERT INTO advanced_material_imports (
|
||
|
|
import_id, display_name, source_image_uri, status
|
||
|
|
) VALUES (?, ?, ?, ?)
|
||
|
|
""",
|
||
|
|
("import-cost", "Cost material", "storage://advanced_materials/source.png", "failed"),
|
||
|
|
)
|
||
|
|
attempts = (
|
||
|
|
(
|
||
|
|
"attempt-failed-usage",
|
||
|
|
1,
|
||
|
|
"failed",
|
||
|
|
json.dumps({"total_tokens": 125, "input_tokens": 75, "output_tokens": 50}),
|
||
|
|
None,
|
||
|
|
),
|
||
|
|
(
|
||
|
|
"attempt-cancelled-image",
|
||
|
|
2,
|
||
|
|
"cancelled",
|
||
|
|
None,
|
||
|
|
"storage://advanced_materials/attempts/cancelled.png",
|
||
|
|
),
|
||
|
|
("attempt-failed-empty", 3, "failed", None, None),
|
||
|
|
)
|
||
|
|
for attempt_id, number, status, usage_json, image_uri in attempts:
|
||
|
|
connection.execute(
|
||
|
|
"""
|
||
|
|
INSERT INTO advanced_material_validation_attempts (
|
||
|
|
attempt_id, import_id, attempt_number, status, prompt,
|
||
|
|
model_route, provider_id, provider_model, usage_json,
|
||
|
|
validation_image_uri
|
||
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||
|
|
""",
|
||
|
|
(
|
||
|
|
attempt_id,
|
||
|
|
"import-cost",
|
||
|
|
number,
|
||
|
|
status,
|
||
|
|
"validation prompt",
|
||
|
|
"advanced-route",
|
||
|
|
"provider-a",
|
||
|
|
"model-a",
|
||
|
|
usage_json,
|
||
|
|
image_uri,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.commit()
|
||
|
|
|
||
|
|
summary = CostService(
|
||
|
|
database,
|
||
|
|
unit_prices={
|
||
|
|
"provider-a:model-a": {
|
||
|
|
"per_request": 1,
|
||
|
|
"per_image": 0.5,
|
||
|
|
"per_1k_tokens": 2,
|
||
|
|
}
|
||
|
|
},
|
||
|
|
).usage_summary()
|
||
|
|
|
||
|
|
assert summary["totals"] == {
|
||
|
|
"image_count": 1,
|
||
|
|
"task_count": 2,
|
||
|
|
"total_tokens": 125,
|
||
|
|
"input_tokens": 75,
|
||
|
|
"output_tokens": 50,
|
||
|
|
"estimated_cost": 2.75,
|
||
|
|
}
|
||
|
|
assert len(summary["groups"]) == 1
|
||
|
|
|
||
|
|
|
||
|
|
def test_style_validation_cost_uses_cases_without_charging_attempt_projection_twice(
|
||
|
|
tmp_path: Path,
|
||
|
|
) -> None:
|
||
|
|
path = tmp_path / "advanced-style-cost.sqlite3"
|
||
|
|
database = _database(path)
|
||
|
|
database.initialize()
|
||
|
|
|
||
|
|
with database.connect() as connection:
|
||
|
|
connection.execute(
|
||
|
|
"""
|
||
|
|
INSERT INTO advanced_material_imports (
|
||
|
|
import_id, display_name, source_image_uri, status, metadata_json
|
||
|
|
) VALUES (?, ?, ?, ?, ?)
|
||
|
|
""",
|
||
|
|
(
|
||
|
|
"style-cost-import",
|
||
|
|
"Style cost",
|
||
|
|
"storage://advanced_materials/style-cost/source.png",
|
||
|
|
"awaiting_review",
|
||
|
|
json.dumps({"workflow_kind": "style_set"}),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"""
|
||
|
|
INSERT INTO advanced_material_validation_attempts (
|
||
|
|
attempt_id, import_id, attempt_number, status, prompt,
|
||
|
|
model_route, provider_id, provider_model, usage_json,
|
||
|
|
validation_image_uri
|
||
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||
|
|
""",
|
||
|
|
(
|
||
|
|
"style-cost-attempt",
|
||
|
|
"style-cost-import",
|
||
|
|
1,
|
||
|
|
"awaiting_review",
|
||
|
|
"watercolor",
|
||
|
|
"style-route",
|
||
|
|
"provider-style",
|
||
|
|
"model-style",
|
||
|
|
json.dumps({"total_tokens": 999}),
|
||
|
|
"storage://advanced_materials/style-cost/portrait.png",
|
||
|
|
),
|
||
|
|
)
|
||
|
|
for index, case_key in enumerate(("portrait", "fullbody", "scene")):
|
||
|
|
connection.execute(
|
||
|
|
"""
|
||
|
|
INSERT INTO advanced_style_validation_cases (
|
||
|
|
case_id, attempt_id, import_id, case_key, sort_order,
|
||
|
|
status, content_prompt, final_prompt, model_route,
|
||
|
|
provider_id, provider_model, validation_image_uri, usage_json
|
||
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||
|
|
""",
|
||
|
|
(
|
||
|
|
f"style-cost-{case_key}",
|
||
|
|
"style-cost-attempt",
|
||
|
|
"style-cost-import",
|
||
|
|
case_key,
|
||
|
|
index,
|
||
|
|
"succeeded",
|
||
|
|
case_key,
|
||
|
|
f"watercolor, {case_key}",
|
||
|
|
"style-route",
|
||
|
|
"provider-style",
|
||
|
|
"model-style",
|
||
|
|
f"storage://advanced_materials/style-cost/{case_key}.png",
|
||
|
|
json.dumps({"total_tokens": 20, "input_tokens": 12, "output_tokens": 8}),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.commit()
|
||
|
|
|
||
|
|
summary = CostService(
|
||
|
|
database,
|
||
|
|
unit_prices={
|
||
|
|
"provider-style:model-style": {
|
||
|
|
"per_request": 1,
|
||
|
|
"per_image": 0.5,
|
||
|
|
"per_1k_tokens": 2,
|
||
|
|
}
|
||
|
|
},
|
||
|
|
).usage_summary()
|
||
|
|
|
||
|
|
assert summary["totals"] == {
|
||
|
|
"image_count": 3,
|
||
|
|
"task_count": 3,
|
||
|
|
"total_tokens": 60,
|
||
|
|
"input_tokens": 36,
|
||
|
|
"output_tokens": 24,
|
||
|
|
"estimated_cost": 4.62,
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def test_orphan_scan_keeps_style_sources_and_validation_cases_referenced(tmp_path: Path) -> None:
|
||
|
|
path = tmp_path / "advanced-style-orphans.sqlite3"
|
||
|
|
database = _database(path)
|
||
|
|
database.initialize()
|
||
|
|
source_uri = "storage://advanced_materials/style-orphan/source.png"
|
||
|
|
validation_uri = "storage://advanced_materials/style-orphan/validation.png"
|
||
|
|
with database.connect() as connection:
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_material_imports "
|
||
|
|
"(import_id, display_name, source_image_uri, status) VALUES (?, ?, ?, ?)",
|
||
|
|
("style-orphan-import", "Style orphan", source_uri, "validating"),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_material_validation_attempts "
|
||
|
|
"(attempt_id, import_id, attempt_number, status, prompt) VALUES (?, ?, ?, ?, ?)",
|
||
|
|
("style-orphan-attempt", "style-orphan-import", 1, "running", "watercolor"),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_sources "
|
||
|
|
"(source_id, import_id, sort_order, is_primary, source_image_uri, status) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?, ?)",
|
||
|
|
("style-orphan-source", "style-orphan-import", 0, 1, source_uri, "succeeded"),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_validation_cases "
|
||
|
|
"(case_id, attempt_id, import_id, case_key, sort_order, status, "
|
||
|
|
"content_prompt, final_prompt, validation_image_uri) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"style-orphan-case",
|
||
|
|
"style-orphan-attempt",
|
||
|
|
"style-orphan-import",
|
||
|
|
"portrait",
|
||
|
|
0,
|
||
|
|
"succeeded",
|
||
|
|
"portrait",
|
||
|
|
"watercolor portrait",
|
||
|
|
validation_uri,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.commit()
|
||
|
|
|
||
|
|
class FakeMediaIndex:
|
||
|
|
def index_files(self, *, root=None, limit=500):
|
||
|
|
del root, limit
|
||
|
|
return {
|
||
|
|
"items": [
|
||
|
|
{"uri": source_uri},
|
||
|
|
{"uri": validation_uri},
|
||
|
|
{"uri": "storage://advanced_materials/style-orphan/unreferenced.png"},
|
||
|
|
],
|
||
|
|
"total": 3,
|
||
|
|
"truncated": False,
|
||
|
|
}
|
||
|
|
|
||
|
|
result = OrphanMediaService(database, FakeMediaIndex()).scan()
|
||
|
|
|
||
|
|
assert result["orphan_count"] == 1
|
||
|
|
assert result["orphans"][0]["uri"].endswith("unreferenced.png")
|
||
|
|
|
||
|
|
|
||
|
|
def test_material_analytics_reports_style_set_pipeline(tmp_path: Path) -> None:
|
||
|
|
path = tmp_path / "advanced-style-analytics.sqlite3"
|
||
|
|
database = _database(path)
|
||
|
|
database.initialize()
|
||
|
|
with database.connect() as connection:
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_material_imports "
|
||
|
|
"(import_id, display_name, source_image_uri, status, metadata_json) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"style-analytics-import",
|
||
|
|
"Analytics style",
|
||
|
|
"storage://advanced_materials/analytics/source.png",
|
||
|
|
"accepted",
|
||
|
|
json.dumps({"workflow_kind": "style_set"}),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
for index in range(2):
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_sources "
|
||
|
|
"(source_id, import_id, sort_order, is_primary, source_image_uri, status) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
f"style-analytics-source-{index}",
|
||
|
|
"style-analytics-import",
|
||
|
|
index,
|
||
|
|
int(index == 0),
|
||
|
|
f"storage://advanced_materials/analytics/{index}.png",
|
||
|
|
"succeeded",
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_consensus_runs "
|
||
|
|
"(consensus_id, import_id, revision, status, source_ids_json) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"style-analytics-consensus",
|
||
|
|
"style-analytics-import",
|
||
|
|
1,
|
||
|
|
"succeeded",
|
||
|
|
json.dumps(["style-analytics-source-0", "style-analytics-source-1"]),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_material_validation_attempts "
|
||
|
|
"(attempt_id, import_id, attempt_number, status, prompt, validation_image_uri, fidelity_score) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"style-analytics-attempt",
|
||
|
|
"style-analytics-import",
|
||
|
|
1,
|
||
|
|
"accepted",
|
||
|
|
"watercolor",
|
||
|
|
"storage://advanced_materials/analytics/portrait.png",
|
||
|
|
0.9,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
for index, case_key in enumerate(("portrait", "fullbody", "scene")):
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_style_validation_cases "
|
||
|
|
"(case_id, attempt_id, import_id, case_key, sort_order, status, "
|
||
|
|
"content_prompt, final_prompt, fidelity_score) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
f"style-analytics-{case_key}",
|
||
|
|
"style-analytics-attempt",
|
||
|
|
"style-analytics-import",
|
||
|
|
case_key,
|
||
|
|
index,
|
||
|
|
"succeeded",
|
||
|
|
case_key,
|
||
|
|
f"watercolor {case_key}",
|
||
|
|
0.8 + index * 0.05,
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.execute(
|
||
|
|
"INSERT INTO advanced_materials "
|
||
|
|
"(material_id, import_id, accepted_attempt_id, display_name, source_image_uri, "
|
||
|
|
"validation_image_uri, prompt, status, metadata_json) "
|
||
|
|
"VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
(
|
||
|
|
"style-analytics-material",
|
||
|
|
"style-analytics-import",
|
||
|
|
"style-analytics-attempt",
|
||
|
|
"Analytics style",
|
||
|
|
"storage://advanced_materials/analytics/source.png",
|
||
|
|
"storage://advanced_materials/analytics/portrait.png",
|
||
|
|
"watercolor",
|
||
|
|
"active",
|
||
|
|
json.dumps({"workflow_kind": "style_set", "style_set": {"source_ids": ["a", "b"]}}),
|
||
|
|
),
|
||
|
|
)
|
||
|
|
connection.commit()
|
||
|
|
|
||
|
|
summary = MaterialAnalyticsService(database).summarize()
|
||
|
|
|
||
|
|
assert summary["advanced_materials"]["active_style_sets"] == 1
|
||
|
|
assert summary["advanced_style_sets"] == {
|
||
|
|
"imports": 1,
|
||
|
|
"accepted_imports": 1,
|
||
|
|
"active_materials": 1,
|
||
|
|
"sources": 2,
|
||
|
|
"source_statuses": {"succeeded": 2},
|
||
|
|
"consensus_runs": 1,
|
||
|
|
"consensus_statuses": {"succeeded": 1},
|
||
|
|
"validation_cases": 3,
|
||
|
|
"validation_case_statuses": {"succeeded": 3},
|
||
|
|
"average_case_fidelity_score": 0.85,
|
||
|
|
}
|