Skip to content

refactor: build VCS clone, git and build job commands with Utopia\Command - #14022

Merged
TorstenDittmann merged 7 commits into
mainfrom
claude/zealous-lovelace-p8u4qk
Sep 30, 2026
Merged

TorstenDittmann merged 7 commits into
mainfrom
claude/zealous-lovelace-p8u4qk

Conversation

@TorstenDittmann

@TorstenDittmann TorstenDittmann commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Follow-up to #13616. That PR moved the builds worker's local commands onto Utopia\Command but left the git clone commands as strings, because utopia-php/vcs returned them as strings. This PR converts those, plus the other shell strings on request and worker paths.

packages/vcs

  • generateCloneCommand() now returns a Command instead of a string. Builds.php needs no change because Console::execute() already accepts a Command.
  • The five near-identical generators (GitHub, GitLab, Gitea, Bitbucket, Origin) share Git::cloneCommand(). Each adapter keeps only its clone-URL logic.
  • Every value is passed as its own argument:
    • cd becomes git -C, through a shared Git::git($directory) that Origin and Gogs use too.
    • echo >> sparse-checkout becomes printf '%s\n'.
    • The "use the branch if it exists, otherwise create it" fallback is a constant sh -c script that reads the directory and branch from positional parameters.
  • A branch or commit value that starts with - is rejected, so it can't reach git as an option. Tags are exempt, because they travel as refs/tags/<name>.
  • Fixes an unquoted value: Gitea's tag clone put {$version} into the command without quoting.
  • Behaviour changes:
    • GitHub and Origin resolved tags with ls-remote | awk. They now fetch refs/tags/<name> directly, as Bitbucket and GitLab already did.
    • An unknown clone type now throws instead of producing a command with no checkout step.
  • Origin and Gogs git helpers (createFile, createBranch, createTag) now run through Console::execute() with Command.
  • Gogs error messages no longer include the command, which contained the clone URL and its access token.
  • Adds a utopia-php/console: ^0.2 requirement.
  • ⚠️ Changing the return type of generateCloneCommand() breaks the public API of the mirrored utopia-php/vcs package, so it needs a new version when released.

packages/agents

  • DiffCheck now builds its cp, git clone, checkout and git diff | head commands with Command, the diff through a diffCommand() method. Adds a utopia-php/console: ^0.2 requirement.

src/Appwrite/Deployment/Deployments.php

  • The build job command is built with Command and sent to the orchestrator as a string, as before.
  • The staging copy is still best effort: previously a ;, now || true, so a failed copy still lets build.sh run.
  • An empty build command is left out instead of passed as '', because Command refuses empty arguments. open-runtimes' build.sh runs bash -c "$1" without set -u, so both cases behave the same.

Not changed: the installer and the SDKs/Specs tasks. These are operator and developer tooling that don't take API input.

Test Plan

  • New CloneCommandTest runs the shared clone command against a local bare repository, through a LocalGit test adapter, and checks what lands on disk:
    • each root-directory form ('', ., ./, /, docs, ./docs/, nested, 0) checks out the right files
    • a directory named with TAB-separated tar options, ;, $(…) and backticks is checked out as a literal directory and runs nothing (the test fails if that step goes back to string interpolation)
    • a tag starting with a dash (refs/tags/-release) clones
  • vcs unit suites pass for all seven adapters (GitHub, GitLab, Gitea, Bitbucket, Origin, Forgejo, Gogs), including branch and commit values starting with a dash (rejected) and an unknown clone type (throws).
  • The vcs E2E clone tests now run the command and check the checked-out files instead of matching the command text. The tag test moves the branch past the tag and asserts the later file is absent.
  • agents DiffCheckTest passes.
  • Ran the Origin helpers against a local repository. A file named -n f is staged correctly and a multi-line commit message containing $(id) is committed as plain text.
  • Ran the Deployments job command shape under sh. A failed staging step still runs the build, and the build command reaches it as one unchanged argument.
  • Pint, Rector and PHPStan pass for the changed packages; bin/monorepo validate passes. Removed one stale phpstan-baseline.neon entry for an assertion this PR deletes.
  • CI is green on the head commit, including the VCSGitHub, VCSGitea, Functions and Sites E2E suites.

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs? (No API metadata changes.)

