Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 3b6f658

Browse files
committed
write spec
1 parent 77c66cf commit 3b6f658

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/ai_bot/tools/create_artifact.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def update_custom_html(artifact = nil)
9393
js = parameters[:js].to_s
9494

9595
artifact_div =
96-
"<div class=\"ai-artifact\" data-ai-artifact-id=#{artifact.id}></div>" if artifact
96+
"<div class=\"ai-artifact\" data-ai-artifact-id=\"#{artifact.id}\"></div>" if artifact
9797

9898
content = []
9999

spec/lib/modules/ai_bot/tools/create_artifact_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,46 @@
44
fab!(:llm_model)
55
let(:bot_user) { DiscourseAi::AiBot::EntryPoint.find_user_from_model(llm_model.name) }
66
let(:llm) { DiscourseAi::Completions::Llm.proxy("custom:#{llm_model.id}") }
7+
fab!(:post)
78

89
before { SiteSetting.ai_bot_enabled = true }
910

1011
describe "#process" do
12+
it "correctly adds details block on final invoke" do
13+
tool =
14+
described_class.new(
15+
{ html_body: "hello" },
16+
bot_user: Fabricate(:user),
17+
llm: llm,
18+
context: {
19+
post_id: post.id,
20+
},
21+
)
22+
23+
tool.parameters = { html_body: "hello" }
24+
25+
tool.invoke {}
26+
27+
artifact_id = AiArtifact.order("id desc").limit(1).pluck(:id).first
28+
29+
expected = <<~MD
30+
[details='View Source']
31+
32+
### HTML
33+
34+
```html
35+
hello
36+
```
37+
38+
[/details]
39+
40+
### Preview
41+
42+
<div class="ai-artifact" data-ai-artifact-id="#{artifact_id}"></div>
43+
MD
44+
expect(tool.custom_raw.strip).to eq(expected.strip)
45+
end
46+
1147
it "can correctly handle partial updates" do
1248
tool = described_class.new({}, bot_user: bot_user, llm: llm)
1349

0 commit comments

Comments
 (0)