package docrevision import ( "context" "fmt" "time" "github.com/jackc/pgx/v5/pgxpool" ) // SeedContentSnapshotForTest 以生产同构方式写入内容快照(本模块所有的 // document_content_blobs + document_snapshots)并返回快照 ID。 // // 用途:集成测试构造合法的 送审→审核→批准 链——账本封快照正是本模块的 // 生产行为。document_records 上的 head/review 指针回填归 docgov //(GovernanceEngine.FreezeHeadSnapshotForTest),两者配合使用。 func SeedContentSnapshotForTest(ctx context.Context, pool *pgxpool.Pool, docID string, actorID int64, content string) (int64, error) { if pool == nil { return 0, fmt.Errorf("docrevision: SeedContentSnapshotForTest requires a pool") } sha := fmt.Sprintf("sha_seed_%d", time.Now().UnixNano()) var snapID int64 err := pool.QueryRow(ctx, ` WITH blob AS ( INSERT INTO document_content_blobs (content_sha256, content_markdown, byte_size, created_at) VALUES ($2, $3, $4, now()) RETURNING content_sha256 ) INSERT INTO document_snapshots (doc_id, content_sha256, actor_user_id, actor_snapshot, source_kind, created_at) SELECT $1::text, blob.content_sha256, $5, '[]'::jsonb, 'human', now() FROM blob RETURNING id `, docID, sha, content, len(content), actorID).Scan(&snapID) if err != nil { return 0, fmt.Errorf("docrevision: seed snapshot: %w", err) } return snapID, nil }