Skip to content

CLI site creation fails when generating default admin password #3417

@chubes4

Description

@chubes4

Summary

studio site create --no-start can fail in the Node-based CLI when Studio generates the default WordPress admin password.

The shared password helper currently imports generatePassword from @automattic/generate-password. That package calls window.crypto.getRandomValues(...), which is valid in browser-like runtimes but not in the Node CLI, where window is undefined.

Impact

A new site can reach the port-assignment step and then fail before saving the site:

✔ Port assigned: 9457
✖ Failed to create site: window is not defined

This also blocks reliable local Homeboy evidence runs for other Studio CLI/site-startup investigations because fresh site creation fails before the benchmark can proceed.

Root cause

Current trunk code path:

studio site create
→ apps/cli/commands/site/create.ts
→ createPassword()
→ tools/common/lib/passwords.ts
→ @automattic/generate-password
→ window.crypto.getRandomValues(...)
→ ReferenceError: window is not defined

The password is the default WordPress admin password generated when the caller does not provide one.

Homeboy evidence

Trunk failure

  • Studio SHA: ad48e06bc8cdbf3a35e9cbf9486d0dcde27c23d2
  • Homeboy run: dc2858ae-b983-4cfe-8a7c-ad4d88dbfd34
  • Artifact: /Users/chubes/.local/share/homeboy/artifacts/dc2858ae-b983-4cfe-8a7c-ad4d88dbfd34/cc43b89c-e68d-438e-b850-d69cb14a8b1f-trace.json
  • Reproduction command captured by Homeboy:
homeboy observe \
  --path /var/folders/lr/c_cmmt7s0592m4njz99v5yb40000gn/T/opencode/studio-trunk-password-evidence \
  --duration 1s \
  --probe '{"type":"cmd.run","command":"node","args":["apps/cli/dist/cli/main.mjs","site","create","--name","Homeboy Password Evidence Trunk","--path","/var/folders/lr/c_cmmt7s0592m4njz99v5yb40000gn/T/opencode/studio-password-evidence-trunk-site","--no-start","--skip-browser","--skip-log-details"]}'

Observed trace excerpt:

✔ Port assigned: 9457
✖ Failed to create site: window is not defined
exit_code: 1
success: false

Candidate success

  • Candidate PR: Generate CLI passwords without window #3416
  • Candidate SHA: 7290bb06ccd8a8325bb89c21854bd3b58a0786a0
  • Homeboy run: b398ab5b-0749-483b-a4e2-659b5c60a239
  • Artifact: /Users/chubes/.local/share/homeboy/artifacts/b398ab5b-0749-483b-a4e2-659b5c60a239/4fecf13b-3fed-4e23-b430-68a821bef220-trace.json

Observed trace excerpt:

✔ Port assigned: 9457
✔ Site created successfully
exit_code: 0
success: true

Expected behavior

The CLI should be able to generate a default WordPress admin password without requiring a browser window global.

Notes

A runtime-neutral implementation can use globalThis.crypto.getRandomValues(...), which is available in the Node CLI runtime and browser-like runtimes.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions