Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- **A catalog document YAML refuses to load is an invalid document**
(`activeagent`, `actionagent`). `Catalog.parse` turned only a syntax
error into `Catalog::InvalidDocument`, while safe loading refuses a tag
naming a Ruby class (`!ruby/object:...`) or an alias to an undefined
anchor with other `Psych` errors. Those escaped the dashboard's catalog
import and preview as a 500, and the `catalogs_import` and
`catalogs_preview` tools as an internal error. They are now refused like
any other invalid catalog: 422 with "the catalog is not valid YAML: ...".
What safe loading permits is unchanged.

## [1.9.8] - 2026-11-12

The dashboard holds a run to its catalog's pass bars: a product's and a
Expand Down
6 changes: 6 additions & 0 deletions actionagent/test/mcp_dashboard_tools_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,12 @@ def structured(body)
assert_equal true, body.dig("result", "isError")
assert_match(/product has no key/, body.dig("result", "content", 0, "text"))
assert_equal(-32602, call_tool("catalogs_import").dig("error", "code"))

%w[catalogs_import catalogs_preview].each do |tool|
body = call_tool(tool, { document: "--- !ruby/object:Object {}\n" })
assert_equal true, body.dig("result", "isError"), "#{tool} answers a refused document as a tool error"
assert_match(/not valid YAML/, body.dig("result", "content", 0, "text"))
end
end

test "catalog_set_run materializes the set as an evaluation and queues its run" do
Expand Down
13 changes: 13 additions & 0 deletions actionagent/test/scenario_catalogs_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ def body
assert_match(/product has no key/, body["errors"].first)
end

test "a document naming a Ruby class is refused as invalid YAML, on import and on preview" do
document = "--- !ruby/object:Object {}\n"

post "/activeagents/api/scenario_catalogs", params: { document: document }, as: :json
assert_response :unprocessable_entity
assert_match(/not valid YAML: Tried to load unspecified class: Object/, body["errors"].first)

post "/activeagents/api/scenario_catalogs/preview", params: { document: document }, as: :json
assert_response :unprocessable_entity
assert_match(/not valid YAML/, body["errors"].first)
assert_equal 0, ActionAgent::ScenarioCatalog.count
end

test "imports every catalog file of a connected repository at a ref" do
ActionAgent::GithubConnection.create!(
access_token: "gho_test", github_user_id: 42, login: "octocat",
Expand Down
7 changes: 5 additions & 2 deletions lib/active_agent/evals/catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,16 @@ def self.load(*paths, name: nil)
end

# Parses YAML text. Raises InvalidDocument for YAML that is not a
# document (a list, a scalar) or that YAML cannot read.
# document (a list, a scalar) or that YAML cannot read: a syntax error,
# and what safe loading refuses — a tag naming a Ruby class other than
# Symbol (Psych::DisallowedClass) or an alias to an undefined anchor
# (Psych::BadAlias), which are not Psych::SyntaxError.
def self.parse(text, name: nil)
document = YAML.safe_load(text.to_s, aliases: true, permitted_classes: [ Symbol ])
raise InvalidDocument, "a scenario catalog is a YAML mapping" unless document.is_a?(Hash)

new([ document ], name: name)
rescue Psych::SyntaxError => e
rescue Psych::Exception => e
raise InvalidDocument, "the catalog is not valid YAML: #{e.message}"
end

Expand Down
31 changes: 31 additions & 0 deletions test/evals/catalog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,37 @@ def gated_catalog(*overlays)
assert_raises(ActiveAgent::Evals::Catalog::NotFound) { ActiveAgent::Evals::Catalog.load(File.join(FIXTURES, "missing.yml")) }
end

# The document is read with YAML.safe_load, which refuses a tag naming a
# Ruby class and an alias to an anchor the document never defines with
# errors of its own, apart from Psych::SyntaxError.
test "refuses YAML that safe loading will not read, as an invalid document" do
{
"--- !ruby/object:Object {}\n" => /Tried to load unspecified class: Object/,
"catalog: x\nproducts: [{ key: p, at: !ruby/object:OpenStruct { a: 1 } }]\n" => /unspecified class: OpenStruct/,
"catalog: x\nproducts: *undefined\n" => /undefined/
}.each do |document, reason|
error = assert_raises(ActiveAgent::Evals::Catalog::InvalidDocument, document) { ActiveAgent::Evals::Catalog.parse(document) }
assert_match(/\Athe catalog is not valid YAML: /, error.message)
assert_match reason, error.message
end
end

test "keeps reading the symbols and aliases a catalog may use" do
catalog = ActiveAgent::Evals::Catalog.parse(<<~YAML)
catalog: x
products:
- key: p
judge: :rules
sets:
- key: s
scenarios:
- &first { key: a, prompt: Which tickets are open? }
- *first
YAML

assert_equal [ "a" ], catalog.scenarios.map(&:key).uniq
end

test "refuses malformed criteria, naming the product or set and the list" do
refused = {
"catalog: x\nproducts: [{ key: p, criteria: oops }]" => /criteria of product "p" are not a list or a mapping of lists/,
Expand Down
Loading