allow ajust sentences

This commit is contained in:
2026-08-30 11:07:50 +08:00
parent 508a26ba02
commit 0d0b82e095
9 changed files with 270 additions and 3 deletions

View File

@@ -259,3 +259,72 @@ def test_admin_can_split_sentence_and_reindexes_following_sentences(tmp_path):
"Next sentence.",
]
assert [item.index for item in document.sentences] == [0, 1, 2]
def test_admin_boundary_adjustment_updates_linked_next_start(tmp_path):
settings = replace(Settings.from_env(), data_dir=tmp_path / "data")
settings.ensure_directories()
repository = VideoRepository(settings.database_path)
repository.upsert_upload(
video_hash=VIDEO_HASH,
title="Boundary lesson",
filename="lesson.mp4",
stored_filename=f"{VIDEO_HASH}.mp4",
content_type="video/mp4",
size_bytes=5,
language="en",
)
repository.save_processing_result(
SentenceBoundaryDocument(
video_hash=VIDEO_HASH,
duration_ms=9000,
algorithm_version="test",
sentences=[
SentenceBoundary(
index=0,
start_ms=0,
end_ms=4000,
text="First.",
language="en",
reference_speech_duration_ms=3600,
),
SentenceBoundary(
index=1,
start_ms=4000,
end_ms=9000,
text="Second.",
language="en",
reference_speech_duration_ms=4600,
),
],
),
None,
)
class UnavailableTranscriber:
available = False
client = TestClient(
create_app(
BoundaryStore(tmp_path / "boundaries.json"),
settings=settings,
repository=repository,
transcriber=UnavailableTranscriber(),
)
)
response = client.put(
f"/api/v1/admin/videos/{VIDEO_HASH}/sentences/0/boundary",
json={"delta_ms": 250},
)
assert response.status_code == 200
updated = response.json()
assert [item["index"] for item in updated] == [0, 1]
assert updated[0]["end_ms"] == 4250
assert updated[1]["start_ms"] == 4250
assert updated[0]["reference_speech_duration_ms"] == 3850
assert updated[1]["reference_speech_duration_ms"] == 4350
document = repository.get_document(VIDEO_HASH)
assert [item.end_ms for item in document.sentences] == [4250, 9000]
assert [item.start_ms for item in document.sentences] == [0, 4250]