Skip to content

Commit 6b682ca

Browse files
clauderfay
authored andcommitted
fix(drupal-core): build issue branches against core's own lock, for #238
## The Issue After the previous commits, the "Drupal issue fork drupal-3587098 (GH)" job installs `drupal/core` from the checked-out `core/`. Drupal then serves HTTP 404 `No route found for "GET https://…/"` on `/`, and HTTP 500 on `/user/login`. The failing run is https://github.com/ddev/coder-ddev/actions/runs/43082118728/job/130737581910. The add-on's `composer.local.json` re-solves every dependency to the newest allowed version. Core's lock for branch `3587098-add-support-for` (May 2026) has Symfony 8.0.6, twig 3.22.0 and Guzzle 7.10.0. The workspace installed Symfony 8.1.11, twig 3.30.0 and Guzzle 7.16.1, which that branch never ran against. ## How This PR Solves The Issue The startup script now edits `composer.local.json` in three ways: | Change | Why | | --- | --- | | Add every `path` repository from core's `composer.json` (`core/` and the four `composer/Plugin/*`), each with the version from its own branch alias | Core's lock lists all five as path packages under the branch alias. Before, only `core/` was declared, so the four plugins came from Packagist. | | Set `extra.drupal-dev.pin-core-lock` when core has a `composer.lock` | The add-on's `CoreLockPinner` limits packages in core's lock to the locked versions. Packages that are not in the lock, such as drush and its own dependencies, still resolve freely. | | Set `config.policy.advisories.block` and `config.audit.block-insecure` to `false` | Composer refuses versions with published advisories. An older lock always has some, so with pinning on the install fails. `composer audit` still reports them. | The pinning belongs in the `amateescu/ddev-drupal-dev` add-on. The template patch is a workaround until the add-on handles it. ## Manual Testing Instructions ```bash coder create <ws> --template drupal-core --parameter drupal_version=12 \ --parameter issue_fork=3587098 --parameter issue_branch=3587098-add-support-for \ --parameter install_profile=minimal --use-parameter-defaults --yes coder logs <ws> | grep -E 'core path packages pinned|Composer install|Drupal installed' # Expect: "pin-core-lock=true", "Composer install complete", "Drupal installed" ssh <ws>.coder 'cd drupal-core && curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1/' # Expect: 200 ssh <ws>.coder 'cd drupal-core && jq -r ".packages[] | select(.name == \"symfony/routing\") | .version" composer.local.lock' # Expect: v8.0.6, the version in the branch's composer.lock ``` Repeat with `drupal_version=12` and `drupal_version=11` and no issue fork. Both must install Drupal. ## Automated Testing Overview Claude Code ran `terraform fmt -recursive`, `make validate` and `make test-templates`, which all pass. On staging-coder.ddev.com, Claude Code pushed this branch's template as an inactive version and created a workspace for issue 3587098. Without this commit, `/` returned 404 and `/user/login` returned 500. With the same `composer.local.json` edits applied by hand, `/` and `/user/login` returned 200. `composer require drush/drush` worked with pinning on. Claude Code then pushed this commit's template and built three workspaces: issue 3587098, plain `drupal_version=12`, and plain `drupal_version=11`. All three installed Drupal, served 200 on `/` and `/user/login`, and passed CI's `dist : [path] core` check. Each installed the `symfony/routing` version in its own core lock: 8.0.6, 8.1.6 and 7.4.23. `ddev drush cr` still fails on branch 3587098 because drush 14.x-dev delegates to core's `dr` binary, which core added after that branch. The template already ignores that failure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UrTUMwsuMweUxTnthbu8zQ
1 parent 047be5c commit 6b682ca

1 file changed

Lines changed: 43 additions & 15 deletions

File tree

