diff --git a/CHANGELOG.md b/CHANGELOG.md index c44b305..3056c7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,13 @@ > `0.1.12`),由 `scripts/version.py` 从 git **算出来**;开发交付的独立说明写入本文件“开发快照”章节,并打 `snapshot/vX.Y.Z` 注释标签 ⇒ 每次开发交付均可追溯, > 但"发布版本"仍然只能由人定(CI 不会自动升版本、不会打 tag)。 +## 开发快照 snapshot/v0.1.53 - 2026-10-24 + +### Changed + +- 版本记录按参考图重排为当前构建信息卡和紧凑折叠列表,当前运行记录默认展开,其他记录收起;变更按新增、调整、修复、安全分类展示,原始说明和提交信息可展开核验。 +- 增加所有角色可用的只读刷新,保留管理员同步、真实版本身份、筛选及完整历史加载;北京时间、长提交与手机排版统一处理,不增加发布或部署权限。 + ## 开发快照 snapshot/v0.1.52 - 2026-10-24 ### Changed diff --git a/web/src/VersionHistory.test.tsx b/web/src/VersionHistory.test.tsx index 516e22d..f3e9d44 100644 --- a/web/src/VersionHistory.test.tsx +++ b/web/src/VersionHistory.test.tsx @@ -89,6 +89,7 @@ const render = (over: Partial[0]> = {}) => notice={null} expanded={null} canSync={false} + onRefresh={vi.fn()} onFilter={vi.fn()} onLoadMore={vi.fn()} onSync={vi.fn()} @@ -98,6 +99,54 @@ const render = (over: Partial[0]> = {}) => ) describe('VersionHistoryView', () => { + it('renders safe readable change rows while retaining the untouched raw notes', () => { + const html = render({ + expanded: developmentItem.commit_sha, + page: { + ...page, + items: [ + { ...developmentItem, release_notes: '### Fixed\n\n- **标题**:修复 `字段`\n- ' }, + ], + }, + }) + expect(html).toContain('class="version-history-change-row"') + expect(html).toContain('class="version-history-change-tag fixed">修复') + expect(html).toContain('标题') + expect(html).toContain('字段') + expect(html).toContain('### Fixed') + expect(html).not.toContain(' { + const html = render({ expanded: undefined }) + expect(html).toContain('data-version-commit="' + releaseItem.commit_sha + '"') + expect(html).toContain('is-current') + expect(html).toContain('aria-controls="version-detail-' + releaseItem.commit_sha + '"') + expect(html.match(/aria-expanded="true"/g)).toHaveLength(1) + expect(html).toContain('正文第一行') + expect(html).toContain('原始记录与提交信息') + expect(render({ expanded: null })).not.toContain('正文第一行') + }) + + it('separates the actual current build into a readable summary card with a read-only refresh', () => { + const html = render({ + build: { + release_version: '0.1.0', + build_kind: 'development', + commit_sha: releaseItem.commit_sha, + display_version: '0.1.0', + built_at: '2026-10-13T08:45:56Z', + identity_available: true, + }, + }) + expect(html).toContain('aria-label="当前版本"') + expect(html).toContain('运行版本') + expect(html).toContain('构建时间(北京时间)') + expect(html).toContain(releaseItem.commit_sha) + expect(html).toContain('刷新') + expect(html).toContain('每一版改了什么') + }) + it('renders the exact development changelog instead of hiding all non-release notes', () => { const html = render({ expanded: developmentItem.commit_sha, @@ -106,7 +155,7 @@ describe('VersionHistoryView', () => { expect(html).toContain('这次开发独有的变更说明') }) it('lists commits newest-first with kind badges, short sha, times and links', () => { - const html = render() + const html = render({ expanded: releaseItem.commit_sha }) expect(html).toContain('版本记录') expect(html).toContain('正式版本') expect(html).toContain('开发版本') @@ -194,10 +243,11 @@ describe('VersionHistoryView', () => { }) it('never renders a tag link without a URL (an empty href looks broken)', () => { - const withURL = render() + const withURL = render({ expanded: releaseItem.commit_sha }) expect(withURL).toContain('查看 tag v0.1.0') expect(withURL).toContain('https://gitea.example/Weknora/knowledge-governance/src/tag/v0.1.0') const withoutURL = render({ + expanded: releaseItem.commit_sha, page: { ...page, items: [{ ...releaseItem, release_tags: [{ name: 'v0.1.0', url: '' }] }], diff --git a/web/src/VersionHistory.tsx b/web/src/VersionHistory.tsx index a3d6b31..40bf86f 100644 --- a/web/src/VersionHistory.tsx +++ b/web/src/VersionHistory.tsx @@ -20,7 +20,18 @@ const FILTERS: ReadonlyArray<{ id: string; label: string }> = [ { id: 'historical', label: '历史' }, ] -const stamp = (value: string) => (value ? new Date(value).toLocaleString('zh-CN', { hour12: false }) : '—') +const stamp = (value: string) => + value && Number.isFinite(new Date(value).getTime()) + ? new Date(value).toLocaleString('zh-CN', { + timeZone: 'Asia/Shanghai', + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + hour12: false, + }) + : '—' const kindLabel: Record = { release: '正式版本', development: '开发版本', historical: '历史提交' } const runningText = (running: VersionHistoryPage['current_running']) => { @@ -53,8 +64,9 @@ interface ViewProps { loadingMore: boolean error: string | null notice: string | null - expanded: string | null + expanded: string | null | undefined canSync: boolean + onRefresh: () => void onFilter: (id: string) => void onLoadMore: () => void onSync: () => void @@ -64,87 +76,196 @@ interface ViewProps { export function VersionHistoryView(props: ViewProps) { const { page, build } = props const items = page?.items ?? [] + const expandedSHA = + props.expanded === undefined + ? (items.find( + (item) => + page?.current_running.state === 'matched' && item.commit_sha === page.current_running.matched_commit_sha + )?.commit_sha ?? + items[0]?.commit_sha ?? + null) + : props.expanded return (

