Skip to content

test: lock scopes so a shipped scope cannot be removed - #14206

Merged
ChiragAgg5k merged 3 commits into
mainfrom
chore/scope-lock
Oct 7, 2026
Merged

ChiragAgg5k merged 3 commits into
mainfrom
chore/scope-lock

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Removing the Assistant in #14167 also removed the assistant.read scope. MCP hosts such as ChatGPT keep requesting the scope list they registered with, so connecting the Appwrite app failed with invalid_scope - Scope 'project:assistant.read' is not supported. until #14200 restored it as deprecated. Keys, functions and sites store scopes too. Scopes are a public contract and should only ever be deprecated.

This adds app/config/scopes/lock.json, the list of every shipped project, organization and account scope, and tests/unit/General/ScopesTest.php, which runs in the unit suite and fails when:

  • a locked scope is missing from its catalog: Scope 'assistant.read' was removed from the project scopes. Clients that stored it would be rejected; keep it and mark it 'deprecated' => true instead.
  • a catalog has a scope the lock doesn't list: Scope 'widgets.read' is not in app/config/scopes/lock.json. Add it under 'project'; once shipped it cannot be removed.

So adding a scope costs one line in the lock, which makes the contract change visible in review, and removing one fails CI. compute.php is left out because it lists the scopes granted to ephemeral keys, not a catalog clients pick from. AGENTS.md now says scopes are never removed and points to the test.

The lock mirrors config on purpose: it is the reviewed snapshot of a published contract, like composer.lock or the committed specs, not an implementation detail.

Seen red: removing assistant.read from project.php and adding an unlocked widgets.read fails both tests with the messages above; restoring the file passes (6 tests). Pint and PHPStan pass on the test.

Closes #14207

Keys, functions, sites and OAuth2 clients store scopes, and MCP hosts such as ChatGPT keep requesting the list they registered with. Removing assistant.read (#14167) broke those clients with invalid_scope until #14200 restored it. Record every shipped scope in app/config/scopes/lock.json and fail the unit suite when one disappears from the catalogs or a new one is not locked, so retiring a scope means deprecating it.
@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No blocking issues — 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Missing lock file fails as JsonException (ScopesTest.php:66) — The locked() helper casts a possibly-false file_get_contents result to string before json_decode (tests/unit/General/ScopesTest.php:66), so a missing or unreadable lock.json surfaces as a bare JsonException "Syntax error".

This PR introduces an immutability contract for Appwrite's scope catalogs: a new app/config/scopes/lock.json records every shipped scope per catalog, and a new tests/unit/General/ScopesTest.php fails CI if a scope is dropped from the configs or a new scope bypasses the lock file. AGENTS.md documents the retirement policy (deprecated scopes stay registered, lock entries are never removed). It is a small, test-and-config-only change with no runtime behavior impact.

Files Change
app/config/scopes/lock.json New lock file snapshotting all shipped scopes per catalog (projectScopes, organizationScopes, accountScopes).
tests/unit/General/ScopesTest.php New unit test asserting the lock file matches the registered scope configs bidirectionally.
AGENTS.md Documents the scopes-never-removed policy and the lock-file mechanism.

Reviewed commit: 9e7020e

@ghost

ghost commented Oct 7, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The previously reported conflict with the base rule restricting the unit tier to local src libraries remains unresolved; the latest change introduces no new findings.

Adds a committed lock of project, organization, and account scopes, plus six data-driven checks rejecting removed scopes and unlocked additions. Updates AGENTS.md to document scope deprecation and configuration contract checks. The latest change converts the catalog data provider to a generator without changing its datasets.

Latest changes: Converts ScopesTest::catalogs() from an array-returning provider to an Iterator using three named yields.

Verdict New comments Fixed Still open
✅ Approved 0 0 1
Fix with agent prompt
### Issue 1
tests/unit/General/ScopesTest.php:33-36
**Keep config-contract checks outside the restricted unit tier**

The base `AGENTS.md` Tests rule limits `tests/unit/` to local `src` libraries; this test checks static configuration rather than a library. Please run these snapshot checks through a dedicated config-validation/CI check outside the unit tier and update the documented path accordingly.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 3
File Change
AGENTS.md Documents scope permanence, the lock checks, and configuration contract tests.
app/config/scopes/lock.json Records project, organization, and account scope names.
tests/unit/General/ScopesTest.php Checks removals and unlocked additions across three catalogs, now using a generator data provider.
⏳ Still open from earlier reviews · 1

Reviewed the commits since d6ed431 · 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 tests/unit/General/ScopesTest.php Resolved
@ChiragAgg5k ChiragAgg5k self-assigned this Oct 7, 2026
@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.

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → chore/scope-lock (after).

Metric Before After Change
🚀 Requests/sec 198.39 207.6 ⚪ +4.6%
⏱️ Latency P50 86.1 ms 83.8 ms ⚪ -2.7%
⏱️ Latency P95 212.33 ms 195.38 ms 🟢 -8%
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 83.8 195.38 12,882 207.6 -16.96
Account 158.89 297.78 678 11.31 -22.55
TablesDB 81.05 150.84 7,006 114.66 -16.69
Storage 77.46 175.1 3,390 57.56 -4.08
Functions 117.13 238.93 1,808 31.38 -8.43

Top API waits (after)

API request Max wait (ms)
account.name.update 492.39
account.prefs.update 423.34
functions.variables.update 405.34
tablesdb.rows.update 393.71
functions.create 369.65

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.

Lock scopes so a shipped scope cannot be removed

1 participant