Skip to content

feat(workflows): expose workflow source directory to steps#3469

Open
rhuss wants to merge 4 commits into
github:mainfrom
rhuss:workflow-dir-context
Open

feat(workflows): expose workflow source directory to steps#3469
rhuss wants to merge 4 commits into
github:mainfrom
rhuss:workflow-dir-context

Conversation

@rhuss

@rhuss rhuss commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

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 types
  • SPECKIT_WORKFLOW_DIR environment variable, set automatically for shell steps
  • Persistence of workflow_dir in state.json so resumed workflows restore the original source directory (not the run-directory copy path)

Value semantics:

  • File-loaded workflows: parent directory of the source YAML file
  • Installed-by-ID workflows: the installation directory (.specify/workflows/<id>/)
  • String-loaded workflows: empty (no source path available)
  • On resume: original source directory preserved from first execution

Closes #3467
Refs #3445

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

10 new tests covering:

  • Expression resolution, defaults, and string interpolation for {{ context.workflow_dir }}
  • StepContext field storage
  • from_yaml vs from_string loading behavior
  • SPECKIT_WORKFLOW_DIR env var presence/absence in shell steps
  • Resume preserves original workflow_dir
  • State persistence round-trip
  • Cross-platform (YAML single-quoted scalars, forward-slash paths for Windows)

All 416 tests pass (including 10 new), verified on macOS locally and CI (ubuntu + windows matrix).

AI Disclosure

  • I did use AI assistance (describe below)

Implementation, tests, and bot review triage performed with Claude Code (Opus 4.6). All changes reviewed and approved by the author.

rhuss added 3 commits July 11, 2026 07:34
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
@rhuss rhuss requested a review from mnriem as a code owner July 11, 2026 06:04
Copilot AI review requested due to automatic review settings July 11, 2026 06:04

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.

Pull request overview

Exposes workflow source directories to workflow expressions and shell steps, preserving them across resumed runs.

Changes:

  • Adds context.workflow_dir and SPECKIT_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.

Comment thread src/specify_cli/workflows/engine.py Outdated
Comment thread tests/test_workflows.py
…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
Copilot AI review requested due to automatic review settings July 11, 2026 06:22

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@rhuss rhuss requested a review from Copilot July 11, 2026 06:22

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(workflows): expose workflow source directory to steps via context.workflow_dir and SPECKIT_WORKFLOW_DIR

2 participants