fix(tests): per-package test databases + legitimate approval fixtures (issue #2 close)
Root causes of the remaining 5 CI PG failures (and the hidden flaky set):
1. All PG-integration packages shared ONE database under parallel package
execution - migrations/seeds/truncates raced (nondeterministic failure
sets, locally and in CI).
Fix: RequireTestDatabaseURL/SkipIfNoTestDatabaseURL now derive a
per-package database (<base>_<pkgHash>, advisory-lock-guarded
CREATE); 9 raw-env straggler tests funnelled through the helpers;
db-package tests call it unqualified (no import cycle).
2. Approval-chain fixtures were not production-shaped: freezeReviewSnapshot
only honors head_snapshot_id, fake content hashes never froze a
snapshot, so ApproverApprove rejected with 'approved requires frozen
review_snapshot_id'. Errors were swallowed (_, _ =) hiding this.
Fix (ownership-respecting, arch-enforced):
- docrevision.SeedContentSnapshotForTest seeds the ledger tables it owns
- docgov GovernanceEngine.FreezeHeadSnapshotForTest freezes head/review
pointers on document_records (docgov-owned) and clears engine cache
- all four integration fixtures use the pair; swallowed errors checked
3. Fixed-name fixtures collide once a package shares one DB (projects
uq_projects_name_global): uniquified in projectinstance + server tests.
4. CAS/ctxmgr tests never bootstrapped migrations (relied on other packages
having migrated the shared DB): explicit RunMigrationsOnceForTest.
Verified: full parallel short suite = 75 packages, 0 failures against an
isolated throwaway PG. CI skip list removed - short tests fully required.
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package docgov
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// FreezeHeadSnapshotForTest 把文档 head/review 快照指针冻结到 snapID
|
||||
// (写本模块所有的 document_records),并清除引擎缓存使后续装载来自 PG。
|
||||
//
|
||||
// 与 docrevision.SeedContentSnapshotForTest 配合:账本 seed 内容快照(docrevision
|
||||
// 生产行为),治理侧冻结指针(本模块生产行为)。供集成测试构造合法批准链。
|
||||
func (e *GovernanceEngine) FreezeHeadSnapshotForTest(ctx context.Context, docID string, snapID int64) error {
|
||||
if e == nil || e.pool == nil {
|
||||
return fmt.Errorf("docgov: FreezeHeadSnapshotForTest requires a PG-backed engine")
|
||||
}
|
||||
if _, err := e.pool.Exec(ctx,
|
||||
`UPDATE document_records SET review_snapshot_id=$1, head_snapshot_id=$1 WHERE doc_id=$2`,
|
||||
snapID, docID); err != nil {
|
||||
return fmt.Errorf("docgov: freeze head snapshot: %w", err)
|
||||
}
|
||||
e.memMu.Lock()
|
||||
delete(e.memDocs, docID)
|
||||
e.memMu.Unlock()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user