MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / load_selection

Function load_selection

scripts/ci/verify-release-selection.py:114–248  ·  view source on GitHub ↗
(
    path: pathlib.Path, *, require_policy: Optional[str] = None
)

Source from the content-addressed store, hash-verified

112
113
114def load_selection(
115 path: pathlib.Path, *, require_policy: Optional[str] = None
116) -> dict[str, dict[str, str]]:
117 regular_status(path, ceiling=MAX_MANIFEST_BYTES, label="release selection")
118 try:
119 text = path.read_text(encoding="utf-8")
120 except UnicodeError as error:
121 raise ContractError("release selection is not UTF-8") from error
122 if "\x00" in text or "\r" in text:
123 raise ContractError("release selection contains forbidden control bytes")
124 lines = text.splitlines()
125 if not lines or lines[0] != "# cbm-release-selection-v1":
126 raise ContractError("release selection marker is missing")
127 metadata: dict[str, str] = {}
128 cursor = 1
129 while cursor < len(lines) and lines[cursor].startswith("# "):
130 raw = lines[cursor][2:]
131 key, separator, value = raw.partition("=")
132 if not separator or not key or not value or key in metadata:
133 raise ContractError(f"malformed or duplicate release-selection metadata: {raw!r}")
134 metadata[key] = value
135 cursor += 1
136 if set(metadata) != {"policy", "targets", "candidates"}:
137 raise ContractError("release selection metadata fields are incomplete or unexpected")
138 if metadata["policy"] not in {"virustotal-v2", "unscanned-dry-run"}:
139 raise ContractError("release selection has an invalid policy")
140 if require_policy is not None and metadata["policy"] != require_policy:
141 raise ContractError(
142 f"release selection policy is {metadata['policy']!r}; required {require_policy!r}"
143 )
144 if metadata["targets"] != str(len(TARGETS)) or metadata["candidates"] != str(
145 len(TARGETS) * len(VARIANTS)
146 ):
147 raise ContractError("release selection metadata does not bind the canonical matrix")
148 reader = csv.DictReader(lines[cursor:], delimiter="\t")
149 if tuple(reader.fieldnames or ()) != SELECTION_FIELDS:
150 raise ContractError("release selection header is malformed or unexpected")
151 rows = list(reader)
152 if any(
153 None in row
154 or any(row.get(field) is None for field in SELECTION_FIELDS)
155 or any(
156 any(ord(character) < 32 for character in value)
157 for value in row.values()
158 if value
159 )
160 for row in rows
161 ):
162 raise ContractError("release selection has missing or surplus cells")
163 if [row["target"] for row in rows] != list(TARGETS):
164 raise ContractError("release selection is not the exact canonical target matrix")
165
166 selections: dict[str, dict[str, str]] = {}
167 analysis_ids: set[str] = set()
168 for row in rows:
169 target = row["target"]
170 binary = "codebase-memory-mcp.exe" if target.startswith("windows-") else "codebase-memory-mcp"
171 classifications = {

Callers 1

mainFunction · 0.85

Calls 3

setFunction · 0.85
regular_statusFunction · 0.70
ContractErrorClass · 0.70

Tested by

no test coverage detected