Skip to content

[#2849] Anchored environment name matching in provision scripts. - #2854

Merged
AlexSkrypnyk merged 7 commits into
mainfrom
feature/2849-anchor-env-match
Jul 29, 2026
Merged

[#2849] Anchored environment name matching in provision scripts.#2854
AlexSkrypnyk merged 7 commits into
mainfrom
feature/2849-anchor-env-match

Conversation

@AlexSkrypnyk

@AlexSkrypnyk AlexSkrypnyk commented Jul 29, 2026

Copy link
Copy Markdown
Member

Closes #2849

Summary

The provision scripts decided whether they were running in a non-production environment by piping the environment name into grep -q -e dev -e stage -e ci -e local, an unanchored substring match rather than an equality check, so any environment name that merely contained one of those words took the development branch. An environment named devops, dev2, stage-uat, or local-testing was silently treated as non-production, running example operations, installing development modules, and rebuilding the search index where none of that should happen. The blast radius is zero for the five environment names Vortex ships, but these scripts exist to be copied and edited by consumer projects, and $settings['environment'] is freely overridable via ENVIRONMENT_TYPE.

The fix adds -x (match the whole line rather than a substring) and -F (fixed strings rather than regular expressions) to the existing grep, so an environment name that is not one of the four listed now falls through to the production branch. The failure mode flips from fail-open to fail-closed. Both flags are POSIX-mandated rather than GNU extensions, and the behaviour was verified against BSD grep and busybox grep, the latter being what runs inside the Alpine-based cli container.

Anchoring the existing condition in place, rather than restructuring it into a case block, keeps the guarded body untouched - so the change is one line per script and the regenerated fixtures move by one line each instead of being rewritten wholesale.

Changes

  • scripts/provision-10-example.sh - example operations guard anchored with grep -qxF
  • scripts/provision-30-search-index.sh - search index rebuild guard anchored the same way
  • .vortex/docs/content/drupal/provision-example.sh - the documented example that consumer projects copy from, anchored to match
  • .vortex/docs/content/drupal/provision.mdx - the inline "Conditional execution" snippet anchored, and its echo message updated to list the environments in the same order
  • .vortex/tooling/tests/unit/provision-example.bats - new regression test asserting an environment named devops takes the skip branch, covering provision-10-example.sh directly for the first time
  • .vortex/tooling/tests/unit/provision-search-index.bats - the same regression test added for the search index guard
  • .vortex/installer/tests/Fixtures/handler_process/_baseline/scripts/provision-*.sh - regenerated via ahoy update-snapshots

The environment list is also normalised to local, ci, dev, stage in all four places, matching the order the docs prose and the ENVIRONMENT_* constants in settings.php already use.

The regression tests assert behaviour rather than the shape of the conditional, so they fail if a later edit drops the -x and reintroduces substring matching.

Screenshots

N/A - the change is confined to shell scripts, documentation and test fixtures.

Before / After

Matching behaviour for representative environment names:

                     before               after
                     grep -q              grep -qxF
                     (substring)          (whole line)
                     ───────────          ────────────
  dev            ──► non-production   ──► non-production   unaffected
  devops         ──► non-production   ──► production       now fixed
  dev2           ──► non-production   ──► production       now fixed
  stage-uat      ──► non-production   ──► production       now fixed
  local-testing  ──► non-production   ──► production       now fixed
  prod           ──► production       ──► production       unaffected
  ┌────────────────────────────────────────────────────────┐
  │ before: any name CONTAINING a listed word opened the   │
  │         development branch         → fail-open         │
  ├────────────────────────────────────────────────────────┤
  │ after:  only the four listed names open it; anything   │
  │         unrecognised is production → fail-closed       │
  └────────────────────────────────────────────────────────┘

Summary by CodeRabbit

  • Bug Fixes

    • Improved environment detection by requiring exact matches for supported development environments.
    • Prevented similarly named environments from incorrectly triggering example operations or search indexing.
    • Preserved production safeguards by skipping development-only operations when appropriate.
  • Tests

    • Added coverage for environment names containing development-related substrings.
    • Added provisioning validation for successful execution and correctly skipped operations.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Provisioning environment checks now require exact matches for local, ci, dev, or stage. Documentation examples were updated, and Bats tests cover devops boundary behavior for example operations and search indexing.

Changes

Environment matching

Layer / File(s) Summary
Exact environment guards
scripts/provision-10-example.sh, scripts/provision-30-search-index.sh, .vortex/docs/content/drupal/provision-example.sh, .vortex/docs/content/drupal/provision.mdx
Provisioning guards and documentation examples now use grep -qxF with the supported environment names; the documentation message was updated.
Boundary-case provisioning tests
.vortex/tooling/tests/unit/provision-example.bats, .vortex/tooling/tests/unit/provision-search-index.bats
Bats coverage verifies that devops follows the production-like example-operations path and the indexing flow remains enabled.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • drevops/vortex#2815: Modifies the related search-index provisioning environment guard and its supporting tests/docs.

Suggested labels: A1

Poem

A bunny checks each name in line,
“dev” must match, not merely shine.
No hidden hops through “devops” land,
Indexing follows the planned command.
Docs and tests now share the trail—
Exact little matches prevail!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The three required environment checks were updated to exact matching, with docs and tests aligned to the issue.
Out of Scope Changes check ✅ Passed The added tests and docs are directly related to the anchored environment-matching fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: anchoring environment name matching in provision scripts.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/2849-anchor-env-match

Comment @coderabbitai help to get the list of available commands.

@AlexSkrypnyk AlexSkrypnyk added this to the 1.41.0 milestone Jul 29, 2026
@AlexSkrypnyk AlexSkrypnyk added the A2 Working clone index A2 label Jul 29, 2026
@github-actions

This comment has been minimized.

@AlexSkrypnyk

This comment has been minimized.

2 similar comments
@AlexSkrypnyk

This comment has been minimized.

@AlexSkrypnyk

This comment has been minimized.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

📖 Documentation preview for this pull request has been deployed to Netlify:

https://6a695911422562f0d270ed04--vortex-docs.netlify.app

This preview is rebuilt on every commit and is not the production documentation site.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.42%. Comparing base (3ca7c57) to head (eb5b610).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2854      +/-   ##
==========================================
- Coverage   86.80%   86.42%   -0.39%     
==========================================
  Files          98       91       -7     
  Lines        4789     4647     -142     
  Branches       47        3      -44     
==========================================
- Hits         4157     4016     -141     
+ Misses        632      631       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

This comment has been minimized.

@AlexSkrypnyk

This comment has been minimized.

2 similar comments
@AlexSkrypnyk

This comment has been minimized.

@AlexSkrypnyk

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown

Code coverage (threshold: 90%)

  Classes: 100.00% (1/1)
  Methods: 100.00% (2/2)
  Lines:   98.55% (204/207)
Per-class coverage
Drupal\ys_demo\Plugin\Block\CounterBlock
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 10/ 10)

@AlexSkrypnyk

This comment has been minimized.

2 similar comments
@AlexSkrypnyk

This comment has been minimized.

@AlexSkrypnyk

Copy link
Copy Markdown
Member Author

Code coverage (threshold: 90%)

  Classes: 100.00% (1/1)
  Methods: 100.00% (2/2)
  Lines:   98.55% (204/207)
Per-class coverage
Drupal\ys_demo\Plugin\Block\CounterBlock
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 10/ 10)

@AlexSkrypnyk
AlexSkrypnyk merged commit 10b840e into main Jul 29, 2026
34 checks passed
@AlexSkrypnyk
AlexSkrypnyk deleted the feature/2849-anchor-env-match branch July 29, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A2 Working clone index A2

Projects

Status: Release queue

Development

Successfully merging this pull request may close these issues.

Anchor environment name matching in provision scripts

1 participant