feat(workflows): expose workflow source directory to steps#3469
Open
rhuss wants to merge 4 commits into
Open
Conversation
Propagate WorkflowDefinition.source_path to steps via
{{ context.workflow_dir }} in template expressions and
SPECKIT_WORKFLOW_DIR env var for shell steps. The original
source directory is persisted in state.json so resume
restores the correct value instead of the run-directory copy path.
Closes github#3467
Assisted-By: 🤖 Claude Code
Applied fixes from bot review comments: - Comment #3563319058: prevent stale SPECKIT_WORKFLOW_DIR leak from parent env - Comment #3563319094: use cross-platform Python one-liner instead of printenv - Comment #3563319103: add monkeypatch.delenv for deterministic env var test - Comment #3563319116: same env leak fix as #3563319058 Assisted-By: 🤖 Claude Code
sys.executable on Windows returns backslash paths (D:\a\...) which YAML
double-quoted strings interpret as escape sequences. Switch to
single-quoted YAML strings and normalize paths with replace("\\", "/").
Assisted-By: 🤖 Claude Code
Contributor
There was a problem hiding this comment.
Pull request overview
Exposes workflow source directories to workflow expressions and shell steps, preserving them across resumed runs.
Changes:
- Adds
context.workflow_dirandSPECKIT_WORKFLOW_DIR. - Persists the source directory in run state.
- Adds expression, shell, persistence, and resume tests.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/base.py |
Adds workflow directory to step context. |
src/specify_cli/workflows/engine.py |
Derives, persists, and restores the directory. |
src/specify_cli/workflows/expressions.py |
Exposes the directory to templates. |
src/specify_cli/workflows/steps/shell/__init__.py |
Supplies the shell environment variable. |
tests/test_workflows.py |
Tests the new behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…st (github#3469) Applied fixes from bot review comments: - Comment #3563382853: resolve source_path before taking parent to ensure absolute paths - Comment #3563382864: add test for installed-by-ID workflow_dir semantics Assisted-By: 🤖 Claude Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Expose the resolved source directory of a workflow definition to steps, enabling workflows to reference sibling files (extension manifests, adapter scripts, etc.) without requiring the user to pass the path redundantly.
What this adds:
{{ context.workflow_dir }}template expression, available in all step typesSPECKIT_WORKFLOW_DIRenvironment variable, set automatically for shell stepsworkflow_dirinstate.jsonso resumed workflows restore the original source directory (not the run-directory copy path)Value semantics:
.specify/workflows/<id>/)Closes #3467
Refs #3445
Testing
uv run specify --helpuv sync && uv run pytest10 new tests covering:
{{ context.workflow_dir }}from_yamlvsfrom_stringloading behaviorSPECKIT_WORKFLOW_DIRenv var presence/absence in shell stepsAll 416 tests pass (including 10 new), verified on macOS locally and CI (ubuntu + windows matrix).
AI Disclosure
Implementation, tests, and bot review triage performed with Claude Code (Opus 4.6). All changes reviewed and approved by the author.