Commit notifications for all Sup repositories
 help / color / mirror / Atom feed
* [sup.git] branch develop updated (53f07beb -> cc601160)
@ 2026-11-28  7:37 Dan Callaghan
  2026-11-28  7:37 ` [sup.git] 01/02: store HookContext closures on the instance not the class Dan Callaghan
  2026-11-28  7:37 ` [sup.git] 02/02: tests: avoid Redwood::start Dan Callaghan
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Callaghan @ 2026-11-28  7:37 UTC (permalink / raw)
  To: sup-commits

Pushed branch develop:
    from 53f07beb bring back sup-recover-sources from the dead
     new 6a28d978 store HookContext closures on the instance not the class
     new cc601160 tests: avoid Redwood::start


Summary of changes:
 lib/sup/hook.rb                    | 13 ++++++++-----
 test/integration/test_draft.rb     | 12 ++++++++----
 test/integration/test_index.rb     | 10 +++++++---
 test/integration/test_maildir.rb   | 11 +++++++----
 test/integration/test_mbox.rb      | 10 +++++++---
 test/test_helper.rb                | 11 +++++++++++
 test/unit/test_index.rb            |  5 ++++-
 test/unit/test_thread_view_mode.rb | 12 +++++++++---
 8 files changed, 61 insertions(+), 23 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [sup.git] 01/02: store HookContext closures on the instance not the class
  2026-11-28  7:37 [sup.git] branch develop updated (53f07beb -> cc601160) Dan Callaghan
@ 2026-11-28  7:37 ` Dan Callaghan
  2026-11-28  7:37 ` [sup.git] 02/02: tests: avoid Redwood::start Dan Callaghan
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Callaghan @ 2026-11-28  7:37 UTC (permalink / raw)
  To: sup-commits

New commit on branch develop:
https://supmua.dev/git/sup/commit/6a28d978d8975bfa6b5c9cf7505948760a3430ba.html

commit 6a28d978d8975bfa6b5c9cf7505948760a3430ba
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 28 17:59:14 2026 +1100

    store HookContext closures on the instance not the class
    
    HookContext allows context variables to be Procs, which get injected
    into the hook context as methods. Currently only used for :filename in
    mime-decode to make it lazy.
    
    Define the method on the HookContext instance, rather than the class,
    and ensure it is cleaned up after evaluating the hook.
    
    This fixes several issues: 'filename' was being leaked into all other
    hook contexts after mime-decode was invoked the first time, and its Proc
    would live eternally for no good reason. And this also fixes a warning
    about redefining the method:
    
        lib/sup/hook.rb:60: warning: method redefined; discarding old filename
        lib/sup/hook.rb:60: warning: previous definition of filename was here
---
 lib/sup/hook.rb | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/sup/hook.rb b/lib/sup/hook.rb
index 4e9cfd20..9e7757bb 100644
--- a/lib/sup/hook.rb
+++ b/lib/sup/hook.rb
@@ -56,16 +56,19 @@ class HookManager
       ## we have to do this via method calls, so you don't get all the
       ## semantics of a regular variable. not ideal.
       __lprocs.each do |k, v|
-        self.class.instance_eval do
-          define_method k do
-            @__cache[k] ||= v.call
-          end
+        define_singleton_method k do
+          @__cache[k] ||= v.call
         end
       end
       ret = eval __hook, __binding, __filename
       BufferManager.clear @__say_id if @__say_id
-      @__cache = {}
       ret
+    ensure
+      (__lprocs || []).each do |k, v|
+        next unless singleton_methods(false).include? k
+        singleton_class.send :remove_method, k
+      end
+      @__cache = {}
     end
   end
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [sup.git] 02/02: tests: avoid Redwood::start
  2026-11-28  7:37 [sup.git] branch develop updated (53f07beb -> cc601160) Dan Callaghan
  2026-11-28  7:37 ` [sup.git] 01/02: store HookContext closures on the instance not the class Dan Callaghan
@ 2026-11-28  7:37 ` Dan Callaghan
  1 sibling, 0 replies; 3+ messages in thread
From: Dan Callaghan @ 2026-11-28  7:37 UTC (permalink / raw)
  To: sup-commits

New commit on branch develop:
https://supmua.dev/git/sup/commit/cc6011601cdb37888718a9bd4188287455fb7425.html

