Skip to content

refactor(init): fold Platformify into the CLI - #252

Merged
pjcdawkins merged 4 commits into
mainfrom
cli-184-fold-platformify-into-upsuncli
Oct 18, 2026
Merged

pjcdawkins merged 4 commits into
mainfrom
cli-184-fold-platformify-into-upsuncli

Conversation

@pjcdawkins

@pjcdawkins pjcdawkins commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Moves the guided init wizard (Platformify) into internal/platformify and drops the github.com/platformsh/platformify dependency. The wizard stays because it supports Fixed configuration, which the AI mode doesn't (see #249).

Three commits:

  1. Import: copies the code from platformsh/platformify at dc7b173, without the standalone binaries, the validate command or the validator schemas (lint replaced those). Tests check generated config with pkg/lint, which showed the test fixtures didn't match real input, so they're corrected.

  2. Simplify: merges the packages into one, and passes the wizard's state explicitly instead of through context values.

    • Vendor assets come from the CLI config, so the root command no longer builds or passes them.
    • Files are written to the Git root that init already finds.
    • Templates render into a map of files, which removes the file system interface and the generated mocks (golang/mock).
    • Runtime and service versions come from pkg/registry, not a generated list.
    • Fixes: values read from package.json keep their case, the shopware keyword is now detected, services without known versions no longer drop the rest, the placeholder web command uses $SOCKET, and the application root is slash-separated on Windows.
  3. Review fixes (bugs inherited from Platformify): apps in a subdirectory get paths resolved from their application root, and .environment (and on Fixed, .platform.app.yaml) is written there. The overwrite prompt and final message list the files actually generated. Template fixes: REDIS_URL for Redis Persistent, DATABASE_SCHEME for Strapi on Fixed, and quoted jq paths for hyphenated relationship names on Fixed.

After this merges, platformsh/platformify can be archived.

🤖 Generated with Claude Code

pjcdawkins and others added 2 commits October 18, 2026 14:37
Copy the Platformify code that `init` uses (the guided wizard and its
templates) from github.com/platformsh/platformify at dc7b173 (main, three
commits after v0.5.0), and drop the module dependency.

Left out: the standalone binaries, the `validate` command and the
`validator` package with its schemas, which `lint` replaced.

The platformifier tests now check the generated config with pkg/lint. Its
stricter checks showed that the test fixtures were unlike real input (the
type and runtime were swapped, and names and service types were invalid),
so the fixtures are corrected.

Refs CLI-184.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merge the imported Platformify packages into internal/platformify, and
pass the wizard's state explicitly instead of through context values.

- Replace vendorization with values from the CLI config, which removes
  the vendor assets from the root command.
- Write to the Git root that init already finds, instead of asking to
  change directory there. Drop the message for projects outside Git, as
  init requires a repository.
- Render templates into a map of files and write them afterwards, which
  replaces the file system interface and the generated mocks.
- Take runtime and service versions from pkg/registry, instead of a
  generated list from the docs registry.
- Remove the no-op Next.js generator and its missing template paths,
  and the unused dependency managers in the template input.

Fixes:
- Keep the case of values read from package.json, e.g. "main".
- Detect the "shopware" composer keyword, which was never matched.
- Skip a service without known versions instead of dropping the rest.
- Use $SOCKET in the placeholder web command, not $UNIX.
- Use a slash-separated application root on Windows.

Template output is unchanged for the existing fixtures (compared before
and after). New tests cover stack detection and generated files, which
are checked with pkg/lint for Flex and Fixed configuration.

Refs CLI-184.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Changes suggested — 🟡 5 warnings · 🔵 1 minor point

🔍 Full review · 27 files reviewed

Verification
  • The flex and fixed templates are byte-identical to platformify v0.5.0's upsun and generic templates (checked with diff against the module cache).
  • The step order in Run matches the original questionnaire, minus WorkingDirectory, which is replaced by passing the Git root as Dir.
  • When a selected service has no versions in askServices, the code now skips it with continue; the original code returned early and dropped the remaining services.
  • Shopware detection in isSymfony matches psr-4 keys and keywords case-insensitively through lookupFold/EqualFold, like the original's lowercasing of the whole file.
  • No caller is left using the old newRootCommand/newInitCommand signatures or the vendorization package; go vet and go test ./internal/platformify pass.

The new internal/platformify tests check stack detection, build steps, and the generated Flex and Fixed config for each fixture, validated with pkg/lint.CheckDir. CI runs them in the make test-go job. No test exercises Run's step order or the survey prompts. That is why the subdirectory application-root problems above go unnoticed: the fixtures set ApplicationRoot directly.

Review details
  • Commit: 9a23163
  • Model: claude-opus-5-5

Review 1 of 10 for this pull request · View the full run

Comment thread internal/platformify/detect.go Outdated
Comment thread internal/platformify/templates/fixed/.environment Outdated
Comment thread internal/platformify/templates/flex/.environment Outdated
Comment thread internal/platformify/messages.go Outdated
Comment thread internal/platformify/templates/fixed/.platform.app.yaml
Comment thread internal/platformify/generate.go Outdated
Fix problems inherited from Platformify, found in review:

