feat(assessment): report planned bank coverage
This commit is contained in:
1 parent
76d32bb79f
commit
a69b1a79bb
10 files changed
+1211
-288
No files matched your search
@@ -0,0 +1,194 @@
|
||||
package assessment
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"lincodex/backend/internal/domain"
|
||||
)
|
||||
|
||||
const bankCoverageManifestPath = "../../../testdata/assessment/bank_manifest.json"
|
||||
|
||||
func loadBankCoverageManifest(t *testing.T) BankCoverageManifest {
|
||||
t.Helper()
|
||||
content, err := os.ReadFile(filepath.FromSlash(bankCoverageManifestPath))
|
||||
if err != nil {
|
||||
t.Fatalf("read bank coverage manifest: %v", err)
|
||||
}
|
||||
manifest, err := ParseBankCoverageManifest(content)
|
||||
if err != nil {
|
||||
t.Fatalf("ParseBankCoverageManifest() error = %v", err)
|
||||
}
|
||||
return manifest
|
||||
}
|
||||
|
||||
func TestBankCoverageManifestMatchesThePlannedTopicCounts(t *testing.T) {
|
||||
manifest := loadBankCoverageManifest(t)
|
||||
if len(manifest.Categories) != 2 {
|
||||
t.Fatalf("manifest has %d categories, want Backend and Network", len(manifest.Categories))
|
||||
}
|
||||
if manifest.Categories[0].Code != "backend" || manifest.Categories[0].RequiredFamilyCount != 25 {
|
||||
t.Fatalf("Backend plan = %+v, want 25 families", manifest.Categories[0])
|
||||
}
|
||||
if !sameStringSet(manifest.Categories[0].RequiredLanguages, []string{"go", "python"}) {
|
||||
t.Fatalf("Backend languages = %v, want Go and Python", manifest.Categories[0].RequiredLanguages)
|
||||
}
|
||||
if manifest.Categories[1].Code != "network" || manifest.Categories[1].RequiredFamilyCount != 15 {
|
||||
t.Fatalf("Network plan = %+v, want 15 families", manifest.Categories[1])
|
||||
}
|
||||
if len(manifest.Categories[1].RequiredLanguages) != 0 {
|
||||
t.Fatalf("Network languages = %v, want no language-specific implementation requirement", manifest.Categories[1].RequiredLanguages)
|
||||
}
|
||||
if got := sumTopicCounts(requiredBankPlan["backend"]); got != 25 {
|
||||
t.Fatalf("Backend topic count = %d, want 25", got)
|
||||
}
|
||||
if got := sumTopicCounts(requiredBankPlan["network"]); got != 15 {
|
||||
t.Fatalf("Network topic count = %d, want 15", got)
|
||||
}
|
||||
if !manifest.CalibrationGates.ExternalMeasurementRequired {
|
||||
t.Fatal("calibration gates must require external measurements")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBankCoverageRejectsAnIncompleteManifest(t *testing.T) {
|
||||
manifest := loadBankCoverageManifest(t)
|
||||
manifest.Categories[0].RequiredLanguages = []string{"python"}
|
||||
content, err := json.Marshal(manifest)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal manifest: %v", err)
|
||||
}
|
||||
if _, err := ParseBankCoverageManifest(content); !errors.Is(err, domain.ErrInvalidAssessmentFamily) {
|
||||
t.Fatalf("ParseBankCoverageManifest(missing Go requirement) error = %v, want invalid manifest", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBankCoverageReportsTheExistingUnreviewedDemoInventory(t *testing.T) {
|
||||
bundle := loadDemoBundle(t)
|
||||
inventory := bankCoverageInventoryFromBundle(t, bundle)
|
||||
report, err := BuildBankCoverageReport(loadBankCoverageManifest(t), inventory)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildBankCoverageReport() error = %v", err)
|
||||
}
|
||||
if report.InventoriedFamilies != 4 || report.PendingReviewDeclarations != 4 || report.DeclaredApprovedReviews != 0 {
|
||||
t.Fatalf("demo inventory/review counts = %d/%d/%d, want 4 inventoried, 4 pending, 0 approved declarations",
|
||||
report.InventoriedFamilies, report.PendingReviewDeclarations, report.DeclaredApprovedReviews)
|
||||
}
|
||||
if len(report.UnassignedFamilyKeys) != 4 || len(report.MissingFamilyKeys) != 40 {
|
||||
t.Fatalf("demo coverage = %d unassigned and %d missing keys, want 4 and 40", len(report.UnassignedFamilyKeys), len(report.MissingFamilyKeys))
|
||||
}
|
||||
if report.Categories[0].PresentFamilies != 0 || report.Categories[0].InventoriedFamilies != 4 {
|
||||
t.Fatalf("Backend coverage = %+v, want 0 planned keys matched and 4 inventoried demo families", report.Categories[0])
|
||||
}
|
||||
if report.Categories[0].RequiredImplementationFiles != 50 || report.Categories[1].RequiredImplementationFiles != 0 {
|
||||
t.Fatalf("implementation requirements = backend %d, network %d, want 50 and 0", report.Categories[0].RequiredImplementationFiles, report.Categories[1].RequiredImplementationFiles)
|
||||
}
|
||||
if !report.CalibrationMeasurementRequired || len(report.UnverifiableEvidence) == 0 {
|
||||
t.Fatalf("report did not preserve external gates and unsupported evidence: %+v", report)
|
||||
}
|
||||
if err := report.StrictError(); err == nil {
|
||||
t.Fatal("StrictError() = nil, want incomplete inventory error")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBankCoverageReportsThe24And14FamilyGaps(t *testing.T) {
|
||||
manifest := loadBankCoverageManifest(t)
|
||||
inventory := BankCoverageInventory{}
|
||||
for _, category := range manifest.Categories {
|
||||
remaining := category.RequiredFamilyCount - 1
|
||||
for _, topic := range category.Topics {
|
||||
for _, key := range topic.FamilyKeys {
|
||||
if remaining == 0 {
|
||||
break
|
||||
}
|
||||
inventory.Families = append(inventory.Families, pendingBankFamily(key, category.Code))
|
||||
remaining--
|
||||
}
|
||||
}
|
||||
}
|
||||
report, err := BuildBankCoverageReport(manifest, inventory)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildBankCoverageReport() error = %v", err)
|
||||
}
|
||||
if report.Categories[0].PresentFamilies != 24 || report.Categories[1].PresentFamilies != 14 {
|
||||
t.Fatalf("coverage = %d/%d and %d/%d, want 24/25 and 14/15",
|
||||
report.Categories[0].PresentFamilies, report.Categories[0].PlannedFamilies,
|
||||
report.Categories[1].PresentFamilies, report.Categories[1].PlannedFamilies)
|
||||
}
|
||||
if len(report.MissingFamilyKeys) != 2 {
|
||||
t.Fatalf("missing family keys = %v, want one gap per category", report.MissingFamilyKeys)
|
||||
}
|
||||
if len(report.MissingIndependentReviews) != 38 {
|
||||
t.Fatalf("missing review declarations = %d, want 38 present families with pending review", len(report.MissingIndependentReviews))
|
||||
}
|
||||
}
|
||||
|
||||
func TestBankCoverageNamesMissingGoVariantAndReviewer(t *testing.T) {
|
||||
manifest := loadBankCoverageManifest(t)
|
||||
key := manifest.Categories[0].Topics[0].FamilyKeys[0]
|
||||
inventory := BankCoverageInventory{
|
||||
Families: []BankCoverageFamilyRecord{pendingBankFamily(key, "backend")},
|
||||
ImplementationFiles: []string{filepath.ToSlash(filepath.Join("solutions", key+".py"))},
|
||||
}
|
||||
report, err := BuildBankCoverageReport(manifest, inventory)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildBankCoverageReport() error = %v", err)
|
||||
}
|
||||
goPath := filepath.ToSlash(filepath.Join("solutions", key+".go"))
|
||||
pythonPath := filepath.ToSlash(filepath.Join("solutions", key+".py"))
|
||||
if !slices.Contains(report.MissingImplementationFiles, goPath) {
|
||||
t.Fatalf("missing implementations = %v, want %s", report.MissingImplementationFiles, goPath)
|
||||
}
|
||||
if slices.Contains(report.MissingImplementationFiles, pythonPath) {
|
||||
t.Fatalf("missing implementations = %v, Python path %s is present", report.MissingImplementationFiles, pythonPath)
|
||||
}
|
||||
if !slices.Contains(report.MissingIndependentReviews, key) {
|
||||
t.Fatalf("missing review declarations = %v, want %s", report.MissingIndependentReviews, key)
|
||||
}
|
||||
if err := report.StrictError(); err == nil {
|
||||
t.Fatal("StrictError() = nil, want missing variant and reviewer declaration to fail strict checks")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBankCoverageReportsFamiliesFromUnplannedCategories(t *testing.T) {
|
||||
family := pendingBankFamily("other-family", "security")
|
||||
report, err := BuildBankCoverageReport(loadBankCoverageManifest(t), BankCoverageInventory{
|
||||
Families: []BankCoverageFamilyRecord{family},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("BuildBankCoverageReport() error = %v", err)
|
||||
}
|
||||
if report.InventoriedFamilies != 1 || !slices.Contains(report.UnassignedCategories, "security") ||
|
||||
!slices.Contains(report.UnassignedFamilyKeys, "other-family") {
|
||||
t.Fatalf("unplanned category inventory = %+v", report)
|
||||
}
|
||||
}
|
||||
|
||||
func bankCoverageInventoryFromBundle(t *testing.T, bundle Bundle) BankCoverageInventory {
|
||||
t.Helper()
|
||||
drafts, err := bundle.Drafts()
|
||||
if err != nil {
|
||||
t.Fatalf("Bundle.Drafts() error = %v", err)
|
||||
}
|
||||
inventory := BankCoverageInventory{}
|
||||
for _, draft := range drafts {
|
||||
core := draft.Core()
|
||||
inventory.Families = append(inventory.Families, BankCoverageFamilyRecord{
|
||||
Key: string(core.Key), Category: string(core.Category), Version: core.Version,
|
||||
Author: string(core.Author), Reviewer: string(core.Reviewer),
|
||||
ReviewStatus: string(core.ReviewStatus), Source: "demo bundle",
|
||||
})
|
||||
}
|
||||
return inventory
|
||||
}
|
||||
|
||||
func pendingBankFamily(key, category string) BankCoverageFamilyRecord {
|
||||
return BankCoverageFamilyRecord{
|
||||
Key: key, Category: category, Version: 1,
|
||||
Author: "operator:author", ReviewStatus: string(domain.AssessmentReviewPending),
|
||||
Source: "unit bundle",
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user