An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Improve handling of duplicate filenames in asset uploads https://github.com/siyuan-note/siyuan/issues/18891
Daniele1a2d14c8bf3
diff --git a/app/src/protyle/render/av/asset.ts b/app/src/protyle/render/av/asset.tsindex c85ae6b31f..f38bf356c8 100644--- a/app/src/protyle/render/av/asset.ts+++ b/app/src/protyle/render/av/asset.ts@@ -24,6 +24,7 @@ import {getFieldIdByCellElement} from "./row";import {base64ToURL, getCompressURL, removeCompressURL} from "../../../util/image";import {isBrowserRenderableImagePath} from "../../../util/imageURL";import {genNetworkImageAssetValue} from "./assetValue";+import {getAssetUploadSuccesses} from "../../upload/uploadResult";export const bindAssetEvent = (options: {protyle: IProtyle,@@ -40,11 +41,11 @@ export const bindAssetEvent = (options: {uploadFiles(options.protyle, event.target.files, event.target, (res) => {const resData = JSON.parse(res);const value: IAVCellAssetValue[] = [];- Object.keys(resData.data.succMap).forEach((key) => {+ getAssetUploadSuccesses(resData.data).forEach((success) => {value.push({- name: key,- content: resData.data.succMap[key],- type: Constants.SIYUAN_ASSETS_IMAGE.includes(getAssetExtension(resData.data.succMap[key]).toLowerCase()) ? "image" : "file"+ name: success.name,+ content: success.path,+ type: Constants.SIYUAN_ASSETS_IMAGE.includes(getAssetExtension(success.path).toLowerCase()) ? "image" : "file"});});updateAssetCell({@@ -496,20 +497,20 @@ export const dragUpload = (files: ILocalFiles[], protyle: IProtyle, cellElement:return;}const addValue: IAVCellAssetValue[] = [];- Object.keys(response.data.succMap).forEach(key => {- const type = getAssetExtension(key).toLowerCase();- const name = key.substring(0, key.length - type.length);+ getAssetUploadSuccesses(response.data).forEach(success => {+ const type = getAssetExtension(success.name).toLowerCase();+ const name = success.name.substring(0, success.name.length - type.length);if (Constants.SIYUAN_ASSETS_IMAGE.includes(type)) {addValue.push({type: "image",name,- content: response.data.succMap[key],+ content: success.path,});} else {addValue.push({type: "file",name,- content: response.data.succMap[key],+ content: success.path,});}});diff --git a/app/src/protyle/upload/index.ts b/app/src/protyle/upload/index.tsindex 69dd5ce4b3..0b5c962e65 100644--- a/app/src/protyle/upload/index.ts+++ b/app/src/protyle/upload/index.ts@@ -24,7 +24,7 @@ import {type IAssetUploadTask,prepareAssetUpload,} from "./pluginEvent";-import {getAssetUploadResult} from "./uploadResult";+import {getAssetUploadResult, getAssetUploadSuccesses} from "./uploadResult";interface FileWithPath extends File {path: string;@@ -141,7 +141,7 @@ const genUploadedLabel = async (responseText: string, protyle: IProtyle, optionsrange.setEndAfter(range.startContainer.parentElement);range.collapse(false);}- const keys = Object.keys(response.data.succMap);+ const successes = getAssetUploadSuccesses(response.data);// https://github.com/siyuan-note/siyuan/issues/7624const nodeElement = hasClosestBlock(range.startContainer);if (nodeElement) {@@ -150,30 +150,29 @@ const genUploadedLabel = async (responseText: string, protyle: IProtyle, options} else {const editableElement = getContenteditableElement(nodeElement);if (editableElement && nodeElement.classList.contains("p") &&- (editableElement.textContent !== "" || keys.length < 2)) {+ (editableElement.textContent !== "" || successes.length < 2)) {insertBlock = false;}}}let successFileText = "";// 插入多个资源文件时按文件名自然升序排列 Use natural ascending order when inserting multiple assets https://github.com/siyuan-note/siyuan/issues/14643- keys.sort((a, b) => a.localeCompare(b, undefined, {numeric: true}));+ successes.sort((a, b) => a.name.localeCompare(b.name, undefined, {numeric: true}) || a.index - b.index);const avAssets: IAVCellAssetValue[] = [];let hasImage = false;- keys.forEach((key, index) => {- const path = response.data.succMap[key];- const type = pathPosix().extname(key).toLowerCase();- const filename = protyle.options.upload.filename(key);+ successes.forEach((success, index) => {+ const type = pathPosix().extname(success.name).toLowerCase();+ const filename = protyle.options.upload.filename(success.name);const name = filename.substring(0, filename.length - type.length);hasImage = Constants.SIYUAN_ASSETS_IMAGE.includes(type);avAssets.push({type: Constants.SIYUAN_ASSETS_IMAGE.includes(type) ? "image" : "file",- content: path,+ content: success.path,name: name});- successFileText += genAssetHTML(type, path, name, filename, options?.htmlAsIframe);+ successFileText += genAssetHTML(type, success.path, name, filename, options?.htmlAsIframe);if (!Constants.SIYUAN_ASSETS_AUDIO.includes(type) && !Constants.SIYUAN_ASSETS_VIDEO.includes(type) &&- keys.length - 1 !== index) {+ successes.length - 1 !== index) {if (nodeElement && nodeElement.classList.contains("table")) {successFileText += "<br>";} else if (insertBlock) {@@ -431,9 +430,9 @@ const uploadPreparedLocalFiles = (input: Extract<IAssetUploadInput, { kind: "locreturn;}let tip = "";- Object.keys(response.data.succMap).forEach(name => {- if (response.data.succMap[name].startsWith("file:")) {- tip += name + ", ";+ getAssetUploadSuccesses(response.data).forEach(success => {+ if (success.path.startsWith("file:")) {+ tip += success.name + ", ";}});if (tip) {diff --git a/app/src/protyle/upload/uploadResult.test.ts b/app/src/protyle/upload/uploadResult.test.tsindex d882cb75fe..b9c8ba8083 100644--- a/app/src/protyle/upload/uploadResult.test.ts+++ b/app/src/protyle/upload/uploadResult.test.ts@@ -1,6 +1,6 @@import {describe, it} from "node:test";import * as assert from "node:assert/strict";-import {getAssetUploadResult} from "./uploadResult";+import {getAssetUploadResult, getAssetUploadSuccesses} from "./uploadResult";const createFile = (name: string) => new File(["content"], name, {type: "image/png"});@@ -15,6 +15,41 @@ describe("asset upload result", () => {assert.equal(result.status, "success");assert.deepEqual(result.acceptedInput, input);assert.equal(result.rejected, undefined);+ assert.deepEqual(getAssetUploadSuccesses({succMap: {"a.png": "assets/a.png"}}), [+ {index: 0, name: "a.png", path: "assets/a.png"},+ ]);+ });++ it("preserves successful uploads with duplicate filenames", () => {+ const input: IAssetUploadInput = {+ kind: "files",+ files: [createFile("image.png"), createFile("image.png")],+ };+ const succFiles: IAssetUploadSuccess[] = [+ {index: 0, name: "image.png", path: "assets/image-first.png"},+ {index: 1, name: "image.png", path: "assets/image-second.png"},+ ];+ const result = getAssetUploadResult(JSON.stringify({+ code: 0,+ data: {succFiles, succMap: {"image.png": "assets/image-second.png"}, errFiles: []},+ }), input);++ assert.equal(result.status, "success");+ assert.deepEqual(result.succFiles, succFiles);+ assert.deepEqual(getAssetUploadSuccesses({succFiles}), succFiles);+ });++ it("does not report full success for a legacy response with duplicate filenames", () => {+ const input: IAssetUploadInput = {+ kind: "files",+ files: [createFile("image.png"), createFile("image.png")],+ };+ const result = getAssetUploadResult(JSON.stringify({+ code: 0,+ data: {succMap: {"image.png": "assets/image.png"}, errFiles: []},+ }), input);++ assert.equal(result.status, "partial");});it("reports partial when frontend validation rejected part of the input", () => {diff --git a/app/src/protyle/upload/uploadResult.ts b/app/src/protyle/upload/uploadResult.tsindex fa843f52c9..7d569b777e 100644--- a/app/src/protyle/upload/uploadResult.ts+++ b/app/src/protyle/upload/uploadResult.ts@@ -1,3 +1,13 @@+export const getAssetUploadSuccesses = (data?: {+ succFiles?: IAssetUploadSuccess[],+ succMap?: Record<string, string>+}): IAssetUploadSuccess[] => {+ if (Array.isArray(data?.succFiles)) {+ return data.succFiles;+ }+ return Object.entries(data?.succMap || {}).map(([name, path], index) => ({index, name, path}));+};+export const getAssetUploadResult = (responseText: string, acceptedInput: IAssetUploadInput,rejected: IAssetUploadRejection[] = []):Omit<IAssetUploadResult, "requestId" | "input"> => {@@ -8,17 +18,17 @@ Omit<IAssetUploadResult, "requestId" | "input"> => {try {const response = JSON.parse(responseText);const succMap = response.data?.succMap as Record<string, string> | undefined;+ const succFiles = response.data?.succFiles as IAssetUploadSuccess[] | undefined;const errFiles = response.data?.errFiles as string[] | undefined;if (typeof response.code === "number" && response.code !== 0) {- return {...inputResult, status: "failed", succMap, errFiles, error: String(response.msg || "")};+ return {...inputResult, status: "failed", succFiles, succMap, errFiles, error: String(response.msg || "")};}- if (succMap) {+ if (Array.isArray(succFiles) || succMap) {const expected = acceptedInput.files.length;- const succeeded = acceptedInput.kind === "files" ?- acceptedInput.files.filter(file => succMap[file.name]).length : Object.keys(succMap).length;+ const succeeded = Array.isArray(succFiles) ? succFiles.length : Object.keys(succMap).length;const status = succeeded === expected && !errFiles?.length && rejected.length === 0 ? "success" :succeeded > 0 ? "partial" : "failed";- return {...inputResult, status, succMap, errFiles};+ return {...inputResult, status, succFiles, succMap, errFiles};}} catch (error) {// 自定义上传接口不一定返回 JSON,HTTP 200 仍视为成功。diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex 79137c4255..d8e92162fa 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -415,6 +415,12 @@ interface IAssetUploadRejection {reasons: TAssetUploadRejectionReason[]}+interface IAssetUploadSuccess {+ index: number,+ name: string,+ path: string+}+interface IAssetUploadResult {requestId: string,status: TAssetUploadStatus,@@ -424,6 +430,8 @@ interface IAssetUploadResult {acceptedInput?: IAssetUploadInput,/** 被前端校验拒绝的文件及其在完整输入中的位置。 */rejected?: IAssetUploadRejection[],+ /** 按 acceptedInput 中的索引记录成功结果,可区分同名文件。 */+ succFiles?: IAssetUploadSuccess[],succMap?: Record<string, string>,errFiles?: string[],error?: stringdiff --git a/docs/API.ja.md b/docs/API.ja.mdindex e36338921a..6753e237b5 100644--- a/docs/API.ja.md+++ b/docs/API.ja.md@@ -715,6 +715,13 @@"msg": "","data": {"errFiles": [""],+ "succFiles": [+ {+ "index": 0,+ "name": "foo.png",+ "path": "assets/foo-20210719092549-9j5y79r.png"+ }+ ],"succMap": {"foo.png": "assets/foo-20210719092549-9j5y79r.png"}@@ -723,7 +730,8 @@```* `errFiles`: アップロード処理でエラーが発生したファイル名のリスト- * `succMap`: 正常に処理されたファイル、キーはアップロード時のファイル名、値はassets/foo-id.pngで、既存のMarkdownコンテンツ内のアセットリンクアドレスをアップロードされたアドレスに置き換えるために使用+ * `succFiles`: 正常に処理されたファイルを入力順に記録します。`index` は `file[]` 内のインデックス、`name` はアップロード時のファイル名、`path` はアップロード後のアセットパスです。同じバッチに同名ファイルが含まれる場合は、このフィールドを使用してください+ * `succMap`: 既存の呼び出し元との互換性を保つための成功ファイルマッピングです。キーはアップロード時のファイル名、値は assets/foo-id.png です。同じバッチに同名ファイルが含まれる場合、同じキーでは最後の項目のみが保持されます## ブロックdiff --git a/docs/API.md b/docs/API.mdindex 4c5d14ed0f..17c8e20061 100644--- a/docs/API.md+++ b/docs/API.md@@ -717,6 +717,13 @@ Move documents by `id`:"msg": "","data": {"errFiles": [""],+ "succFiles": [+ {+ "index": 0,+ "name": "foo.png",+ "path": "assets/foo-20210719092549-9j5y79r.png"+ }+ ],"succMap": {"foo.png": "assets/foo-20210719092549-9j5y79r.png"}@@ -725,9 +732,8 @@ Move documents by `id`:```* `errFiles`: List of filenames with errors in upload processing- * `succMap`: For successfully processed files, the key is the file name when uploading, and the value is- assets/foo-id.png, which is used to replace the asset link address in the existing Markdown content with the- uploaded address+ * `succFiles`: Successfully processed files in input order. `index` is the file's index in `file[]`, `name` is its upload filename, and `path` is the uploaded asset path. Use this field when a batch can contain duplicate filenames+ * `succMap`: Compatibility mapping for existing callers. The key is the upload filename and the value is assets/foo-id.png. When a batch contains duplicate filenames, only the last item with a given key remains in this map## Blocksdiff --git a/docs/API.zh-CN.md b/docs/API.zh-CN.mdindex db04ef8d27..009ef6519e 100644--- a/docs/API.zh-CN.md+++ b/docs/API.zh-CN.md@@ -715,6 +715,13 @@"msg": "","data": {"errFiles": [""],+ "succFiles": [+ {+ "index": 0,+ "name": "foo.png",+ "path": "assets/foo-20210719092549-9j5y79r.png"+ }+ ],"succMap": {"foo.png": "assets/foo-20210719092549-9j5y79r.png"}@@ -723,7 +730,8 @@```* `errFiles`:处理时遇到错误的文件名- * `succMap`:处理成功的文件,key 为上传时的文件名,value 为 assets/foo-id.png,用于将已有 Markdown 内容中的资源文件链接地址替换为上传后的地址+ * `succFiles`:按输入顺序记录处理成功的文件,`index` 为文件在 `file[]` 中的索引,`name` 为上传时的文件名,`path` 为上传后的资源文件路径;同一批文件包含同名文件时应使用该字段+ * `succMap`:为兼容现有调用方保留的成功文件映射,key 为上传时的文件名,value 为 assets/foo-id.png;同一批文件包含同名文件时,同名 key 仅保留最后一项## 块diff --git a/kernel/api/asset.go b/kernel/api/asset.goindex 6b4339192a..969b645c91 100644--- a/kernel/api/asset.go+++ b/kernel/api/asset.go@@ -612,14 +612,15 @@ func insertLocalAssets(c *gin.Context) {isUpload = isUploadArg.(bool)}id := arg["id"].(string)- succMap, err := model.InsertLocalAssets(id, assetPaths, isUpload)+ succMap, succFiles, err := model.InsertLocalAssets(id, assetPaths, isUpload)if err != nil {ret.Code = -1ret.Msg = err.Error()return}ret.Data = map[string]any{- "succMap": succMap,+ "succFiles": succFiles,+ "succMap": succMap,}}@@ -654,7 +655,7 @@ func insertCover(c *gin.Context) {}id := arg["id"].(string)- succMap, err := model.InsertLocalAssets(id, []string{srcPath}, true)+ succMap, succFiles, err := model.InsertLocalAssets(id, []string{srcPath}, true)if nil != err {ret.Code = -1ret.Msg = err.Error()@@ -662,6 +663,7 @@ func insertCover(c *gin.Context) {}ret.Data = map[string]any{- "succMap": succMap,+ "succFiles": succFiles,+ "succMap": succMap,}}diff --git a/kernel/cli/cmd/asset.go b/kernel/cli/cmd/asset.goindex 9f2d9ba357..eac2a4b8f7 100644--- a/kernel/cli/cmd/asset.go+++ b/kernel/cli/cmd/asset.go@@ -60,7 +60,7 @@ var assetUploadCmd = &cobra.Command{return nil}- succMap, err := model.InsertLocalAssets(id, files, true)+ succMap, _, err := model.InsertLocalAssets(id, files, true)if err != nil {return err}diff --git a/kernel/mcp/tools/asset.go b/kernel/mcp/tools/asset.goindex 1dae705ca9..004218bbc8 100644--- a/kernel/mcp/tools/asset.go+++ b/kernel/mcp/tools/asset.go@@ -207,15 +207,15 @@ func assetUpload(args map[string]any) (CallToolResult, error) {return CallToolResult{Content: []ContentItem{{Type: "text", Text: "invalid asset path: " + err.Error()}}, IsError: true}, nil}- succMap, err := model.InsertLocalAssets(id, fileList, true)+ _, succFiles, err := model.InsertLocalAssets(id, fileList, true)if err != nil {return CallToolResult{Content: []ContentItem{{Type: "text", Text: "upload assets failed: " + err.Error()}}, IsError: true}, nil}var sb strings.Builder- sb.WriteString(fmt.Sprintf("Uploaded %d file(s):\n\n", len(succMap)))- for k, v := range succMap {- sb.WriteString(fmt.Sprintf("- %s -> %v\n", k, v))+ sb.WriteString(fmt.Sprintf("Uploaded %d file(s):\n\n", len(succFiles)))+ for _, result := range succFiles {+ sb.WriteString(fmt.Sprintf("- %s -> %s\n", result.Name, result.Path))}return CallToolResult{Content: []ContentItem{{Type: "text", Text: sb.String()}}}, nil}diff --git a/kernel/model/upload.go b/kernel/model/upload.goindex af70c1a144..a1ae3bc8a0 100644--- a/kernel/model/upload.go+++ b/kernel/model/upload.go@@ -94,8 +94,22 @@ func InsertAssetBytes(id, fileName string, data []byte) (assetPath string, creatreturn assetPath, true, nil}-func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMap map[string]any, err error) {+// AssetUploadSuccess 记录单个输入文件的成功上传结果。+type AssetUploadSuccess struct {+ Index int `json:"index"`+ Name string `json:"name"`+ Path string `json:"path"`+}++func recordAssetUploadSuccess(succMap map[string]any, succFiles *[]AssetUploadSuccess, index int, name, assetPath string) {+ succMap[name] = assetPath+ *succFiles = append(*succFiles, AssetUploadSuccess{Index: index, Name: name, Path: assetPath})+}++func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMap map[string]any,+ succFiles []AssetUploadSuccess, err error) {succMap = map[string]any{}+ succFiles = make([]AssetUploadSuccess, 0, len(assetAbsPaths))bt := treenode.GetBlockTree(id)if nil == bt {@@ -111,7 +125,7 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMa}}- for _, assetAbsPath := range assetAbsPaths {+ for index, assetAbsPath := range assetAbsPaths {baseName := filepath.Base(assetAbsPath)fName := baseNamefName = util.FilterUploadFileName(fName)@@ -123,14 +137,14 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMaif !strings.HasPrefix(assetAbsPath, "\\\\") {assetAbsPath = "file://" + assetAbsPath}- succMap[baseName] = assetAbsPath+ recordAssetUploadSuccess(succMap, &succFiles, index, baseName, assetAbsPath)continue}if gulu.File.IsSubPath(assetsDirPath, assetAbsPath) {// 已经位于 assets 目录下的资源文件不处理// Dragging a file from the assets folder into the editor causes the kernel to exit https://github.com/siyuan-note/siyuan/issues/15355- succMap[baseName] = "assets/" + baseName+ recordAssetUploadSuccess(succMap, &succFiles, index, baseName, "assets/"+baseName)continue}@@ -164,7 +178,7 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMa}if "" != existAssetPath && !strings.HasPrefix(hash, "random_") {- succMap[baseName] = strings.TrimPrefix(existAssetPath, "/")+ recordAssetUploadSuccess(succMap, &succFiles, index, baseName, strings.TrimPrefix(existAssetPath, "/"))f.Close()} else {blockID := ast.NewNodeID()@@ -189,7 +203,7 @@ func InsertLocalAssets(id string, assetAbsPaths []string, isUpload bool) (succMaif IsEncryptedBox(bt.BoxID) {p += "?box=" + bt.BoxID}- succMap[baseName] = p+ recordAssetUploadSuccess(succMap, &succFiles, index, baseName, p)if !IsEncryptedBox(bt.BoxID) {cache.SetAssetHash(hash, p) // 加密笔记本不写全局 cache,避免跨边界去重污染}@@ -259,12 +273,13 @@ func Upload(c *gin.Context) {var errFiles []stringsuccMap := map[string]any{}files := form.File["file[]"]+ succFiles := make([]AssetUploadSuccess, 0, len(files))skipIfDuplicated := false // 默认不跳过重复文件,但是有的场景需要跳过,比如上传 PDF 标注图片 https://github.com/siyuan-note/siyuan/issues/10666if nil != form.Value["skipIfDuplicated"] {skipIfDuplicated = "true" == form.Value["skipIfDuplicated"][0]}- for _, file := range files {+ for index, file := range files {baseName := file.Filename_, lastID := util.LastID(baseName)if !ast.IsNodeIDPattern(lastID) {@@ -318,7 +333,7 @@ func Upload(c *gin.Context) {}if "" != existAssetPath && !strings.HasPrefix(hash, "random_") {- succMap[baseName] = strings.TrimPrefix(existAssetPath, "/")+ recordAssetUploadSuccess(succMap, &succFiles, index, baseName, strings.TrimPrefix(existAssetPath, "/"))f.Close()} else {if skipIfDuplicated {@@ -338,7 +353,8 @@ func Upload(c *gin.Context) {} else {if 0 < len(matches) {fName = filepath.Base(matches[0])- succMap[baseName] = strings.TrimPrefix(path.Join(relAssetsDirPath, fName), "/")+ recordAssetUploadSuccess(succMap, &succFiles, index, baseName,+ strings.TrimPrefix(path.Join(relAssetsDirPath, fName), "/"))f.Close()break}@@ -439,7 +455,7 @@ func Upload(c *gin.Context) {if uploadBoxID != "" && IsEncryptedBox(uploadBoxID) {p += "?box=" + uploadBoxID}- succMap[baseName] = p+ recordAssetUploadSuccess(succMap, &succFiles, index, baseName, p)if uploadBoxID == "" || !IsEncryptedBox(uploadBoxID) {cache.SetAssetHash(hash, p) // 加密笔记本不写全局 cache}@@ -447,8 +463,9 @@ func Upload(c *gin.Context) {}ret.Data = map[string]any{- "errFiles": errFiles,- "succMap": succMap,+ "errFiles": errFiles,+ "succFiles": succFiles,+ "succMap": succMap,}IncSync()diff --git a/kernel/model/upload_test.go b/kernel/model/upload_test.gonew file mode 100644index 0000000000..60ca08bad4--- /dev/null+++ b/kernel/model/upload_test.go@@ -0,0 +1,39 @@+// SiYuan - From thought to insight, with agents+// Copyright (c) 2020-present, b3log.org+//+// This program is free software: you can redistribute it and/or modify+// it under the terms of the GNU Affero General Public License as published by+// the Free Software Foundation, either version 3 of the License, or+// (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU Affero General Public License for more details.+//+// You should have received a copy of the GNU Affero General Public License+// along with this program. If not, see <https://www.gnu.org/licenses/>.++package model++import "testing"++func TestRecordAssetUploadSuccessPreservesDuplicateNames(t *testing.T) {+ succMap := map[string]any{}+ var succFiles []AssetUploadSuccess+ recordAssetUploadSuccess(succMap, &succFiles, 0, "image.png", "assets/image-first.png")+ recordAssetUploadSuccess(succMap, &succFiles, 1, "image.png", "assets/image-second.png")++ if len(succFiles) != 2 {+ t.Fatalf("expected two successful files, got %d", len(succFiles))+ }+ if succFiles[0].Index != 0 || succFiles[0].Path != "assets/image-first.png" {+ t.Fatalf("unexpected first successful file: %+v", succFiles[0])+ }+ if succFiles[1].Index != 1 || succFiles[1].Path != "assets/image-second.png" {+ t.Fatalf("unexpected second successful file: %+v", succFiles[1])+ }+ if succMap["image.png"] != "assets/image-second.png" {+ t.Fatalf("legacy success map should retain the latest path, got %v", succMap["image.png"])+ }+}