release: bump version to 0.84.0
ci / backend (push) Canceled after 0s
ci / frontend (push) Canceled after 0s
ci / delivery (push) Canceled after 0s

This commit is contained in:
linkong committed 2026-12-04 07:07:19 +08:00
1 parent 3b1b9ef68c
commit e1cc27f13d
241 files changed
+42779 -6027

No files matched your search

+73
View File
@@ -146,6 +146,79 @@ describe('protocol-core static and range handling', () => {
),
).rejects.toThrow()
})
test('caches boundary artifacts to disk, cleans stale versions, and serves local 206/HEAD', async () => {
const fs = require('node:fs')
const boundaryCacheDir = path.join(tempRoot, 'boundary-cache')
fs.mkdirSync(boundaryCacheDir, { recursive: true })
const staleFile = path.join(boundaryCacheDir, 'earth-boundaries.oldver.pmtiles')
writeFileSync(staleFile, 'stale-data', 'utf8')
const payload = 'PMTiles-Mock-Archive-Payload-0123456789'
const upstreamCalls: Array<{ url: string; range: string | null }> = []
const handler = createEarthProtocolHandler({
earthBundleRoot: bundleRoot,
boundaryCacheDir,
getBackendUrl: () => 'http://127.0.0.1:8000',
fetchImpl: (async (input: RequestInfo | URL, init?: RequestInit) => {
const headers = new Headers(init?.headers)
const range = headers.get('range')
upstreamCalls.push({ url: String(input), range })
if (range && /^bytes=(\d+)-(\d*)$/.test(range)) {
const match = /^bytes=(\d+)-(\d*)$/.exec(range)!
const start = Number(match[1])
const end = match[2] ? Math.min(Number(match[2]), payload.length - 1) : payload.length - 1
const slice = payload.slice(start, end + 1)
return new Response(slice, {
status: 206,
headers: {
'Content-Range': `bytes ${start}-${end}/${payload.length}`,
'Content-Length': String(slice.length),
Accept: 'bytes',
},
})
}
return new Response(payload, {
status: 200,
headers: { 'Content-Length': String(payload.length) },
})
}) as typeof fetch,
})
// First Range request misses local disk cache -> proxies upstream AND caches full file in background.
const url = 'planet://earth/api/v1/earth/boundaries/files/earth-boundaries.newver.pmtiles'
const first = await handler(new Request(url, { headers: { Range: 'bytes=0-6' } }))
expect(first.status).toBe(206)
expect(await first.text()).toBe('PMTiles')
const targetPath = path.join(boundaryCacheDir, 'earth-boundaries.newver.pmtiles')
for (let i = 0; i < 40 && !fs.existsSync(targetPath); i += 1) {
await new Promise((r) => setTimeout(r, 15))
}
expect(fs.existsSync(targetPath)).toBe(true)
expect(fs.existsSync(staleFile)).toBe(false)
// Subsequent Range and HEAD requests hit local disk cache with zero upstream calls.
const callsBeforeHit = upstreamCalls.length
const hitRange = await handler(new Request(url, { headers: { Range: 'bytes=8-11' } }))
expect(hitRange.status).toBe(206)
expect(hitRange.headers.get('Content-Range')).toBe(`bytes 8-11/${payload.length}`)
expect(hitRange.headers.get('Cache-Control')).toContain('immutable')
expect(await hitRange.text()).toBe('Mock')
const hitHead = await handler(new Request(url, { method: 'HEAD' }))
expect(hitHead.status).toBe(200)
expect(hitHead.headers.get('Content-Length')).toBe(String(payload.length))
expect(await hitHead.text()).toBe('')
expect(upstreamCalls.length).toBe(callsBeforeHit)
// Path traversal or unexpected extensions are never read/written from local boundary cache.
const traversal = await handler(
new Request('planet://earth/api/v1/earth/boundaries/files/..%2Fsecret.pmtiles'),
)
expect(traversal.status).toBe(200)
expect(upstreamCalls.length).toBe(callsBeforeHit + 1)
})
})
describe('external links and runtime config', () => {