Skip to content

Commit 7a23eed

Browse files
committed
fix: address seventh round of Copilot PR review feedback
- Strip frontmatter from command layers during composition: parse each layer into (frontmatter, body), compose bodies only, then reattach the highest-priority frontmatter to avoid leaking YAML metadata - Filter disabled presets in bash resolve_template and resolve_template_content: skip presets with enabled=false - Filter disabled presets in PowerShell Resolve-Template and Resolve-TemplateContent: add Where-Object enabled filter to match Python resolver behavior
1 parent 6dddae8 commit 7a23eed

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

scripts/bash/common.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,8 @@ try:
321321
data = json.load(f)
322322
presets = data.get('presets', {})
323323
for pid, meta in sorted(presets.items(), key=lambda x: x[1].get('priority', 10)):
324-
print(pid)
324+
if meta.get('enabled', True) is not False:
325+
print(pid)
325326
except Exception:
326327
sys.exit(1)
327328
" 2>/dev/null); then
@@ -408,7 +409,8 @@ try:
408409
data = json.load(f)
409410
presets = data.get('presets', {})
410411
for pid, meta in sorted(presets.items(), key=lambda x: x[1].get('priority', 10)):
411-
print(pid)
412+
if meta.get('enabled', True) is not False:
413+
print(pid)
412414
except Exception:
413415
sys.exit(1)
414416
" 2>/dev/null); then

scripts/powershell/common.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ function Resolve-Template {
330330
$presets = $registryData.presets
331331
if ($presets) {
332332
$sortedPresets = $presets.PSObject.Properties |
333+
Where-Object { $null -eq $_.Value.enabled -or $_.Value.enabled -ne $false } |
333334
Sort-Object { if ($null -ne $_.Value.priority) { $_.Value.priority } else { 10 } } |
334335
ForEach-Object { $_.Name }
335336
}
@@ -402,6 +403,7 @@ function Resolve-TemplateContent {
402403
$presets = $registryData.presets
403404
if ($presets) {
404405
$sortedPresets = $presets.PSObject.Properties |
406+
Where-Object { $null -eq $_.Value.enabled -or $_.Value.enabled -ne $false } |
405407
Sort-Object { if ($null -ne $_.Value.priority) { $_.Value.priority } else { 10 } } |
406408
ForEach-Object { $_.Name }
407409
}

src/specify_cli/presets.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,11 +2346,41 @@ def resolve_content(
23462346
if content is None:
23472347
return None
23482348

2349+
# For command composition, strip frontmatter from each layer to avoid
2350+
# leaking YAML metadata into the composed body. The highest-priority
2351+
# layer's frontmatter will be reattached at the end.
2352+
is_command = template_type == "command"
2353+
top_frontmatter_text = None
2354+
2355+
def _strip_frontmatter(text: str) -> tuple:
2356+
"""Return (frontmatter_text_with_fences, body) or (None, text)."""
2357+
if not text.startswith("---"):
2358+
return None, text
2359+
end = text.find("---", 3)
2360+
if end == -1:
2361+
return None, text
2362+
fm_block = text[:end + 3]
2363+
body = text[end + 3:].strip()
2364+
return fm_block, body
2365+
2366+
if is_command:
2367+
fm, body = _strip_frontmatter(content)
2368+
if fm:
2369+
top_frontmatter_text = fm
2370+
content = body
2371+
23492372
# Apply composition layers from bottom to top
23502373
for layer in reversed_layers[start_idx:]:
23512374
layer_content = layer["path"].read_text(encoding="utf-8")
23522375
strategy = layer["strategy"]
23532376

2377+
if is_command:
2378+
fm, layer_body = _strip_frontmatter(layer_content)
2379+
layer_content = layer_body
2380+
# Track the highest-priority frontmatter seen
2381+
if fm:
2382+
top_frontmatter_text = fm
2383+
23542384
if strategy == "replace":
23552385
content = layer_content
23562386
elif strategy == "prepend":
@@ -2371,4 +2401,8 @@ def resolve_content(
23712401
)
23722402
content = layer_content.replace(placeholder, content)
23732403

2404+
# Reattach the highest-priority frontmatter for commands
2405+
if is_command and top_frontmatter_text:
2406+
content = top_frontmatter_text + "\n\n" + content
2407+
23742408
return content

0 commit comments

Comments
 (0)