This commit is contained in:
@@ -38,6 +38,12 @@ def timeline(task_id):
|
||||
|
||||
def owner_plan(task_id):
|
||||
task(task_id)
|
||||
single = STATE / 'handoffs' / (task_id + '.single.json')
|
||||
if single.is_file():
|
||||
plan = cd.read_json(cd.immutable_file(single))
|
||||
candidate.check_plan(plan)
|
||||
cd.require(plan['task'] == task_id and [i['task'] for i in plan['items']] == [task_id], 'invalid single-task plan')
|
||||
return plan
|
||||
matches = [candidate.FENCE.search(row.get('content') or '') for row in reversed(sorted(
|
||||
timeline(task_id), key=lambda row: row.get('createdAt', ''))) if (row.get('actor') or {}).get('id') == cd.RELEASE_OWNER]
|
||||
match = next((row for row in matches if row), None)
|
||||
@@ -105,6 +111,9 @@ def publish_candidate(plan, receipt, run):
|
||||
f'发布任务 {task(plan["task"])["url"]}')
|
||||
body += ('\n\n请在本包执行实测,用 kg-qa-v1 代码块回填 sha、bundle、url、required、passed、failed、blocked、verdict。'
|
||||
'业务单记录用例,发布单记录批次回归;每份报告附对应证据。')
|
||||
single = [item['task'] for item in plan['items']] == [plan['task']]
|
||||
if single:
|
||||
body = body.split('业务单记录用例')[0] + '请在本单逐项记录实测证据。在结构化报告加 cases 对象,business 和 regression 各列本轮通过的业务及同批回归用例编号,两组编号独立,合计等于 required。验收登记后,由负责人在本单切到待发布。'
|
||||
key = 'ready ' + receipt['bundle']
|
||||
add_comment(plan['task'], key, body)
|
||||
for item in plan['items']:
|
||||
@@ -115,14 +124,14 @@ def publish_candidate(plan, receipt, run):
|
||||
cd.require((STATE / 'handoffs' / (plan['task'] + '.preview.json')).is_file(),
|
||||
f'{item_id}: another QA round is already in progress')
|
||||
add_comment(item_id, key, body)
|
||||
if (STATE / 'handoffs' / (plan['task'] + '.preview.json')).is_file():
|
||||
if single or (STATE / 'handoffs' / (plan['task'] + '.preview.json')).is_file():
|
||||
summon_qa(plan, item_id, body)
|
||||
continue
|
||||
cd.require(status == WAIT_TEST, f'{item_id}: requirement must be in 待测试')
|
||||
add_comment(item_id, key, body)
|
||||
cd.require((task(item_id).get('status') or {}).get('id') == WAIT_TEST,
|
||||
f'{item_id}: task status changed during candidate handoff')
|
||||
managed = (STATE / 'handoffs' / (plan['task'] + '.preview.json')).is_file()
|
||||
managed = single or (STATE / 'handoffs' / (plan['task'] + '.preview.json')).is_file()
|
||||
invitation = STATE / cd.acceptance_digest(plan) / (item_id + '.qa-invite.json')
|
||||
if managed:
|
||||
cd.record(invitation, {'state': 'sending'})
|
||||
@@ -131,7 +140,7 @@ def publish_candidate(plan, receipt, run):
|
||||
if managed:
|
||||
cd.record(invitation, {'state': 'sent', 'via': 'status'})
|
||||
|
||||
if (STATE / 'handoffs' / (plan['task'] + '.preview.json')).is_file():
|
||||
if not single and (STATE / 'handoffs' / (plan['task'] + '.preview.json')).is_file():
|
||||
summon_qa(plan, plan['task'], body + '\n请实测批次回归,报告写在本发布单。')
|
||||
|
||||
|
||||
@@ -154,7 +163,7 @@ def register(task_id):
|
||||
cd.require(receipt.get('mode') == 'acceptance', 'isolated smoke results are ineligible for publication')
|
||||
runtime.attest(directory / 'bundle', receipt)
|
||||
reports = {}
|
||||
tasks = [item['task'] for item in plan['items']] + [task_id]
|
||||
tasks = list(dict.fromkeys([item['task'] for item in plan['items']] + [task_id]))
|
||||
for item_id in tasks:
|
||||
obj = task(item_id)
|
||||
rows = sorted(timeline(item_id), key=lambda row: row.get('createdAt', ''), reverse=True)
|
||||
|
||||
@@ -42,7 +42,7 @@ def check_plan(plan):
|
||||
items = plan['items']
|
||||
cd.require(isinstance(items, list) and 0 < len(items) <= 100, 'require one to 100 requirements')
|
||||
for item in items:
|
||||
cd.require(isinstance(item, dict) and cd.matches(cd.UUID, item.get('task')) and item['task'] != plan['task'],
|
||||
cd.require(isinstance(item, dict) and cd.matches(cd.UUID, item.get('task')) and (item['task'] != plan['task'] or len(items) == 1),
|
||||
'invalid requirement identity')
|
||||
by_pr = set(item) == {'task', 'pr'} and type(item['pr']) is int and item['pr'] > 0
|
||||
by_commit = set(item) == {'task', 'commit'} and cd.matches(cd.SHA, item['commit'])
|
||||
@@ -91,6 +91,13 @@ def check_qa(plan, receipt, reports, authors):
|
||||
cd.require(all(type(v) is int for v in values) and values[0] > 0
|
||||
and values == [values[0], values[0], 0, 0] and report.get('verdict') == 'passed',
|
||||
f'{task}: required QA cases have not passed')
|
||||
if [i['task'] for i in plan['items']] == [plan['task']]:
|
||||
cases = report.get('cases')
|
||||
cd.require(isinstance(cases, dict) and all(isinstance(cases.get(k), list) and cases[k]
|
||||
for k in ('business', 'regression')), 'single-task QA needs business and regression cases')
|
||||
ids = cases['business'] + cases['regression']
|
||||
cd.require(all(isinstance(v, str) and v.strip() for v in ids) and len(set(ids)) == len(ids) == values[0],
|
||||
'single-task QA case IDs must match the required count')
|
||||
|
||||
|
||||
def git(*args, cwd=None, allowed=(0,)):
|
||||
|
||||
+27
-49
@@ -1,7 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
"""HiFox comment handoffs on the release executor. All user-visible actions are scoped to a verified event."""
|
||||
import argparse
|
||||
import html
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
@@ -90,58 +89,37 @@ def frozen_approval(task_id, comment_id=None):
|
||||
|
||||
|
||||
def preflight(task, event=None):
|
||||
"""Freeze a test candidate on the originating task. Production still requires its owner event."""
|
||||
sha, ref = resolve(task, event)
|
||||
label = f"知识治理发布批次|{task['identifier']} · {sha[:12]}"
|
||||
DIRECTORY.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
claim = DIRECTORY / f"{task['id']}-{sha}.json"
|
||||
with cd.deploy_lock(DIRECTORY / 'handoff.lock'):
|
||||
# Validate range, all ingredients and CI before creating any task. A fresh UUID is only a dry-run identity.
|
||||
import uuid
|
||||
scope = {'task': str(uuid.uuid4()), 'items': [{'task': task['id'], **({'commit': sha} if ref == sha else {'pr': int(ref)})}],
|
||||
'sha': sha, 'base': assistant.worker.main_site_sha()}
|
||||
scope['extra'] = [s for s in candidate.git('rev-list', '--first-parent', f"{scope['base']}..{sha}", cwd=assistant.SOURCE).splitlines() if s != sha]
|
||||
candidate.verify_source(scope, assistant.SOURCE)
|
||||
if event:
|
||||
review_identity(task, comments(task['id']), event)
|
||||
children = cli('task', 'list', '--parent', task['id'], '--limit', '100')
|
||||
matches = [r for r in children if r['title'] == label]
|
||||
cd.require(len(children) < 100 and len(matches) <= 1, 'ambiguous release record')
|
||||
if matches:
|
||||
cd.require(claim.exists(), 'unclaimed release record needs reconciliation')
|
||||
launch = coordinator.task(matches[0]['id'])
|
||||
else:
|
||||
cd.require(not claim.exists(), 'previous creation outcome needs reconciliation')
|
||||
cd.record(claim, {'state': 'creating'})
|
||||
created = cli('task', 'create', '--space', cd.SPACE, '--parent', task['id'], '--type', '需求',
|
||||
'--title', label, '--status', '待开始', '--assignee', 'agent:' + ASSISTANT,
|
||||
'--body', f"{task['identifier']} 独立发布单。系统将回填版本范围预览,请等待负责人确认。")
|
||||
launch = coordinator.task(created['id'])
|
||||
cd.require(launch['parentTaskId'] == task['id'] and launch['title'] == label and
|
||||
(launch.get('delegate') or {}).get('id') == ASSISTANT, 'release handoff readback mismatch')
|
||||
cd.record(claim, {'state': 'created', 'release': launch['id']})
|
||||
scope['task'] = launch['id']
|
||||
candidate.check_plan(scope)
|
||||
path = DIRECTORY / (launch['id'] + '.preview.json')
|
||||
base = assistant.worker.main_site_sha()
|
||||
revisions = candidate.git('rev-list', '--first-parent', f'{base}..{sha}', cwd=assistant.SOURCE).splitlines()
|
||||
task_id = task['id']
|
||||
source = {'commit': sha} if ref == sha else {'pr': int(ref)}
|
||||
plan = {'task': task_id, 'items': [dict(source, task=task_id)], 'base': base, 'sha': sha,
|
||||
'extra': [revision for revision in revisions if revision != sha]}
|
||||
candidate.verify_source(plan, assistant.SOURCE)
|
||||
latest = coordinator.task(task_id)
|
||||
cd.require(latest['status']['id'] in (coordinator.WAIT_TEST, coordinator.TESTING), 'task left QA stage')
|
||||
review_identity(latest, comments(task_id), event)
|
||||
path = DIRECTORY / (task_id + '.single.json')
|
||||
if path.exists():
|
||||
saved = cd.read_json(cd.immutable_file(path))
|
||||
cd.require(scope == saved['plan'], 'baseline or scope changed; review a fresh batch')
|
||||
return {'state': 'existing_preview', 'url': launch['url'], 'plan': scope}
|
||||
lines = [f"{s[:12]} {candidate.git('show', '-s', '--format=%s', s, cwd=assistant.SOURCE)}" for s in scope['extra']]
|
||||
safe_title = ' '.join(task['title'].splitlines()).replace('```', '')
|
||||
body = f"发布范围预览 · {task['identifier']}\n\n线上基线 `{scope['base']}`\n\n候选 `{sha}`\n\n本次修复:{safe_title}\n\n同批改动:\n" + '\n'.join(lines or ['无']) + '\n\n请负责人在这条评论下回复「确认范围」,系统将据此准备候选包。'
|
||||
marker = '[KG candidate scope ' + cd.acceptance_digest(scope) + ']'
|
||||
entries = [r for r in comments(launch['id']) if r['content'].startswith(marker + '\n')]
|
||||
if not entries:
|
||||
cli('task', 'comment', launch['id'], '--body', marker + '\n\n' + body)
|
||||
entries = [r for r in comments(launch['id']) if r['content'].startswith(marker + '\n')]
|
||||
cd.require(len(entries) == 1, 'expected one scope preview comment')
|
||||
stored = entries[0]
|
||||
normalized = html.unescape(stored['content']).replace(
|
||||
f"[{task['identifier']}](mention://task/{task['id']})", task['identifier'])
|
||||
cd.require(normalized == marker + '\n\n' + body, 'scope preview readback differs from plan')
|
||||
comment = stored['id']
|
||||
cd.record(path, {'plan': scope, 'comment': comment, 'content': stored['content']})
|
||||
return {'state': 'awaiting_scope', 'url': launch['url'], 'plan': scope}
|
||||
previous = cd.read_json(cd.immutable_file(path))
|
||||
cd.require(previous == plan, 'existing candidate differs; reconcile its QA round before replacement')
|
||||
else:
|
||||
cd.require(not cd.metadata(latest, 'cd_acceptance'), 'task already has a registered candidate')
|
||||
cd.record(path, plan)
|
||||
extras = [candidate.git('show', '-s', '--format=%h %s', s, cwd=assistant.SOURCE) for s in plan['extra']]
|
||||
# Keep source text literal inside a code block. HiFox expands task references in prose.
|
||||
scope = '\n'.join(extras) or '无'
|
||||
body = f'本单候选版本 `{sha}`,线上基线 `{base}`。同批主干变更:\n\n```text\n{scope}\n```'
|
||||
marker = '[KG single ' + cd.acceptance_digest(plan) + ']'
|
||||
if not any(r['content'].startswith(marker) for r in comments(task_id)):
|
||||
cli('task', 'comment', task_id, '--body', marker + '\n\n' + body)
|
||||
cd.require(any(r['content'].startswith(marker) and sha in r['content'] and base in r['content']
|
||||
for r in comments(task_id)), 'candidate scope readback failed')
|
||||
return coordinator.queue(task_id)
|
||||
|
||||
|
||||
def qa(task, row):
|
||||
|
||||
@@ -23,6 +23,21 @@ class CandidateReleaseTest(unittest.TestCase):
|
||||
for n, sha in ((20, A), (21, B))}
|
||||
self.report = {'actor': {'id': OWNER}, 'createdAt': '2026-11-01T11:00:00Z', 'id': OWNER}
|
||||
|
||||
def test_one_requirement_owns_its_own_release(self):
|
||||
plan = dict(self.plan, items=[{'task': TASK, 'commit': B}], extra=[A])
|
||||
candidate.check_scope(plan, self.prs.__getitem__, [A, B])
|
||||
with self.assertRaises(cd.CDError):
|
||||
candidate.check_plan(dict(plan, items=plan['items'] + [{'task': QA2, 'pr': 20}]))
|
||||
|
||||
def test_single_report_covers_business_and_batch(self):
|
||||
plan = dict(self.plan, items=[{'task': TASK, 'commit': B}], extra=[A])
|
||||
report = self.result()
|
||||
for missing in ({}, {'business': ['C-001']}, {'business': [], 'regression': ['R-001']}):
|
||||
with self.assertRaises(cd.CDError):
|
||||
candidate.check_qa(plan, RUN, {TASK: (self.report, dict(report, cases=missing))}, {OWNER})
|
||||
complete = dict(report, cases={'business': ['C-001'], 'regression': ['R-001']}, required=2, passed=2)
|
||||
candidate.check_qa(plan, RUN, {TASK: (self.report, complete)}, {OWNER})
|
||||
|
||||
def test_scope_accounts_for_entire_main_range(self):
|
||||
candidate.check_scope(self.plan, self.prs.__getitem__, [A, B])
|
||||
with self.assertRaisesRegex(cd.CDError, 'outside the release scope'):
|
||||
|
||||
Reference in New Issue
Block a user