MCPcopy Index your code
hub / github.com/coder/coder / TestEditFiles

Function TestEditFiles

coderd/x/chatd/chattool/editfiles_test.go:20–509  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestEditFiles(t *testing.T) {
21 t.Parallel()
22
23 // Verify the generated tool schema exposes old_text/new_text
24 // (not the deprecated search/replace) so the rename is
25 // auditable without running a separate program.
26 t.Run("SchemaUsesOldTextNewText", func(t *testing.T) {
27 t.Parallel()
28 tool := chattool.EditFiles(chattool.EditFilesOptions{})
29 info := tool.Info()
30
31 // Dig into: files -> items -> properties -> edits -> items -> properties
32 filesSchema := info.Parameters["files"]
33 require.NotNil(t, filesSchema, "missing files parameter")
34 filesMap, ok := filesSchema.(map[string]any)
35 require.True(t, ok)
36 items, ok := filesMap["items"].(map[string]any)
37 require.True(t, ok)
38 props, ok := items["properties"].(map[string]any)
39 require.True(t, ok)
40 editsSchema, ok := props["edits"].(map[string]any)
41 require.True(t, ok)
42 editItems, ok := editsSchema["items"].(map[string]any)
43 require.True(t, ok)
44 editProps, ok := editItems["properties"].(map[string]any)
45 require.True(t, ok)
46
47 assert.Contains(t, editProps, "old_text", "schema should expose old_text")
48 assert.Contains(t, editProps, "new_text", "schema should expose new_text")
49 assert.Contains(t, editProps, "replace_all", "schema should expose replace_all")
50 assert.NotContains(t, editProps, "search", "schema should not expose deprecated search")
51 assert.NotContains(t, editProps, "replace", "schema should not expose deprecated replace")
52
53 // Verify required fields.
54 editRequired, ok := editItems["required"].([]string)
55 require.True(t, ok)
56 assert.Contains(t, editRequired, "old_text")
57 assert.Contains(t, editRequired, "new_text")
58 assert.NotContains(t, editRequired, "replace_all", "replace_all should be optional")
59 })
60
61 t.Run("PlanTurnRejectsNonPlanPath", func(t *testing.T) {
62 t.Parallel()
63 ctrl := gomock.NewController(t)
64 mockConn := agentconnmock.NewMockAgentConn(ctrl)
65 planPath := "/home/coder/.coder/plans/PLAN-test-uuid.md"
66 getWorkspaceConnCalled := false
67 tool := chattool.EditFiles(chattool.EditFilesOptions{
68 GetWorkspaceConn: func(context.Context) (workspacesdk.AgentConn, error) {
69 getWorkspaceConnCalled = true
70 return mockConn, nil
71 },
72 ResolvePlanPath: func(context.Context) (string, string, error) {
73 return planPath, "/home/coder", nil
74 },
75 IsPlanTurn: true,
76 })
77

Callers

nothing calls this directly

Calls 14

EXPECTMethod · 0.95
EditFilesFunction · 0.92
NewMockAgentConnFunction · 0.92
relativePlanPathMessageFunction · 0.85
RunMethod · 0.65
ResolvePathMethod · 0.65
EditFilesMethod · 0.65
NewMethod · 0.65
InfoMethod · 0.45

Tested by

no test coverage detected