Give each rake task its own debug log
Dev sessions, fixture replays, and test runs all appended to
log/debug.log, so reading back a real client session meant picking
it out of replayed exchanges.

Assisted-by: GLM-5.3 via pi
change zqtomzqwxynnsnysylnxpwqqkwvvklor
commit 3e3571ec9f68eb27c7713868161e73451f902d12
author Alpha Chen <alpha@kejadlen.dev>
date
parent vluynnos
diff --git a/Rakefile b/Rakefile
index 165f359..27b4321 100644
--- a/Rakefile
+++ b/Rakefile
@@ -20,6 +20,13 @@ task :dev do
   # a fresh `rake dev` is what resets to the fixtures. The data lives in
   # a session-scoped tmpdir: two servers running at once each get their
   # own database, and the directory goes when the task does.
+  # A dev session's debug exchanges go to their own log, truncated per
+  # start, so reading a session back never means picking it out of older
+  # ones — log/debug.log stays the deployment default. An exported
+  # PRO_TACTS_DEBUG_LOG (e.g. stderr) wins over both.
+  ENV["PRO_TACTS_DEBUG_LOG"] ||= "log/dev.log"
+  File.truncate("log/dev.log", 0) if File.exist?("log/dev.log")
+
   Dir.mktmpdir("pro-tacts-dev") do |dir|
     data_dir = Pathname.new(dir)
     ENV["PRO_TACTS_DATA_DIR"] = data_dir.to_s
@@ -34,9 +41,13 @@ task :fixtures do
   # Mirrors test/test_helper.rb, which cannot be required here without
   # minitest/autorun running its at_exit hook inside rake. Its own
   # tmpdir, so a fixture re-record cannot race a concurrent test run.
+  # The debug log dies with that tmpdir too: the fixture files are the
+  # durable record of a re-record, and a replay's exchanges must not
+  # append to a log a real client session also uses.
   Dir.mktmpdir("pro-tacts-test") do |dir|
     data_dir = Pathname.new(dir)
     ENV["PRO_TACTS_DATA_DIR"] = data_dir.to_s
+    ENV["PRO_TACTS_DEBUG_LOG"] ||= (data_dir / "debug.log").to_s
     require "pro_tacts/web"
     require_relative "test/fixture_data"
     require_relative "test/pro_tacts/exchange_fixtures"
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 4a16f66..3f00b0d 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -36,6 +36,12 @@ unhandled_dir = Pathname.new(Dir.mktmpdir("pro-tacts-unhandled"))
 ENV["PRO_TACTS_UNHANDLED_DIR"] = unhandled_dir.to_s
 Minitest.after_run { FileUtils.rm_rf(unhandled_dir) }
 
+# Debug exchanges, when PRO_TACTS_DEBUG is exported for a test run, get
+# their own log, truncated per run: stderr would bury the test progress
+# under full bodies, and log/debug.log is for real client sessions only.
+ENV["PRO_TACTS_DEBUG_LOG"] ||= "log/test.log"
+File.truncate("log/test.log", 0) if File.exist?("log/test.log")
+
 require_relative "fixture_data"
 require "pro_tacts/web"
 require "minitest/autorun"