Skip to content

refactor: extract build configuration factory#197

Closed
PrzemyslawKlys wants to merge 1 commit intocodex/thin-cmdlets-project-versioningfrom
codex/thin-cmdlets-build-configuration
Closed

refactor: extract build configuration factory#197
PrzemyslawKlys wants to merge 1 commit intocodex/thin-cmdlets-project-versioningfrom
codex/thin-cmdlets-build-configuration

Conversation

@PrzemyslawKlys
Copy link
Member

Summary

  • move New-ConfigurationBuild segment assembly into a typed factory
  • keep the cmdlet focused on parameter binding and WriteObject behavior
  • cover missing-module credential and signing certificate validation in focused tests

Validation

  • dotnet test .\PowerForge.Tests\PowerForge.Tests.csproj -c Release --filter "BuildConfigurationFactoryTests|ProjectVersionServiceTests"
  • pwsh .\Module\Build\Build-Module.ps1 -NoSign

Stack

@PrzemyslawKlys PrzemyslawKlys added enhancement New feature or request codex .NET Pull requests that update .NET code labels Mar 11, 2026
@PrzemyslawKlys PrzemyslawKlys deleted the branch codex/thin-cmdlets-project-versioning March 11, 2026 15:35
@claude
Copy link

claude bot commented Mar 11, 2026

Code Review - PR #197: refactor: extract build configuration factory

@claude
Copy link

claude bot commented Mar 11, 2026

Test: can we post?

@claude
Copy link

claude bot commented Mar 11, 2026

Deleting test comment - full review follows

@claude
Copy link

claude bot commented Mar 11, 2026

Code Review - PR 197 refactor extract build configuration factory

Good refactoring overall. Extracting the factory makes the logic unit-testable without standing up a full PSCmdlet, and the new tests cover the most important validation paths. A few issues worth addressing before merging.

POTENTIAL BUGS

  1. CertificatePFXPassword validated by Specified flag only not by value

The PFX password check in CreateSigningSegment only verifies the parameter was bound via CertificatePFXPasswordSpecified, not that it is non-empty. If a caller passes an empty string for -CertificatePFXPassword, the validation passes silently while an empty password proceeds into signing. This is inconsistent with the credential check just above it, which correctly uses string.IsNullOrWhiteSpace. Suggested fix: also check string.IsNullOrWhiteSpace on request.CertificatePFXPassword.

  1. ResolveSecret reads a file without error handling

File.ReadAllText will throw a raw FileNotFoundException or IOException if the path is invalid, with no indication of which parameter caused it. Wrapping and re-throwing as ArgumentException with the file path in the message would give users clearer diagnostics.

  1. else-if chains silently discard conflicting inputs

Both CreateBuildModuleSegment and CreateSigningSegment use else-if chains for mutually exclusive parameters. If a caller specifies more than one, extras are silently ignored. Now that this logic is in a focused factory, it would be worth documenting the priority order in an XML doc comment on Create, or throwing ArgumentException for ambiguous combinations.

MISSING TEST COVERAGE

  1. CertificatePFXBase64 without password is untested

Create_throws_when_pfx_path_has_no_password covers only the CertificatePFXPath branch. The identical validation guard in the CertificatePFXBase64 branch has no test. A parallel test case for CertificatePFXBase64Specified without CertificatePFXPasswordSpecified would close the gap.

  1. Secret file-not-found path is untested

A test passing a non-existent path to InstallMissingModulesCredentialSecretFilePath would document expected behavior and catch regressions if error handling is later improved.

MINOR NOTES

  1. enableBuildLibraries flag is set by only two properties

In CreateBuildLibrariesSegment, buildLibraries.Enable = true only fires when NETConfiguration or NETFramework is specified. Other NET properties such as NETProjectName and NETBinaryModule do not activate Enable. If intentional, a comment explaining the invariant would help future readers.

  1. InstallMissingModulesCredentialUserNameSpecified unused in validation

CreateBuildModuleSegment checks string.IsNullOrWhiteSpace on the username value but never reads the Specified flag. The test Create_reads_missing_module_secret_from_file sets InstallMissingModulesCredentialUserNameSpecified = true, which is harmless but misleading.

SUMMARY

Refactoring intent: Good - clean separation of concerns
ProcessRecord complexity: Significantly reduced
Happy-path test coverage: Covered
Credential and signing validation tests: Covered
PFX password empty-string edge case: Not guarded
File-not-found error handling: Raw exception leaks through
CertificatePFXBase64 test: Missing
Silent else-if parameter priority: Undocumented

The factory pattern is the right approach and the PR is in good shape. Items 1-3 are real bugs worth fixing before merge; items 4-5 are test gaps that would improve confidence. Items 6-7 are low-priority nits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex enhancement New feature or request .NET Pull requests that update .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant