Skip to content

fix(config): close the review findings carried over from 2.0.8 - #14235

Merged
ChiragAgg5k merged 6 commits into
mainfrom
fix/config-loader-review
Oct 7, 2026
Merged

ChiragAgg5k merged 6 commits into
mainfrom
fix/config-loader-review

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

Summary

Fixes the review findings on #14227 that sat in utopia-php/config 2.0.8 as released, and were left unchanged there because absorb PRs only move code. Part of #13828.

Finding Fix Commit
Non-public properties throw a raw Error Config::load() rejects any non-public property with Load before assigning. a792823
Absent optional keys leave typed properties uninitialised An absent optional key keeps the property's default. Without a default, a nullable property becomes null; any other property raises Load instead of returning an object that fails on first read. Applies to #[Key] and #[ConfigKey]. a792823
Exception tests send KEY to a schema reading key testExceptionValidator and testExceptionWithoutType send key and pin the message of the path they cover. a792823
Parser\PHP prints tag-less config Contents must start with <?php. Anything before it (missing tag, text, a newline, a BOM) is rejected with Parse before include. 5a12875
Dotenv cuts values at any # and mis-keys export An unquoted # starts a comment only at the start of the value or after whitespace, so pa#ss and https://x.com/a#b stay whole. A leading export is dropped from the key. 711bf65
README JSON has a trailing comma and variable-source example does not run Removed the comma. The example now uses named arguments throughout and new WhiteList(['high', 'low']), and the combined example uses WhiteList too. A new "Schema rules" section states the loader and Parser\PHP contract. 9ca5f5e

The last commit (2a3da2c) keeps the fixtures in the shape under test. Rector would make the non-public fixture property readonly and give the nullable optional fixtures a null default, which removes the case the optional-key test covers. So the non-public fixture is protected, and RestoreDefaultNullToNullableTypePropertyRector is skipped for tests/ConfigTest.php only.

Three existing PHPTest fixtures used heredocs that left four spaces before <?php. include was printing those, and the new open-tag rule rejects them, so their closing markers now strip the indentation.

Effect on Appwrite

Appwrite and Cloud use only the registry (setParam/getParam) and Parser\Dotenv, the latter in repository env detection (Detections/Create, Repositories/XList). Detection now keeps SECRET=pa#ss whole and reads export EXPORTED=yes as EXPORTED. The Gitea e2e test testDetectionReadsVariablesFromDotenv covers both. Nothing in Appwrite or Cloud calls the typed loader or Parser\PHP.

Release

Not released here. If a semver-strict call is wanted, three changes alter what previously accepted input produces:

  • An optional absent key on a non-nullable property with no default used to return an object (fatal only on read). It now throws Load.
  • Contents with anything before <?php used to parse (after printing that text). They are now rejected.
  • Unquoted values with an inner #, and keys behind export, parse differently.

That argues for config/3.0.0. The non-public check and the nullable-becomes-null case only turn a fatal into Load or a usable object, so they would be fine in a minor. Since no consumer uses the typed loader or Parser\PHP (Edge and open-runtimes/executor are on the 0.2 registry), 2.2.0 with these called out in the notes is also defensible. The Dotenv change is the only one an existing consumer (Appwrite env detection) sees, and there it is a fix.

Tests

Each fix was seen red: I reverted the hunk and the new or corrected tests failed, then passed with it restored.

  • Visibility check removed: the 2 non-public tests fail.
  • leaveUnset removed: the usable-object test errors and the no-default test fails.
  • Validator or type check removed: the corrected testExceptionValidator / testExceptionWithoutType fail. Before this PR they stayed green with those checks removed.
  • Open-tag check removed: all 4 testPHPParseExceptionMissingStart cases fail.
  • Old Dotenv parser: the # and export tests fail.
  • README: the original getting-started example throws Parse, and the variable-source example is a fatal ("positional argument after named argument"). Both now run and dump the loaded object.

Results:

  • bin/monorepo check config and bin/monorepo test config: 84 tests / 282 assertions.
  • Root packages suite filtered to Utopia\Config in appwrite/base:2.1.0: 84 tests pass. Appwrite unit suite: 1397 tests pass.
  • composer lint, composer refactor:check, PHPStan (no errors, with no stale baseline entries) and bin/monorepo validate pass.
  • The extended Gitea e2e expectations match the parser's output on the same .env fixture. The test itself runs in CI's VCSGitea job.

A non-public schema property reached `$instance->$name = $value` from
Config's scope and threw a raw Error. An absent optional key left a
typed property without a default uninitialised, so the returned object
failed on first read. Both now raise Load: properties must be public,
and an absent optional key keeps the declared default, becomes null on a
nullable property, or is reported missing.

The validator and missing-type tests sent `KEY` to a schema reading
`key`, so they failed on the missing required key and stayed green with
their checks removed. They now send `key` and pin the message of the
path they cover.
Parser\PHP includes the contents, so anything before `<?php`, or a file
with no open tag at all, was printed to output and only then rejected
because include returned 1. It now refuses such contents before
including them. The test covers a missing tag, text, a newline and a
byte order mark before it, and asserts nothing is printed. Three
existing tests built their fixtures with heredocs that left four spaces
before the tag, which were being printed; their closing markers now
strip that indentation.
An unquoted value was cut at its first `#`, so `pa#ss` became `pa` and a
URL lost its fragment; `export KEY=value` was stored under `export KEY`.
A `#` now starts a comment only at the start of the value or after
whitespace, and a leading `export` is dropped from the key, matching
common dotenv implementations. Repository env detection reads `.env`
files through this parser, so the Gitea detection test covers both.
The getting-started config.json had a trailing comma that json_decode()
rejects, and the variable-source example passed a positional argument
after named ones and used `Whitelist` with string arguments instead of
`WhiteList` with a list. Both now run as written. A new section states
what Config::load() and Parser\PHP accept.
Rector would make the non-public fixture property readonly and give the
nullable optional fixtures a null default, which removes the case the
optional-key test covers. The non-public fixture is protected, and the
default-null rule is skipped for ConfigTest.
@luxor-code-review

luxor-code-review Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 PHP guard rejects valid <?PHP open tags (PHP.php:24) — The new guard requires contents to start with a lowercase <?php tag (packages/config/src/Parser/PHP.php:24), but PHP open tags are case-insensitive, so <?PHP is valid and include would parse it correctly.

This PR introduces a standalone packages/config package providing a reflection-based typed config registry (Config::load) with MISSING sentinel handling, plus dotenv and PHP config file parsers with validation guards, accompanied by unit tests, a Rector config, and a README.

Files Change
packages/config/src/Config.php, rector.php, README.md New typed config registry using reflection over public properties with nested ConfigKey support and schema rules.
packages/config/src/Parser/Dotenv.php Dotenv parser with inline-comment detection, quoting, and export-prefix handling.
packages/config/src/Parser/PHP.php PHP config parser that validates the file starts with a PHP open tag before executing it.
packages/config/tests/** Unit tests covering config loading, dotenv edge cases, and PHP parser guards.
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php Minor e2e test adjustment.

Reviewed commit: 2a3da2c

@ChiragAgg5k ChiragAgg5k self-assigned this Oct 7, 2026
@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The pull request adds schema visibility checks and defined handling for absent optional keys, rejects PHP configuration content before the opening tag, and updates dotenv parsing to preserve embedded hashes and recognize export prefixes. It also corrects README examples and adds regression coverage, including Gitea environment detection. The latest changes implement the parser checks with string operations and whitespace checks instead of regular expressions.

Latest changes: The newest commit replaces regex-based dotenv comment detection, export-prefix stripping, and PHP opening-tag validation with string operations and ctype_space checks.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 9
File Change
packages/config/README.md Corrects JSON and PHP examples and documents schema and PHP parser rules.
packages/config/rector.php Preserves nullable properties without defaults in loader test fixtures.
packages/config/src/Config.php Rejects non-public schema properties and handles absent optional values explicitly.
packages/config/src/Parser/Dotenv.php Preserves embedded hashes and strips export prefixes using string and whitespace checks.
packages/config/src/Parser/PHP.php Validates the opening PHP tag using string operations before including configuration.
packages/config/tests/ConfigTest.php Corrects exception-path inputs and covers visibility and optional-key handling.
packages/config/tests/Parser/DotenvTest.php Covers embedded hashes, comment boundaries, and export prefixes.
packages/config/tests/Parser/PHPTest.php Adjusts heredoc fixtures and checks rejection without printed output.
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php Checks detection of embedded hashes and exported dotenv variables.

Reviewed the commits since 2a3da2c · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

Comment thread packages/config/src/Parser/Dotenv.php Resolved
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/config-loader-review (after).

Metric Before After Change
🚀 Requests/sec 166.05 170.26 ⚪ +2.5%
⏱️ Latency P50 104.33 ms 100.05 ms ⚪ -4.1%
⏱️ Latency P95 248.3 ms 242.81 ms ⚪ -2.2%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 100.05 242.81 10,830 170.26 -5.5
Account 194.18 380.9 570 9.43 -9.37
TablesDB 95.35 185.85 5,890 95.12 -2.4
Storage 93.9 206.35 2,850 47.63 -8.47
Functions 144.7 291.49 1,520 26.2 -17.78

Top API waits (after)

API request Max wait (ms)
functions.create 716.74
functions.variables.update 516.66
account.prefs.update 483.1
account.name.update 469.67
tablesdb.rows.update 419.82

AGENTS.md rules out new preg_* calls. The dotenv comment cut, the export
prefix and the PHP open-tag check use string functions instead; ctype_space
matches the same characters as PCRE's \s, and the comment cut keeps the
regex's cut point (before the whitespace), so results are unchanged.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 1b690eb into main Oct 7, 2026
57 checks passed
@ChiragAgg5k
ChiragAgg5k deleted the fix/config-loader-review branch October 7, 2026 16:42
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