Skip to content

Fix three class names held in strings, and gate the shape - #1537

Merged
fog-workflows[bot] merged 2 commits into
working-1.6from
fix-string-class-literals
Aug 31, 2026
Merged

fog-workflows[bot] merged 2 commits into
working-1.6from
fix-string-class-literals

Conversation

@mastacontrola

@mastacontrola mastacontrola commented Aug 31, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1535, found by running the namespaced plugin tree against a live install rather than reasoning about it. Three separate sites, one mistake.

A class name held in a string is resolved as written, from the global namespace. The enclosing namespace is not applied and use is not consulted. Since ADR 0013 §2 retired the reverse aliases, nothing declares the global spellings any more — so each of these named a class that does not exist. None of them throw: the predicate answers "no such class" exactly as it would for a genuine absence, and the caller quietly takes its fallback.

Site Was Symptom
PluginRunner::_discoverTasks() is_subclass_of(basename($file, '.task.php'), …) every plugin task skipped; the only trace is Skipping, not a PluginTask
Plugin::getManager() class_exists(pName . 'Manager') falls back to PluginManager; installdb() then correctly reports a manager file it cannot load, so every plugin install throws
OpenAPI::_permission() method_exists('Authorization', …) returned null for every operation — the published API document described the whole REST API as needing no permission

The same call in _discoverTasks() already carried a comment recording this exact failure for its second argument. It was written for one argument and not the other.

The fixes

The two plugin sites go through FOGBase::qualify(), which leaves a plugin still in the global namespace untouched — both spellings work, which is the compatibility guarantee #1535 is built on.

OpenAPI::_permission()'s guard is deleted rather than qualified. It bought nothing even when it worked: the method it tests for is declared in this repository, beside the file that was testing for it. (PHPStan says the same thing once the name resolves — function.alreadyNarrowedType.)

The gate

tests/string-class-literals-are-qualified.test.php is new and general: a token-driven scan of packages/ for a bare class literal in method_exists(), class_exists(), is_subclass_of(), property_exists() and friends, checking argument 0 — and argument 1 for is_subclass_of()/is_a(), which is the position that cost _discoverTasks() its tasks. A literal PHP itself declares (class_exists('PDO')) is allowed; those really are global.

Token-driven rather than regex on purpose: the same text already appears inside a comment in FOGURLRequests.php, recounting this exact bug in prose.

It counts 2 with the fixes reverted and 0 now.

tests/plugin-namespace.test.php gains the two plugin call sites — getManager() executed against a fixture plugin (the mutation returns FOG\Managers\PluginManager, which is the reported symptom), and _discoverTasks() anchored on its whole expression, because the method itself needs a database.

Verification

  • Both new call-site assertions and the new gate were mutation-verified — each reversion observed red, restored from a scratchpad copy rather than git checkout --.
  • Full suite 242/242; both phpstan passes clean, unscoped.
  • Against the lab (podman MariaDB from a dump of the 1.6 server, shadow web tree, namespaced plugin tree on disk): getManager() + installdb() now succeed for all seven installed plugins (ldap, location, windowskey, ou, ntfy, helloworld, oidc) — this is what threw before the fix. The one real .task.php in fog-plugins resolves: helloworldheartbeat is not a PluginTask, FOG\Plugins\Helloworld\HelloWorldHeartbeat is.

Downstream

No change to Route::$validClasses, so nothing for FogApi to sync. The OpenAPI change alters the content of the published document — every operation now carries the permission it always required — without changing which paths it describes.

Also here: the FOG_PLUGINS_VERSION bump

v1.6.21 → v1.6.22, the fog-plugins release that carries the namespaces (FOGProject/fog-plugins#33). It rides in this PR rather than one of its own because the two fixes above are its precondition — on a core without them, every plugin install throws and every plugin task is skipped. A pin bump landing first would ship that combination for however long it sat alone.

Found by running the namespaced plugins against a live install rather than
reasoning about them. A class name in a PHP string is resolved as written,
from the global namespace -- the enclosing namespace is not applied and
`use` is not consulted -- so every one of these named a class that stopped
existing when ADR 0013 §2 retired the reverse aliases. None of them throw:
the predicate answers "no such class" and the caller takes its fallback.

  - PluginRunner::_discoverTasks() handed a bare basename to
    is_subclass_of(), so a namespaced task is not a PluginTask and the
    daemon skips every plugin task, logging only "Skipping, not a
    PluginTask". The same call's SECOND argument already carried a comment
    recording this exact failure.
  - Plugin::getManager() handed plugins.pName . 'Manager' to class_exists()
    and fell back to PluginManager. installdb() then correctly reports a
    manager file it cannot load, so every plugin install throws.
  - OpenAPI::_permission() guarded on method_exists('Authorization', ...),
    false on every call, so the published API document described the whole
    REST API as needing no permission. The guard is gone rather than
    qualified: the method is declared in this repository, beside the file
    that was testing for it.

The first two go through FOGBase::qualify(), which leaves a plugin still in
the global namespace untouched -- so both spellings work, which is the
compatibility guarantee this branch is built on.

tests/string-class-literals-are-qualified.test.php is the general gate: a
token-driven scan for a bare class literal in method_exists(), class_exists(),
is_subclass_of() and friends, allowing classes PHP itself declares. It counts
2 with the fixes reverted. tests/plugin-namespace.test.php gains the two
plugin call sites -- getManager() executed against a fixture plugin,
_discoverTasks() anchored on its whole expression because it needs a
database.

Co-Authored-By: Claude <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot enabled auto-merge August 31, 2026 13:21
The release every plugin class in FOG\Plugins\<Plugin> ships in, paired with
the core autoload arm that resolves it (#1535). Without this bump the change
never reaches a server: the installer reads this constant to pick which
plugins release to download.

It rides in this pull request rather than one of its own, because the
namespaced plugins need the two fixes here. On a core without them every
plugin install throws and every plugin task is skipped -- so a pin bump
landing first would ship a broken combination for however long it sat alone.

Co-Authored-By: Claude <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot added this pull request to the merge queue Aug 31, 2026
Merged via the queue into working-1.6 with commit 7f47508 Aug 31, 2026
9 checks passed
@mastacontrola
mastacontrola deleted the fix-string-class-literals branch August 31, 2026 13:32
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