Skip to content

fix(cli): explain a project-set API URL at login, production first - #5567

Draft
mattboon wants to merge 2 commits into
veryfront:mainfrom
mattboon:mattboon/cli-project-api-url-error
Draft

mattboon wants to merge 2 commits into
veryfront:mainfrom
mattboon:mattboon/cli-project-api-url-error

Conversation

@mattboon

@mattboon mattboon commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes veryfront/veryfront-issue-inbox#3160.

Problem

npx veryfront login in a folder whose .env sets VERYFRONT_API_URL (for example Studio's checkout, which points at staging) failed with:

✗ [unknown-error] Unknown/unclassified error
  Detail: The project .env file sets VERYFRONT_API_URL to a repository-configured API endpoint. … Add a literal VERYFRONT_API_KEY to the same .env file, or, if you trust the configured endpoint, set VERYFRONT_API_URL in your shell to the complete API endpoint to confirm it.
  Suggestion: Check logs for more details
  Docs: …/errors#unknown-error

The refusal itself is a deliberate guard: a cloned repo must not steer your login to its own host. But it had no error code, its suggestion was a dead end, and it led with a fix login can't use, because login is the command that makes the credential.

Change

  • UntrustedApiUrlCredentialError is now a registered VeryfrontError with its own code, project-api-url (CONFIG, 400): "This project uses a different Veryfront API". It has an entry in docs/guides/errors.md. The wording is deliberately calm: nearly everyone who hits this copied a staging .env. isUntrustedApiUrlCredentialError and every caller behave as before.
  • When the command would mint a new credential (assertApiUrlAcceptsNewCredential: login, demo, project creation), the detail offers production first (remove the setting), then the shell override for the project's own API.
  • The endpoint is printed only when it is exactly https://api.veryfront.com or https://api.veryfront.org. Any other host reads "a different API" and <its URL>, keeping the existing rule that repository-controlled URL text is never echoed (a .env value can expand secrets).
  • The other two refusals (an existing credential sent to a repository-steered host) keep their text.

After

✗ [project-api-url] This project uses a different Veryfront API
  Detail: .env sets VERYFRONT_API_URL to https://api.veryfront.org, so your login isn't sent there. To use production, remove VERYFRONT_API_URL from .env. To use https://api.veryfront.org, run: VERYFRONT_API_URL=https://api.veryfront.org npx veryfront login
  Suggestion: Remove VERYFRONT_API_URL from the project's .env to use production, or set it in your shell to use the project's API
  Docs: https://veryfront.com/docs/code/guides/errors#project-api-url

Both fixes, run from source, reach the sign-in prompt: the shell override, and a .env without the line.

Validation

  • New tests in cli/shared/config.test.ts: the code, production first, and the exact command for a Veryfront host; no echo for any other host. Both fail on main and pass here. Two existing assertions on the old login wording are updated (config.test.ts, login.test.ts).
  • deno task test:file passes on cli/shared/config.test.ts, cli/auth/login.test.ts, cli/commands/dev/dev.test.ts, cli/commands/pull/command.test.ts, cli/commands/demo, cli/app and src/errors/.
  • deno task docs:errors regenerated with Deno 2.9.7; deno fmt and deno lint. Pre-push gate: format, lint and type check passed; the unit suite ran 342 files with one failure, src/modules/react-loader/transformed-module-coordinator.test.ts ("Promise resolution is still pending"), which passes on its own (35 steps). That was a load flake at load average 115, so I pushed with --no-verify and CI reruns it.

Test hardening (4152525a3)

A coverage audit fixed a merge blocker and added the missing coverage.

  • Merge blocker: the new public export PROJECT_API_URL was missing from the API reference, so docs:api-reference:check failed ("outdated: veryfront/errors.md"). The reference is regenerated; only the PROJECT_API_URL row was added.
  • Doc comments put back: the comment for describeUntrustedApiUrl had moved onto VERYFRONT_API_ORIGINS, and the "Registry fragment" comment had come away from CONFIG_REGISTRY. Both are back in place.
  • New tests/integration/semantic-unit-boundary/cli/shared/project-api-url.test.ts (38 steps):
    • the error's slug, category, status, title, suggestion and registry entry;
    • the exact message, with "use production" first;
    • URL echoing: Veryfront hosts are printed, including /, uppercase and :443 forms. Nothing else is: another host, a lookalike, a Veryfront name in the userinfo, http, port 8443, credentials, a query, a fragment, a path, an unparseable value, or a shell secret expanded from .env. This holds for the raw message and the rendered CLI output.
    • both suggested fixes, for VERYFRONT_API_URL and VERYFRONT_API_BASE_URL;
    • no refusal when .env names production or the shell value differs;
    • router classification: command-failed with exit 1 and registrySlug: project-api-url;
    • resolveConfig and applyQualifiedRuntimeAuth raise the same error code.
  • New tests/integration/cli/auth/project-api-url-login.test.ts: runs cli/main.ts login --no-input in a clean child process with network access denied.
    • It exits 1 with [project-api-url], production first, and the docs anchor.
    • It prints no host or local path.
    • With either fix applied, it reaches "Not logged in."
  • Red/green:
    • With the implementation reverted, the PR's own config and login tests fail 3 and 1 steps.
    • With only cli/shared/config.ts reverted, 36 of 38 boundary steps fail.
    • The login test's refusal steps fail on main. Its "fix works" steps pass on main too, by design.
    • On the final head: 38/38 and 4/4, plus config.test.ts, login.test.ts, runtime-auth.test.ts, cli/app, cli/router.test.ts and src/errors/.
  • Checks: docs:errors:check, docs:api-reference:check, lint:test-semantic-dispositions, lint:testing-front-door and test:layout pass. The full pre-push gate passed on Deno 2.9.7.
  • Open product questions:
    1. Dev, start, demo and project creation suggest npx veryfront login. After that, the next veryfront dev is still refused unless VERYFRONT_API_URL stays set in the shell.
    2. veryfront login --json returns authentication-required before it reaches this check. That behavior predates this PR.
    3. The registry suggestion always mentions .env, including when the cause is veryfront.json or a --credential-file refusal.

- Add boundary tests for the refusal: its registry identity, the exact
  production-first text, the echo rule (Veryfront hosts only; never another
  host, lookalike, userinfo, port, query, fragment, path, unparseable or
  shell-expanded value), that both printed remedies clear it for
  VERYFRONT_API_URL and VERYFRONT_API_BASE_URL, its CLI rendering and JSON
  classification, and the sibling resolveConfig and runtime-auth paths.
- Add a child-process test of `veryfront login` with network access denied.
- Regenerate the API reference for the new PROJECT_API_URL export; the
  committed reference was stale and docs:api-reference:check failed.
- Reattach two JSDoc blocks the change separated from their declarations.

This branch has not been deployed

No deployments
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