forked from linkong/planet
release: bump version to 0.84.2
This commit is contained in:
1 parent
5e6352f524
commit
30b44ec00d
77 files changed
+3312
-1039
No files matched your search
@@ -0,0 +1,82 @@
|
||||
import { beforeEach, describe, expect, test } from 'bun:test'
|
||||
|
||||
import {
|
||||
fetchRuntimeVersion,
|
||||
getCachedRuntimeVersion,
|
||||
parseHealthVersion,
|
||||
resetRuntimeVersionCache,
|
||||
} from '../src/admin/components/layout/runtimeVersion'
|
||||
|
||||
describe('runtimeVersion', () => {
|
||||
beforeEach(() => {
|
||||
resetRuntimeVersionCache()
|
||||
})
|
||||
|
||||
test('parseHealthVersion validates and normalizes semver strings', () => {
|
||||
expect(parseHealthVersion({ status: 'healthy', version: '0.84.1' })).toBe('0.84.1')
|
||||
expect(parseHealthVersion({ version: ' v0.84.2-rc.1 ' })).toBe('0.84.2-rc.1')
|
||||
expect(parseHealthVersion({ version: '' })).toBeNull()
|
||||
expect(parseHealthVersion({ version: 'invalid' })).toBeNull()
|
||||
expect(parseHealthVersion(null)).toBeNull()
|
||||
})
|
||||
|
||||
test('fetchRuntimeVersion caches resolved backend version across calls', async () => {
|
||||
let calls = 0
|
||||
const fakeFetch = (async () => {
|
||||
calls += 1
|
||||
return new Response(JSON.stringify({ status: 'healthy', version: '0.84.1' }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
}) as typeof fetch
|
||||
|
||||
expect(await fetchRuntimeVersion('0.84.0', fakeFetch)).toBe('0.84.1')
|
||||
expect(getCachedRuntimeVersion()).toBe('0.84.1')
|
||||
expect(await fetchRuntimeVersion('0.84.0', fakeFetch)).toBe('0.84.1')
|
||||
expect(calls).toBe(1)
|
||||
})
|
||||
|
||||
test('fetchRuntimeVersion deduplicates concurrent default fetch requests', async () => {
|
||||
const originalFetch = globalThis.fetch
|
||||
let calls = 0
|
||||
globalThis.fetch = (async () => {
|
||||
calls += 1
|
||||
await Promise.resolve()
|
||||
return new Response(JSON.stringify({ status: 'healthy', version: '0.84.1' }), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
})
|
||||
}) as typeof fetch
|
||||
|
||||
try {
|
||||
const [first, second] = await Promise.all([
|
||||
fetchRuntimeVersion('0.84.0'),
|
||||
fetchRuntimeVersion('0.84.0'),
|
||||
])
|
||||
expect(first).toBe('0.84.1')
|
||||
expect(second).toBe('0.84.1')
|
||||
expect(calls).toBe(1)
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch
|
||||
}
|
||||
})
|
||||
|
||||
test('fetchRuntimeVersion falls back without caching errors', async () => {
|
||||
const serverErrorFetch = (async () => new Response('error', { status: 500 })) as typeof fetch
|
||||
expect(await fetchRuntimeVersion('0.84.0', serverErrorFetch)).toBe('0.84.0')
|
||||
expect(getCachedRuntimeVersion()).toBeNull()
|
||||
|
||||
const networkErrorFetch = (async () => {
|
||||
throw new Error('network down')
|
||||
}) as typeof fetch
|
||||
expect(await fetchRuntimeVersion('0.84.0', networkErrorFetch)).toBe('0.84.0')
|
||||
expect(getCachedRuntimeVersion()).toBeNull()
|
||||
|
||||
const recoveryFetch = (async () =>
|
||||
new Response(JSON.stringify({ status: 'healthy', version: '0.84.2' }), {
|
||||
status: 200,
|
||||
})) as typeof fetch
|
||||
expect(await fetchRuntimeVersion('0.84.0', recoveryFetch)).toBe('0.84.2')
|
||||
expect(getCachedRuntimeVersion()).toBe('0.84.2')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,114 @@
|
||||
import { afterEach, describe, expect, mock, test } from 'bun:test'
|
||||
import { readFileSync } from 'node:fs'
|
||||
|
||||
mock.module('satellite.js', () => ({
|
||||
twoline2satrec: () => ({ satnum: '25544' }),
|
||||
propagate: () => ({ position: { x: 6800, y: 0, z: 0 } }),
|
||||
eciToEcf: (position: { x: number; y: number; z: number }) => position,
|
||||
gstime: () => 0,
|
||||
}))
|
||||
|
||||
const COMPACT_PAYLOAD = {
|
||||
format: 'satellite_compact_v1',
|
||||
count: 2,
|
||||
fields: [
|
||||
'id',
|
||||
'norad_cat_id',
|
||||
'name',
|
||||
'constellation_group',
|
||||
'tle_line1',
|
||||
'tle_line2',
|
||||
'fallback_elements',
|
||||
],
|
||||
satellites: [
|
||||
[
|
||||
1,
|
||||
25544,
|
||||
'ISS (ZARYA)',
|
||||
'space_station',
|
||||
'1 25544U 98067A 26338.50000000 .00016717 00000-0 10270-3 0 9005',
|
||||
'2 25544 51.6400 200.0000 0005000 100.0000 260.0000 15.50000000123456',
|
||||
null,
|
||||
],
|
||||
[
|
||||
2,
|
||||
44713,
|
||||
'STARLINK-1007',
|
||||
'starlink',
|
||||
'1 44713U 19074A 26338.50000000 .00001000 00000-0 10000-3 0 9001',
|
||||
'2 44713 53.0000 120.0000 0001500 90.0000 270.0000 15.06000000123456',
|
||||
null,
|
||||
],
|
||||
],
|
||||
}
|
||||
|
||||
describe('satellite refresh preservation', () => {
|
||||
const originalWindow = globalThis.window
|
||||
const originalFetch = globalThis.fetch
|
||||
|
||||
afterEach(async () => {
|
||||
const { clearSatelliteData } = await import('../public/earth/js/satellites.js')
|
||||
clearSatelliteData()
|
||||
globalThis.window = originalWindow
|
||||
globalThis.fetch = originalFetch
|
||||
})
|
||||
|
||||
test('preserves rendered satellites when forced refresh fails and supports 304 ETag reuse', async () => {
|
||||
const { getSatelliteCount, loadSatellites } = await import(
|
||||
'../public/earth/js/satellites.js'
|
||||
)
|
||||
|
||||
globalThis.window = {
|
||||
location: { origin: 'https://earth.test' },
|
||||
dispatchEvent: () => true,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
} as unknown as Window & typeof globalThis
|
||||
|
||||
const seenHeaders: Array<Record<string, string>> = []
|
||||
let mode: 'ok' | 'fail' | '304' = 'ok'
|
||||
|
||||
globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => {
|
||||
seenHeaders.push({ ...(init?.headers as Record<string, string> | undefined) })
|
||||
if (mode === 'fail') {
|
||||
return new Response('backend unavailable', { status: 502 })
|
||||
}
|
||||
if (mode === '304') {
|
||||
return new Response(null, {
|
||||
status: 304,
|
||||
headers: { etag: '"sat-v1"' },
|
||||
})
|
||||
}
|
||||
return new Response(JSON.stringify(COMPACT_PAYLOAD), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
etag: '"sat-v1"',
|
||||
},
|
||||
})
|
||||
}) as typeof fetch
|
||||
|
||||
const initial = await loadSatellites({ skipCache: true })
|
||||
expect(initial.count).toBe(2)
|
||||
expect(getSatelliteCount()).toBe(2)
|
||||
|
||||
mode = 'fail'
|
||||
await expect(loadSatellites({ forceNetwork: true, skipCache: true })).rejects.toThrow('HTTP 502')
|
||||
expect(getSatelliteCount()).toBe(2)
|
||||
|
||||
mode = '304'
|
||||
const revalidated = await loadSatellites({ forceNetwork: true, skipCache: true })
|
||||
expect(revalidated.notModified).toBe(true)
|
||||
expect(revalidated.count).toBe(2)
|
||||
expect(getSatelliteCount()).toBe(2)
|
||||
expect(seenHeaders[2]?.['If-None-Match']).toBe('"sat-v1"')
|
||||
})
|
||||
|
||||
test('ensureSatellitesEnabled does not clear satellites before loading new data', () => {
|
||||
const mainSource = readFileSync(new URL('../public/earth/js/main.js', import.meta.url), 'utf8')
|
||||
const startIdx = mainSource.indexOf('async function ensureSatellitesEnabled(')
|
||||
expect(startIdx).toBeGreaterThan(-1)
|
||||
const snippet = mainSource.slice(startIdx, mainSource.indexOf('await loadSatellites(', startIdx))
|
||||
expect(snippet).not.toContain('clearSatelliteData()')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user