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.
163 lines
4.9 KiB
Go
163 lines
4.9 KiB
Go
package projectinstance
|
|
|
|
import (
|
|
"context"
|
|
|
|
"chat-agent-system/internal/workflowdef"
|
|
)
|
|
|
|
// NewMemoryStore 返回内存 Store,供跨包集成测试使用。
|
|
func NewMemoryStore() Store {
|
|
return newMemStore()
|
|
}
|
|
|
|
// TestResolver 返回最小正式商务工作流解析器。
|
|
func TestResolver() VersionResolver {
|
|
return testResolver()
|
|
}
|
|
|
|
// ValidTestPlan 返回单阶段 intake 测试规划。
|
|
func ValidTestPlan() WorkflowPlan {
|
|
return validPlan()
|
|
}
|
|
|
|
// StubDocChecker 内存文档批准状态探针。
|
|
type StubDocChecker struct {
|
|
States map[string]string
|
|
}
|
|
|
|
func (s *StubDocChecker) TaskApprovalStates(_ context.Context, _ int64) (map[string]string, error) {
|
|
if s == nil {
|
|
return map[string]string{}, nil
|
|
}
|
|
return s.States, nil
|
|
}
|
|
|
|
type stubVersionResolver struct {
|
|
versions map[string]*workflowdef.Version
|
|
defs map[string]*workflowdef.Definition
|
|
}
|
|
|
|
func (s *stubVersionResolver) GetDefinitionByKey(_ context.Context, key string) (*workflowdef.Definition, error) {
|
|
d, ok := s.defs[key]
|
|
if !ok {
|
|
return nil, workflowdef.ErrNotFound
|
|
}
|
|
return d, nil
|
|
}
|
|
|
|
func (s *stubVersionResolver) GetVersion(_ context.Context, workflowID int64, version int) (*workflowdef.Version, error) {
|
|
for _, v := range s.versions {
|
|
if v.WorkflowID == workflowID && v.Version == version {
|
|
copyV := *v
|
|
return ©V, nil
|
|
}
|
|
}
|
|
return nil, workflowdef.ErrNotFound
|
|
}
|
|
|
|
func (s *stubVersionResolver) ListDefinitions(_ context.Context) ([]workflowdef.Definition, error) {
|
|
out := make([]workflowdef.Definition, 0, len(s.defs))
|
|
for _, d := range s.defs {
|
|
out = append(out, *d)
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
func disabledDocResolver() *stubVersionResolver {
|
|
r := testResolver()
|
|
r.versions[workflowdef.OfficialKeyMain].Definition.Stages[0].DocTasks = append(
|
|
r.versions[workflowdef.OfficialKeyMain].Definition.Stages[0].DocTasks,
|
|
workflowdef.DocTaskDef{
|
|
Key: "research", Title: "市场调研", CreatorConfigurable: true, BlockingWhenEnabled: false, DefaultEnabled: false,
|
|
OutputDocType: "research", OutputDocTitle: "市场调研",
|
|
},
|
|
)
|
|
return r
|
|
}
|
|
|
|
func testResolver() *stubVersionResolver {
|
|
key := workflowdef.OfficialKeyMain
|
|
ver := &workflowdef.Version{
|
|
ID: 100, WorkflowID: 10, Version: 1, Status: workflowdef.StatusPublished,
|
|
WorkflowKey: key, WorkflowName: workflowdef.OfficialWorkflowName(key),
|
|
Definition: workflowdef.VersionDefinition{
|
|
SchemaVersion: 2,
|
|
WorkflowKey: key,
|
|
Stages: []workflowdef.StageDef{{
|
|
Key: "V0.1_triage", Name: "V0.1 需求摸底", Optional: false, Position: 10,
|
|
DocTasks: []workflowdef.DocTaskDef{{
|
|
Key: "intake", Title: "用户初始需求收集表", CreatorConfigurable: true, BlockingWhenEnabled: true, DefaultEnabled: true,
|
|
OutputDocType: "intake", OutputDocTitle: "用户初始需求收集表",
|
|
}},
|
|
}},
|
|
},
|
|
}
|
|
return &stubVersionResolver{
|
|
defs: map[string]*workflowdef.Definition{
|
|
key: {ID: 10, Key: key, Name: workflowdef.OfficialWorkflowName(key), LatestPublishedVersion: 1},
|
|
},
|
|
versions: map[string]*workflowdef.Version{key: ver},
|
|
}
|
|
}
|
|
|
|
// OptionalDutyResolver 导出含可裁剪 research 文档的测试定义。
|
|
func OptionalDutyResolver() VersionResolver {
|
|
return optionalDutyResolver()
|
|
}
|
|
|
|
// OptionalDutyPlan 导出一份 full + none 测试规划。
|
|
func OptionalDutyPlan(intake, research DocDuty) WorkflowPlan {
|
|
return optionalDutyPlan(intake, research)
|
|
}
|
|
|
|
func optionalDutyResolver() *stubVersionResolver {
|
|
r := testResolver()
|
|
r.versions[workflowdef.OfficialKeyMain].Definition.Stages[0].DocTasks = []workflowdef.DocTaskDef{
|
|
{
|
|
Key: "intake", Title: "用户初始需求收集表", CreatorConfigurable: true, BlockingWhenEnabled: true, DefaultEnabled: true,
|
|
OutputDocType: "intake", OutputDocTitle: "用户初始需求收集表",
|
|
},
|
|
{
|
|
Key: "research", Title: "市场调研", CreatorConfigurable: true, BlockingWhenEnabled: false, DefaultEnabled: true,
|
|
OutputDocType: "research", OutputDocTitle: "市场调研",
|
|
},
|
|
}
|
|
return r
|
|
}
|
|
|
|
func requiredDutyResolver() *stubVersionResolver {
|
|
r := testResolver()
|
|
r.versions[workflowdef.OfficialKeyMain].Definition.Stages[0].DocTasks[0].Required = true
|
|
r.versions[workflowdef.OfficialKeyMain].Definition.Stages[0].DocTasks[0].CreatorConfigurable = false
|
|
return r
|
|
}
|
|
|
|
func optionalDutyPlan(intake, research DocDuty) WorkflowPlan {
|
|
return WorkflowPlan{
|
|
WorkflowDefinitionKey: workflowdef.OfficialKeyMain,
|
|
WorkflowVersion: 1,
|
|
Stages: []StagePlan{{
|
|
StageKey: "V0.1_triage", Enabled: true,
|
|
DocTasks: []DocTaskPlan{
|
|
{TaskKey: "intake", Enabled: true, Duties: intake},
|
|
{TaskKey: "research", Enabled: true, Duties: research},
|
|
},
|
|
}},
|
|
}
|
|
}
|
|
|
|
func validPlan() WorkflowPlan {
|
|
return WorkflowPlan{
|
|
WorkflowDefinitionKey: workflowdef.OfficialKeyMain,
|
|
WorkflowVersion: 1,
|
|
Stages: []StagePlan{{
|
|
StageKey: "V0.1_triage", Enabled: true,
|
|
DocTasks: []DocTaskPlan{{
|
|
TaskKey: "intake", Enabled: true,
|
|
Duties: DocDuty{AuthorUserID: 1, ReviewerUserID: 2, ApproverUserID: 3},
|
|
}},
|
|
}},
|
|
}
|
|
}
|