[#217] Defer component supplementary check construction#265
Conversation
…time - Change ComponentDefinition.supplementaryChecks from [any DoctorCheck] to a factory closure (URL?, Environment) -> [any DoctorCheck], eliminating the eager ProjectDetector.findProjectRoot() call in convertComponent() - Add --ifdef noindent to .swiftformat and reformat affected files - Add #if DEBUG convenience init on ComponentDefinition for test call sites
- Delegate #if DEBUG convenience init to primary init via self.init() - Change compactMap to map since makeCheck returns non-optional
Code Review SummaryBranch: Clean, well-scoped change. The core problem — No Critical IssuesImportant Issues (2)
Suggestions (3)
Strengths
Pre-existing Issues (outside PR scope)
|
- Add SupplementaryCheckFactory typealias for readability - Document why isAlreadyInstalled passes nil projectRoot - Add tests for component-level doctorChecks factory closure - Add test verifying allDoctorChecks forwards projectRoot to factory
Summary
ExternalPackAdapter.convertComponent()eagerly calledProjectDetector.findProjectRoot()for each component with inlinedoctorChecks, baking the result intoComponentDefinition.supplementaryChecksat construction time. This caused global-scope doctor runs to use CWD's project root instead ofnil, and madeallDoctorChecks(projectRoot:)inconsistent — derived checks used the passed scope, supplementary checks ignored it.Closes #217
Changes
ComponentDefinition.supplementaryChecksfrom[any DoctorCheck]to a factory closure@Sendable (URL?, Environment) -> [any DoctorCheck]that defers construction to execution timeallDoctorChecks(projectRoot:environment:)to call the factory with scope-correct parametersExternalPackAdapter.convertComponent()with a closure, eliminating theProjectDetector.findProjectRoot()callComponentExecutor.isAlreadyInstalled()to call the factory with(nil, Environment())#if DEBUGconvenience init onComponentDefinitionaccepting[any DoctorCheck]for test ergonomics--ifdef noindentto.swiftformatand reformattedEnvironment.swiftTest plan
swift testpasses locally (782 tests in 92 suites)swiftformat --lint .andswiftlintpass without violationsChecklist for engine changes
.shellCommandcomponents havesupplementaryDoctorChecksdefined (deriveDoctorCheck()returnsnilfor shell actions)