Skip to content

LockedCommand creates Environment twice (once for lock file, once in perform) #207

@bguidolim

Description

@bguidolim

Severity: LOW

LockedCommand.run() in FileLock.swift creates let env = Environment() solely to derive env.lockFile. Then each command's perform() creates a second Environment() (either directly or via PackCommandContext()).

This double-construction affects all LockedCommand conformers (AddPack, RemovePack, UpdatePack, SyncCommand, DoctorCommand, CleanupCommand, ExportCommand).

The cost is negligible in practice (~12 URL path constructions, static-cached tool resolution), but it's architecturally untidy.

Fix: Change LockedCommand protocol to pass the Environment from run() into perform():

protocol LockedCommand: ParsableCommand {
    var skipLock: Bool { get }
    func perform(env: Environment) throws
}

This would require updating all conformers but eliminates the redundant construction and opens the door for injectable Environment in tests (deferred per decision in decision_testing_command_testability_strategy).

Found during review of #109.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtTechnical debt and code quality improvements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions