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.
- checksums.yaml +4 -4
- data/.vimproject +135 -55
- data/README.md +2 -1
- data/VERSION +1 -1
- data/doc/Improvements.md +490 -148
- data/doc/Model.md +53 -10
- data/doc/StartHere.md +44 -19
- data/doc/developer/Architecture.md +25 -6
- data/doc/developer/Backends.md +207 -48
- data/doc/developer/ChatLifecycle.md +121 -20
- data/doc/developer/DelegationInternals.md +320 -34
- data/doc/developer/DesignPrinciples.md +205 -16
- data/doc/developer/PathEngine.md +628 -0
- data/doc/developer/PromptProcessing.md +332 -82
- data/doc/developer/Provenance.md +402 -44
- data/doc/developer/Sandbox.md +213 -0
- data/doc/user/BuildingAgents.md +130 -18
- data/doc/user/Cookbook.md +29 -8
- data/doc/user/CoreConcepts.md +7 -6
- data/doc/user/Delegation.md +166 -15
- data/doc/user/GettingStarted.md +20 -16
- data/doc/user/ManagingContext.md +155 -17
- data/doc/user/MultiAgentWorkflows.md +105 -15
- data/doc/user/Python.md +11 -1
- data/doc/user/RunningInference.md +90 -47
- data/doc/user/ToolCalling.md +134 -29
- data/doc/user/WritingChats.md +56 -27
- data/lib/scout/llm/agent/attach.rb +64 -0
- data/lib/scout/llm/agent/chat.rb +32 -0
- data/lib/scout/llm/agent/construction.rb +64 -0
- data/lib/scout/llm/agent/conversation.rb +304 -0
- data/lib/scout/llm/agent/delegate.rb +56 -238
- data/lib/scout/llm/agent/path/edit.rb +230 -0
- data/lib/scout/llm/agent/path/patch.rb +252 -0
- data/lib/scout/llm/agent/path/workflow_kinds.rb +175 -0
- data/lib/scout/llm/agent/path.rb +1777 -0
- data/lib/scout/llm/agent/save.rb +11 -9
- data/lib/scout/llm/agent/workflow.rb +79 -17
- data/lib/scout/llm/agent.rb +151 -27
- data/lib/scout/llm/ask.rb +37 -27
- data/lib/scout/llm/backends/anthropic.rb +1 -1
- data/lib/scout/llm/backends/bedrock.rb +3 -2
- data/lib/scout/llm/backends/default.rb +131 -32
- data/lib/scout/llm/backends/glm.rb +28 -1
- data/lib/scout/llm/backends/huggingface.rb +1 -1
- data/lib/scout/llm/backends/ollama.rb +1 -1
- data/lib/scout/llm/backends/openai.rb +7 -6
- data/lib/scout/llm/backends/openwebui.rb +14 -7
- data/lib/scout/llm/backends/relay.rb +8 -2
- data/lib/scout/llm/chat/agent_meta.rb +24 -60
- data/lib/scout/llm/chat/parse.rb +1 -1
- data/lib/scout/llm/chat/process/files.rb +10 -0
- data/lib/scout/llm/chat/process/meta.rb +5 -7
- data/lib/scout/llm/chat/process/tools.rb +104 -52
- data/lib/scout/llm/chat/prompt/epoch_tool_compactation.rb +355 -0
- data/lib/scout/llm/chat/prompt/inbox.rb +188 -0
- data/lib/scout/llm/chat/prompt/shorten_tools.rb +797 -13
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch.rb +1 -365
- data/lib/scout/llm/chat/prompt/shorten_tools_epoch_increment.rb +1 -0
- data/lib/scout/llm/chat/prompt.rb +24 -10
- data/lib/scout/llm/chat/provenance/live.rb +1080 -0
- data/lib/scout/llm/chat/provenance/tokens.rb +386 -0
- data/lib/scout/llm/chat/provenance.rb +352 -626
- data/lib/scout/llm/chat.rb +8 -2
- data/lib/scout/llm/embed.rb +15 -3
- data/lib/scout/llm/image.rb +4 -1
- data/lib/scout/llm/mcp.rb +4 -2
- data/lib/scout/llm/request_context.rb +234 -0
- data/lib/scout/llm/sandbox.rb +263 -0
- data/lib/scout/llm/tools/call.rb +163 -42
- data/lib/scout/llm/tools/definition.rb +48 -0
- data/lib/scout/llm/tools/knowledge_base.rb +1 -0
- data/lib/scout/llm/tools/mcp.rb +50 -43
- data/lib/scout/llm/tools/workflow.rb +90 -20
- data/lib/scout/llm/tools.rb +14 -41
- data/lib/scout/model/decision/base.rb +43 -0
- data/lib/scout/model/decision/jev.rb +161 -0
- data/lib/scout/model/python/torch.rb +1 -1
- data/research/clear-tools-inherit.md +171 -0
- data/research/path-engine-dc1-dc2-dc3-fixes.md +279 -0
- data/research/path-kind-chat-role.md +96 -0
- data/research/path-kind-contract-fixes-engine.md +307 -0
- data/research/scout-ai-runtime-availability.md +65 -0
- data/research/subsys/README.md +127 -0
- data/research/subsys/agent-delegation.md +201 -0
- data/research/subsys/agent-society.md +275 -0
- data/research/subsys/agentworkflow.md +233 -0
- data/research/subsys/backends.md +221 -0
- data/research/subsys/chat.md +314 -0
- data/research/subsys/embed-image.md +244 -0
- data/research/subsys/entry-cli.md +253 -0
- data/research/subsys/model-ml.md +326 -0
- data/research/subsys/provenance.md +290 -0
- data/research/subsys/tools.md +334 -0
- data/scout-ai.gemspec +72 -26
- data/scout_commands/agent/ask +8 -7
- data/scout_commands/llm/abridged +40 -0
- data/scout_commands/llm/ask +9 -9
- data/scout_commands/llm/md +2 -0
- data/scout_commands/llm/prov +845 -80
- data/scout_commands/llm/word +4 -0
- data/share/word/reference.docx +0 -0
- data/test/integration/scout/model/decision/test_jev.rb +144 -0
- data/test/scout/llm/agent/test_attach.rb +117 -0
- data/test/scout/llm/agent/test_conversation.rb +407 -0
- data/test/scout/llm/agent/test_delegate.rb +209 -0
- data/test/scout/llm/agent/test_path.rb +1812 -0
- data/test/scout/llm/agent/test_path_edit.rb +908 -0
- data/test/scout/llm/agent/test_path_errors.rb +390 -0
- data/test/scout/llm/agent/test_path_filesystem.rb +532 -0
- data/test/scout/llm/agent/test_path_patch.rb +233 -0
- data/test/scout/llm/agent/test_path_promotion.rb +386 -0
- data/test/scout/llm/agent/test_path_workflow_integration.rb +665 -0
- data/test/scout/llm/agent/test_save.rb +70 -15
- data/test/scout/llm/agent/test_workflow.rb +130 -4
- data/test/scout/llm/backends/test_anthropic.rb +4 -4
- data/test/scout/llm/backends/test_bedrock.rb +4 -4
- data/test/scout/llm/backends/test_format_other.rb +43 -0
- data/test/scout/llm/backends/test_ollama.rb +2 -2
- data/test/scout/llm/backends/test_openwebui.rb +12 -8
- data/test/scout/llm/backends/test_reasoning.rb +114 -0
- data/test/scout/llm/chat/agent_meta_fixtures.rb +109 -22
- data/test/scout/llm/chat/prompt/test_epoch_tool_compactation.rb +612 -0
- data/test/scout/llm/chat/prov_plot_fixtures.rb +131 -0
- data/test/scout/llm/chat/test_agent_meta.rb +40 -80
- data/test/scout/llm/chat/test_agent_meta_provenance.rb +200 -28
- data/test/scout/llm/chat/test_agent_meta_tokens.rb +112 -7
- data/test/scout/llm/chat/test_agent_view.rb +178 -0
- data/test/scout/llm/chat/test_live_report.rb +282 -0
- data/test/scout/llm/chat/test_live_workload.rb +193 -0
- data/test/scout/llm/chat/test_parse.rb +32 -2
- data/test/scout/llm/chat/test_prompt.rb +411 -0
- data/test/scout/llm/chat/test_prov_cli.rb +708 -13
- data/test/scout/llm/chat/test_prov_cli_live.rb +152 -0
- data/test/scout/llm/chat/test_prov_plot.rb +213 -0
- data/test/scout/llm/chat/test_prov_timeline.rb +355 -0
- data/test/scout/llm/chat/test_provenance.rb +67 -22
- data/test/scout/llm/chat/test_provenance_index.rb +479 -0
- data/test/scout/llm/chat/test_society_view.rb +159 -0
- data/test/scout/llm/test_agent.rb +1 -1
- data/test/scout/llm/test_embed.rb +103 -1
- data/test/scout/llm/test_request_context.rb +299 -0
- data/test/scout/llm/test_sandbox.rb +249 -0
- data/test/scout/llm/tools/test_agent_pairing.rb +150 -0
- data/test/scout/llm/tools/test_call_delegation_conflict.rb +316 -0
- data/test/scout/llm/tools/test_definition.rb +332 -0
- data/test/scout/llm/tools/test_jobs_file.rb +211 -0
- data/test/scout/llm/tools/test_mcp.rb +37 -8
- data/test/scout/llm/tools/test_workflow.rb +45 -1
- data/test/scout/model/decision/test_jev.rb +453 -0
- data/test/scout/model/python/huggingface/causal/test_next_token.rb +7 -10
- data/test/scout/model/python/huggingface/test_causal.rb +11 -2
- data/test/scout/model/python/huggingface/test_classification.rb +5 -3
- data/test/scout/model/python/test_availability.rb +116 -0
- data/test/scout/model/python/test_torch.rb +54 -2
- data/test/support/availability.rb +72 -174
- data/test/support/fake_clients.rb +18 -9
- data/test/support/fixtures.rb +75 -6
- data/test/support/mock_backend.rb +9 -1
- data/test/support/test_fixtures.rb +156 -0
- data/test/test_helper.rb +14 -4
- metadata +71 -25
- data/research/ChatAnalyst-required-changes.md +0 -167
- data/research/agent-delegation-analysis.md +0 -810
- data/research/agent-meta-provenance-integration-plan.md +0 -622
- data/research/agent-workflow-analysis.md +0 -1120
- data/research/backends-analysis.md +0 -836
- data/research/chat-core-analysis.md +0 -946
- data/research/chatanalyst-provenance/00-baseline.md +0 -30
- data/research/chatanalyst-provenance/01-repo-map.md +0 -60
- data/research/chatanalyst-provenance/02-event-reconstruction.md +0 -55
- data/research/chatanalyst-provenance/03-duplication-evidence.md +0 -45
- data/research/chatanalyst-provenance/04-tooling-root-cause.md +0 -57
- data/research/chatanalyst-provenance/05-fix-plan.md +0 -46
- data/research/chatanalyst-provenance/07-critic-review.md +0 -25
- data/research/chatanalyst-provenance/final-report.md +0 -45
- data/research/chatanalyst-provenance/resumption.md +0 -37
- data/research/coding-philosophy-analysis.md +0 -928
- data/research/commands-analysis.md +0 -947
- data/research/multi-agent-patterns-analysis.md +0 -853
- data/research/prompt-strategies-analysis.md +0 -630
- data/research/prov-verbosity-fix-notes.md +0 -77
- data/research/provenance-analysis.md +0 -469
- data/research/synthesis-report.md +0 -487
- 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
|