# encoding: UTF-8 require "tmpdir" require_relative "test_helper" require_relative "../lib/meow/transcript" module MeowTranscriptTest MeowTest.test("Transcript store writes timestamped typed records and lists them") do Dir.mktmpdir("meow-transcript") do |directory| now = Time.new(2026, 9, 17, 12, 30, 0, "+02:00") store = MeowClient::TranscriptStore.new(directory, :clock => proc { now }) path = store.start("profile-1", "Test MUD") store.write_record("mud", "Welcome\nPrompt>") store.write_record("command", "> look") store.close text = File.binread(path) MeowTest.assert(text.include?("[2026-09-17T12:30:00+02:00] [mud] Welcome")) MeowTest.assert(text.include?("[command] > look")) MeowTest.assert_equal(1, store.list("profile-1").size) end end MeowTest.test("Transcript paths stay inside the transcript root") do Dir.mktmpdir("meow-transcript") do |directory| store = MeowClient::TranscriptStore.new(directory) MeowTest.assert_raises(ArgumentError) { store.read(File.join(directory, "..", "outside.txt")) } end end MeowTest.test("Transcript deletion removes one file and profile deletion removes the directory") do Dir.mktmpdir("meow-transcript") do |directory| store = MeowClient::TranscriptStore.new(directory) first = store.start("profile", "One") store.close store.delete(first) MeowTest.assert_empty(store.list("profile")) store.start("profile", "Two") store.close store.delete_profile("profile") MeowTest.assert_empty(store.list("profile")) end end end