From 484977e3f05bca8b5f83d9ac293d08251a1dac44 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 19 Dec 2024 09:45:34 +0000 Subject: [PATCH 1/2] fix(deps): update module github.com/akedrou/textdiff to v0.1.0 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b7e6c26..39b4847 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.22.5 require ( connectrpc.com/connect v1.17.0 - github.com/akedrou/textdiff v0.0.0-20230423230343-2ebdcebdccc1 + github.com/akedrou/textdiff v0.1.0 github.com/anthropics/anthropic-sdk-go v0.2.0-alpha.4 github.com/auth0/go-jwt-middleware/v2 v2.2.2 github.com/coder/websocket v1.8.12 diff --git a/go.sum b/go.sum index 2721d97..88a14e8 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ connectrpc.com/connect v1.17.0 h1:W0ZqMhtVzn9Zhn2yATuUokDLO5N+gIuBWMOnsQrfmZk= connectrpc.com/connect v1.17.0/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8= -github.com/akedrou/textdiff v0.0.0-20230423230343-2ebdcebdccc1 h1:XfKKiQL7irIGI7nfu4a6IKhrgUHvKwhH/AnuHgZy/+U= -github.com/akedrou/textdiff v0.0.0-20230423230343-2ebdcebdccc1/go.mod h1:PJwvxBpzqjdeomc0r8Hgc+xJC7k6z+k371tffCGXR2M= +github.com/akedrou/textdiff v0.1.0 h1:K7nbOVQju7/coCXnJRJ2fsltTwbSvC+M4hKBUJRBRGY= +github.com/akedrou/textdiff v0.1.0/go.mod h1:a9CCC49AKtFTmVDNFHDlCg7V/M7C7QExDAhb2SkL6DQ= github.com/anthropics/anthropic-sdk-go v0.2.0-alpha.4 h1:TdGQS+RoR4AUO6gqUL74yK1dz/Arrt/WG+dxOj6Yo6A= github.com/anthropics/anthropic-sdk-go v0.2.0-alpha.4/go.mod h1:GJxtdOs9K4neo8Gg65CjJ7jNautmldGli5/OFNabOoo= github.com/auth0/go-jwt-middleware/v2 v2.2.2 h1:vrvkFZf72r3Qbt45KLjBG3/6Xq2r3NTixWKu2e8de9I= From 4cd9f746e74531f68980a0a4302f24bd715e6e6c Mon Sep 17 00:00:00 2001 From: Dylan Ratcliffe Date: Thu, 19 Dec 2024 10:45:06 +0000 Subject: [PATCH 2/2] Updated diff library --- llm/render_prompt.go | 6 +++++- llm/render_prompt_test.go | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/llm/render_prompt.go b/llm/render_prompt.go index 3ab76aa..572cbda 100644 --- a/llm/render_prompt.go +++ b/llm/render_prompt.go @@ -222,8 +222,12 @@ func itemDiffToYAMLDiff(itemDiff *sdp.ItemDiff) (string, error) { } // Diff the YAML + + // `myers.ComputeEdits` is deprecated, but I haven't yet found a good + // alternative that handles multiple diffs in a single file nicely. See the + // `TestDiffLibrary` for an example of what output we're expecting edits := myers.ComputeEdits(beforeYAML, afterYAML) - unified, err := textdiff.ToUnified("current", "proposed", beforeYAML, edits) + unified, err := textdiff.ToUnified("current", "proposed", beforeYAML, edits, 3) if err != nil { return "", err diff --git a/llm/render_prompt_test.go b/llm/render_prompt_test.go index 0019284..4c48526 100644 --- a/llm/render_prompt_test.go +++ b/llm/render_prompt_test.go @@ -251,7 +251,15 @@ image: ghcr.io/overmindtech/api-server@sha256:462be60d478b3e86796ce628765ec3f42b func TestDiffLibrary(t *testing.T) { edits := myers.ComputeEdits(testBefore, testAfter) - unified, _ := textdiff.ToUnified("name", "name", testBefore, edits) + + unified, _ := textdiff.ToUnified("name", "name", testBefore, edits, 3) + + // We want the diff to be smart i.e. not to print the whole file twice, but + // instead focus on the two lines that changed (the top and the bottom) + lines := strings.Split(unified, "\n") + if len(lines) > 17 { + t.Errorf("diff is too long: %d lines", len(lines)) + } fmt.Println(fmt.Sprint(unified)) }