🤖 Generated with Claude Code

https://claude.ai/code/session_01XirP99UR2sHfDpCiioktcu

@ghost

ghost commented Sep 30, 2026 •

Copy link
Copy Markdown

🔵 Tier A · Mergeable after minor fixes

The deployment command changes need automated regression coverage alongside the existing deployment-library tests.

Moves VCS cloning and Git helpers, DiffCheck commands, and deployment build-job commands onto Utopia\Command. Consolidates clone generation across providers, adds ref validation and local clone tests, and changes tag checkout to fetch the named tag directly.

Verdict New comments Fixed Still open
✅ Approved 1 0 0
Finding Where
🟡 Cover the deployment job command changes with regression tests src/Appwrite/Deployment/Deployments.php:472
Fix with agent prompt
### Issue 1
src/Appwrite/Deployment/Deployments.php:472-477
**Cover the deployment job command changes with regression tests**

The existing `tests/unit/Deployment/DeploymentsTest.php` exercises payload generation, but no test covers the newly omitted empty build argument or the rewritten best-effort staging command. Please add shell-level regression coverage verifying that empty builds still succeed, nonempty build commands arrive unchanged as one argument, and staging failure does not prevent the build from running.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
📂 Walkthrough · 13
File Change
packages/agents/composer.json Adds the console dependency.
packages/agents/src/DiffCheck/DiffCheck.php Builds copy, clone, checkout, and diff commands with Command and executes them through Console.
packages/vcs/composer.json Adds the console dependency.
packages/vcs/phpstan-baseline.neon Removes an obsolete assertion baseline entry.
packages/vcs/src/Adapter.php Changes the clone-command return contract to Command.
packages/vcs/src/Adapter/Git.php Introduces shared sparse clone construction and leading-dash ref validation.
packages/vcs/src/Adapter/Git/Bitbucket.php, packages/vcs/src/Adapter/Git/GitHub.php, packages/vcs/src/Adapter/Git/GitLab.php, packages/vcs/src/Adapter/Git/Gitea.php Delegates clone construction to the shared Git implementation.
packages/vcs/src/Adapter/Git/Gogs.php Migrates CLI Git helpers to Command and omits command text from failures.
packages/vcs/src/Adapter/Git/Origin.php Uses shared clone generation and migrates Git mutation helpers to Command.
packages/vcs/tests/Base.php Adds invalid-ref and unknown-clone-type coverage.
packages/vcs/tests/CloneCommandTest.php, packages/vcs/tests/LocalGit.php Adds local filesystem clone tests for sparse paths and hostile values.
packages/vcs/tests/E2E/Base.php Checks cloned files rather than command strings and executes the tag clone.
src/Appwrite/Deployment/Deployments.php Composes best-effort staging and build invocation with Command.

Reviewed b15116d · 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/vcs/tests/E2E/Base.php Resolved

@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

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Refactors git and shell command building to use a command abstraction.

The PR appears safe to merge; no new actionable findings remain.

Summary

The PR replaces shell-string construction with Utopia\Command for VCS cloning, Git helpers, diff checks, and deployment build jobs. It also adds executable clone tests that check the files produced rather than the command text.

Reviews (3) · Last reviewed commit: "fix(vcs): accept tags starting with a da..."

Comment thread packages/vcs/tests/Base.php Resolved
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → claude/zealous-lovelace-p8u4qk (after).

Metric Before After Change
🚀 Requests/sec 178.99 161.62 🔴 -9.7%
⏱️ Latency P50 97.15 ms 105.07 ms 🔴 +8.1%
⏱️ Latency P95 230.37 ms 257.45 ms 🔴 +11.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 105.07 257.45 10,260 161.62 +27.08
Account 209.35 424.04 540 9.14 +83.76
TablesDB 101.61 198.81 5,580 91.43 +25.97
Storage 95.02 209.79 2,700 45.44 +5.81
Functions 153.82 325.51 1,440 24.83 +52.03

Top API waits (after)

