ollama_chat 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 218e8513f0c79f05dda81a5361b10d1006c887e16b1c39c816f6598fec6f90e1
4
- data.tar.gz: 4584b135f6e1f9ed78c947bd915827215f2d035e9f16040ce4090c30ac3bcbbb
3
+ metadata.gz: cb31e7c6931a74314a918fa3f94838bccb89e2c7abd81c04632132998ed22f4b
4
+ data.tar.gz: e75bd24632b7c7ef65e1d316802db5a919a7c4e401941e1b080e15bfea208618
5
5
  SHA512:
6
- metadata.gz: 0bc92973a4eed105376057b8cd61ee0838db59ba101a29825ed0e8d6d56e85bf4a2ce38b817a4124ea912212875f670c94c1668756d7058fe0a4f3fdc98477b3
7
- data.tar.gz: 17021a77a6a2a8ab49dfe5ea624ab916048acbd2cc1762486fcdd6052ac5931193ff931ab3e01208b9e8dd3b42bab60a29be42c3d4cc0b359d2cb7dcfcd6f2e2
6
+ metadata.gz: 6c722b060b9e8c3e4e2de8cb3eca4656a75cc4eb063cc710350b27529d5b4449f58b75cf0f19cf6842019e0fe261ef0eda6af09e8ed8428458d01d2824315c3c
7
+ data.tar.gz: 28c6966b8e3d663935f8cc5ddfe572df73c3d8471bb51168734c98641099c983e59859b44f576d3e92b80ca2277633d9ce7d00ac37cd464c087cf77104942368
data/CHANGES.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changes
2
2
 
3
+ ## 2025-09-15 v0.0.32
4
+
5
+ - Fixed file path parsing for escaped spaces and URI handling
6
+ - Updated regex pattern for relative paths to better handle `\ ` escaped spaces
7
+ - Added explicit unescaping of spaces in test case for `./spec/assets/file\ with\ spaces.html`
8
+
9
+ ## 2025-09-15 v0.0.31
10
+
11
+ - Added new test asset file `"spec/assets/example with \".html"` as
12
+ `spec/assets/example_with_quote.html`
13
+ - Enhanced parsing tests in `spec/ollama_chat/parsing_spec.rb` to support file
14
+ URLs with spaces and quotes
15
+ - Added cleanup code using `FileUtils.rm_f` in test cases to remove temporary
16
+ files
17
+ - Modified test method names to reflect support for spaces and quotes in file
18
+ paths
19
+ - Added `ghostscript` package to the Dockerfile dependencies
20
+ - Added `fail_fast: true` to the script configuration
21
+ - Added a check for `pbcopy` command in clipboard spec
22
+ - Wrapped SimpleCov require in begin/rescue block to handle LoadError
23
+ - Set default `OLLAMA_HOST` environment variable to 'localhost:11434' in spec
24
+ helper
25
+ - Added `CONTENT_REGEXP` for unified parsing of URLs, tags, and file references
26
+ - Updated `parse_content` method to use new regex and support quoted file paths
27
+ - Introduced `check_exist:` option in `fetch_source` to validate file existence
28
+ - Extracted file reading logic into new helper method
29
+ `fetch_source_as_filename`
30
+ - Enhanced handling of file URLs with spaces and special characters
31
+ - Added comprehensive tests for parsing file paths with spaces, quotes, and
32
+ encoding
33
+ - Supported `file://` URI decoding using `URI.decode_www_form_component`
34
+ - Refactored `fetch_source` to better handle relative, absolute, and tilde
35
+ paths
36
+ - Updated spec files to use `Pathname` and improved assertions for file content
37
+ - Updated `gem_hadar` development dependency version from **2.3** to **2.6**
38
+
3
39
  ## 2025-09-11 v0.0.30
4
40
 
5
41
  - Changed `config.prompts.web_import` to `config.prompts.web_summarize` in default branch
@@ -189,6 +189,21 @@ module OllamaChat::Parsing
189
189
  )
190
190
  end
191
191
 
