scout-ai 2.0.0 → 2.2.0

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.
Files changed (185) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +135 -55
  3. data/README.md +2 -1
  4. data/VERSION +1 -1
  5. data/doc/Improvements.md +490 -148
  6. data/doc/Model.md +53 -10
  7. data/doc/StartHere.md +44 -19
  8. data/doc/developer/Architecture.md +25 -6
  9. data/doc/developer/Backends.md +207 -48
  10. data/doc/developer/ChatLifecycle.md +121 -20
  11. data/doc/developer/DelegationInternals.md +320 -34
  12. data/doc/developer/DesignPrinciples.md +205 -16
  13. data/doc/developer/PathEngine.md +628 -0
  14. data/doc/developer/PromptProcessing.md +332 -82
  15. data/doc/developer/Provenance.md +402 -44
  16. data/doc/developer/Sandbox.md +213 -0
  17. data/doc/user/BuildingAgents.md +130 -18
  18. data/doc/user/Cookbook.md +29 -8
  19. data/doc/user/CoreConcepts.md +7 -6
  20. data/doc/user/Delegation.md +166 -15
  21. data/doc/user/GettingStarted.md +20 -16
  22. data/doc/user/ManagingContext.md +155 -17
  23. data/doc/user/MultiAgentWorkflows.md +105 -15
  24. data/doc/user/Python.md +11 -1
  25. data/doc/user/RunningInference.md +90 -47
  26. data/doc/user/ToolCalling.md +134 -29
  27. data/doc/user/WritingChats.md +56 -27
  28. data/lib/scout/llm/agent/attach.rb +64 -0
  29. data/lib/scout/llm/agent/chat.rb +32 -0
  30. data/lib/scout/llm/agent/construction.rb +64 -0
  31. data/lib/scout/llm/agent/conversation.rb +304 -0
  32. data/lib/scout/llm/agent/delegate.rb +56 -238
  33. data/lib/scout/llm/agent/path/edit.rb +230 -0
  34. data/lib/scout/llm/agent/path/patch.rb +252 -0
  35. data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
  36. data/lib/scout/llm/agent/path.rb +1777 -0
  37. data/lib/scout/llm/agent/save.rb +11 -9
  38. data/lib/scout/llm/agent/workflow.rb +79 -17
  39. data/lib/scout/llm/agent.rb +151 -27
  40. data/lib/scout/llm/ask.rb +37 -27
  41. data/lib/scout/llm/backends/anthropic.rb +1 -1
  42. data/lib/scout/llm/backends/bedrock.rb +3 -2
  43. data/lib/scout/llm/backends/default.rb +131 -32
  44. data/lib/scout/llm/backends/glm.rb +28 -1
  45. data/lib/scout/llm/backends/huggingface.rb +1 -1
  46. data/lib/scout/llm/backends/ollama.rb +1 -1
  47. data/lib/scout/llm/backends/openai.rb +7 -6
  48. data/lib/scout/llm/backends/openwebui.rb +14 -7
  49. data/lib/scout/llm/backends/relay.rb +8 -2
  50. data/lib/scout/llm/chat/agent_meta.rb +24 -60
  51. data/lib/scout/llm/chat/parse.rb +1 -1
  52. data/lib/scout/llm/chat/process/files.rb +10 -0
  53. data/lib/scout/llm/chat/process/meta.rb +5 -7
  54. data/lib/scout/llm/chat/process/tools.rb +104 -52
  55. data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
  56. data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
  57. data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
  58. data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
  59. data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
  60. data/lib/scout/llm/chat/prompt.rb +24 -10
  61. data/lib/scout/llm/chat/provenance/live.rb +1080 -0
  62. data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
  63. data/lib/scout/llm/chat/provenance.rb +352 -626
  64. data/lib/scout/llm/chat.rb +8 -2
  65. data/lib/scout/llm/embed.rb +15 -3
  66. data/lib/scout/llm/image.rb +4 -1
  67. data/lib/scout/llm/mcp.rb +4 -2
  68. data/lib/scout/llm/request_context.rb +234 -0
  69. data/lib/scout/llm/sandbox.rb +263 -0
  70. data/lib/scout/llm/tools/call.rb +163 -42
  71. data/lib/scout/llm/tools/definition.rb +48 -0
  72. data/lib/scout/llm/tools/knowledge_base.rb +1 -0
  73. data/lib/scout/llm/tools/mcp.rb +50 -43
  74. data/lib/scout/llm/tools/workflow.rb +90 -20
  75. data/lib/scout/llm/tools.rb +14 -41
  76. data/lib/scout/model/decision/base.rb +43 -0
  77. data/lib/scout/model/decision/jev.rb +161 -0
  78. data/lib/scout/model/python/torch.rb +1 -1
  79. data/research/clear-tools-inherit.md +171 -0
  80. data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
  81. data/research/path-kind-chat-role.md +96 -0
  82. data/research/path-kind-contract-fixes-engine.md +307 -0
  83. data/research/scout-ai-runtime-availability.md +65 -0
  84. data/research/subsys/README.md +127 -0
  85. data/research/subsys/agent-delegation.md +201 -0
  86. data/research/subsys/agent-society.md +275 -0
  87. data/research/subsys/agentworkflow.md +233 -0
  88. data/research/subsys/backends.md +221 -0
  89. data/research/subsys/chat.md +314 -0
  90. data/research/subsys/embed-image.md +244 -0
  91. data/research/subsys/entry-cli.md +253 -0
  92. data/research/subsys/model-ml.md +326 -0
  93. data/research/subsys/provenance.md +290 -0
  94. data/research/subsys/tools.md +334 -0
  95. data/scout-ai.gemspec +72 -26
  96. data/scout_commands/agent/ask +8 -7
  97. data/scout_commands/llm/abridged +40 -0
  98. data/scout_commands/llm/ask +9 -9
  99. data/scout_commands/llm/md +2 -0
  100. data/scout_commands/llm/prov +845 -80
  101. data/scout_commands/llm/word +4 -0
  102. data/share/word/reference.docx +0 -0
  103. data/test/integration/scout/model/decision/test_jev.rb +144 -0
  104. data/test/scout/llm/agent/test_attach.rb +117 -0
  105. data/test/scout/llm/agent/test_conversation.rb +407 -0
  106. data/test/scout/llm/agent/test_delegate.rb +209 -0
  107. data/test/scout/llm/agent/test_path.rb +1812 -0
  108. data/test/scout/llm/agent/test_path_edit.rb +908 -0
  109. data/test/scout/llm/agent/test_path_errors.rb +390 -0
  110. data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
  111. data/test/scout/llm/agent/test_path_patch.rb +233 -0
  112. data/test/scout/llm/agent/test_path_promotion.rb +386 -0
  113. data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
  114. data/test/scout/llm/agent/test_save.rb +70 -15
  115. data/test/scout/llm/agent/test_workflow.rb +130 -4
  116. data/test/scout/llm/backends/test_anthropic.rb +4 -4
  117. data/test/scout/llm/backends/test_bedrock.rb +4 -4
  118. data/test/scout/llm/backends/test_format_other.rb +43 -0
  119. data/test/scout/llm/backends/test_ollama.rb +2 -2
  120. data/test/scout/llm/backends/test_openwebui.rb +12 -8
  121. data/test/scout/llm/backends/test_reasoning.rb +114 -0
  122. data/test/scout/llm/chat/agent_meta_fixtures.rb +109 -22
  123. data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
  124. data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
  125. data/test/scout/llm/chat/test_agent_meta.rb +40 -80
  126. data/test/scout/llm/chat/test_agent_meta_provenance.rb +200 -28
  127. data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
  128. data/test/scout/llm/chat/test_agent_view.rb +178 -0
  129. data/test/scout/llm/chat/test_live_report.rb +282 -0
  130. data/test/scout/llm/chat/test_live_workload.rb +193 -0
  131. data/test/scout/llm/chat/test_parse.rb +32 -2
  132. data/test/scout/llm/chat/test_prompt.rb +411 -0
  133. data/test/scout/llm/chat/test_prov_cli.rb +708 -13
  134. data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
  135. data/test/scout/llm/chat/test_prov_plot.rb +213 -0
  136. data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
  137. data/test/scout/llm/chat/test_provenance.rb +67 -22
  138. data/test/scout/llm/chat/test_provenance_index.rb +479 -0
  139. data/test/scout/llm/chat/test_society_view.rb +159 -0
  140. data/test/scout/llm/test_agent.rb +1 -1
  141. data/test/scout/llm/test_embed.rb +103 -1
  142. data/test/scout/llm/test_request_context.rb +299 -0
  143. data/test/scout/llm/test_sandbox.rb +249 -0
  144. data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
  145. data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
  146. data/test/scout/llm/tools/test_definition.rb +332 -0
  147. data/test/scout/llm/tools/test_jobs_file.rb +211 -0
  148. data/test/scout/llm/tools/test_mcp.rb +37 -8
  149. data/test/scout/llm/tools/test_workflow.rb +45 -1
  150. data/test/scout/model/decision/test_jev.rb +453 -0
  151. data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
  152. data/test/scout/model/python/huggingface/test_causal.rb +11 -2
  153. data/test/scout/model/python/huggingface/test_classification.rb +5 -3
  154. data/test/scout/model/python/test_availability.rb +116 -0
  155. data/test/scout/model/python/test_torch.rb +54 -2
  156. data/test/support/availability.rb +72 -174
  157. data/test/support/fake_clients.rb +18 -9
  158. data/test/support/fixtures.rb +75 -6
  159. data/test/support/mock_backend.rb +9 -1
  160. data/test/support/test_fixtures.rb +156 -0
  161. data/test/test_helper.rb +14 -4
  162. metadata +71 -25
  163. data/research/ChatAnalyst-required-changes.md +0 -167
  164. data/research/agent-delegation-analysis.md +0 -810
  165. data/research/agent-meta-provenance-integration-plan.md +0 -622
  166. data/research/agent-workflow-analysis.md +0 -1120
  167. data/research/backends-analysis.md +0 -836
  168. data/research/chat-core-analysis.md +0 -946
  169. data/research/chatanalyst-provenance/00-baseline.md +0 -30
  170. data/research/chatanalyst-provenance/01-repo-map.md +0 -60
  171. data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
  172. data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
  173. data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
  174. data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
  175. data/research/chatanalyst-provenance/07-critic-review.md +0 -25
  176. data/research/chatanalyst-provenance/final-report.md +0 -45
  177. data/research/chatanalyst-provenance/resumption.md +0 -37
  178. data/research/coding-philosophy-analysis.md +0 -928
  179. data/research/commands-analysis.md +0 -947
  180. data/research/multi-agent-patterns-analysis.md +0 -853
  181. data/research/prompt-strategies-analysis.md +0 -630
  182. data/research/prov-verbosity-fix-notes.md +0 -77
  183. data/research/provenance-analysis.md +0 -469
  184. data/research/synthesis-report.md +0 -487
  185. data/research/tools-system-analysis.md +0 -779
@@ -0,0 +1,453 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')
3
+
4
+ class TestDecisionJev < Test::Unit::TestCase
5
+
6
+ QUESTIONS = {
7
+ "supported" => {
8
+ "type" => "noul",
9
+ "instructions" => "Does the evidence support the claim?"
10
+ },
11
+
12
+ "interpretation" => {
13
+ "type" => "choice",
14
+ "instructions" => "How should the evidence be interpreted?",
15
+ "criteria" => {
16
+ "direct" => "Directly supports the claim",
17
+ "indirect" => "Supports the claim indirectly",
18
+ "contradictory" => "Provides evidence against the claim",
19
+ "unclear" => "The evidence is insufficient"
20
+ }
21
+ }
22
+ }.freeze
23
+
24
+ STATE = {
25
+ "claim" => "The treatment inhibits pathway X",
26
+ "evidence" => [
27
+ "Expression of X decreased after treatment",
28
+ "The effect was observed in three replicates"
29
+ ]
30
+ }.freeze
31
+
32
+ class FakeClient
33
+ attr_reader :calls
34
+
35
+ def initialize(response)
36
+ @response = response
37
+ @calls = []
38
+ end
39
+
40
+ def evaluate(**arguments)
41
+ @calls << arguments
42
+ @response
43
+ end
44
+ end
45
+
46
+ def test_eval_delegates_to_client
47
+ response = {
48
+ "model" => "jev-1.13.0",
49
+ "answers" => {
50
+ "supported" => {
51
+ "type" => "noul",
52
+ "noul" => 0.92
53
+ },
54
+
55
+ "interpretation" => {
56
+ "type" => "choice",
57
+ "choice" => "indirect",
58
+ "probabilities" => {
59
+ "direct" => 0.15,
60
+ "indirect" => 0.70,
61
+ "contradictory" => 0.03,
62
+ "unclear" => 0.12
63
+ },
64
+ "confidence" => 0.70
65
+ }
66
+ },
67
+
68
+ "usage" => {
69
+ "input_tokens" => 100,
70
+ "output_tokens" => 20
71
+ }
72
+ }
73
+
74
+ client = FakeClient.new(response)
75
+
76
+ decision = Decision::Jev.new(
77
+ client: client,
78
+ model: "jev-1.13.0",
79
+ questions: QUESTIONS
80
+ )
81
+
82
+ result = decision.eval(STATE)
83
+
84
+ assert_equal 1, client.calls.length
85
+
86
+ call = client.calls.first
87
+
88
+ assert_equal "jev-1.13.0", call[:model]
89
+ assert_equal STATE, call[:state]
90
+ assert_equal QUESTIONS, call[:questions]
91
+
92
+ assert_equal response, result.value
93
+ end
94
+
95
+ def test_eval_list_evaluates_each_input
96
+ responses = [
97
+ { "answers" => { "supported" => { "noul" => 0.9 } } },
98
+ { "answers" => { "supported" => { "noul" => 0.2 } } }
99
+ ]
100
+
101
+ client = Class.new do
102
+ attr_reader :calls
103
+
104
+ def initialize(responses)
105
+ @responses = responses
106
+ @calls = []
107
+ end
108
+
109
+ def evaluate(**arguments)
110
+ @calls << arguments
111
+ @responses.shift
112
+ end
113
+ end.new(responses)
114
+
115
+ decision = Decision::Jev.new(
116
+ client: client,
117
+ model: "jev-1.13.0",
118
+ questions: QUESTIONS
119
+ )
120
+
121
+ inputs = [
122
+ { "id" => 1 },
123
+ { "id" => 2 }
124
+ ]
125
+
126
+ results = decision.eval_list(inputs)
127
+
128
+ assert_equal 2, results.length
129
+ assert_equal inputs, client.calls.map { |call| call[:state] }
130
+
131
+ assert_equal 0.9,
132
+ results[0].value.dig("answers", "supported", "noul")
133
+
134
+ assert_equal 0.2,
135
+ results[1].value.dig("answers", "supported", "noul")
136
+ end
137
+
138
+ def test_model_defaults_to_latest
139
+ client = FakeClient.new({})
140
+
141
+ decision = Decision::Jev.new(
142
+ client: client,
143
+ questions: QUESTIONS
144
+ )
145
+
146
+ decision.eval(STATE)
147
+
148
+ assert_equal "jev-latest", client.calls.first[:model]
149
+ end
150
+
151
+
152
+ # ------------------------------------------------------------------
153
+ # Client tests
154
+ # ------------------------------------------------------------------
155
+
156
+ FakeResponse = Struct.new(:code, :body, :headers) do
157
+ def [](name)
158
+ headers[name]
159
+ end
160
+ end
161
+
162
+ class FakeHTTP
163
+ attr_accessor :open_timeout, :read_timeout
164
+ attr_reader :requests
165
+
166
+ def initialize(*responses)
167
+ @responses = responses
168
+ @requests = []
169
+ end
170
+
171
+ def request(request)
172
+ @requests << request
173
+ response = @responses.shift
174
+
175
+ raise "No fake response configured" unless response
176
+
177
+ response
178
+ end
179
+ end
180
+
181
+ def fake_response(code, body, headers = {})
182
+ FakeResponse.new(
183
+ code.to_s,
184
+ body,
185
+ headers
186
+ )
187
+ end
188
+
189
+ def test_client_sends_correct_request
190
+ response_body = JSON.generate(
191
+ "model" => "jev-1.13.0",
192
+ "answers" => {
193
+ "supported" => {
194
+ "type" => "noul",
195
+ "noul" => 0.91
196
+ }
197
+ },
198
+ "usage" => {
199
+ "input_tokens" => 100,
200
+ "output_tokens" => 10
201
+ }
202
+ )
203
+
204
+ http = FakeHTTP.new(
205
+ fake_response(200, response_body)
206
+ )
207
+
208
+ client = Decision::Jev::Client.new(
209
+ api_key: "test-key",
210
+ http_factory: ->(_uri) { http }
211
+ )
212
+
213
+ result = client.evaluate(
214
+ model: "jev-1.13.0",
215
+ state: STATE,
216
+ questions: QUESTIONS
217
+ )
218
+
219
+ assert_equal "jev-1.13.0", result["model"]
220
+ assert_equal 0.91,
221
+ result.dig("answers", "supported", "noul")
222
+
223
+ assert_equal 1, http.requests.length
224
+
225
+ request = http.requests.first
226
+
227
+ assert_equal "Bearer test-key", request["Authorization"]
228
+ assert_equal "application/json", request["Content-Type"]
229
+ assert_equal "application/json", request["Accept"]
230
+
231
+ body = JSON.parse(request.body)
232
+
233
+ assert_equal "jev-1.13.0", body["model"]
234
+ assert_equal STATE, body["state"]
235
+ assert_equal QUESTIONS, body["questions"]
236
+ end
237
+
238
+ def test_client_retries_rate_limit
239
+ response_body = JSON.generate(
240
+ "model" => "jev-1.13.0",
241
+ "answers" => {},
242
+ "usage" => {
243
+ "input_tokens" => 1,
244
+ "output_tokens" => 1
245
+ }
246
+ )
247
+
248
+ http = FakeHTTP.new(
249
+ fake_response(429, '{"error":"rate limit"}'),
250
+ fake_response(200, response_body)
251
+ )
252
+
253
+ sleeps = []
254
+
255
+ client = Decision::Jev::Client.new(
256
+ api_key: "test-key",
257
+ http_factory: ->(_uri) { http },
258
+ sleeper: ->(seconds) { sleeps << seconds }
259
+ )
260
+
261
+ result = client.evaluate(
262
+ state: "hello",
263
+ model: "jev-1.13.0",
264
+ questions: {
265
+ "x" => {
266
+ "type" => "noul",
267
+ "instructions" => "Is this true?"
268
+ }
269
+ }
270
+ )
271
+
272
+ assert_equal "jev-1.13.0", result["model"]
273
+ assert_equal 2, http.requests.length
274
+ assert_equal [0.25], sleeps
275
+ end
276
+
277
+ def test_client_honors_retry_after
278
+ response_body = JSON.generate(
279
+ "model" => "jev-1.13.0",
280
+ "answers" => {},
281
+ "usage" => {
282
+ "input_tokens" => 1,
283
+ "output_tokens" => 1
284
+ }
285
+ )
286
+
287
+ http = FakeHTTP.new(
288
+ fake_response(
289
+ 429,
290
+ '{"error":"rate limit"}',
291
+ "Retry-After" => "3"
292
+ ),
293
+ fake_response(200, response_body)
294
+ )
295
+
296
+ sleeps = []
297
+
298
+ client = Decision::Jev::Client.new(
299
+ api_key: "test-key",
300
+ http_factory: ->(_uri) { http },
301
+ sleeper: ->(seconds) { sleeps << seconds }
302
+ )
303
+
304
+ client.evaluate(
305
+ model: "jev-1.13.0",
306
+ state: "hello",
307
+ questions: {
308
+ "x" => {
309
+ "type" => "noul",
310
+ "instructions" => "Is this true?"
311
+ }
312
+ }
313
+ )
314
+
315
+ assert_equal [3.0], sleeps
316
+ assert_equal 2, http.requests.length
317
+ end
318
+
319
+ def test_client_retries_529
320
+ response_body = JSON.generate(
321
+ "model" => "jev-1.13.0",
322
+ "answers" => {},
323
+ "usage" => {
324
+ "input_tokens" => 1,
325
+ "output_tokens" => 1
326
+ }
327
+ )
328
+
329
+ http = FakeHTTP.new(
330
+ fake_response(529, '{"error":"overloaded"}'),
331
+ fake_response(200, response_body)
332
+ )
333
+
334
+ sleeps = []
335
+
336
+ client = Decision::Jev::Client.new(
337
+ api_key: "test-key",
338
+ http_factory: ->(_uri) { http },
339
+ sleeper: ->(seconds) { sleeps << seconds }
340
+ )
341
+
342
+ result = client.evaluate(
343
+ model: "jev-1.13.0",
344
+ state: "hello",
345
+ questions: {
346
+ "x" => {
347
+ "type" => "noul",
348
+ "instructions" => "Is this true?"
349
+ }
350
+ }
351
+ )
352
+
353
+ assert_equal "jev-1.13.0", result["model"]
354
+ assert_equal 2, http.requests.length
355
+ end
356
+
357
+ def test_client_raises_after_max_retries
358
+ http = FakeHTTP.new(
359
+ fake_response(529, '{"error":"overloaded"}'),
360
+ fake_response(529, '{"error":"overloaded"}'),
361
+ fake_response(529, '{"error":"overloaded"}')
362
+ )
363
+
364
+ client = Decision::Jev::Client.new(
365
+ api_key: "test-key",
366
+ max_retries: 2,
367
+ http_factory: ->(_uri) { http },
368
+ sleeper: ->(_seconds) {}
369
+ )
370
+
371
+ error = assert_raise(Decision::Jev::Error) do
372
+ client.evaluate(
373
+ model: "jev-1.13.0",
374
+ state: "hello",
375
+ questions: {
376
+ "x" => {
377
+ "type" => "noul",
378
+ "instructions" => "Is this true?"
379
+ }
380
+ }
381
+ )
382
+ end
383
+
384
+ assert_equal 529, error.status
385
+ assert_equal 3, http.requests.length
386
+ end
387
+
388
+ def test_client_does_not_retry_normal_errors
389
+ http = FakeHTTP.new(
390
+ fake_response(400, '{"error":"bad request"}')
391
+ )
392
+
393
+ sleeps = []
394
+
395
+ client = Decision::Jev::Client.new(
396
+ api_key: "test-key",
397
+ http_factory: ->(_uri) { http },
398
+ sleeper: ->(seconds) { sleeps << seconds }
399
+ )
400
+
401
+ error = assert_raise(Decision::Jev::Error) do
402
+ client.evaluate(
403
+ model: "jev-1.13.0",
404
+ state: "hello",
405
+ questions: {
406
+ "x" => {
407
+ "type" => "noul",
408
+ "instructions" => "Is this true?"
409
+ }
410
+ }
411
+ )
412
+ end
413
+
414
+ assert_equal 400, error.status
415
+ assert_empty sleeps
416
+ assert_equal 1, http.requests.length
417
+ end
418
+
419
+ def test_client_detects_invalid_json
420
+ http = FakeHTTP.new(
421
+ fake_response(200, "not json")
422
+ )
423
+
424
+ client = Decision::Jev::Client.new(
425
+ api_key: "test-key",
426
+ http_factory: ->(_uri) { http }
427
+ )
428
+
429
+ error = assert_raise(Decision::Jev::Error) do
430
+ client.evaluate(
431
+ model: "jev-1.13.0",
432
+ state: "hello",
433
+ questions: {
434
+ "x" => {
435
+ "type" => "noul",
436
+ "instructions" => "Is this true?"
437
+ }
438
+ }
439
+ )
440
+ end
441
+
442
+ assert_equal 200, error.status
443
+ end
444
+
445
+ def test_client_requires_api_key
446
+ assert_raise(Decision::Jev::Error) do
447
+ Decision::Jev::Client.new(
448
+ api_key: nil
449
+ )
450
+ end
451
+ end
452
+ end
453
+
@@ -5,12 +5,15 @@ MODEL = 'distilgpt2'
5
5
 
6
6
  require 'scout-ai'
7
7
  class TestClass < Test::Unit::TestCase
8
- # Conditional omission: the local-cache probe never downloads; training
9
- # 1000 epochs also needs torch, which is probed the same bounded way.
8
+ # Conditional omission: modules first then local-cache probe (never
9
+ # downloads). model.init needs torch (TorchModel.init_python) and
10
+ # transformers (scout_ai.huggingface.model); training goes through
11
+ # scout_ai.huggingface.data and scout_ai.huggingface.train.next_token,
12
+ # which also import datasets.
10
13
  def test_main
11
- omit "huggingface model #{MODEL}: #{Availability.hf_model_reason(MODEL)}" unless Availability.hf_model_cached?(MODEL)
12
- reason = Availability.python_modules_reason('transformers')
14
+ reason = Availability.python_modules_reason('torch', 'transformers', 'datasets', route: :embedded)
13
15
  omit "python infrastructure missing: #{reason}" if reason
16
+ omit "huggingface model #{MODEL}: #{Availability.hf_model_reason(MODEL)}" unless Availability.hf_model_cached?(MODEL)
14
17
 
15
18
  model = NextTokenModel.new
16
19
  train_texts = [
@@ -22,12 +25,10 @@ class TestClass < Test::Unit::TestCase
22
25
  ]
23
26
 
24
27
  TmpFile.with_path do |tmp_dir|
25
- iii tmp_dir
26
28
 
27
29
  sss 0
28
30
  model = NextTokenModel.new MODEL, tmp_dir, training_num_train_epochs: 1000, training_learning_rate: 0.1
29
31
 
30
- iii :new
31
32
  chat = Chat.setup []
32
33
  chat.user "say hi"
33
34
  ppp model.eval chat
@@ -35,18 +36,15 @@ class TestClass < Test::Unit::TestCase
35
36
  model.save
36
37
  model = PythonModel.new tmp_dir
37
38
 
38
- iii :load
39
39
  chat = Chat.setup []
40
40
  chat.user "say hi"
41
41
  ppp model.eval chat
42
42
 
43
- iii :training
44
43
  state, tokenizer = model.init
45
44
  tokenizer.pad_token = tokenizer.eos_token
46
45
  model.add_list train_texts.shuffle
47
46
  model.train
48
47
 
49
- iii :trained
50
48
  chat = Chat.setup []
51
49
  chat.user "say hi"
52
50
  ppp model.eval chat
@@ -54,7 +52,6 @@ class TestClass < Test::Unit::TestCase
54
52
  model.save
55
53
  model = PythonModel.new tmp_dir
56
54
 
57
- iii :load_again
58
55
  chat = Chat.setup []
59
56
  chat.user "say hi"
60
57
  ppp model.eval chat
@@ -4,10 +4,17 @@ require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1
4
4
  class TestClass < Test::Unit::TestCase
5
5
  MODEL = 'mistralai/Mistral-7B-Instruct-v0.3'
6
6
 
7
- # Conditional omission: runs only when the model is already in the local
8
- # huggingface cache. The probe never downloads (see
7
+ # Conditional omission, modules first then cache (sibling style, see
8
+ # test_classification.rb): model.init runs TorchModel.init_python, which
9
+ # imports torch into the embedded PyCall interpreter
10
+ # (lib/scout/model/python/torch/helpers.rb), and
11
+ # scout_ai.huggingface.model.load_model/load_tokenizer import transformers
12
+ # dynamically (python/scout_ai/huggingface/model.py). The causal eval path
13
+ # does NOT import datasets. Neither probe downloads anything (see
9
14
  # test/support/availability.rb).
10
15
  def test_eval_chat
16
+ reason = Availability.python_modules_reason('torch', 'transformers', route: :embedded)
17
+ omit "python infrastructure missing: #{reason}" if reason
11
18
  omit "huggingface model #{MODEL}: #{Availability.hf_model_reason(MODEL)}" unless Availability.hf_model_cached?(MODEL)
