From 4d62c7928dd76f04c7665ce84c2d8a19d0785e6d Mon Sep 17 00:00:00 2001 From: Ziad Arafat Date: Wed, 25 Nov 2026 15:16:47 -0700 Subject: [PATCH] Let an owner clear an uncertain playlist write before reimport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The import guard already required verification, but no command could clear the pending mutation, so a flagged playlist stayed stuck. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- tests/test_playlist_command.py | 47 +++++++++++++++++++++++++ watch/watch.py | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) diff --git a/tests/test_playlist_command.py b/tests/test_playlist_command.py index 913ce8c..2c72b0e 100644 --- a/tests/test_playlist_command.py +++ b/tests/test_playlist_command.py @@ -370,3 +370,50 @@ async def test_uncertain_prior_create_requires_verification_before_reimport( await asyncio.gather(*cog._pollers) assert edge.creations == 0 assert any("verification" in text for text in ctx.texts) + + +async def test_playlist_verify_clears_mutation_and_allows_reimport( + playlist_command: CommandCase, +) -> None: + """Catch a dead end after an uncertain playlist write.""" + cog, ctx, _edge, _channel, _bot = playlist_command + key = "1:playlist:7kRUsOsraSiY4fyDcu7Bnb" + await cog.config.pending_jobs.set( + { + key: { + "owner": 1, + "notified": True, + "stage": "attention", + "kind": "playlist", + "mutation": "Jellyfin playlist create", + } + } + ) + await Watch.playlist_verify.callback(cog, ctx) + job = (await cog.config.pending_jobs())[key] + assert "mutation" not in job + assert any("Verified" in text for text in ctx.texts) + + +async def test_playlist_verify_is_owner_only( + playlist_command: CommandCase, +) -> None: + """Catch a non-owner clearing an uncertain write.""" + cog, ctx, _edge, _channel, bot = playlist_command + bot.owner = False + key = "1:playlist:7kRUsOsraSiY4fyDcu7Bnb" + await cog.config.pending_jobs.set( + { + key: { + "owner": 1, + "notified": True, + "stage": "attention", + "kind": "playlist", + "mutation": "Jellyfin playlist create", + } + } + ) + await Watch.playlist_verify.callback(cog, ctx) + job = (await cog.config.pending_jobs())[key] + assert job["mutation"] == "Jellyfin playlist create" + assert any("Only the bot owner" in text for text in ctx.texts) diff --git a/watch/watch.py b/watch/watch.py index d8050c0..dbde23c 100644 --- a/watch/watch.py +++ b/watch/watch.py @@ -1469,6 +1469,70 @@ class Watch(commands.Cog): allowed_mentions=discord.AllowedMentions.none(), ) + @playlist.command(name="verify") + @commands.is_owner() + async def playlist_verify( + self, ctx: commands.Context, *, target: str = "" + ) -> None: + """Bot owner: clear an uncertain playlist write.""" + if not await self.bot.is_owner(ctx.author): + await ctx.send( + "Only the bot owner can verify playlist writes." + ) + return + async with self.config.pending_jobs() as jobs: + flagged = [ + (key, job) + for key, job in jobs.items() + if job.get("kind") == "playlist" + and job.get("mutation") + ] + if not flagged: + await ctx.send( + "No playlist jobs need owner " + "verification." + ) + return + needle = target.strip().lower() + matches = [ + (key, job) + for key, job in flagged + if not needle + or needle in key.lower() + or needle in str(job.get("name", "")).lower() + ] + if not matches: + await ctx.send( + "No flagged playlist job matched " + f"`{target.strip()}`." + ) + return + if len(matches) > 1: + listing = "\n".join( + f"- `{key}` " + f"({job.get('name', 'unknown')}): " + f"{job.get('mutation')}" + for key, job in matches[:10] + ) + await ctx.send( + "Multiple playlist jobs need " + "verification; name one:\n" + f"{listing}", + allowed_mentions=( + discord.AllowedMentions.none() + ), + ) + return + key, job = matches[0] + action = job.pop("mutation", None) + name = discord.utils.escape_markdown( + str(job.get("name", key)) + ) + await ctx.send( + f"Verified **{name}**: cleared `{action}`. " + "You can reimport or resume the playlist." + ) + @watch.command(name="link") async def watch_link(self, ctx: commands.Context, *, name: str) -> None: """Link your Jellyfin user name, for "next" requests."""