Files
arcrun-collector/cmd/arcrun-app/skipped_test.go
T
Leo 67effe3b7f 首頁「沒被整理的檔案」修兩病:同一件事講兩次/不說是哪一個檔
leo 08-06 封測回報(附截圖+「他放一個 md 檔無法通過」)。

## ① 同一件事講兩次,而且「另外」前面沒有東西
截圖實況:
  「看起來不是文件,所以跳過了。」   ← 底下是空的(非文件檔不逐檔點名)
  「**另外**有 1 個不是文件的檔案(圖片、影片、壓縮檔之類)也沒有處理。」
真兇:app.go buildSkipped 的 else 分支先寫一句通用說明,
接著無條件再寫 Other 那句——後者的「另外」是為「兩種都有」寫的,
在「只有非文件檔」時就變成前面沒有東西可以「另外」。
解:該分支只講一句、自己帶數量,且不留 Other。「另外」只在兩種都有時出現。

## ② 只報總數=等於沒說(這才是 md 那題卡住的原因)
封測者放 .md 說「無法通過」,但畫面只寫「有 1 個不是文件的檔案」,
**沒說是哪一個** ⇒ 誰也判斷不出發生什麼事。
而 `.md` 明明在 allowedExt 白名單裡(scan.go:26),我在本機實測也一次就過:
    "path":"arcrun-md-test.md","status":"ingested","http_status":200
⇒ 那個「1 個」必然不是他以為的那個檔(副檔名被 Windows 藏起來、存成別的格式…),
  但沒有檔名就永遠查不出來。
解:scan 收集非文件檔的檔名(上限 5 個),一路帶到 status.json 與首頁。
「只報總數」在幾百張圖時是對的,在 1 個時是失職——少量就點名。

## 驗
· 兩支新測試釘住規則:只有非文件檔時不准出現第二句、不准出現「另外」;
  兩種都有時「另外」才成立並帶數量
· 實際文案打出來看過(見下),不是只看測試綠
    有 1 個檔案沒有被整理
    看起來不是文件(圖片、影片、壓縮檔之類),所以跳過了。這是正常的,你不用做什麼。
      · 我的筆記.md.txt
· 312 張圖的情況:列 5 個 +「…還有 307 個」,不洗版
· collector 全測試過、app 測試過、go vet 全綠
2026-08-06 16:12:01 +08:00

118 lines
4.4 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package main
// skipped_test.go — 首頁「這些檔案還讀不了」那張卡(G-6.2,2026-08-06)。
//
// 這一層驗的不是資料對不對(那在 collector/scan_skipped_test.go),
// 而是**話有沒有講成人話**:使用者看到的是檔名與該不該動手,
// 不是 allowedExt、extractor、副檔名白名單這些系統內部詞。
import (
"strings"
"testing"
)
func TestBuildSkippedNilWhenNothingSkipped(t *testing.T) {
if got := buildSkipped(syncStatus{}); got != nil {
t.Fatalf("沒東西被略過時不該生出卡片(會白佔首頁版面):%+v", got)
}
}
func TestBuildSkippedNamesTheFilesInPlainWords(t *testing.T) {
u := buildSkipped(syncStatus{
SkippedDocs: []skippedDoc{
{Path: "提案/舊版報告.doc", Ext: ".doc"},
{Path: "簡報.key", Ext: ".key"},
},
SkippedDocCount: 2,
})
if u == nil {
t.Fatal("有讀不了的檔卻沒生出卡片=又回到安靜略過")
}
if !strings.Contains(u.Title, "2") {
t.Errorf("標題要講幾個檔,實得 %q", u.Title)
}
// 使用者看的是檔名,不是我們的相對路徑。
if u.Files[0] != "舊版報告.doc(舊版 Word" {
t.Errorf("檔名該配上他認得的格式名,實得 %q", u.Files[0])
}
if u.Files[1] != "簡報.keyKeynote" {
t.Errorf("實得 %q", u.Files[1])
}
// 要回答「我現在該做什麼」——答案是不用做什麼,而且要說出替代路。
for _, want := range []string{"不用重丟", "PDF"} {
if !strings.Contains(u.Note, want) {
t.Errorf("說明要包含 %q,實得 %q", want, u.Note)
}
}
// 不准把系統內部詞漏給使用者。
for _, leak := range []string{"allowedExt", "extractor", "ErrUnsupported", "副檔名"} {
if strings.Contains(u.Title+u.Note, leak) {
t.Errorf("不該對使用者講 %q", leak)
}
}
}
// 清單有上限,但**總數不能被截掉**——否則使用者以為只有 20 個檔沒進去。
func TestBuildSkippedShowsRemainderCount(t *testing.T) {
docs := make([]skippedDoc, 20)
for i := range docs {
docs[i] = skippedDoc{Path: "檔.doc", Ext: ".doc"}
}
u := buildSkipped(syncStatus{SkippedDocs: docs, SkippedDocCount: 57})
if u.More != 37 {
t.Errorf("沒列出來的還有 37 個,實得 %d", u.More)
}
if !strings.Contains(u.Title, "57") {
t.Errorf("標題該講真實總數 57,實得 %q", u.Title)
}
}
// 整個資料夾都是照片這種情況:不必驚動他,但也不能一個字都不說。
//
// 🔴 2026-08-06 leo 封測截圖抓到的病:這張卡把同一件事講了兩次——
// 先一句通用的「看起來不是文件,所以跳過了。」(底下是空的,因為非文件檔不點名),
// 再一句「**另外**有 1 個…也沒有處理。」而「另外」前面根本沒有東西。
// ⇒ 只有非文件檔時**只准講一句**,而且那一句要自己帶數量。
func TestBuildSkippedOtherOnly(t *testing.T) {
u := buildSkipped(syncStatus{SkippedOtherCount: 312})
if u == nil {
t.Fatal("只有非文件檔時仍要說一句,不能沉默")
}
if len(u.Files) != 0 {
t.Error("非文件檔不逐檔點名(幾百張圖會變成噪音)")
}
if !strings.Contains(u.Title, "312") {
t.Errorf("只有非文件檔時,數量要出現在標題(那是唯一會被看到的一句),實得 %q", u.Title)
}
if u.Other != "" {
t.Errorf("同一件事不准講兩次——沒有讀不了的文件時不該再出現一句,實得 %q", u.Other)
}
if strings.Contains(u.Title+u.Note, "另外") {
t.Errorf("前面沒有東西可以「另外」,實得 %q / %q", u.Title, u.Note)
}
}
// 兩種都有時,「另外」才成立——它接在「讀不了的檔」那段之後。
func TestBuildSkippedBothKinds(t *testing.T) {
u := buildSkipped(syncStatus{
SkippedDocs: []skippedDoc{{Path: "舊報告.doc", Ext: ".doc"}},
SkippedDocCount: 1,
SkippedOtherCount: 3,
})
if !strings.Contains(u.Title, "讀不了") {
t.Errorf("有讀不了的文件時,標題要講那件事,實得 %q", u.Title)
}
if !strings.Contains(u.Other, "另外") || !strings.Contains(u.Other, "3") {
t.Errorf("兩種都有時才用「另外」並帶數量,實得 %q", u.Other)
}
}
func TestExtLabelFallsBackToRawExt(t *testing.T) {
if got := extLabel(".xyz"); got != "xyz" {
t.Errorf("沒對照到的格式原樣顯示,實得 %q", got)
}
if got := extLabel(".DOC"); got != "舊版 Word" {
t.Errorf("大寫副檔名也要認得(Windows 常見),實得 %q", got)
}
}