Commit Graph

4 Commits

Author SHA1 Message Date
08ab6ea6fc 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.
2026-05-20 06:40:34 -07:00
df01387124 Code review actions: rename version file, drop Gemfile conditional, tighten gemspec, switch URLs to GitHub
Three tightly-coupled cleanups from the Tobi+Sandi review:

1. Rename lib/opencode/rails/version.rb -> lib/opencode/rails_version.rb
   (Sandi S1: file path was lying about its contents — the file defines
   Opencode::RAILS_VERSION, NOT Opencode::Rails::VERSION). Updated the
   require_relative in opencode-rails.gemspec and lib/opencode-rails.rb
   to match. Removed the now-empty lib/opencode/rails/ directory.

2. Drop the 'if File.exist?(...) gem opencode-ruby, path: ...' Gemfile
   conditional (Tobi T2 / Sandi S4: Bundler behavior must not depend on
   filesystem state). The dev-time sibling-repo override is now
   documented in CONTRIBUTING.md as the standard 'bundle config
   local.opencode-ruby <path>' pattern, which is what Bundler ships
   for this use case.

3. Tighten opencode-ruby runtime dep from '~> 0.0.1.alpha1' to
   '= 0.0.1.alpha1' (Tobi T1: ~> during alpha is aspirational; pin
   exactly until the public API stabilizes).

Same commit also switches all forward-looking URLs (gemspec homepage,
metadata, README link to opencode-ruby) from Gitea to GitHub since the
gems will eventually publish there. Functional 'git:' URL in
ajent-rails' Gemfile stays on Gitea — that's where the gems actually
are right now; ajent-rails Gemfile flips to GitHub when the user does
the actual remote setup.

Test assertion in loading_test was tightened to match either an
installed-gem path ('gems/opencode-X-VERSION/') or a sibling-repo
checkout ('/opencode-X/'), via a small GEM_PATH_PATTERN helper.

15 tests, 50 assertions, 0 failures.
2026-05-20 06:35:58 -07:00
8ccfe0f7cf Rename Opencode::Rails::VERSION -> Opencode::RAILS_VERSION
Critical fix: defining Opencode::Rails as a module shadowed ::Rails
under Ruby's constant lookup whenever host code referenced top-level
Rails.something from inside the Opencode:: namespace.

Caught when host code in lib/opencode/containers/container.rb failed
to boot:

  /workspaces/app/lib/opencode/containers/container.rb:433:
    undefined method 'root' for module Opencode::Rails (NoMethodError)
      "notes.md" => Rails.root.join(...)

Ruby resolved 'Rails' to 'Opencode::Rails' first (the gem's version
namespace) before falling back to ::Rails. The fix removes the
intermediate module entirely:

  module Opencode
    RAILS_VERSION = "0.0.1.alpha1"
  end

Added a regression test (test_no_opencode_rails_module) so the
shadowing never sneaks back in. opencode-ruby uses Opencode::VERSION
for its own gem version; we can't double-up on that constant, so this
gem uses RAILS_VERSION as a sibling on the same Opencode module.
2026-05-20 05:22:23 -07:00
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