@@ -3474,3 +3474,115 @@ def test_cli_resume_input_invalid_format_errors(self, project_dir):
34743474 )
34753475 assert result .exit_code == 1
34763476 assert "Invalid input format" in result .stdout
3477+
3478+
3479+ class TestWorkflowAddUrlResolution :
3480+ """CLI-level tests for workflow add <url> GitHub release URL resolution."""
3481+
3482+ VALID_WORKFLOW_YAML = """
3483+ schema_version: "1.0"
3484+ workflow:
3485+ id: "test-wf"
3486+ name: "Test Workflow"
3487+ version: "1.0.0"
3488+ description: "A test workflow"
3489+ steps:
3490+ - id: step-one
3491+ type: shell
3492+ run: "echo hello"
3493+ """
3494+
3495+ def test_workflow_add_from_github_release_url_resolves_and_downloads (self , project_dir ):
3496+ """'workflow add <github-release-url>' resolves to API asset URL."""
3497+ from typer .testing import CliRunner
3498+ from unittest .mock import patch , MagicMock
3499+ from specify_cli import app
3500+
3501+ captured_urls = []
3502+
3503+ class FakeResponse :
3504+ def __init__ (self , data , url = None ):
3505+ self ._data = data
3506+ self ._url = url or "https://api.github.com/repos/org/repo/releases/assets/42"
3507+
3508+ def read (self ):
3509+ return self ._data
3510+
3511+ def geturl (self ):
3512+ return self ._url
3513+
3514+ def __enter__ (self ):
3515+ return self
3516+
3517+ def __exit__ (self , * a ):
3518+ return False
3519+
3520+ def fake_open_url (url , timeout = None , extra_headers = None ):
3521+ captured_urls .append ((url , extra_headers , timeout ))
3522+ if "releases/tags/" in url :
3523+ return FakeResponse (json .dumps ({
3524+ "assets" : [{"name" : "workflow.yml" , "url" : "https://api.github.com/repos/org/repo/releases/assets/42" }]
3525+ }).encode ())
3526+ return FakeResponse (self .VALID_WORKFLOW_YAML .encode ())
3527+
3528+ runner = CliRunner ()
3529+ with patch .object (Path , "cwd" , return_value = project_dir ), \
3530+ patch ("specify_cli.authentication.http.open_url" , side_effect = fake_open_url ):
3531+ result = runner .invoke (app , [
3532+ "workflow" , "add" ,
3533+ "https://github.com/org/repo/releases/download/v1.0/workflow.yml" ,
3534+ ])
3535+
3536+ assert result .exit_code == 0 , result .output
3537+ assert "Test Workflow" in result .output
3538+ # First call resolves the release tag with timeout=30
3539+ tag_calls = [(url , h , t ) for url , h , t in captured_urls if "releases/tags/" in url ]
3540+ assert len (tag_calls ) == 1
3541+ assert tag_calls [0 ][2 ] == 30 # timeout matches download timeout
3542+ # Second call downloads from the resolved asset URL with octet-stream
3543+ asset_calls = [(url , h , t ) for url , h , t in captured_urls if "releases/assets/" in url ]
3544+ assert len (asset_calls ) >= 1
3545+ assert asset_calls [0 ][1 ] == {"Accept" : "application/octet-stream" }
3546+
3547+ def test_workflow_add_from_direct_api_asset_url_passes_through (self , project_dir ):
3548+ """'workflow add <api-asset-url>' uses URL directly with octet-stream."""
3549+ from typer .testing import CliRunner
3550+ from unittest .mock import patch
3551+ from specify_cli import app
3552+
3553+ captured_urls = []
3554+
3555+ class FakeResponse :
3556+ def __init__ (self , data , url = None ):
3557+ self ._data = data
3558+ self ._url = url or "https://api.github.com/repos/org/repo/releases/assets/42"
3559+
3560+ def read (self ):
3561+ return self ._data
3562+
3563+ def geturl (self ):
3564+ return self ._url
3565+
3566+ def __enter__ (self ):
3567+ return self
3568+
3569+ def __exit__ (self , * a ):
3570+ return False
3571+
3572+ def fake_open_url (url , timeout = None , extra_headers = None ):
3573+ captured_urls .append ((url , extra_headers ))
3574+ return FakeResponse (self .VALID_WORKFLOW_YAML .encode ())
3575+
3576+ runner = CliRunner ()
3577+ with patch .object (Path , "cwd" , return_value = project_dir ), \
3578+ patch ("specify_cli.authentication.http.open_url" , side_effect = fake_open_url ):
3579+ result = runner .invoke (app , [
3580+ "workflow" , "add" ,
3581+ "https://api.github.com/repos/org/repo/releases/assets/42" ,
3582+ ])
3583+
3584+ assert result .exit_code == 0 , result .output
3585+ # Should go directly to the asset URL with Accept header
3586+ assert len (captured_urls ) == 1
3587+ assert captured_urls [0 ][0 ] == "https://api.github.com/repos/org/repo/releases/assets/42"
3588+ assert captured_urls [0 ][1 ] == {"Accept" : "application/octet-stream" }
0 commit comments