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.
This commit is contained in:
commit
11a2b2e46e
130 files changed
+19267
No files matched your search
@@ -0,0 +1,246 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from cbb_refresh_verify.dialog_models import ControlSnapshot, DialogPhase, WindowSnapshot
|
||||
from cbb_refresh_verify.dialog_rules import (
|
||||
DialogRule,
|
||||
RuleConfigError,
|
||||
decide,
|
||||
load_rules,
|
||||
)
|
||||
|
||||
|
||||
ASSETS = Path(__file__).resolve().parents[1] / "src" / "cbb_refresh_verify" / "assets"
|
||||
|
||||
|
||||
def prompt(text, *, phase=DialogPhase.PCB_STARTING, window_class="#32770",
|
||||
control_types=("Text", "Button")):
|
||||
controls = tuple(
|
||||
ControlSnapshot(
|
||||
handle=100 + index,
|
||||
control_id=index,
|
||||
class_name=control_type,
|
||||
name=text if index == 0 else "OK",
|
||||
control_type=control_type,
|
||||
patterns=("Invoke",) if control_type == "Button" else (),
|
||||
)
|
||||
for index, control_type in enumerate(control_types)
|
||||
)
|
||||
return WindowSnapshot(
|
||||
hwnd=10,
|
||||
pid=20,
|
||||
process_name="ExpeditionPCB.exe",
|
||||
process_role="pcb",
|
||||
window_class=window_class,
|
||||
title="Expedition PCB",
|
||||
phase=phase,
|
||||
controls=controls,
|
||||
)
|
||||
|
||||
|
||||
def matching_rule(rule_id, priority):
|
||||
return DialogRule(
|
||||
rule_id=rule_id,
|
||||
priority=priority,
|
||||
category="OBSERVE_PROGRESS",
|
||||
phases=(DialogPhase.PROJECT_INTEGRATION,),
|
||||
semantic_all=("task is being processed",),
|
||||
)
|
||||
|
||||
|
||||
def test_default_save_rule_is_out_of_phase_during_license_acquisition():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
snapshot = prompt(
|
||||
"Do you want to save the Reusable Block cell?",
|
||||
phase=DialogPhase.LICENSE_ACQUISITION,
|
||||
)
|
||||
|
||||
decision = decide(snapshot, rules)
|
||||
|
||||
assert decision.error_code == "DIALOG_OUT_OF_PHASE"
|
||||
assert decision.rule_id == "reusable-block-save"
|
||||
|
||||
|
||||
def test_license_selector_is_allowed_after_com_attach_wait():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
snapshot = prompt(
|
||||
"Select the desired product license",
|
||||
phase=DialogPhase.DOCUMENT_ATTACH,
|
||||
window_class="#32770",
|
||||
control_types=("GXWND", "Button"),
|
||||
)
|
||||
|
||||
decision = decide(snapshot, rules)
|
||||
|
||||
assert decision.rule_id == "license-selector"
|
||||
assert decision.error_code == ""
|
||||
|
||||
|
||||
def test_open_lock_confirmation_is_allowed_during_pcb_starting():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
snapshot = prompt(
|
||||
"Continue to open the design with read/write access permission?",
|
||||
phase=DialogPhase.PCB_STARTING,
|
||||
)
|
||||
|
||||
decision = decide(snapshot, rules)
|
||||
|
||||
assert decision.rule_id == "open-lock-confirm"
|
||||
assert decision.error_code == ""
|
||||
|
||||
|
||||
def test_forward_annotation_confirmation_is_accepted_during_document_attach():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
snapshot = prompt(
|
||||
"New changes are ready for Forward Annotation. Do you want to Forward Annotate now?",
|
||||
phase=DialogPhase.DOCUMENT_ATTACH,
|
||||
)
|
||||
|
||||
decision = decide(snapshot, rules)
|
||||
|
||||
assert decision.rule_id == "forward-annotation-confirm"
|
||||
assert decision.action == "confirm_forward_annotation"
|
||||
assert decision.error_code == ""
|
||||
|
||||
|
||||
def test_forward_annotation_confirmation_is_accepted_during_pcb_starting():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
snapshot = prompt(
|
||||
"New changes are ready for Forward Annotation. Do you want to Forward Annotate now?",
|
||||
phase=DialogPhase.PCB_STARTING,
|
||||
)
|
||||
|
||||
decision = decide(snapshot, rules)
|
||||
|
||||
assert decision.rule_id == "forward-annotation-confirm"
|
||||
assert decision.action == "confirm_forward_annotation"
|
||||
assert decision.error_code == ""
|
||||
|
||||
|
||||
def test_project_integration_panel_is_observation_only():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
snapshot = prompt(
|
||||
"&Project file and Design Forward Annotation Required, connectivity changed "
|
||||
"No pending schematic CES changes to load into PCB",
|
||||
phase=DialogPhase.PROJECT_INTEGRATION,
|
||||
)
|
||||
|
||||
decision = decide(snapshot, rules)
|
||||
|
||||
assert decision.rule_id == "project-integration-panel"
|
||||
assert decision.category == "OBSERVE_PROGRESS"
|
||||
assert decision.action == ""
|
||||
assert decision.error_code == ""
|
||||
|
||||
|
||||
def test_license_selector_prefers_nonblocking_ok_click_before_uia_invoke():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
snapshot = prompt(
|
||||
"Select the desired product license",
|
||||
phase=DialogPhase.DOCUMENT_ATTACH,
|
||||
window_class="#32770",
|
||||
control_types=("GXWND", "Button"),
|
||||
)
|
||||
|
||||
decision = decide(snapshot, rules)
|
||||
|
||||
assert decision.channels.index("win32_button_click") < decision.channels.index("uia_invoke")
|
||||
|
||||
|
||||
def test_tip_of_day_prefers_nonblocking_ok_click_before_uia_invoke():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
decision = decide(prompt("Tip of the Day"), rules)
|
||||
|
||||
assert decision.rule_id == "tip-of-day"
|
||||
assert decision.channels.index("win32_button_click") < decision.channels.index("uia_invoke")
|
||||
|
||||
|
||||
def test_integration_progress_out_of_phase_remains_observation_only():
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json")
|
||||
decision = decide(
|
||||
prompt(
|
||||
"Your task is being processed. Elapsed time 10 seconds",
|
||||
phase=DialogPhase.SAVE,
|
||||
),
|
||||
rules,
|
||||
)
|
||||
|
||||
assert decision.rule_id == "integration-progress"
|
||||
assert decision.category == "OBSERVE_PROGRESS"
|
||||
assert decision.error_code == "DIALOG_OUT_OF_PHASE"
|
||||
|
||||
|
||||
def test_equal_priority_matches_are_rejected():
|
||||
snapshot = prompt(
|
||||
"Your task is being processed. Elapsed time 10 seconds",
|
||||
phase=DialogPhase.PROJECT_INTEGRATION,
|
||||
)
|
||||
|
||||
decision = decide(snapshot, (matching_rule("a", 10), matching_rule("b", 10)))
|
||||
|
||||
assert decision.error_code == "DIALOG_RULE_CONFLICT"
|
||||
assert "a" in decision.detail and "b" in decision.detail
|
||||
|
||||
|
||||
def test_override_replaces_rule_by_id(tmp_path):
|
||||
override = tmp_path / "rules.json"
|
||||
override.write_text(json.dumps({
|
||||
"schema_version": 1,
|
||||
"rules": [{"rule_id": "tip-of-day", "enabled": False}],
|
||||
}), encoding="utf-8")
|
||||
|
||||
rules = load_rules(ASSETS / "dialog_rules.v1.json", override)
|
||||
|
||||
assert next(rule for rule in rules if rule.rule_id == "tip-of-day").enabled is False
|
||||
|
||||
|
||||
def test_unknown_schema_is_rejected(tmp_path):
|
||||
path = tmp_path / "rules.json"
|
||||
path.write_text(json.dumps({"schema_version": 2, "rules": []}), encoding="utf-8")
|
||||
|
||||
with pytest.raises(RuleConfigError, match="schema_version"):
|
||||
load_rules(path)
|
||||
|
||||
|
||||
def test_negative_semantic_evidence_prevents_match():
|
||||
rule = DialogRule(
|
||||
rule_id="continue-not-cancel",
|
||||
priority=1,
|
||||
category="SAFE_CONFIRM",
|
||||
phases=(DialogPhase.PCB_STARTING,),
|
||||
semantic_any=("continue",),
|
||||
semantic_none=("destructive",),
|
||||
action="confirm",
|
||||
)
|
||||
|
||||
decision = decide(prompt("Continue destructive recovery"), (rule,))
|
||||
|
||||
assert decision.error_code == "UNKNOWN_DIALOG"
|
||||
|
||||
|
||||
def test_known_ime_language_bar_is_observation_only_not_an_unknown_dialog():
|
||||
snapshot = WindowSnapshot(hwnd=100, pid=200, process_name='ExpeditionPCB.exe',
|
||||
process_role='pcb', window_class='CiceroUIWndFrame', title='TF_FloatingLangBar_WndTitle',
|
||||
phase=DialogPhase.PCB_STARTING, controls=(), owner_hwnd=99)
|
||||
decision = decide(snapshot, load_rules(ASSETS/'dialog_rules.v1.json'))
|
||||
assert decision.category == 'OBSERVE_PROGRESS'
|
||||
assert decision.error_code == ''
|
||||
assert decision.action == ''
|
||||
|
||||
|
||||
def test_language_bar_filter_does_not_ignore_a_real_dialog_with_same_caption():
|
||||
snapshot = prompt('TF_FloatingLangBar_WndTitle')
|
||||
decision = decide(snapshot, load_rules(ASSETS/'dialog_rules.v1.json'))
|
||||
assert decision.error_code == 'UNKNOWN_DIALOG'
|
||||
|
||||
|
||||
def test_database_open_failure_is_classified_and_declines_log_view():
|
||||
snapshot = prompt('Problem encountered while opening one of the database files. '
|
||||
'See PCBLogFile.txt for details. Loading of the job has failed. '
|
||||
'Do you wish to view the log file now?')
|
||||
decision = decide(snapshot, load_rules(ASSETS/'dialog_rules.v1.json'))
|
||||
assert decision.category == 'FATAL_ACK'
|
||||
assert decision.error_code == 'MENTOR_DATABASE_LOAD_FAILED'
|
||||
assert dict(decision.target)['control_id'] == 7 # IDNO, never launch another log viewer
|
||||
Reference in new issue
Block a user