11import test from "ava" ;
2+ import sinon from "sinon" ;
23
4+ import { ActionsEnvVars } from "../actions-util" ;
5+ import { getTestEnv } from "../testing-utils" ;
36import { ConfigurationError } from "../util" ;
47
58import {
@@ -10,15 +13,17 @@ import {
1013} from "./remote-file" ;
1114
1215test ( "expandConfigFileInput accepts full remote addresses" , async ( t ) => {
13- t . deepEqual ( parseRemoteFileAddress ( "owner/repo/path@ref" ) , {
16+ const env = getTestEnv ( ) ;
17+
18+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo/path@ref" ) , {
1419 owner : "owner" ,
1520 repo : "repo" ,
1621 path : "path" ,
1722 ref : "ref" ,
1823 } satisfies RemoteFileAddress ) ;
1924
2025 t . deepEqual (
21- parseRemoteFileAddress ( "owner/repo/path/to/codeql.yml@ref/feature" ) ,
26+ parseRemoteFileAddress ( env , "owner/repo/path/to/codeql.yml@ref/feature" ) ,
2227 {
2328 owner : "owner" ,
2429 repo : "repo" ,
@@ -28,15 +33,50 @@ test("expandConfigFileInput accepts full remote addresses", async (t) => {
2833 ) ;
2934} ) ;
3035
36+ test ( "expandConfigFileInput accepts remote address without an owner" , async ( t ) => {
37+ const env = getTestEnv ( ) ;
38+ const owner = "test-owner" ;
39+ const getRequired = sinon . stub ( env , "getRequired" ) ;
40+ getRequired
41+ . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY )
42+ . returns ( `${ owner } /current-repo` ) ;
43+
44+ t . deepEqual ( parseRemoteFileAddress ( env , "repo@ref" ) , {
45+ owner,
46+ repo : "repo" ,
47+ path : DEFAULT_CONFIG_FILE_NAME ,
48+ ref : "ref" ,
49+ } satisfies RemoteFileAddress ) ;
50+
51+ t . deepEqual ( parseRemoteFileAddress ( env , "repo" ) , {
52+ owner,
53+ repo : "repo" ,
54+ path : DEFAULT_CONFIG_FILE_NAME ,
55+ ref : DEFAULT_CONFIG_FILE_REF ,
56+ } satisfies RemoteFileAddress ) ;
57+ } ) ;
58+
59+ test ( "expandConfigFileInput throws for invalid `GITHUB_REPOSITORY`" , async ( t ) => {
60+ const env = getTestEnv ( ) ;
61+ const getRequired = sinon . stub ( env , "getRequired" ) ;
62+ getRequired . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY ) . returns ( `not-valid` ) ;
63+
64+ t . throws ( ( ) => parseRemoteFileAddress ( env , "repo@ref" ) , {
65+ instanceOf : Error ,
66+ } ) ;
67+ } ) ;
68+
3169test ( "expandConfigFileInput accepts remote address without a path" , async ( t ) => {
32- t . deepEqual ( parseRemoteFileAddress ( "owner/repo@ref" ) , {
70+ const env = getTestEnv ( ) ;
71+
72+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo@ref" ) , {
3373 owner : "owner" ,
3474 repo : "repo" ,
3575 path : DEFAULT_CONFIG_FILE_NAME ,
3676 ref : "ref" ,
3777 } satisfies RemoteFileAddress ) ;
3878
39- t . deepEqual ( parseRemoteFileAddress ( "owner/repo" ) , {
79+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo" ) , {
4080 owner : "owner" ,
4181 repo : "repo" ,
4282 path : DEFAULT_CONFIG_FILE_NAME ,
@@ -45,14 +85,16 @@ test("expandConfigFileInput accepts remote address without a path", async (t) =>
4585} ) ;
4686
4787test ( "expandConfigFileInput accepts remote address without a ref" , async ( t ) => {
48- t . deepEqual ( parseRemoteFileAddress ( "owner/repo/path" ) , {
88+ const env = getTestEnv ( ) ;
89+
90+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo/path" ) , {
4991 owner : "owner" ,
5092 repo : "repo" ,
5193 path : "path" ,
5294 ref : DEFAULT_CONFIG_FILE_REF ,
5395 } satisfies RemoteFileAddress ) ;
5496
55- t . deepEqual ( parseRemoteFileAddress ( "owner/repo/path@" ) , {
97+ t . deepEqual ( parseRemoteFileAddress ( env , "owner/repo/path@" ) , {
5698 owner : "owner" ,
5799 repo : "repo" ,
58100 path : "path" ,
@@ -61,13 +103,17 @@ test("expandConfigFileInput accepts remote address without a ref", async (t) =>
61103} ) ;
62104
63105test ( "expandConfigFileInput rejects invalid values" , async ( t ) => {
64- t . throws ( ( ) => parseRemoteFileAddress ( " " ) , {
65- instanceOf : ConfigurationError ,
66- } ) ;
67- t . throws ( ( ) => parseRemoteFileAddress ( "repo//absolute" ) , {
106+ const env = getTestEnv ( ) ;
107+ const owner = "owner" ;
108+ const getRequired = sinon . stub ( env , "getRequired" ) ;
109+ getRequired
110+ . withArgs ( ActionsEnvVars . GITHUB_REPOSITORY )
111+ . returns ( `${ owner } /current-repo` ) ;
112+
113+ t . throws ( ( ) => parseRemoteFileAddress ( env , " " ) , {
68114 instanceOf : ConfigurationError ,
69115 } ) ;
70- t . throws ( ( ) => parseRemoteFileAddress ( "repo:file.yml:unexpected " ) , {
116+ t . throws ( ( ) => parseRemoteFileAddress ( env , "repo//absolute " ) , {
71117 instanceOf : ConfigurationError ,
72118 } ) ;
73119} ) ;
0 commit comments