Skip to content

Resolve preset templates without PyYAML on the execution host - #5531

Open
XSY-28 wants to merge 11 commits into
github:mainfrom
XSY-28:fix/4884-preset-template-projection
Open

XSY-28 wants to merge 11 commits into
github:mainfrom
XSY-28:fix/4884-preset-template-projection

Conversation

@XSY-28

@XSY-28 XSY-28 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

Preset template resolution can fail when Specify is installed in an isolated environment and the Python interpreter on the agent's machine lacks PyYAML. The CLI now records validated template fields in the installed preset registry. Generated Bash, PowerShell, and Python resolvers read those fields with Python's standard library and direct users to refresh the project when the data is missing or stale.

Preset updates and explicit project refreshes regenerate the data. Existing generated scripts keep their current behavior until refreshed.

Related to #4884, phase 1.

Testing

  • Tested locally with .venv/bin/specify --help
  • The affected macOS suite passed 1,296 tests after merging current main, with 52 platform or fixture skips. It included the new Unicode preset-path regression and upstream legacy UTF-8 controls.
  • Tested a relocated sample project with an installed preset and an isolated interpreter that cannot import PyYAML. Covered missing and stale data, upgrade recovery, update, and removal.

The same regression failed on upstream main with PyYAML is required to resolve preset template composition. Native Windows PowerShell 5.1 verification passed on 240a667, including the batch-launcher variant and Unicode preset paths. The run finished with 169 passes and 101 platform/fixture skips.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance

AI disclosure: OpenAI Codex (GPT-6.2 Sol, gpt-6.2-sol, xhigh reasoning, autonomous mode) investigated the issue, wrote the implementation, tests, and documentation, ran local verification, and drafted this pull request on behalf of @XSY-28. There was no human line-by-line review before submission.

Review follow-up

Commit c978d1d checks Python 3.11+ before accepting an override or fallback. The Bash extension registry reader can use the same PyYAML-free interpreter. Refresh validates all installed manifests and registry data before copying shared scripts. Generated projects require the projection for manifest-bearing presets after refresh, and projects with earlier generated scripts can still use the established YAML path until they upgrade.

The new regressions cover loss of both projection fields, missing or corrupted registry data, malformed YAML, mismatched preset identity, and a failed refresh leaving existing script bytes untouched. The FileHelper check passed on the locally constructed merge tree against the current upstream base used for verification.

The affected local suite passed 2,019 tests with 133 skips. Windows PowerShell 5.1.26100.33822 passed 266 tests with 121 fixture or platform skips on the exact review commit. Native Windows verification

OpenAI Codex (GPT-6.2 Sol, xhigh, autonomous) handled this review round on behalf of @XSY-28.

Second review follow-up

Commit 6695625 uses UTF-8 for the private Bash resolver pipe and reports when a project needs a compatible Python interpreter to honor its registry. The Python entry point returns its normal resolution error when a file cannot be accessed. Preset refresh honors permitted links inside the project and keeps the existing journal and atomic registry-write safeguards.

All four reported cases were reproduced before these changes. The affected local suite passed 2,024 tests with 133 skips, and the FileHelper boundary check passed on the locally constructed upstream merge tree. The exact commit passed 270 tests with 122 skips on Windows PowerShell 5.1.26100.33822. Native Windows verification

OpenAI Codex (GPT-6.2 Sol, xhigh, autonomous) handled this review round on behalf of @XSY-28.

Related to github#4884 (phase 1).

Assisted-by: OpenAI Codex (model: GPT-6.2 Sol, autonomous)
Assisted-by: OpenAI Codex (model: GPT-6.2 Sol, autonomous)
Assisted-by: OpenAI Codex (model: GPT-6.2 Sol, autonomous)
@XSY-28
XSY-28 requested a review from mnriem as a code owner November 23, 2026 16:39
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 16:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved interpreter-selection and registry/projection recovery defects can break preset composition, leave template resolution unrepaired, or silently restore the PyYAML dependency.

5 open issues
What changed in this PR

This PR moves preset-template validation into Specify CLI and stores validated fields in the installed registry, allowing refreshed project scripts to resolve templates without PyYAML on the execution host.

Changes:

  • Generate template projections during preset installation and explicit refresh.
  • Update all three resolver variants to read projections and detect stale data.
  • Document execution-host requirements and add relocated, PyYAML-free regression coverage.

