Sandi S2 (smoke coverage was 4/12) + Tobi T7 (adapter exception path
untested) consensus actions. 38 new tests across 9 files take total
from 15 -> 53 tests, 50 -> 134 assertions.
Per-class breakdown:
session_test.rb (2 tests)
Contract on initialize parameters (positional record + keyword
callables) and public surface (ensure!/recreate!/abort!/just_created?).
AR fixtures stay in the host suite.
turn_test.rb (4 tests)
Required + optional keyword arg contracts (locks the 9 required
+ 8 optional keys against drift). Public surface = [:call] only.
Result struct exercised as a value object with status predicates
and cost/token delegation.
message_artifacts_test.rb (2 tests)
Contract on initialize parameters; public surface = [:attach_from].
impostor_test.rb (3 tests)
Initialize keyword contract; delegation to ActiveStorage attachment
via a Struct double on #filename.
sandbox_test.rb (5 tests)
Real tmpdir instantiation: #path / #exists? / #files (Enumerator
when block-less, yields SandboxFile values when files present) /
#file lookup-by-basename returns nil for missing.
sandbox_file_test.rb (4 tests)
Real tmpdir + file: basic readers, marcel-backed content_type
detection, #safe? size-cap rejection, #as_artifact identity
conversion returns Opencode::Artifact.
transform_test.rb (8 tests)
Documents the abstract contract (source_filename / destination_filename /
render all raise NotImplementedError). A trivial concrete subclass
inside the test exercises the default implementations of
#applies_to?, #trusted?, #owned_filenames, and #purge_impostors?
that delegate to the two abstract filename methods.
tool_display_test.rb (5 tests)
Known tool canonicalization, status predicates (running/completed/
errored/in_flight/terminal), unknown-tool fallback, nil-part
tolerance (callers sometimes pass non-tool parts_json entries).
uploaded_files_prompt_test.rb (3 tests)
Initialize keyword contract; #text returns raw content + empty
sandbox_file_names map when no files attached; public surface check.
Plus 2 new tests in error_reporter_test.rb (C4):
- test_adapter_exceptions_propagate: adapter that raises must
propagate, not silently swallow — operators need to know the
error tracker is broken.
- test_report_returns_adapter_return_value: report passes through
the adapter's return value verbatim (Rails.error.report returns
the error itself; callers can chain).
Faithful to actual implementations: every test was first written from
the API I expected, then corrected against the class internals when
errors surfaced. The corrections themselves document the contract:
SandboxFile expects a String sandbox_prefix with trailing separator
(not a Pathname), Transform's filename methods are abstract not
nil-defaulting, etc.
76 lines
2.3 KiB
Ruby
76 lines
2.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test_helper"
|
|
|
|
class Opencode::ErrorReporterTest < Minitest::Test
|
|
def setup
|
|
@original_adapter = Opencode::ErrorReporter.adapter
|
|
Opencode::ErrorReporter.adapter = nil
|
|
end
|
|
|
|
def teardown
|
|
Opencode::ErrorReporter.adapter = @original_adapter
|
|
end
|
|
|
|
def test_report_is_no_op_without_adapter
|
|
# Must not raise, must return nil.
|
|
result = Opencode::ErrorReporter.report(StandardError.new("boom"))
|
|
assert_nil result
|
|
end
|
|
|
|
def test_report_forwards_to_adapter
|
|
captured = []
|
|
Opencode::ErrorReporter.adapter = ->(error, **opts) {
|
|
captured << [error, opts]
|
|
:sentinel
|
|
}
|
|
|
|
err = ArgumentError.new("bad arg")
|
|
result = Opencode::ErrorReporter.report(err, severity: :error, context: { foo: 1 })
|
|
|
|
assert_equal :sentinel, result
|
|
assert_equal 1, captured.length
|
|
captured_error, captured_opts = captured.first
|
|
assert_same err, captured_error
|
|
assert_equal :error, captured_opts[:severity]
|
|
assert_equal({ foo: 1 }, captured_opts[:context])
|
|
end
|
|
|
|
def test_report_accepts_no_keyword_args
|
|
invoked = false
|
|
Opencode::ErrorReporter.adapter = ->(error, **opts) {
|
|
invoked = true
|
|
assert_empty opts
|
|
refute_nil error
|
|
}
|
|
|
|
Opencode::ErrorReporter.report(RuntimeError.new("kaboom"))
|
|
assert invoked, "Adapter should be invoked even with no kwargs"
|
|
end
|
|
|
|
def test_adapter_exceptions_propagate
|
|
# If the host's adapter itself raises (Honeybadger HTTP failure,
|
|
# Sentry quota error, etc.) the gem must propagate — silently
|
|
# swallowing the adapter's own errors would hide an outage from
|
|
# operators who think their error tracker is healthy.
|
|
Opencode::ErrorReporter.adapter = ->(_error, **_opts) {
|
|
raise StandardError, "adapter blew up"
|
|
}
|
|
|
|
raised = assert_raises(StandardError) do
|
|
Opencode::ErrorReporter.report(RuntimeError.new("original"))
|
|
end
|
|
assert_equal "adapter blew up", raised.message
|
|
end
|
|
|
|
def test_report_returns_adapter_return_value
|
|
# Useful for hosts wanting Rails.error.report's standard return
|
|
# (the error itself). Verifies the call shape doesn't transform it.
|
|
sentinel = Object.new
|
|
Opencode::ErrorReporter.adapter = ->(_error, **_opts) { sentinel }
|
|
|
|
result = Opencode::ErrorReporter.report(StandardError.new("x"))
|
|
assert_same sentinel, result
|
|
end
|
|
end
|