commit cc6011601cdb37888718a9bd4188287455fb7425
Author: Dan Callaghan <djc@djc.id.au>
AuthorDate: Sat Nov 28 18:34:23 2026 +1100

    tests: avoid Redwood::start
    
    Calling Redwood::start meant that some parts of the Sup code would be
    initialised from the user's real ~/.sup, which made their behaviour
    sensitive to the user's config. Worse still, the tests would write
    ~/.sup/config.yaml if it was missing due to Redwood::load_config.
    
    Avoid Redwood::start in all tests, in favour of explicitly initialising
    whichever Manager classes are needed pointing to temp dirs.
    
    Also add a guard in test_helper to try and ensure nothing leaks into or
    out of the real ~/.sup in future.
---
 test/integration/test_draft.rb     | 12 ++++++++----
 test/integration/test_index.rb     | 10 +++++++---
 test/integration/test_maildir.rb   | 11 +++++++----
 test/integration/test_mbox.rb      | 10 +++++++---
 test/test_helper.rb                | 11 +++++++++++
 test/unit/test_index.rb            |  5 ++++-
 test/unit/test_thread_view_mode.rb | 12 +++++++++---
 7 files changed, 53 insertions(+), 18 deletions(-)

diff --git a/test/integration/test_draft.rb b/test/integration/test_draft.rb
index 4d176894..201306e9 100644
--- a/test/integration/test_draft.rb
+++ b/test/integration/test_draft.rb
@@ -1,14 +1,20 @@
-require "sup"
 require "test_helper"
+require "sup"
 
 class TestDraft < Minitest::Test
   include Redwood
 
   def setup
     @path = Dir.mktmpdir
-    start
+    $config = { :stem_language => "english" }
     Logger.remove_sink $stderr
     @draft_dir = File.join @path, "drafts"
+    HookManager.init File.join(@path, "hooks")
+    UpdateManager.init
+    SourceManager.init
+    PollManager.init
+    LabelManager.init File.join(@path, "labels.txt")
+    DraftManager.init @draft_dir
     @test_message_1 = <<EOS
 From: Some Person <someone@example.invalid>
 To:
@@ -20,10 +26,8 @@ Message-ID: <123@example.invalid>
 
 My incomplete message
 EOS
-    DraftManager.instance.instance_eval "@dir = '#{@draft_dir}'"
     Index.init @path
     Index.load
-    SourceManager.instance.instance_eval "@sources = {}"
     @draft_source = DraftManager.new_source
     SourceManager.add_source @draft_source
   end
diff --git a/test/integration/test_index.rb b/test/integration/test_index.rb
index 6dbeb59d..b64c5d3b 100644
--- a/test/integration/test_index.rb
+++ b/test/integration/test_index.rb
@@ -1,5 +1,5 @@
-require "sup"
 require "test_helper"
+require "sup"
 
 class TestIndexIntegration < Minitest::Test
   include Redwood
@@ -39,11 +39,15 @@ EOS
   end
 
   def start_sup_and_add_source source
-    start
+    $config = { :stem_language => "english" }
     Logger.remove_sink $stderr
+    HookManager.init File.join(@path, "hooks")
+    UpdateManager.init
+    SourceManager.init
+    PollManager.init
+    LabelManager.init File.join(@path, "labels.txt")
     Index.init @path
     Index.load
-    SourceManager.instance.instance_eval '@sources = {}'
     SourceManager.instance.add_source source
     PollManager.poll_from source
     Index.save_index
diff --git a/test/integration/test_maildir.rb b/test/integration/test_maildir.rb
index 1f734983..6ac8330a 100644
--- a/test/integration/test_maildir.rb
+++ b/test/integration/test_maildir.rb
@@ -1,5 +1,5 @@
-require "sup"
 require "test_helper"
+require "sup"
 
 class TestMaildir < Minitest::Test
 
@@ -40,11 +40,15 @@ EOS
   end
 
   def start_sup_and_add_source(source)
-    start
+    $config = { :stem_language => "english" }
     Logger.remove_sink $stderr
+    HookManager.init File.join(@path, "hooks")
+    UpdateManager.init
+    SourceManager.init
+    PollManager.init
+    LabelManager.init File.join(@path, "labels.txt")
     Index.init @path
     Index.load
-    SourceManager.instance.instance_eval '@sources = {}'
     SourceManager.instance.add_source source
     PollManager.poll_from source
     Index.save_index
@@ -91,4 +95,3 @@ EOS
     assert_equal fallback_date, messages_in_index.first.date
   end
 end
-
diff --git a/test/integration/test_mbox.rb b/test/integration/test_mbox.rb
index c80f7b81..739acf5c 100644
--- a/test/integration/test_mbox.rb
+++ b/test/integration/test_mbox.rb
@@ -1,5 +1,5 @@
-require "sup"
 require "test_helper"
+require "sup"
 
 class TestMbox < Minitest::Test
 
@@ -33,11 +33,15 @@ EOS
   end
 
   def start_sup_and_add_source(source)
-    start
+    $config = { :stem_language => "english" }
     Logger.remove_sink $stderr
+    HookManager.init File.join(@path, "hooks")
+    UpdateManager.init
+    SourceManager.init
+    PollManager.init
+    LabelManager.init File.join(@path, "labels.txt")
     Index.init @path
     Index.load
-    SourceManager.instance.instance_eval '@sources = {}'
     SourceManager.instance.add_source source
     PollManager.poll_from source
     Index.save_index
diff --git a/test/test_helper.rb b/test/test_helper.rb
index d331781a..35d3295c 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,6 +1,8 @@
 require "rubygems" rescue nil
 require 'minitest/autorun'
 require "rr"
+require "tmpdir"
+require "fileutils"
 
 def fixture_path(filename)
   File.expand_path("../fixtures/#{filename}", __FILE__)
@@ -11,3 +13,12 @@ def fixture_contents(filename)
   File.open(fixture_path(filename)) { |io| file = io.read }
   file
 end
+
+## Set SUP_BASE to an empty temp dir, so that tests do not accidentally touch ~/.sup.
+## This means test_helper must be require'd before sup.
+if defined? Redwood::BASE_DIR
+  abort "test_helper must be required before sup"
+end
+test_sup_base = Dir.mktmpdir "sup-base-for-tests"
+ENV["SUP_BASE"] = test_sup_base
+Minitest.after_run { FileUtils.rm_rf test_sup_base }
diff --git a/test/unit/test_index.rb b/test/unit/test_index.rb
index 08221aa2..ad084985 100644
--- a/test/unit/test_index.rb
+++ b/test/unit/test_index.rb
@@ -6,8 +6,11 @@ require "sup"
 class TestIndex < Minitest::Test
   def setup
     @path = Dir.mktmpdir
-    Redwood::start
+    $config = { :stem_language => "english" }
     Redwood::Logger.remove_sink $stderr
+    Redwood::HookManager.init File.join(@path, "hooks")
+    Redwood::SearchManager.init File.join(@path, "searches.txt")
+    Redwood::SourceManager.init
     Redwood::Index.init @path
     Redwood::Index.load
   end
diff --git a/test/unit/test_thread_view_mode.rb b/test/unit/test_thread_view_mode.rb
index 4c8ae839..ad7edcb8 100644
--- a/test/unit/test_thread_view_mode.rb
+++ b/test/unit/test_thread_view_mode.rb
@@ -1,6 +1,6 @@
+require "test_helper"
 require "dummy_buffer"
 require "dummy_source"
-require "test_helper"
 
 require "sup"
 
@@ -11,18 +11,24 @@ class TestThreadViewMode < Minitest::Test
     $config = {
       :indent_spaces => 2,
       :thread_by_subject => false,
+      :stem_language => "english",
+      :default_attachment_save_dir => "",
     }
     @path = Dir.mktmpdir
     @out = File.open File::NULL, "w"
     @inp = File.open File::NULL, "r"
     @screen = Ncurses.newterm "dumb", @out, @inp
     BufferManager.init
-    Redwood::start
     Logger.remove_sink $stderr
+    HookManager.init File.join(@path, "hooks")
+    UpdateManager.init
+    SourceManager.init
+    PollManager.init
+    LabelManager.init File.join(@path, "labels.txt")
+    ContactManager.init File.join(@path, "contacts.txt")
     Index.init File.join(@path, "xapian")
     Index.load
     @source = DummySource.new("sup-test://test_thread_view_mode")
-    SourceManager.instance.instance_eval '@sources = {}'
     SourceManager.instance.add_source @source
   end
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-28  7:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-28  7:37 [sup.git] branch develop updated (53f07beb -> cc601160) Dan Callaghan
2026-11-28  7:37 ` [sup.git] 01/02: store HookContext closures on the instance not the class Dan Callaghan
2026-11-28  7:37 ` [sup.git] 02/02: tests: avoid Redwood::start Dan Callaghan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox