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.
70 lines
2.5 KiB
Ruby
70 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require "test_helper"
|
|
|
|
# Smoke test for Opencode::Transform — the base class for
|
|
# content-rewriting transforms. It is intentionally abstract:
|
|
# #source_filename, #destination_filename, and #render all raise
|
|
# NotImplementedError. Subclasses (host-side) provide the meat.
|
|
# These tests document the abstract contract.
|
|
class Opencode::TransformTest < Minitest::Test
|
|
def test_source_filename_is_abstract
|
|
err = assert_raises(NotImplementedError) { Opencode::Transform.new.source_filename }
|
|
assert_match(/must implement #source_filename/, err.message)
|
|
end
|
|
|
|
def test_destination_filename_is_abstract
|
|
err = assert_raises(NotImplementedError) { Opencode::Transform.new.destination_filename }
|
|
assert_match(/must implement #destination_filename/, err.message)
|
|
end
|
|
|
|
def test_render_is_abstract
|
|
err = assert_raises(NotImplementedError) { Opencode::Transform.new.render(Object.new) }
|
|
assert_match(/must implement #render/, err.message)
|
|
end
|
|
|
|
def test_purge_impostors_defaults_to_false
|
|
refute Opencode::Transform.new.purge_impostors?,
|
|
"Default #purge_impostors? must be false — conservative opt-in by subclasses"
|
|
end
|
|
|
|
# A trivial concrete subclass exercises the defaults that DO exist
|
|
# (#applies_to?, #trusted?, #owned_filenames all delegate to the
|
|
# two abstract filename methods).
|
|
class FakeTransform < Opencode::Transform
|
|
def source_filename = "agent-output.json"
|
|
def destination_filename = "rendered.html"
|
|
end
|
|
|
|
Attachment = Struct.new(:filename, keyword_init: true)
|
|
Basenamed = Struct.new(:basename, keyword_init: true)
|
|
|
|
def test_applies_to_matches_source_filename_by_default
|
|
transform = FakeTransform.new
|
|
matching = Basenamed.new(basename: "agent-output.json")
|
|
other = Basenamed.new(basename: "something-else.json")
|
|
|
|
assert transform.applies_to?(matching)
|
|
refute transform.applies_to?(other)
|
|
end
|
|
|
|
def test_trusted_matches_destination_filename_by_default
|
|
transform = FakeTransform.new
|
|
trusted = Attachment.new(filename: "rendered.html")
|
|
untrusted = Attachment.new(filename: "agent-output.json")
|
|
|
|
assert transform.trusted?(trusted)
|
|
refute transform.trusted?(untrusted)
|
|
end
|
|
|
|
def test_owned_filenames_is_source_and_destination
|
|
assert_equal %w[agent-output.json rendered.html],
|
|
FakeTransform.new.owned_filenames
|
|
end
|
|
|
|
def test_error_is_a_subclass_of_standarderror
|
|
assert_operator Opencode::Transform::Error, :<, StandardError,
|
|
"Transform::Error must be rescuable by `rescue StandardError`"
|
|
end
|
|
end
|