Skip to content

feat: add support for flavor selection #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tucksaun
Copy link
Member

@tucksaun tucksaun commented Jul 3, 2025

As a maintainer, I need on a regular basis to pick specific server type to reproduce issues.
But patching source code to do so is:
a. cumbersome
b. error prone

And sometimes this can be useful for users as well (imagine you have a 8.4.5 installed with CLI only and 8.4.4 with FPM and CLI and your project requires FPM for instance).

This also lays the ground to pick more variants (debug or zts for example)

@tucksaun tucksaun force-pushed the feat/variant-support branch 2 times, most recently from 2147c05 to ec516ca Compare July 3, 2025 13:34
@tucksaun tucksaun changed the title feat: add support for variant selection feat: add support for flavor selection Jul 3, 2025
@fabpot fabpot requested a review from Copilot July 4, 2025 06:07
Copilot

This comment was marked as outdated.

@tucksaun tucksaun force-pushed the feat/variant-support branch from 3df8d38 to 9c3a414 Compare July 4, 2025 08:01
@tucksaun tucksaun requested a review from Copilot July 4, 2025 08:01
As a maintainer I need on a regular basis to pick specific server type to reproduce issues.
But patching source code to do so is:
a. cumbersome
b. error prone

And sometimes this can be useful for users as well (imagine you have a 8.4.5 installed with CLI only and 8.4.4 with FPM and CLI and your project requires FPM for instance).

This also lays the ground to pick more flavors (debug or zts for example)
@tucksaun tucksaun force-pushed the feat/variant-support branch from 9c3a414 to 2d61ff5 Compare July 4, 2025 08:02
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for selecting specific PHP “flavors” (cli, cgi, fpm, frankenphp) when discovering and choosing versions. Key changes include:

  • Introduction of Flavor* constants, SupportsFlavor and ForceFlavorIfSupported methods in version.go
  • Parsing of optional -flavor suffix in bestVersion and filtering by flavor in store.go
  • New tests in version_test.go and extended store_test.go to cover flavor-based selection

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
version.go Added flavor constants, override field, SupportsFlavor and ForceFlavorIfSupported, updated serverType
version_test.go Added tests for SupportsFlavor covering all flavor cases
store.go Added newEmpty, updated bestVersion to parse flavor suffix and filter versions
store_test.go Switched to newEmpty, added sorting, extended TestBestVersion to validate “-fpm” requirement
Comments suppressed due to low confidence (3)

version.go:61

  • [nitpick] The field name typeOverride is not immediately clear; consider renaming to overrideServerType or forcedServerType for better readability.
	typeOverride serverType

version.go:144

  • Public methods should have doc comments. Add a comment explaining what ForceFlavorIfSupported does, its side-effects on the Version, and when it should be used.
func (v *Version) ForceFlavorIfSupported(flavor string) bool {

version.go:144

  • There are no tests covering ForceFlavorIfSupported. Add unit tests to verify that it correctly applies overrides only when the flavor is supported and doesn’t apply when unsupported.
func (v *Version) ForceFlavorIfSupported(flavor string) bool {

// look for an exact match, the order does not matter here
for _, v := range s.versions {
if v.Version == versionPrefix {
if v.Version == versionPrefix && v.ForceFlavorIfSupported(flavor) {
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling ForceFlavorIfSupported here mutates the Version (setting typeOverride) during lookup, which can leak state across calls. Consider using SupportsFlavor for filtering and only applying ForceFlavorIfSupported when actually selecting a version to avoid unintended side-effects.

Suggested change
if v.Version == versionPrefix && v.ForceFlavorIfSupported(flavor) {
if v.Version == versionPrefix && v.SupportsFlavor(flavor) {
v.ForceFlavorIfSupported(flavor)

Copilot uses AI. Check for mistakes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot, what do you think about this one? My goal was to avoid unnecessary double checks because selecting the best PHP version is somewhat on the hot path for the CLI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the overhead is significant.

versionPrefix = newVersionPrefix
}

// start from the end as versions are always sorted
for i := len(s.versions) - 1; i >= 0; i-- {
v := s.versions[i]
if strings.HasPrefix(v.Version, versionPrefix) {
if strings.HasPrefix(v.Version, versionPrefix) && v.ForceFlavorIfSupported(flavor) {
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue as above: using ForceFlavorIfSupported here changes the Version state during iteration. Swap this for a pure SupportsFlavor check, and defer state changes until after the best match is chosen.

Suggested change
if strings.HasPrefix(v.Version, versionPrefix) && v.ForceFlavorIfSupported(flavor) {
if strings.HasPrefix(v.Version, versionPrefix) && v.SupportsFlavor(flavor) {
v.ForceFlavorIfSupported(flavor) // Apply state change after match is chosen

Copilot uses AI. Check for mistakes.

} else {
isPatchVersion = true
}
// Check if versionPrefix has a expectedFlavors constraint, if so first do an
Copy link
Preview

Copilot AI Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Minor typo/grammar: “a expectedFlavors constraint” is awkward and refers to a non-existent identifier. Consider rephrasing to “an expected-flavor constraint” or simply “a flavor constraint.”

Suggested change
// Check if versionPrefix has a expectedFlavors constraint, if so first do an
// Check if versionPrefix has an expected-flavor constraint, if so first do an

Copilot uses AI. Check for mistakes.

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

Successfully merging this pull request may close these issues.

2 participants