12
19
  #model = CausalModel.new 'BSC-LT/salamandra-2b-instruct'
13
20
  model = CausalModel.new MODEL
@@ -23,6 +30,8 @@ class TestClass < Test::Unit::TestCase
23
30
  end
24
31
 
25
32
  def test_eval_train
33
+ reason = Availability.python_modules_reason('torch', 'transformers', route: :embedded)
34
+ omit "python infrastructure missing: #{reason}" if reason
26
35
  omit "huggingface model #{MODEL}: #{Availability.hf_model_reason(MODEL)}" unless Availability.hf_model_cached?(MODEL)
27
36
  #model = CausalModel.new 'BSC-LT/salamandra-2b-instruct'
28
37
  model = CausalModel.new MODEL
@@ -13,10 +13,12 @@ class TestSequenceClassification < Test::Unit::TestCase
13
13
  end
14
14
 
15
15
  # Conditional omission: the probe only checks the local huggingface cache
16
- # (never downloads) and that transformers/datasets are importable, so this
17
- # runs whenever the environment can actually serve it.
16
+ # (never downloads) and that torch/transformers/datasets are importable, so
17
+ # this runs whenever the environment can actually serve it. torch comes from
18
+ # TorchModel.init_python (model.init), transformers from
19
+ # scout_ai.huggingface.model, datasets from the training path.
18
20
  def test_train_sequence_classification
