or set(observed_scope.keys()) != ASSEMBLED_DEVICE_LOT_SCOPE_KEY_SET ): return False, "NON_EXACT_7KEY_SCOPE_MISSING_OR_UNEXPECTED_EXTRA_KEYS", None for key in ASSEMBLED_DEVICE_LOT_SCOPE_KEYS: ev = expected_scope.get(key) ov = observed_scope.get(key) if not _is_canonical_identifier(ev) or not _is_canonical_identifier(ov) or ev != ov: return False, f"SCOPE_KEY_MISSING_NONCANONICAL_OR_MISMATCHED:{key}", None if expected_scope["physical_route_id"] != "ROUTE_3P_MODULAR_PLANAR_ENVELOPE": return False, "PHYSICAL_ROUTE_NOT_ROUTE_3P_MODULAR_PLANAR_ENVELOPE", None eligible_products = { pid: str(spec["donor_sha256"]) for pid, spec in pc.DESIGN_Y_V2_DONOR_BINDINGS.items() if str(spec.get("role") or "") in ELIGIBLE_R3P05_FULLSTACK_ROLES } pvid = expected_scope["product_variant_id"] if pvid not in eligible_products: return False, f"PRODUCT_NOT_ELIGIBLE_FULLSTACK_DESIGN_Y_V2:{pvid}", None if expected_scope["construct_sha256"] != eligible_products[pvid]: return False, "CONSTRUCT_SHA256_MISMATCH_OR_NON_DIGEST", None return True, "OK", pvid def _parse_commonmark_headings(text: str) -> List[Dict[str, Any]]: """Stdlib CommonMark 0.31.2 block parser extracting all rendered ATX and multiline Setext headings. Properly ignores fenced code blocks (backtick/tilde >= 3 chars), indented code blocks (>= 4 spaces or tab), and HTML comments (), while recursively stripping blockquote ('>') and list-item container prefixes so headings inside blockquotes or list items are still detected as rendered headings. """ norm = text.replace("\r\n", "\n").replace("\r", "\n") raw_lines = norm.split("\n") line_offsets: List[int] = [] pos = 0 for ln in raw_lines: line_offsets.append(pos) pos += len(ln) + 1 headings: List[Dict[str, Any]] = [] in_fence = False fence_char = "" fence_len = 0 in_html_comment = False para_lines: List[tuple[int, str, int]] = [] # (line_idx, stripped_text, container_depth) atx_re = re.compile(r"^ {0,3}(#{1,6})(?:[ \t]+(.*?))?[ \t]*$") fence_open_re = re.compile(r"^ {0,3}(`{3,}|~{3,})(.*)$") setext_re = re.compile(r"^ {0,3}(=+|-+)[ \t]*$") bq_re = re.compile(r"^ {0,3}> ?(.*)$") ul_re = re.compile(r"^ {0,3}[-+*][ \t]+(.*)$") ol_re = re.compile(r"^ {0,3}\d{1,9}[.)][ \t]+(.*)$") def _strip_containers(line: str) -> tuple[str, int]: depth = 0 cur = line while True: mb = bq_re.match(cur) if mb: depth += 1 cur = mb.group(1) continue mu = ul_re.match(cur) if mu: depth += 1 cur = mu.group(1) continue mo = ol_re.match(cur) if mo: depth += 1 cur = mo.group(1) continue break return cur, depth def _clean_atx_title(raw_title: str) -> str: t = raw_title.strip() # Strip optional CommonMark closing '#' sequence preceded by space/tab t = re.sub(r"(?:^|[ \t])#+[ \t]*$", "", t).strip() return t def _render_cm_inline_text(raw_title: str) -> str: # Decode CommonMark backslash-escaped ASCII punctuation and HTML character references (., ., etc.) unesc = re.sub(r'\\([!"#$%&\'()*+,\-./:;<=>?@\[\\\]^_`{|}~])', r"\1", raw_title) return html.unescape(unesc) for idx, raw_line in enumerate(raw_lines): # 1. Active HTML comment block (CommonMark Type 2) if in_html_comment: if "-->" in raw_line: in_html_comment = False para_lines.clear() continue # 2. Active fenced code block if in_fence: close_pat = rf"^ {{0,3}}{re.escape(fence_char)}{{{fence_len},}}[ \t]*$" if re.match(close_pat, raw_line): in_fence = False para_lines.clear() continue # Strip blockquote/list containers to inspect leaf block leaf, c_depth = _strip_containers(raw_line) # 3. Blank line resets paragraph buffer if not leaf.strip(): para_lines.clear() continue # 4. Opening HTML comment block (0-3 spaces) if re.match(r"^ {0,3}" not in leaf[leaf.find("