版本记录

-

- {page - ? runningText(page.current_running) - : build - ? `当前运行:${build.identity_available ? build.display_version : '未知'}` - : '当前运行版本未知'} -

-

- {page ? syncText(page.sync) : '正在读取同步状态…'} - {page?.sync.status === 'running' || page?.sync.status === 'pending' ? ( - 同步中 - ) : null} - {page && page.sync.status === 'failed' ? ( - 同步失败 - ) : null} -

+

查看当前构建,以及每次更新带来的变化。

- {props.canSync ? ( - - ) : null} -
- - {props.error ? ( -
- {props.error} + {props.canSync ? ( + + ) : null}
- ) : null} - {props.notice ?
{props.notice}
: null} + +
+

当前版本

+
+
+
运行版本
+
+ {page + ? page.current_running.state === 'unknown' + ? '未知' + : page.current_running.display_version + : build?.identity_available + ? build.display_version + : '未知'} +
+
+
+
构建类型
+
+ {build?.build_kind === 'development' ? '开发构建' : build?.build_kind === 'release' ? '正式构建' : '未知'} +
+
+
+
提交
+
+ {(page ? page.current_running.commit_sha : build?.identity_available ? build.commit_sha : '') || '—'} +
+
+
+
构建时间(北京时间)
+
+ {build && (!page || build.commit_sha === page.current_running.commit_sha) ? stamp(build.built_at) : '—'} +
+
+
+

{page ? runningText(page.current_running) : '当前运行版本未知'}

+
+
+
+

每一版改了什么

+

记录来自仓库,只读展示,不执行发布或部署。

+
+

+ {page ? syncText(page.sync) : '正在读取同步状态…'} + {page?.sync.status === 'running' || page?.sync.status === 'pending' ? ( + 同步中 + ) : null} + {page?.sync.status === 'failed' ? 同步失败 : null} +

- - - {items.length === 0 && !props.loading ? ( -
- {page?.sync.available - ? '暂无记录(先同步一次,或该筛选下没有条目)' - : '版本记录未接线:等待配置只读的仓库来源'} -
- ) : null} - -
    - {items.map((item) => ( - props.onExpand(props.expanded === item.commit_sha ? null : item.commit_sha)} - /> - ))} -
- - {props.loading ?
正在读取版本记录…
: null} - {page?.has_more ? ( - - ) : null} + ) : null} +
) } +function ChangeNotes({ text }: { text: string }) { + const categories: Record = { + Added: { label: '新增', tone: 'added' }, + Changed: { label: '调整', tone: 'changed' }, + Fixed: { label: '修复', tone: 'fixed' }, + Security: { label: '安全', tone: 'security' }, + } + let category = { label: '说明', tone: 'note' } + return ( +
+ {text.split(/\r?\n/).map((line, index) => { + const trimmed = line.trim() + if (!trimmed) return null + const heading = /^#{1,6}\s+(.+)$/.exec(trimmed) + if (heading) { + if (categories[heading[1]]) { + category = categories[heading[1]] + return null + } + return

{heading[1]}

+ } + const content = trimmed.replace(/^[-*]\s+/, '') + return ( +

+ {category.label} + + {content + .split(/(\*\*[^*]+\*\*|`[^`]+`)/g) + .map((part, i) => + part.startsWith('**') && part.endsWith('**') ? ( + {part.slice(2, -2)} + ) : part.startsWith('`') && part.endsWith('`') ? ( + {part.slice(1, -1)} + ) : ( + part + ) + )} + +

+ ) + })} +
+ ) +} + function TimelineEntry({ item, currentMatchedSHA, @@ -156,56 +277,77 @@ function TimelineEntry({ expanded: boolean onExpand: () => void }) { - const isRelease = item.record_kind === 'release' && item.version_state === 'verified' - const heading = isRelease ? item.version_label : item.version_label || `历史提交 · ${item.short_sha}` + const heading = item.version_label || `历史提交 · ${item.short_sha}` const note = item.version_state === 'verified' ? item.release_notes : '' - const hasDetail = Boolean(item.body) || Boolean(note) + const isCurrent = Boolean(item.commit_sha && item.commit_sha === currentMatchedSHA) + const detailID = 'version-detail-' + item.commit_sha return ( -
  • -
    - {heading} - {stamp(item.committed_at)} -
    -
    +
  • + {!item.version_label && item.record_kind === 'historical' ? (

    版本号未能核验:{reasonLabel(item.version_reason)}

    ) : null} - {hasDetail ? ( - <> - - {expanded ? ( -
    - {note ?
    {note}
    : null} - {item.body ?
    {item.body}
    : null} + {expanded ? ( +
    + {note ? ( + + ) : ( +

    此提交未附单独的变更说明,可查看下方原始提交。

    + )} +
    + 原始记录与提交信息 +
    +
    +
    提交
    +
    {item.commit_sha}
    +
    +
    +
    作者
    +
    {item.author_display || '—'}
    +
    +
    +
    提交标题
    +
    {item.subject}
    +
    +
    + {note ?
    {note}
    : null} + {item.body ?
    {item.body}
    : null} +
    + {item.commit_url ? ( + + 查看提交 + + ) : null} + {item.release_tags + .filter((tag) => tag.url) + .map((tag) => ( + + 查看 tag {tag.name} + + ))}
    - ) : null} - +
    +
    ) : null} -
    - {item.commit_url ? ( - - 查看提交 - - ) : null} - {/* 没有链接就不渲染:空 href 点下去像"没反应/空白",比不显示更糟 */} - {item.release_tags - .filter((tag) => tag.url) - .map((tag) => ( - - 查看 tag {tag.name} - - ))} -
  • ) } @@ -219,7 +361,7 @@ export function VersionHistory() { const [loadingMore, setLoadingMore] = useState(false) const [error, setError] = useState(null) const [notice, setNotice] = useState(null) - const [expanded, setExpanded] = useState(null) + const [expanded, setExpanded] = useState(undefined) const cursor = useRef('') const load = useCallback(async (kind: string, append: boolean) => { @@ -276,6 +418,7 @@ export function VersionHistory() { notice, expanded, canSync, + onRefresh: () => void load(filter, false), onFilter: setFilter, onLoadMore: () => void load(filter, true), onSync: () => void onSync(), diff --git a/web/src/versionHistory.css b/web/src/versionHistory.css index b406b0d..e2127f6 100644 --- a/web/src/versionHistory.css +++ b/web/src/versionHistory.css @@ -1,46 +1,124 @@ -/* 「版本记录」页:只读时间线。窄屏(≤760px,与工作台既有断点一致)单列、无横向溢出。 */ +/* Version records: build identity first, then compact commit accordions. */ .version-history { display: flex; flex-direction: column; - gap: 12px; + gap: 18px; + min-width: 0; + padding: 24px; + color: var(--ink-base); +} +.version-history-header, +.version-history-current-card, +.version-history-records { + background: var(--bg-panel, #fff); + border: 1px solid var(--border-base, #e2e8f0); + border-radius: 10px; + padding: 20px; min-width: 0; } .version-history-header { display: flex; - align-items: flex-start; + align-items: center; justify-content: space-between; - gap: 12px; - flex-wrap: wrap; + gap: 16px; } -.version-history-header h2 { +.version-history h2 { margin: 0 0 4px; + font-size: 22px; +} +.version-history h3 { + margin: 0; font-size: 18px; } -.version-history-header p { +.version-history-header p, +.version-history-records-heading p { margin: 0; - color: var(--muted, #666); + color: var(--ink-mute, #64748b); font-size: 13px; } +.version-history-actions { + display: flex; + gap: 8px; + flex-shrink: 0; +} +.version-history-actions button { + padding: 7px 14px; +} +.version-history-build-grid { + display: grid; + grid-template-columns: 0.8fr 0.8fr 2fr 1.3fr; + margin: 16px 0 0; + border: 1px solid var(--border-base, #e2e8f0); + background: var(--bg-page, #f8fafc); +} +.version-history-build-grid > div { + padding: 12px 14px; + min-width: 0; + border-right: 1px solid var(--border-base, #e2e8f0); +} +.version-history-build-grid > div:last-child { + border-right: 0; +} +.version-history dt { + color: var(--ink-mute, #64748b); + font-size: 12px; + margin-bottom: 5px; +} +.version-history dd { + margin: 0; + overflow-wrap: anywhere; + font-size: 13px; +} +.version-history-running-version { + font-size: 22px !important; + font-weight: 650; + color: var(--ink-strong); +} +.version-history-running-state { + margin: 12px 0 0; + color: var(--ink-mute, #64748b); + font-size: 12px; + overflow-wrap: anywhere; +} +.version-history-records-heading { + display: flex; + justify-content: space-between; + align-items: center; + gap: 12px; + flex-wrap: wrap; +} .version-history-sync-line { display: flex; align-items: center; + flex-wrap: wrap; gap: 8px; - margin-top: 4px !important; + margin: 10px 0 14px; + color: var(--ink-mute, #64748b); + font-size: 12px; } .version-history-notice { - padding: 8px 10px; + padding: 10px 14px; border-radius: 6px; - background: rgba(64, 158, 255, 0.12); + background: var(--c-run-bg, #eff6ff); font-size: 13px; } .version-history-filters { display: flex; - gap: 8px; + gap: 6px; flex-wrap: wrap; + margin: 0 0 16px; +} +.version-history-filters button { + padding: 5px 13px; + background: transparent; + color: var(--ink-mute); + box-shadow: none; } .version-history-filters button.active { font-weight: 600; - border-color: currentColor; + color: var(--c-run, #2563eb); + background: var(--c-run-bg, #eff6ff); + border-color: var(--c-run-border, #bfdbfe); } .version-history-timeline { list-style: none; @@ -52,109 +130,270 @@ min-width: 0; } .version-history-entry { - border-left: 3px solid rgba(127, 127, 127, 0.35); - padding: 10px 12px; - background: rgba(127, 127, 127, 0.06); - border-radius: 6px; + border: 1px solid var(--border-base, #e2e8f0); + border-radius: 8px; + background: var(--bg-panel, #fff); min-width: 0; + overflow: hidden; } -.version-history-entry.release { - border-left-color: #2f9e44; -} -.version-history-entry.development { - border-left-color: #1c7ed6; +.version-history-entry.is-current { + border-color: #3ba879; } .version-history-entry-head { - display: flex; - justify-content: space-between; - gap: 8px; - flex-wrap: wrap; -} -.version-history-entry-head strong { - font-size: 15px; -} -.version-history-entry-meta { display: flex; align-items: center; - gap: 8px; - flex-wrap: wrap; - margin-top: 4px; - font-size: 12px; - color: var(--muted, #666); + gap: 10px; + width: 100%; + min-height: 62px; + padding: 12px 16px; + border: 0; + border-radius: 0; + background: transparent; + box-shadow: none; + text-align: left; + color: inherit; + font-weight: 400; +} +.version-history-entry-head:hover { + background: var(--bg-hover, #f8fafc); +} +.version-history-entry-head[aria-expanded='true'] { + background: var(--bg-page, #f8fafc); + border-bottom: 1px solid var(--border-base, #e2e8f0); +} +.version-history-entry-head:focus-visible { + outline: 2px solid var(--c-run, #2563eb); + outline-offset: -3px; +} +.version-history-version { + display: inline-block; + flex-shrink: 0; + font-size: 13px; + padding: 3px 8px; + border: 1px solid var(--border-strong, #cbd5e1); + border-radius: 5px; + font-weight: 500; + color: var(--ink-mute); +} +.version-history-version.development { + border-color: #b4d1f5; + color: #2465aa; +} +.version-history-version.release { + border-color: #b1d7bd; + color: #24814e; } .version-history-badge { - padding: 1px 6px; - border-radius: 999px; - border: 1px solid currentColor; - font-size: 12px; -} -.version-history-badge.release { - color: #2f9e44; -} -.version-history-badge.development { - color: #1c7ed6; -} -.version-history-badge.historical { - color: #868e96; + display: inline-block; + padding: 2px 6px; + border-radius: 4px; + font-size: 11px; + white-space: nowrap; + flex-shrink: 0; + color: var(--ink-mute); + background: var(--bg-soft); } .version-history-badge.current { - color: #e8590c; + color: #177244; + background: #eaf7ef; } -.version-history-badge.pending { - color: #1c7ed6; +.version-history-badge.pending, +.version-history-badge.development { + color: #2465aa; + background: #eff6ff; +} +.version-history-badge.release { + color: #24814e; + background: #eaf7ef; } .version-history-badge.warn { - color: #c92a2a; + color: #b42318; + background: #fff1ef; } .version-history-sha { - font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-family: var(--font-mono, ui-monospace, monospace); overflow-wrap: anywhere; + font-size: 12px; +} +.version-history-entry-head > .version-history-sha, +.version-history-entry-head time { + color: var(--ink-faint, #7c8c9f); + flex-shrink: 0; + font-size: 12px; } .version-history-subject { - margin: 6px 0 0; - overflow-wrap: anywhere; -} -.version-history-reason { - margin: 4px 0 0; - font-size: 12px; - color: #c92a2a; + flex: 1; + min-width: 80px; + font-size: 14px; + line-height: 1.6; overflow-wrap: anywhere; } .version-history-toggle { - margin-top: 6px; + flex-shrink: 0; + font-size: 13px; + color: var(--c-run, #2563eb); } -.version-history-detail pre { - margin: 6px 0 0; - padding: 8px; - max-height: 320px; - overflow: auto; - background: rgba(127, 127, 127, 0.1); - border-radius: 6px; +.version-history-detail { + padding: 16px; + min-width: 0; +} +.version-history-notes h4 { + margin: 0 0 12px; + font-size: 14px; +} +.version-history-change-row { + display: flex; + align-items: baseline; + gap: 12px; + margin: 0 0 12px; + font-size: 14px; + line-height: 1.8; + overflow-wrap: anywhere; +} +.version-history-change-row > span:last-child { + min-width: 0; +} +.version-history-change-tag { + flex-shrink: 0; + padding: 1px 7px; + border-radius: 4px; + font-size: 12px; + line-height: 1.6; + background: #eef2f6; + color: #536275; +} +.version-history-change-tag.added { + background: #eaf7ef; + color: #177244; +} +.version-history-change-tag.fixed { + background: #fff3df; + color: #986000; +} +.version-history-change-tag.changed { + background: #eff6ff; + color: #2465aa; +} +.version-history-change-tag.security { + background: #fff1ef; + color: #b42318; +} +.version-history-notes code { + font-size: 12px; + background: var(--bg-soft); + border-radius: 3px; + padding: 1px 4px; +} +.version-history-reason, +.version-history-no-notes { + margin: 0; + font-size: 12px; + color: var(--ink-mute); + overflow-wrap: anywhere; +} +.version-history-reason { + padding: 0 16px 10px; + color: #986000; +} +.version-history-technical { + margin-top: 14px; + padding-top: 12px; + border-top: 1px solid var(--border-base); + font-size: 12px; + color: var(--ink-mute); +} +.version-history-technical summary { + cursor: pointer; +} +.version-history-technical dl { + display: grid; + gap: 10px; + margin: 12px 0; +} +.version-history-technical pre { white-space: pre-wrap; overflow-wrap: anywhere; + max-height: 320px; + overflow: auto; font-size: 12px; + line-height: 1.7; + padding: 12px; + border: 1px solid var(--border-base); + border-radius: 6px; + background: var(--bg-page); } .version-history-links { display: flex; - gap: 10px; flex-wrap: wrap; - margin-top: 6px; - font-size: 13px; + gap: 12px; + margin-top: 10px; +} +.version-history-more { + display: block; + margin: 18px auto 0; +} +@media (max-width: 1100px) { + .version-history-entry-head { + flex-wrap: wrap; + } + .version-history-subject { + flex-basis: 55%; + } + .version-history-build-grid { + grid-template-columns: 1fr 1fr; + } + .version-history-build-grid > div { + border-bottom: 1px solid var(--border-base); + } } - @media (max-width: 760px) { + .version-history { + padding: 12px; + overflow-wrap: anywhere; + } .version-history-header { flex-direction: column; align-items: stretch; } - .version-history-entry { - padding: 8px 10px; + .version-history-header, + .version-history-current-card, + .version-history-records { + padding: 14px; } .version-history-entry-head { flex-direction: column; - gap: 2px; + align-items: flex-start; + gap: 7px; + padding: 12px; + } + .version-history-entry-head > .version-history-badge { + align-self: flex-start; + } + .version-history-entry-head time { + white-space: normal; + } + .version-history-subject { + flex-basis: auto; + width: 100%; + } + .version-history-toggle { + align-self: flex-end; + } + .version-history-build-grid { + grid-template-columns: 1fr; + } + .version-history-build-grid > div { + border-right: 0; + } + .version-history-actions { + flex-wrap: wrap; + } + .version-history-detail { + padding: 12px; + } + .version-history-change-row { + gap: 8px; } - /* 窄屏单列:正文/标题/hash 一律换行,不出现横向滚动 */ .version-history, .version-history-timeline, .version-history-entry, @@ -165,7 +404,7 @@ overflow-wrap: anywhere; word-break: break-word; } - .version-history-detail pre { + .version-history-technical pre { max-height: none; } }