fix: unify task workspace directory resolution
This commit is contained in:
@ -41,11 +41,11 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
provider = BilibiliTopCommentProvider(bilibili_api=api)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
task = Task("task-1", "local_file", str(root / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso())
|
||||
task_dir_1 = root / "task-1"
|
||||
task_dir_2 = root / "task-2"
|
||||
task_dir_1.mkdir(parents=True, exist_ok=True)
|
||||
task_dir_2.mkdir(parents=True, exist_ok=True)
|
||||
task = Task("task-1", "local_file", str(task_dir_1 / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso())
|
||||
(task_dir_1 / "songs.txt").write_text("00:00:00 Song A — Artist A\n", encoding="utf-8")
|
||||
(task_dir_1 / "songs.json").write_text(json.dumps({"songs": [{"title": "Song A", "artist": "Artist A"}]}), encoding="utf-8")
|
||||
(task_dir_1 / "bvid.txt").write_text("BV1SPLIT111", encoding="utf-8")
|
||||
@ -65,6 +65,13 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
def list_task_contexts_by_session_key(self, session_key): # noqa: ANN001
|
||||
return [self.get_task_context("task-1"), self.get_task_context("task-2")]
|
||||
|
||||
def get_task(self, task_id): # noqa: ANN001
|
||||
mapping = {
|
||||
"task-1": Task("task-1", "local_file", str(task_dir_1 / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso()),
|
||||
"task-2": Task("task-2", "local_file", str(task_dir_2 / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso()),
|
||||
}
|
||||
return mapping[task_id]
|
||||
|
||||
result = provider.comment(
|
||||
task,
|
||||
{
|
||||
@ -88,9 +95,9 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
provider = BilibiliTopCommentProvider(bilibili_api=api)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
task = Task("task-2", "local_file", str(root / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso())
|
||||
task_dir = root / "task-2"
|
||||
task_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task("task-2", "local_file", str(task_dir / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso())
|
||||
(task_dir / "songs.txt").write_text("00:00:00 Song B — Artist B\n", encoding="utf-8")
|
||||
(task_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Song B", "artist": "Artist B"}]}), encoding="utf-8")
|
||||
(task_dir / "bvid.txt").write_text("BV1SPLIT222", encoding="utf-8")
|
||||
@ -108,6 +115,13 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
def list_task_contexts_by_session_key(self, session_key): # noqa: ANN001
|
||||
return [self.get_task_context("task-1"), self.get_task_context("task-2")]
|
||||
|
||||
def get_task(self, task_id): # noqa: ANN001
|
||||
mapping = {
|
||||
"task-1": Task("task-1", "local_file", str(root / "task-1" / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso()),
|
||||
"task-2": Task("task-2", "local_file", str(task_dir / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso()),
|
||||
}
|
||||
return mapping[task_id]
|
||||
|
||||
result = provider.comment(
|
||||
task,
|
||||
{
|
||||
@ -128,17 +142,17 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
provider = BilibiliTopCommentProvider(bilibili_api=_FakeBilibiliApi())
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
work_dir = root / "task-1"
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task(
|
||||
id="task-1",
|
||||
source_type="local_file",
|
||||
source_path=str(root / "source.mp4"),
|
||||
source_path=str(work_dir / "source.mp4"),
|
||||
title="task-1",
|
||||
status="published",
|
||||
created_at=utc_now_iso(),
|
||||
updated_at=utc_now_iso(),
|
||||
)
|
||||
work_dir = root / task.title
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
(work_dir / "songs.txt").write_text("00:00:00 Test Song - Tester\n", encoding="utf-8")
|
||||
(work_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Test Song", "artist": "Tester"}]}), encoding="utf-8")
|
||||
(work_dir / "bvid.txt").write_text("BV1COMMENT123", encoding="utf-8")
|
||||
@ -162,16 +176,52 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
self.assertTrue((work_dir / "comment_full_done.flag").exists())
|
||||
self.assertTrue((work_dir / "comment_done.flag").exists())
|
||||
|
||||
def test_comment_uses_source_path_parent_when_task_title_differs(self) -> None:
|
||||
provider = BilibiliTopCommentProvider(bilibili_api=_FakeBilibiliApi())
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
work_dir = root / "task-id-dir"
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task(
|
||||
id="task-id",
|
||||
source_type="bilibili_url",
|
||||
source_path=str(work_dir / "task-id.mp4"),
|
||||
title="display-title",
|
||||
status="published",
|
||||
created_at=utc_now_iso(),
|
||||
updated_at=utc_now_iso(),
|
||||
)
|
||||
(work_dir / "songs.txt").write_text("00:00:00 Test Song - Tester\n", encoding="utf-8")
|
||||
(work_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Test Song", "artist": "Tester"}]}), encoding="utf-8")
|
||||
(work_dir / "bvid.txt").write_text("BV1COMMENT123", encoding="utf-8")
|
||||
cookies_file = root / "cookies.json"
|
||||
cookies_file.write_text("{}", encoding="utf-8")
|
||||
|
||||
result = provider.comment(
|
||||
task,
|
||||
{
|
||||
"session_dir": str(root),
|
||||
"cookies_file": str(cookies_file),
|
||||
"post_split_comment": True,
|
||||
"post_full_video_timeline_comment": False,
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(result["status"], "ok")
|
||||
self.assertEqual(result["split"]["status"], "skipped")
|
||||
self.assertEqual(result["split"]["reason"], "comment_disabled")
|
||||
self.assertTrue((work_dir / "comment_done.flag").exists())
|
||||
|
||||
def test_full_comment_aggregates_session_parts_on_anchor_task(self) -> None:
|
||||
api = _FakeBilibiliApi()
|
||||
provider = BilibiliTopCommentProvider(bilibili_api=api)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
task = Task("task-1", "local_file", str(root / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso())
|
||||
task_dir_1 = root / "task-1"
|
||||
task_dir_2 = root / "task-2"
|
||||
task_dir_1.mkdir(parents=True, exist_ok=True)
|
||||
task_dir_2.mkdir(parents=True, exist_ok=True)
|
||||
task = Task("task-1", "local_file", str(task_dir_1 / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso())
|
||||
(task_dir_1 / "songs.txt").write_text("00:00:01 Song A\n00:02:00 Song B\n", encoding="utf-8")
|
||||
(task_dir_1 / "songs.json").write_text(json.dumps({"songs": [{"title": "Song A"}]}), encoding="utf-8")
|
||||
(task_dir_1 / "bvid.txt").write_text("BV1SPLIT111", encoding="utf-8")
|
||||
@ -191,6 +241,13 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
def list_task_contexts_by_session_key(self, session_key): # noqa: ANN001
|
||||
return [self.get_task_context("task-1"), self.get_task_context("task-2")]
|
||||
|
||||
def get_task(self, task_id): # noqa: ANN001
|
||||
mapping = {
|
||||
"task-1": Task("task-1", "local_file", str(task_dir_1 / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso()),
|
||||
"task-2": Task("task-2", "local_file", str(task_dir_2 / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso()),
|
||||
}
|
||||
return mapping[task_id]
|
||||
|
||||
result = provider.comment(
|
||||
task,
|
||||
{
|
||||
@ -214,9 +271,9 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
provider = BilibiliTopCommentProvider(bilibili_api=api)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
task = Task("task-2", "local_file", str(root / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso())
|
||||
task_dir = root / "task-2"
|
||||
task_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task("task-2", "local_file", str(task_dir / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso())
|
||||
(task_dir / "songs.txt").write_text("00:00:03 Song C\n", encoding="utf-8")
|
||||
(task_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Song C"}]}), encoding="utf-8")
|
||||
(task_dir / "bvid.txt").write_text("BV1SPLIT222", encoding="utf-8")
|
||||
@ -235,6 +292,13 @@ class BilibiliTopCommentProviderTests(unittest.TestCase):
|
||||
def list_task_contexts_by_session_key(self, session_key): # noqa: ANN001
|
||||
return [self.get_task_context("task-1"), self.get_task_context("task-2")]
|
||||
|
||||
def get_task(self, task_id): # noqa: ANN001
|
||||
mapping = {
|
||||
"task-1": Task("task-1", "local_file", str(root / "task-1" / "source-1.mp4"), "task-1", "published", utc_now_iso(), utc_now_iso()),
|
||||
"task-2": Task("task-2", "local_file", str(task_dir / "source-2.mp4"), "task-2", "published", utc_now_iso(), utc_now_iso()),
|
||||
}
|
||||
return mapping[task_id]
|
||||
|
||||
result = provider.comment(
|
||||
task,
|
||||
{
|
||||
|
||||
@ -50,22 +50,71 @@ class BiliupCliAdapterTests(unittest.TestCase):
|
||||
|
||||
|
||||
class BiliupCliPublishProviderTests(unittest.TestCase):
|
||||
def test_publish_uses_source_path_parent_when_task_title_differs(self) -> None:
|
||||
adapter = _FakeBiliupAdapter()
|
||||
provider = BiliupCliPublishProvider(adapter=adapter)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
work_dir = root / "task-id-dir"
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task(
|
||||
id="task-id",
|
||||
source_type="bilibili_url",
|
||||
source_path=str(work_dir / "task-id.mp4"),
|
||||
title="display-title",
|
||||
status="split_done",
|
||||
created_at=utc_now_iso(),
|
||||
updated_at=utc_now_iso(),
|
||||
)
|
||||
(work_dir / "songs.txt").write_text("00:00:00 Test Song - Tester\n", encoding="utf-8")
|
||||
(work_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Test Song"}]}), encoding="utf-8")
|
||||
upload_config = root / "upload_config.json"
|
||||
upload_config.write_text("{}", encoding="utf-8")
|
||||
clip_path = work_dir / "clip-1.mp4"
|
||||
clip_path.write_text("fake", encoding="utf-8")
|
||||
clip = Artifact(
|
||||
id=None,
|
||||
task_id=task.id,
|
||||
artifact_type="clip_video",
|
||||
path=str(clip_path),
|
||||
metadata_json="{}",
|
||||
created_at=utc_now_iso(),
|
||||
)
|
||||
|
||||
record = provider.publish(
|
||||
task,
|
||||
[clip],
|
||||
{
|
||||
"session_dir": str(root),
|
||||
"upload_config_file": str(upload_config),
|
||||
"biliup_path": "runtime/biliup",
|
||||
"cookie_file": "runtime/cookies.json",
|
||||
"retry_count": 1,
|
||||
"command_timeout_seconds": 123,
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(record.bvid, "BV1TEST12345")
|
||||
self.assertEqual(adapter.optional_calls[0]["log_path"], work_dir / "publish.log")
|
||||
self.assertTrue((work_dir / "bvid.txt").exists())
|
||||
self.assertTrue((work_dir / "upload_done.flag").exists())
|
||||
|
||||
def test_publish_passes_timeout_and_log_path(self) -> None:
|
||||
adapter = _FakeBiliupAdapter()
|
||||
provider = BiliupCliPublishProvider(adapter=adapter)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
work_dir = root / "task-1"
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task(
|
||||
id="task-1",
|
||||
source_type="local_file",
|
||||
source_path=str(root / "source.mp4"),
|
||||
source_path=str(work_dir / "source.mp4"),
|
||||
title="task-1",
|
||||
status="split_done",
|
||||
created_at=utc_now_iso(),
|
||||
updated_at=utc_now_iso(),
|
||||
)
|
||||
work_dir = root / task.title
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
(work_dir / "songs.txt").write_text("00:00:00 Test Song - Tester\n", encoding="utf-8")
|
||||
(work_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Test Song"}]}), encoding="utf-8")
|
||||
upload_config = root / "upload_config.json"
|
||||
@ -117,17 +166,17 @@ class BiliupCliPublishProviderTests(unittest.TestCase):
|
||||
provider = BiliupCliPublishProvider(adapter=adapter)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
work_dir = root / "task-1"
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task(
|
||||
id="task-1",
|
||||
source_type="local_file",
|
||||
source_path=str(root / "source.mp4"),
|
||||
source_path=str(work_dir / "source.mp4"),
|
||||
title="task-1",
|
||||
status="split_done",
|
||||
created_at=utc_now_iso(),
|
||||
updated_at=utc_now_iso(),
|
||||
)
|
||||
work_dir = root / task.title
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
(work_dir / "songs.txt").write_text("00:00:00 Test Song - Tester\n", encoding="utf-8")
|
||||
(work_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Test Song"}]}), encoding="utf-8")
|
||||
(work_dir / "bvid.txt").write_text("BVOLD1234567", encoding="utf-8")
|
||||
@ -165,17 +214,17 @@ class BiliupCliPublishProviderTests(unittest.TestCase):
|
||||
provider = BiliupCliPublishProvider(adapter=adapter)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
work_dir = root / "task-1"
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task(
|
||||
id="task-1",
|
||||
source_type="local_file",
|
||||
source_path=str(root / "source.mp4"),
|
||||
source_path=str(work_dir / "source.mp4"),
|
||||
title="task-1",
|
||||
status="split_done",
|
||||
created_at=utc_now_iso(),
|
||||
updated_at=utc_now_iso(),
|
||||
)
|
||||
work_dir = root / task.title
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
(work_dir / "songs.txt").write_text("00:00:00 Test Song - Tester\n", encoding="utf-8")
|
||||
(work_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Test Song"}]}), encoding="utf-8")
|
||||
(work_dir / "bvid.txt").write_text("BV1RESUME1234", encoding="utf-8")
|
||||
@ -225,17 +274,17 @@ class BiliupCliPublishProviderTests(unittest.TestCase):
|
||||
provider = BiliupCliPublishProvider(adapter=adapter)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
work_dir = root / "task-1"
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
task = Task(
|
||||
id="task-1",
|
||||
source_type="local_file",
|
||||
source_path=str(root / "source.mp4"),
|
||||
source_path=str(work_dir / "source.mp4"),
|
||||
title="task-1",
|
||||
status="split_done",
|
||||
created_at=utc_now_iso(),
|
||||
updated_at=utc_now_iso(),
|
||||
)
|
||||
work_dir = root / task.title
|
||||
work_dir.mkdir(parents=True, exist_ok=True)
|
||||
(work_dir / "songs.txt").write_text("00:00:00 Test Song - Tester\n", encoding="utf-8")
|
||||
(work_dir / "songs.json").write_text(json.dumps({"songs": [{"title": "Test Song"}]}), encoding="utf-8")
|
||||
(work_dir / "bvid.txt").write_text("BV1RESUME1234", encoding="utf-8")
|
||||
|
||||
@ -75,8 +75,10 @@ class PublishServiceTests(unittest.TestCase):
|
||||
provider = _FakePublishProvider()
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
root = Path(tmpdir)
|
||||
task1 = Task("task-1", "local_file", "/tmp/a.mp4", "task-1", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
task2 = Task("task-2", "local_file", "/tmp/b.mp4", "task-2", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
(root / "task-1").mkdir(parents=True, exist_ok=True)
|
||||
(root / "task-2").mkdir(parents=True, exist_ok=True)
|
||||
task1 = Task("task-1", "local_file", str(root / "task-1" / "source.mp4"), "task-1", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
task2 = Task("task-2", "local_file", str(root / "task-2" / "source.mp4"), "task-2", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
ctx1 = TaskContext(None, "task-1", "session-1", "s", None, "part-1", "2026-04-04T09:23:00+08:00", None, None, task1.created_at, task1.updated_at)
|
||||
ctx2 = TaskContext(None, "task-2", "session-1", "s", None, "part-2", "2026-04-04T09:25:00+08:00", None, None, task2.created_at, task2.updated_at)
|
||||
artifacts = {
|
||||
@ -108,8 +110,9 @@ class PublishServiceTests(unittest.TestCase):
|
||||
root = Path(tmpdir)
|
||||
(root / "task-1").mkdir(parents=True, exist_ok=True)
|
||||
(root / "task-1" / "bvid.txt").write_text("BV1SESSION123", encoding="utf-8")
|
||||
task1 = Task("task-1", "local_file", "/tmp/a.mp4", "task-1", "published", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
task2 = Task("task-2", "local_file", "/tmp/b.mp4", "task-2", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
(root / "task-2").mkdir(parents=True, exist_ok=True)
|
||||
task1 = Task("task-1", "local_file", str(root / "task-1" / "source.mp4"), "task-1", "published", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
task2 = Task("task-2", "local_file", str(root / "task-2" / "source.mp4"), "task-2", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
ctx1 = TaskContext(None, "task-1", "session-1", "s", None, "part-1", "2026-04-04T09:23:00+08:00", None, None, task1.created_at, task1.updated_at)
|
||||
ctx2 = TaskContext(None, "task-2", "session-1", "s", None, "part-2", "2026-04-04T09:25:00+08:00", None, None, task2.created_at, task2.updated_at)
|
||||
repo = _FakeRepo([task1, task2], [ctx1, ctx2], {"task-2": []})
|
||||
@ -132,8 +135,8 @@ class PublishServiceTests(unittest.TestCase):
|
||||
(root / "task-2" / "songs.txt").write_text("00:00:00 Song B — Artist B\n", encoding="utf-8")
|
||||
(root / "task-1" / "songs.json").write_text('{"songs":[{"title":"Song A"},{"title":"Song A2"}]}\n', encoding="utf-8")
|
||||
(root / "task-2" / "songs.json").write_text('{"songs":[{"title":"Song B"}]}\n', encoding="utf-8")
|
||||
task1 = Task("task-1", "local_file", "/tmp/a.mp4", "task-1", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
task2 = Task("task-2", "local_file", "/tmp/b.mp4", "task-2", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
task1 = Task("task-1", "local_file", str(root / "task-1" / "source.mp4"), "task-1", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
task2 = Task("task-2", "local_file", str(root / "task-2" / "source.mp4"), "task-2", "split_done", "2026-01-01T00:00:00+00:00", "2026-01-01T00:00:00+00:00")
|
||||
ctx1 = TaskContext(None, "task-1", "session-1", "s", None, "part-1", "2026-04-04T09:23:00+08:00", None, None, task1.created_at, task1.updated_at)
|
||||
ctx2 = TaskContext(None, "task-2", "session-1", "s", None, "part-2", "2026-04-04T09:25:00+08:00", None, None, task2.created_at, task2.updated_at)
|
||||
artifacts = {
|
||||
|
||||
Reference in New Issue
Block a user