Files
opencode-rails/test/opencode/artifact_test.rb
Ajay Krishnan 0611a2aa82 Add smoke tests for opencode-rails
14 tests across 4 files covering the gem's public surface:

  test/opencode/loading_test.rb (5 tests)
    - All 12 gem-provided constants resolve after require
    - Transitively-loaded opencode-ruby constants are present
    - Opencode::Session source_location points at this gem
    - Opencode::Client source_location points at opencode-ruby
    - Opencode::Rails::VERSION matches semver

  test/opencode/error_reporter_test.rb (3 tests)
    - report is no-op without adapter (returns nil)
    - report forwards error + opts to adapter
    - report works with no kwargs

  test/opencode/exchange_test.rb (3 tests)
    - Initializes with empty / nil / Array(coerced) messages
    - tool_artifacts(exclude:) doesn't raise on empty input

  test/opencode/artifact_test.rb (3 tests)
    - Filename/content/content_type/metadata readers
    - metadata defaults to {} when omitted
    - Trust metadata round-trips

Behavioral tests for Session/Turn/MessageArtifacts (AR + ActiveStorage
fixtures) stay in the host application (ajent-rails) where the
integration environment exists. Same pattern as opencode-ruby:
  - gem smoke tests prove load-time correctness
  - host tests prove integration correctness
2026-05-20 05:15:49 -07:00

37 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
# Smoke test for Opencode::Artifact — verifies the value-object surface
# (filename/content/content_type readers). Behavioral tests around how
# the host's ActiveStorage-backed AIGL::Trip/etc. records build artifact
# collections live in the host's test suite.
class Opencode::ArtifactTest < Minitest::Test
def test_value_object_readers
artifact = Opencode::Artifact.new(
filename: "notes.md",
content: "# Notes",
content_type: "text/markdown"
)
assert_equal "notes.md", artifact.filename
assert_equal "# Notes", artifact.content
assert_equal "text/markdown", artifact.content_type
end
def test_metadata_defaults_to_empty_hash
artifact = Opencode::Artifact.new(filename: "x.txt", content: "hi", content_type: "text/plain")
assert_equal({}, artifact.metadata)
end
def test_metadata_accepts_trust_hash
artifact = Opencode::Artifact.new(
filename: "x.html",
content: "<p>",
content_type: "text/html",
metadata: { trust: "host_rendered" }
)
assert_equal "host_rendered", artifact.metadata[:trust]
end
end