Skip to content

Read version from Composer runtime, not hardcoded constants#81

Merged
kennethphough merged 1 commit into
masterfrom
hotfix/version-from-composer
Apr 26, 2026
Merged

Read version from Composer runtime, not hardcoded constants#81
kennethphough merged 1 commit into
masterfrom
hotfix/version-from-composer

Conversation

@kennethphough

@kennethphough kennethphough commented Apr 26, 2026

Copy link
Copy Markdown
Member

Summary

  • Replace hardcoded MAJOR/MINOR/PATCH constants in src/Core/Version.php with \Composer\InstalledVersions::getPrettyVersion('keyqcloud/kyte-php').
  • 3 new tests pin the new contract.

Why

The old implementation required manual bumps on every release. Nobody did — every install reported v4.1.1 regardless of what composer actually pulled. The MCP serverInfo.version handshake surfaced this on a v4.3.1 install during Phase 2 dev verification last session.

Composer 2.x's InstalledVersions API is the idiomatic answer: returns "v4.3.2" on tagged installs, "dev-master" on branch installs, "unknown" if composer runtime data isn't present. Zero maintenance.

Test plan

  • docker compose -f tests/docker-compose.test.yml run --rm php vendor/bin/phpunit --testsuite unit → 34/34 green locally
  • CI green on this PR

Note

Pre-existing flake spotted while running this: tests/ModelTest.php seeds rows in TestTable that don't get torn down between runs. Rerunning phpunit against the same mariadb container fails at line 285. Fresh container passes. Worth adding tearDown when ModelTest is next touched — not addressed here (scope discipline).

The previous implementation pinned MAJOR/MINOR/PATCH to 4.1.1 and
required someone to manually bump the constants on every release.
Nobody did — every install reported v4.1.1 regardless of what composer
actually pulled. The MCP serverInfo handshake surfaced this on a v4.3.1
install during Phase 2 verification.

Read \Composer\InstalledVersions::getPrettyVersion('keyqcloud/kyte-php')
instead. Returns:
  - "v4.3.2" on a tagged install
  - "dev-master" / "dev-feature/..." on a branch install
  - "unknown" if composer's runtime data isn't present (raw git clone)

This is the standard Composer 2.x API for "what version of this
package is installed." Zero maintenance, correct result.

3 new tests in tests/VersionTest.php pin the new contract:
non-empty string return, parity with Composer\InstalledVersions,
guard against regression to the old hardcoded "v4.1.1" string.

34/34 unit tests green.

Pre-existing flake noted: tests/ModelTest.php seeds rows in TestTable
that don't get torn down between runs; rerunning phpunit against the
same mariadb container fails at line 285. Fresh container passes.
Worth adding tearDown logic when ModelTest is next touched. Not
addressed here (scope discipline).
@kennethphough
kennethphough merged commit 11c2ae9 into master Apr 26, 2026
2 checks passed
@kennethphough
kennethphough deleted the hotfix/version-from-composer branch April 26, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant