Skip to content

Commit 56c1829

Browse files
Copilotsawka
andauthored
Update aiusechat read_dir tests for typed entry output (#3007)
`pkg/aiusechat/tools_readdir_test.go` was still asserting the old `entries` payload shape after `read_dir` moved to returning typed directory entries. This caused the `pkg/aiusechat` test failures even though the tool behavior itself was already correct. - **Align test expectations with current callback output** - Update `TestReadDirCallback` to treat `entries` as `[]fileutil.DirEntryOut` - Assert directory/file classification via the `Dir` field instead of map lookups - **Fix truncation/sorting coverage** - Update `TestReadDirSortBeforeTruncate` to validate the typed slice returned by `readDirCallback` - Preserve the existing intent of the test: directories should still be sorted ahead of files before truncation - **Keep scope limited to stale tests** - No changes to `read_dir` implementation or output contract - Only the broken test assumptions were corrected ```go entries, ok := resultMap["entries"].([]fileutil.DirEntryOut) if !ok { t.Fatalf("entries is not a slice of DirEntryOut") } for _, entry := range entries { if entry.Dir { // directory assertions } } ``` <!-- START COPILOT CODING AGENT TIPS --> --- ✨ Let Copilot coding agent [set things up for you](https://github.com/wavetermdev/waveterm/issues/new?title=✨+Set+up+Copilot+instructions&body=Configure%20instructions%20for%20this%20repository%20as%20documented%20in%20%5BBest%20practices%20for%20Copilot%20coding%20agent%20in%20your%20repository%5D%28https://gh.io/copilot-coding-agent-tips%29%2E%0A%0A%3COnboard%20this%20repo%3E&assignees=copilot) — coding agent works faster and does higher quality work when set up for your repo. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent 7ef0bcd commit 56c1829

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

pkg/aiusechat/tools_readdir_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"github.com/wavetermdev/waveterm/pkg/aiusechat/uctypes"
14+
"github.com/wavetermdev/waveterm/pkg/util/fileutil"
1415
)
1516

1617
func TestReadDirCallback(t *testing.T) {
@@ -64,16 +65,16 @@ func TestReadDirCallback(t *testing.T) {
6465
t.Errorf("Expected 3 entries, got %d", entryCount)
6566
}
6667

67-
entries, ok := resultMap["entries"].([]map[string]any)
68+
entries, ok := resultMap["entries"].([]fileutil.DirEntryOut)
6869
if !ok {
69-
t.Fatalf("entries is not a slice of maps")
70+
t.Fatalf("entries is not a slice of DirEntryOut")
7071
}
7172

7273
// Check that we have the expected entries
7374
foundFiles := 0
7475
foundDirs := 0
7576
for _, entry := range entries {
76-
if entry["is_dir"].(bool) {
77+
if entry.Dir {
7778
foundDirs++
7879
} else {
7980
foundFiles++
@@ -208,12 +209,15 @@ func TestReadDirSortBeforeTruncate(t *testing.T) {
208209
}
209210

210211
resultMap := result.(map[string]any)
211-
entries := resultMap["entries"].([]map[string]any)
212+
entries, ok := resultMap["entries"].([]fileutil.DirEntryOut)
213+
if !ok {
214+
t.Fatalf("entries is not a slice of DirEntryOut")
215+
}
212216

213217
// Count directories in the result
214218
dirCount := 0
215219
for _, entry := range entries {
216-
if entry["is_dir"].(bool) {
220+
if entry.Dir {
217221
dirCount++
218222
}
219223
}
@@ -225,7 +229,7 @@ func TestReadDirSortBeforeTruncate(t *testing.T) {
225229

226230
// First 3 entries should be directories
227231
for i := 0; i < 3; i++ {
228-
if !entries[i]["is_dir"].(bool) {
232+
if !entries[i].Dir {
229233
t.Errorf("Expected entry %d to be a directory, but it was a file", i)
230234
}
231235
}

0 commit comments

Comments
 (0)