Files
cbb-refresh-verify-795/docs/superpowers/plans/2026-09-16-cbb-refresh-verify.md
T
阿白叔 11a2b2e46e Import CBB refresh verify r4 stability baseline
Preserve tested Verify source, authoritative READY checks, bounded bridge retries, diagnostics and failure-only reporting. Include 336-test suite and packaging assets; exclude live Mentor samples, field logs, backups and distributions.
2026-09-29 15:05:20 +08:00

14 KiB

CBB Refresh Verify 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: Build and package a directly usable Windows CBB contents-verification tool that follows the DxDesigner replacement tool's application and release standards.

Architecture: Reuse the replacement tool's PySide6 bootstrap, logging, worker, and onedir PyInstaller conventions while keeping CBB-specific logic in focused library-reader, verify-runner, and evidence modules. COM library enumeration and the official ReuseBlockImporter.exe -chkContents process are isolated behind Qt-free interfaces so they can be tested with fakes.

Tech Stack: Python 3.12, PySide6, pywin32 COM, pytest, PyInstaller 6.x, PowerShell build scripts.

Spec: docs/superpowers/specs/2026-09-16-cbb-refresh-verify-design.md

Global Constraints

  • Windows desktop target.
  • Python >=3.12,<3.13.
  • Dependencies remain limited to PySide6 and pywin32 plus existing build/test tools.
  • Final release is dist\\CbbRefreshVerify\\CbbRefreshVerify.exe in onedir layout.
  • No fixed-coordinate UI automation, SendKeys, or production-library writes.
  • DMS-unavailable runs must classify as BLOCKED or UNKNOWN, never fabricated PASS.
  • Runtime classification must not consume historical screenshots or old run JSON files.

Task 1: Align Project Metadata and Runtime Layout

Files:

  • Modify: pyproject.toml
  • Create: src/cbb_refresh_verify/__init__.py
  • Create: src/cbb_refresh_verify/application.py
  • Modify: src/cbb_refresh_verify/__main__.py
  • Test: tests/test_application.py

Interfaces:

  • Produces cbb_refresh_verify.application.main(argv: Sequence[str] | None) -> int.

  • Produces resolve_data_root(cli_value: Path | None) -> Path.

  • Supports --smoke-test --data-root <path> and logs application_start plus application_clean_shutdown.

  • Step 1: Write failing bootstrap tests

def test_smoke_arguments_exit_zero_and_write_lifecycle_log(tmp_path):
    from cbb_refresh_verify.application import main
    assert main(["--smoke-test", "--data-root", str(tmp_path)]) == 0
    text = (tmp_path / "logs" / "application.log").read_text(encoding="utf-8")
    assert "application_start" in text
    assert "application_clean_shutdown" in text
  • Step 2: Run the focused test and verify it fails

Run: python -m pytest tests/test_application.py -q

Expected: FAIL because the lifecycle bootstrap and logging context do not exist.

  • Step 3: Port only the replacement tool's bootstrap patterns

Implement application.py with argument parsing, product-specific data root, logging setup, exception hooks, QApplication creation, and a smoke-test timer. Keep the CBB window import lazy. Use an absolute import in __main__.py.

  • Step 4: Run the focused test and verify it passes

Run: python -m pytest tests/test_application.py -q

Expected: PASS with zero failures.

  • Step 5: Commit the bootstrap slice
git add pyproject.toml src/cbb_refresh_verify tests/test_application.py
git commit -m "feat: align cbb application bootstrap"

Task 2: Implement Typed Central-Library Reader

Files:

  • Create: src/cbb_refresh_verify/models.py
  • Modify: src/cbb_refresh_verify/library_reader.py
  • Test: tests/test_library_reader.py

Interfaces:

  • CbbRecord(name: str, partition_name: str, logical_type: str).

  • LibraryReadResult(records: tuple[CbbRecord, ...], error: str | None).

  • read_library(path: Path, *, dispatch: Callable | None = None) -> LibraryReadResult.

  • Step 1: Write failing reader tests with COM fakes

def test_reader_filters_reusable_block_partition_and_returns_sorted_records():
    result = read_library(Path("fixture.lmc"), dispatch=fake_dispatch)
    assert [item.name for item in result.records] == ["A_CBB", "Z_CBB"]
    assert result.error is None

def test_reader_surfaces_com_error_instead_of_returning_empty_success():
    result = read_library(Path("fixture.lmc"), dispatch=lambda _: (_ for _ in ()).throw(RuntimeError("DMS")))
    assert result.records == ()
    assert "DMS" in result.error
  • Step 2: Run reader tests and verify they fail

Run: python -m pytest tests/test_library_reader.py -q

Expected: FAIL because typed records and structured errors are not implemented.

  • Step 3: Implement COM reader and test seam

