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.
61 lines
2.1 KiB
Go
61 lines
2.1 KiB
Go
package ctxmgr
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"chat-agent-system/internal/replyexport"
|
|
)
|
|
|
|
func TestCollectProjectDialogue_ExcludesPrivateAndIncludesShared(t *testing.T) {
|
|
ctx := context.Background()
|
|
mgr := NewContextManager(nil, nil, DefaultTimeDecayConfig())
|
|
projectID := int64(501)
|
|
meta := map[string]any{"project_id": projectID}
|
|
|
|
_, _ = mgr.RecordUserMessageWithID(ctx, "sess-501", 1, "user", "[private] 不应纳入", "", "", meta)
|
|
_, _ = mgr.RecordUserMessageWithID(ctx, "sess-501", 1, "user", "项目需要支持多用户协作", "", "", meta)
|
|
_, _ = mgr.RecordUserMessageWithID(ctx, "sess-501", 1, "assistant", "好的,我会整理需求要点。", "", "", map[string]any{
|
|
"project_id": projectID,
|
|
"export_policy": string(replyexport.PolicyFull),
|
|
"content_kind": string(replyexport.KindDocumentText),
|
|
})
|
|
|
|
res, err := mgr.CollectProjectDialogue(ctx, projectID, CollectProjectDialogueOptions{})
|
|
if err != nil {
|
|
t.Fatalf("CollectProjectDialogue: %v", err)
|
|
}
|
|
if len(res.Lines) != 2 {
|
|
t.Fatalf("expected 2 shared lines, got %d: %v", len(res.Lines), res.Lines)
|
|
}
|
|
if res.ExcludedPrivate < 1 {
|
|
t.Fatalf("expected excluded private >= 1, got %d", res.ExcludedPrivate)
|
|
}
|
|
}
|
|
|
|
func TestCollectProjectDialogue_StageFilter(t *testing.T) {
|
|
ctx := context.Background()
|
|
mgr := NewContextManager(nil, nil, DefaultTimeDecayConfig())
|
|
projectID := int64(502)
|
|
|
|
_, _ = mgr.RecordUserMessageWithID(ctx, "sess-502", 1, "user", "立项阶段讨论", "", "", map[string]any{
|
|
"project_id": projectID, "stage_key": "biz_intake",
|
|
})
|
|
_, _ = mgr.RecordUserMessageWithID(ctx, "sess-502", 1, "user", "研发阶段讨论", "", "", map[string]any{
|
|
"project_id": projectID, "stage_key": "biz_feasibility",
|
|
})
|
|
|
|
res, err := mgr.CollectProjectDialogue(ctx, projectID, CollectProjectDialogueOptions{
|
|
AllowedStageKey: "biz_intake",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CollectProjectDialogue: %v", err)
|
|
}
|
|
if len(res.Lines) != 1 {
|
|
t.Fatalf("expected 1 stage-filtered line, got %d: %v", len(res.Lines), res.Lines)
|
|
}
|
|
if res.ExcludedNoAccess != 1 {
|
|
t.Fatalf("expected 1 excluded by stage, got %d", res.ExcludedNoAccess)
|
|
}
|
|
}
|