import test from 'node:test' import assert from 'node:assert/strict' const BASE = process.env.AIIMAGE_LIVE_BASE || 'http://127.0.0.1:18080' test('test_task_180_public_version_live_reachability', async () => { // 公开版本路径可达。 const res = await fetch(`${BASE}/api/version`) assert.equal(res.status, 200) const body = (await res.json()) as Record assert.ok('version' in body) assert.ok('desc' in body) assert.ok('url' in body) }) test('test_task_180_public_version_live_latest_contract', async () => { // latest 契约含 version/file_url(允许 null)。 const res = await fetch(`${BASE}/api/version/latest`) assert.equal(res.status, 200) const body = (await res.json()) as Record assert.ok('version' in body) assert.ok('file_url' in body) }) test('test_task_180_public_version_live_no_envelope', async () => { // 公开接口无 success 包装。 const body = (await (await fetch(`${BASE}/api/version`)).json()) as Record assert.equal('success' in body, false, '公开接口不包装 ApiResponse') assert.equal('data' in body, false) }) test('test_task_180_public_version_live_values_type', async () => { const body = (await (await fetch(`${BASE}/api/version`)).json()) as Record for (const key of ['version', 'desc', 'url']) { const v = body[key] assert.ok(v === null || typeof v === 'string' || typeof v === 'number', key) } }) test('test_task_180_public_version_live_latest_keys_only', async () => { const body = (await (await fetch(`${BASE}/api/version/latest`)).json()) as Record const keys = Object.keys(body).sort() assert.deepEqual(keys, ['file_url', 'version'], 'latest 仅含两个字段') }) test('test_task_180_public_version_live_download_url_preserved', async () => { const body = (await (await fetch(`${BASE}/api/version/latest`)).json()) as Record if (body.file_url) assert.match(String(body.file_url), /^https?:\/\//) })