Dispatch LibraryManager.Application, open the .lmc, inspect partition type 7, enumerate reusable-block entries, and return sorted unique CBB records. Preserve exception text in LibraryReadResult.error; do not swallow exceptions into [].

  • Step 4: Run reader tests and verify they pass

Run: python -m pytest tests/test_library_reader.py -q

Expected: PASS with zero failures.

  • Step 5: Commit the reader slice
git add src/cbb_refresh_verify/models.py src/cbb_refresh_verify/library_reader.py tests/test_library_reader.py
git commit -m "feat: read reusable blocks from central libraries"

Task 3: Implement Verify Runner and Evidence

Files:

  • Create: src/cbb_refresh_verify/verify_runner.py
  • Create: src/cbb_refresh_verify/evidence.py
  • Test: tests/test_verify_runner.py

Interfaces:

  • VerifyRequest(lmc_file: Path, block_name: str, libspec: Path, dms_login_config: Path, mentor_bin: Path | None, evidence_dir: Path, timeout_seconds: int).

  • VerifyResult(status: Literal["PASS", "FAIL", "TIMEOUT", "BLOCKED", "UNKNOWN"], exit_code: int | None, stdout: str, stderr: str, report_path: Path | None, evidence_path: Path | None, command: tuple[str, ...]).

  • build_verify_command(request: VerifyRequest, executable: Path) -> tuple[str, ...].

  • run_verify(request: VerifyRequest, *, process_factory=...) -> VerifyResult.

  • Step 1: Write failing command and classification tests

def test_command_uses_official_logical_physical_contents_check():
    command = build_verify_command(request, Path("ReuseBlockImporter.exe"))
    assert command == ("ReuseBlockImporter.exe", "-lmcFile", "lib.lmc", "-blockName", "CBB1", "-logicalType", "LP", "-chkContents", "-libSpec", "parts", "-dmsLoginConfig", "login")

def test_missing_executable_is_blocked():
    assert run_verify(request_with_missing_executable()).status == "BLOCKED"

def test_success_requires_success_text_and_no_error_marker(fake_success_process):
    assert run_verify(request, process_factory=fake_success_process).status == "PASS"
  • Step 2: Run runner tests and verify they fail

Run: python -m pytest tests/test_verify_runner.py -q

Expected: FAIL because the request/result types and runner are absent.

  • Step 3: Implement validation, process execution, classification, and evidence

Resolve the configured Mentor bin first and the known EE7.9.5 fallback second. Validate all required files before launching. Capture stdout/stderr, enforce timeout, terminate on stop, write a text report and JSON evidence, and classify only from current process output.

  • Step 4: Run runner tests and verify they pass

Run: python -m pytest tests/test_verify_runner.py -q

Expected: PASS with zero failures.

  • Step 5: Commit the runner slice
git add src/cbb_refresh_verify/verify_runner.py src/cbb_refresh_verify/evidence.py tests/test_verify_runner.py
git commit -m "feat: run cbb contents verification with evidence"

Task 4: Build the PySide6 UI With Background Workers

Files:

  • Create: src/cbb_refresh_verify/ui/main_window.py
  • Create: src/cbb_refresh_verify/ui/workers.py
  • Modify: src/cbb_refresh_verify/application.py
  • Test: tests/test_ui.py

Interfaces:

  • MainWindow(reader=read_library, verifier=run_verify).

  • UI fields expose central-library path, CBB selection, LibSpec, DMS config, Mentor bin, evidence directory, Verify, Stop, status, output, report, and evidence path.

  • Step 1: Write failing UI behavior tests

def test_verify_disabled_until_required_fields_are_present(qtbot):
    window = MainWindow(reader=fake_reader, verifier=fake_verifier)
    qtbot.addWidget(window)
    assert not window.verify_button.isEnabled()
    window.lmc_edit.setText("lib.lmc")
    window.libspec_edit.setText("parts")
    window.dms_edit.setText("login")
    assert window.verify_button.isEnabled()

def test_reader_error_is_visible_and_does_not_create_cbb_selection(qtbot):
    window = MainWindow(reader=failing_reader, verifier=fake_verifier)
    qtbot.addWidget(window)
    window.load_library()
    assert window.cbb_combo.count() == 0
    assert "DMS" in window.status_label.text()
  • Step 2: Run UI tests and verify they fail

Run: python -m pytest tests/test_ui.py -q

Expected: FAIL because the new window and worker classes are absent.

  • Step 3: Implement the UI and worker signals

Use QThread/worker objects or the same worker pattern as the replacement tool. Load the central library asynchronously, populate the CBB list, disable controls while running, stream output, support Stop, and render the separate contents result and Library Manager green-state note.

  • Step 4: Run UI tests and verify they pass

