@@ -352,3 +352,97 @@ func TestPipelinePushSuccessWithAlphaPatch(t *testing.T) {
352
352
err = PipelinePush (t .Context (), "r8.im/user/test" , dir , apiClient , client , cfg )
353
353
require .NoError (t , err )
354
354
}
355
+
356
+ func TestPipelinePushSuccessWithURLInstallPath (t * testing.T ) {
357
+ // Setup mock web server for cog.replicate.com (token exchange)
358
+ webServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
359
+ switch r .URL .Path {
360
+ case "/api/token/user" :
361
+ // Mock token exchange response
362
+ //nolint:gosec
363
+ tokenResponse := `{
364
+ "keys": {
365
+ "cog": {
366
+ "key": "test-api-token",
367
+ "expires_at": "2024-12-31T23:59:59Z"
368
+ }
369
+ }
370
+ }`
371
+ w .WriteHeader (http .StatusOK )
372
+ w .Write ([]byte (tokenResponse ))
373
+ default :
374
+ w .WriteHeader (http .StatusNotFound )
375
+ }
376
+ }))
377
+ defer webServer .Close ()
378
+
379
+ // Setup mock API server for api.replicate.com (version and release endpoints)
380
+ apiServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
381
+ switch r .URL .Path {
382
+ case "/v1/models/user/test/versions" :
383
+ // Mock version creation response
384
+ versionResponse := `{"id": "test-version-id"}`
385
+ w .WriteHeader (http .StatusCreated )
386
+ w .Write ([]byte (versionResponse ))
387
+ case "/v1/models/user/test/releases" :
388
+ // Mock release creation response - empty body with 204 status
389
+ w .WriteHeader (http .StatusNoContent )
390
+ default :
391
+ w .WriteHeader (http .StatusNotFound )
392
+ }
393
+ }))
394
+ defer apiServer .Close ()
395
+
396
+ cdnServer := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
397
+ switch r .URL .Path {
398
+ case "/requirements.txt" :
399
+ // Mock requirements.txt response
400
+ requirementsResponse := "mycustompackage==1.1.0b2\n coglet @ https://github.com/replicate/cog-runtime/releases/download/v0.1.0-alpha29/coglet-0.1.0a29-py3-none-any.whl"
401
+ w .Header ().Add (EtagHeader , "a" )
402
+ w .WriteHeader (http .StatusOK )
403
+ w .Write ([]byte (requirementsResponse ))
404
+ default :
405
+ w .WriteHeader (http .StatusNotFound )
406
+ }
407
+ }))
408
+ defer cdnServer .Close ()
409
+
410
+ webURL , err := url .Parse (webServer .URL )
411
+ require .NoError (t , err )
412
+ apiURL , err := url .Parse (apiServer .URL )
413
+ require .NoError (t , err )
414
+ cdnURL , err := url .Parse (cdnServer .URL )
415
+ require .NoError (t , err )
416
+
417
+ t .Setenv (env .SchemeEnvVarName , webURL .Scheme )
418
+ t .Setenv (env .WebHostEnvVarName , webURL .Host )
419
+ t .Setenv (env .APIHostEnvVarName , apiURL .Host )
420
+ t .Setenv (env .PipelinesRuntimeHostEnvVarName , cdnURL .Host )
421
+
422
+ dir := t .TempDir ()
423
+
424
+ // Create mock predict
425
+ predictPyPath := filepath .Join (dir , "predict.py" )
426
+ handle , err := os .Create (predictPyPath )
427
+ require .NoError (t , err )
428
+ handle .WriteString ("import cog" )
429
+ handle .Close ()
430
+ dockertest .MockCogConfig = "{\" build\" :{\" python_version\" :\" 3.12\" ,\" python_packages\" :[\" torch==2.5.0\" ,\" mycustompackage>=1.0\" ],\" system_packages\" :[\" git\" ]},\" image\" :\" test\" ,\" predict\" :\" " + predictPyPath + ":Predictor\" }"
431
+
432
+ // Setup mock command
433
+ command := dockertest .NewMockCommand ()
434
+ client , err := cogHttp .ProvideHTTPClient (t .Context (), command )
435
+ require .NoError (t , err )
436
+ webClient := web .NewClient (command , client )
437
+ apiClient := api .NewClient (command , client , webClient )
438
+
439
+ cfg := config .DefaultConfig ()
440
+ requirementsPath := filepath .Join (dir , "requirements.txt" )
441
+ handle , err = os .Create (requirementsPath )
442
+ require .NoError (t , err )
443
+ handle .WriteString ("mycustompackage>=1.0" )
444
+ handle .Close ()
445
+ cfg .Build .PythonRequirements = filepath .Base (requirementsPath )
446
+ err = PipelinePush (t .Context (), "r8.im/user/test" , dir , apiClient , client , cfg )
447
+ require .NoError (t , err )
448
+ }
0 commit comments