Skip to content

Commit 6c5cdc8

Browse files
authored
feat: support SPECKIT_WORKFLOW_RUN_ID override
1 parent 1b6b05a commit 6c5cdc8

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

src/specify_cli/workflows/engine.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from __future__ import annotations
1212

1313
import json
14+
import os
1415
import re
1516
import uuid
1617
from datetime import datetime, timezone
@@ -433,8 +434,14 @@ def execute(
433434
"""
434435
from . import STEP_REGISTRY
435436

437+
effective_run_id = run_id
438+
if effective_run_id is None:
439+
env_run_id = os.environ.get("SPECKIT_WORKFLOW_RUN_ID", "").strip()
440+
if env_run_id:
441+
effective_run_id = env_run_id
442+
436443
state = RunState(
437-
run_id=run_id,
444+
run_id=effective_run_id,
438445
workflow_id=definition.id,
439446
project_root=self.project_root,
440447
)

tests/test_workflows.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,48 @@ def test_workflow_without_context_reference_unchanged(self, project_dir):
23322332
assert state.status == RunStatus.COMPLETED
23332333
assert state.step_results["only-step"]["output"]["stdout"].strip() == "hello"
23342334

2335+
def test_run_id_uses_speckit_workflow_run_id_env_override(self, project_dir, monkeypatch):
2336+
"""When no run_id argument is provided, SPECKIT_WORKFLOW_RUN_ID overrides UUID generation."""
2337+
from specify_cli.workflows.engine import WorkflowDefinition, WorkflowEngine
2338+
2339+
monkeypatch.setenv("SPECKIT_WORKFLOW_RUN_ID", "env-run-123")
2340+
definition = WorkflowDefinition.from_string("""
2341+
schema_version: "1.0"
2342+
workflow:
2343+
id: "env-run-id"
2344+
name: "Env Run Id"
2345+
version: "1.0.0"
2346+
steps:
2347+
- id: stamp
2348+
type: shell
2349+
run: "echo {{ context.run_id }}"
2350+
""")
2351+
state = WorkflowEngine(project_dir).execute(definition)
2352+
2353+
assert state.run_id == "env-run-123"
2354+
assert state.step_results["stamp"]["output"]["stdout"].strip() == "env-run-123"
2355+
2356+
def test_run_id_arg_takes_precedence_over_env_override(self, project_dir, monkeypatch):
2357+
"""Explicit run_id keeps existing precedence over SPECKIT_WORKFLOW_RUN_ID."""
2358+
from specify_cli.workflows.engine import WorkflowDefinition, WorkflowEngine
2359+
2360+
monkeypatch.setenv("SPECKIT_WORKFLOW_RUN_ID", "env-run-123")
2361+
definition = WorkflowDefinition.from_string("""
2362+
schema_version: "1.0"
2363+
workflow:
2364+
id: "explicit-run-id"
2365+
name: "Explicit Run Id"
2366+
version: "1.0.0"
2367+
steps:
2368+
- id: stamp
2369+
type: shell
2370+
run: "echo {{ context.run_id }}"
2371+
""")
2372+
state = WorkflowEngine(project_dir).execute(definition, run_id="explicit-456")
2373+
2374+
assert state.run_id == "explicit-456"
2375+
assert state.step_results["stamp"]["output"]["stdout"].strip() == "explicit-456"
2376+
23352377

23362378
# ===== State Persistence Tests =====
23372379

0 commit comments

Comments
 (0)