- Detect the application root before the steps that use it, and resolve
  the PHP web root, package.json, index.js and the Flask app from it, so
  that an app in a subdirectory gets paths that exist.
- Write .environment, and on Fixed .platform.app.yaml, in the
  application root, where they are read.
- Ask about overwriting once the application root is known, listing the
  files that would be generated, and list the written files when done.
  This drops .platform/applications.yaml, which was never written.
- Export REDIS_URL for Redis Persistent: the template compared the cache
  to "redis_persistent", which never matched.
- Set DATABASE_SCHEME for Strapi on Fixed from $DB_SCHEME: $DB_CONNECTION
  is only set for Laravel.
- Quote relationship names in jq paths on Fixed, as jq parsed names such
  as "redis-persistent" as a subtraction.
- Render relationships from the service names, and drop the unused
  endpoint mapping.

Refs CLI-184.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@upsun-dispatch

upsun-dispatch Bot commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

📋 PR Summary

This PR moves the guided init wizard (Platformify) into internal/platformify and removes the external platformsh/platformify dependency. Along the way it simplifies the code to a single package, renders templates into an in-memory map of files, and takes versions from pkg/registry. It also fixes several bugs inherited from Platformify. The latest change updates the overwrite prompt. It now lists two groups: generated files that will be overwritten, and other existing config files that will be kept and may conflict, such as a stale root .platform.app.yaml or extra .upsun/*.yml.

Changes
Layer / File(s) Summary
CLI wiring
commands/init.go Calls the internal platformify package and writes files to the Git root that init already finds.
commands/root.go No longer builds or passes vendor assets to the wizard.
commands/auth_test.go Test adjustments after the dependency change.
commands/completion_test.go Test adjustments after the dependency change.
commands/lint_test.go Test adjustments after the dependency change.
commands/list_models_test.go Test adjustments after the dependency change.
Dependencies & docs
go.mod Drops platformify and golang/mock.
go.sum Removes checksums for the dropped modules.
CLAUDE.md Updates the docs to describe the new package layout.
Wizard
internal/platformify/platformify.go The wizard's main flow. Adds existingConfig, so the confirmation prompt can separate generated files that will be overwritten from other config files that will be kept.
internal/platformify/detect.go Detects the stack, dependencies and application root.
internal/platformify/generate.go Renders templates into a map of files.
internal/platformify/models.go Defines the wizard state and template input models.
internal/platformify/survey.go Survey prompt helpers.
internal/platformify/files.go File lookup helpers.
internal/platformify/messages.go User-facing messages, including the final message listing the generated files.
internal/platformify/colors.go Terminal colour helpers.
Tests
internal/platformify/generate_test.go Tests generation, plus a new TestExistingConfig covering both the overwrite and kept-file lists.
internal/platformify/detect_test.go Detection tests.
internal/platformify/fixtures_test.go Corrected test input fixtures.
Templates
internal/platformify/templates/fixed/.platform.app.yaml Fixed app config template.
internal/platformify/templates/fixed/.environment Fixed environment template, with the DATABASE_SCHEME, REDIS_URL and jq quoting fixes.
internal/platformify/templates/fixed/.platform/routes.yaml Fixed routes template.
internal/platformify/templates/fixed/.platform/services.yaml Fixed services template.
internal/platformify/templates/flex/.environment Flex environment template.
internal/platformify/templates/flex/.upsun/config.yaml Flex config template.
internal/platformify/templates/django/settings_psh.py Django settings template.

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Changes suggested — 🟡 1 warning

🔁 Incremental · 11 files reviewed

Verification
  • detectApplicationRoot now runs before setLocations/setBuildSteps/setWebCommand. Those steps read files relative to appDir(), so the PHP location root, scripts.build check, index.js fallback and Flask entry point are all resolved inside the app's own directory.
  • outputPath puts .environment and .platform.app.yaml in the app root. For a root app it gives .environment, since path.Join("/", ".environment") with the leading slash trimmed is .environment. Shared .platform/* and .upsun/config.yaml files stay at the project root.
  • Fixed jq paths now use .["name"], so redis-persistent resolves, and both templates match redis-persistent with a hyphen, which is the service name askServices produces.
  • confirmOverwrite keeps Django's appended settings.py out of the overwrite list because the generated content starts with the current file contents (bytes.HasPrefix).
  • done lists the keys of the rendered file map, so it no longer names .platform/applications.yaml, which no template generates.

New tests cover this: TestSubdirectoryApp (detection for Laravel, Express and Flask apps in a subdirectory), TestGenerateSubdirectoryApp (output paths for Flex and Fixed), TestGenerateRedisPersistent and TestGenerateStrapiDatabaseScheme. No test covers confirmOverwrite when config files already exist at the root.

Review details

Review 2 of 10 for this pull request · View the full run

Comment thread internal/platformify/platformify.go Outdated
The overwrite check only looked at the files the wizard generates, so
on Fixed an app config at another path (e.g. a root .platform.app.yaml
when the app is now in a subdirectory, or .platform/applications.yaml)
was kept without a warning, and could define a conflicting app.

List those files, and other .upsun/*.yaml files on Flex, as kept, and
ask whether to continue.

Refs CLI-184.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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