Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions packages/deploy/src/cloud-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,32 @@ test('canonicalizeCloudUrl: origin.agentrelay.cloud/cloud → public canonical',
);
});

test('canonicalizeCloudUrl: staging.agentrelay.cloud → public canonical', () => {
test('canonicalizeCloudUrl: staging.agentrelay.cloud is preserved for staging deploys', () => {
assert.equal(
canonicalizeCloudUrl('https://staging.agentrelay.cloud'),
'https://agentrelay.com/cloud'
'https://staging.agentrelay.cloud/cloud'
);
assert.equal(
canonicalizeCloudUrl('https://staging.agentrelay.cloud/cloud'),
'https://staging.agentrelay.cloud/cloud'
);
assert.equal(
canonicalizeCloudUrl('https://staging.agentrelay.cloud/cloud/'),
'https://staging.agentrelay.cloud/cloud'
);
});

test('canonicalizeCloudUrl: origin preview host → public canonical', () => {
assert.equal(
canonicalizeCloudUrl('https://origin-preview-pr-113.agentrelay.cloud/cloud'),
'https://preview-pr-113.agentrelay.cloud/cloud'
);
});

test('canonicalizeCloudUrl: preview public host gets cloud base path', () => {
assert.equal(
canonicalizeCloudUrl('https://preview-pr-113.agentrelay.cloud'),
'https://preview-pr-113.agentrelay.cloud/cloud'
);
});

Expand Down
19 changes: 16 additions & 3 deletions packages/deploy/src/cloud-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ import type { ActiveWorkspacePointer } from './login.js';
* (the handler should emit a configured public URL, never `request.url`).
*
* Rules:
* - Map known-bypass hostnames (`origin.agentrelay.cloud`,
* `*.agentrelay.cloud`) → canonical `https://agentrelay.com/cloud`.
* - Map known-bypass hostnames back to their public cloud host:
* `origin.agentrelay.cloud` → `https://agentrelay.com/cloud` and
* `origin-<stage>.agentrelay.cloud` → `https://<stage>.agentrelay.cloud/cloud`.
* - Preserve stage-labeled public hosts such as `staging.agentrelay.cloud`
* so explicit staging deploys do not silently talk to production.
* - Add the `/cloud` base path for bare stage-labeled public hosts.
* - Map the apex `agentrelay.com` (no `/cloud` basePath) → canonical
* `https://agentrelay.com/cloud` so callers that hardcoded the apex
* don't land on the Next.js marketing 404 page.
Expand All @@ -40,9 +44,18 @@ export function canonicalizeCloudUrl(input: string): string {
return trimmed;
}
const host = url.hostname.toLowerCase();
if (host === 'agentrelay.cloud' || host.endsWith('.agentrelay.cloud')) {
if (host === 'agentrelay.cloud' || host === 'origin.agentrelay.cloud') {
return 'https://agentrelay.com/cloud';
}
if (host.startsWith('origin-') && host.endsWith('.agentrelay.cloud')) {
return `https://${host.slice('origin-'.length)}/cloud`;
}
if (
host.endsWith('.agentrelay.cloud') &&
(url.pathname === '' || url.pathname === '/')
) {
return `https://${host}/cloud`;
}
Comment on lines +47 to +58

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Instead of returning hardcoded string literals and discarding other parts of the URL (such as ports, query parameters, hashes, or non-root subpaths), we can mutate the URL object directly. This is much more robust, preserves any additional URL metadata, and avoids manual string concatenation.

For example, if a URL like https://origin-preview-pr-113.agentrelay.cloud/cloud/some-path?debug=true is passed, mutating the URL object will correctly preserve the subpath and query parameters, whereas the current implementation would completely discard them.

  if (host === 'agentrelay.cloud' || host === 'origin.agentrelay.cloud') {
    url.hostname = 'agentrelay.com';
    url.protocol = 'https:';
    if (url.pathname === '' || url.pathname === '/') {
      url.pathname = '/cloud';
    }
  } else if (host.startsWith('origin-') && host.endsWith('.agentrelay.cloud')) {
    url.hostname = host.slice('origin-'.length);
    url.protocol = 'https:';
    if (url.pathname === '' || url.pathname === '/') {
      url.pathname = '/cloud';
    }
  } else if (
    host.endsWith('.agentrelay.cloud') &&
    (url.pathname === '' || url.pathname === '/')
  ) {
    url.pathname = '/cloud';
    url.protocol = 'https:';
  }

if (
host === 'agentrelay.com'
&& (url.pathname === '' || url.pathname === '/')
Expand Down
2 changes: 1 addition & 1 deletion packages/deploy/test/e2e/weekly-digest.smoke.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'node:path';
import test from 'node:test';
import { pathToFileURL } from 'node:url';

const DEFAULT_STAGING_URL = 'https://staging.agentrelay.com';
const DEFAULT_STAGING_URL = 'https://staging.agentrelay.cloud/cloud';
const FIXTURE_REPO = envValue('WORKFORCE_E2E_FIXTURE_REPO') ?? 'AgentWorkforce/deploy-e2e-fixtures';
const ISSUE_TITLE_RE = /^Weekly digest\s+—\s+/u;
const POLL_TIMEOUT_MS = 90_000;
Expand Down
Loading