@@ -116,7 +116,7 @@ public async Task BuildAsync_ScriptExists_ExecutesPowershell()
116116 Directory . CreateDirectory ( packageDir ) ;
117117 var scriptDir = Path . Combine ( _tempDirectory . DirectoryPath , "eng" , "scripts" ) ;
118118 Directory . CreateDirectory ( scriptDir ) ;
119- File . WriteAllText ( Path . Combine ( scriptDir , "build-sdk .ps1" ) , "# build script" ) ;
119+ File . WriteAllText ( Path . Combine ( scriptDir , "Build-Sdk .ps1" ) , "# build script" ) ;
120120
121121 _mockGitHelper
122122 . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
@@ -144,7 +144,7 @@ public async Task BuildAsync_ScriptFails_ReturnsFailure()
144144 Directory . CreateDirectory ( packageDir ) ;
145145 var scriptDir = Path . Combine ( _tempDirectory . DirectoryPath , "eng" , "scripts" ) ;
146146 Directory . CreateDirectory ( scriptDir ) ;
147- File . WriteAllText ( Path . Combine ( scriptDir , "build-sdk .ps1" ) , "# build script" ) ;
147+ File . WriteAllText ( Path . Combine ( scriptDir , "Build-Sdk .ps1" ) , "# build script" ) ;
148148
149149 _mockGitHelper
150150 . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
@@ -184,7 +184,7 @@ public async Task BuildAsync_DoesNotUseSpecGenSdkConfig()
184184 Directory . CreateDirectory ( packageDir ) ;
185185 var scriptDir = Path . Combine ( _tempDirectory . DirectoryPath , "eng" , "scripts" ) ;
186186 Directory . CreateDirectory ( scriptDir ) ;
187- File . WriteAllText ( Path . Combine ( scriptDir , "build-sdk .ps1" ) , "# build script" ) ;
187+ File . WriteAllText ( Path . Combine ( scriptDir , "Build-Sdk .ps1" ) , "# build script" ) ;
188188
189189 _mockGitHelper
190190 . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
@@ -203,6 +203,173 @@ public async Task BuildAsync_DoesNotUseSpecGenSdkConfig()
203203
204204 #endregion
205205
206+ #region PackAsync Tests
207+
208+ [ Test ]
209+ public async Task PackAsync_EmptyPath_ReturnsFailure ( )
210+ {
211+ var ( success , errorMessage , _, _) = await _service . PackAsync ( string . Empty ) ;
212+
213+ Assert . That ( success , Is . False ) ;
214+ Assert . That ( errorMessage , Does . Contain ( "required and cannot be empty" ) ) ;
215+ }
216+
217+ [ Test ]
218+ public async Task PackAsync_NonexistentPath_ReturnsFailure ( )
219+ {
220+ var ( success , errorMessage , _, _) = await _service . PackAsync ( "/nonexistent/path" ) ;
221+
222+ Assert . That ( success , Is . False ) ;
223+ Assert . That ( errorMessage , Does . Contain ( "does not exist" ) ) ;
224+ }
225+
226+ [ Test ]
227+ public async Task PackAsync_MissingPackScript_ReturnsFailure ( )
228+ {
229+ var packageDir = Path . Combine ( _tempDirectory . DirectoryPath , "sdk" , "core" , "azure_core" ) ;
230+ Directory . CreateDirectory ( packageDir ) ;
231+ File . WriteAllText ( Path . Combine ( packageDir , "Cargo.toml" ) , "[package]\n name = \" azure_core\" \n " ) ;
232+
233+ _mockGitHelper
234+ . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
235+ . ReturnsAsync ( _tempDirectory . DirectoryPath ) ;
236+
237+ SetupCargoMetadata ( "azure_core" , "0.34.0" ) ;
238+
239+ var ( success , errorMessage , _, _) = await _service . PackAsync ( packageDir ) ;
240+
241+ Assert . That ( success , Is . False ) ;
242+ Assert . That ( errorMessage , Does . Contain ( "Pack script not found" ) ) ;
243+ }
244+
245+ [ Test ]
246+ public async Task PackAsync_ScriptExists_ExecutesPowershellWithCorrectArgs ( )
247+ {
248+ var packageDir = Path . Combine ( _tempDirectory . DirectoryPath , "sdk" , "core" , "azure_core" ) ;
249+ Directory . CreateDirectory ( packageDir ) ;
250+ File . WriteAllText ( Path . Combine ( packageDir , "Cargo.toml" ) , "[package]\n name = \" azure_core\" \n " ) ;
251+ CreatePackScript ( ) ;
252+
253+ _mockGitHelper
254+ . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
255+ . ReturnsAsync ( _tempDirectory . DirectoryPath ) ;
256+
257+ SetupCargoMetadata ( "azure_core" , "0.34.0" ) ;
258+
259+ _mockPowershellHelper
260+ . Setup ( x => x . Run ( It . IsAny < PowershellOptions > ( ) , It . IsAny < CancellationToken > ( ) ) )
261+ . ReturnsAsync ( new ProcessResult { ExitCode = 0 , OutputDetails = [ ( StdioLevel . StandardOutput , "ok" ) ] } ) ;
262+
263+ var ( success , _, _, _) = await _service . PackAsync ( packageDir ) ;
264+
265+ Assert . That ( success , Is . True ) ;
266+ _mockPowershellHelper . Verify ( x => x . Run (
267+ It . Is < PowershellOptions > ( o =>
268+ o . Args . Contains ( "-PackageNames" ) &&
269+ o . Args . Contains ( "azure_core" ) &&
270+ o . Args . Contains ( "-NoVerify" ) ) ,
271+ It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
272+ }
273+
274+ [ Test ]
275+ public async Task PackAsync_WithOutputPath_PassesOutputPathArg ( )
276+ {
277+ var packageDir = Path . Combine ( _tempDirectory . DirectoryPath , "sdk" , "core" , "azure_core" ) ;
278+ Directory . CreateDirectory ( packageDir ) ;
279+ File . WriteAllText ( Path . Combine ( packageDir , "Cargo.toml" ) , "[package]\n name = \" azure_core\" \n " ) ;
280+ CreatePackScript ( ) ;
281+ var outputDir = Path . Combine ( _tempDirectory . DirectoryPath , "output" ) ;
282+
283+ _mockGitHelper
284+ . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
285+ . ReturnsAsync ( _tempDirectory . DirectoryPath ) ;
286+
287+ SetupCargoMetadata ( "azure_core" , "0.34.0" ) ;
288+
289+ _mockPowershellHelper
290+ . Setup ( x => x . Run ( It . IsAny < PowershellOptions > ( ) , It . IsAny < CancellationToken > ( ) ) )
291+ . ReturnsAsync ( new ProcessResult { ExitCode = 0 , OutputDetails = [ ] } ) ;
292+
293+ await _service . PackAsync ( packageDir , outputDir ) ;
294+
295+ _mockPowershellHelper . Verify ( x => x . Run (
296+ It . Is < PowershellOptions > ( o =>
297+ o . Args . Contains ( "-OutputPath" ) &&
298+ o . Args . Contains ( outputDir ) ) ,
299+ It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
300+ }
301+
302+ [ Test ]
303+ public async Task PackAsync_ScriptFails_ReturnsFailure ( )
304+ {
305+ var packageDir = Path . Combine ( _tempDirectory . DirectoryPath , "sdk" , "core" , "azure_core" ) ;
306+ Directory . CreateDirectory ( packageDir ) ;
307+ File . WriteAllText ( Path . Combine ( packageDir , "Cargo.toml" ) , "[package]\n name = \" azure_core\" \n " ) ;
308+ CreatePackScript ( ) ;
309+
310+ _mockGitHelper
311+ . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
312+ . ReturnsAsync ( _tempDirectory . DirectoryPath ) ;
313+
314+ SetupCargoMetadata ( "azure_core" , "0.34.0" ) ;
315+
316+ _mockPowershellHelper
317+ . Setup ( x => x . Run ( It . IsAny < PowershellOptions > ( ) , It . IsAny < CancellationToken > ( ) ) )
318+ . ReturnsAsync ( new ProcessResult { ExitCode = 1 , OutputDetails = [ ( StdioLevel . StandardOutput , "cargo publish failed" ) ] } ) ;
319+
320+ var ( success , errorMessage , _, _) = await _service . PackAsync ( packageDir ) ;
321+
322+ Assert . That ( success , Is . False ) ;
323+ Assert . That ( errorMessage , Does . Contain ( "Pack failed with exit code 1" ) ) ;
324+ }
325+
326+ [ Test ]
327+ public async Task PackAsync_ResolvesArtifactPath_WhenCrateExists ( )
328+ {
329+ var packageDir = Path . Combine ( _tempDirectory . DirectoryPath , "sdk" , "core" , "azure_core" ) ;
330+ Directory . CreateDirectory ( packageDir ) ;
331+ File . WriteAllText ( Path . Combine ( packageDir , "Cargo.toml" ) , "[package]\n name = \" azure_core\" \n " ) ;
332+ CreatePackScript ( ) ;
333+
334+ // Create the .crate artifact
335+ var targetDir = Path . Combine ( _tempDirectory . DirectoryPath , "target" , "package" ) ;
336+ Directory . CreateDirectory ( targetDir ) ;
337+ File . WriteAllText ( Path . Combine ( targetDir , "azure_core-0.34.0.crate" ) , "fake" ) ;
338+
339+ _mockGitHelper
340+ . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
341+ . ReturnsAsync ( _tempDirectory . DirectoryPath ) ;
342+
343+ SetupCargoMetadata ( "azure_core" , "0.34.0" ) ;
344+
345+ _mockPowershellHelper
346+ . Setup ( x => x . Run ( It . IsAny < PowershellOptions > ( ) , It . IsAny < CancellationToken > ( ) ) )
347+ . ReturnsAsync ( new ProcessResult { ExitCode = 0 , OutputDetails = [ ] } ) ;
348+
349+ var ( success , _, _, artifactPath ) = await _service . PackAsync ( packageDir ) ;
350+
351+ Assert . That ( success , Is . True ) ;
352+ Assert . That ( artifactPath , Does . Contain ( "azure_core-0.34.0.crate" ) ) ;
353+ }
354+
355+ [ Test ]
356+ public async Task PackAsync_DiscoverRepoRootFails_ReturnsFailure ( )
357+ {
358+ var packageDir = Path . Combine ( _tempDirectory . DirectoryPath , "sdk" , "core" , "azure_core" ) ;
359+ Directory . CreateDirectory ( packageDir ) ;
360+
361+ _mockGitHelper
362+ . Setup ( x => x . DiscoverRepoRootAsync ( It . IsAny < string > ( ) , It . IsAny < CancellationToken > ( ) ) )
363+ . ReturnsAsync ( string . Empty ) ;
364+
365+ var ( success , errorMessage , _, _) = await _service . PackAsync ( packageDir ) ;
366+
367+ Assert . That ( success , Is . False ) ;
368+ Assert . That ( errorMessage , Does . Contain ( "Failed to discover local sdk repo" ) ) ;
369+ }
370+
371+ #endregion
372+
206373 #region GetPackageInfo Tests
207374
208375 [ Test ]
@@ -375,4 +542,15 @@ public async Task GetPackageInfo_CargoOutputWithExtraFields_ParsesCorrectly()
375542 }
376543
377544 #endregion
545+
546+ #region Helper Methods
547+
548+ private void CreatePackScript ( )
549+ {
550+ var scriptDir = Path . Combine ( _tempDirectory . DirectoryPath , "eng" , "scripts" ) ;
551+ Directory . CreateDirectory ( scriptDir ) ;
552+ File . WriteAllText ( Path . Combine ( scriptDir , "Pack-Crates.ps1" ) , "# pack script" ) ;
553+ }
554+
555+ #endregion
378556}
0 commit comments