9.5 KiB
QC Result Optional Conclusion Implementation Plan
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Allow「填写检测结果」to save without a pass/fail conclusion when task status is 待执行/进行中 (shows as 待结论); keep conclusion required when status is 已完成.
Architecture: Empty string (or null) continues to mean「待结论」in display helpers. Add a pure backend normalizer for conclusion×status rules; wire it into apply_task_result and the API. Frontend adds a third radio「待结论」, disables it for ywc, stops defaulting to tg, and only validates conclusion when saving as completed.
Tech Stack: FastAPI / SQLAlchemy (Python 3.9), Vue 3 + Element Plus, pytest
Spec: docs/superpowers/specs/2026-07-22-qc-result-optional-conclusion-design.md
File map
| File | Responsibility |
|---|---|
backend/app/crud/qc_task.py |
Pure resolve_task_result_conclusion + apply_task_result uses it |
backend/tests/test_qc_task_result_conclusion.py |
Unit tests for the pure helper |
backend/app/api/qc.py |
Optional body field; defer validation to service / match new rules |
web-admin/.../QcWorkOrderTaskSubList.vue |
Dialog radios, defaults, client validation |
Task 1: Backend pure helper + unit tests
Files:
-
Modify:
backend/app/crud/qc_task.py(add helper near_QC_TASK_RESULT_STATUSES) -
Create:
backend/tests/test_qc_task_result_conclusion.py -
Step 1: Write failing tests
# backend/tests/test_qc_task_result_conclusion.py
import pytest
from app.crud.qc_task import resolve_task_result_conclusion
def test_empty_ok_for_jxz():
assert resolve_task_result_conclusion("", "jxz") == ""
assert resolve_task_result_conclusion(None, "dzx") == ""
def test_tg_btg_ok_for_any_status():
assert resolve_task_result_conclusion("tg", "ywc") == "tg"
assert resolve_task_result_conclusion("btg", "jxz") == "btg"
def test_empty_rejected_for_ywc():
with pytest.raises(ValueError, match="请选择检测结论"):
resolve_task_result_conclusion("", "ywc")
def test_invalid_code_rejected():
with pytest.raises(ValueError, match="检测结论无效"):
resolve_task_result_conclusion("xyz", "jxz")
- Step 2: Run tests — expect FAIL (import / not defined)
cd backend && source venv/bin/activate && pytest tests/test_qc_task_result_conclusion.py -v
Expected: FAIL (function missing)
- Step 3: Implement helper in
qc_task.py
Place after _QC_TASK_RESULT_STATUSES = frozenset({"dzx", "jxz", "ywc"}):
def resolve_task_result_conclusion(
conclusion: Optional[str],
target_status: str,
) -> str:
"""Normalize conclusion for apply_task_result.
Returns '' | 'tg' | 'btg'. Empty allowed only when target is dzx/jxz.
"""
concl = (conclusion or "").strip()
if concl and concl not in ("tg", "btg"):
raise ValueError("检测结论无效")
if target_status == "ywc" and concl not in ("tg", "btg"):
raise ValueError("请选择检测结论(通过/不通过)")
return concl
Ensure Optional is already imported from typing in that file.
- Step 4: Run tests — expect PASS
cd backend && source venv/bin/activate && pytest tests/test_qc_task_result_conclusion.py -v
Expected: 4 passed
- Step 5: Commit (only if user asked to commit in this session; otherwise leave unstaged and continue)
git add backend/app/crud/qc_task.py backend/tests/test_qc_task_result_conclusion.py
git commit -m "$(cat <<'EOF'
feat(qc): allow empty task conclusion when status is not completed
EOF
)"
Task 2: Wire helper into apply_task_result + API
Files:
-
Modify:
backend/app/crud/qc_task.py—apply_task_result -
Modify:
backend/app/api/qc.py—TaskCompleteWithResultBody+complete-with-resulthandler -
Step 1: Update
apply_task_resultvalidation block
Replace the current early conclusion check:
concl = (conclusion or "").strip()
if concl not in ("tg", "btg"):
raise ValueError("请选择检测结论(通过/不通过)")
target = (task_status or "").strip() or "ywc"
if target not in _QC_TASK_RESULT_STATUSES:
raise ValueError("任务状态无效")
With:
target = (task_status or "").strip() or "ywc"
if target not in _QC_TASK_RESULT_STATUSES:
raise ValueError("任务状态无效")
concl = resolve_task_result_conclusion(conclusion, target)
Keep t.conclusion = concl (empty string clears to pending). Optionally use t.conclusion = concl or None if surrounding code prefers NULL; both display as 待结论 — prefer concl as '' then assign t.conclusion = concl or None for cleaner DB nulls:
t.conclusion = concl or None
Signature may stay conclusion: str or become Optional[str] = None — prefer:
conclusion: Optional[str] = None,
- Step 2: Update API body + handler
In TaskCompleteWithResultBody:
conclusion: Optional[str] = Field(None, alias="conclusion")
In the complete-with-result handler, remove the hard reject:
concl = (body.conclusion or "").strip()
if concl not in ("tg", "btg"):
return error_response(400, "请选择检测结论(通过/不通过)")
Pass body.conclusion through to apply_task_result (still catch ValueError → 400 as today). Keep attachment / results / commit flow unchanged.
- Step 3: Re-run unit tests + quick import check
cd backend && source venv/bin/activate && pytest tests/test_qc_task_result_conclusion.py -v
Expected: PASS
- Step 4: Commit (if committing)
git add backend/app/crud/qc_task.py backend/app/api/qc.py
git commit -m "$(cat <<'EOF'
feat(qc): accept optional conclusion on complete-with-result for in-progress tasks
EOF
)"
Task 3: Frontend dialog — radio, default, validation
Files:
-
Modify:
web-admin/src/views/quality-inspection/qc-work-order/QcWorkOrderTaskSubList.vue -
Step 1: Template — three radios + disable 待结论 when ywc
Replace the 结论 el-form-item block (~320–325) with:
<el-form-item label="结论" :required="resultSaveStatus === 'ywc'">
<el-radio-group v-model="resultConclusion">
<el-radio value="" :disabled="resultSaveStatus === 'ywc'">待结论</el-radio>
<el-radio value="tg">通过</el-radio>
<el-radio value="btg">不通过</el-radio>
</el-radio-group>
</el-form-item>
- Step 2:
openResult— default to pending, not 通过
Change initial assign and detail backfill:
resultConclusion.value = ''
and:
const c = (detail.conclusion || '').trim()
resultConclusion.value = c === 'tg' || c === 'btg' ? c : ''
Remove both places that set resultConclusion.value = 'tg' / detail.conclusion || 'tg'.
- Step 3:
submitResult— require conclusion only for ywc
Replace:
if (!resultConclusion.value) {
ElMessage.warning('请选择检测结论')
return
}
With:
if (
resultSaveStatus.value === 'ywc' &&
resultConclusion.value !== 'tg' &&
resultConclusion.value !== 'btg'
) {
ElMessage.warning('请选择检测结论')
return
}
data.conclusion remains resultConclusion.value (may be '').
- Step 4: Manual smoke (dev)
- 质检工单 / 我的质检任务 → 填写检测结果:三项可见;无结论任务默认「待结论」。
- 状态「进行中」+「待结论」→ 保存成功,卡片「待结论」。
- 改「已完成」:「待结论」禁用;未改结论直接保存 → 提示请选择检测结论。
- 「已完成」+「通过」→ 与改前一致。
- Step 5: Commit (if committing)
git add web-admin/src/views/quality-inspection/qc-work-order/QcWorkOrderTaskSubList.vue
git commit -m "$(cat <<'EOF'
feat(web-admin): allow pending conclusion when saving QC results in progress
EOF
)"
Task 4: Verify + graph update
- Step 1: Grep sanity
rg -n "请选择检测结论|resultConclusion\.value = 'tg'|detail\.conclusion \|\| 'tg'" \
backend/app/api/qc.py \
backend/app/crud/qc_task.py \
web-admin/src/views/quality-inspection/qc-work-order/QcWorkOrderTaskSubList.vue
Expect: no unconditional default-to-tg; API no longer hard-rejects empty before service; frontend only warns when ywc.
- Step 2: Update knowledge graph (backend + frontend touched)
./scripts/update-graph.sh all
- Step 3: Confirm checklist against spec §6
| Spec验收 | Done? |
|---|---|
| 两页弹窗三项含待结论 | |
| dzx/jxz + 待结论可保存 | |
| ywc 禁用待结论且必填 | |
| 回填 tg/btg;改回待结论后列表正确 | |
| ywc + tg/btg 行为不变 |
Self-review
| Spec requirement | Task |
|---|---|
| 待结论 radio + disable on ywc | T3 |
| Default empty not tg | T3 |
| Client validate only when ywc | T3 |
| Backend empty OK for dzx/jxz | T1–T2 |
| Backend ywc requires tg/btg | T1–T2 |
No new djl code / no schema change |
(none) |
| Display helpers unchanged | (none) |
| Shared component covers both pages | T3 |