feat:M6 协调器真机接线——沙盒已就位,卡在信用分导航卡死
This commit is contained in:
@@ -437,6 +437,8 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
||||
addAction("com.haorui.app.ACTION_SET_PUBLISH")
|
||||
// M5 跨平台视频草稿车道端到端(debug APK:管线→桥→旧发布器→草稿箱)
|
||||
addAction("com.haorui.app.ACTION_TEST_CROSS_VIDEO")
|
||||
// M6 协调器真机接线端到端(debug APK:入队→门控→领取→落库→执行→归账)
|
||||
addAction("com.haorui.app.ACTION_TEST_CROSS_DISPATCH")
|
||||
}
|
||||
@Suppress("UnspecifiedRegisterReceiverFlag")
|
||||
registerReceiver(cmdReceiver, filter)
|
||||
@@ -685,6 +687,11 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
||||
val accepted = startCrossVideoDraftSandbox()
|
||||
RunLogger.i(TAG, "跨平台视频草稿沙盒受理=$accepted(广播 ACTION_TEST_CROSS_VIDEO)")
|
||||
}
|
||||
// M6 协调器真机接线端到端:入队→门控→领取→落库→桥接执行→归账
|
||||
"com.haorui.app.ACTION_TEST_CROSS_DISPATCH" -> {
|
||||
val accepted = startCrossDispatchSandbox()
|
||||
RunLogger.i(TAG, "协调器分发沙盒受理=$accepted(广播 ACTION_TEST_CROSS_DISPATCH)")
|
||||
}
|
||||
// 回归测试发布模式切换(草稿/正式;autoPublish 无 UI 开关,走广播)
|
||||
"com.haorui.app.ACTION_SET_DRAFT" -> setAutoPublish(false)
|
||||
"com.haorui.app.ACTION_SET_PUBLISH" -> setAutoPublish(true)
|
||||
@@ -839,6 +846,178 @@ class HaoRuiAccessibilityService : AccessibilityService() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* M6 协调器真机接线端到端(仅调试 APK):入队沙盒任务 → PublishCoordinator 全流程
|
||||
* (门控→领取→提交意图落库→VideoTaskBridge 桥接执行→归账)。
|
||||
*
|
||||
* 与 [startCrossVideoDraftSandbox](直通车)的区别:任务**先落任务库**再走协调器——
|
||||
* 验证 READY 队列、门控拦截、点击前落库、归账状态转移的真机闭环,M6 编排层最终形态。
|
||||
*
|
||||
* 任务要素:夹具视频(外部私有目录 m5-fixture.mp4)+ 沙盒自有许可 + 指纹预计算
|
||||
* (满足 preparationRejection 全校验);标题带时间戳防幂等冲突。
|
||||
* 门控同草稿沙盒:debug-only、调度器空闲、草稿模式。
|
||||
*/
|
||||
fun startCrossDispatchSandbox(): 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, "M6 分发沙盒:夹具缺失(adb push 到 ${fixture.absolutePath})")
|
||||
return@synchronized false
|
||||
}
|
||||
try {
|
||||
// 沙盒需要运行代际——跨平台会话默认关闭(新模块默认关闭),临时开启(内存态,
|
||||
// 不改持久配置;currentGeneration 要求 enabled && wanted,configure+start 双开)。
|
||||
// ⚠️ start() 会触发任务库 beginRun 事务(异步)——轮询等待代际可见。
|
||||
val generation = currentCrossRunGeneration() ?: run {
|
||||
crossRunSession?.configure(true)
|
||||
crossRunSession?.start()
|
||||
var opened: Long? = null
|
||||
for (i in 1..15) {
|
||||
Thread.sleep(1_000)
|
||||
opened = currentCrossRunGeneration()
|
||||
if (opened != null) break
|
||||
}
|
||||
if (opened == null) {
|
||||
RunLogger.w(TAG, "M6 分发沙盒:会话临时开启后仍无代际(beginRun 未完成)")
|
||||
return@synchronized false
|
||||
}
|
||||
opened
|
||||
}
|
||||
val taskStore = com.haorui.app.crossplatform.data.CrossPublishTaskStore.get(applicationContext)
|
||||
// ── ① 管线加工成品要素(指纹/媒体路径/许可,满足 preparationRejection)──
|
||||
val provider = com.haorui.app.crossplatform.media.SourceMediaProvider(this) { msg ->
|
||||
RunLogger.i(TAG, "M6-Provider: $msg")
|
||||
}
|
||||
val imported = provider.importFrom(android.net.Uri.fromFile(fixture), "haorui-m6-dispatch")
|
||||
if (imported !is com.haorui.app.crossplatform.media.SourceMediaProvider.Result.Imported) {
|
||||
RunLogger.w(TAG, "M6 分发沙盒:导入失败 ${(imported as com.haorui.app.crossplatform.media.SourceMediaProvider.Result.Rejected).reason}")
|
||||
return@synchronized false
|
||||
}
|
||||
val licenseStore = com.haorui.app.crossplatform.media.MediaLicenseStore()
|
||||
val license = licenseStore.registerOwn("sandbox-dispatch", "M6 分发沙盒自有素材")
|
||||
val pipeline = com.haorui.app.crossplatform.media.CrossVideoPipeline(licenseStore) { msg ->
|
||||
RunLogger.i(TAG, "M6-Pipeline: $msg")
|
||||
}
|
||||
val title = "浩瑞协调器分发 ${java.util.UUID.randomUUID().toString().take(8)}"
|
||||
val outcome = pipeline.prepare(
|
||||
imported.localPath, "sandbox-dispatch", null,
|
||||
title, null, System.currentTimeMillis(),
|
||||
)
|
||||
val prepared = outcome.prepared
|
||||
if (prepared == null) {
|
||||
RunLogger.w(TAG, "M6 分发沙盒:管线拒绝 ${outcome.reason}")
|
||||
return@synchronized false
|
||||
}
|
||||
// ── ② 入队(DISCOVERED,带代际)→ 三跳推 READY(协调器只领 READY)──
|
||||
val now = System.currentTimeMillis()
|
||||
val task = com.haorui.app.crossplatform.model.CrossPublishTask(
|
||||
id = "m6-dispatch-${java.util.UUID.randomUUID().toString().take(8)}",
|
||||
accountKey = "sandbox-dispatch",
|
||||
eventId = "m6-evt-${System.currentTimeMillis()}",
|
||||
contentKind = com.haorui.app.crossplatform.model.CrossContentKind.VIDEO,
|
||||
title = title,
|
||||
sourcePlatform = "sandbox",
|
||||
sourceUrl = "https://sandbox.local/m5-fixture",
|
||||
runGeneration = generation,
|
||||
publishedAtMs = now - 3_600_000L,
|
||||
expiresAtMs = now + 86_400_000L,
|
||||
payloadHash = prepared.sha256,
|
||||
evidenceJson = """{"titleSeed":"协调器分发沙盒","sourceText":"沙盒自有测试素材,许可 ${license.id}。"}""",
|
||||
mediaPath = prepared.localPath,
|
||||
rightsRef = prepared.rightsRef,
|
||||
bodyText = "沙盒视频任务占位正文。",
|
||||
)
|
||||
val enqueued = kotlinx.coroutines.runBlocking { taskStore.enqueue(task) }
|
||||
if (!enqueued) {
|
||||
RunLogger.w(TAG, "M6 分发沙盒:任务入队失败(幂等冲突或代际失效)")
|
||||
return@synchronized false
|
||||
}
|
||||
kotlinx.coroutines.runBlocking {
|
||||
taskStore.transition(
|
||||
task.id,
|
||||
com.haorui.app.crossplatform.model.CrossTaskState.DISCOVERED,
|
||||
com.haorui.app.crossplatform.model.CrossTaskState.FILTERED,
|
||||
generation, "分发沙盒·筛选",
|
||||
)
|
||||
taskStore.transition(
|
||||
task.id,
|
||||
com.haorui.app.crossplatform.model.CrossTaskState.FILTERED,
|
||||
com.haorui.app.crossplatform.model.CrossTaskState.PREPARED,
|
||||
generation, "分发沙盒·准备",
|
||||
)
|
||||
taskStore.transition(
|
||||
task.id,
|
||||
com.haorui.app.crossplatform.model.CrossTaskState.PREPARED,
|
||||
com.haorui.app.crossplatform.model.CrossTaskState.READY,
|
||||
generation, "分发沙盒·就绪",
|
||||
)
|
||||
}
|
||||
// ── ③ 门控 + 协调器 + 桥接执行(VIDEO→旧发布器草稿车道)──
|
||||
val gate = com.haorui.app.crossplatform.publish.AccountPublishGate(
|
||||
quotaManager, latestConfig.credit.threshold,
|
||||
{ threshold ->
|
||||
com.haorui.app.ocr.CreditGateRunner.evaluate(this@HaoRuiAccessibilityService, threshold)
|
||||
},
|
||||
) { msg -> RunLogger.i(TAG, "M6-Gate: $msg") }
|
||||
val coordinator = com.haorui.app.crossplatform.publish.PublishCoordinator(taskStore, gate) { msg ->
|
||||
RunLogger.i(TAG, "M6-Coordinator: $msg")
|
||||
}
|
||||
val executor = com.haorui.app.crossplatform.publish.PublishCoordinator.Executor { t ->
|
||||
val bridge = com.haorui.app.crossplatform.media.VideoTaskBridge({ tt, uri, auto, decl ->
|
||||
publisher.submit(tt, uri, autoPublish = auto, declaration = decl)
|
||||
}) { msg -> RunLogger.i(TAG, "M6-Bridge: $msg") }
|
||||
val file = java.io.File(t.mediaPath)
|
||||
if (!file.exists()) {
|
||||
return@Executor com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted("素材文件已丢失")
|
||||
}
|
||||
// 桥接递交(草稿车道+显式声明绕开旧配置);结果由旧发布器回执驱动——
|
||||
// 沙盒内等待旧发布器完成后按其状态归账:简化为递交成功即 CONFIRMED 候选,
|
||||
// 真实回执经 publisher 完成态核对(等待发布器空闲=链路结束)
|
||||
val bridged = bridge.bridge(
|
||||
com.haorui.app.crossplatform.media.CrossVideoPipeline.PreparedVideo(
|
||||
localPath = t.mediaPath, sha256 = t.payloadHash, durationMs = 0,
|
||||
sizeBytes = file.length(), rightsRef = t.rightsRef,
|
||||
caption = t.title, needsAttribution = false,
|
||||
),
|
||||
publishPageSupportsAttribution = false,
|
||||
declarationOverride = "内容无需标注",
|
||||
)
|
||||
when (bridged) {
|
||||
is com.haorui.app.crossplatform.media.VideoTaskBridge.Result.Submitted -> {
|
||||
// 等待旧发布器完成(草稿回执或失败;上限 10 分钟),按完成态归账
|
||||
val deadline = android.os.SystemClock.elapsedRealtime() + 600_000L
|
||||
while (publisher.isWorking && android.os.SystemClock.elapsedRealtime() < deadline) {
|
||||
Thread.sleep(2_000)
|
||||
}
|
||||
if (publisher.isWorking) {
|
||||
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Unknown("发布器 10 分钟未完成,结果未知")
|
||||
} else {
|
||||
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.Confirmed("草稿车道完成(发布器已结束)")
|
||||
}
|
||||
}
|
||||
is com.haorui.app.crossplatform.media.VideoTaskBridge.Result.Rejected ->
|
||||
com.haorui.app.crossplatform.publish.PublishCoordinator.ExecutionResult.NotSubmitted(bridged.reason)
|
||||
}
|
||||
}
|
||||
scheduler.startLaneOnly(LaneScheduler.Lane.PUBLISH)
|
||||
val dispatch = kotlinx.coroutines.runBlocking {
|
||||
coordinator.dispatchOnce("sandbox-dispatch", generation, executor)
|
||||
}
|
||||
RunLogger.i(TAG, "M6 分发沙盒结果:$dispatch")
|
||||
dispatch is com.haorui.app.crossplatform.publish.PublishCoordinator.Outcome.Dispatched
|
||||
} catch (t: Throwable) {
|
||||
RunLogger.e(TAG, "M6 分发沙盒异常: ${t.javaClass.simpleName}:${t.message}", t)
|
||||
false
|
||||
} finally {
|
||||
// 沙盒收尾:会话按持久配置回正(若原本关闭则 stop+configure 恢复关闭态)
|
||||
crossRunSession?.stop()
|
||||
crossRunSession?.configure(latestConfig.crossPlatform.enabled)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅调试 APK 的知乎单候选采集沙盒(端到端真机验收)。
|
||||
* 只读采集、不发布、不启动调度器——WATCHDOG(恢复链)不运行,
|
||||
|
||||
Reference in New Issue
Block a user