discourse/plugins/discourse-ai/spec/lib/completions/tool_arguments_parser_spec.rb
Sam 65024326dd
FEATURE: Add AI authoring to Discourse Workflows (#40504)
Previously, admins could only build Discourse Workflows by manually
adding and connecting every trigger, condition, and action node on the
canvas.

This change adds an AI authoring assistant, gated behind
`discourse_workflows_ai_authoring_enabled` and DiscourseAi, that turns a
natural-language request into a server-validated, reviewable workflow
patch the admin applies. It only ever proposes drafts and never
publishes.

---------

Co-authored-by: chapoi <101828855+chapoi@users.noreply.github.com>
Co-authored-by: Rafael Silva <xfalcox@gmail.com>
Co-authored-by: Joffrey JAFFEUX <j.jaffeux@gmail.com>
2026-06-18 18:32:30 +02:00

35 lines
1.1 KiB
Ruby
Vendored

# frozen_string_literal: true
RSpec.describe DiscourseAi::Completions::ToolArgumentsParser do
before { enable_current_plugin }
it "returns hash arguments with symbolized keys" do
expect(described_class.parse("kind" => "group", "options" => { "notify" => true })).to eq(
{ kind: "group", options: { notify: true } },
)
end
it "parses blank arguments as an empty hash" do
expect(described_class.parse(" ")).to eq({})
end
it "parses arguments with padding" do
expect(described_class.parse(" {\"kind\":\"group\",\"query\":\"friend\"} ")).to eq(
{ kind: "group", query: "friend" },
)
end
it "repairs an omitted opening delimiter" do
expect(described_class.parse("kind\": \"group\", \"query\": \"friend\"} ")).to eq(
{ kind: "group", query: "friend" },
)
end
it "repairs omitted closing delimiters" do
expect(described_class.parse('{"outer":{"inner":"value"')).to eq({ outer: { inner: "value" } })
end
it "raises on invalid arguments" do
expect { described_class.parse("not-json") }.to raise_error(JSON::ParserError)
end
end