Skip to content

refactor: run shell commands through Utopia\Command - #13616

Merged
loks0n merged 1 commit into
mainfrom
feat/utopia-command
Sep 14, 2026
Merged

loks0n merged 1 commit into
mainfrom
feat/utopia-command

Conversation

@loks0n

@loks0n loks0n commented Sep 10, 2026

Copy link
Copy Markdown
Member

Summary

Supersedes #11937 by @TorstenDittmann, re-applied on current main against the released utopia-php/console 0.2.9.

  • Bump utopia-php/console to ^0.2 and utopia-php/database to ^7.3.8 (the first database release that accepts console 0.2, chore: allow utopia-php/console 0.2 utopia-php/database#965).
  • Build every locally composed shell command with Utopia\Command instead of concatenating escaped strings. Plain commands reach proc_open as an argument array with no shell; the one composite chain (the template commit-and-push in the builds worker) is rendered by the library with every argument escaped.

Migrated call sites:

  • src/Appwrite/Certificates/LetsEncrypt.php: certbot issuance
  • src/Appwrite/Platform/Modules/Functions/Workers/Builds.php: mkdir, mv, rsync, the git config/checkout/add/commit/push chain, git rev-parse, rm
  • src/Appwrite/Migration/Infrastructure/Version/V1.php: docker volume ls and the two docker run invocations that count and copy build artifacts
  • tests/e2e: every tar packaging helper, docker exec/inspect/logs, and the mkdir in the empty-site test

The two git clone commands in the builds worker stay as strings because utopia-php/vcs still returns them that way.

Testing

  • Pint on all changed files: passed
  • PHPStan on the changed source files: no errors
  • Unit suite: passes apart from host-environment failures (maxminddb extension, avatar font rendering, missing signing-key env), none related
  • E2E not yet run locally; CI covers the suites the original PR listed:
    • Functions/FunctionsConsoleClientTest --filter=testFunctionDeploymentRetentionWithMaintenance
    • Sites/SitesConsoleClientTest --filter=testSiteDeploymentRetentionWithMaintenance
    • Functions/FunctionsCustomServerTest --filter=testCreateFunctionAndDeploymentFromTemplate (+ Branch, Commit)
    • Functions/FunctionsCustomServerTest --filter=testCreateDeploymentLarge
    • Sites/SitesCustomServerTest --filter=testEmptySiteSource
    • ProjectWebhooks/WebhooksCustomServerTest --filter=testCreateDeployment

🤖 Generated with Claude Code

@greptile-apps

greptile-apps Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The changes since the previous review introduce no new actionable defects, so the PR appears safe to merge despite the remaining non-blocking coverage gap.

Fix All in Claude CodeFindings

  1. P2 Artifact migration lacks coverage ▶
Fix with agent prompt
### Issue 1
src/Appwrite/Migration/Infrastructure/Version/V1.php:118-133
This refactors the critical build-volume copy path, including two volume mounts and an embedded `sh -c` program, without an observable regression test. Add a behavioral test that populates a legacy volume, runs the migration, and verifies the target files and retry behavior. An assertion against the rendered command would be implementation-coupled and would not protect artifact recovery.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

  • Converts certificate issuance, build preparation, artifact migration, and E2E helper commands to structured arguments.
  • Uses argument-array execution for individual commands and an escaped composite command for the template commit-and-push workflow.
  • Preserves the existing observable behavior of deployment packaging and maintenance helpers.

Reviews (5) · Last reviewed commit: "refactor: run shell commands through Uto..."

Comment on lines +118 to +133
$copy = (new Command('docker'))
->argument('run')
->flag('--rm')
->option('-v', $source . ':/from:ro')
->option('-v', $target . ':/to')
->argument($image)
->argument('sh')
->option(
'-c',
'cd /from && find . -type f | while read -r file; do'
. ' size=$(stat -c %s "$file");'
. ' [ "$(stat -c %s "/to/$file" 2>/dev/null)" = "$size" ] ||'
. ' { mkdir -p "/to/$(dirname "$file")" && cp -a "$file" "/to/$file"; };'
. ' [ "$(stat -c %s "/to/$file" 2>/dev/null)" = "$size" ] || echo "$file"; done'
),
'',
$stdout,
$stderr
);
);
$exit = Console::execute($copy, '', $stdout, $stderr);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Artifact migration lacks coverage

This refactors the critical build-volume copy path, including two volume mounts and an embedded sh -c program, without an observable regression test. Add a behavioral test that populates a legacy volume, runs the migration, and verifies the target files and retry behavior. An assertion against the rendered command would be implementation-coupled and would not protect artifact recovery.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Migration/Infrastructure/Version/V1.php
Line: 118-133

Comment:
**Artifact migration lacks coverage**

This refactors the critical build-volume copy path, including two volume mounts and an embedded `sh -c` program, without an observable regression test. Add a behavioral test that populates a legacy volume, runs the migration, and verifies the target files and retry behavior. An assertion against the rendered command would be implementation-coupled and would not protect artifact recovery.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

@loks0n
loks0n force-pushed the feat/utopia-command branch from 6d56740 to c9aeb06 Compare September 10, 2026 17:47
@github-actions

github-actions Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat/utopia-command (after).

Metric Before After Change
🚀 Requests/sec 186.89 189.01 ⚪ +1.1%
⏱️ Latency P50 91.91 ms 91.36 ms ⚪ -0.6%
⏱️ Latency P95 223.05 ms 214.69 ms ⚪ -3.7%
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 91.36 214.69 11,799 189.01 -8.36
Account 181.76 328.53 621 10.3 -30.76
TablesDB 88.75 162.18 6,417 105.21 -9.81
Storage 84.11 182.35 3,105 52.85 -5.87
Functions 136.99 263.53 1,656 28.92 -3.56

Top API waits (after)

API request Max wait (ms)
functions.create 504.41
account.name.update 478.94
functions.variables.create 434.03
tablesdb.rows.create 428.25
functions.variables.update 423.53

@loks0n
loks0n force-pushed the feat/utopia-command branch 2 times, most recently from 4f40828 to 0a2e591 Compare September 12, 2026 13:15
Bump utopia-php/console to ^0.2 and build every locally composed shell
command with Utopia\Command instead of concatenating escaped strings.
Plain commands now reach proc_open as an argument array (no shell), and
the one composite chain (the template commit-and-push in the builds
worker) is rendered by the library with every argument escaped.

Migrated call sites:

- src/Appwrite/Certificates/LetsEncrypt.php: certbot issuance
- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php: mkdir, mv,
  rsync, git config/checkout/add/commit/push chain, git rev-parse, rm
- src/Appwrite/Migration/Infrastructure/Version/V1.php: docker volume ls
  and the two docker run invocations that count and copy build artifacts
- tests/e2e: every tar packaging helper, docker exec/inspect/logs and the
  mkdir in the empty-site test

The two git clone commands in the builds worker are left as strings
because utopia-php/vcs still returns them as such.

utopia-php/database is bumped to 7.3.8, the first release that accepts
console 0.2.

Supersedes #11937 by @TorstenDittmann.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@loks0n
loks0n force-pushed the feat/utopia-command branch from 0a2e591 to d7ecbaf Compare September 14, 2026 10:47
@loks0n
loks0n merged commit e4f5341 into main Sep 14, 2026
198 of 200 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Sep 15, 2026
1 of 2 tasks
@TorstenDittmann
TorstenDittmann deleted the feat/utopia-command branch September 30, 2026 13:14
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