feat: remove agent name from app URLs (#19750)

## Summary

In this pull request we're removing `agent_name` from subdomains in APP
urls when an `app` is used in the subdomain. `agent_names` will still be
used when a `port` is used in the subdomain.

Closes: https://github.com/coder/coder/issues/18485

### Changes

- Updated regex to support an optional agent name
- Added logic to support checking the app slug for a matching port
(e.g., 8080 or 8080s)

### Testing

- Updated all tests to support an optional `agent_name`
This commit is contained in:
Rafael Rodriguez
2025-09-26 12:25:58 -05:00
committed by GitHub
parent 403a9e57c9
commit d29a52462b
6 changed files with 359 additions and 99 deletions
+8 -3
View File
@@ -159,10 +159,16 @@ func (d *Details) PathAppURL(app App) *url.URL {
// SubdomainAppURL returns the URL for the given subdomain app.
func (d *Details) SubdomainAppURL(app App) *url.URL {
// Agent name is optional when app slug is present
agentName := app.AgentName
if !appurl.PortRegex.MatchString(app.AppSlugOrPort) {
agentName = ""
}
appHost := appurl.ApplicationURL{
Prefix: app.Prefix,
AppSlugOrPort: app.AppSlugOrPort,
AgentName: app.AgentName,
AgentName: agentName,
WorkspaceName: app.WorkspaceName,
Username: app.Username,
}
@@ -234,7 +240,7 @@ func setupProxyTestWithFactory(t *testing.T, factory DeploymentFactory, opts *De
details.Apps.Owner = App{
Username: me.Username,
WorkspaceName: workspace.Name,
AgentName: agnt.Name,
AgentName: "", // Agent name is optional when app slug is present
AppSlugOrPort: proxyTestAppNameOwner,
Query: proxyTestAppQuery,
}
@@ -474,7 +480,6 @@ func createWorkspaceWithApps(t *testing.T, client *codersdk.Client, orgID uuid.U
// findProtoApp is needed as the order of apps returned from PG database
// is not guaranteed.
AppSlugOrPort: findProtoApp(t, protoApps, app.Slug).Slug,
AgentName: proxyTestAgentName,
WorkspaceName: workspace.Name,
Username: me.Username,
}