Skip to content

Commit 2e428cd

Browse files
Add docstrings to satisfy CodeRabbit coverage on PR #918.
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 44337b9 commit 2e428cd

4 files changed

Lines changed: 14 additions & 0 deletions

File tree

application/utils/external_project_parsers/parsers/pci_dss.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424

2525
def _parse_float_env(name: str, default: float) -> float:
26+
"""Read a float from an environment variable, falling back on invalid values."""
2627
raw = os.environ.get(name, "").strip()
2728
if not raw:
2829
return default
@@ -34,6 +35,7 @@ def _parse_float_env(name: str, default: float) -> float:
3435

3536

3637
def _parse_float_tuple_env(name: str, default: tuple[float, ...]) -> tuple[float, ...]:
38+
"""Read a comma-separated float tuple from env, falling back on invalid values."""
3739
raw = os.environ.get(name, "").strip()
3840
if not raw:
3941
return default
@@ -46,6 +48,7 @@ def _parse_float_tuple_env(name: str, default: tuple[float, ...]) -> tuple[float
4648

4749

4850
def _parse_str_tuple_env(name: str, default: tuple[str, ...]) -> tuple[str, ...]:
51+
"""Read a comma-separated string tuple from env, falling back when empty."""
4952
raw = os.environ.get(name, "").strip()
5053
if not raw:
5154
return default

application/utils/external_project_parsers/parsers/secure_headers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def entry(self, section: str, hyperlink: str, tags: List[str]) -> defs.Standard:
5353
def resolve_cre_external_id(
5454
self, cache: db.Node_collection, external_id: str
5555
) -> tuple[list[defs.CRE], str]:
56+
"""Resolve a markdown CRE id, applying legacy remaps when needed."""
5657
candidates = [external_id]
5758
remapped = LEGACY_CRE_ID_REMAP.get(external_id)
5859
if remapped and remapped not in candidates:

application/utils/gap_analysis.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ def get_next_id(step, previous_id):
117117

118118

119119
def _link_type_to_path_relationship(ltype: defs.LinkTypes) -> str:
120+
"""Map a link type to the path relationship label stored in GA cache rows."""
120121
if ltype == defs.LinkTypes.AutomaticallyLinkedTo:
121122
return "AUTOMATICALLY_LINKED_TO"
122123
return "LINKED_TO"
123124

124125

125126
def _opencre_overlap_link_sort_key(link: defs.Link) -> int:
127+
"""Prefer manual CRE links over automatic links when ordering overlap paths."""
126128
if link.ltype == defs.LinkTypes.LinkedTo:
127129
return 0
128130
if link.ltype == defs.LinkTypes.AutomaticallyLinkedTo:
@@ -136,6 +138,7 @@ def _build_direct_link_path(
136138
*,
137139
ltype: defs.LinkTypes = defs.LinkTypes.LinkedTo,
138140
) -> Dict[str, Any]:
141+
"""Build a single-hop GA path between two documents with the given link type."""
139142
segment_start = start_document.shallow_copy()
140143
if segment_start.doctype != defs.Credoctypes.CRE.value:
141144
segment_start.id = ""
@@ -160,6 +163,7 @@ def _add_direct_link_result(
160163
*,
161164
ltype: defs.LinkTypes = defs.LinkTypes.LinkedTo,
162165
) -> None:
166+
"""Insert one direct link path into grouped GA results, skipping duplicates."""
163167
shared_paths = grouped_paths.setdefault(
164168
start_document.id,
165169
{
@@ -244,6 +248,7 @@ def opencre_direct_pairs(standard_names: List[str]) -> List[List[str]]:
244248

245249

246250
def missing_opencre_direct_pairs(collection: Any) -> List[List[str]]:
251+
"""Return OpenCRE-directed standard pairs that are not yet cached."""
247252
missing: List[List[str]] = []
248253
for pair in opencre_direct_pairs(collection.standards()):
249254
cache_key = make_resources_key(pair)

scripts/compute_pci_dss_cre_mappings.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656

5757
def _configure_llm_env() -> None:
58+
"""Set default embedding model env vars for offline PCI mapping runs."""
5859
embed_model = os.environ.get("CRE_EMBED_MODEL")
5960
if not embed_model:
6061
vertex_embed = os.environ.get(
@@ -66,6 +67,7 @@ def _configure_llm_env() -> None:
6667

6768

6869
def fetch_pci_rows(url: str = PCI_SHEET_CSV_URL) -> List[Dict[str, str]]:
70+
"""Download PCI DSS spreadsheet rows that include a control id."""
6971
with urllib.request.urlopen(url, timeout=120) as resp:
7072
raw = resp.read().decode("utf-8-sig")
7173
reader = csv.DictReader(io.StringIO(raw))
@@ -80,6 +82,7 @@ def resolve_with_method(
8082
cache,
8183
control_embedding: List[float],
8284
) -> tuple[Optional[defs.CRE], str, Optional[float]]:
85+
"""Resolve one PCI control embedding using the staged PCI DSS linker."""
8386
for threshold in PCI_DSS_CRE_SIMILARITY_THRESHOLDS:
8487
match = prompt.get_id_of_most_similar_cre_paginated(
8588
control_embedding, similarity_threshold=threshold
@@ -112,6 +115,7 @@ def compute_mappings(
112115
*,
113116
limit: Optional[int] = None,
114117
) -> List[Dict[str, Any]]:
118+
"""Embed PCI rows and resolve CRE links, returning per-control mapping records."""
115119
prompt = prompt_client.PromptHandler(cache)
116120
mappings: List[Dict[str, Any]] = []
117121
total = len(rows) if limit is None else min(limit, len(rows))
@@ -155,6 +159,7 @@ def compute_mappings(
155159

156160

157161
def main() -> int:
162+
"""CLI entrypoint for computing PCI DSS to CRE mapping JSON."""
158163
parser = argparse.ArgumentParser(description="Compute PCI DSS → CRE mappings")
159164
parser.add_argument(
160165
"--cache-file",

0 commit comments

Comments
 (0)