‎drupal-core/template.tf‎

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -881,24 +881,52 @@ web_environment:
881881
TESTENV_EOF
882882
log_setup "✓ .ddev/config.zzz-coder-test-env.yaml written (SIMPLETEST_BASE_URL override)"
883883
884-
# Make Composer install drupal/core from the checked-out core/ directory.
885-
# On an issue branch, Composer gives the root package core's branch
886-
# alias (e.g. 12.x-dev), but gives the core/ path package the raw branch
887-
# name (dev-<issue>-<slug>), which doesn't match the root's
888-
# "self.version" requirement. Composer then takes drupal/core dev-main
889-
# from Packagist, so the branch is built against today's main
890-
# dependencies, and an older branch can't install at all (#238).
891-
# Declaring core/ first, with the version from its own branch alias,
892-
# makes the local copy win.
893-
_core_alias=$(jq -r '(.extra["branch-alias"] // {}) | to_entries | first | .value // empty' core/composer.json 2>/dev/null)
894-
if [ -n "$_core_alias" ] && [ -f composer.local.json ]; then
895-
if jq --arg v "$_core_alias" \
896-
'.repositories = ({"drupal-core-local": {"type": "path", "url": "core", "options": {"versions": {"drupal/core": $v}}}} + (.repositories // {}))' \
884+
# Build the checked-out branch the way core's own CI does: with its own
885+
# core/ and composer/Plugin/* code, and the dependency versions in its
886+
# composer.lock (#238).
887+
#
888+
# 1. Path packages. On an issue branch, Composer gives the root package
889+
# core's branch alias (e.g. 12.x-dev), but gives the path packages
890+
# the raw branch name (dev-<issue>-<slug>), which doesn't match the
891+
# root's "self.version" requirements. Composer then takes drupal/core
892+
# and the core-* plugins from Packagist (today's main). Declaring
893+
# every path repository from core's composer.json first, each with
894+
# the version from its own branch alias, makes the local copies win.
895+
# 2. pin-core-lock. The add-on's overlay re-solves everything to the
896+
# newest allowed versions, so an older branch runs against
897+
# dependencies it never saw (a May branch got Symfony 8.1 instead of
898+
# its locked 8.0 and served 404 on every route). The add-on's
899+
# extra.drupal-dev.pin-core-lock restricts packages core's lock has
900+
# to the locked versions; packages it doesn't have (drush and its
901+
# own dependencies) still resolve freely. It needs step 1, since
902+
# the lock records the path packages under the branch alias.
903+
# 3. Security blocking off. Composer refuses versions with published
904+
# advisories, and an older lock always has some, so with pinning on
905+
# the install has nothing to fall back to. This is a throwaway dev
906+
# environment for testing that branch; `composer audit` still
907+
# reports them. Both keys: policy.* is Composer >=2.11, audit.* older.
908+
_path_repos='{}'
909+
for _dir in $(jq -r '.repositories[]? | select(.type == "path") | .url' composer.json 2>/dev/null); do
910+
_name=$(jq -r '.name // empty' "$_dir/composer.json" 2>/dev/null)
911+
_alias=$(jq -r '(.extra["branch-alias"] // {}) | to_entries | first | .value // empty' "$_dir/composer.json" 2>/dev/null)
912+
[ -n "$_name" ] && [ -n "$_alias" ] || continue
913+
_path_repos=$(jq -c --arg n "$_name" --arg u "$_dir" --arg v "$_alias" \
914+
'. + {("local-" + $n): {"type": "path", "url": $u, "options": {"versions": {($n): $v}}}}' <<< "$_path_repos")
915+
done
916+
_pin_core_lock=false
917+
[ -f composer.lock ] && _pin_core_lock=true
918+
if [ "$_path_repos" != "{}" ] && [ -f composer.local.json ]; then
919+
if jq --argjson r "$_path_repos" --argjson pin "$_pin_core_lock" \
920+
'.repositories = ($r + (.repositories // {}))
921+
| if $pin then .extra["drupal-dev"]["pin-core-lock"] = true
922+
| .config.policy.advisories.block = false
923+
| .config.audit["block-insecure"] = false
924+
else . end' \
897925
composer.local.json > composer.local.json.tmp && mv composer.local.json.tmp composer.local.json; then
898-
log_setup "✓ composer.local.json: drupal/core pinned to local core/ ($_core_alias)"
926+
log_setup "✓ composer.local.json: core path packages pinned to the checkout ($(jq -r 'keys | map(ltrimstr("local-")) | join(", ")' <<< "$_path_repos")), pin-core-lock=$_pin_core_lock"
899927
else
900928
rm -f composer.local.json.tmp
901-
log_setup "⚠ Could not pin drupal/core to local core/ in composer.local.json"
929+
log_setup "⚠ Could not pin core path packages in composer.local.json"
902930
fi
903931
fi
904932

0 commit comments

Comments
 (0)