| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664 |
- """Product-specific regression checks for the current FCB board."""
- from __future__ import annotations
- from collections import Counter
- from collections.abc import Mapping
- class BoardRegressionError(RuntimeError):
- """Raised when generated board facts drift from the reviewed board."""
- EXPECTED_COUNTS = {
- "footprints": 1052,
- "touchpoints": 110,
- "pads": 472,
- "connector_contacts": 288,
- "connector_auxiliary_pads": 116,
- }
- EXPECTED_CATEGORIES = {"CON": 62, "J": 16, "PL": 3, "TP": 29}
- FOUR_CONTACT_REFS = {
- "CON12", "CON30", "CON31", "CON32", "CON33", "CON34", "CON35", "CON36",
- "CON37", "CON38", "CON39", "CON40", "CON54", "CON58", "CON59", "CON60",
- "CON61", "CON62", "CON63", "CON64", "CON65", "CON66", "CON67", "CON68",
- "CON69", "CON70", "CON77", "CON78",
- }
- THREE_CONTACT_REFS = {
- "CON53", "CON55", "CON56", "CON57", "CON79", "CON80", "CON81", "CON82",
- "CON83", "CON84", "CON85", "CON86", "CON87", "CON88", "CON89", "CON90",
- "CON91", "CON92", "CON93", "CON94", "CON95", "CON96", "CON97", "CON98",
- }
- FOURTEEN_CONTACT_REFS = {"CON18", "CON27", "CON28", "CON29"}
- POWER_CONTACT_REFS = {"CON2", "CON23"}
- FAN_CONTACT_REFS = {"CON8", "CON24", "CON25", "CON26"}
- EXPECTED_CONNECTOR_REFERENCES = (
- FOUR_CONTACT_REFS
- | THREE_CONTACT_REFS
- | FOURTEEN_CONTACT_REFS
- | POWER_CONTACT_REFS
- | FAN_CONTACT_REFS
- )
- def _category(reference: str) -> str:
- return next((prefix for prefix in ("CON", "J", "PL", "TP") if reference.startswith(prefix)), "OTHER")
- def _pin_index(touchpoint: Mapping[str, object]) -> dict[str, Mapping[str, object]]:
- pins = touchpoint.get("pins", [])
- return {
- str(pin.get("number")): pin
- for pin in pins
- if isinstance(pin, Mapping) and pin.get("number") is not None
- }
- def _validate_recommendable_pins(touchpoints: list[Mapping[str, object]]) -> None:
- for touchpoint in touchpoints:
- for pin in touchpoint.get("pins", []):
- if not isinstance(pin, Mapping):
- continue
- recommendation = pin.get("recommendation")
- if not isinstance(recommendation, Mapping) or recommendation.get("eligible") is not True:
- continue
- fpga = pin.get("fpga")
- valid = (
- pin.get("evidence_tier") == "cross_verified"
- and isinstance(fpga, Mapping)
- and fpga.get("evidence_tier") == "cross_verified"
- and bool(fpga.get("ball"))
- and pin.get("electrical") is True
- and pin.get("mechanical") is not True
- and pin.get("pad_role") == "contact"
- and pin.get("reserved") is not True
- and pin.get("fixed_load_conflict") is not True
- and pin.get("function_category") not in {"power", "ground"}
- and str(pin.get("net") or "").upper() not in {"GND", "AGND", "DGND", "PGND"}
- and pin.get("external_level") not in {None, "", "unknown"}
- )
- if not valid:
- raise BoardRegressionError(
- f"recommendable pin violates contract: {touchpoint.get('reference')}.{pin.get('number')}"
- )
- def _expected_connector_contract(reference: str) -> tuple[str, list[list[str]], set[str], int]:
- if reference in FOUR_CONTACT_REFS:
- order = ["1", "2", "3", "4"] if reference in {"CON54", "CON77", "CON78"} else ["4", "3", "2", "1"]
- return "CON_11251W00_NPX_SX_4P", [[number] for number in order], {"5", "6"}, 0
- if reference in THREE_CONTACT_REFS:
- return "CON_51541_003_P1D25", [["3", "2", "1"]], {"4", "5"}, 0
- if reference in FOURTEEN_CONTACT_REFS:
- return (
- "CON_3110_14P_P2D54",
- [
- ["13", "11", "9", "7", "5", "3", "1"],
- ["14", "12", "10", "8", "6", "4", "2"],
- ],
- set(),
- 0,
- )
- if reference == "CON23":
- return "CON_C22930_1084N_X", [["5", "1"], ["6", "2"], ["7", "3"], ["8", "4"]], {"9", "10"}, 2
- if reference == "CON2":
- return "CON_C22930_1084N_X", [["4", "8"], ["3", "7"], ["2", "6"], ["1", "5"]], {"9", "10"}, 2
- if reference in FAN_CONTACT_REFS:
- return "CON_PZGM_B03_08P", [[str(number)] for number in range(8, 0, -1)], set(), 1
- raise BoardRegressionError(f"missing connector regression contract for {reference}")
- def _validate_connector_contracts(by_reference: Mapping[str, Mapping[str, object]]) -> None:
- actual_references = {reference for reference in by_reference if reference.startswith("CON")}
- if actual_references != EXPECTED_CONNECTOR_REFERENCES:
- missing = sorted(EXPECTED_CONNECTOR_REFERENCES.difference(actual_references))
- extra = sorted(actual_references.difference(EXPECTED_CONNECTOR_REFERENCES))
- raise BoardRegressionError(f"connector reference set drifted; missing={missing} extra={extra}")
- for reference in sorted(EXPECTED_CONNECTOR_REFERENCES):
- touchpoint = by_reference[reference]
- connector = touchpoint.get("connector")
- if not isinstance(connector, Mapping):
- raise BoardRegressionError(f"{reference} connector contract missing")
- profile, grid, shield_numbers, mechanical_count = _expected_connector_contract(reference)
- order = [number for row in grid for number in row]
- if connector.get("review_status") != "cross_verified":
- raise BoardRegressionError(f"{reference} connector layout is not cross-verified")
- if connector.get("profile") != profile:
- raise BoardRegressionError(f"{reference} profile={connector.get('profile')} expected {profile}")
- if connector.get("view") != "board_front":
- raise BoardRegressionError(f"{reference} connector view must be board_front")
- if connector.get("contact_grid") != grid or connector.get("contact_order") != order:
- raise BoardRegressionError(f"{reference} contact order or grid drifted")
- expected_columns = len(grid[0]) if grid else 0
- expected_auxiliary = len(shield_numbers) + mechanical_count
- if (
- connector.get("contact_count") != len(order)
- or connector.get("auxiliary_pad_count") != expected_auxiliary
- or connector.get("rows") != len(grid)
- or connector.get("columns") != expected_columns
- ):
- raise BoardRegressionError(f"{reference} connector dimensions or pad counts drifted")
- raw_pins = touchpoint.get("pins", [])
- pins = [pin for pin in raw_pins if isinstance(pin, Mapping)] if isinstance(raw_pins, list) else []
- pin_ids = [str(pin.get("id") or "") for pin in pins]
- if not all(pin_ids) or len(pin_ids) != len(set(pin_ids)):
- raise BoardRegressionError(f"{reference} pin ids are missing or duplicated")
- numbered = _pin_index(touchpoint)
- for board_order, number in enumerate(order, start=1):
- pin = numbered.get(number)
- if pin is None or pin.get("pad_role") != "contact":
- raise BoardRegressionError(f"{reference}.{number} contact pin role drifted")
- row = next(index for index, values in enumerate(grid, start=1) if number in values)
- column = grid[row - 1].index(number) + 1
- if (
- pin.get("board_order") != board_order
- or pin.get("row") != row
- or pin.get("column") != column
- ):
- raise BoardRegressionError(f"{reference}.{number} board-front position drifted")
- actual_shields = {
- str(pin.get("number")) for pin in pins if pin.get("pad_role") == "shield"
- }
- if actual_shields != shield_numbers:
- raise BoardRegressionError(f"{reference} shield pad classification drifted")
- actual_mechanical = sum(pin.get("pad_role") == "mechanical" for pin in pins)
- if actual_mechanical != mechanical_count:
- raise BoardRegressionError(f"{reference} mechanical pad classification drifted")
- if any(pin.get("pad_role") == "unknown" for pin in pins):
- raise BoardRegressionError(f"{reference} contains an unknown pad role")
- def _validate_j3_jtag(by_reference: Mapping[str, Mapping[str, object]]) -> None:
- touchpoint = by_reference.get("J3")
- if not isinstance(touchpoint, Mapping):
- raise BoardRegressionError("J3 FPGA JTAG header missing")
- if "FPGA JTAG" not in str(touchpoint.get("summary") or ""):
- raise BoardRegressionError("J3 FPGA JTAG purpose missing")
- connector = touchpoint.get("connector")
- grid = [["6", "1"], ["7", "2"], ["8", "3"], ["9", "4"], ["10", "5"]]
- order = [number for row in grid for number in row]
- if not isinstance(connector, Mapping):
- raise BoardRegressionError("J3 connector layout missing")
- if (
- connector.get("profile") != "J3_FPGA_JTAG_2X5"
- or connector.get("review_status") != "cross_verified"
- or connector.get("view") != "board_front"
- or connector.get("contact_grid") != grid
- or connector.get("contact_order") != order
- or connector.get("contact_count") != 10
- or connector.get("auxiliary_pad_count") != 0
- or connector.get("rows") != 5
- or connector.get("columns") != 2
- ):
- raise BoardRegressionError("J3 board-front contact grid drifted")
- pins = _pin_index(touchpoint)
- expected_nets = {
- "1": "N9532014",
- "2": "GND",
- "3": "N9532092",
- "4": "N9532034",
- "5": "N9532142",
- "6": "Net_649",
- "7": "Net_650",
- "8": "Net_648",
- "9": "N9532240",
- "10": "GND",
- }
- if set(pins) != set(expected_nets):
- raise BoardRegressionError("J3 pin set drifted")
- for board_order, number in enumerate(order, start=1):
- pin = pins[number]
- row = next(index for index, values in enumerate(grid, start=1) if number in values)
- column = grid[row - 1].index(number) + 1
- if (
- pin.get("net") != expected_nets[number]
- or pin.get("pad_role") != "contact"
- or pin.get("board_order") != board_order
- or pin.get("row") != row
- or pin.get("column") != column
- ):
- raise BoardRegressionError(f"J3.{number} net or board-front position drifted")
- signal_specs = {
- "1": ("FPGA_TCK", "A7", "input", "jtag_tck", "R63"),
- "3": ("FPGA_TDO", "C6", "output", "jtag_tdo", "R65"),
- "5": ("FPGA_TMS", "B8", "input", "jtag_tms", "R67"),
- "9": ("FPGA_TDI", "A6", "input", "jtag_tdi", "R69"),
- }
- for number, (signal, ball, direction, category, series_resistor) in signal_specs.items():
- pin = pins[number]
- fpga = pin.get("fpga")
- programming = pin.get("programming")
- path_text = " ".join(str(value) for value in pin.get("path", []))
- programming_text = " ".join(
- str(value)
- for value in (
- programming.get("conclusion", "") if isinstance(programming, Mapping) else "",
- programming.get("network_explanation", "") if isinstance(programming, Mapping) else "",
- programming.get("hdl_guidance", "") if isinstance(programming, Mapping) else "",
- *(programming.get("connection_guidance", []) if isinstance(programming, Mapping) else []),
- *(programming.get("risks", []) if isinstance(programming, Mapping) else []),
- )
- )
- if (
- pin.get("direction") != direction
- or pin.get("function_category") != category
- or pin.get("reserved") is not True
- or pin.get("evidence_tier") != "cross_verified"
- or not isinstance(fpga, Mapping)
- or fpga.get("ball") != ball
- or fpga.get("board_signal") != signal
- or fpga.get("evidence_tier") != "cross_verified"
- or signal not in path_text
- or f"U3.{ball}" not in path_text
- or series_resistor not in path_text
- or not isinstance(programming, Mapping)
- or programming.get("status") != "verified_fpga"
- or ("专用" not in programming_text and "dedicated" not in programming_text.lower())
- ):
- raise BoardRegressionError(f"J3.{number} dedicated JTAG path drifted")
- vref = pins["4"]
- vref_programming = vref.get("programming")
- vref_text = " ".join(
- str(value)
- for value in (
- vref.get("summary", ""),
- *vref.get("path", []),
- vref_programming.get("conclusion", "") if isinstance(vref_programming, Mapping) else "",
- vref_programming.get("network_explanation", "") if isinstance(vref_programming, Mapping) else "",
- *(vref_programming.get("connection_guidance", []) if isinstance(vref_programming, Mapping) else []),
- )
- )
- if (
- vref.get("function_category") != "reference_voltage"
- or vref.get("fpga") is not None
- or "R61" not in vref_text
- or "+3V3" not in vref_text
- or not isinstance(vref_programming, Mapping)
- or vref_programming.get("status") != "not_programmable"
- or ("不是给板子供电" not in vref_text and "not board power" not in vref_text.lower())
- ):
- raise BoardRegressionError("J3.4 VREF purpose drifted")
- for number in ("6", "7", "8"):
- pin = pins[number]
- programming = pin.get("programming")
- if (
- pin.get("function_category") != "not_connected"
- or pin.get("fpga") is not None
- or pin.get("reserved") is not True
- or not isinstance(programming, Mapping)
- or programming.get("status") != "not_programmable"
- ):
- raise BoardRegressionError(f"J3.{number} NC status drifted")
- def _validate_programming_guidance(by_reference: Mapping[str, Mapping[str, object]]) -> None:
- for reference, touchpoint in by_reference.items():
- pins = touchpoint.get("pins", [])
- for pin in pins if isinstance(pins, list) else []:
- if not isinstance(pin, Mapping):
- continue
- programming = pin.get("programming")
- if not isinstance(programming, Mapping):
- raise BoardRegressionError(f"{reference}.{pin.get('number')} programming guidance missing")
- if programming.get("status") not in {
- "verified_fpga",
- "verified_mcu",
- "board_only",
- "not_programmable",
- "unknown",
- }:
- raise BoardRegressionError(f"{reference}.{pin.get('number')} programming status invalid")
- for field in ("conclusion", "network_explanation", "hdl_guidance"):
- if not str(programming.get(field) or "").strip():
- raise BoardRegressionError(
- f"{reference}.{pin.get('number')} programming {field} missing"
- )
- for field in ("connection_guidance", "constraints", "risks", "sources"):
- if not isinstance(programming.get(field), list):
- raise BoardRegressionError(
- f"{reference}.{pin.get('number')} programming {field} must be an array"
- )
- if programming.get("status") == "verified_fpga":
- fpga = pin.get("fpga")
- if (
- pin.get("evidence_tier") != "cross_verified"
- or not isinstance(fpga, Mapping)
- or fpga.get("evidence_tier") != "cross_verified"
- or not fpga.get("ball")
- ):
- raise BoardRegressionError(
- f"{reference}.{pin.get('number')} programming claims an unverified FPGA path"
- )
- if programming.get("status") == "verified_mcu":
- mcu = pin.get("mcu")
- if (
- pin.get("evidence_tier") != "cross_verified"
- or not isinstance(mcu, Mapping)
- or mcu.get("evidence_tier") != "cross_verified"
- or not mcu.get("device")
- or not mcu.get("pin")
- or not mcu.get("signal")
- or pin.get("fpga") is not None
- ):
- raise BoardRegressionError(
- f"{reference}.{pin.get('number')} programming claims an invalid MCU path"
- )
- if mcu.get("device") == "U27" and mcu.get("family") != "GD32F303CGT6":
- raise BoardRegressionError(
- f"{reference}.{pin.get('number')} U27 family must remain GD32F303CGT6"
- )
- con78 = _pin_index(by_reference["CON78"])
- for number, signal, ball, peer in (
- ("1", "UART2_TX", "M10", "RX"),
- ("2", "UART2_RX", "N11", "TX"),
- ):
- pin = con78[number]
- programming = pin.get("programming")
- text = " ".join(
- str(value)
- for value in (
- programming.get("conclusion", ""),
- programming.get("network_explanation", ""),
- programming.get("hdl_guidance", ""),
- *programming.get("connection_guidance", []),
- *programming.get("constraints", []),
- )
- ) if isinstance(programming, Mapping) else ""
- required = (signal, ball, "U23", peer, "TTL", f"LOCATION = {ball}", "IOSTANDARD = LVCMOS33")
- if not isinstance(programming, Mapping) or programming.get("status") != "verified_fpga" or any(
- value not in text for value in required
- ):
- raise BoardRegressionError(f"CON78.{number} programming guidance drifted")
- con30_pin4 = _pin_index(by_reference["CON30"])["4"]
- con30_fpga = con30_pin4.get("fpga")
- con30_programming = con30_pin4.get("programming")
- con30_text = " ".join(
- str(value)
- for value in (
- con30_programming.get("conclusion", ""),
- con30_programming.get("network_explanation", ""),
- con30_programming.get("hdl_guidance", ""),
- *con30_programming.get("constraints", []),
- )
- ) if isinstance(con30_programming, Mapping) else ""
- if (
- con30_pin4.get("net") != "FAN_GPIO4"
- or con30_pin4.get("summary") != "MOTOR_EN_N"
- or con30_pin4.get("external_level") != "3.3V LVCMOS"
- or "R937 4.7K to +3V3" not in str(con30_pin4.get("board_pull") or "")
- or not isinstance(con30_fpga, Mapping)
- or con30_fpga.get("ball") != "A10"
- or con30_fpga.get("board_signal") != "MOTOR_EN_N"
- or not isinstance(con30_programming, Mapping)
- or con30_programming.get("status") != "verified_fpga"
- or any(value not in con30_text for value in ("MOTOR_EN_N", "FAN_GPIO4", "A10"))
- ):
- raise BoardRegressionError("CON30.4 MOTOR_EN_N programming guidance drifted")
- if con30_pin4.get("active_level") != "low" or (
- "低电平" not in con30_text and "low active" not in con30_text
- ):
- raise BoardRegressionError("CON30.4 programming must remain low active")
- con31_pin4 = _pin_index(by_reference["CON31"])["4"]
- con31_fpga = con31_pin4.get("fpga")
- con31_programming = con31_pin4.get("programming")
- con31_text = " ".join(
- str(value)
- for value in (
- *con31_pin4.get("path", []),
- con31_pin4.get("polarity", ""),
- con31_programming.get("conclusion", ""),
- con31_programming.get("network_explanation", ""),
- con31_programming.get("hdl_guidance", ""),
- *con31_programming.get("constraints", []),
- )
- ) if isinstance(con31_programming, Mapping) else ""
- if (
- con31_pin4.get("net") != "N9971986"
- or con31_pin4.get("function_category") != "pwm"
- or con31_pin4.get("evidence_tier") != "cross_verified"
- or not isinstance(con31_fpga, Mapping)
- or con31_fpga.get("ball") != "E10"
- or con31_fpga.get("board_signal") != "FAN_GPIO6"
- or con31_fpga.get("evidence_tier") != "cross_verified"
- or not isinstance(con31_programming, Mapping)
- or con31_programming.get("status") != "verified_fpga"
- or con31_programming.get("evidence_tier") != "cross_verified"
- or any(value not in con31_text for value in ("N9971986", "Q105", "FAN_GPIO6", "E10"))
- or ("拉低" not in con31_text and "pulls connector low" not in con31_text)
- ):
- raise BoardRegressionError("CON31.4 programming verified open-collector path drifted")
- con58_pin4 = _pin_index(by_reference["CON58"])["4"]
- con58_fpga = con58_pin4.get("fpga")
- con58_programming = con58_pin4.get("programming")
- con58_text = " ".join(
- str(value)
- for value in (
- con58_pin4.get("summary", ""),
- con58_programming.get("conclusion", ""),
- con58_programming.get("network_explanation", ""),
- con58_programming.get("hdl_guidance", ""),
- *con58_programming.get("constraints", []),
- )
- ) if isinstance(con58_programming, Mapping) else ""
- if (
- con58_pin4.get("net") != "FAN_GPIO38"
- or con58_pin4.get("function_category") != "motor_step"
- or con58_pin4.get("active_level") != "rising_edge"
- or not isinstance(con58_fpga, Mapping)
- or con58_fpga.get("ball") != "D15"
- or con58_fpga.get("board_signal") != "MOTOR_STEP"
- or not isinstance(con58_programming, Mapping)
- or con58_programming.get("status") != "verified_fpga"
- or not any(marker in con58_text for marker in ("上升沿", "rising edge", "rising-edge"))
- ):
- raise BoardRegressionError("CON58.4 MOTOR_STEP rising-edge semantics drifted")
- con65_pin4 = _pin_index(by_reference["CON65"])["4"]
- con65_fpga = con65_pin4.get("fpga")
- con65_programming = con65_pin4.get("programming")
- con65_text = " ".join(
- str(value)
- for value in (
- con65_pin4.get("summary", ""),
- con65_programming.get("conclusion", ""),
- con65_programming.get("network_explanation", ""),
- con65_programming.get("hdl_guidance", ""),
- *con65_programming.get("constraints", []),
- )
- ) if isinstance(con65_programming, Mapping) else ""
- if (
- con65_pin4.get("net") != "FAN_GPIO32"
- or con65_pin4.get("function_category") != "motor_direction"
- or con65_pin4.get("active_level") != "state"
- or not isinstance(con65_fpga, Mapping)
- or con65_fpga.get("ball") != "H14"
- or con65_fpga.get("board_signal") != "MOTOR_DIR"
- or not isinstance(con65_programming, Mapping)
- or con65_programming.get("status") != "verified_fpga"
- or not any(marker in con65_text for marker in ("方向状态", "direction state"))
- ):
- raise BoardRegressionError("CON65.4 MOTOR_DIR state semantics drifted")
- con53_pin1 = _pin_index(by_reference["CON53"])["1"]
- con53_programming = con53_pin1.get("programming")
- con53_text = " ".join(
- str(value)
- for value in (
- con53_programming.get("hdl_guidance", ""),
- *con53_programming.get("risks", []),
- )
- ) if isinstance(con53_programming, Mapping) else ""
- if (
- con53_pin1.get("function_category") != "remote_temperature"
- or not isinstance(con53_programming, Mapping)
- or con53_programming.get("status") != "board_only"
- or "open-drain" not in con53_text
- or not any(marker in con53_text for marker in ("只拉低或释放", "drive low or release"))
- or "R811/R812" not in con53_text
- ):
- raise BoardRegressionError("CON53.1 CT7428 open-drain programming guidance drifted")
- V12_EXPECTED_COUNTS = {
- "footprints": 1317,
- "touchpoints": 118,
- "pads": 629,
- "resistors": 644,
- "resistor_pads": 1288,
- }
- V12_EXPECTED_CATEGORIES = {"CON": 88, "J": 18, "PL": 4, "TP": 8}
- V12_EXPECTED_RESISTORS = 644
- def _board_identity(payload: Mapping[str, object]) -> str:
- board = payload.get("board")
- if not isinstance(board, Mapping):
- return ""
- return f"{board.get('id') or ''} {board.get('name') or ''}".lower()
- def _validate_v12_product_regression(payload: Mapping[str, object]) -> None:
- """Lightweight contract for FCB V1.2 until full cross-verification catches up."""
- counts = payload.get("counts")
- if not isinstance(counts, Mapping):
- raise BoardRegressionError("counts missing")
- for name, expected in V12_EXPECTED_COUNTS.items():
- if counts.get(name) != expected:
- raise BoardRegressionError(f"{name}={counts.get(name)} expected {expected}")
- categories = counts.get("categories")
- if not isinstance(categories, Mapping):
- raise BoardRegressionError("category counts missing")
- for name, expected in V12_EXPECTED_CATEGORIES.items():
- if categories.get(name) != expected:
- raise BoardRegressionError(f"{name}={categories.get(name)} expected {expected}")
- if categories.get("R") != V12_EXPECTED_RESISTORS:
- raise BoardRegressionError(f"R={categories.get('R')} expected {V12_EXPECTED_RESISTORS}")
- sides = counts.get("sides")
- if not isinstance(sides, Mapping) or sides.get("front") != 118 or sides.get("back") != 0:
- back = sides.get("back") if isinstance(sides, Mapping) else "missing"
- raise BoardRegressionError(f"all touchpoints must be front-side; back={back}")
- raw_touchpoints = payload.get("touchpoints", [])
- touchpoints = [item for item in raw_touchpoints if isinstance(item, Mapping)] if isinstance(raw_touchpoints, list) else []
- references = [str(item.get("reference") or "") for item in touchpoints]
- if "CON5" in references:
- raise BoardRegressionError("CON5 must not appear as a footprint hotspot")
- if len(touchpoints) != 118 or len(set(references)) != 118:
- raise BoardRegressionError(
- f"touchpoint list has {len(touchpoints)} rows and {len(set(references))} unique references"
- )
- actual_categories = Counter(_category(reference) for reference in references)
- if dict(actual_categories) != V12_EXPECTED_CATEGORIES:
- raise BoardRegressionError(f"touchpoint reference categories drifted: {dict(actual_categories)}")
- if any(item.get("side") != "front" for item in touchpoints):
- raise BoardRegressionError("touchpoint list contains a non-front item")
- raw_resistors = payload.get("resistors", [])
- resistors = [item for item in raw_resistors if isinstance(item, Mapping)] if isinstance(raw_resistors, list) else []
- resistor_refs = [str(item.get("reference") or "") for item in resistors]
- if len(resistors) != V12_EXPECTED_RESISTORS or len(set(resistor_refs)) != V12_EXPECTED_RESISTORS:
- raise BoardRegressionError(
- f"resistor list has {len(resistors)} rows and {len(set(resistor_refs))} unique references"
- )
- for required in ("R7", "R12", "R63", "R674", "R1225"):
- if required not in set(resistor_refs):
- raise BoardRegressionError(f"{required} missing from resistor index")
- by_reference = {str(item.get("reference")): item for item in touchpoints}
- for required in ("CON12", "CON78", "J3"):
- if required not in by_reference:
- raise BoardRegressionError(f"{required} missing on V1.2 board")
- con78 = by_reference["CON78"]
- pins = _pin_index(con78)
- for number, net in (("1", "RS232_TX2"), ("2", "RS232_RX2")):
- if number not in pins or pins[number].get("net") != net:
- actual = pins.get(number, {}).get("net") if number in pins else "missing"
- raise BoardRegressionError(f"CON78.{number} net={actual} expected {net}")
- _validate_recommendable_pins(touchpoints)
- from .data import validate_resistor_index
- try:
- validate_resistor_index(payload)
- except ValueError as exc:
- raise BoardRegressionError(str(exc)) from exc
- def validate_product_regression(payload: Mapping[str, object]) -> None:
- identity = _board_identity(payload)
- if "v1.2" in identity or "20260717" in identity or "fcb_fpga_mcu_v1_2" in identity:
- _validate_v12_product_regression(payload)
- return
- counts = payload.get("counts")
- if not isinstance(counts, Mapping):
- raise BoardRegressionError("counts missing")
- for name, expected in EXPECTED_COUNTS.items():
- if counts.get(name) != expected:
- raise BoardRegressionError(f"{name}={counts.get(name)} expected {expected}")
- categories = counts.get("categories")
- if not isinstance(categories, Mapping):
- raise BoardRegressionError("category counts missing")
- for name, expected in EXPECTED_CATEGORIES.items():
- if categories.get(name) != expected:
- raise BoardRegressionError(f"{name}={categories.get(name)} expected {expected}")
- sides = counts.get("sides")
- if not isinstance(sides, Mapping) or sides.get("front") != 110 or sides.get("back") != 0:
- back = sides.get("back") if isinstance(sides, Mapping) else "missing"
- raise BoardRegressionError(f"all touchpoints must be front-side; back={back}")
- raw_touchpoints = payload.get("touchpoints", [])
- touchpoints = [item for item in raw_touchpoints if isinstance(item, Mapping)] if isinstance(raw_touchpoints, list) else []
- references = [str(item.get("reference") or "") for item in touchpoints]
- if "CON5" in references:
- raise BoardRegressionError("CON5 must not appear as a footprint hotspot")
- if len(touchpoints) != 110 or len(set(references)) != 110:
- raise BoardRegressionError(f"touchpoint list has {len(touchpoints)} rows and {len(set(references))} unique references")
- actual_categories = Counter(_category(reference) for reference in references)
- if dict(actual_categories) != EXPECTED_CATEGORIES:
- raise BoardRegressionError(f"touchpoint reference categories drifted: {dict(actual_categories)}")
- if any(item.get("side") != "front" for item in touchpoints):
- raise BoardRegressionError("touchpoint list contains a non-front item")
- by_reference = {str(item.get("reference")): item for item in touchpoints}
- _validate_connector_contracts(by_reference)
- _validate_j3_jtag(by_reference)
- con78 = by_reference.get("CON78")
- if con78 is None:
- raise BoardRegressionError("CON78 missing")
- pins = _pin_index(con78)
- expected_nets = {
- "1": "RS232_TX2",
- "2": "RS232_RX2",
- "3": "GND",
- "4": "GND",
- "5": "GND",
- "6": "GND",
- }
- for number, net in expected_nets.items():
- if number not in pins or pins[number].get("net") != net:
- actual = pins.get(number, {}).get("net") if number in pins else "missing"
- raise BoardRegressionError(f"CON78.{number} net={actual} expected {net}")
- for number, ball in (("1", "M10"), ("2", "N11")):
- pin = pins[number]
- fpga = pin.get("fpga")
- if not isinstance(fpga, Mapping) or fpga.get("ball") != ball:
- actual = fpga.get("ball") if isinstance(fpga, Mapping) else "missing"
- raise BoardRegressionError(f"CON78.{number} FPGA ball={actual} expected {ball}")
- if "U23" not in " ".join(str(item) for item in pin.get("path", [])):
- raise BoardRegressionError(f"CON78.{number} path must include U23")
- _validate_recommendable_pins(touchpoints)
- _validate_programming_guidance(by_reference)
|