Fully autonomous AI Agents system capable of performing complex penetration testing tasks
Go ai-agentsai-security-toolanthropicautonomous-agentsgolanggptgraphqlmulti-agent-systemoffensive-securityopen-sourceopenaipenetration-testingpenetration-testing-toolsreactsecurity-automationsecurity-testingsecurity-toolsself-hosted
feat(docker): partial-success container listing instead of fail-fast
Sergey Kozyrenko1300f60a2b6f
diff --git a/backend/pkg/docker/client.go b/backend/pkg/docker/client.goindex aae4a7f2..fa6a44a1 100644--- a/backend/pkg/docker/client.go+++ b/backend/pkg/docker/client.go@@ -65,7 +65,7 @@ type DockerClient interface {ContainerExecAttach(ctx context.Context, execID string, config container.ExecAttachOptions) (types.HijackedResponse, error)ContainerExecInspect(ctx context.Context, execID string) (container.ExecInspect, error)ContainerStatPath(ctx context.Context, containerID string, path string) (container.PathStat, error)- ListContainerDir(ctx context.Context, containerID string, dirPath string) ([]container.PathStat, error)+ ListContainerDir(ctx context.Context, containerID string, dirPath string) (ContainerDirListing, error)CopyToContainer(ctx context.Context, containerID string, dstPath string, content io.Reader, options container.CopyToContainerOptions) errorCopyFromContainer(ctx context.Context, containerID string, srcPath string) (io.ReadCloser, container.PathStat, error)Cleanup(ctx context.Context) error@@ -570,21 +570,38 @@ func (dc *dockerClient) ContainerStatPath(return dc.client.ContainerStatPath(ctx, containerID, path)}+// ContainerEntryError is a directory entry that could not be stat'd during a+// listing; the rest of the listing is still returned.+type ContainerEntryError struct {+ Name string+ Path string+ Err error+}++// ContainerDirListing is the result of ListContainerDir: the entries that+// stat'd successfully, plus per-entry failures. A directory-level fault (path+// not a directory, ls failed, container gone) is returned as an error instead —+// a single unreadable entry never blanks the whole listing.+type ContainerDirListing struct {+ Files []container.PathStat+ Failures []ContainerEntryError+}+func (dc *dockerClient) ListContainerDir(ctx context.Context,containerID string,dirPath string,-) ([]container.PathStat, error) {+) (ContainerDirListing, error) {if strings.TrimSpace(dirPath) == "" {dirPath = WorkFolderPathInContainer}dirStat, err := dc.ContainerStatPath(ctx, containerID, dirPath)if err != nil {- return nil, fmt.Errorf("failed to stat container path '%s': %w", dirPath, err)+ return ContainerDirListing{}, fmt.Errorf("failed to stat container path '%s': %w", dirPath, err)}if !dirStat.Mode.IsDir() {- return nil, fmt.Errorf("container path '%s' is not a directory", dirPath)+ return ContainerDirListing{}, fmt.Errorf("container path '%s' is not a directory", dirPath)}createResp, err := dc.ContainerExecCreate(ctx, containerID, container.ExecOptions{@@ -594,27 +611,27 @@ func (dc *dockerClient) ListContainerDir(Tty: true,})if err != nil {- return nil, fmt.Errorf("failed to create ls exec for '%s': %w", dirPath, err)+ return ContainerDirListing{}, fmt.Errorf("failed to create ls exec for '%s': %w", dirPath, err)}resp, err := dc.ContainerExecAttach(ctx, createResp.ID, container.ExecAttachOptions{Tty: true,})if err != nil {- return nil, fmt.Errorf("failed to attach ls exec for '%s': %w", dirPath, err)+ return ContainerDirListing{}, fmt.Errorf("failed to attach ls exec for '%s': %w", dirPath, err)}output, readErr := io.ReadAll(resp.Reader)resp.Close()if readErr != nil {- return nil, fmt.Errorf("failed to read ls output for '%s': %w", dirPath, readErr)+ return ContainerDirListing{}, fmt.Errorf("failed to read ls output for '%s': %w", dirPath, readErr)}inspect, err := dc.ContainerExecInspect(ctx, createResp.ID)if err != nil {- return nil, fmt.Errorf("failed to inspect ls exec for '%s': %w", dirPath, err)+ return ContainerDirListing{}, fmt.Errorf("failed to inspect ls exec for '%s': %w", dirPath, err)}if inspect.ExitCode != 0 {- return nil, fmt.Errorf("ls command failed for '%s' with exit code %d: %s", dirPath, inspect.ExitCode, string(output))+ return ContainerDirListing{}, fmt.Errorf("ls command failed for '%s' with exit code %d: %s", dirPath, inspect.ExitCode, string(output))}names := make([]string, 0)@@ -626,26 +643,37 @@ func (dc *dockerClient) ListContainerDir(names = append(names, name)}- stats, err := statContainerEntries(ctx, names, containerListWorkers, func(ctx context.Context, name string) (container.PathStat, error) {+ stats, failures := statContainerEntries(ctx, names, containerListWorkers, func(ctx context.Context, name string) (container.PathStat, error) {return dc.ContainerStatPath(ctx, containerID, path.Join(dirPath, name))})- if err != nil {- return nil, err++ listing := ContainerDirListing{Files: stats}+ for _, f := range failures {+ listing.Failures = append(listing.Failures, ContainerEntryError{+ Name: f.name,+ Path: path.Join(dirPath, f.name),+ Err: f.err,+ })}- return stats, nil+ return listing, nil+}++type statFailure struct {+ name string+ err error}// statContainerEntries stats every name concurrently, bounded to `workers`-// in-flight calls, and returns the results in input order. It waits for all-// stats before reporting, so the surfaced error is the lowest-index failure-// deterministically — not whichever call happened to fail first.+// in-flight calls. A per-entry stat error never aborts the batch: the successful+// stats and the failures are both returned (in input order) so the caller can+// serve a partial listing rather than discarding everything on one bad entry.func statContainerEntries(ctx context.Context,names []string,workers int,statFn func(context.Context, string) (container.PathStat, error),-) ([]container.PathStat, error) {+) ([]container.PathStat, []statFailure) {// errgroup.SetLimit(0) blocks the first Go() forever and SetLimit(<0) runs// unbounded; clamp a non-positive count to the standard bound so the pool// never deadlocks or floods the Docker daemon.@@ -670,13 +698,17 @@ func statContainerEntries(}_ = g.Wait()+ oks := make([]container.PathStat, 0, len(names))+ var failures []statFailurefor i, name := range names {if errs[i] != nil {- return nil, fmt.Errorf("failed to stat container entry '%s': %w", name, errs[i])+ failures = append(failures, statFailure{name: name, err: errs[i]})+ } else {+ oks = append(oks, stats[i])}}- return stats, nil+ return oks, failures}func (dc *dockerClient) CopyToContainer(diff --git a/backend/pkg/docker/client_statfanout_test.go b/backend/pkg/docker/client_statfanout_test.goindex ed9e2609..8d8a616c 100644--- a/backend/pkg/docker/client_statfanout_test.go+++ b/backend/pkg/docker/client_statfanout_test.go@@ -2,9 +2,9 @@ package dockerimport ("context"+ "errors""fmt""math/rand"- "strings""sync/atomic""testing""time"@@ -16,68 +16,68 @@ func okStat(_ context.Context, name string) (container.PathStat, error) {return container.PathStat{Name: name, Size: int64(len(name))}, nil}-func TestStatContainerEntries_AllSucceedInInputOrder(t *testing.T) {+func failNames(failures []statFailure) map[string]bool {+ m := make(map[string]bool, len(failures))+ for _, f := range failures {+ m[f.name] = true+ }+ return m+}++func TestStatContainerEntries_AllSucceed(t *testing.T) {names := []string{"c", "a", "b", "z", "m"}- stats, err := statContainerEntries(context.Background(), names, 20, okStat)- if err != nil {- t.Fatalf("unexpected error: %v", err)+ stats, failures := statContainerEntries(context.Background(), names, 20, okStat)+ if len(failures) != 0 {+ t.Fatalf("unexpected failures: %v", failures)}if len(stats) != len(names) {t.Fatalf("got %d stats, want %d", len(stats), len(names))}- for i, name := range names {- if stats[i].Name != name {- t.Fatalf("result order not preserved at %d: got %q want %q", i, stats[i].Name, name)- }- }}func TestStatContainerEntries_Empty(t *testing.T) {- stats, err := statContainerEntries(context.Background(), nil, 20, okStat)- if err != nil {- t.Fatalf("unexpected error: %v", err)- }- if len(stats) != 0 {- t.Fatalf("got %d stats, want 0", len(stats))+ stats, failures := statContainerEntries(context.Background(), nil, 20, okStat)+ if len(stats) != 0 || len(failures) != 0 {+ t.Fatalf("got %d stats / %d failures, want 0/0", len(stats), len(failures))}}-// With several failing entries, the surfaced error is deterministically the-// lowest-index failure regardless of completion order, so it stays reproducible.-func TestStatContainerEntries_LowestIndexErrorSurfaces(t *testing.T) {+// A per-entry stat error must NOT abort the batch: the readable entries are+// returned and the failing ones come back as failures — partial success.+func TestStatContainerEntries_PartialSuccessNotAborting(t *testing.T) {names := []string{"e0", "e1", "e2", "e3", "e4"}- fail := map[string]bool{"e3": true, "e1": true} // lowest failing index is 1- // e3 fails fast, e1 fails slowly: completion order would surface e3, but- // the input-order rule must surface e1.- delay := map[string]time.Duration{"e1": 20 * time.Millisecond}+ fail := map[string]bool{"e1": true, "e3": true}statFn := func(_ context.Context, name string) (container.PathStat, error) {- time.Sleep(delay[name])if fail[name] {return container.PathStat{}, fmt.Errorf("boom %s", name)}return container.PathStat{Name: name}, nil}- stats, err := statContainerEntries(context.Background(), names, 20, statFn)- if err == nil {- t.Fatal("expected an error")+ stats, failures := statContainerEntries(context.Background(), names, 20, statFn)++ fn := failNames(failures)+ if len(fn) != 2 || !fn["e1"] || !fn["e3"] {+ t.Fatalf("want failures {e1,e3}, got %v", fn)}- if stats != nil {- t.Fatalf("expected nil stats on error, got %v", stats)+ wantOK := []string{"e0", "e2", "e4"} // successes, preserved in input order+ if len(stats) != len(wantOK) {+ t.Fatalf("want %d readable entries, got %d", len(wantOK), len(stats))}- if !strings.Contains(err.Error(), "entry 'e1'") {- t.Fatalf("want lowest-index entry 'e1' in error, got %q", err.Error())+ for i, s := range stats {+ if s.Name != wantOK[i] {+ t.Fatalf("success order at %d: got %q want %q", i, s.Name, wantOK[i])+ }}}// The pool never runs more than `workers` stat calls at once — the load-bearing-// bound against the Docker daemon (which caps idle but not active connections).+// bound against the Docker daemon.func TestStatContainerEntries_RespectsConcurrencyLimit(t *testing.T) {const workers = 5names := make([]string, 100)for i := range names {names[i] = fmt.Sprintf("e%d", i)}-var cur, max atomic.Int64statFn := func(_ context.Context, name string) (container.PathStat, error) {c := cur.Add(1)@@ -91,9 +91,8 @@ func TestStatContainerEntries_RespectsConcurrencyLimit(t *testing.T) {cur.Add(-1)return container.PathStat{Name: name}, nil}-- if _, err := statContainerEntries(context.Background(), names, workers, statFn); err != nil {- t.Fatalf("unexpected error: %v", err)+ if _, failures := statContainerEntries(context.Background(), names, workers, statFn); len(failures) != 0 {+ t.Fatalf("unexpected failures: %v", failures)}if got := max.Load(); got > workers {t.Fatalf("concurrency exceeded limit: peak=%d, limit=%d", got, workers)@@ -102,6 +101,34 @@ func TestStatContainerEntries_RespectsConcurrencyLimit(t *testing.T) {}}+// The caller's context reaches each stat call; a cancellation turns entries into+// failures rather than blanking the whole batch.+func TestStatContainerEntries_ContextPropagates(t *testing.T) {+ ctx, cancel := context.WithCancel(context.Background())+ names := []string{"a", "b", "c", "d", "e"}+ var once atomic.Bool+ statFn := func(ctx context.Context, name string) (container.PathStat, error) {+ if once.CompareAndSwap(false, true) {+ cancel()+ }+ select {+ case <-ctx.Done():+ return container.PathStat{}, ctx.Err()+ case <-time.After(2 * time.Second):+ return container.PathStat{Name: name}, nil+ }+ }+ _, failures := statContainerEntries(ctx, names, 20, statFn)+ if len(failures) == 0 {+ t.Fatal("expected failures once the context is cancelled")+ }+ for _, f := range failures {+ if !errors.Is(f.err, context.Canceled) {+ t.Fatalf("failure %q: want context.Canceled, got %v", f.name, f.err)+ }+ }+}+// A non-positive worker count must fall back to a safe bound rather than// deadlock (errgroup SetLimit(0)) or run unbounded (SetLimit(<0)).func TestStatContainerEntries_NonPositiveWorkersFallBack(t *testing.T) {@@ -111,22 +138,15 @@ func TestStatContainerEntries_NonPositiveWorkersFallBack(t *testing.T) {}for _, workers := range []int{0, -1} {t.Run(fmt.Sprintf("workers=%d", workers), func(t *testing.T) {- type out struct {- stats []container.PathStat- err error- }- done := make(chan out, 1)+ done := make(chan int, 1)go func() {- stats, err := statContainerEntries(context.Background(), names, workers, okStat)- done <- out{stats, err}+ stats, _ := statContainerEntries(context.Background(), names, workers, okStat)+ done <- len(stats)}()select {- case got := <-done:- if got.err != nil {- t.Fatalf("unexpected error: %v", got.err)- }- if len(got.stats) != len(names) {- t.Fatalf("got %d stats, want %d", len(got.stats), len(names))+ case n := <-done:+ if n != len(names) {+ t.Fatalf("got %d stats, want %d", n, len(names))}case <-time.After(3 * time.Second):t.Fatal("statContainerEntries hung with a non-positive worker count")@@ -135,76 +155,43 @@ func TestStatContainerEntries_NonPositiveWorkersFallBack(t *testing.T) {}}-// The caller's context reaches each stat call, so a cancellation aborts them.-func TestStatContainerEntries_ContextPropagates(t *testing.T) {- ctx, cancel := context.WithCancel(context.Background())- names := []string{"a", "b", "c", "d", "e"}- var once atomic.Bool- statFn := func(ctx context.Context, name string) (container.PathStat, error) {- if once.CompareAndSwap(false, true) {- cancel()- }- select {- case <-ctx.Done():- return container.PathStat{}, ctx.Err()- case <-time.After(2 * time.Second):- return container.PathStat{Name: name}, nil- }- }- if _, err := statContainerEntries(ctx, names, 20, statFn); err == nil {- t.Fatal("expected an error once the context is cancelled")- }-}--// Property-based: over randomized shapes, success yields input-order stats and-// any failure yields exactly the lowest-index entry's error. Fixed seed.+// Property-based: over randomized shapes nothing is lost — every failing name+// lands in failures, every other name yields a stat, and stats+failures == n.func TestStatContainerEntries_PropertyFuzz(t *testing.T) {rng := rand.New(rand.NewSource(2))for iter := 0; iter < 300; iter++ {n := rng.Intn(50)names := make([]string, n)+ wantFail := make(map[string]bool, n)for i := range names {names[i] = fmt.Sprintf("it%d-e%d", iter, i)- }- fail := make(map[string]bool, n)- delay := make(map[string]time.Duration, n)- lowest := -1- for i, nm := range names {if rng.Intn(3) == 0 {- fail[nm] = true- if lowest == -1 {- lowest = i- }+ wantFail[names[i]] = true}- delay[nm] = time.Duration(rng.Intn(2)) * time.Millisecond}statFn := func(_ context.Context, name string) (container.PathStat, error) {- time.Sleep(delay[name])- if fail[name] {+ if wantFail[name] {return container.PathStat{}, fmt.Errorf("boom %s", name)}- return container.PathStat{Name: name, Size: int64(len(name))}, nil+ return container.PathStat{Name: name}, nil}+ stats, failures := statContainerEntries(context.Background(), names, 20, statFn)- stats, err := statContainerEntries(context.Background(), names, 20, statFn)- if lowest >= 0 {- if err == nil {- t.Fatalf("iter %d: expected error for lowest-index failure %q", iter, names[lowest])- }- if want := fmt.Sprintf("entry '%s'", names[lowest]); !strings.Contains(err.Error(), want) {- t.Fatalf("iter %d: want %q in error, got %q", iter, want, err.Error())- }- if stats != nil {- t.Fatalf("iter %d: want nil stats on error", iter)- }- continue+ if len(stats)+len(failures) != n {+ t.Fatalf("iter %d: lost data — %d stats + %d failures != %d names", iter, len(stats), len(failures), n)+ }+ gotFail := failNames(failures)+ if len(gotFail) != len(wantFail) {+ t.Fatalf("iter %d: want %d failures, got %d", iter, len(wantFail), len(gotFail))}- if err != nil {- t.Fatalf("iter %d: unexpected error: %v", iter, err)+ for nm := range wantFail {+ if !gotFail[nm] {+ t.Fatalf("iter %d: missing failure for %q", iter, nm)+ }}- for i, name := range names {- if stats[i].Name != name {- t.Fatalf("iter %d: order not preserved at %d", iter, i)+ for _, s := range stats {+ if wantFail[s.Name] {+ t.Fatalf("iter %d: %q failed but appears in stats", iter, s.Name)}}}diff --git a/backend/pkg/server/models/flow_files.go b/backend/pkg/server/models/flow_files.goindex 8e1dacbb..e478ff70 100644--- a/backend/pkg/server/models/flow_files.go+++ b/backend/pkg/server/models/flow_files.go@@ -28,11 +28,21 @@ type ContainerFile struct {ModifiedAt time.Time `json:"modified_at"`}+// ContainerFileError is a directory entry that could not be read during a+// listing; the readable entries are still returned so one bad entry never+// blanks the whole listing.+type ContainerFileError struct {+ Name string `json:"name"`+ Path string `json:"path"`+ Message string `json:"message"`+}+// ContainerFiles is the list response for container directory listing.type ContainerFiles struct {- Path string `json:"path"`- Files []ContainerFile `json:"files"`- Total uint64 `json:"total"`+ Path string `json:"path"`+ Files []ContainerFile `json:"files"`+ Failures []ContainerFileError `json:"failures,omitempty"`+ Total uint64 `json:"total"`}// PullFlowFilesRequest is the request body for pulling files from a container.diff --git a/backend/pkg/server/services/flow_files.go b/backend/pkg/server/services/flow_files.goindex ffb3c144..9422633f 100644--- a/backend/pkg/server/services/flow_files.go+++ b/backend/pkg/server/services/flow_files.go@@ -964,7 +964,9 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {// resolved file.Path so that overlapping queries never return the same// entry twice.seenPaths := make(map[string]struct{})+ seenFailPaths := make(map[string]struct{})allFiles := make([]models.ContainerFile, 0)+ allFailures := make([]models.ContainerFileError, 0)for _, containerPath := range containerPaths {pathStat, err := s.dockerClient.ContainerStatPath(c.Request.Context(), containerName, containerPath)if err != nil {@@ -985,7 +987,7 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {continue}- stats, err := s.dockerClient.ListContainerDir(c.Request.Context(), containerName, containerPath)+ listing, err := s.dockerClient.ListContainerDir(c.Request.Context(), containerName, containerPath)if err != nil {logger.FromContext(c).WithError(err).WithFields(map[string]any{"flow_id": flowID,@@ -994,13 +996,24 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {response.Error(c, response.ErrInternal, err)return}- for _, stat := range stats {+ for _, stat := range listing.Files {file := convertContainerFile(containerPath, stat)if _, seen := seenPaths[file.Path]; !seen {seenPaths[file.Path] = struct{}{}allFiles = append(allFiles, file)}}+ for _, fe := range listing.Failures {+ if _, seen := seenFailPaths[fe.Path]; seen {+ continue+ }+ seenFailPaths[fe.Path] = struct{}{}+ allFailures = append(allFailures, models.ContainerFileError{+ Name: fe.Name,+ Path: fe.Path,+ Message: fe.Err.Error(),+ })+ }}// Sort by name for deterministic output across all paths.@@ -1024,10 +1037,40 @@ func (s *FlowFileService) GetFlowContainerFiles(c *gin.Context) {responsePath = containerPaths[0]}+ // A per-entry stat failure (dangling symlink, a file removed mid-listing,+ // transient /proc entries) degrades the listing but must not blank it: the+ // readable files are returned and each skipped entry is logged and carried+ // back in Failures so an operator can tell what and how much was skipped.+ if len(allFailures) > 0 {+ log := logger.FromContext(c)+ const maxLoggedFailures = 20+ for i, fe := range allFailures {+ if i >= maxLoggedFailures {+ log.WithFields(map[string]any{+ "flow_id": flowID,+ "suppressed": len(allFailures) - maxLoggedFailures,+ }).Warn("additional container entries skipped (log capped)")+ break+ }+ log.WithFields(map[string]any{+ "flow_id": flowID,+ "entry": fe.Name,+ "entry_path": fe.Path,+ "error": fe.Message,+ }).Warn("container entry skipped: could not stat")+ }+ log.WithFields(map[string]any{+ "flow_id": flowID,+ "listed": len(allFiles),+ "failed": len(allFailures),+ }).Warn("container listing degraded: some entries could not be read")+ }+response.Success(c, http.StatusOK, models.ContainerFiles{- Path: responsePath,- Files: allFiles,- Total: uint64(len(allFiles)),+ Path: responsePath,+ Files: allFiles,+ Failures: allFailures,+ Total: uint64(len(allFiles)),})}diff --git a/backend/pkg/server/services/flow_files_test.go b/backend/pkg/server/services/flow_files_test.goindex a8531331..bd43e0ee 100644--- a/backend/pkg/server/services/flow_files_test.go+++ b/backend/pkg/server/services/flow_files_test.go@@ -971,6 +971,7 @@ type fakeDockerClient struct {statPathMap map[string]container.PathStatstatPathErrMap map[string]errorlistDirMap map[string][]container.PathStat+ listDirFailMap map[string][]docker.ContainerEntryErrorlistDirErrMap map[string]error// CopyFromContainer behaviour.@@ -1049,18 +1050,23 @@ func (f *fakeDockerClient) ContainerStatPath(_ context.Context, _ string, p stri}return f.statPath, f.statPathErr}-func (f *fakeDockerClient) ListContainerDir(_ context.Context, _ string, p string) ([]container.PathStat, error) {+func (f *fakeDockerClient) ListContainerDir(_ context.Context, _ string, p string) (docker.ContainerDirListing, error) {if f.listDirErrMap != nil {if err, ok := f.listDirErrMap[p]; ok {- return nil, err+ return docker.ContainerDirListing{}, err+ }+ }+ if f.listDirFailMap != nil {+ if fails, ok := f.listDirFailMap[p]; ok {+ return docker.ContainerDirListing{Files: f.listDirMap[p], Failures: fails}, nil}}if f.listDirMap != nil {if dir, ok := f.listDirMap[p]; ok {- return dir, nil+ return docker.ContainerDirListing{Files: dir}, nil}}- return f.listDir, f.listDirErr+ return docker.ContainerDirListing{Files: f.listDir}, f.listDirErr}func (f *fakeDockerClient) CopyToContainer(_ context.Context, containerID string, dstPath string, content io.Reader, options container.CopyToContainerOptions) error {body, _ := io.ReadAll(content)@@ -3012,19 +3018,20 @@ func TestFlowFileService_PullFlowFilesScenarios(t *testing.T) {func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {tests := []struct {- name string- flowOwner uint64- uid uint64- flowID uint64- privs []string- queryPath string // builds ?path=<value>- rawQuery string // when set, used verbatim as query string (overrides queryPath)- dockerSetup func(*fakeDockerClient)- dockerNil bool- wantStatus int- wantPathInResp string- wantFileNames []string // expected file names in sorted order (nil = don't check)- wantTotal uint64 // > 0: verify response Total+ name string+ flowOwner uint64+ uid uint64+ flowID uint64+ privs []string+ queryPath string // builds ?path=<value>+ rawQuery string // when set, used verbatim as query string (overrides queryPath)+ dockerSetup func(*fakeDockerClient)+ dockerNil bool+ wantStatus int+ wantPathInResp string+ wantFileNames []string // expected file names in sorted order (nil = don't check)+ wantTotal uint64 // > 0: verify response Total+ wantFailureNames []string // expected Failures[].Name (nil = don't check)}{// ── single-path: existing behaviour (backward compatibility) ──────────{@@ -3166,6 +3173,36 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {wantPathInResp: "/etc",wantFileNames: []string{"passwd"},},+ {+ // A per-entry stat failure (dangling symlink, a file removed+ // mid-listing, a transient /proc pid) must degrade to a partial+ // listing — HTTP 200 with the readable files plus the failure+ // surfaced in Failures — not a 500 that blanks the whole directory.+ name: "per-entry stat failure returns partial listing not 500",+ flowOwner: 1, uid: 1, flowID: 1,+ privs: []string{"flow_files.view", "containers.view"},+ queryPath: "/work",+ dockerSetup: func(d *fakeDockerClient) {+ d.running = true+ d.statPathMap = map[string]container.PathStat{+ "/work": {Mode: os.ModeDir | 0755},+ }+ d.listDirMap = map[string][]container.PathStat{+ "/work": {{Name: "good.txt", Size: 3, Mode: 0644}},+ }+ d.listDirFailMap = map[string][]docker.ContainerEntryError{+ "/work": {{+ Name: "dangling",+ Path: "/work/dangling",+ Err: fmt.Errorf("no such file or directory"),+ }},+ }+ },+ wantStatus: http.StatusOK,+ wantPathInResp: "/work",+ wantFileNames: []string{"good.txt"},+ wantFailureNames: []string{"dangling"},+ },{// Two directories are queried; results are merged and sorted by name.// The response Path must be empty because there is no single "current dir".@@ -3380,6 +3417,13 @@ func TestFlowFileService_GetFlowContainerFilesScenarios(t *testing.T) {assert.Equal(t, tt.wantTotal, resp.Total, "response Total mismatch")assert.Len(t, resp.Files, int(tt.wantTotal), "response Files length mismatch")}+ if tt.wantFailureNames != nil {+ names := make([]string, len(resp.Failures))+ for i, f := range resp.Failures {+ names[i] = f.Name+ }+ assert.ElementsMatch(t, tt.wantFailureNames, names)+ }})}}diff --git a/backend/pkg/tools/terminal_test.go b/backend/pkg/tools/terminal_test.goindex 11516e3d..bee7601e 100644--- a/backend/pkg/tools/terminal_test.go+++ b/backend/pkg/tools/terminal_test.go@@ -96,8 +96,8 @@ func (m *contextAwareMockDockerClient) ContainerExecAttach(ctx context.Context,func (m *contextAwareMockDockerClient) ContainerStatPath(_ context.Context, _ string, _ string) (container.PathStat, error) {return container.PathStat{}, nil}-func (m *contextAwareMockDockerClient) ListContainerDir(_ context.Context, _ string, _ string) ([]container.PathStat, error) {- return nil, nil+func (m *contextAwareMockDockerClient) ListContainerDir(_ context.Context, _ string, _ string) (docker.ContainerDirListing, error) {+ return docker.ContainerDirListing{}, nil}func (m *contextAwareMockDockerClient) ContainerExecInspect(_ context.Context, _ string) (container.ExecInspect, error) {return m.inspectResp, nil