Skip to content

The environments declaration in the root marker: the question, its validation and the checks of plx doctor - #120

Merged
davidjalbers merged 17 commits into
stacks-3from
davidjalbers/plx-302-the-environments-declaration-in-the
Dec 6, 2026
Merged

davidjalbers merged 17 commits into
stacks-3from
davidjalbers/plx-302-the-environments-declaration-in-the

Conversation

@davidjalbers

@davidjalbers davidjalbers commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

What it does

  • The root marker may carry environments: a map of name to promotes_from and optional auto_promote (§ 3.6, § 3.7).
    One function of lib reads and validates it: packages/lib/src/declaredEnvironments.ts.
    The name rule is the one environment files use, imported from environments.ts.
  • repo-turbo and repo-operations ask environments as a yaml question (default {}; repo-turbo skips it for a package repo).
    plx new, plx apply and plx update carry the nested value as written.
  • plx doctor: PLX-Stack/FileNamesDeclared and PLX-Stack/DeclaredHasFile (repo checks, silenced by a deviation), and an invalid declaration as a finding of no requirement with its reason.
  • ENVIRONMENT_BRANCHES is gone; environmentOf takes the declaration. An invalid declaration deploys from no branch.
  • An environment file may list no name under PLEXUS_ (own test and code commits).
  • PLX-276: both repo templates run git init --initial-branch=main. A test with no git configuration holds it. No env/ branch is created at birth.

Interface for PLX-303 and PLX-305 (@plexus-ms/lib)

  • readDeclaredEnvironments(ctx, dir): Promise<DeclaredEnvironments> reads the root marker of dir; declareEnvironments(value) is the pure form.
  • DeclaredEnvironments = { environments: DeclaredEnvironment[]; problems: string[] }; never throws; order as written; problems empty means valid, and a caller that acts refuses otherwise.
  • DeclaredEnvironment = { name, promotesFrom, autoPromote, branch: 'env/<name>', source: 'main' | 'env/<promotesFrom>' }.
  • environmentBranch(name), environmentOfBranch(environments, ref), describeBranches(declared, 'and' | 'or') (the branches of a valid declaration only), declarationRefusal(declared) (the problems, or where to declare one, or undefined where branches deploy), DEFAULT_BRANCH, ENVIRONMENTS_KEY.
  • environmentOf(declared, event, ref, given) keeps its rule, with the declaration first.
  • Templates see the raw answer: auto_promote is absent when not written, so a template must use is defined (the default is applied by the loader only).

