diff --git a/Sources/WeiBei/Stores/CourseProjectRootSupport.swift b/Sources/WeiBei/Stores/CourseProjectRootSupport.swift index 58274bb57..d262e7543 100644 --- a/Sources/WeiBei/Stores/CourseProjectRootSupport.swift +++ b/Sources/WeiBei/Stores/CourseProjectRootSupport.swift @@ -277,8 +277,8 @@ enum CoursePortableExportError: LocalizedError { switch self { case .unstableCourseState: return "这门课程仍有回答、笔记或动作尚未保存。请先等待完成或中断,再继续。" - case let .invalidSourceEntry(path, reason): - return "课程内容“\(path)”无法安全导出:\(reason)" + case let .invalidSourceEntry(path, _): + return "课程内容“\(path)”无法导出,未生成导出文件。请确认该文件仍可在 Finder 中打开,然后重试。" } } } diff --git a/Sources/WeiBei/Stores/WorkspaceStore.swift b/Sources/WeiBei/Stores/WorkspaceStore.swift index 19a6cd48c..7f87847b9 100644 --- a/Sources/WeiBei/Stores/WorkspaceStore.swift +++ b/Sources/WeiBei/Stores/WorkspaceStore.swift @@ -3368,15 +3368,11 @@ final class WorkspaceStore: ObservableObject { sourceInfo = try await courseProjectFileWorker .validatedRegularSource(sharedURL) } catch { - // 源文件真没了:跳过该项,不中止整次导出。 - continue - } - // S3:身份漂移可容忍则静默继续。 - let identityOK = item.importedFileIdentity.map { - $0.matchesAcrossVolumeDrift(sourceInfo.identity) - } ?? true - if !identityOK { - continue + WeiBeiLog.workspace.error("code=course_export_source_unavailable stage=validate underlying=\(WeiBeiLog.code(error), privacy: .public) path=\(sharedURL.path, privacy: .private) reason=\(WeiBeiLog.truncated(error.localizedDescription), privacy: .private)") + throw CoursePortableExportError.invalidSourceEntry( + path: state.items[index].courseRelativePath, + reason: error.localizedDescription + ) } let sourceSnapshot: CourseFileSnapshot do { @@ -3386,7 +3382,11 @@ final class WorkspaceStore: ObservableObject { expectedIdentity: sourceInfo.identity ) } catch { - continue + WeiBeiLog.workspace.error("code=course_export_source_unavailable stage=snapshot underlying=\(WeiBeiLog.code(error), privacy: .public) path=\(sourceInfo.url.path, privacy: .private) reason=\(WeiBeiLog.truncated(error.localizedDescription), privacy: .private)") + throw CoursePortableExportError.invalidSourceEntry( + path: state.items[index].courseRelativePath, + reason: error.localizedDescription + ) } // digest 不一致时仍以磁盘现状导出(S3 静默降级;S6-9 可再收紧日志)。 _ = expectedContentDigest diff --git a/Tests/WeiBeiSafetyTests/CourseProjectRootSelfCheck.swift b/Tests/WeiBeiSafetyTests/CourseProjectRootSelfCheck.swift index 4d27b45d9..615836fc0 100644 --- a/Tests/WeiBeiSafetyTests/CourseProjectRootSelfCheck.swift +++ b/Tests/WeiBeiSafetyTests/CourseProjectRootSelfCheck.swift @@ -4964,6 +4964,42 @@ enum CourseProjectRootSelfCheck { ) ) } + + let missingSharedTarget = exportParent.appendingPathComponent( + "共享原件缺失", + isDirectory: true + ) + let missingSharedStagingBefore = try stagingNames() + try FileManager.default.removeItem(at: sharedSourceURL) + do { + _ = try store.exportPortableCourseCopyForSelfCheck( + courseID: courseA, + to: missingSharedTarget + ) + throw CheckError.failed("共享原件缺失仍完成导出") + } catch let error as CoursePortableExportError { + guard case let .invalidSourceEntry(path, reason) = error else { + throw CheckError.failed("共享原件缺失返回了错误的导出错误") + } + try check( + path == sharedPortableItem.courseRelativePath + && !reason.isEmpty + && error.localizedDescription.contains(path) + && !error.localizedDescription.contains(reason) + && !error.localizedDescription.contains( + sharedSourceURL.path + ), + "共享原件缺失错误没有安全指向课程相对文件" + ) + } + try check( + !missingSharedTarget.exists + && !missingSharedTarget.appendingPathComponent( + ".weibei/\(CourseProjectManifest.portableExportCompletionFileName)" + ).exists + && (try stagingNames()) == missingSharedStagingBefore, + "共享原件缺失仍留下了目标、成功标记或暂存" + ) } @MainActor