AI-generated review for the requester by GitHub Copilot (model unknown, autonomous); analysis and summary are AI-generated.

File Description
tests/​test_preset_template_execution_host.py Exercises resolution, refresh, update, and removal on an isolated execution host.
tests/​test_check_prerequisites_python_parity.py Reuses the shared script-installation helper.
src/​specify_cli/​presets/​_registry.py Stores and refreshes validated template projections.
src/​specify_cli/​presets/​_manifest.py Hashes the exact manifest bytes parsed.
src/​specify_cli/​presets/​_manager.py Records projection metadata during installation.
src/​specify_cli/​markdown_sections.py Adds shared projection validation and template lookup.
src/​specify_cli/​__init__.py Refreshes preset projections with shared infrastructure.
scripts/​python/​common.py Resolves templates using registry metadata.
scripts/​powershell/​common.ps1 Adds projection-based resolution and stdlib interpreter selection.
scripts/​bash/​common.sh Adds projection-based resolution and stdlib interpreter selection.
docs/​upgrade.md Explains projection refresh during integration upgrades.
docs/​presets/​api.md Documents runtime requirements and recovery guidance.
docs/​installation.md Clarifies Python requirements on the execution host.

Review effort: Balanced (adaptive)

Comment thread scripts/bash/common.sh Resolved
Comment thread scripts/bash/common.sh Resolved
Comment thread scripts/python/common.py Outdated
Comment on lines +567 to +570
if metadata and ("template_projection_version" in metadata or "template_entries" in metadata):
templates = _section_engine().preset_template_projection(manifest_path, metadata)
else:
templates = _legacy_template_entries(manifest_path) if manifest_path.is_file() else []
Comment thread src/specify_cli/presets/_registry.py Resolved
Comment thread src/specify_cli/presets/_registry.py Outdated
Comment on lines +145 to +147
manifest = PresetManifest(path)
if manifest.id != pack_id:
raise PresetValidationError(f"Preset manifest {path} must declare id '{pack_id}'")
@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Nov 23, 2026
adityajai119 and others added 6 commits November 23, 2026 11:01
…ut as UTF-8 (github#5504)

In src/specify_cli/_version.py, Tier-3 install-method detection (uv tool list
and pipx list --json) and post-upgrade verification (specify --version) called
subprocess.run(..., capture_output=True, text=True) without an explicit
encoding:

- On Windows (cp1252), UTF-8 paths or metadata containing cp1252-undefined
  bytes (such as 0x90 or 0x9D) caused subprocess._readerthread to fail with an
  unhandled background-thread UnicodeDecodeError and leave result.stdout as
  None, silently misclassifying uv tool and pipx installations as unsupported
  and failing _verify_upgrade().
- Under narrow POSIX locales (LC_ALL=C), non-ASCII bytes in specify --version
  output raised an unhandled UnicodeDecodeError from _verify_upgrade() past
  except (TimeoutExpired, OSError).

Pass encoding="utf-8", errors="replace" to all three captured subprocess calls.

Fixes github#5503

Assisted-by: OpenCode (model: Gemini 4 Carbon, autonomous)
…g Python helpers (github#5506)

Following github#5475, auto_commit.py, initialize_repo.py, and git_common.py still
invoked git with capture_output=True, text=True and no explicit encoding, and
printed diagnostics directly to sys.stderr without a narrow-pipe fallback:

- In auto_commit.py, git ls-files --others --exclude-standard with
  core.quotepath=false emitted raw UTF-8 paths whose cp1252-undefined bytes
  (such as 0x90) left stdout as None and crashed .stdout.strip() with
  AttributeError.
- In auto_commit.py and initialize_repo.py, git failures emitting UTF-8 bytes
  undefined in cp1252 left result.stdout or result.stderr as None and crashed
  (result.stdout + result.stderr) with TypeError.
- In auto_commit.py, initialize_repo.py, and git_common.py, writing non-ASCII
  diagnostics or branch names to narrow stderr pipes raised UnicodeEncodeError.

Decode git subprocess streams as UTF-8 with replacement, guard nullable streams,
write stderr lines with backslashreplace fallback, and bump the git extension
to 1.0.9.

Fixes github#5505

Assisted-by: OpenCode (model: Gemini 4 Carbon, autonomous)
…tics in Resolve-TemplateContent (github#5502)

* fix(powershell): preserve non-ASCII preset paths and manifest diagnostics in Resolve-TemplateContent

In scripts/powershell/common.ps1, Resolve-TemplateContent Base64-encoded
section selectors from the Python preset.yml probe but printed file_value raw
and redirected stderr under the caller's $ErrorActionPreference = 'Stop':

- Non-ASCII file paths encodable in cp1252 (e.g. templates/cafe with accent)
  were decoded by Windows PowerShell 5.1 under OEM cp437, silently missing the
  preset layer and falling through to lower layers.
- Non-ASCII file paths outside cp1252 (or under ASCII locales) raised
  UnicodeEncodeError inside the probe and failed as manifest_invalid.
- Missing PyYAML (exit 2) and malformed preset.yml (exit 3) triggered a
  terminating NativeCommandError on stderr redirection before reaching the
  $LASTEXITCODE handlers.

Base64-encode file_value alongside selector, relax $ErrorActionPreference
around the probe (matching replace-section), and write probe error details
directly to the temp file as UTF-8.

Fixes github#5501

Assisted-by: OpenCode (model: Gemini 4 Carbon, autonomous)

* test(powershell): restrict only stdio pipe encoding on POSIX in github#5502

Keep UTF-8 filesystem encoding intact on POSIX runners by setting
PYTHONIOENCODING=ascii instead of LC_ALL=C / LANG=C / PYTHONCOERCECLOCALE=0,
so candidate.is_file() resolves Unicode preset paths while the Python probe
pipe remains ASCII-restricted.

Assisted-by: OpenCode (model: Gemini 4 Carbon, autonomous)
`extension add` printed the catalog entry's name with ext_info['name'],
so an entry without one exited with KeyError: 'name' before the
download started. github#5308 made search and info fall back to the ID for
the same entries; add now does too, as the preset twin already does.

Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
preset add printed manifest.name and the catalog entry name straight
into Rich markup, so a name like "Lean Kit [beta]" lost its bracketed
part and "Lean [/] Kit" raised MarkupError after the preset was
already installed. github#3826 escaped the same fields in preset list and
info; add now matches, as extension add already does.

Assisted-by: Claude Code (model: Claude Opus 5.5, autonomous)
Keep direct helper invocation for Windows batch launchers and upstream's Base64 path transport and UTF-8 diagnostics.

Assisted-by: OpenAI Codex (model: GPT-6.2 Sol, autonomous)
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Non-ASCII template filenames fail under ASCII stdout, and missing or invalid registries cause upgrade refresh to silently skip installed presets, leaving template resolution broken.

5 open issues
1 previously missed issue

In code that hasn't changed since last review

Medium severity Encode projection filenames as UTF-8 on stdout

scripts/​bash/​common.sh:725

The new projection path still writes the manifest filename directly to Python's stdout, whose encoding is inherited from the execution host. With a valid projection referencing préface-功能.md and PYTHONIOENCODING=ascii, this invocation fails with UnicodeEncodeError and returns no template; the same fixture resolves successfully with UTF-8, without PyYAML. Force UTF-8 for this subprocess, or use the ASCII-safe filename transport used by the PowerShell helper.

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved Unicode filename handling, uncaught filesystem errors, and skipped legacy preset refreshes can break template resolution or report a successful refresh without restoring functionality.

7 open issues

Review effort: Balanced

Comment thread scripts/bash/common.sh Resolved
Comment thread scripts/python/common.py Resolved
@mnriem

mnriem commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback and fix CI/CD errors

Probe the minimum Python version before accepting a runtime. Validate registry recovery before copying scripts and keep configuration I/O inside FileHelper.

Assisted-by: OpenAI Codex (model: GPT-6.2 Sol, autonomous)
Copilot AI balanced review requested due to automatic review settings November 23, 2026 18:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread scripts/bash/common.sh Resolved
Comment thread src/specify_cli/presets/_registry.py Resolved
@mnriem

mnriem commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

Use UTF-8 for Bash's private manifest pipe, require an interpreter when registry order matters, and report Python filesystem errors. Honor scoped preset input links without changing the journaled registry write boundary.

Assisted-by: OpenAI Codex (model: GPT-6.2 Sol, autonomous)
Copilot AI balanced review requested due to automatic review settings November 23, 2026 19:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed to evaluate a manifest-symlink handling concern that can silently ignore declared configuration and mislabel valid presets as corrupted.

2 open issues
4 resolved since last review

Review effort: Balanced

@mnriem

mnriem commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Please address Copilot feedback

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants