import test from 'node:test' import assert from 'node:assert/strict' import { readSource } from './helpers.ts' import { displayDownloadUrl, isPublicDownloadUrl } from '../src/pages/records/version-display.ts' test('test_task_130_version_download_normal_primary_path', () => { // 正常主路径:长 URL 显示为省略中段的可读文本。 const long = 'https://oss.aishufu.top/nanri-image/versions/package-1.0.46-20260101.zip' const shown = displayDownloadUrl(long, 24) assert.ok(shown.length < long.length) assert.ok(shown.includes('…')) }) test('test_task_130_version_download_normal_variant_input', () => { // 正常变体:短 URL 原样显示。 const url = 'https://oss/a.zip' assert.equal(displayDownloadUrl(url, 64), url) }) test('test_task_130_version_download_repeated_is_idempotent', () => { // 正常重复:展示稳定。 const url = 'https://oss/a.zip' assert.equal(displayDownloadUrl(url, 64), displayDownloadUrl(url, 64)) }) test('test_task_130_version_download_boundary_empty_input', () => { // 边界空值:空/非法地址回空。 assert.equal(displayDownloadUrl('', 64), '') assert.equal(isPublicDownloadUrl(''), false) }) test('test_task_130_version_download_boundary_single_item', () => { // 边界单元素:https 可下载。 assert.equal(isPublicDownloadUrl('https://oss/a.zip'), true) }) test('test_task_130_version_download_boundary_limit_or_missing_field', () => { // 边界上限:非 http 地址不可下载。 assert.equal(isPublicDownloadUrl('ftp://x'), false) }) test('test_task_130_version_download_invalid_input_rejected', () => { // 异常输入:非字符串按空处理。 assert.equal(displayDownloadUrl(null as unknown as string, 64), '') }) test('test_task_130_version_download_dependency_failure_returns_actionable_message', () => { // 依赖失败/可操作:展示纯逻辑、无框架/http;不把完整 URL 写入日志。 const mod = readSource('src/pages/records/version-display.ts') assert.equal(/axios|http\.|vue|console\./.test(mod), false, '展示模块保持纯逻辑') assert.match(mod, /displayDownloadUrl/) })