19
- reason = Availability.python_modules_reason('transformers', 'datasets')
21
+ reason = Availability.python_modules_reason('torch', 'transformers', 'datasets', route: :embedded)
20
22
  omit "python infrastructure missing: #{reason}" if reason
21
23
  omit "huggingface model #{MODEL}: #{Availability.hf_model_reason(MODEL)}" unless Availability.hf_model_cached?(MODEL)
22
24
 
@@ -0,0 +1,116 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require 'tmpdir'
3
+ require 'fileutils'
4
+
5
+ class TestAvailability < Test::Unit::TestCase
6
+ def test_python_helpers_delegate_default_and_embedded_routes_to_scout_rig
7
+ rig = ScoutRig::Testing::Availability
8
+ calls = []
9
+ originals = %i[python? python_modules? python_modules_reason].to_h { |name| [name, rig.method(name)] }
10
+ rig.define_singleton_method(:python?) { |**options| calls << [:python?, options]; true }
11
+ rig.define_singleton_method(:python_modules?) { |*modules, **options| calls << [:python_modules?, modules, options]; true }
12
+ rig.define_singleton_method(:python_modules_reason) { |*modules, **options| calls << [:python_modules_reason, modules, options]; nil }
13
+
14
+ assert Availability.python?(route: :embedded)
15
+ assert Availability.python?
16
+ assert Availability.python_modules?(:torch, route: :embedded)
17
+ assert_nil Availability.python_modules_reason('transformers', route: :embedded)
18
+ assert_equal [
19
+ [:python?, {route: :embedded}],
20
+ [:python?, {route: ScoutRig::Testing::Availability::DEFAULT_ROUTE}],
21
+ [:python_modules?, [:torch], {route: :embedded}],
22
+ [:python_modules_reason, ['transformers'], {route: :embedded}]
23
+ ], calls
24
+ ensure
25
+ originals&.each { |name, method| rig.define_singleton_method(name, method) }
26
+ end
27
+
28
+ def test_huggingface_cache_checks_hf_hub_cache_and_hf_home_without_download
29
+ Dir.mktmpdir do |dir|
30
+ old_home, old_hub = ENV['HF_HOME'], ENV['HF_HUB_CACHE']
31
+ ENV['HF_HOME'] = File.join(dir, 'home')
32
+ ENV.delete('HF_HUB_CACHE')
33
+ FileUtils.mkdir_p(File.join(ENV['HF_HOME'], 'hub', 'models--org--model', 'snapshots', 'revision'))
34
+ assert Availability.hf_model_cached?('org/model')
35
+
36
+ custom_hub = File.join(dir, 'custom-hub')
37
+ ENV['HF_HUB_CACHE'] = custom_hub
38
+ FileUtils.mkdir_p(File.join(custom_hub, 'models--other--model', 'snapshots', 'revision'))
39
+ assert Availability.hf_model_cached?('other/model')
40
+ assert_match(/not in local cache.*probing would download it/, Availability.hf_model_reason('missing/model'))
41
+ ensure
42
+ old_home.nil? ? ENV.delete('HF_HOME') : ENV['HF_HOME'] = old_home
43
+ old_hub.nil? ? ENV.delete('HF_HUB_CACHE') : ENV['HF_HUB_CACHE'] = old_hub
44
+ end
45
+ end
46
+
47
+ def test_r_package_reason_delegates_to_scout_rig
48
+ rig = ScoutRig::Testing::Availability
49
+ original = rig.method(:r_packages_reason)
50
+ rig.define_singleton_method(:r_packages_reason) { |*packages, **options| [packages, options] }
51
+ assert_equal [%w[e1071], {}], Availability.r_packages_reason('e1071')
52
+ ensure
53
+ rig.define_singleton_method(:r_packages_reason, original) if original
54
+ end
55
+
56
+ def test_endpoint_reachability_uses_tcp_primitive_not_http
57
+ path = Object.new
58
+ path.define_singleton_method(:exists?) { true }
59
+ path.define_singleton_method(:yaml) { {url: 'https://example.invalid:9443/v1'} }
60
+ original_path = Scout.method(:etc) if Scout.respond_to?(:etc)
61
+ original_tcp = Scout::Testing::Availability.method(:tcp_reachable?)
62
+ calls = []
63
+ endpoint = Object.new
64
+ endpoint.define_singleton_method(:find_with_extension) { |_extension| path }
65
+ ai = Object.new
66
+ ai.define_singleton_method(:[]) { |_key| endpoint }
67
+ etc = Object.new
68
+ etc.define_singleton_method(:AI) { ai }
69
+ Scout.define_singleton_method(:etc) { etc }
70
+ Scout::Testing::Availability.define_singleton_method(:tcp_reachable?) do |host, port, timeout:|
71
+ calls << [host, port, timeout]
72
+ true
73
+ end
74
+
75
+ assert Availability.endpoint_reachable?('example', 3)
76
+ assert_equal [['example.invalid', 9443, 3]], calls
77
+ ensure
78
+ if original_path
79
+ Scout.define_singleton_method(:etc, original_path)
80
+ elsif Scout.singleton_class.instance_methods(false).include?(:etc)
81
+ Scout.singleton_class.remove_method(:etc)
82
+ end
83
+ Scout::Testing::Availability.define_singleton_method(:tcp_reachable?, original_tcp) if original_tcp
84
+ end
85
+
86
+ def test_local_mock_endpoint_needs_no_network_probe
87
+ assert Availability.endpoint_configured?('mock')
88
+ assert Availability.endpoint_reachable?('mock')
89
+ assert_nil Availability.endpoint_reason('mock')
90
+ assert_not_include Availability.real_endpoints, 'mock'
91
+ end
92
+
93
+ def test_cuda_uses_embedded_python_and_generic_command_runner
94
+ rig = ScoutRig::Testing::Availability
95
+ generic = Scout::Testing::Availability
96
+ old_modules, old_embedded, old_runner = rig.method(:python_modules?), rig.method(:embedded_python), generic.method(:run_command)
97
+ calls = []
98
+ rig.define_singleton_method(:python_modules?) { |*modules, **options| calls << [:modules, modules, options]; true }
99
+ rig.define_singleton_method(:embedded_python) { '/test/python' }
100
+ generic.define_singleton_method(:run_command) do |argv, timeout:|
101
+ calls << [:run, argv, timeout]
102
+ result = Object.new
103
+ result.define_singleton_method(:success?) { true }
104
+ result.define_singleton_method(:exit_status) { 0 }
105
+ result
106
+ end
107
+
108
+ assert Availability.cuda?
109
+ assert_equal [:modules, [:torch], {route: :embedded}], calls[0]
110
+ assert_equal [:run, ['/test/python', '-c', 'import sys, torch; sys.exit(0 if torch.cuda.is_available() else 1)'], 30], calls[1]
111
+ ensure
112
+ rig.define_singleton_method(:python_modules?, old_modules) if old_modules
113
+ rig.define_singleton_method(:embedded_python, old_embedded) if old_embedded
114
+ generic.define_singleton_method(:run_command, old_runner) if old_runner
115
+ end
116
+ end