@@ -3586,3 +3586,73 @@ def fake_open_url(url, timeout=None, extra_headers=None):
35863586 assert len (captured_urls ) == 1
35873587 assert captured_urls [0 ][0 ] == "https://api.github.com/repos/org/repo/releases/assets/42"
35883588 assert captured_urls [0 ][1 ] == {"Accept" : "application/octet-stream" }
3589+
3590+ def test_workflow_add_catalog_based_resolves_github_release_url (self , project_dir ):
3591+ """'workflow add <id>' with catalog GitHub release URL resolves via API."""
3592+ from typer .testing import CliRunner
3593+ from unittest .mock import patch
3594+ from specify_cli import app
3595+
3596+ captured_urls = []
3597+
3598+ class FakeResponse :
3599+ def __init__ (self , data , url = None ):
3600+ self ._data = data
3601+ self ._url = url or "https://api.github.com/repos/org/repo/releases/assets/55"
3602+
3603+ def read (self ):
3604+ return self ._data
3605+
3606+ def geturl (self ):
3607+ return self ._url
3608+
3609+ def __enter__ (self ):
3610+ return self
3611+
3612+ def __exit__ (self , * a ):
3613+ return False
3614+
3615+ def fake_open_url (url , timeout = None , extra_headers = None ):
3616+ captured_urls .append ((url , extra_headers ))
3617+ if "releases/tags/" in url :
3618+ return FakeResponse (json .dumps ({
3619+ "assets" : [{"name" : "workflow.yml" , "url" : "https://api.github.com/repos/org/repo/releases/assets/55" }]
3620+ }).encode ())
3621+ # Use workflow YAML with id matching catalog key
3622+ wf_yaml = """
3623+ schema_version: "1.0"
3624+ workflow:
3625+ id: "my-wf"
3626+ name: "My Workflow"
3627+ version: "1.0.0"
3628+ description: "A catalog workflow"
3629+ steps:
3630+ - id: step-one
3631+ type: shell
3632+ run: "echo hello"
3633+ """
3634+ return FakeResponse (wf_yaml .encode ())
3635+
3636+ fake_catalog_info = {
3637+ "id" : "my-wf" ,
3638+ "name" : "My Workflow" ,
3639+ "version" : "1.0.0" ,
3640+ "url" : "https://github.com/org/repo/releases/download/v2.0/workflow.yml" ,
3641+ "_install_allowed" : True ,
3642+ }
3643+
3644+ runner = CliRunner ()
3645+ with patch .object (Path , "cwd" , return_value = project_dir ), \
3646+ patch ("specify_cli.authentication.http.open_url" , side_effect = fake_open_url ), \
3647+ patch ("specify_cli.workflows.catalog.WorkflowCatalog.get_workflow_info" , return_value = fake_catalog_info ):
3648+ result = runner .invoke (app , ["workflow" , "add" , "my-wf" ])
3649+
3650+ assert result .exit_code == 0 , result .output
3651+ # Should resolve via releases/tags API
3652+ tag_calls = [url for url , _ in captured_urls if "releases/tags/" in url ]
3653+ assert len (tag_calls ) == 1
3654+ assert "releases/tags/v2.0" in tag_calls [0 ]
3655+ # Should download from resolved asset URL with octet-stream
3656+ asset_calls = [(url , h ) for url , h in captured_urls if "releases/assets/" in url ]
3657+ assert len (asset_calls ) >= 1
3658+ assert asset_calls [0 ][1 ] == {"Accept" : "application/octet-stream" }
0 commit comments