fix(api): editable-spec detail + PATCH-merge saves + shared gateway parser

Deployment/program edits could silently drop spec fields:

- GET /deployments/{name} served the runtime view (no reach/program/root/expose)
  for deployed deployments, so the dashboard round-tripped a lossy manifest and
  stripped fields on save (broke astro). Now serves the editable castle.yaml spec
  when the deployment is in config.
- _save_deployment and save_program replaced the whole object with client input.
  Now shallow-merge over the existing spec (omit = preserve, null = clear), so a
  partial/lossy save can't drop untouched fields.
- save_yaml rebuilt GatewayConfig from `port` only, wiping tls/domain/tunnel/
  cert_hook on a whole-file save. Now uses a shared parse_gateway() (also used by
  load_config) so gateway fields can't drift between the two.

Dashboard forms (ServiceFields/StaticFields) send explicit null to clear, per the
merge contract; adds exposure host-label helpers. Coverage: detail-serves-spec,
save round-trip, partial-patch-preserves, null-clears, program partial-patch,
parse_gateway, and config save/load round-trip.
This commit is contained in:
2026-07-05 23:23:59 -07:00
parent eeaa65f7ce
commit 07c02aa151
10 changed files with 309 additions and 72 deletions

View File

@@ -60,3 +60,18 @@ export function subdomainUrl(subdomain: string): string | null {
if (labels.length <= 2) return null
return `${protocol}//${subdomain}.${labels.slice(1).join(".")}`
}
/**
* The concrete host a subdomain is exposed at — `<subdomain>.<domain>` — using
* this node's configured gateway domain. Falls back to the literal
* `<subdomain>.<gateway.domain>` placeholder only when no domain is configured
* (off mode), so hints and previews show real values wherever one exists.
*/
export function gatewayHost(subdomain: string, domain?: string | null): string {
return domain ? `${subdomain}.${domain}` : `${subdomain}.<gateway.domain>`
}
/** Same as {@link gatewayHost}, for the public (Cloudflare tunnel) zone. */
export function publicGatewayHost(subdomain: string, publicDomain?: string | null): string {
return publicDomain ? `${subdomain}.${publicDomain}` : `${subdomain}.<gateway.public_domain>`
}