@@ -5477,6 +5477,137 @@ def fake_open_url(url, timeout=None, extra_headers=None):
54775477 assert len (asset_calls ) >= 1
54785478 assert asset_calls [0 ][1 ] == {"Accept" : "application/octet-stream" }
54795479
5480+ def test_workflow_add_from_ghes_release_url_resolves_via_api_v3 (self , project_dir , monkeypatch ):
5481+ """'workflow add <ghes-release-url>' resolves via GHES /api/v3 endpoint."""
5482+ from typer .testing import CliRunner
5483+ from unittest .mock import patch
5484+ from specify_cli import app
5485+ from specify_cli .authentication import http as _auth_http
5486+ from specify_cli .authentication .config import AuthConfigEntry
5487+
5488+ monkeypatch .setattr (_auth_http , "_config_override" , [
5489+ AuthConfigEntry (hosts = ("ghes.example" ,), provider = "github" , auth = "bearer" , token = "t" ),
5490+ ])
5491+
5492+ captured_urls = []
5493+
5494+ class FakeResponse :
5495+ def __init__ (self , data , url = None ):
5496+ self ._data = data
5497+ self ._url = url or "https://ghes.example/api/v3/repos/org/repo/releases/assets/42"
5498+
5499+ def read (self ):
5500+ return self ._data
5501+
5502+ def geturl (self ):
5503+ return self ._url
5504+
5505+ def __enter__ (self ):
5506+ return self
5507+
5508+ def __exit__ (self , * a ):
5509+ return False
5510+
5511+ def fake_open_url (url , timeout = None , extra_headers = None ):
5512+ captured_urls .append ((url , extra_headers ))
5513+ if "releases/tags/" in url :
5514+ return FakeResponse (json .dumps ({
5515+ "assets" : [{"name" : "workflow.yml" , "url" : "https://ghes.example/api/v3/repos/org/repo/releases/assets/42" }]
5516+ }).encode ())
5517+ return FakeResponse (self .VALID_WORKFLOW_YAML .encode ())
5518+
5519+ runner = CliRunner ()
5520+ with patch .object (Path , "cwd" , return_value = project_dir ), \
5521+ patch ("specify_cli.authentication.http.open_url" , side_effect = fake_open_url ):
5522+ result = runner .invoke (app , [
5523+ "workflow" , "add" ,
5524+ "https://ghes.example/org/repo/releases/download/v1.0/workflow.yml" ,
5525+ ])
5526+
5527+ assert result .exit_code == 0 , result .output
5528+ # Tag lookup must use the GHES /api/v3 endpoint
5529+ assert any ("ghes.example/api/v3/repos/org/repo/releases/tags/v1.0" in url for url , _ in captured_urls )
5530+ # Asset download must carry Accept: application/octet-stream
5531+ asset_calls = [(url , h ) for url , h in captured_urls if "releases/assets/" in url ]
5532+ assert len (asset_calls ) >= 1
5533+ assert asset_calls [0 ][1 ] == {"Accept" : "application/octet-stream" }
5534+
5535+ def test_workflow_add_catalog_based_ghes_release_url_resolves_via_api_v3 (self , project_dir , monkeypatch ):
5536+ """'workflow add <id>' with a GHES catalog URL resolves via /api/v3."""
5537+ from typer .testing import CliRunner
5538+ from unittest .mock import patch
5539+ from specify_cli import app
5540+ from specify_cli .authentication import http as _auth_http
5541+ from specify_cli .authentication .config import AuthConfigEntry
5542+
5543+ monkeypatch .setattr (_auth_http , "_config_override" , [
5544+ AuthConfigEntry (hosts = ("ghes.example" ,), provider = "github" , auth = "bearer" , token = "t" ),
5545+ ])
5546+
5547+ captured_urls = []
5548+
5549+ class FakeResponse :
5550+ def __init__ (self , data , url = None ):
5551+ self ._data = data
5552+ self ._url = url or "https://ghes.example/api/v3/repos/org/repo/releases/assets/55"
5553+
5554+ def read (self ):
5555+ return self ._data
5556+
5557+ def geturl (self ):
5558+ return self ._url
5559+
5560+ def __enter__ (self ):
5561+ return self
5562+
5563+ def __exit__ (self , * a ):
5564+ return False
5565+
5566+ ghes_wf_yaml = """
5567+ schema_version: "1.0"
5568+ workflow:
5569+ id: "my-wf"
5570+ name: "My GHES Workflow"
5571+ version: "1.0.0"
5572+ description: "A GHES catalog workflow"
5573+ steps:
5574+ - id: step-one
5575+ type: shell
5576+ run: "echo hello"
5577+ """
5578+
5579+ def fake_open_url (url , timeout = None , extra_headers = None ):
5580+ captured_urls .append ((url , extra_headers ))
5581+ if "releases/tags/" in url :
5582+ return FakeResponse (json .dumps ({
5583+ "assets" : [{"name" : "workflow.yml" , "url" : "https://ghes.example/api/v3/repos/org/repo/releases/assets/55" }]
5584+ }).encode ())
5585+ return FakeResponse (ghes_wf_yaml .encode ())
5586+
5587+ fake_catalog_info = {
5588+ "id" : "my-wf" ,
5589+ "name" : "My GHES Workflow" ,
5590+ "version" : "1.0.0" ,
5591+ "url" : "https://ghes.example/org/repo/releases/download/v2.0/workflow.yml" ,
5592+ "_install_allowed" : True ,
5593+ }
5594+
5595+ runner = CliRunner ()
5596+ with patch .object (Path , "cwd" , return_value = project_dir ), \
5597+ patch ("specify_cli.authentication.http.open_url" , side_effect = fake_open_url ), \
5598+ patch ("specify_cli.workflows.catalog.WorkflowCatalog.get_workflow_info" , return_value = fake_catalog_info ):
5599+ result = runner .invoke (app , ["workflow" , "add" , "my-wf" ])
5600+
5601+ assert result .exit_code == 0 , result .output
5602+ # Tag lookup must use GHES /api/v3
5603+ tag_calls = [url for url , _ in captured_urls if "releases/tags/" in url ]
5604+ assert len (tag_calls ) == 1
5605+ assert "ghes.example/api/v3/repos/org/repo/releases/tags/v2.0" in tag_calls [0 ]
5606+ # Asset download must carry Accept: application/octet-stream
5607+ asset_calls = [(url , h ) for url , h in captured_urls if "releases/assets/" in url ]
5608+ assert len (asset_calls ) >= 1
5609+ assert asset_calls [0 ][1 ] == {"Accept" : "application/octet-stream" }
5610+
54805611
54815612class TestWorkflowRunExitCodes :
54825613 """CLI-level tests for the run/resume process exit codes."""
0 commit comments