Repository navigation
fix(deployments): preserve VCS source roots - #13574
Conversation
… into `providerRootDirectory` reached the jobs-service through `trim($subdir, '/')`, which strips slashes but not dots. `docs`, `docs/` and `/docs` all canonicalized to `docs`, while `./docs` survived verbatim as an artifact subdir naming a path segment that does not exist in the extracted tree. `.` and `./` were worse: they collapsed to a non-empty `.`, so the repository-root case emitted a subdir instead of omitting one. Canonicalize on the consume side, in `Deployments::rootDirectory()`. Every remote-source build funnels through `submit()`, so one choke point covers new writes, rows already holding `./docs`, webhooks, duplicates and templates without a migration. Drop whole `.` segments rather than trimming the character. The builds worker's `ltrim($path, '.')` turned `.github` into `github` — a silent wrong-directory build — and left `../etc` traversal intact. Both worker call sites now share the canonicalizer, and the jobs-service hand-off passes the canonicalized value instead of re-reading the raw attribute, which also closes a mismatch where the template push committed at a space-stripped path but sent the space-bearing one. `..` segments are dropped rather than resolved, so a subdir cannot escape the tree it indexes into.
The shared deployment document carried every other `provider*` field but not `providerRootDirectory`, so a push-triggered deployment persisted an empty root directory. The build itself was correct — the root directory is passed separately — but duplicating such a deployment reads the value back off the source document, so a redeploy silently built from the repository root. The trait is shared by GitHub, GitLab, Gitea, Bitbucket and Origin.
|
Dropping `..` segments made `docs/../x` build `docs/x`, which is neither the directory the caller named nor the one POSIX would resolve — and if both exist, the wrong application deploys with no warning. Resolving the segment instead would let the subdir climb out of the tree it indexes into. Refuse the path instead. The failure is the owner's to fix, so it joins the refused-variable-key case in carrying its reason into the build log rather than a generic internal error.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Builds a function from './docs/nested/' — the form the console's directory picker writes — over the Gitea suite, the only live-VCS suite CI boots. Covers both halves observably: the push-created deployment must execute the nested entrypoint, and duplicating it must reach 'ready'. A duplicate reads the root directory back off the source deployment, so a regression that stops persisting it builds from the repository root, where the auto-init README is the only file and no entrypoint exists.
…uild The deployment response model does not expose providerRootDirectory, so reading it off the body asserted on a key that is never returned. Duplicating the push-created deployment proves the same thing through behavior: the duplicate reads the root directory back off the deployment it copies, so it only reaches 'ready' if the push persisted one. Also deploy explicitly before pushing, so the nested entrypoint is observed executing on a deployment the test activated rather than one it assumed was active.
Refusing `..` added a failure mode where there was none: `trim($subdir, '/')` has always passed a parent segment through untouched, so `docs/../x` reaches the extractor today and resolves to the directory it names. Rejecting it before job submission turns a working deployment into a 400. Canonicalize the forms that actually diverge — empty and `.` segments — and leave the rest of the path as given. Dropping `..` instead would silently build `docs/x`, which is the reason it was singled out in the first place.
Keep main's build timeout plumbing and the Utopia\Command refactor, and drop the root directory canonicalization this branch had added: the orchestrator cleans an artifact subdir on every extraction path, and the sparse-checkout pattern is the vcs adapter's to resolve.
|
|
||
| \file_put_contents($workdir . '/docs/nested/index.js', "module.exports = async (context) => context.res.send('gitea-nested-v2:' + process.env.APPWRITE_VCS_ROOT_DIRECTORY);\n"); | ||
| $this->gitHelper('git add docs && git commit -m "Update nested function"', $workdir); | ||
| $this->gitHelper('git push origin main', $workdir); | ||
|
|
||
| $webhookDeploymentId = $this->waitForNewDeploymentReadyHelper($functionId, $knownIds); | ||
| $this->assertEventually(fn () => $this->assertExecutionOutputHelper($functionId, 'gitea-nested-v2:./docs/nested/', $webhookDeploymentId), 30000, 1000); | ||
|
|
||
| // Upgrade fixture: deployments created before source roots were saved | ||
| // have NULL here. This metadata has no public update endpoint. | ||
| $seed = function (?string $root) use ($projectId, $webhookDeploymentId) { | ||
| global $register; | ||
| $pools = $register->get('pools'); | ||
| $cache = new Cache(new Sharding(\array_map( | ||
| fn (string $name) => new CachePool($pools->get($name)), | ||
| Config::getParam('pools-cache', []), | ||
| ))); | ||
| $authorization = new Authorization(); | ||
| $factory = new Factory($pools, $cache, $authorization); | ||
|
|
||
| $authorization->skip(function () use ($factory, $projectId, $webhookDeploymentId, $root) { | ||
| $project = $factory->platform()->getDocument('projects', $projectId); | ||
| $database = $factory->project($project); | ||
| $database->updateDocument('deployments', $webhookDeploymentId, new Document([ | ||
| 'providerRootDirectory' => $root, | ||
| ])); | ||
| $database->purgeCachedDocument('deployments', $webhookDeploymentId); |
There was a problem hiding this comment.
Legacy fixture mirrors internals
This legacy-deployment scenario constructs production database, cache, and authorization services, directly updates the deployment record, purges its cache, and then asserts the stored attribute. That violates the repository directive to test observable behavior rather than mirror storage or configuration details, and it makes this regression test brittle against unrelated persistence refactors. This requirement must be satisfied before merging; use a sanctioned fixture or helper to represent a legacy deployment while retaining the duplicate-and-execute assertions.
Context Used: Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. (source)
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php
Line: 185-211
Comment:
**Legacy fixture mirrors internals**
This legacy-deployment scenario constructs production database, cache, and authorization services, directly updates the deployment record, purges its cache, and then asserts the stored attribute. That violates the repository directive to test observable behavior rather than mirror storage or configuration details, and it makes this regression test brittle against unrelated persistence refactors. This requirement must be satisfied before merging; use a sanctioned fixture or helper to represent a legacy deployment while retaining the duplicate-and-execute assertions.
**Context Used:** Call out and harshly judge implementation-coupled tests. We don't mirror source code, configuration, or version pins in assertions. We test observable behavior; use linters for syntax and schema checks. ([source](https://app.greptile.com/review/custom-context?memory=instruction-0))
---
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!
There was a problem hiding this comment.
That scenario is gone. The test no longer writes to the database; it only uses the public API.
Redeploy builds from the wrong directory for functions and sites whose code lives in a subdirectory.
Duplicate/Create.phppassed the root directory stored on the source deployment, which deployments created from a git push never store, so the build ran against the repository root.Redeploy now takes the root directory from the function or site, like every other VCS build path and like the entrypoint and build commands it already reads from there. Changing the root directory marks the function as not live, so a redeploy after that change now applies it.
Deployments::createFromVcs()also records the root directory on the deployment, soAPPWRITE_VCS_ROOT_DIRECTORYis no longer empty for push and redeploy builds.The Gitea e2e test deploys a function from
functions/api, changes the root directory tofunctions/web, redeploys, and checks that the execution comes fromfunctions/webwith that root directory in its environment.Fixes #13587