192
+ CONTENT_REGEXP = %r{
193
+ (https?://\S+) # Match HTTP/HTTPS URLs
194
+ | # OR
195
+ (?<![a-zA-Z\d]) # Negative lookbehind: not part of a larger word
196
+ \# # Literal # character (starts a tag)
197
+ ([\w\]\[]+) # Tag content: alphanumeric, brackets, underscores
198
+ | # OR
199
+ (file://(?:[^\s#]+)) # Match file:// URLs
200
+ | # OR
201
+ "((?:\.\.|[~.]?)/(?:\\"|\\|[^"\\]+)+)" # Quoted file path with escaped " quotes
202
+ | # OR
203
+ (\S*\/\S+) # File path with at least one forward slash
204
+ }x
205
+ private_constant :CONTENT_REGEXP
206
+
192
207
  # Parses content and processes embedded resources based on document policy
193
208
  #
194
209
  # This method analyzes input content for URLs, tags, and file references,
@@ -203,28 +218,30 @@ module OllamaChat::Parsing
203
218
  def parse_content(content, images)
204
219
  images.clear
205
220
  tags = Documentrix::Utils::Tags.new valid_tag: /\A#*([\w\]\[]+)/
206
-
207
221
  contents = [ content ]
208
- content.scan(%r((https?://\S+)|(?<![a-zA-Z\d])#+([\w\]\[]+)|(?:file://)?(\S*\/\S+))).each do |url, tag, file|
222
+ content.scan(CONTENT_REGEXP).each { |url, tag, file_url, quoted_file, file|
223
+ check_exist = false
209
224
  case
210
225
  when tag
211
226
  tags.add(tag)
212
227
  next
213
- when file
214
- file = file.sub(/#.*/, '')
215
- file =~ %r(\A[~./]) or file.prepend('./')
216
- file = begin
217
- File.expand_path(file)
218
- rescue ArgumentError
219
- next
220
- end
221
- File.exist?(file) or next
222
- source = file
223
228
  when url
224
229
  links.add(url.to_s)
225
230
  source = url
231
+ when file_url
232
+ check_exist = true
233
+ source = file_url
234
+ when quoted_file
235
+ file = quoted_file.gsub('\"', ?")
236
+ file =~ %r(\A[~./]) or file.prepend('./')
237
+ check_exist = true
238
+ source = file
239
+ when file
240
+ file =~ %r(\A[~./]) or file.prepend('./')
241
+ check_exist = true
242
+ source = file
226
243
  end
227
- fetch_source(source) do |source_io|
244
+ fetch_source(source, check_exist:) do |source_io|
228
245
  case source_io&.content_type&.media_type
229
246
  when 'image'
230
247
  add_image(images, source_io, source)
@@ -246,7 +263,7 @@ module OllamaChat::Parsing
246
263
  )
247
264
  end
248
265
  end
249
- end
266
+ }
250
267
  new_content = contents.select { _1.present? rescue nil }.compact * "\n\n"
251
268
  return new_content, (tags unless tags.empty?)
252
269
  end
@@ -52,14 +52,14 @@ module OllamaChat::SourceFetching
52
52
  # @param source [ String ] the source identifier which can be a command, URL, or file path
53
53
  #
54
54
  # @yield [ tmp ]
55
- def fetch_source(source, &block)
55
+ def fetch_source(source, check_exist: false, &block)
56
56
  case source
57
- when %r(\A!(.*))
57
+ when %r{\A!(.*)}
58
58
  command = $1
59
59
  OllamaChat::Utils::Fetcher.execute(command) do |tmp|
60
60
  block.(tmp)
61
61
  end
62
- when %r(\Ahttps?://\S+)
62
+ when %r{\Ahttps?://\S+}
63
63
  links.add(source.to_s)
64
64
  OllamaChat::Utils::Fetcher.get(
65
65
  source,
@@ -70,12 +70,24 @@ module OllamaChat::SourceFetching
70
70
  ) do |tmp|
71
71
  block.(tmp)
72
72
  end
73
- when %r(\Afile://(/\S*?)#|\A((?:\.\.|[~.]?)/\S*))
74
- filename = $~.captures.compact.first
73
+ when %r{\Afile://([^\s#]+)}
74
+ filename = $1
75
+ filename = URI.decode_www_form_component(filename)
75
76
  filename = File.expand_path(filename)
76
- OllamaChat::Utils::Fetcher.read(filename) do |tmp|
77
- block.(tmp)
78
- end
77
+ check_exist && !File.exist?(filename) and return
78
+ fetch_source_as_filename(filename, &block)
79
+ when %r{\A((?:\.\.|[~.]?)/(?:\\ |\\|[^\\]+)*)}
80
+ filename = $1
81
+ filename = filename.gsub('\ ', ' ')
82
+ filename = File.expand_path(filename)
83
+ check_exist && !File.exist?(filename) and return
84
+ fetch_source_as_filename(filename, &block)
85
+ when %r{\A"((?:\.\.|[~.]?)/(?:\\"|\\|[^"\\]+)+)"}
86
+ filename = $1
87
+ filename = filename.gsub('\"', ?")
88
+ filename = File.expand_path(filename)
89
+ check_exist && !File.exist?(filename) and return
90
+ fetch_source_as_filename(filename, &block)
79
91
  else
80
92
  raise "invalid source #{source.inspect}"
81
93
  end
@@ -83,6 +95,21 @@ module OllamaChat::SourceFetching
83
95
  STDERR.puts "Cannot fetch source #{source.to_s.inspect}: #{e.class} #{e}\n#{e.backtrace * ?\n}"
84
96
  end
85
97
 
98
+ # Reads a file and extends it with header extension metadata. It then yields
99
+ # the file to the provided block for processing. If the file does not exist,
100
+ # it outputs an error message to standard error.
101
+ #
102
+ # @param filename [ String ] the path to the file to be read
103
+ #
104
+ # @yield [ file ] yields the opened file with header extension
105
+ #
106
+ # @return [ nil ] returns nil if the file does not exist
107
+ # @return [ Object ] returns the result of the block execution if the file exists
108
+ private def fetch_source_as_filename(filename, &block)
109
+ OllamaChat::Utils::Fetcher.read(filename) do |tmp|
110
+ block.(tmp)
111
+ end
112
+ end
86
113
 
87
114
  # Adds an image to the images collection from the given source IO and source
88
115
  # identifier.
@@ -1,6 +1,6 @@
1
1
  module OllamaChat
2
2
  # OllamaChat version
3
- VERSION = '0.0.30'
3
+ VERSION = '0.0.32'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
data/ollama_chat.gemspec CHANGED
@@ -1,9 +1,9 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: ollama_chat 0.0.30 ruby lib
2
+ # stub: ollama_chat 0.0.32 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "ollama_chat".freeze
6
- s.version = "0.0.30".freeze
6
+ s.version = "0.0.32".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["ollama_chat".freeze, "ollama_chat_send".freeze]
15
15
  s.extra_rdoc_files = ["README.md".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze]
16
- s.files = [".utilsrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_chat_send".freeze, "config/searxng/settings.yml".freeze, "docker-compose.yml".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/ollama_chat_config/default_config.yml".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze, "ollama_chat.gemspec".freeze, "redis/redis.conf".freeze, "spec/assets/api_show.json".freeze, "spec/assets/api_tags.json".freeze, "spec/assets/api_version.json".freeze, "spec/assets/conversation.json".freeze, "spec/assets/duckduckgo.html".freeze, "spec/assets/example.atom".freeze, "spec/assets/example.csv".freeze, "spec/assets/example.html".freeze, "spec/assets/example.pdf".freeze, "spec/assets/example.ps".freeze, "spec/assets/example.rb".freeze, "spec/assets/example.rss".freeze, "spec/assets/example.xml".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/prompt.txt".freeze, "spec/assets/searxng.json".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_list_spec.rb".freeze, "spec/ollama_chat/message_output_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/file_argument_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
16
+ s.files = [".utilsrc".freeze, "CHANGES.md".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "bin/ollama_chat".freeze, "bin/ollama_chat_send".freeze, "config/searxng/settings.yml".freeze, "docker-compose.yml".freeze, "lib/ollama_chat.rb".freeze, "lib/ollama_chat/chat.rb".freeze, "lib/ollama_chat/clipboard.rb".freeze, "lib/ollama_chat/conversation.rb".freeze, "lib/ollama_chat/dialog.rb".freeze, "lib/ollama_chat/document_cache.rb".freeze, "lib/ollama_chat/follow_chat.rb".freeze, "lib/ollama_chat/history.rb".freeze, "lib/ollama_chat/information.rb".freeze, "lib/ollama_chat/kramdown_ansi.rb".freeze, "lib/ollama_chat/message_format.rb".freeze, "lib/ollama_chat/message_list.rb".freeze, "lib/ollama_chat/message_output.rb".freeze, "lib/ollama_chat/model_handling.rb".freeze, "lib/ollama_chat/ollama_chat_config.rb".freeze, "lib/ollama_chat/ollama_chat_config/default_config.yml".freeze, "lib/ollama_chat/parsing.rb".freeze, "lib/ollama_chat/server_socket.rb".freeze, "lib/ollama_chat/source_fetching.rb".freeze, "lib/ollama_chat/switches.rb".freeze, "lib/ollama_chat/utils.rb".freeze, "lib/ollama_chat/utils/cache_fetcher.rb".freeze, "lib/ollama_chat/utils/chooser.rb".freeze, "lib/ollama_chat/utils/fetcher.rb".freeze, "lib/ollama_chat/utils/file_argument.rb".freeze, "lib/ollama_chat/version.rb".freeze, "lib/ollama_chat/vim.rb".freeze, "lib/ollama_chat/web_searching.rb".freeze, "ollama_chat.gemspec".freeze, "redis/redis.conf".freeze, "spec/assets/api_show.json".freeze, "spec/assets/api_tags.json".freeze, "spec/assets/api_version.json".freeze, "spec/assets/conversation.json".freeze, "spec/assets/duckduckgo.html".freeze, "spec/assets/example.atom".freeze, "spec/assets/example.csv".freeze, "spec/assets/example.html".freeze, "spec/assets/example.pdf".freeze, "spec/assets/example.ps".freeze, "spec/assets/example.rb".freeze, "spec/assets/example.rss".freeze, "spec/assets/example.xml".freeze, "spec/assets/example_with_quote.html".freeze, "spec/assets/kitten.jpg".freeze, "spec/assets/prompt.txt".freeze, "spec/assets/searxng.json".freeze, "spec/ollama_chat/chat_spec.rb".freeze, "spec/ollama_chat/clipboard_spec.rb".freeze, "spec/ollama_chat/follow_chat_spec.rb".freeze, "spec/ollama_chat/information_spec.rb".freeze, "spec/ollama_chat/kramdown_ansi_spec.rb".freeze, "spec/ollama_chat/message_list_spec.rb".freeze, "spec/ollama_chat/message_output_spec.rb".freeze, "spec/ollama_chat/model_handling_spec.rb".freeze, "spec/ollama_chat/parsing_spec.rb".freeze, "spec/ollama_chat/server_socket_spec.rb".freeze, "spec/ollama_chat/source_fetching_spec.rb".freeze, "spec/ollama_chat/switches_spec.rb".freeze, "spec/ollama_chat/utils/cache_fetcher_spec.rb".freeze, "spec/ollama_chat/utils/fetcher_spec.rb".freeze, "spec/ollama_chat/utils/file_argument_spec.rb".freeze, "spec/ollama_chat/web_searching_spec.rb".freeze, "spec/spec_helper.rb".freeze, "tmp/.keep".freeze]
17
17
  s.homepage = "https://github.com/flori/ollama_chat".freeze
18
18
  s.licenses = ["MIT".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "OllamaChat - A command-line interface (CLI) for interacting with an Ollama AI model.".freeze, "--main".freeze, "README.md".freeze]
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
24
24
 
25
25
  s.specification_version = 4
26
26
 
27
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.3".freeze])
27
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 2.6".freeze])
28
28
  s.add_development_dependency(%q<all_images>.freeze, ["~> 0.6".freeze])
29
29
  s.add_development_dependency(%q<rspec>.freeze, ["~> 3.2".freeze])
30
30
  s.add_development_dependency(%q<kramdown>.freeze, ["~> 2.0".freeze])
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <body>
4
+
5
+ <h1>My First Heading</h1>
6
+
7
+ <p>My first paragraph.</p>
8
+
9
+ </body>
10
+ </html>
@@ -8,6 +8,7 @@ describe OllamaChat::Clipboard do
8
8
  connect_to_ollama_server
9
9
 
10
10
  it 'can copy to clipboard' do
11
+ `which pbcopy`.full? or skip 'pbcopy not in path'
11
12
  expect(STDERR).to receive(:puts).with(/No response available to copy to the system clipboard/)
12
13
  expect(chat.copy_to_clipboard).to be_nil
13
14
  chat.instance_variable_get(:@messages).load_conversation(asset('conversation.json'))
@@ -167,9 +167,10 @@ EOT
167
167
  end
168
168
 
169
169
  it 'can parse file URLs' do
170
- content, = chat.parse_content("see file://#{Dir.pwd}/spec/assets/example.html", [])
170
+ source_path= Pathname.pwd.join('spec/assets/example.html')
171
+ content, = chat.parse_content("see file://#{source_path}", [])
171
172
  expect(content).to include(<<~EOT)
172
- Imported "#{Pathname.pwd.join('spec/assets/example.html')}":
173
+ Imported "file://#{source_path}":
173
174
 
174
175
  # My First Heading
175
176
 
@@ -177,15 +178,48 @@ EOT
177
178
  EOT
178
179
  end
179
180
 
181
+ it 'can parse file URLs with spaces and quotes' do
182
+ file_path = Pathname.pwd.join('spec/assets/example with ".html')
183
+ FileUtils.cp 'spec/assets/example_with_quote.html', file_path
184
+ file_url = "file://#{file_path.to_s.gsub(' ', '%20').gsub('"', '%22')}"
185
+ content, = chat.parse_content("see #{file_url}", [])
186
+ expect(content).to include(<<~EOT)
187
+ Imported "#{file_url}":
188
+
189
+ # My First Heading
190
+
191
+ My first paragraph.
192
+ EOT
193
+ ensure
194
+ FileUtils.rm_f file_path
195
+ end
196
+
180
197
  it 'can parse file paths' do
181
- content, = chat.parse_content("see #{Dir.pwd}/spec/assets/example.html", [])
198
+ file_path = Pathname.pwd.join('spec/assets/example.html')
199
+ content, = chat.parse_content("see #{file_path}", [])
200
+ expect(content).to include(<<~EOT)
201
+ Imported "#{file_path}":
202
+
203
+ # My First Heading
204
+
205
+ My first paragraph.
206
+ EOT
207
+ end
208
+
209
+ it 'can parse quoted file paths' do
210
+ file_path = Pathname.pwd.join('spec/assets/example with ".html')
211
+ FileUtils.cp 'spec/assets/example_with_quote.html', file_path
212
+ quoted_file_path = file_path.to_s.gsub('"', '\"')
213
+ content, = chat.parse_content(%{see "#{quoted_file_path}"}, [])
182
214
  expect(content).to include(<<~EOT)
183
- Imported "#{Pathname.pwd.join('spec/assets/example.html')}":
215
+ Imported "#{quoted_file_path}":
184
216
 
185
217
  # My First Heading
186
218
 
187
219
  My first paragraph.
188
220
  EOT
221
+ ensure
222
+ FileUtils.rm_f file_path
189
223
  end
190
224
 
191
225
  it 'can add images' do
@@ -36,4 +36,67 @@ describe OllamaChat::SourceFetching do
36
36
  'This source was now embedded: ./spec/assets/example.html'
37
37
  )
38
38
  end
39
+
40
+ describe '#fetch_source' do
41
+ context 'with filename' do
42
+ it 'can handle files without spaces' do
43
+ source = './spec/assets/example.html'
44
+ expect(chat).to receive(:fetch_source_as_filename).
45
+ with(File.expand_path(source))
46
+ chat.fetch_source(source)
47
+ end
48
+
49
+ it 'can handle files with \\ escaped spaces' do
50
+ source = './spec/assets/file\ with\ spaces.html'
51
+ unescaped = source.gsub('\ ', ' ')
52
+ expect(chat).to receive(:fetch_source_as_filename).
53
+ with(File.expand_path(unescaped))
54
+ chat.fetch_source(source)
55
+ end
56
+
57
+ it 'can handle files with spaces in " quotes' do
58
+ source = '"./spec/assets/file with spaces.html"'
59
+ expect(chat).to receive(:fetch_source_as_filename).
60
+ with(File.expand_path(source[1..-2]))
61
+ chat.fetch_source(source)
62
+ end
63
+
64
+ it 'can handle files with spaces and " in " quotes' do
65
+ source = '"./spec/assets/file with \" and spaces.html"'
66
+ expect(chat).to receive(:fetch_source_as_filename).
67
+ with(File.expand_path('./spec/assets/file with " and spaces.html'))
68
+ chat.fetch_source(source)
69
+ end
70
+
71
+ it 'handles relative paths correctly' do
72
+ source = '../spec/assets/example.html'
73
+ expect(chat).to receive(:fetch_source_as_filename).
74
+ with(File.expand_path(source))
75
+ chat.fetch_source(source)
76
+ end
77
+
78
+ it 'handles tilde expansion in filename' do
79
+ source = '~/test.txt'
80
+ expect(chat).to receive(:fetch_source_as_filename).
81
+ with(File.expand_path(source))
82
+ chat.fetch_source(source)
83
+ end
84
+
85
+ it 'handles absolute paths in filename' do
86
+ source = '/tmp/test.txt'
87
+ expect(chat).to receive(:fetch_source_as_filename).
88
+ with(File.expand_path(source))
89
+ chat.fetch_source(source)
90
+ end
91
+ end
92
+
93
+ context 'with file:// URI' do
94
+ it 'fetches content from file URI with encoded paths' do
95
+ source = 'file:///path/with%20spaces/file.txt'
96
+ expect(chat).to receive(:fetch_source_as_filename).
97
+ with('/path/with spaces/file.txt')
98
+ chat.fetch_source(source)
99
+ end
100
+ end
101
+ end
39
102
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,8 @@
1
- require 'gem_hadar/simplecov'
2
- GemHadar::SimpleCov.start
1
+ begin
2
+ require 'gem_hadar/simplecov'
3
+ GemHadar::SimpleCov.start
4
+ rescue LoadError
5
+ end
3
6
  require 'rspec'
4
7
  require 'tins/xt/expose'
5
8
  begin
@@ -143,6 +146,9 @@ RSpec.configure do |config|
143
146
  config.extend StubOllamaServer
144
147
 
145
148
  config.around(&ProtectEnvVars.apply)
149
+ config.before(:each) do
150
+ ENV['OLLAMA_HOST'] = 'localhost:11434'
151
+ end
146
152
 
147
153
  config.before(:suite) do
148
154
  infobar.show = nil
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ollama_chat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '2.3'
18
+ version: '2.6'
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '2.3'
25
+ version: '2.6'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: all_images
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -466,6 +466,7 @@ files:
466
466
  - spec/assets/example.rb
467
467
  - spec/assets/example.rss
468
468
  - spec/assets/example.xml
469
+ - spec/assets/example_with_quote.html
469
470
  - spec/assets/kitten.jpg
470
471
  - spec/assets/prompt.txt
471
472
  - spec/assets/searxng.json