Files
simple-aircraft-manager-rails/test/services/logbook_transcriber_test.rb
T
rickyandClaude Opus 5.5 1c6c2f88c0 Blackstone oil analysis, .sam.zip export/import, AI logbook transcription
- Oil analysis: Blackstone PDF import (20 elements, oil properties, universal
  averages), results stored per element, oil type, "leave out of trends",
  the original app's statuses; AvLab fixes (multi-line comments, unrelated
  labels no longer steal values). Existing records migrate.
- Aircraft archives in the original app's .sam.zip format (schema v2): export
  from Access & Sharing, background import from the Fleet page, rake tasks.
  Archives move both ways between this app and the original.
- Scanned logbook pages (images or PDFs) upload as a document; with
  ANTHROPIC_API_KEY set, Claude transcribes them into logbook entries.
- Fix: deleting a component or aircraft failed when AD compliances or
  inspection records pointed at a component.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-06 21:05:19 -05:00

33 lines
1.4 KiB
Ruby

require "test_helper"
class LogbookTranscriberTest < ActiveSupport::TestCase
Message = Struct.new(:stop_reason, :content, :model)
Text = Struct.new(:type, :text)
def client_returning(message)
Class.new do
define_method(:beta) { self }
define_method(:messages) { self }
define_method(:stream) { |**| Struct.new(:accumulated_message).new(message) }
end.new
end
def transcribe(message) = LogbookTranscriber.new(client: client_returning(message)).transcribe([ { data: "x", media_type: "image/png" } ])
test "reads the structured answer" do
json = { entries: [ { "text" => "Annual" } ], non_logbook_pages: [ 2 ], unparseable_pages: [] }.to_json
result = transcribe(Message.new(:end_turn, [ Text.new(:thinking, ""), Text.new(:text, json) ], "claude-opus-5-5"))
assert_equal [ { "text" => "Annual" } ], result.entries
assert_equal [ 2 ], result.non_logbook_pages
end
test "turns refusals, truncation and bad JSON into clear errors" do
{ refusal: "declined", max_tokens: "too long to finish" }.each do |reason, message|
error = assert_raises(LogbookTranscriber::Error) { transcribe(Message.new(reason, [], "m")) }
assert_match message, error.message
end
error = assert_raises(LogbookTranscriber::Error) { transcribe(Message.new(:end_turn, [ Text.new(:text, "{nope") ], "m")) }
assert_match "wasn't valid JSON", error.message
end
end