Readings (not decided by the issue or the decisions)

  1. An operations repo follows the same branch model as an app repo (main, env/<name>) (the maintainer's opening reading).
  2. A repo with stacks and no environments deploys nothing and passes plx doctor, unless a stack has an environment file, which is then an undeclared environment (the maintainer's opening reading).
  3. environments null, {} or absent declares nothing; a declared name whose entry is null or {} has no promotes_from and is refused.
  4. A name that fails the name rule is not also reported as undeclared (its finding is in PLX-Stack/EnvironmentFile).
  5. A declaration with problems is still returned with what could be read, but environmentOf returns no environment for any branch.
  6. plx deploy reads the declaration only to find the environment of a branch; --environment stands in without reading it, as before.
  7. plx-ci setup reads the declaration from the working directory (.) of the step.
  8. The two doctor checks bind the repo, and a repo with no stack that declares an environment fails DeclaredHasFile.
  9. PLX-Stack/EnvironmentFile refuses any PLEXUS_ name; the page's doctor paragraph still says "not every name under PLEXUS_" (compendium sentence to correct).
  10. The index standard-index.json got the two names appended by hand (ship regenerates); the lint against the new pages reports only older NoCommittedValues and PathPrefix citations that were there before.
  11. The update test ship.integration.test.ts now expects environments: {} among the defaults spliced into a repo-operations marker; its commit comes after the template commit because the expectation only changed with it.

PLX-276

Resolved by git init --initial-branch=main in both repo templates and environmentsQuestion.test.ts ("born on main", with GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM at /dev/null).
No env/ branch and no develop is created at birth (§ 6.2).

The search of the done-when

$ git grep -n ENVIRONMENT_BRANCHES
$
$ git grep -nE "\b(production|staging|develop)\b" -- templates packages/lib/src/deployTargets.ts ':!*.test.ts' ':!templates/e2e-playwright' ':!templates/*/template.yml'
packages/lib/src/deployTargets.ts:7: ... `production` when absent ...
packages/lib/src/deployTargets.ts:31:export const DEFAULT_ENVIRONMENT = 'production';
templates/app-nextjs/files/Dockerfile:9:ENV NODE_ENV=production
templates/repo-operations/files/.github/workflows/deploy.yml.jinja:4:# ... deploys every stack of the repo ... into production.
templates/repo-operations/files/.github/workflows/deploy.yml.jinja:23:    # One deploy of production at a time ...
templates/repo-operations/files/.github/workflows/deploy.yml.jinja:25:      group: deploy-production
templates/repo-operations/files/.github/workflows/deploy.yml.jinja:65:        run: plx deploy --environment production --inventory inventory
templates/repo-operations/files/PLEXUS.md.jinja:5:- `plx deploy --environment <name> ...` ...; the workflow `deploy` does it into production.
templates/repo-turbo/files/.github/workflows/on_push.yml.jinja:68:# On a push to main or develop: ...
templates/repo-turbo/files/.github/workflows/on_push.yml.jinja:73:    branches: [main, develop]
templates/repo-turbo/files/.github/workflows/{% if not publishes_packages %}on_commit.yml{% endif %}.jinja:4:# On a push to any branch but main and develop: ...
templates/repo-turbo/files/.github/workflows/{% if not publishes_packages %}on_commit.yml{% endif %}.jinja:8:    branches-ignore: [main, develop]
templates/repo-turbo/files/mise.toml.jinja:72:description = "Promote staging to prod: fast-forward main to what is on develop ..."
templates/repo-turbo/files/mise.toml.jinja:73:run = 'git fetch -q origin && git push origin origin/develop:refs/heads/main'
templates/repo-turbo/files/mise.toml.jinja:96:description = "Build the production artifacts ..."
templates/stack/files/compose.yaml.jinja:12:      NODE_ENV: production
templates/stack/files/compose.yaml.jinja:46:      NODE_ENV: production

NODE_ENV and "production artifacts" are no environment name.
Each other hit stays, and the issue that removes it:

  • deployTargets.ts:7,31 (DEFAULT_ENVIRONMENT): the deploy verb's issue, PLX-299, which deletes the inventory records.
  • repo-operations/.../deploy.yml.jinja:4,23,25,65 and repo-operations/files/PLEXUS.md.jinja:5: the workflows issue, PLX-303.
  • repo-turbo/.../on_push.yml.jinja:68,73 and on_commit.yml...jinja:4,8: the workflows issue, PLX-303.
  • repo-turbo/files/mise.toml.jinja:72,73 (the promote task): the promote and release issue, PLX-305.

None of these files is changed here.

What no test covers

  • A real run of plx deploy or plx-ci setup from a GitHub run on an env/<name> branch.
  • The workflow templates rendered from the declaration (PLX-303) and plx promote (PLX-305).
  • plx new with the declaration given as a -a environments=... string on the command line (the engine's YAML cast is tested, the flag through the proof only: --answers file).
  • Real mise install birth beyond the proof run.
  • An answer given as -a environments=... is read by the engine as YAML 1.1, so the names on, y, no and n become booleans; the marker is read as YAML 1.2, where they stay names.
  • git init --initial-branch needs git 2.28 or newer; both repo templates say so beside the birth command, and an older git fails at that command, which the failure lists by hand.

Release-notes material

  • repo-turbo and repo-operations have a new question environments; plx update adds environments: {} to a marker without it.
  • A repo with stacks must declare its environments, and each environment file must be declared, or plx doctor fails.
  • A repo born by plx new is on main; birth needs git 2.28 or newer.
  • plx deploy and plx-ci setup deploy only from env/<name> branches the repo declares; main and develop no longer deploy.
  • A repo that takes this version and declares nothing no longer deploys from main or develop: plx deploy and plx-ci setup refuse loudly, saying the repo declares no environment and where to declare one.
    This and the workflows rendered from the declaration ship in one version.
  • An environment file may list no name under PLEXUS_.

Verification

  • TURBO_FORCE=true mise run test: exit 0.
  • Newborn files run (node newborns/scratch.ts node --test): repo-turbo, repo-operations, update-released (including two new tests for a declaration kept by plx update), pipeline, deploy-job, package-pipeline: all pass.
  • A proof with the packed plx (plx new on a machine with init.defaultBranch=trunk, doctor pass and five failures, plx apply after a hand edit) is kept by the author.

Lines

+997 −72 over 25 files; 664 added and 36 removed lines are in tests, fixtures and the index (66% of the additions).

🤖 Generated with Claude Code

davidjalbers and others added 15 commits December 6, 2026 04:08
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ion and its branches

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… that declares none deploys from no branch

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e declaration

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…NCHES is gone

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…n main

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…file and a declared environment without a file

The index of requirement names gets the two names of the new pages by hand, as the last change did; ship regenerates the file.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ironment files

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…environments as it was written

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ks of the declaration

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ration of environments with its other defaults

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@davidjalbers davidjalbers self-assigned this Dec 6, 2026
davidjalbers and others added 2 commits December 6, 2026 05:07
… deploying branch, and one with none says where to declare

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…vironment, instead of a branch that does not deploy; the repo templates say birth needs git 2.28

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@davidjalbers
davidjalbers merged commit f9c0166 into stacks-3 Dec 6, 2026
2 checks passed
@davidjalbers
davidjalbers deleted the davidjalbers/plx-302-the-environments-declaration-in-the branch December 6, 2026 04:48
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