feat(任务): 连续未命中 N 步跳过本账号(miss_limit)

- 任务级 miss_limit:连续 N 个叶子步骤 miss → 本账号剩余步骤跳过,换下一个号
- 成功一步清零;每个账号/每条内容重新计数;容器步骤不参与
- 编辑器顶部可填,保存进 params.miss_limit;计划任务段会带进计划任务
- 发布视频111 设 miss_limit=2
- 新增 test_miss_limit 用例;TASK_DEV / CHANGES 同步
This commit is contained in:
2026-10-18 15:52:15 +08:00
parent 2ed198f1a0
commit 6c1f241a16
9 changed files with 146 additions and 5 deletions
+2 -1
View File
@@ -25,6 +25,7 @@
test_plan 计划调度:选账号→现算设备、每人限 N 条、计划 CRUD、时间点→cron、运行收尾
test_action_ref 动作引用:执行时现展开、循环引用挡住、引用扫描(谁在用)、删除保护、摊平逃生口
test_assets 资产管理:模板导入(两项校验/分拣/去重/音频)、指定素材、编辑元数据、共享文件删除
test_miss_limit 连续未命中:连续 N 步 miss 跳过本账号,成功一次重新计数
"""
import os
import subprocess
@@ -35,7 +36,7 @@ CASES = ["test_parse_name.py", "test_upload_name.py", "test_name_scope.py",
"test_switch_account.py", "test_foreach_account.py", "test_push_by_name.py",
"test_expect_el.py", "test_read_text.py", "test_account_folder.py",
"test_task_try.py", "test_roster.py", "test_plan.py",
"test_action_ref.py", "test_assets.py"]
"test_action_ref.py", "test_assets.py", "test_miss_limit.py"]
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
+71
View File
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
"""连续未命中策略:连续 N 步 miss → 跳过本账号剩余步骤。
不连 adb、不连真机:步骤用的是测试里挂上去的假 handler。
"""
import io
import os
import sys
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
os.environ['DATABASE_URL'] = 'sqlite:///:memory:'
os.environ['DEPLOY_ENV'] = 'dev'
os.environ['DB_ALLOW_SQLITE_FALLBACK'] = '1'
_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
sys.path.insert(0, _ROOT)
os.chdir(_ROOT)
from tasks.generic import task as gt # noqa: E402
fails = []
def check(label, got, want):
ok = got == want
if not ok:
fails.append(label)
print((' ✅ ' if ok else ' ❌ ') + label + ('' if ok else '\n 得到 %r\n 期望 %r' % (got, want)))
def step(name, ok):
return {"type": "fake", "label": name, "params": {"name": name, "ok": ok}}
def run(steps, miss_limit):
w = gt.GenericStepsWorker("M1", {"miss_limit": miss_limit})
calls = []
def fake(d, params, depth=0):
calls.append(params.get("name"))
return params.get("ok")
w._exec_fake = fake
w._exec_steps(None, steps)
return calls, w
print('=== 1. 连续 2 次 miss → 跳过本账号剩余步骤 ===')
calls, w = run([step('a', False), step('b', False), step('c', True)], 2)
check('a、b 执行了,c 没执行', calls, ['a', 'b'])
check('置位 skip_rest', w._skip_rest, True)
print('=== 2. 中间成功一次会重新计数 ===')
calls, w = run([step('a', False), step('b', True), step('c', False),
step('d', False), step('e', True)], 2)
check('成功之前的 miss 不算连续', calls, ['a', 'b', 'c', 'd'])
print('=== 3. 不连续 miss 不触发 ===')
calls, w = run([step('a', False), step('b', True), step('c', False)], 2)
check('三步都执行', calls, ['a', 'b', 'c'])
check('没有置位 skip_rest', w._skip_rest, False)
print('=== 4. miss_limit=0(默认)不启用 ===')
calls, w = run([step('a', False), step('b', False), step('c', False)], 0)
check('全部执行', calls, ['a', 'b', 'c'])
check('没有置位 skip_rest', w._skip_rest, False)
print()
if fails:
print('❌ 失败 %d 项:%s' % (len(fails), ' / '.join(fails)))
sys.exit(1)
print('✅ 全部通过(未连任何真机)')
+2 -1
View File
@@ -183,7 +183,7 @@ try:
# ==================== ②c 任务段:只取任务步骤 ====================
print("▶ ②c 计划里直接用任务:只取步骤,拆掉外层账号循环")
db.session.add(TaskJob(id="job1", name="发布任务111", task_type="generic_steps",
params=json.dumps({"steps": [
params=json.dumps({"miss_limit": 2, "steps": [
{"type": "screen_on", "label": "亮屏", "params": {}},
{"type": "foreach_account", "label": "循环账号",
"params": {"children": [
@@ -206,6 +206,7 @@ try:
task_job, task_err = plan_mod.build_plan_job(
task_plan, {"serial": "s", "device_name": "A07", "accounts": ["号甲"]})
check("任务段构建不报错", task_err, "")
check("任务段的 miss_limit 带进计划任务", task_job.params.get("miss_limit"), 2)
task_kids = task_job.params["steps"][1]["params"]["children"]
check("任务段外层账号循环被拆掉(不再套一层)",
any(s["type"] == "foreach_account" for s in task_kids), False)