Run: python -m pytest tests/test_ui.py -q

Expected: PASS with zero failures.

  • Step 5: Commit the UI slice
git add src/cbb_refresh_verify/ui src/cbb_refresh_verify/application.py tests/test_ui.py
git commit -m "feat: add cbb verify desktop interface"

Task 5: Align PyInstaller Onedir Packaging and Smoke Test

Files:

  • Modify: packaging/CbbRefreshVerify.spec
  • Modify: packaging/Build-CbbRefreshVerify.ps1
  • Create: tests/test_packaging.py
  • Modify: README.md

Interfaces:

  • Build output: dist/CbbRefreshVerify/CbbRefreshVerify.exe.

  • Smoke invocation: CbbRefreshVerify.exe --smoke-test --data-root <temporary-directory>.

  • Step 1: Write failing packaging checks

def test_spec_uses_onedir_collect_and_product_name():
    text = Path("packaging/CbbRefreshVerify.spec").read_text(encoding="utf-8")
    assert "COLLECT(" in text
    assert "CbbRefreshVerify" in text

def test_build_script_validates_executable():
    text = Path("packaging/Build-CbbRefreshVerify.ps1").read_text(encoding="utf-8")
    assert "CbbRefreshVerify.exe" in text
  • Step 2: Run packaging checks and verify they fail

Run: python -m pytest tests/test_packaging.py -q

Expected: FAIL because the current spec is one-file style and the build script lacks replacement-tool cleanup and smoke validation.

  • Step 3: Port the replacement tool's safe build flow

Use project-root resolution, .venv preference, guarded cleanup of build/CbbRefreshVerify and dist/CbbRefreshVerify, Analysis -> PYZ -> EXE -> COLLECT, Qt binary exclusions, executable existence validation, and a hidden smoke run that checks startup and clean-shutdown log entries.

  • Step 4: Run packaging checks and build

Run: python -m pytest tests/test_packaging.py -q
Run: ./packaging/Build-CbbRefreshVerify.ps1

Expected: tests PASS, build exits 0, and dist/CbbRefreshVerify/CbbRefreshVerify.exe exists.

  • Step 5: Smoke-test the frozen executable

Run: dist/CbbRefreshVerify/CbbRefreshVerify.exe --smoke-test --data-root <temporary-directory>

Expected: exit code 0; <temporary-directory>/logs/application.log contains application_start and application_clean_shutdown.

  • Step 6: Commit packaging and documentation
git add packaging tests/test_packaging.py README.md
git commit -m "build: package cbb refresh verify onedir release"

Task 6: End-to-End Fixture Verification and Release Checklist

Files:

  • Create: tests/test_fixture_flow.py
  • Modify: README.md
  • Create: RELEASE-CHECKLIST.md

Interfaces:

  • Fixture flow verifies CBB discovery without modifying fixtures or the production library.

  • Release checklist records build command, executable path, smoke output, fixture reader result, and DMS-dependent limitations.

  • Step 1: Write the fixture-flow test

def test_fixture_library_reader_finds_expected_cbb_names(fake_fixture_dispatch):
    result = read_library(Path("fixtures/cloned-library/mentor_lib.lmc"), dispatch=fake_fixture_dispatch)
    assert "1GPHY_RTL8211F_A" in {item.name for item in result.records}
  • Step 2: Run the fixture test and verify it fails

Run: python -m pytest tests/test_fixture_flow.py -q

Expected: FAIL until the fixture dispatch adapter and typed result path are connected.

  • Step 3: Connect fixture adapter and document environment-dependent DMS behavior

Keep the adapter read-only. Document that a missing DMS returns BLOCKED/UNKNOWN; only a real work-machine run can establish an actual Verify PASS.

  • Step 4: Run the full test suite

Run: python -m pytest -q

Expected: PASS with zero failures.

  • Step 5: Rebuild and repeat frozen smoke test

Run: ./packaging/Build-CbbRefreshVerify.ps1

Expected: exit 0 and the executable plus lifecycle logs are present.

  • Step 6: Review release checklist and commit final state
git add tests/test_fixture_flow.py README.md RELEASE-CHECKLIST.md
git commit -m "test: validate cbb fixture flow and release criteria"

Plan Self-Review

  • Spec coverage: bootstrap/reuse, COM reader, Verify runner, UI, evidence, error handling, packaging, fixture testing, and DMS limitations each have a dedicated task.
  • Placeholder scan: no TBD, TODO, or unspecified implementation steps remain.
  • Type consistency: CbbRecord, LibraryReadResult, VerifyRequest, and VerifyResult are defined before UI and fixture tasks consume them.
  • Scope: the plan does not copy replacement-tool business logic or add PCB synchronization/upload behavior.