Keep verified Gateway active through transient discovery failures
All checks were successful
Build and Deploy Gateway / build-and-push (push) Successful in 16s
Build and Deploy Gateway / deploy (push) Successful in 7s

This commit is contained in:
2026-07-31 10:57:00 +03:00
parent c6d3fd39fb
commit fdc6f687f3
5 changed files with 39 additions and 18 deletions

View File

@@ -78,7 +78,7 @@ test('Gateway presence is authenticated by the shared subscription secret', asyn
}), false);
});
test('host route freshness and Gateway failures drive a safe automatic fallback', () => {
test('verified Gateway stays active through transient discovery failures', () => {
const now = Date.now();
const statePath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'harbor-route-')), 'network.json');
fs.writeFileSync(statePath, JSON.stringify({
@@ -106,14 +106,23 @@ test('host route freshness and Gateway failures drive a safe automatic fallback'
state = nextGatewayAutoState(state, { network });
assert.equal(state.mode, 'gateway-direct');
state = nextGatewayAutoState(state, { network });
assert.equal(state.mode, 'local-vpn');
assert.equal(state.mode, 'gateway-direct');
assert.equal(state.gatewayId, 'gateway-1');
assert.equal(state.failures, 3);
state = nextGatewayAutoState(state, {
network: null,
error: 'host snapshot stale',
});
assert.equal(state.mode, 'gateway-direct');
assert.equal(state.gatewayId, 'gateway-1');
assert.equal(state.lastError, 'host snapshot stale');
assert.equal(applyGatewayPreference(state, false).mode, 'local-vpn');
const newNetwork = { ...network, mac: '11:22:33:44:55:66' };
state = nextGatewayAutoState(nextGatewayAutoState(createGatewayAutoState(), {
network,
verifiedGateway: { gatewayId: 'gateway-1' },
}), { network: newNetwork });
state = nextGatewayAutoState(state, { network: newNetwork });
assert.equal(state.mode, 'local-vpn');
assert.equal(state.gatewayId, '');
assert.equal(readHostNetworkState(statePath, { now: now + 16_000 }), null);