Skip to content
代码片段 群组 项目
未验证 提交 75bff99c 编辑于 作者: Darby Frey's avatar Darby Frey 提交者: GitLab
浏览文件

Fixes VR diff creation bug

上级 5696bedc
No related branches found
No related tags found
无相关合并请求
......@@ -119,10 +119,12 @@ def create_llm_diff_from_blocks
fixed_code = finding_presenter.source_code.dup
changes.each do |old_code, new_code|
fixed_code.gsub!(old_code.lstrip, new_code.lstrip)
fixed_code.gsub!(old_code.strip, new_code.strip)
end
create_llm_diff_from_given_code(fixed_code)
# Diffy expects fixed_code to include a trailing newline
# since we're stripping the newlines above, we add it here.
create_llm_diff_from_given_code("#{fixed_code}\n")
end
def create_llm_diff_from_code_block
......
......@@ -458,7 +458,7 @@
diff --git a/src/main.c b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -4,5 +4,5 @@
@@ -4,5 +4,6 @@
{
char buf[8];
- memcpy(&buf, "123456789");
......@@ -471,7 +471,7 @@
file: 'vulnerabilities/remediation',
formats: :patch,
locals: hash_including(
diff: diff
diff: "#{diff}+\n"
)
).and_call_original
expect(service).to receive(:render_template).with(
......@@ -493,7 +493,7 @@
diff --git a/src/main.c b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -4,5 +4,5 @@
@@ -4,5 +4,6 @@
{
char buf[8];
- memcpy(&buf, "123456789");
......@@ -507,7 +507,7 @@
file: 'vulnerabilities/remediation',
formats: :patch,
locals: hash_including(
diff: diff
diff: "#{diff}+\n"
)
).and_call_original
expect(service).to receive(:render_template).with(
......@@ -540,6 +540,40 @@
end
end
end
context 'when extra newlines are returned from the LLM' do
let(:llm_patch) { "<old_code>\n memcpy(&buf, \"123456789\");\n\n</old_code><new_code>\n memcpy(&buf, \"1\");\n</new_code>" }
it 'successfully creates a functional diff and patch from the LLM patch' do
diff = <<~HEREDOC
diff --git a/src/main.c b/src/main.c
--- a/src/main.c
+++ b/src/main.c
@@ -4,5 +4,6 @@
{
char buf[8];
- memcpy(&buf, "123456789");
+ memcpy(&buf, "1");
printf("hello, world!");
}
HEREDOC
expect(service).to receive(:render_template).with(
file: 'vulnerabilities/remediation',
formats: :patch,
locals: hash_including(
diff: "#{diff}+\n"
)
).and_call_original
expect(service).to receive(:render_template).with(
file: 'vulnerabilities/merge_request_description',
formats: :md,
locals: instance_of(Hash)
).and_call_original
expect(result[:status]).to eq(:success)
end
end
end
context 'when suggestion_merge_request is present in params' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册