Files
knowledge-governance/internal/versionhistory/development_test.go
T
姚章浩 013ce4a24e
build / build (push) Successful in 1m3s
fix(version): 补全开发快照记录与同步交付闭环
收录 main、注释开发快照和完整运行 SHA;开发说明绑定原提交,补记 0.1.1–0.1.25。
进行中同步按仓库合并,完成后重新执行;启动入队,部署脚本读回版本证据。
开发快照独立于正式标签与 Release,既有冲突标签不移动。

已运行:整仓 make verify,Go 673 通过、前端 274 通过,92 个已声明可选跳过,必需跳过 0。
隔离 PostgreSQL 重复同步队列用例及 -race 通过;未更新现有 8088、未修改生产问答。
2026-10-18 18:11:49 +08:00

88 lines
3.9 KiB
Go

package versionhistory
import (
"context"
"fmt"
"knowledge-governance/internal/governance"
"net/http"
"strings"
"testing"
"time"
)
func TestGiteaSnapshotRefIsExplicitAndNotesArePreserved(t *testing.T) {
server := fakeGitea(t, func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/api/v1/repos/Weknora/knowledge-governance/commits" {
if r.URL.Query().Get("sha") != shaB {
t.Error("snapshot commit history silently used default branch")
}
fmt.Fprintf(w, `[{"sha":%q,"parents":[],"commit":{"message":"fixture"}}]`, shaB)
return
}
if r.URL.Path == "/api/v1/repos/Weknora/knowledge-governance/git/refs/tags" {
fmt.Fprintf(w, `[{"ref":"refs/tags/snapshot/v0.1.1","object":{"type":"tag","sha":%q}}]`, shaT)
return
}
fmt.Fprintf(w, `{"message":"development notes","object":{"type":"commit","sha":%q}}`, shaB)
})
c, _ := NewGiteaClient(validConfig(server.URL))
if _, _, e := c.ListCommitsAtRef(context.Background(), shaB, 1, 50); e != nil {
t.Fatal(e)
}
tags, e := c.ListTags(context.Background())
if e != nil || len(tags) != 1 || tags[0].Message != "development notes" {
t.Fatal("annotated snapshot notes lost", e)
}
}
func TestDevelopmentVersionsHaveTheirOwnChangelogNotes(t *testing.T) {
a, b := shaA, shaB
now := time.Now()
text := "# Changelog\n\n## [Unreleased]\n\n### Added\n\n- unrelated future work\n\n## 开发快照 snapshot/v0.1.1 - 2026-10-18\n\n### Fixed\n\n- fix specifically delivered here\n\n## [0.1.0] - 2026-10-13\n\n### Added\n\n- baseline\n"
result := DeriveVersions(DeriveInput{Commits: []RawCommit{{SHA: a, CommittedAt: now}, {SHA: b, Parents: []string{a}, CommittedAt: now}}, Tags: []RawTag{{Name: "v0.1.0", TargetSHA: a, Annotated: true}}, Changelog: func(string) (string, error) { return text, nil }})
for _, v := range result.Records {
if v.CommitSHA == b && (v.ReleaseNotes != "### Fixed\n\n- fix specifically delivered here" || v.RecordKind != governance.RecordKindDevelopment) {
t.Fatalf("development version lacks its own notes: %q", v.ReleaseNotes)
}
}
}
func TestHistoricDevelopmentArchiveBindsExactCommit(t *testing.T) {
archive := "## 开发快照 snapshot/v0.1.1 - 2026-10-18\n\n目标提交:" + shaB + "\n\n### Fixed\n\n- historic delivery notes\n"
input := DeriveInput{DeliveryArchive: archive, Commits: []RawCommit{{SHA: shaA}, {SHA: shaB, Parents: []string{shaA}}}, Tags: []RawTag{{Name: "v0.1.0", TargetSHA: shaA, Annotated: true}}, Changelog: func(string) (string, error) { return "## [0.1.0] - 2026-10-13\n\n### Added\n\n- baseline", nil }}
result := DeriveVersions(input)
for _, v := range result.Records {
if v.CommitSHA == shaB && !strings.Contains(v.ReleaseNotes, "historic delivery notes") {
t.Fatal("archived notes missing")
}
}
input.DeliveryArchive = strings.ReplaceAll(archive, shaB, strings.Repeat("c", 40))
result = DeriveVersions(input)
for _, v := range result.Records {
if v.CommitSHA == shaB && v.ReleaseNotes != "" {
t.Fatal("different commit reused same-number archive notes")
}
}
}
type snapshotRefSource struct {
fakeSource
other []RawCommit
}
func (s *snapshotRefSource) ListCommitsAtRef(_ context.Context, _ string, page, limit int) ([]RawCommit, int, error) {
if page == 1 {
return s.other, len(s.other), nil
}
return nil, len(s.other), nil
}
func TestSyncIncludesDeliveredSnapshotOutsideMain(t *testing.T) {
a := RawCommit{SHA: shaA}
b := RawCommit{SHA: shaB, Parents: []string{shaA}}
src := &snapshotRefSource{fakeSource: fakeSource{commits: []RawCommit{a}, total: 1, pageSize: 50, head: shaA, tags: []RawTag{{Name: "snapshot/v0.1.1", TargetSHA: shaB, Annotated: true}}}, other: []RawCommit{b, a}}
store := &fakeStore{}
run, e := newTestSyncer(t, src, store).Sync(context.Background(), "fixture", "admin")
if e != nil || len(store.saved) != 1 || len(store.saved[0].records) != 2 || !run.Complete {
t.Fatal("delivered non-main snapshot omitted", e, run.FetchedCount)
}
}