kreuzberg 4.6.3-aarch64-linux → 4.7.2-aarch64-linux

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.
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Cross-language serialization tests for Ruby bindings
4
- #
5
- # Validates that ExtractionConfig serializes consistently with other language bindings
6
-
7
- require 'json'
8
- require 'spec_helper'
9
-
10
- RSpec.describe Kreuzberg::ExtractionConfig do
11
- describe '#to_h' do
12
- it 'serializes minimal config to hash' do
13
- config = described_class.new
14
- hash = config.to_h
15
-
16
- expect(hash).to be_a(Hash)
17
- expect(hash).to have_key(:use_cache)
18
- expect(hash).to have_key(:enable_quality_processing)
19
- expect(hash).to have_key(:force_ocr)
20
- end
21
-
22
- it 'serializes config with all fields' do
23
- config = described_class.new(
24
- use_cache: true,
25
- enable_quality_processing: true,
26
- force_ocr: false
27
- )
28
-
29
- hash = config.to_h
30
-
31
- expect(hash[:use_cache]).to be(true)
32
- expect(hash[:enable_quality_processing]).to be(true)
33
- expect(hash[:force_ocr]).to be(false)
34
- end
35
-
36
- it 'preserves field values after serialization' do
37
- original = described_class.new(
38
- use_cache: false,
39
- enable_quality_processing: true
40
- )
41
-
42
- hash = original.to_h
43
-
44
- expect(hash[:use_cache]).to be(false)
45
- expect(hash[:enable_quality_processing]).to be(true)
46
- end
47
- end
48
-
49
- describe '#to_json' do
50
- it 'serializes to JSON' do
51
- config = described_class.new(use_cache: true)
52
- json = config.to_json
53
-
54
- expect(json).to be_a(String)
55
-
56
- parsed = JSON.parse(json, symbolize_names: true)
57
- expect(parsed).to have_key(:use_cache)
58
- expect(parsed[:use_cache]).to be(true)
59
- end
60
-
61
- it 'produces valid JSON' do
62
- config = described_class.new
63
- json = config.to_json
64
-
65
- expect { JSON.parse(json) }.not_to raise_error
66
- end
67
-
68
- it 'uses snake_case field names' do
69
- config = described_class.new(use_cache: true)
70
- json = config.to_json
71
-
72
- expect(json).to include('use_cache')
73
- expect(json).not_to include('useCache')
74
- end
75
- end
76
-
77
- describe 'round-trip serialization' do
78
- it 'survives serialization -> deserialization -> serialization' do
79
- config1 = described_class.new(
80
- use_cache: true,
81
- enable_quality_processing: false
82
- )
83
-
84
- json1 = config1.to_json
85
- hash1 = JSON.parse(json1, symbolize_names: true)
86
-
87
- config2 = described_class.new(hash1)
88
- json2 = config2.to_json
89
-
90
- # JSON strings should be equivalent
91
- expect(JSON.parse(json1)).to eq(JSON.parse(json2))
92
- end
93
- end
94
-
95
- describe 'field consistency' do
96
- it 'includes all mandatory fields' do
97
- config = described_class.new
98
- hash = config.to_h
99
-
100
- mandatory_fields = %i[use_cache enable_quality_processing force_ocr]
101
- mandatory_fields.each do |field|
102
- expect(hash).to have_key(field)
103
- end
104
- end
105
-
106
- it 'handles nested ocr config' do
107
- config = described_class.new(
108
- ocr: {
109
- backend: 'tesseract',
110
- language: 'eng'
111
- }
112
- )
113
-
114
- hash = config.to_h
115
-
116
- expect(hash).to have_key(:ocr)
117
- expect(hash[:ocr][:backend]).to eq('tesseract')
118
- expect(hash[:ocr][:language]).to eq('eng')
119
- end
120
- end
121
-
122
- describe 'immutability' do
123
- it 'does not modify original config during serialization' do
124
- config = described_class.new(use_cache: true)
125
-
126
- json1 = config.to_json
127
- json2 = config.to_json
128
- json3 = config.to_json
129
-
130
- expect(json1).to eq(json2)
131
- expect(json2).to eq(json3)
132
- end
133
- end
134
- end
@@ -1,199 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'stringio'
4
-
5
- RSpec.describe 'Kreuzberg package' do
6
- describe 'import and structure' do
7
- it 'can be required without errors' do
8
- expect { require 'kreuzberg' }.not_to raise_error
9
- end
10
-
11
- it 'has a version constant' do
12
- expect(Kreuzberg::VERSION).not_to be_nil
13
- expect(Kreuzberg::VERSION).to be_a(String)
14
- expect(Kreuzberg::VERSION).to match(/^\d+\.\d+\.\d+/)
15
- end
16
- end
17
-
18
- describe 'sorbet-runtime dependency' do
19
- it 'loads sorbet-runtime as a runtime dependency' do
20
- expect { require 'sorbet-runtime' }.not_to raise_error
21
- expect(defined?(T)).to eq('constant')
22
- end
23
-
24
- it 'loads Kreuzberg types backed by T::Struct without error' do
25
- expect { Kreuzberg::BoundingBox }.not_to raise_error
26
- expect { Kreuzberg::Element }.not_to raise_error
27
- expect { Kreuzberg::ElementMetadata }.not_to raise_error
28
- expect { Kreuzberg::HtmlMetadata }.not_to raise_error
29
- expect { Kreuzberg::DocumentNode }.not_to raise_error
30
- end
31
-
32
- it 'instantiates T::Struct types correctly' do
33
- bbox = Kreuzberg::BoundingBox.new(x0: 0.0, y0: 0.0, x1: 100.0, y1: 50.0)
34
- expect(bbox).to be_a(T::Struct)
35
- expect(bbox.x0).to eq(0.0)
36
- expect(bbox.x1).to eq(100.0)
37
- end
38
- end
39
-
40
- describe 'public API exports' do
41
- describe 'configuration classes' do
42
- it 'exports Config::Extraction' do
43
- expect(defined?(Kreuzberg::Config::Extraction)).to eq('constant')
44
- end
45
-
46
- it 'exports Config::OCR' do
47
- expect(defined?(Kreuzberg::Config::OCR)).to eq('constant')
48
- end
49
-
50
- it 'exports Config::Chunking' do
51
- expect(defined?(Kreuzberg::Config::Chunking)).to eq('constant')
52
- end
53
-
54
- it 'exports Config::LanguageDetection' do
55
- expect(defined?(Kreuzberg::Config::LanguageDetection)).to eq('constant')
56
- end
57
-
58
- it 'exports Config::PDF' do
59
- expect(defined?(Kreuzberg::Config::PDF)).to eq('constant')
60
- end
61
-
62
- it 'exports Config::HtmlOptions' do
63
- expect(defined?(Kreuzberg::Config::HtmlOptions)).to eq('constant')
64
- end
65
-
66
- it 'exports Config::Keywords' do
67
- expect(defined?(Kreuzberg::Config::Keywords)).to eq('constant')
68
- end
69
- end
70
-
71
- describe 'result classes' do
72
- it 'exports Result' do
73
- expect(defined?(Kreuzberg::Result)).to eq('constant')
74
- end
75
-
76
- it 'exports Result::Table' do
77
- expect(defined?(Kreuzberg::Result::Table)).to eq('constant')
78
- end
79
-
80
- it 'exports Result::Chunk' do
81
- expect(defined?(Kreuzberg::Result::Chunk)).to eq('constant')
82
- end
83
-
84
- it 'exports Result::Image' do
85
- expect(defined?(Kreuzberg::Result::Image)).to eq('constant')
86
- end
87
- end
88
-
89
- describe 'exception classes' do
90
- it 'exports Errors::Error' do
91
- expect(defined?(Kreuzberg::Errors::Error)).to eq('constant')
92
- end
93
-
94
- it 'exports Errors::ValidationError' do
95
- expect(defined?(Kreuzberg::Errors::ValidationError)).to eq('constant')
96
- end
97
-
98
- it 'exports Errors::ParsingError' do
99
- expect(defined?(Kreuzberg::Errors::ParsingError)).to eq('constant')
100
- end
101
-
102
- it 'exports Errors::OCRError' do
103
- expect(defined?(Kreuzberg::Errors::OCRError)).to eq('constant')
104
- end
105
-
106
- it 'exports Errors::MissingDependencyError' do
107
- expect(defined?(Kreuzberg::Errors::MissingDependencyError)).to eq('constant')
108
- end
109
-
110
- it 'exports Errors::IOError' do
111
- expect(defined?(Kreuzberg::Errors::IOError)).to eq('constant')
112
- end
113
-
114
- it 'exports Errors::PluginError' do
115
- expect(defined?(Kreuzberg::Errors::PluginError)).to eq('constant')
116
- end
117
- end
118
-
119
- describe 'extraction functions (sync)' do
120
- it 'exports extract_file_sync' do
121
- expect(Kreuzberg).to respond_to(:extract_file_sync)
122
- end
123
-
124
- it 'exports extract_bytes_sync' do
125
- expect(Kreuzberg).to respond_to(:extract_bytes_sync)
126
- end
127
-
128
- it 'exports batch_extract_files_sync' do
129
- expect(Kreuzberg).to respond_to(:batch_extract_files_sync)
130
- end
131
- end
132
-
133
- describe 'extraction functions (async)' do
134
- it 'exports extract_file' do
135
- expect(Kreuzberg).to respond_to(:extract_file)
136
- end
137
-
138
- it 'exports extract_bytes' do
139
- expect(Kreuzberg).to respond_to(:extract_bytes)
140
- end
141
-
142
- it 'exports batch_extract_files' do
143
- expect(Kreuzberg).to respond_to(:batch_extract_files)
144
- end
145
- end
146
-
147
- describe 'utility modules' do
148
- it 'exports CLI' do
149
- expect(defined?(Kreuzberg::CLI)).to eq('constant')
150
- end
151
-
152
- it 'exports CLIProxy' do
153
- expect(defined?(Kreuzberg::CLIProxy)).to eq('constant')
154
- end
155
-
156
- it 'exports APIProxy' do
157
- expect(defined?(Kreuzberg::APIProxy)).to eq('constant')
158
- end
159
-
160
- it 'exports MCPProxy' do
161
- expect(defined?(Kreuzberg::MCPProxy)).to eq('constant')
162
- end
163
- end
164
- end
165
-
166
- describe 'module structure' do
167
- it 'defines Kreuzberg as a module' do
168
- expect(Kreuzberg).to be_a(Module)
169
- end
170
-
171
- it 'defines Kreuzberg::Config as a module' do
172
- expect(Kreuzberg::Config).to be_a(Module)
173
- end
174
-
175
- it 'defines Kreuzberg::Errors as a module' do
176
- expect(Kreuzberg::Errors).to be_a(Module)
177
- end
178
- end
179
-
180
- describe 'basic extraction smoke tests' do
181
- it 'extracts inline text via bytes API' do
182
- bytes = StringIO.new('Hello from Kreuzberg')
183
- result = Kreuzberg.extract_bytes_sync(data: bytes.string, mime_type: 'text/plain')
184
-
185
- expect(result.content).to include('Hello')
186
- expect(result.mime_type).to eq('text/plain')
187
- end
188
-
189
- it 'extracts from small temp file via sync API' do
190
- file = create_test_file('Simple document for smoke testing')
191
- result = Kreuzberg.extract_file_sync(path: file)
192
-
193
- expect(result.content).to include('Simple document')
194
- expect(result.mime_type).to eq('text/plain')
195
- ensure
196
- File.delete(file) if file && File.exist?(file)
197
- end
198
- end
199
- end
@@ -1,213 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe Kreuzberg::Config::Chunking do
4
- describe '#initialize' do
5
- it 'creates config with default values' do
6
- config = described_class.new
7
-
8
- expect(config.max_chars).to eq 1000
9
- expect(config.max_overlap).to eq 200
10
- expect(config.preset).to be_nil
11
- expect(config.embedding).to be_nil
12
- expect(config.enabled).to be true
13
- end
14
-
15
- it 'creates config with custom values' do
16
- config = described_class.new(
17
- max_chars: 500,
18
- max_overlap: 100,
19
- preset: 'fast'
20
- )
21
-
22
- expect(config.max_chars).to eq 500
23
- expect(config.max_overlap).to eq 100
24
- expect(config.preset).to eq 'fast'
25
- end
26
-
27
- it 'accepts chunk_size alias for max_chars' do
28
- config = described_class.new(chunk_size: 750)
29
-
30
- expect(config.max_chars).to eq 750
31
- end
32
-
33
- it 'accepts chunk_overlap alias for max_overlap' do
34
- config = described_class.new(chunk_overlap: 150)
35
-
36
- expect(config.max_overlap).to eq 150
37
- end
38
-
39
- it 'uses max_chars when both chunk_size and max_chars provided' do
40
- config = described_class.new(chunk_size: 500, max_chars: 1000)
41
-
42
- expect(config.max_chars).to eq 500
43
- end
44
-
45
- it 'accepts embedding as instance' do
46
- embedding = Kreuzberg::Config::Embedding.new(model: { type: :preset, name: 'fast' })
47
- config = described_class.new(embedding: embedding)
48
-
49
- expect(config.embedding).to be_a Kreuzberg::Config::Embedding
50
- end
51
-
52
- it 'converts embedding hash to instance' do
53
- config = described_class.new(embedding: { model: { type: :preset, name: 'balanced' } })
54
-
55
- expect(config.embedding).to be_a Kreuzberg::Config::Embedding
56
- end
57
- end
58
-
59
- describe '#to_h' do
60
- it 'serializes to hash with default values' do
61
- config = described_class.new
62
- hash = config.to_h
63
-
64
- expect(hash).to be_a Hash
65
- expect(hash[:max_chars]).to eq 1000
66
- expect(hash[:max_overlap]).to eq 200
67
- expect(hash[:enabled]).to be true
68
- end
69
-
70
- it 'includes embedding in hash when present' do
71
- config = described_class.new(embedding: { model: { type: :preset, name: 'fast' } })
72
- hash = config.to_h
73
-
74
- expect(hash[:embedding]).to be_a Hash
75
- end
76
-
77
- it 'compacts nil values from hash' do
78
- config = described_class.new
79
- hash = config.to_h
80
-
81
- expect(hash.key?(:preset)).to be false
82
- expect(hash.key?(:embedding)).to be false
83
- end
84
- end
85
-
86
- describe 'validation' do
87
- it 'rejects negative max_chars' do
88
- expect do
89
- described_class.new(max_chars: -100)
90
- end.to raise_error ArgumentError, /max_chars must be a positive integer/
91
- end
92
-
93
- it 'rejects negative max_overlap' do
94
- expect do
95
- described_class.new(max_overlap: -50)
96
- end.to raise_error ArgumentError, /max_overlap must be a positive integer/
97
- end
98
-
99
- it 'accepts zero values' do
100
- expect do
101
- described_class.new(max_chars: 0, max_overlap: 0)
102
- end.not_to raise_error
103
- end
104
-
105
- it 'accepts positive values' do
106
- expect do
107
- described_class.new(max_chars: 2000, max_overlap: 500)
108
- end.not_to raise_error
109
- end
110
- end
111
-
112
- describe 'keyword arguments' do
113
- it 'accepts all keyword arguments' do
114
- config = described_class.new(
115
- max_chars: 750,
116
- max_overlap: 150,
117
- preset: 'balanced',
118
- enabled: true
119
- )
120
-
121
- expect(config.max_chars).to eq 750
122
- expect(config.max_overlap).to eq 150
123
- expect(config.preset).to eq 'balanced'
124
- expect(config.enabled).to be true
125
- end
126
-
127
- it 'converts preset to string' do
128
- config = described_class.new(preset: :fast)
129
-
130
- expect(config.preset).to eq 'fast'
131
- expect(config.preset).to be_a String
132
- end
133
- end
134
-
135
- describe 'equality' do
136
- it 'compares configs by value' do
137
- config1 = described_class.new(max_chars: 500, max_overlap: 100)
138
- config2 = described_class.new(max_chars: 500, max_overlap: 100)
139
-
140
- expect(config1.max_chars).to eq config2.max_chars
141
- expect(config1.max_overlap).to eq config2.max_overlap
142
- end
143
-
144
- it 'detects differences' do
145
- config1 = described_class.new(max_chars: 500)
146
- config2 = described_class.new(max_chars: 1000)
147
-
148
- expect(config1.max_chars).not_to eq config2.max_chars
149
- end
150
- end
151
-
152
- describe 'nested config integration' do
153
- it 'can be nested in Extraction config' do
154
- chunking = described_class.new(max_chars: 750, preset: 'fast')
155
- extraction = Kreuzberg::Config::Extraction.new(chunking: chunking)
156
-
157
- expect(extraction.chunking).to be_a described_class
158
- expect(extraction.chunking.max_chars).to eq 750
159
- end
160
-
161
- it 'accepts hash in Extraction config' do
162
- extraction = Kreuzberg::Config::Extraction.new(
163
- chunking: { max_chars: 500, preset: 'balanced' }
164
- )
165
-
166
- expect(extraction.chunking).to be_a described_class
167
- expect(extraction.chunking.max_chars).to eq 500
168
- end
169
- end
170
-
171
- describe 'symbol vs string key handling' do
172
- it 'converts symbol preset to string' do
173
- config = described_class.new(preset: :fast)
174
-
175
- expect(config.preset).to eq 'fast'
176
- expect(config.preset).to be_a String
177
- end
178
-
179
- it 'converts integer strings to integers' do
180
- config = described_class.new(max_chars: '1500', max_overlap: '300')
181
-
182
- expect(config.max_chars).to eq 1500
183
- expect(config.max_overlap).to eq 300
184
- expect(config.max_chars).to be_a Integer
185
- end
186
- end
187
-
188
- describe 'enabled field' do
189
- it 'defaults to true' do
190
- config = described_class.new
191
-
192
- expect(config.enabled).to be true
193
- end
194
-
195
- it 'accepts false' do
196
- config = described_class.new(enabled: false)
197
-
198
- expect(config.enabled).to be false
199
- end
200
-
201
- it 'converts truthy values to true' do
202
- config = described_class.new(enabled: 'yes')
203
-
204
- expect(config.enabled).to be true
205
- end
206
-
207
- it 'can be nil' do
208
- config = described_class.new(enabled: nil)
209
-
210
- expect(config.enabled).to be_nil
211
- end
212
- end
213
- end