@@ -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