Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Sources/WeiBei/Stores/CourseProjectRootSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 中打开,然后重试。"
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/WeiBei/Stores/WorkspaceStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
36 changes: 36 additions & 0 deletions Tests/WeiBeiSafetyTests/CourseProjectRootSelfCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down