scout-ai 2.1.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 (186) hide show
  1. checksums.yaml +4 -4
  2. data/.vimproject +133 -58
  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 +319 -33
  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 +388 -40
  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 +13 -17
  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 +77 -16
  39. data/lib/scout/llm/agent.rb +147 -31
  40. data/lib/scout/llm/ask.rb +28 -17
  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 +127 -34
  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 -49
  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 +343 -676
  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 +71 -27
  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 +724 -59
  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 +28 -27
  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 +67 -28
  127. data/test/scout/llm/chat/test_agent_meta_tokens.rb +59 -8
  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 +310 -15
  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 +70 -26
  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/provenance-continuation-accounting.md +0 -255
  185. data/research/synthesis-report.md +0 -487
  186. data/research/tools-system-analysis.md +0 -779
@@ -0,0 +1,390 @@
1
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
2
+ require File.expand_path(__FILE__).sub(%r(/test/.*), '/lib/scout/llm/agent/path.rb')
3
+
4
+ require "tmpdir"
5
+
6
+ class TestPathErrors < Test::Unit::TestCase
7
+ def setup
8
+ @tmpdir = Scout.tmp.agent_path_test.find
9
+ FileUtils.mkdir_p(@tmpdir)
10
+ @agent = LLM.agent
11
+ end
12
+
13
+ def teardown
14
+ FileUtils.remove_entry(@tmpdir) if @tmpdir && File.exist?(@tmpdir)
15
+ end
16
+
17
+ def register_text_kind(name = "text", capabilities = {})
18
+ @agent.register_path_kind(
19
+ name,
20
+ "description" => "Test text paths",
21
+ "locations" => ["project", "tmp"],
22
+ "default_location" => "project",
23
+ "roots" => {
24
+ "project" => @tmpdir,
25
+ "tmp" => File.join(@tmpdir, "tmp")
26
+ },
27
+ "capabilities" => capabilities
28
+ )
29
+ end
30
+
31
+ def test_path_delete_missing_file_raises_parameter_exception
32
+ register_text_kind
33
+
34
+ error = assert_raise(ParameterException) do
35
+ @agent.path_delete(
36
+ "kind" => "text",
37
+ "path" => "ghost.txt"
38
+ )
39
+ end
40
+
41
+ assert_match(/Path does not exist or is not readable/, error.message)
42
+ assert_match(/ghost\.txt/, error.message)
43
+ end
44
+
45
+ # Review point 4: the serialized error through the agent-facing tool
46
+ # callable must be ParameterException, with no raw Errno::ENOENT escape.
47
+ def test_path_delete_missing_file_through_tool_callable
48
+ register_text_kind
49
+
50
+ tools = @agent.instance_variable_get(:@other_options)[:tools]
51
+
52
+ result = JSON.parse(
53
+ tools["path_delete"].first.call(
54
+ "path_delete",
55
+ {"kind" => "text", "path" => "ghost.txt"}
56
+ )
57
+ )
58
+
59
+ # Serialized ParameterException message, not a raw Errno::ENOENT escape.
60
+ assert_match(/Path does not exist or is not readable/, result["exception"])
61
+ assert_match(/ghost\.txt/, result["exception"])
62
+ assert result.key?("exception_line")
63
+ end
64
+
65
+ # Review point 4 control: the ENOENT normalization must not change the
66
+ # happy path. Deleting an existing file still works and the file is gone.
67
+ def test_path_delete_existing_file_still_deletes_after_enoent_normalization
68
+ register_text_kind
69
+
70
+ @agent.path_write(
71
+ "kind" => "text",
72
+ "path" => "present.txt",
73
+ "content" => "bye"
74
+ )
75
+
76
+ assert File.exist?(File.join(@tmpdir, "present.txt"))
77
+
78
+ result = @agent.path_delete(
79
+ "kind" => "text",
80
+ "path" => "present.txt"
81
+ )
82
+
83
+ assert_equal true, result["deleted"]
84
+ assert !File.exist?(File.join(@tmpdir, "present.txt"))
85
+ end
86
+
87
+ def test_error_matrix_unknown_kind
88
+ error = assert_raise(ParameterException) do
89
+ @agent.path_read("kind" => "nope", "path" => "hello.txt")
90
+ end
91
+ assert_match(/Unknown path kind: nope/, error.message)
92
+ end
93
+
94
+ def test_error_matrix_unknown_location
95
+ register_text_kind
96
+ error = assert_raise(ParameterException) do
97
+ @agent.resolve_path("text", "hello.txt", "missing")
98
+ end
99
+ assert_match(/Location "missing" is not supported by path kind text/, error.message)
100
+ end
101
+
102
+ def test_error_matrix_location_without_configured_root_is_rejected_at_registration
103
+ error = assert_raise(ParameterException) do
104
+ @agent.register_path_kind(
105
+ "orphan", "locations" => ["tmp", "custom"], "default_location" => "tmp",
106
+ "roots" => {"tmp" => @tmpdir}
107
+ )
108
+ end
109
+ assert_match(/no root configured for location custom/i, error.message)
110
+ assert_false @agent.path_kind_registry.key?("orphan")
111
+ assert_equal({}, @agent.instance_variable_get(:@other_options))
112
+ end
113
+
114
+ def test_error_matrix_missing_required_argument
115
+ register_text_kind
116
+ error = assert_raise(ParameterException) do
117
+ @agent.path_read("kind" => "text")
118
+ end
119
+ assert_match(/Missing required argument "path"/, error.message)
120
+
121
+ error = assert_raise(ParameterException) do
122
+ @agent.path_write("kind" => "text", "path" => "hello.txt")
123
+ end
124
+ assert_match(/Missing required argument "content"/, error.message)
125
+
126
+ error = assert_raise(ParameterException) do
127
+ @agent.path_edit("kind" => "text", "path" => "hello.txt")
128
+ end
129
+ assert_match(/Missing required argument "selector"/, error.message)
130
+
131
+ error = assert_raise(ParameterException) do
132
+ @agent.path_move("kind" => "text", "path" => "hello.txt")
133
+ end
134
+ assert_match(/Missing required argument "destination"/, error.message)
135
+
136
+ error = assert_raise(ParameterException) do
137
+ @agent.path_rename("kind" => "text", "path" => "hello.txt")
138
+ end
139
+ assert_match(/Missing required argument "name"/, error.message)
140
+ end
141
+
142
+ def test_error_matrix_invalid_selector
143
+ register_text_kind
144
+
145
+ error = assert_raise(ParameterException) do
146
+ @agent.path_apply_selector("hello world", {"type" => "unknown"}, "x")
147
+ end
148
+ assert_match(/Unknown selector type "unknown"/, error.message)
149
+
150
+ error = assert_raise(ParameterException) do
151
+ @agent.path_apply_selector("hello world", {"start" => 1, "end" => 2}, "x")
152
+ end
153
+ assert_match(/Invalid selector: missing key "type"/, error.message)
154
+
155
+ error = assert_raise(ParameterException) do
156
+ @agent.path_apply_selector("hello world", nil, "x")
157
+ end
158
+ assert_match(/Invalid selector: expected a mapping/, error.message)
159
+
160
+ error = assert_raise(ParameterException) do
161
+ @agent.path_apply_selector("hello world", {"type" => "lines"}, "x")
162
+ end
163
+ assert_match(/Invalid selector: missing key "start"/, error.message)
164
+
165
+ error = assert_raise(ParameterException) do
166
+ @agent.path_apply_selector("hello world", {"type" => "regexp"}, "x")
167
+ end
168
+ assert_match(/Invalid selector: missing key "pattern"/, error.message)
169
+ end
170
+
171
+ def test_error_matrix_malformed_selector_values_reject_and_never_mutate
172
+ register_text_kind
173
+ @agent.path_write(
174
+ "kind" => "text", "path" => "keep.txt", "content" => "a\nb\nc\n"
175
+ )
176
+ target = File.join(@tmpdir, "keep.txt")
177
+ before = File.read(target)
178
+
179
+ malformed = [
180
+ ["nil start", {"type" => "lines", "start" => nil, "end" => 1}],
181
+ ["nil end", {"type" => "lines", "start" => 0, "end" => nil}],
182
+ ["string start", {"type" => "lines", "start" => "1", "end" => 2}],
183
+ ["float start", {"type" => "lines", "start" => 1.5, "end" => 2}],
184
+ ["start beyond document", {"type" => "lines", "start" => 9, "end" => 10}],
185
+ ["start > end", {"type" => "lines", "start" => 2, "end" => 1}],
186
+ ["chars nil index", {"type" => "chars", "start" => nil, "end" => 2}],
187
+ ["chars string index", {"type" => "chars", "start" => "0", "end" => 2}],
188
+ ["chars out of range", {"type" => "chars", "start" => 99, "end" => 120}],
189
+ ["invalid regexp", {"type" => "regexp", "pattern" => "["}]
190
+ ]
191
+
192
+ malformed.each do |label, selector|
193
+ error = assert_raise(ParameterException) do
194
+ @agent.path_edit(
195
+ "kind" => "text", "path" => "keep.txt",
196
+ "selector" => selector, "replacement" => "z"
197
+ )
198
+ end
199
+ assert_equal "a\nb\nc\n", File.read(target),
200
+ "#{label}: file must stay byte-identical"
201
+ end
202
+
203
+ assert_equal before, File.read(target)
204
+ end
205
+
206
+ def test_error_matrix_path_outside_grant
207
+ register_text_kind
208
+ outside = Dir.mktmpdir("path-outside")
209
+ target = File.join(outside, "escape.txt")
210
+
211
+ error = assert_raise(ParameterException) do
212
+ @agent.path_write("kind" => "text", "path" => target, "content" => "no")
213
+ end
214
+ assert_equal "Path access denied by sandbox (outside_grants)", error.message
215
+ assert_false File.exist?(target)
216
+ ensure
217
+ FileUtils.remove_entry(outside) if outside && File.exist?(outside)
218
+ end
219
+
220
+ def test_error_matrix_unsupported_operation
221
+ register_text_kind("text", "validate" => false,
222
+ "promote" => false, "rename" => false)
223
+
224
+ error = assert_raise(ParameterException) do
225
+ @agent.path_validate("kind" => "text", "path" => "hello.txt")
226
+ end
227
+ assert_match(/Path kind text does not support validate/, error.message)
228
+
229
+ error = assert_raise(ParameterException) do
230
+ @agent.path_promote("kind" => "text", "path" => "hello.txt")
231
+ end
232
+ assert_match(/Path kind text does not support promote/, error.message)
233
+
234
+ error = assert_raise(ParameterException) do
235
+ @agent.path_rename("kind" => "text", "path" => "hello.txt", "name" => "x.txt")
236
+ end
237
+ assert_match(/Path kind text does not support rename/, error.message)
238
+ end
239
+
240
+ # ------------------------------------------------------------------
241
+ # Promotion (ENGINE-CONTROLLED)
242
+ #
243
+ # The engine resolves the destination from a declarative spec, authorizes
244
+ # BOTH endpoints, enforces no-clobber, and performs the move itself via
245
+ # path_move_target. A kind callback is never the writer. Optional
246
+ # post-move behavior hooks through "promotion_post_move". Every
247
+ # rejection case asserts that no filesystem mutation happened (source
248
+ # unchanged, destination absent).
249
+ # ------------------------------------------------------------------
250
+
251
+ # ------------------------------------------------------------------
252
+ # Root-selector grammar (fix 3) and path_kinds kind filter (fix 5)
253
+ #
254
+ # "", "." and "./" address the kind ROOT, never one file inside it.
255
+ # Every file-shaped built-in must reject them with a ParameterException
256
+ # that names the operation that received the value, points at path_list
257
+ # as the enumeration surface, and never leaks the junk target
258
+ # ("<root>/..rb") an extension-bearing kind would otherwise resolve to.
259
+ # path_list is not guarded (it normalizes the selector to the root
260
+ # listing) and path_dispatch is not guarded (custom operations own their
261
+ # path grammar); both contracts are pinned in test_path.rb.
262
+ # ------------------------------------------------------------------
263
+
264
+ # Extension-bearing by default, mimicking a task-like kind; pass
265
+ # extension: nil for the no-extension variant. validate and smoke get
266
+ # real implementations so the matrix exercises the path guard, not the
267
+ # "no implementation" raise that precedes it in path_kind_operation.
268
+ def register_root_selector_kind(name = "rbkind", extension: "rb")
269
+ definition = {
270
+ "description" => "Root-selector probe kind #{name}",
271
+ "locations" => ["project"],
272
+ "default_location" => "project",
273
+ "roots" => {"project" => File.join(@tmpdir, name)},
274
+ "capabilities" => {
275
+ "read" => true, "write" => true, "edit" => true,
276
+ "move" => true, "rename" => true, "delete" => true,
277
+ "validate" => true, "smoke" => true, "promote" => true,
278
+ "patch" => true
279
+ },
280
+ "validate" => ->(*) { {"ok" => true} },
281
+ "smoke" => ->(*) { {"ok" => true} }
282
+ }
283
+ definition["extension"] = extension unless extension.nil?
284
+
285
+ @agent.register_path_kind(name, definition)
286
+ FileUtils.mkdir_p(File.join(@tmpdir, name))
287
+ end
288
+
289
+ # One callable per file-shaped operation, with every OTHER argument
290
+ # filled in validly so the first path's rejection is the only thing the
291
+ # invocation can fail on.
292
+ def root_selector_invocations(kind, value)
293
+ {
294
+ "path_read" => -> { @agent.path_read("kind" => kind, "path" => value) },
295
+ "path_write" => -> { @agent.path_write("kind" => kind, "path" => value, "content" => "x") },
296
+ "path_patch" => -> { @agent.path_patch("kind" => kind, "path" => value, "patch" => "") },
297
+ "path_edit" => lambda {
298
+ @agent.path_edit(
299
+ "kind" => kind, "path" => value,
300
+ "selector" => {"type" => "lines", "start" => 1, "end" => 1},
301
+ "replacement" => "x"
302
+ )
303
+ },
304
+ "path_move" => -> { @agent.path_move("kind" => kind, "path" => value, "destination" => "dest") },
305
+ "path_rename" => -> { @agent.path_rename("kind" => kind, "path" => value, "name" => "newname") },
306
+ "path_delete" => -> { @agent.path_delete("kind" => kind, "path" => value) },
307
+ "path_validate" => -> { @agent.path_validate("kind" => kind, "path" => value) },
308
+ "path_smoke" => -> { @agent.path_smoke("kind" => kind, "path" => value) },
309
+ "path_promote" => -> { @agent.path_promote("kind" => kind, "path" => value) }
310
+ }
311
+ end
312
+
313
+ def test_error_matrix_root_selector_rejected_by_every_file_shaped_operation
314
+ # Extension-bearing and no-extension kinds must behave identically: the
315
+ # rejection is about the path grammar, not the kind's file naming.
316
+ {"rbkind" => "rb", "plainkind" => nil}.each do |kind, extension|
317
+ register_root_selector_kind(kind, extension: extension)
318
+
319
+ # "" and "." are pinned on every operation; "./" is the same root
320
+ # selector, pinned on one operation per kind so the matrix stays
321
+ # readable while still covering the spelling.
322
+ root_selector_invocations(kind, "./").slice("path_read").each do |operation, call|
323
+ error = assert_raise(ParameterException,
324
+ "#{kind} #{operation} './'") { call.call }
325
+ assert_match(/addresses the kind root/, error.message, "#{kind} #{operation} './'")
326
+ end
327
+
328
+ root_selector_invocations(kind, nil).keys.each do |operation|
329
+ ["", "."].each do |value|
330
+ call = root_selector_invocations(kind, value).fetch(operation)
331
+
332
+ error = assert_raise(ParameterException,
333
+ "#{kind} #{operation} #{value.inspect}") { call.call }
334
+
335
+ # The message names the operation that received the value and
336
+ # points at the enumeration surface.
337
+ assert_match(/Invalid path for #{operation}/, error.message,
338
+ "#{kind} #{operation} #{value.inspect}")
339
+ assert_match(/addresses the kind root/, error.message,
340
+ "#{kind} #{operation} #{value.inspect}")
341
+ assert_match(/path_list/, error.message,
342
+ "#{kind} #{operation} #{value.inspect}")
343
+ # The resolved junk target must never reach the caller.
344
+ assert_not_match(/\.\.rb/, error.message,
345
+ "#{kind} #{operation} #{value.inspect}")
346
+ end
347
+ end
348
+ end
349
+ end
350
+
351
+ def test_path_write_root_selector_creates_no_file
352
+ register_root_selector_kind("rbkind")
353
+ root = File.join(@tmpdir, "rbkind")
354
+
355
+ error = assert_raise(ParameterException) do
356
+ @agent.path_write("kind" => "rbkind", "path" => ".", "content" => "junk")
357
+ end
358
+ assert_match(/addresses the kind root/, error.message)
359
+
360
+ # Neither the "..rb" junk target a "." path used to produce, nor the
361
+ # empty-path variant, may appear on disk.
362
+ assert_false File.exist?(File.join(root, "..rb")),
363
+ "no junk ..rb file may be created by a rejected root selector"
364
+ assert_false File.exist?(File.join(root, ".rb")),
365
+ "no file may be created from an empty path"
366
+ assert_empty Dir.children(root).sort, "the kind root must stay empty"
367
+ end
368
+
369
+ def test_error_matrix_path_kinds_unknown_kind_lists_available_kinds
370
+ register_text_kind
371
+
372
+ error = assert_raise(ParameterException) do
373
+ @agent.path_kinds("kind" => "nope")
374
+ end
375
+
376
+ # Same lowercase spelling the rest of the error matrix pins.
377
+ assert_match(/Unknown path kind: nope/, error.message)
378
+ # The message names at least one kind that IS available.
379
+ assert_match(/available: .*text/, error.message)
380
+ end
381
+
382
+ # A nil or empty kind still enumerates everything: the filter is opt-in.
383
+ def test_error_matrix_path_kinds_empty_kind_returns_full_map
384
+ register_text_kind
385
+
386
+ assert @agent.path_kinds({"kind" => ""}).key?("text")
387
+ assert @agent.path_kinds({"kind" => nil}).key?("text")
388
+ end
389
+
390
+ end