@@ -140,3 +140,116 @@ def test_remote_execution(cli, datafiles):
140140
141141 # Verify recc is getting action cache hits for both, compiling and linking
142142 assert recc_log .count ("Action Cache hit" ) == 2
143+
144+
145+ @pytest .mark .skipif (not HAVE_SANDBOX , reason = "Only available with a functioning sandbox" )
146+ @pytest .mark .datafiles (DATA_DIR )
147+ def test_cache_only (cli , datafiles ):
148+ project = str (datafiles )
149+ checkout1 = os .path .join (cli .directory , "checkout1" )
150+ checkout2 = os .path .join (cli .directory , "checkout2" )
151+ element_name = "recc/cacheonly.bst"
152+
153+ # Always cache buildtrees to be able to check recc logs
154+ result = cli .run (project = project , args = ["--cache-buildtrees" , "always" , "build" , element_name ])
155+ if result .exit_code != 0 :
156+ # Output recc logs in case of failure
157+ cli .run (
158+ project = project ,
159+ args = [
160+ "shell" ,
161+ "--build" ,
162+ "--use-buildtree" ,
163+ element_name ,
164+ "--" ,
165+ "sh" ,
166+ "-c" ,
167+ "cat config.log .recc-log/* */.recc-log/*" ,
168+ ],
169+ )
170+ assert result .exit_code == 0
171+
172+ result = cli .run (project = project , args = ["artifact" , "checkout" , element_name , "--directory" , checkout1 ])
173+ assert result .exit_code == 0
174+
175+ assert_contains (
176+ checkout1 ,
177+ [
178+ "/usr" ,
179+ "/usr/bin" ,
180+ "/usr/share" ,
181+ "/usr/bin/hello" ,
182+ "/usr/share/doc" ,
183+ "/usr/share/doc/amhello" ,
184+ "/usr/share/doc/amhello/README" ,
185+ ],
186+ )
187+
188+ # Check the main build log
189+ result = cli .run (project = project , args = ["artifact" , "log" , element_name ])
190+ assert result .exit_code == 0
191+ log = result .output
192+
193+ # Verify we get expected output exactly once
194+ assert log .count ("Making all in src" ) == 1
195+
196+ result = cli .run (
197+ project = project ,
198+ args = [
199+ "shell" ,
200+ "--build" ,
201+ "--use-buildtree" ,
202+ element_name ,
203+ "--" ,
204+ "sh" ,
205+ "-c" ,
206+ "cat src/.recc-log/recc.buildbox*" ,
207+ ],
208+ )
209+ assert result .exit_code == 0
210+ recc_log = result .output
211+
212+ # Verify recc is using local execution for both, compiling and linking
213+ assert recc_log .count ("Action not cached and running in cache-only mode, executing locally" ) == 2
214+
215+ # Delete artifact from BuildStream cache to trigger a BuildStream rebuild with action cache hits for recc
216+ result = cli .run (project = project , args = ["artifact" , "delete" , element_name ])
217+ assert result .exit_code == 0
218+
219+ result = cli .run (project = project , args = ["--cache-buildtrees" , "always" , "build" , element_name ])
220+ assert result .exit_code == 0
221+
222+ result = cli .run (project = project , args = ["artifact" , "checkout" , element_name , "--directory" , checkout2 ])
223+ assert result .exit_code == 0
224+
225+ assert_contains (
226+ checkout2 ,
227+ [
228+ "/usr" ,
229+ "/usr/bin" ,
230+ "/usr/share" ,
231+ "/usr/bin/hello" ,
232+ "/usr/share/doc" ,
233+ "/usr/share/doc/amhello" ,
234+ "/usr/share/doc/amhello/README" ,
235+ ],
236+ )
237+
238+ result = cli .run (
239+ project = project ,
240+ args = [
241+ "shell" ,
242+ "--build" ,
243+ "--use-buildtree" ,
244+ element_name ,
245+ "--" ,
246+ "sh" ,
247+ "-c" ,
248+ "cat src/.recc-log/recc.buildbox*" ,
249+ ],
250+ )
251+ assert result .exit_code == 0
252+ recc_log = result .output
253+
254+ # Verify recc is getting action cache hits for both, compiling and linking
255+ assert recc_log .count ("Action Cache hit" ) == 2
0 commit comments