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

Function TestDetectFileDump

coderd/x/chatd/chattool/execute_test.go:551–629  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

549}
550
551func TestDetectFileDump(t *testing.T) {
552 t.Parallel()
553
554 tests := []struct {
555 name string
556 command string
557 wantHit bool
558 }{
559 {
560 name: "CatFile",
561 command: "cat foo.txt",
562 wantHit: true,
563 },
564 {
565 name: "NotCatPrefix",
566 command: "concatenate foo",
567 wantHit: false,
568 },
569 {
570 name: "GrepIncludeAll",
571 command: "grep --include-all pattern",
572 wantHit: true,
573 },
574 {
575 name: "RgListFiles",
576 command: "rg -l pattern",
577 wantHit: true,
578 },
579 {
580 name: "GrepRecursive",
581 command: "grep -r pattern",
582 wantHit: false,
583 },
584 }
585
586 for _, tc := range tests {
587 t.Run(tc.name, func(t *testing.T) {
588 t.Parallel()
589 ctrl := gomock.NewController(t)
590 mockConn := agentconnmock.NewMockAgentConn(ctrl)
591
592 mockConn.EXPECT().
593 StartProcess(gomock.Any(), gomock.Any()).
594 Return(workspacesdk.StartProcessResponse{ID: "proc-1"}, nil)
595 exitCode := 0
596 mockConn.EXPECT().
597 ProcessOutput(gomock.Any(), "proc-1", gomock.Any()).
598 Return(workspacesdk.ProcessOutputResponse{
599 Running: false,
600 ExitCode: &exitCode,
601 Output: "output",
602 }, nil)
603
604 tool := newExecuteTool(t, mockConn)
605 ctx := testutil.Context(t, testutil.WaitMedium)
606 input, err := json.Marshal(map[string]any{
607 "command": tc.command,
608 })

Callers

nothing calls this directly

Calls 11

EXPECTMethod · 0.95
NewMockAgentConnFunction · 0.92
ContextFunction · 0.92
newExecuteToolFunction · 0.85
RunMethod · 0.65
StartProcessMethod · 0.65
ProcessOutputMethod · 0.65
MarshalMethod · 0.45
UnmarshalMethod · 0.45
ContainsMethod · 0.45
EmptyMethod · 0.45

Tested by

no test coverage detected