feat: M5 端到端+3 缺陷修复+文档
This commit is contained in:
@@ -435,6 +435,8 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
||||
// 回归测试:发布模式切换(草稿/正式)
|
||||
addAction("com.haorui.app.ACTION_SET_DRAFT")
|
||||
addAction("com.haorui.app.ACTION_SET_PUBLISH")
|
||||
// M5 跨平台视频草稿车道端到端(debug APK:管线→桥→旧发布器→草稿箱)
|
||||
addAction("com.haorui.app.ACTION_TEST_CROSS_VIDEO")
|
||||
}
|
||||
@Suppress("UnspecifiedRegisterReceiverFlag")
|
||||
registerReceiver(cmdReceiver, filter)
|
||||
@@ -678,6 +680,11 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
||||
val accepted = startArticleMachineVerify(title, body)
|
||||
RunLogger.i(TAG, "文章验证受理=$accepted(广播 ACTION_TEST_ARTICLE title=$title bodyLen=${body.length})")
|
||||
}
|
||||
// M5 跨平台视频草稿车道端到端:夹具经管线(导入→校验→许可→桥)→旧发布器
|
||||
"com.haorui.app.ACTION_TEST_CROSS_VIDEO" -> {
|
||||
val accepted = startCrossVideoDraftSandbox()
|
||||
RunLogger.i(TAG, "跨平台视频草稿沙盒受理=$accepted(广播 ACTION_TEST_CROSS_VIDEO)")
|
||||
}
|
||||
// 回归测试发布模式切换(草稿/正式;autoPublish 无 UI 开关,走广播)
|
||||
"com.haorui.app.ACTION_SET_DRAFT" -> setAutoPublish(false)
|
||||
"com.haorui.app.ACTION_SET_PUBLISH" -> setAutoPublish(true)
|
||||
@@ -764,6 +771,74 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
||||
accepted
|
||||
}
|
||||
|
||||
/**
|
||||
* M5 跨平台视频草稿车道端到端(仅调试 APK):自有测试视频经**完整管线**
|
||||
* (SourceMediaProvider 导入→VideoFileValidator 校验→许可→CrossVideoPipeline 加工)
|
||||
* → VideoTaskBridge 桥接 → 旧 PublishMachine 草稿车道 → 草稿箱核对。
|
||||
*
|
||||
* 与 [startDraftSandbox] 的区别:素材走新链路加工(校验/许可/署名编排全跑),
|
||||
* 标题与递交来自管线成品而非直接 submit——M5 最终验收门槛。
|
||||
*
|
||||
* 素材来源:App 外部私有目录 `m5-fixture.mp4`(adb push,分区存储下无需权限;
|
||||
* MediaStore 生产导入待授权后单独验收)。门控同草稿沙盒:debug-only、
|
||||
* 调度器空闲、草稿模式、新模块总开关不校验(沙盒独立于正式入口)。
|
||||
*/
|
||||
fun startCrossVideoDraftSandbox(): Boolean = synchronized(stepLifecycleLock) {
|
||||
if (applicationInfo.flags and android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE == 0 ||
|
||||
!::scheduler.isInitialized || scheduler.isRunning || publisher.isWorking || interactor.isWorking ||
|
||||
frontGuard.creditNavigating || !foregroundCoordinator.isIdle() || latestConfig.toutiao.autoPublish ||
|
||||
runCatching { videoDownloader.hasPendingDrafts() }.getOrDefault(true)) return@synchronized false
|
||||
val fixture = java.io.File(getExternalFilesDir(null), "m5-fixture.mp4")
|
||||
if (!fixture.exists() || fixture.length() <= 0) {
|
||||
RunLogger.w(TAG, "M5 草稿沙盒:夹具缺失(adb push 到 ${fixture.absolutePath})")
|
||||
return@synchronized false
|
||||
}
|
||||
val logs = mutableListOf<String>()
|
||||
try {
|
||||
// ── 完整管线 ──────────────────────────────────────
|
||||
val provider = com.haorui.app.crossplatform.media.SourceMediaProvider(this) { msg ->
|
||||
RunLogger.i(TAG, "M5-Provider: $msg"); logs.add(msg)
|
||||
}
|
||||
val imported = provider.importFrom(android.net.Uri.fromFile(fixture), "haorui-m5-e2e")
|
||||
if (imported !is com.haorui.app.crossplatform.media.SourceMediaProvider.Result.Imported) {
|
||||
RunLogger.w(TAG, "M5 草稿沙盒:导入失败 ${(imported as com.haorui.app.crossplatform.media.SourceMediaProvider.Result.Rejected).reason}")
|
||||
return@synchronized false
|
||||
}
|
||||
// 许可:测试夹具登记为自有素材(沙盒专用,不进生产许可库)
|
||||
val licenseStore = com.haorui.app.crossplatform.media.MediaLicenseStore()
|
||||
licenseStore.registerOwn("sandbox-account", "M5 草稿沙盒自有素材")
|
||||
val pipeline = com.haorui.app.crossplatform.media.CrossVideoPipeline(licenseStore) { msg ->
|
||||
RunLogger.i(TAG, "M5-Pipeline: $msg"); logs.add(msg)
|
||||
}
|
||||
val title = "浩瑞跨平台视频草稿 ${java.util.UUID.randomUUID().toString().take(8)}"
|
||||
val outcome = pipeline.prepare(
|
||||
imported.localPath, "sandbox-account", null,
|
||||
title, null, System.currentTimeMillis(),
|
||||
)
|
||||
val prepared = outcome.prepared
|
||||
if (prepared == null) {
|
||||
RunLogger.w(TAG, "M5 草稿沙盒:管线拒绝 ${outcome.reason}")
|
||||
return@synchronized false
|
||||
}
|
||||
// ── 桥接 → 旧发布器(草稿车道)─────────────────────
|
||||
// 声明经 declarationOverride 透传(绕开旧配置"内容为原创"——M0 已知问题)
|
||||
val bridge = com.haorui.app.crossplatform.media.VideoTaskBridge({ t, uri, auto, decl ->
|
||||
publisher.submit(t, uri, autoPublish = auto, declaration = decl)
|
||||
}) { msg -> RunLogger.i(TAG, "M5-Bridge: $msg") }
|
||||
val bridged = bridge.bridge(prepared, declarationOverride = "内容无需标注")
|
||||
if (bridged !is com.haorui.app.crossplatform.media.VideoTaskBridge.Result.Submitted) {
|
||||
RunLogger.w(TAG, "M5 草稿沙盒:桥接拒绝 ${(bridged as com.haorui.app.crossplatform.media.VideoTaskBridge.Result.Rejected).reason}")
|
||||
return@synchronized false
|
||||
}
|
||||
scheduler.startLaneOnly(LaneScheduler.Lane.PUBLISH)
|
||||
RunLogger.i(TAG, "M5 草稿沙盒受理:标题「$title」素材=${prepared.localPath} sha=${prepared.sha256.take(12)}…")
|
||||
true
|
||||
} catch (t: Throwable) {
|
||||
RunLogger.e(TAG, "M5 草稿沙盒异常: ${t.javaClass.simpleName}:${t.message}", t)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅调试 APK 的知乎单候选采集沙盒(端到端真机验收)。
|
||||
* 只读采集、不发布、不启动调度器——WATCHDOG(恢复链)不运行,
|
||||
|
||||
@@ -617,8 +617,14 @@ class PublishMachine(
|
||||
if (!declarationVerified || !draftEditorMatches(fresh)) { pauseForReview("草稿标题或声明已变化,未发送"); return }
|
||||
val button = NodeLocator.byId(fresh, ToutiaoSelectors.ID_PUB_DRAFT) ?: return
|
||||
try {
|
||||
val id = try { videoDownloader?.beginDraft(mediaUri, title, declaration) }
|
||||
catch (failure: Exception) { log("草稿意图保存失败:${failure.javaClass.simpleName}"); null }
|
||||
// M5:跨平台素材(crossplatform/video 目录)用放宽版登记——待核对保护语义一致
|
||||
val id = try {
|
||||
if (videoDownloader?.isCrossPlatformMedia(mediaUri) == true) {
|
||||
videoDownloader.beginDraftCrossPlatform(mediaUri, title, declaration)
|
||||
} else {
|
||||
videoDownloader?.beginDraft(mediaUri, title, declaration)
|
||||
}
|
||||
} catch (failure: Exception) { log("草稿意图保存失败:${failure.javaClass.simpleName}"); null }
|
||||
if (id == null) { pauseForReview("草稿意图无法保存,未点击存草稿"); return }
|
||||
draftAttemptId = id
|
||||
receiptWaitStartMs = SystemClock.elapsedRealtime()
|
||||
|
||||
@@ -21,10 +21,13 @@ class VideoTaskBridge(
|
||||
private val logger: (String) -> Unit = {},
|
||||
) {
|
||||
|
||||
/** 旧发布器最小接口(真机绑定 PublishMachine;测试注入假实现)。 */
|
||||
/** 旧发布器最小接口(真机绑定 PublishMachine.submit;测试注入假实现)。 */
|
||||
fun interface Publisher {
|
||||
/** 与 PublishMachine.submit 同语义:false=拒绝(非空闲/门控拦截)。 */
|
||||
fun submit(title: String, mediaUri: String, autoPublish: Boolean): Boolean
|
||||
/**
|
||||
* 与 PublishMachine.submit 同语义:false=拒绝(非空闲/门控拦截)。
|
||||
* @param declaration 作品声明(草稿沙盒显式传"内容无需标注"绕开旧配置;null=用发布器默认)。
|
||||
*/
|
||||
fun submit(title: String, mediaUri: String, autoPublish: Boolean, declaration: String?): Boolean
|
||||
}
|
||||
|
||||
/** 桥接结果。 */
|
||||
@@ -39,10 +42,12 @@ class VideoTaskBridge(
|
||||
* 把加工成品递交给旧发布器(仅草稿)。
|
||||
* @param prepared 管线成品(CrossVideoPipeline.prepare 产出)。
|
||||
* @param publishPageSupportsAttribution 发布页是否已取证可署名——首版恒 false。
|
||||
* @param declarationOverride 递交时的作品声明覆盖(null=发布器默认配置)。
|
||||
*/
|
||||
fun bridge(
|
||||
prepared: CrossVideoPipeline.PreparedVideo,
|
||||
publishPageSupportsAttribution: Boolean = false,
|
||||
declarationOverride: String? = null,
|
||||
): Result {
|
||||
// ① 署名前置检查:需署名且发布页无法填写 → 跳过(不静默放行不合规转载)
|
||||
if (prepared.needsAttribution && !publishPageSupportsAttribution) {
|
||||
@@ -62,7 +67,8 @@ class VideoTaskBridge(
|
||||
}
|
||||
// ③ 递交(草稿车道;autoPublish=false 由本桥硬编码——新链路首版 DRY_RUN)。
|
||||
// 旧发布器只有标题输入;简介/署名段暂以标题行承载(首行),完整简介控件待取证。
|
||||
val ok = publisher.submit(titleOf(prepared), prepared.localPath, autoPublish = false)
|
||||
// 声明经 [declarationOverride] 透传(沙盒显式传值绕开旧配置;默认 null=发布器默认)。
|
||||
val ok = publisher.submit(titleOf(prepared), prepared.localPath, autoPublish = false, declaration = declarationOverride)
|
||||
if (!ok) {
|
||||
return Result.Rejected("发布器拒绝(非空闲或门控拦截)")
|
||||
}
|
||||
|
||||
@@ -46,11 +46,27 @@ class VideoDownloader(private val context: Context) {
|
||||
|
||||
private val pendingDrafts = PendingDraftStore(File(context.filesDir, "pending-drafts"))
|
||||
|
||||
/** 跨平台素材导入目录(M5 SourceMediaProvider 落盘处;与 videoDir 同受待核对保护)。 */
|
||||
private val crossVideoDir: File = File(context.filesDir, "crossplatform/video")
|
||||
|
||||
fun beginDraft(path: String, title: String, declaration: String): String {
|
||||
check(File(path).canonicalFile.parentFile == videoDir.canonicalFile) { "草稿素材不在下载目录" }
|
||||
return pendingDrafts.begin(path, title, declaration).id
|
||||
}
|
||||
|
||||
/**
|
||||
* 跨平台素材的草稿意图登记(M5,2026-11-15):素材在 crossplatform 导入目录也接受。
|
||||
* 与 [beginDraft] 同用 PendingDraftStore(待核对保护语义一致);目录校验放宽为
|
||||
* 旧下载目录**或** crossplatform/video——仍防任意路径注入,非放开。
|
||||
*/
|
||||
fun beginDraftCrossPlatform(path: String, title: String, declaration: String): String {
|
||||
val parent = runCatching { File(path).canonicalFile.parentFile }.getOrNull()
|
||||
check(parent == videoDir.canonicalFile || parent == crossVideoDir.canonicalFile) {
|
||||
"草稿素材不在受管目录(videoDir/crossplatform)"
|
||||
}
|
||||
return pendingDrafts.begin(path, title, declaration).id
|
||||
}
|
||||
|
||||
fun confirmDraft(id: String): Boolean = pendingDrafts.confirm(id)
|
||||
|
||||
fun hasPendingDrafts(): Boolean = pendingDrafts.attempts().isNotEmpty()
|
||||
@@ -59,6 +75,11 @@ class VideoDownloader(private val context: Context) {
|
||||
File(path).isFile && File(path).canonicalFile.parentFile == videoDir.canonicalFile
|
||||
}.getOrDefault(false)
|
||||
|
||||
/** 素材是否为跨平台导入目录(M5;beginDraftCrossPlatform 的路径判定用)。 */
|
||||
fun isCrossPlatformMedia(path: String): Boolean = runCatching {
|
||||
File(path).isFile && File(path).canonicalFile.parentFile == crossVideoDir.canonicalFile
|
||||
}.getOrDefault(false)
|
||||
|
||||
/**
|
||||
* 已下载内容的 SHA-256 集合(内容级去重)。
|
||||
* ⚠️ 并发安全:管线多协程可能并行下载/查重(第一性审计)→ 线程安全 Set。
|
||||
|
||||
@@ -13,6 +13,11 @@
|
||||
name="internal_videos"
|
||||
path="videos/" />
|
||||
|
||||
<!-- M5 跨平台视频素材(SourceMediaProvider 导入目录 filesDir/crossplatform/video/) -->
|
||||
<files-path
|
||||
name="crossplatform_video"
|
||||
path="crossplatform/" />
|
||||
|
||||
<!-- 日志导出(LogExporter.generateExportFile → cacheDir/export/) -->
|
||||
<cache-path
|
||||
name="export"
|
||||
|
||||
Reference in New Issue
Block a user