MCPcopy Index your code
hub / github.com/dagger/dagger / TestLLMFileSyncing

Method TestLLMFileSyncing

cmd/dagger/shell_test.go:47–135  ·  view source on GitHub ↗
(ctx context.Context, t *testctx.T)

Source from the content-addressed store, hash-verified

45}
46
47func (DaggerCMDSuite) TestLLMFileSyncing(ctx context.Context, t *testctx.T) {
48 if _, err := os.Stat("/dagger.env"); os.IsNotExist(err) {
49 t.Skip(".env not configured")
50 }
51
52 testModDir := filepath.Join("testdata", "cmd-test")
53
54 // run out of the module test dir
55 t.Chdir(testModDir)
56
57 // use .env file configured through module
58 cp := exec.Command("cp", "/dagger.env", ".env")
59 cp.Stdout = os.Stdout
60 cp.Stderr = os.Stderr
61 err := cp.Run()
62 require.NoError(t, err)
63
64 // connect (from test module dir, workdir)
65 dag, err := dagger.Connect(ctx)
66 require.NoError(t, err)
67 t.Cleanup(func() { dag.Close() })
68
69 sidebarContent := map[string]idtui.SidebarSection{}
70 handler := newShellCallHandler(dag, &idtui.FrontendMock{
71 SetSidebarContentFunc: func(sec idtui.SidebarSection) {
72 sidebarContent[sec.Title] = sec
73 },
74 })
75
76 require.NoError(t, handler.Initialize(ctx))
77
78 // runReact calls ReactToInput and runs async work synchronously (for testing).
79 runReact := func(ev uv.KeyPressEvent) {
80 work := handler.ReactToInput(ctx, ev, "", true)
81 if work != nil {
82 work()
83 }
84 }
85
86 // set prompt to our test agent and switch to prompt mode
87 handler.Handle(ctx, "agent=$(agent)")
88 runReact(uv.KeyPressEvent{Text: ">", Code: '>'})
89
90 // make a change
91 handler.Handle(ctx, "Write 'apple' to fruit.txt.")
92
93 sec, has := sidebarContent["Changes"]
94 require.True(t, has, "Should have shown a Changes section in the sidebar.")
95 require.Contains(t, sec.Body(80), "fruit.txt")
96
97 // sync it down
98 runReact(uv.KeyPressEvent{Code: 's', Mod: uv.ModCtrl})
99 contents, err := os.ReadFile("fruit.txt")
100 require.NoError(t, err)
101 require.Contains(t, string(contents), "apple")
102
103 // make our own changes
104 require.NoError(t, os.WriteFile("fruit.txt", []byte("potato"), 0644))

Callers

nothing calls this directly

Calls 15

newShellCallHandlerFunction · 0.85
CleanupMethod · 0.80
InitializeMethod · 0.80
BodyMethod · 0.80
StatMethod · 0.65
RunMethod · 0.65
ConnectMethod · 0.65
CloseMethod · 0.65
ReactToInputMethod · 0.65
HandleMethod · 0.65
ContainsMethod · 0.65
ReadFileMethod · 0.65

Tested by

no test coverage detected