Merge origin/main into review/pr-1593

Conflicts: docs/CURRENT-STATE.md layer table, src/ui/layerPanel.js imports,
src/data/dataCredits.test.mjs imports; both sides kept.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Mazeyar Moeini FeizabadiandClaude Fable 5.2 committed 2026-11-10 21:20:15 +01:00
commit 3342d7a07a
194 files changed
+16487 -764

No files matched your search

+2 -2
View File
@@ -313,9 +313,9 @@ test('FIRMS retains a large successful source during partial failure and filters
const first = json(await request());
assert.equal(first.count, 130001);
assert.equal(first.sources.filter((s) => s.ok).length, 1);
assert.equal(calls, 4);
assert.equal(calls, 3);
assert.equal(json(await request()).count, 130001);
assert.equal(calls, 4);
assert.equal(calls, 3);
assert.deepEqual(json(await request('/status')).transactions, {
used: 3,
limit: 5000,
+165 -2
View File
@@ -1,6 +1,7 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { once } from 'node:events';
import { gunzipSync } from 'node:zlib';
import { WebSocketServer } from 'ws';
import { setTimeout as delay } from 'node:timers/promises';
import * as providers from '../../server/providers/live.js';
@@ -15,7 +16,7 @@ function install(plugin, preview = false) {
},
},
});
return async (route, url = '/', method = 'GET') => {
return async (route, url = '/', method = 'GET', headers = {}) => {
assert.ok(routes.has(route), `registered route: ${route}`);
const response = {
statusCode: 200,
@@ -32,7 +33,7 @@ function install(plugin, preview = false) {
this.body = body;
},
};
await routes.get(route)({ url, method }, response);
await routes.get(route)({ url, method, headers }, response);
return response;
};
}
@@ -584,6 +585,168 @@ test('track backfill proxy returns 502 on an oversized upstream body and caches
assert.equal(callCount, 1);
});
test('the aircraft snapshot routes decline a non-GET before any upstream work', async (t) => {
// A fetch that throws proves the refusal comes before any upstream call.
t.mock.method(globalThis, 'fetch', async (url) => {
throw new Error(`upstream must not be reached: ${url}`);
});
const cases = [
[install(providers.openSkyProxy()), '/api/flights'],
[install(providers.adsbLolProxy()), '/api/military'],
];
for (const [request, route] of cases) {
for (const method of ['POST', 'PUT', 'DELETE', 'PATCH']) {
const response = await request(route, '/', method);
assert.equal(response.statusCode, 405, `${method} ${route}`);
// RFC 9110 section 15.5.6: a 405 names the methods it accepts.
assert.equal(response.headers.allow, 'GET', `${method} ${route}`);
assert.deepEqual(JSON.parse(response.body), {
error: 'Method Not Allowed',
});
}
}
});
test('the snapshot method check hands each /track route on to its own handler', async () => {
// The snapshot mount also matches /track, so it must hand /track on
// before it checks the method.
for (const [plugin, route] of [
[providers.openSkyProxy(), '/api/flights'],
[providers.adsbLolProxy(), '/api/military'],
]) {
const routes = new Map();
plugin.configureServer({
middlewares: { use: (path, handler) => routes.set(path, handler) },
});
const res = {
statusCode: 200,
writeHead(s) {
this.statusCode = s;
},
end() {},
};
let handedOn = false;
await routes.get(route)(
{ url: '/track?icao24=abc123', method: 'POST' },
res,
() => {
handedOn = true;
},
);
assert.ok(handedOn, `${route}/track reaches next()`);
assert.equal(
res.statusCode,
200,
`${route}/track is not answered by the snapshot handler`,
);
}
});
test('the OpenSky snapshot is compressed for clients that ask, and an error body never inherits the cached frame', async (t) => {
environment(t, {
OPENSKY_AUTH_MODE: 'anon',
OPENSKY_CLIENT_ID: undefined,
OPENSKY_CLIENT_SECRET: undefined,
OPENSKY_USERNAME: undefined,
OPENSKY_PASSWORD: undefined,
});
let now = Date.now();
t.mock.method(Date, 'now', () => now);
t.mock.method(console, 'log', () => {});
t.mock.method(console, 'error', () => {});
let upstreamStatus = 200;
let snapshotAgeMs = 0;
t.mock.method(globalThis, 'fetch', async (url) => {
if (url.includes('/lat/'))
return Response.json({
now: now / 1000,
ac: Array.from({ length: 200 }, (_, index) => ({
hex: `abc${index}`,
lat: 30,
lon: -97,
alt_baro: 10000,
})),
});
assert.ok(url.includes('/states/'), `unexpected upstream call: ${url}`);
if (upstreamStatus !== 200)
return new Response('{"error":"upstream"}', { status: upstreamStatus });
const sourceSeconds = Math.floor((now - snapshotAgeMs) / 1000);
// Healthy credits keep the 9 s base TTL, so the clock jumps below clear it.
return Response.json(
{
time: sourceSeconds,
states: Array.from({ length: 200 }, (_, index) => [
`abc${index}`,
'CALLSIGN',
'United States',
sourceSeconds,
-97.7,
30.1,
10000,
]),
},
{ headers: { 'x-rate-limit-remaining': '4000' } },
);
});
// A fresh module: the snapshot cache, its frame and the TTL are module state.
const isolated = await import(
`../../server/providers/aircraft/opensky.js?compression=${now}`
);
const states = install(isolated.openSkyProxy());
const compressed = await states('/api/flights', '/', 'GET', {
'accept-encoding': 'gzip, deflate, br',
});
assert.equal(compressed.statusCode, 200);
assert.equal(compressed.headers['content-encoding'], 'gzip');
assert.equal(compressed.headers.vary, 'Accept-Encoding');
assert.ok(Buffer.isBuffer(compressed.body));
// Same cached snapshot, no Accept-Encoding: identity bytes, which the frame
// above must decode to.
const identity = await states('/api/flights');
assert.equal(identity.headers['x-opensky-cache'], 'HIT');
assert.equal(identity.headers['content-encoding'], undefined);
assert.equal(identity.headers.vary, 'Accept-Encoding');
assert.equal(gunzipSync(compressed.body).toString(), identity.body);
// `gzip;q=0` refuses gzip.
const refused = await states('/api/flights', '/', 'GET', {
'accept-encoding': 'gzip;q=0',
});
assert.equal(refused.headers['content-encoding'], undefined);
assert.equal(refused.body, identity.body);
// An upstream rejection is not cached, so it must not carry the previous
// snapshot's Content-Encoding.
upstreamStatus = 403;
now += 60000; // past the 9 s base TTL
const rejected = await states('/api/flights', '/', 'GET', {
'accept-encoding': 'gzip',
});
assert.equal(rejected.statusCode, 403);
assert.equal(rejected.headers['content-encoding'], undefined);
assert.ok(JSON.parse(rejected.body).error, 'a readable error body');
// A snapshot too old to serve falls back to adsb.lol, which negotiates the
// same way.
upstreamStatus = 200;
snapshotAgeMs = 3600000;
now += 60000;
const regional = await states('/api/flights', '?lat=30&lon=-97', 'GET', {
'accept-encoding': 'gzip',
});
assert.equal(regional.statusCode, 200);
assert.equal(regional.headers['x-flight-source'], 'adsb.lol');
assert.equal(regional.headers['content-encoding'], 'gzip');
assert.equal(regional.headers.vary, 'Accept-Encoding');
assert.equal(
JSON.parse(gunzipSync(regional.body).toString()).states.length,
200,
);
});
test('OpenSky Basic mode no longer sends username and password: it asks anonymously and warns once', async (t) => {
environment(t, {
OPENSKY_CLIENT_ID: undefined,
+32 -9
View File
@@ -20,12 +20,9 @@ import {
import { openAiRealtimeProxy } from 'gods-eye-view/server/providers/openai';
import { keySetupEndpoint } from 'gods-eye-view/server/standalone/key-setup';
import { realtimeInstructions } from '../../server/providers/openai/instructions.js';
import {
GEV_REALTIME_TOOLS,
offeredTools,
realtimeTools,
} from '../../server/providers/openai/tools.js';
import { GEV_REALTIME_TOOLS } from '../../server/providers/openai/tools.js';
import { createDebugLogHandler } from '../../server/providers/openai/debug-log.js';
import { realtimeSessionTools } from '../../server/providers/openai/realtime.js';
import { attachVoiceResult } from '../voice/speech.js';
import { sanitizeDebugValue } from '../voice/realtimeDiagnostics.js';
import { standaloneVoiceTools } from '../../server/standalone/voiceTools.js';
@@ -199,7 +196,10 @@ test('Realtime handler preserves tools and default instructions, isolates suppli
sent.at(-1).session.instructions,
realtimeInstructions(guidance),
);
assert.deepEqual(sent.at(-1).session.tools, realtimeTools());
assert.deepEqual(
sent.at(-1).session.tools,
realtimeSessionTools(GEV_REALTIME_TOOLS),
);
}
assert.notEqual(sent[0].session.instructions, sent[1].session.instructions);
assert.equal(sent[0].session.instructions, sent[2].session.instructions);
@@ -607,7 +607,10 @@ test('osm_query is offered only when an operator configured Overpass', async (t)
assert.doesNotMatch(plain.instructions, /osm_query/);
assert.ok(names(plain).includes('resolve_area'));
assert.ok(names(plain).includes('find_imagery'));
assert.deepEqual(configured.tools, GEV_REALTIME_TOOLS);
assert.deepEqual(
configured.tools,
realtimeSessionTools(GEV_REALTIME_TOOLS, { overpass: true }),
);
assert.match(configured.instructions, /osm_query/);
assert.equal(
configured.instructions,
@@ -656,7 +659,7 @@ test('Realtime sessions carry supplied tools, and the standalone voice adds the
);
assert.equal(response.status, 200);
// Without an operator Overpass, osm_query is left out of the session.
assert.deepEqual(sent.at(-1).session.tools, offeredTools(tools));
assert.deepEqual(sent.at(-1).session.tools, realtimeSessionTools(tools));
assert.ok(
!sent.at(-1).session.tools.some(({ name }) => name === 'osm_query'),
);
@@ -740,6 +743,26 @@ test('key setup writes only the supplied application root, retains request guard
assert.equal(existsSync(path.join(untouched, '.env')), false);
});
test('Realtime sessions leave out the Unicode property patterns OpenAI refuses (#1618)', async (t) => {
// OpenAI answers 400 invalid_function_parameters for a whole Realtime session
// whose tool schema uses `\p{…}`, as resolve_area's area ids do, so voice
// never connects. The session drops only those patterns, as typed chat does.
env(t, 'OPENAI_API_KEY', 'fixture-upstream-secret');
env(t, 'GEV_RATELIMIT_OPENAI_PER_MIN', undefined);
const sent = [];
t.mock.method(globalThis, 'fetch', async (_url, options) => {
sent.push(JSON.parse(options.body).session);
return Response.json({ value: 'fixture-ephemeral' });
});
const response = await request(
install(openAiRealtimeProxy({})).get('/api/realtime/token'),
);
assert.equal(response.status, 200);
const { tools } = sent.at(-1);
assert.ok(tools.some(({ name }) => name === 'resolve_area'));
assert.doesNotMatch(JSON.stringify(tools), /\\\\[pP]\{/);
});
test('Realtime service configuration selects compatible endpoint/model without forwarding request model IDs or keys', async () => {
const handler = install(
openAiRealtimeProxy({
@@ -757,7 +780,7 @@ test('Realtime service configuration selects compatible endpoint/model without f
assert.equal(payload.session.model, 'configured-model');
assert.deepEqual(
payload.session.tools,
realtimeTools({ overpass: false }),
realtimeSessionTools(GEV_REALTIME_TOOLS),
);
return Response.json({ value: 'short-lived-fixture' });
},
+19
View File
@@ -501,6 +501,25 @@ test('the upstream host is pinned: a redirect is refused, not followed', async (
assert.deepEqual(seen, ['error'], 'a redirect would escape the pinned host');
});
test('the routing proxy declines a non-GET before rate limiting or upstream', async (t) => {
// A fetch that throws proves the refusal comes before any upstream call.
const request = install(installRouteMiddleware);
t.mock.method(globalThis, 'fetch', async () => {
throw new Error('upstream must not be reached');
});
for (const method of ['POST', 'PUT', 'DELETE', 'PATCH']) {
const response = await request(
'/api/route',
'?profile=car&coords=-97,30;-97.01,30.01',
method,
);
assert.equal(response.statusCode, 405, method);
// RFC 9110 section 15.5.6: a 405 names the methods it accepts.
assert.equal(response.headers.allow, 'GET', method);
assert.deepEqual(response.body, { error: 'Method Not Allowed' });
}
});
test('both paid Google routes refuse cross-site requests before calling Google', async (t) => {
const plugin = googlePlacesContextProxy({ resolveApiKey: () => 'key' });
const routes = new Map();
+131
View File
@@ -0,0 +1,131 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { gunzipSync } from 'node:zlib';
import {
acceptsGzip,
encodedBody,
gzipBody,
} from '../../server/providers/common/compress.js';
/** A request shaped like the one Node hands a middleware. */
function request(acceptEncoding) {
return {
url: '/api/flights',
method: 'GET',
headers:
acceptEncoding === undefined ? {} : { 'accept-encoding': acceptEncoding },
};
}
/** Repetitive JSON shaped like a snapshot body. */
function snapshotBody(states = 200) {
return JSON.stringify({
time: 1700000000,
states: Array.from({ length: states }, (_, index) => [
`abc${index}`,
'CALLSIGN',
'United States',
1700000000,
30.1,
-97.7,
10000,
]),
});
}
/** Seeded high-entropy bytes, so the "gzip made it bigger" check is stable. */
function incompressibleBytes(length) {
const bytes = Buffer.alloc(length);
let state = 123456789;
for (let index = 0; index < length; index += 1) {
state = (state * 1103515245 + 12345) % 2147483648;
bytes[index] = (state >>> 16) & 0xff;
}
return bytes;
}
test('accept-encoding is read the way clients actually write it', () => {
assert.equal(acceptsGzip(request('gzip')), true);
assert.equal(acceptsGzip(request('gzip, deflate, br')), true);
assert.equal(acceptsGzip(request('br;q=1.0, gzip;q=0.8')), true);
assert.equal(acceptsGzip(request('GZIP')), true);
assert.equal(acceptsGzip(request(' gzip ')), true);
assert.equal(acceptsGzip(request('br, deflate')), false);
assert.equal(acceptsGzip(request('identity')), false);
assert.equal(acceptsGzip(request('')), false);
assert.equal(acceptsGzip(request(undefined)), false);
assert.equal(acceptsGzip({}), false);
assert.equal(acceptsGzip(undefined), false);
// `q=0` names gzip and refuses it (RFC 9110 section 12.4.2).
assert.equal(acceptsGzip(request('gzip;q=0')), false);
assert.equal(acceptsGzip(request('gzip;q=0.000')), false);
assert.equal(acceptsGzip(request('gzip;q=0.001')), true);
assert.equal(acceptsGzip(request('gzip;q=1')), true);
assert.equal(acceptsGzip(request('gzip;q=1.000')), true);
// A q that is not a whole `qvalue` is unreadable and must not round into
// acceptance.
assert.equal(acceptsGzip(request('gzip;q=bogus')), false);
assert.equal(acceptsGzip(request('gzip;q=1oops')), false);
assert.equal(acceptsGzip(request('gzip;q=0.5abc')), false);
assert.equal(acceptsGzip(request('gzip;q=2')), false);
assert.equal(acceptsGzip(request('gzip;q=1.5')), false);
assert.equal(acceptsGzip(request('gzip;q=0.0001')), false);
assert.equal(acceptsGzip(request('gzip;q=')), false);
// `gzip` is not matched as a substring of a neighbouring token.
assert.equal(acceptsGzip(request('x-gzip')), false);
assert.equal(acceptsGzip(request('gzipped')), false);
});
test('a body is only compressed when compression pays for itself', async () => {
assert.equal(await gzipBody(''), null);
assert.equal(
await gzipBody('{"states":[]}'),
null,
'below the frame threshold',
);
assert.equal(await gzipBody(Buffer.alloc(1023, 'a')), null, 'one byte short');
const identity = snapshotBody();
assert.ok(identity.length > 1024, 'fixture is worth compressing');
const compressed = await gzipBody(identity);
assert.ok(Buffer.isBuffer(compressed));
assert.ok(compressed.byteLength < Buffer.byteLength(identity));
assert.equal(gunzipSync(compressed).toString(), identity);
// Buffers are accepted as-is; data gzip cannot shrink stays uncompressed.
assert.ok((await gzipBody(Buffer.from(identity))) !== null);
assert.equal(await gzipBody(incompressibleBytes(4096)), null);
});
test('the encoded body and the header that names it are chosen together', async () => {
const identity = snapshotBody();
const compressed = await gzipBody(identity);
const negotiated = encodedBody(request('gzip'), identity, compressed);
assert.equal(negotiated.body, compressed);
assert.equal(negotiated.headers['Content-Encoding'], 'gzip');
assert.equal(negotiated.headers.Vary, 'Accept-Encoding');
assert.equal(gunzipSync(negotiated.body).toString(), identity);
// Offered but refused: identity bytes and no Content-Encoding.
const refused = encodedBody(request('br'), identity, compressed);
assert.equal(refused.body, identity);
assert.equal(refused.headers['Content-Encoding'], undefined);
assert.equal(refused.headers.Vary, 'Accept-Encoding');
// Wanted but not available: same answer.
const unavailable = encodedBody(request('gzip'), identity, null);
assert.equal(unavailable.body, identity);
assert.equal(unavailable.headers['Content-Encoding'], undefined);
// Vary is on both branches, so a shared cache cannot serve the wrong encoding.
assert.equal(unavailable.headers.Vary, 'Accept-Encoding');
assert.equal(
encodedBody(request(undefined), identity, compressed).headers.Vary,
'Accept-Encoding',
);
});