fix(bom): preserve local vendor spec on config import

This commit is contained in:
Mikhail Chusavitin
2026-02-27 10:11:20 +03:00
parent 586114c79c
commit a42a80beb8
2 changed files with 67 additions and 0 deletions

View File

@@ -148,6 +148,9 @@ func (s *Service) ImportConfigurationsToLocal() (*ConfigImportResult, error) {
if localCfg.Line <= 0 && existing.Line > 0 {
localCfg.Line = existing.Line
}
// vendor_spec is local-only for BOM tab and is not stored on server.
// Preserve it during server pull updates.
localCfg.VendorSpec = existing.VendorSpec
result.Updated++
} else {
result.Imported++

View File

@@ -315,6 +315,70 @@ func TestImportConfigurationsToLocalPullsLine(t *testing.T) {
}
}
func TestImportConfigurationsToLocalPreservesLocalVendorSpec(t *testing.T) {
local := newLocalDBForSyncTest(t)
serverDB := newServerDBForSyncTest(t)
cfg := models.Configuration{
UUID: "server-vendorspec-config",
OwnerUsername: "tester",
Name: "Cfg VendorSpec Pull",
Items: models.ConfigItems{{LotName: "CPU_PULL", Quantity: 1, UnitPrice: 900}},
ServerCount: 1,
Line: 50,
}
total := cfg.Items.Total()
cfg.TotalPrice = &total
if err := serverDB.Create(&cfg).Error; err != nil {
t.Fatalf("seed server config: %v", err)
}
localSpec := localdb.VendorSpec{
{
SortOrder: 10,
VendorPartnumber: "GPU-NVHGX-H200-8141",
Quantity: 1,
Description: "NVIDIA HGX Delta-Next GPU Baseboard",
LotMappings: []localdb.VendorSpecLotMapping{
{LotName: "GPU_NV_H200_141GB_SXM_(HGX)", QuantityPerPN: 8},
},
},
}
if err := local.SaveConfiguration(&localdb.LocalConfiguration{
UUID: cfg.UUID,
OriginalUsername: "tester",
Name: "Local cfg",
Items: localdb.LocalConfigItems{{LotName: "CPU_PULL", Quantity: 1, UnitPrice: 900}},
IsActive: true,
SyncStatus: "synced",
Line: 50,
VendorSpec: localSpec,
CreatedAt: time.Now().Add(-30 * time.Minute),
UpdatedAt: time.Now().Add(-30 * time.Minute),
}); err != nil {
t.Fatalf("seed local configuration: %v", err)
}
svc := syncsvc.NewServiceWithDB(serverDB, local)
if _, err := svc.ImportConfigurationsToLocal(); err != nil {
t.Fatalf("import configurations to local: %v", err)
}
localCfg, err := local.GetConfigurationByUUID(cfg.UUID)
if err != nil {
t.Fatalf("load local config: %v", err)
}
if len(localCfg.VendorSpec) != 1 {
t.Fatalf("expected local vendor_spec preserved, got %d rows", len(localCfg.VendorSpec))
}
if localCfg.VendorSpec[0].VendorPartnumber != "GPU-NVHGX-H200-8141" {
t.Fatalf("unexpected vendor_partnumber after import: %q", localCfg.VendorSpec[0].VendorPartnumber)
}
if len(localCfg.VendorSpec[0].LotMappings) != 1 || localCfg.VendorSpec[0].LotMappings[0].LotName != "GPU_NV_H200_141GB_SXM_(HGX)" {
t.Fatalf("unexpected lot mappings after import: %+v", localCfg.VendorSpec[0].LotMappings)
}
}
func TestPushPendingChangesCreateThenUpdateBeforeFirstPush(t *testing.T) {
local := newLocalDBForSyncTest(t)
serverDB := newServerDBForSyncTest(t)