API request Max wait (ms)
account.name.update 630.78
account.prefs.update 551.89
functions.create 496.61
tablesdb.rows.delete 487.28
functions.delete 475.6

Comment thread packages/vcs/src/Adapter/Git.php Resolved
Comment thread packages/vcs/tests/CloneCommandTest.php Resolved
claude and others added 7 commits September 30, 2026 13:53
generateCloneCommand() now returns a Command instead of a string. The five
near-identical generators share Git::cloneCommand(), which passes every
value as its own argument: cd becomes git -C, echo becomes printf, and the
branch fallback is a constant sh -c script that reads its values from
positional parameters. Refs starting with a dash are rejected so they
cannot reach git as options.

This also fixes the Gitea tag clone, which interpolated the tag name
unquoted, and replaces GitHub's and Origin's ls-remote | awk tag lookup
with a direct refs/tags fetch. Origin's and Gogs' git helpers run through
Console::execute with Command, and Gogs no longer echoes the
token-carrying clone URL in its error message.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XirP99UR2sHfDpCiioktcu
Co-Authored-By: Torsten Dittmann <[email protected]>
The staging step stays best effort: a failed copy still lets build.sh run,
as the previous ';' did. An empty build command is left out, which build.sh
treats the same as an empty argument.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XirP99UR2sHfDpCiioktcu
Co-Authored-By: Torsten Dittmann <[email protected]>
…haviour

Review follow-up. DiffCheck gets diffCommand() and the Git adapter a shared
git() in place of closures, and Gogs and Origin use git() too. The clone
tests now run the shared clone command against a local repository through
a LocalGit test adapter, asserting which files are checked out and that a
root directory full of tar options and shell syntax is checked out as a
literal directory without running anything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XirP99UR2sHfDpCiioktcu
Co-Authored-By: Torsten Dittmann <[email protected]>
Applies Rector's NewMethodCallWithoutParenthesesRector, which the vcs
package's PHP set enforces and CI checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XirP99UR2sHfDpCiioktcu
Co-Authored-By: Torsten Dittmann <[email protected]>
A tag reaches git as refs/tags/<name>, so a leading dash cannot turn it
into an option; only branch and commit values are rejected now, as tag
clones accepted such names before. CloneCommandTest restores whatever
GIT_CONFIG_GLOBAL held before it ran instead of unsetting it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01XirP99UR2sHfDpCiioktcu
Co-Authored-By: Torsten Dittmann <[email protected]>
@TorstenDittmann
TorstenDittmann force-pushed the claude/zealous-lovelace-p8u4qk branch from 3bdcfdf to b15116d Compare September 30, 2026 13:53

@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 src/Appwrite/Deployment/Deployments.php Resolved
@TorstenDittmann
TorstenDittmann merged commit dcb7137 into main Sep 30, 2026
55 checks passed
@TorstenDittmann
TorstenDittmann deleted the claude/zealous-lovelace-p8u4qk branch September 30, 2026 14:40
abnegate added a commit that referenced this pull request Oct 1, 2026
Main moved by 20 commits, which left the PR conflicting, so GitHub ran
no CI on f4351e9. The commits bring:
- the email-password session duration parameter (#14004);
- resolved-address reuse for outbound requests (#14028);
- VCS and build commands through Utopia\Command (#14022);
- the full first chunk in the resume ownership test (#14026). That is
  the same change as the branch's e24bef4, so it merged cleanly.

The one conflict was the import block of
src/Appwrite/Deployment/Deployments.php. The branch had added
ClientExceptionInterface and main had added Utopia\Command, so both
stay, in alphabetical order. Main changed neither the root
composer.json nor composer.lock, and none of its changes touch the
database 8 API.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
sub4biz pushed a commit to sub4biz/appwrite that referenced this pull request Oct 5, 2026
Template versions such as 0.1.* are not refspecs. PR appwrite#14022 fetches
refs/tags/<version> directly, so those clones fail. Resolve a glob to the
last tag git ls-remote lists for it, the same tag the old GitHub and Origin
lookup selected, and keep exact tag names on the direct fetch.

Co-authored-by: Chirag Aggarwal <[email protected]>
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.

2 participants