Forum teuk.org

🪄 Mischief Managed Again — Claude Additions Repaired, Karma Ranked, Tests Green

in Mediabot · started by TeuK · 1mo ago

TeuK · 1mo ago

Overview

After a busy Claude-assisted development pass, Mediabot v3 received several new improvements around reminders, karma, command helpers, and test automation. The first integration was not clean: a few Perl insertions broke UserCommands.pm, and the bot refused to start.

The good news: the code was recovered, cleaned, and validated by the full static and live test suites.

Mischief managed. The bot is back on its feet, and the tests are green. ✨


What Claude Added

This round introduced and refined several user-facing and internal features:

  • reminder/list handling improvements;
  • karma history and karma ranking support;
  • safer karma update limits;
  • additional helper/user command coverage;
  • expanded static tests for Claude persona and karma history;
  • a full verbose test runner with configurable log output;
  • stronger live-test coverage around routing, auth, public dispatch, user commands, and Partyline restart behavior.

The most visible new behavior is around karma: when karma changes, the bot can compute and display the target’s rank within the channel.


The Breakage

The Claude pass left two real Perl syntax problems in Mediabot/UserCommands.pm.

1. Broken reminder list concatenation

A missing concatenation operator produced a syntax error around mbRemindList_ctx:

$r->{id_reminder}, $r->{to_nick}$due_t5,

Fixed as:

$r->{id_reminder}, $r->{to_nick} . $due_t5,

2. Misplaced karma rank block

The karma rank code had been inserted inside the argument list of botPrivmsg(), which made Perl parse my $rank_str where it expected an expression separator.

The fix was to compute $rank_str before sending the IRC message:

my $rank_str = '';
eval {
    my $sth_rank = $self->{dbh}->prepare(
        'SELECT COUNT(*)+1 AS rank FROM KARMA WHERE id_channel=? AND score>?'
    );
    if ($sth_rank && $sth_rank->execute($id_channel, $score)) {
        my $rr = $sth_rank->fetchrow_hashref;
        $sth_rank->finish;
        $rank_str = " (rank #$rr->{rank})" if $rr && defined $rr->{rank};
    }
};

Mediabot::Helpers::botPrivmsg(
    $self,
    $channel,
    "$target\'s karma: ${sign}${score}${rank_str}"
);

Test Runner Improvements

The full test runner was also improved.

t/full_test.sh now supports:

./t/full_test.sh -d /home/backupwws/mediabot_tests

with a safe fallback to:

/tmp/mediabot_tests

It also supports:

./t/full_test.sh -h

and preserves both static and live test logs while keeping proper exit codes through PIPESTATUS.

This makes long test runs easier to archive, inspect, and compare.


Live Test Repairs

Several live tests were updated to match the current bot behavior instead of older assumptions.

Important fixes included:

  • !help now correctly expects NOTICE output instead of channel flood;
  • failed login pollution between tests was removed;
  • valid login checks were made tolerant of delayed auth guard lines;
  • multiline userinfo / whoami output is drained properly;
  • Partyline restart tests now accept the current authenticated banner behavior;
  • Partyline DB access was made compatible with both DBD::mysql and DBD::MariaDB.

The Partyline restart test now validates the important behavior:

  • connect to Partyline;
  • authenticate;
  • request .restart;
  • confirm IRC QUIT;
  • keep Partyline alive;
  • confirm the bot reconnects and answers again on IRC.

Database and Debian 13 Compatibility

The schema drift checker had already been made friendlier for Debian 13:

  • auto-detects DBD::mysql or DBD::MariaDB;
  • avoids port=3306 with DBD::MariaDB and localhost;
  • uses SET NAMES utf8mb4 instead of fragile driver-specific charset attributes.

This keeps fresh Debian 13 installs practical without forcing a specific Perl DB driver package when MariaDB’s DBI driver is already available.


Validation

After the recovery work, all tests passed:

Static tests: green
Live tests:   green

The bot also starts successfully again after the UserCommands.pm syntax repairs.

This validates:

  • Perl syntax;
  • command dispatch;
  • Claude-related tests;
  • karma history/ranking tests;
  • schema drift tooling;
  • live IRC connection;
  • registration/login flows;
  • Partyline access;
  • Partyline restart and IRC reconnect;
  • database-backed commands;
  • quote commands;
  • public and private command routing.

Files Touched

Main areas involved in this round:

File / Area Purpose
Mediabot/UserCommands.pm reminder and karma fixes, syntax recovery
t/cases/235_external_claude_persona.t Claude persona coverage
t/cases/236_usercommands_karmahist.t karma history coverage
t/live/*.t live test expectations aligned with current behavior
t/full_test.sh full static + live test runner with log directory support
tools/check_schema_drift.pl Debian 13 / MariaDB-friendly schema checks

Final Verdict

This was a messy but valuable round: Claude added useful features, then left a few sharp edges behind. Those edges are now cleaned up.

Mediabot v3 is in a stronger state than before:

  • more features;
  • better tests;
  • better live validation;
  • better Debian 13 compatibility;
  • cleaner recovery from a risky AI-assisted patch.

Mischief managed. Again. 🪄

You must be logged in to reply.