Skip to content

The agent that grows with you

test(install-e2e): a later step's mock rebinds the port the surviving gateway froze

Tekniuma4c13ee015d5
diff --git a/tests-js/scripts/desktop-smoke.test.ts b/tests-js/scripts/desktop-smoke.test.ts
index 3d7055bb81d..9f9615881aa 100644
--- a/tests-js/scripts/desktop-smoke.test.ts
+++ b/tests-js/scripts/desktop-smoke.test.ts
@@ -15,6 +15,17 @@ import { assertBackendOrigin, localBackendProcess, readBundledBundleEnv, readIns
import { writeEnvFile, writeMockProviderConfig } from './mock-provider-config.ts'
import { MOCK_REPLY, startMockServer } from './mock-server.ts'
+test('a later CI step\'s mock rebinds the dead mock\'s port, so a gateway that outlived it still answers', async (): Promise<void> => {
+ // The detached gateway froze `http://127.0.0.1:<port>` at boot; the step that started that mock is gone.
+ const earlier = await startMockServer()
+ await earlier.close()
+ const later = await startMockServer({ port: earlier.port })
+
+ try {
+ expect(later.url).toBe(earlier.url)
+ } finally { await later.close() }
+})
+
test('one server owns inference and a fresh, per-server prompt witness', async (): Promise<void> => {
const first = await startMockServer()
const second = await startMockServer()
diff --git a/tests-js/scripts/mock-server.ts b/tests-js/scripts/mock-server.ts
index 43735b36ed3..b6b7636803d 100644
--- a/tests-js/scripts/mock-server.ts
+++ b/tests-js/scripts/mock-server.ts
@@ -55,6 +55,14 @@ verificationWritePath?: string
* handle's `path` to let the test decide when the process exits.
*/
backgroundReleasePath?: string
+
+/**
+ * Port to bind (default: any free port). An install/update journey runs its
+ * phases in separate CI steps, and each step's mock dies with that step while
+ * the detached gateway survives with the provider URL it read at boot; the
+ * next step rebinds the same port so that URL keeps answering.
+ */
+port?: number
}
export interface MockServer {
@@ -994,7 +1002,7 @@ export function startMockServer(options: MockServerOptions = {}): Promise<MockSe
server.on('error', reject)
- server.listen(0, '127.0.0.1', () => {
+ server.listen(options.port ?? 0, '127.0.0.1', () => {
const addr = server.address()
if (addr === null || typeof addr === 'string') {
diff --git a/tests/install/e2e-assets/desktop-smoke-windows.ps1 b/tests/install/e2e-assets/desktop-smoke-windows.ps1
index 2bd44aab470..ced9ec91c85 100644
--- a/tests/install/e2e-assets/desktop-smoke-windows.ps1
+++ b/tests/install/e2e-assets/desktop-smoke-windows.ps1
@@ -3,8 +3,13 @@
function Start-DesktopJourneyMock([string]$Node, [string]$Assets, [string]$Work, [string]$HermesHome, [string]$Out) {
New-Item -ItemType Directory -Path $Out -Force | Out-Null
$urlFile = Join-Path $Work 'chat-mock-url'
+ # An earlier step's mock died with that step; the detached gateway did not, and it
+ # kept the provider URL it read at boot. Rebind that URL's port (see mock-provider.mjs).
+ $priorUrl = if (Test-Path -LiteralPath $urlFile) { (Get-Content -LiteralPath $urlFile -Raw).Trim() } else { '' }
Remove-Item -LiteralPath $urlFile -Force -ErrorAction SilentlyContinue
- $mock = Start-Process -FilePath $Node -ArgumentList @(('"' + (Join-Path $Assets 'mock-provider.mjs') + '"'), ('"' + $urlFile + '"')) `
+ $mockArgs = @(('"' + (Join-Path $Assets 'mock-provider.mjs') + '"'), ('"' + $urlFile + '"'))
+ if ($priorUrl) { $mockArgs += ('"' + $priorUrl + '"') }
+ $mock = Start-Process -FilePath $Node -ArgumentList $mockArgs `
-PassThru -RedirectStandardOutput (Join-Path $Out 'chat-mock.log') -RedirectStandardError (Join-Path $Out 'chat-mock-error.log')
try {
$deadline = (Get-Date).AddSeconds(30)
diff --git a/tests/install/e2e-assets/mock-provider.mjs b/tests/install/e2e-assets/mock-provider.mjs
index c252e213802..4b2b2b72d33 100644
--- a/tests/install/e2e-assets/mock-provider.mjs
+++ b/tests/install/e2e-assets/mock-provider.mjs
@@ -3,9 +3,12 @@
// (importing, not executing, so the dev-launcher block never runs) and
// publishes its URL to a file for the shell driver to consume.
//
-// Usage: node mock-provider.mjs <url-file>
+// Usage: node mock-provider.mjs <url-file> [<prior-url>]
// Writes "<url-file>" with the base URL (http://127.0.0.1:<port>) once
// the server is listening, then stays alive until SIGINT or SIGTERM.
+// <prior-url>: the URL an earlier step's (now dead) mock published. Its port
+// is rebound when free, so a gateway that outlived that step, and froze the
+// provider URL at boot, still reaches this mock; otherwise any free port.
// @ts-check
import fs from 'node:fs';
@@ -14,10 +17,17 @@ import { startMockServer } from '../../../tests-js/scripts/mock-server.ts';
const urlFile = process.argv[2];
if (!urlFile) {
- console.error('usage: node mock-provider.mjs <url-file>');
+ console.error('usage: node mock-provider.mjs <url-file> [<prior-url>]');
process.exit(1);
}
-const mock = await startMockServer();
+const priorPort = /^http:\/\/127\.0\.0\.1:(\d+)\/?$/.exec((process.argv[3] ?? '').trim())?.[1];
+let mock;
+try {
+ mock = await startMockServer(priorPort ? { port: Number(priorPort) } : {});
+} catch (error) {
+ console.error(`[mock-provider] prior port ${priorPort} unavailable (${error}); using a free port`);
+ mock = await startMockServer();
+}
fs.writeFileSync(urlFile, mock.url);
console.log(`[mock-provider] listening at ${mock.url}`);
diff --git a/tests/install/e2e-assets/mock-provider.sh b/tests/install/e2e-assets/mock-provider.sh
index 16f85c8cad1..9285130cca8 100755
--- a/tests/install/e2e-assets/mock-provider.sh
+++ b/tests/install/e2e-assets/mock-provider.sh
@@ -41,12 +41,16 @@ mock_start() {
return 0
fi
+ # A dead mock's URL is still what a gateway that outlived its step froze at boot:
+ # the new instance rebinds that port when free (mock-provider.mjs <prior-url>).
+ local prior_url
+ prior_url="$(cat "$MOCK_URLFILE" 2>/dev/null || true)"
rm -f "$MOCK_PIDFILE" "$MOCK_URLFILE"
# Bare `node file.ts` type-stripping works on node >=22.18 (the images
# ship 22.22+; the installed managed node is >=26) - same contract as
# the repo's own `dev:mock` script.
- node "$ASSETS/mock-provider.mjs" "$MOCK_URLFILE" > "$LOG_DIR/mock.log" 2>&1 &
+ node "$ASSETS/mock-provider.mjs" "$MOCK_URLFILE" "$prior_url" > "$LOG_DIR/mock.log" 2>&1 &
echo $! > "$MOCK_PIDFILE"
local _i