updated series_index to float and added UniqueConstraint to audiobook and audiobook_author
treefmt / nix fmt (pull_request) Failing after 5s
pytest / pytest (pull_request) Successful in 26s
build_systems / build-bob (pull_request) Successful in 45s
build_systems / build-leviathan (pull_request) Successful in 55s
build_systems / build-rhapsody-in-green (pull_request) Successful in 56s
build_systems / build-brain (pull_request) Successful in 47s
build_systems / build-jeeves (pull_request) Successful in 2m36s
treefmt / nix fmt (pull_request) Failing after 5s
pytest / pytest (pull_request) Successful in 26s
build_systems / build-bob (pull_request) Successful in 45s
build_systems / build-leviathan (pull_request) Successful in 55s
build_systems / build-rhapsody-in-green (pull_request) Successful in 56s
build_systems / build-brain (pull_request) Successful in 47s
build_systems / build-jeeves (pull_request) Successful in 2m36s
This commit is contained in:
@@ -6,7 +6,8 @@ import json
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy import create_engine, select
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.orm import Session, sessionmaker
|
||||
|
||||
from python.orm.richie import Audiobook, AudiobookAuthor, AudiobookSeries, RichieBase
|
||||
@@ -113,6 +114,62 @@ def test_output_stem_uses_catalog_slugs() -> None:
|
||||
assert audible_convert.output_stem(metadata) == "glynn_stewart-starships_mage_01-title-slug"
|
||||
|
||||
|
||||
def test_output_stem_formats_half_series_index() -> None:
|
||||
metadata = StandardBookMetadata(
|
||||
author_id=1,
|
||||
author="glynn_stewart",
|
||||
book_id=None,
|
||||
title="title-slug",
|
||||
series_id=1,
|
||||
series="starships_mage",
|
||||
series_index=1.5,
|
||||
confidence=0.96,
|
||||
needs_review=False,
|
||||
evidence=["test"],
|
||||
)
|
||||
|
||||
assert audible_convert.output_stem(metadata) == "glynn_stewart-starships_mage_01.5-title-slug"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("metadata", "expected"),
|
||||
[
|
||||
(
|
||||
StandardBookMetadata(
|
||||
author_id=1,
|
||||
author="mark_e_cooper",
|
||||
book_id=None,
|
||||
title="merkiaari-wars-series-books-1-3",
|
||||
series_id=1,
|
||||
series="merkiaari_wars",
|
||||
series_index=1,
|
||||
confidence=0.96,
|
||||
needs_review=False,
|
||||
evidence=["test"],
|
||||
),
|
||||
"mark_e_cooper-merkiaari_wars_01-03-merkiaari-wars-series-books-1-3",
|
||||
),
|
||||
(
|
||||
StandardBookMetadata(
|
||||
author_id=1,
|
||||
author="rhett_c_bruno",
|
||||
book_id=None,
|
||||
title="the-circuit-books-1-3",
|
||||
series_id=1,
|
||||
series="the_circuit",
|
||||
series_index=1,
|
||||
confidence=0.96,
|
||||
needs_review=False,
|
||||
evidence=["test"],
|
||||
),
|
||||
"rhett_c_bruno-the_circuit_01-03-the-circuit-books-1-3",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_output_stem_formats_omnibus_book_range(metadata, expected) -> None:
|
||||
assert audible_convert.output_stem(metadata) == expected
|
||||
|
||||
|
||||
def test_convert_aax_file_runs_ffmpeg(tmp_path, monkeypatch) -> None:
|
||||
"""test_convert_aax_file_runs_ffmpeg."""
|
||||
commands = []
|
||||
@@ -196,6 +253,8 @@ def test_system_prompt_instructs_agent_to_detect_omnibuses() -> None:
|
||||
assert "Detect omnibus or box-set editions" in prompt
|
||||
assert "books-1-3" in prompt
|
||||
assert "Keep series_index as the" in prompt
|
||||
assert "series_index must be a whole number or .5 value" in prompt
|
||||
assert "differ only by underscores" in prompt
|
||||
|
||||
|
||||
def test_standard_book_metadata_accepts_valid_tool_output(tmp_path, monkeypatch, audiobook_engine) -> None:
|
||||
@@ -666,6 +725,85 @@ def test_standard_book_metadata_can_create_missing_catalog_rows(
|
||||
assert book.series_id == series.id
|
||||
|
||||
|
||||
def test_standard_book_metadata_accepts_half_series_index(tmp_path, monkeypatch, audiobook_engine) -> None:
|
||||
install_fake_ollama(
|
||||
monkeypatch,
|
||||
[
|
||||
tool_response("search_series", {"query": "bobiverse", "author_id": 4}),
|
||||
final_response(
|
||||
{
|
||||
"author_id": 4,
|
||||
"book_id": None,
|
||||
"title": "bobiverse-short",
|
||||
"series_id": 4,
|
||||
"series_index": 1.5,
|
||||
"confidence": 0.95,
|
||||
"evidence": ["series novella from tags"],
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
metadata = standard_book_metadata(
|
||||
"Bobiverse Short.aax",
|
||||
{"title": "Bobiverse Short", "artist": "Dennis E Taylor"},
|
||||
audiobook_engine,
|
||||
tmp_path / "agent.jsonl",
|
||||
"test-key",
|
||||
config=metadata_agent.AgentConfig(),
|
||||
)
|
||||
|
||||
assert metadata.series_index == 1.5
|
||||
assert metadata.needs_review is False
|
||||
with Session(audiobook_engine) as session:
|
||||
book = session.get(Audiobook, 1)
|
||||
assert book.series_index == 1.5
|
||||
|
||||
|
||||
def test_standard_book_metadata_reuses_series_with_only_underscore_difference(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
audiobook_engine,
|
||||
) -> None:
|
||||
with Session(audiobook_engine) as session:
|
||||
session.add(AudiobookSeries(id=5, name="starships", author_id=1))
|
||||
session.commit()
|
||||
install_fake_ollama(
|
||||
monkeypatch,
|
||||
[
|
||||
tool_response("ensure_series", {"name": "starship_s", "author_id": 1}),
|
||||
final_response(
|
||||
{
|
||||
"author_id": 1,
|
||||
"book_id": None,
|
||||
"title": "starships-short",
|
||||
"series_id": 5,
|
||||
"series_index": 1,
|
||||
"confidence": 0.95,
|
||||
"evidence": ["reused existing series with equivalent slug"],
|
||||
},
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
metadata = standard_book_metadata(
|
||||
"Starship S Short.aax",
|
||||
{"title": "Starship S Short", "artist": "Glynn Stewart"},
|
||||
audiobook_engine,
|
||||
tmp_path / "agent.jsonl",
|
||||
"test-key",
|
||||
config=metadata_agent.AgentConfig(),
|
||||
)
|
||||
|
||||
assert metadata.series == "starships"
|
||||
with Session(audiobook_engine) as session:
|
||||
series_names = session.scalars(
|
||||
select(AudiobookSeries.name).where(AudiobookSeries.author_id == 1).order_by(AudiobookSeries.name),
|
||||
).all()
|
||||
assert "starship_s" not in series_names
|
||||
assert series_names == ["black_fleet_trilogy", "starships", "starships_mage"]
|
||||
|
||||
|
||||
def test_standard_book_metadata_normalizes_noisy_created_catalog_rows(
|
||||
tmp_path,
|
||||
monkeypatch,
|
||||
@@ -888,6 +1026,19 @@ def test_richie_exports_audiobook_models() -> None:
|
||||
assert Audiobook.__tablename__ == "audiobook"
|
||||
|
||||
|
||||
def test_audiobook_title_author_series_is_unique(audiobook_engine) -> None:
|
||||
with Session(audiobook_engine) as session:
|
||||
session.add_all(
|
||||
[
|
||||
Audiobook(title="duplicate-title", author_id=1, series_id=1, series_index=1),
|
||||
Audiobook(title="duplicate-title", author_id=1, series_id=1, series_index=2),
|
||||
],
|
||||
)
|
||||
|
||||
with pytest.raises(IntegrityError):
|
||||
session.commit()
|
||||
|
||||
|
||||
def test_main_dry_run_prints_outputs_without_converting(tmp_path, monkeypatch, capsys) -> None:
|
||||
input_directory = tmp_path / "raw"
|
||||
output_directory = tmp_path / "audiobooks"
|
||||
|
||||
Reference in New Issue
Block a user