Add focused smoke tests for the remaining 8 gem classes + adapter-raises edge

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.
This commit is contained in:
2026-05-20 06:40:34 -07:00
parent df01387124
commit 08ab6ea6fc
10 changed files with 460 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
# frozen_string_literal: true
require "test_helper"
# Contract smoke for Opencode::Turn (the orchestrator) and its inner
# Result value object. Behavioral coverage (the full send -> stream ->
# recover -> finalize loop) lives in the host application — Turn needs
# an Opencode::Client, an AR Message, a subject record, etc., which are
# all integration-level concerns.
class Opencode::TurnTest < Minitest::Test
REQUIRED_INIT_KEYS = %i[
message subject query_text client session_for observer_factory
system_context agent_name tracer
].freeze
OPTIONAL_INIT_KEYS = %i[
on_finalized on_turn_finished on_activity_tick
empty_stream_retry_delay final_exchange_timeout
final_exchange_retry_delay error_fallback_content error_feature
].freeze
def test_required_keyword_arguments
params = Opencode::Turn.instance_method(:initialize).parameters
required = params.select { |kind, _| kind == :keyreq }.map(&:last).sort
assert_equal REQUIRED_INIT_KEYS.sort, required,
"Turn's required keyword args drifted. Expected: #{REQUIRED_INIT_KEYS.sort}, got: #{required}"
end
def test_optional_keyword_arguments_match_documented_surface
params = Opencode::Turn.instance_method(:initialize).parameters
optional = params.select { |kind, _| kind == :key }.map(&:last).sort
assert_equal OPTIONAL_INIT_KEYS.sort, optional,
"Turn's optional keyword args drifted. Expected: #{OPTIONAL_INIT_KEYS.sort}, got: #{optional}"
end
def test_public_surface_is_call_only
# Turn is an orchestrator; the only public verb is #call. Everything
# else is internal. Locking this prevents helpers from accidentally
# bleeding into the public API.
assert_equal [ :call ], Opencode::Turn.instance_methods(false)
end
def test_result_is_a_value_object_with_status_predicates
fake_message = Struct.new(:cost, :input_tokens, :output_tokens, keyword_init: true).new(
cost: 0.012, input_tokens: 100, output_tokens: 50
)
result = Opencode::Turn::Result.new(
status: :completed, message: fake_message, duration_ms: 1234
)
assert result.completed?
refute result.cancelled?
refute result.errored?
refute result.failed?
assert_equal 1234, result.duration_ms
assert_equal 0.012, result.cost
assert_equal 100, result.input_tokens
assert_equal 50, result.output_tokens
end
end