@@ -5,6 +5,7 @@ jest.mock("@actions/core", () => {
55 ( name : string ) => ( mockInputs [ name ] ?? "" ) === "true" ,
66 ) ,
77 getInput : jest . fn ( ( name : string ) => mockInputs [ name ] ?? "" ) ,
8+ warning : jest . fn ( ) ,
89 } ;
910} ) ;
1011
@@ -24,6 +25,7 @@ const ORIGINAL_HOME = process.env.HOME;
2425describe ( "cacheDependencyGlob" , ( ) => {
2526 beforeEach ( ( ) => {
2627 jest . resetModules ( ) ;
28+ jest . clearAllMocks ( ) ;
2729 mockInputs = { } ;
2830 process . env . HOME = "/home/testuser" ;
2931 } ) ;
@@ -84,3 +86,74 @@ describe("cacheDependencyGlob", () => {
8486 ) ;
8587 } ) ;
8688} ) ;
89+
90+ describe ( "venvPath" , ( ) => {
91+ beforeEach ( ( ) => {
92+ jest . resetModules ( ) ;
93+ jest . clearAllMocks ( ) ;
94+ mockInputs = { } ;
95+ process . env . HOME = "/home/testuser" ;
96+ } ) ;
97+
98+ afterEach ( ( ) => {
99+ process . env . HOME = ORIGINAL_HOME ;
100+ } ) ;
101+
102+ it ( "defaults to .venv in the working directory" , async ( ) => {
103+ mockInputs [ "working-directory" ] = "/workspace" ;
104+ const { venvPath } = await import ( "../../src/utils/inputs" ) ;
105+ expect ( venvPath ) . toBe ( "/workspace/.venv" ) ;
106+ } ) ;
107+
108+ it ( "resolves a relative venv-path" , async ( ) => {
109+ mockInputs [ "working-directory" ] = "/workspace" ;
110+ mockInputs [ "activate-environment" ] = "true" ;
111+ mockInputs [ "venv-path" ] = "custom-venv" ;
112+ const { venvPath } = await import ( "../../src/utils/inputs" ) ;
113+ expect ( venvPath ) . toBe ( "/workspace/custom-venv" ) ;
114+ } ) ;
115+
116+ it ( "normalizes venv-path with trailing slash" , async ( ) => {
117+ mockInputs [ "working-directory" ] = "/workspace" ;
118+ mockInputs [ "activate-environment" ] = "true" ;
119+ mockInputs [ "venv-path" ] = "custom-venv/" ;
120+ const { venvPath } = await import ( "../../src/utils/inputs" ) ;
121+ expect ( venvPath ) . toBe ( "/workspace/custom-venv" ) ;
122+ } ) ;
123+
124+ it ( "keeps an absolute venv-path unchanged" , async ( ) => {
125+ mockInputs [ "working-directory" ] = "/workspace" ;
126+ mockInputs [ "activate-environment" ] = "true" ;
127+ mockInputs [ "venv-path" ] = "/tmp/custom-venv" ;
128+ const { venvPath } = await import ( "../../src/utils/inputs" ) ;
129+ expect ( venvPath ) . toBe ( "/tmp/custom-venv" ) ;
130+ } ) ;
131+
132+ it ( "expands tilde in venv-path" , async ( ) => {
133+ mockInputs [ "working-directory" ] = "/workspace" ;
134+ mockInputs [ "activate-environment" ] = "true" ;
135+ mockInputs [ "venv-path" ] = "~/.venv" ;
136+ const { venvPath } = await import ( "../../src/utils/inputs" ) ;
137+ expect ( venvPath ) . toBe ( "/home/testuser/.venv" ) ;
138+ } ) ;
139+
140+ it ( "warns when venv-path is set but activate-environment is false" , async ( ) => {
141+ mockInputs [ "working-directory" ] = "/workspace" ;
142+ mockInputs [ "venv-path" ] = "custom-venv" ;
143+
144+ const { activateEnvironment, venvPath } = await import (
145+ "../../src/utils/inputs"
146+ ) ;
147+
148+ expect ( activateEnvironment ) . toBe ( false ) ;
149+ expect ( venvPath ) . toBe ( "/workspace/custom-venv" ) ;
150+
151+ const mockedCore = jest . requireMock ( "@actions/core" ) as {
152+ warning : jest . Mock ;
153+ } ;
154+
155+ expect ( mockedCore . warning ) . toHaveBeenCalledWith (
156+ "venv-path is only used when activate-environment is true" ,
157+ ) ;
158+ } ) ;
159+ } ) ;
0 commit comments