Fix id flip
This commit is contained in:
@@ -311,7 +311,7 @@ func buildNativeUnchecked(p *project.Project, opts NativeBuildOptions, progress
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
lockAdded, lockPruned, err := saveNativeBaseLockfiles(collected)
|
||||
lockAdded, lockPruned, err := saveNativeLockfiles(collected)
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
}
|
||||
@@ -419,11 +419,11 @@ func nativeCompileGroup(datasetName string) string {
|
||||
}
|
||||
}
|
||||
|
||||
func saveNativeBaseLockfiles(collected []nativeCollectedDataset) (int, int, error) {
|
||||
func saveNativeLockfiles(collected []nativeCollectedDataset) (int, int, error) {
|
||||
added := 0
|
||||
pruned := 0
|
||||
for _, dataset := range collected {
|
||||
if dataset.Dataset.Kind != nativeDatasetBase || dataset.Dataset.LockPath == "" {
|
||||
if dataset.Dataset.LockPath == "" {
|
||||
continue
|
||||
}
|
||||
current, err := loadLockfile(dataset.Dataset.LockPath)
|
||||
@@ -2769,7 +2769,6 @@ func collectPlainDataset(dataset nativeDataset) (nativeCollectedDataset, error)
|
||||
}
|
||||
|
||||
rows := make([]map[string]any, 0, len(rawRows))
|
||||
lockModified := false
|
||||
explicitID := make([]bool, 0, len(rawRows))
|
||||
for index, raw := range rawRows {
|
||||
rowObj, ok := raw.(map[string]any)
|
||||
@@ -2804,7 +2803,6 @@ func collectPlainDataset(dataset nativeDataset) (nativeCollectedDataset, error)
|
||||
usedIDs[nextID] = struct{}{}
|
||||
nextID = nextAvailableID(usedIDs)
|
||||
}
|
||||
lockModified = true
|
||||
continue
|
||||
}
|
||||
if !explicitID[index] {
|
||||
@@ -2812,12 +2810,6 @@ func collectPlainDataset(dataset nativeDataset) (nativeCollectedDataset, error)
|
||||
}
|
||||
}
|
||||
|
||||
if lockModified {
|
||||
if err := saveLockfile(dataset.LockPath, lockData); err != nil {
|
||||
return nativeCollectedDataset{}, fmt.Errorf("dataset %s: %w", dataset.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
slices.SortFunc(rows, func(a, b map[string]any) int {
|
||||
return a["id"].(int) - b["id"].(int)
|
||||
})
|
||||
|
||||
@@ -11330,6 +11330,39 @@ func TestBuildNativeSupportsLoosePlainTableAtTopdataDataRoot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectDoesNotRewritePlainDatasetLockfile(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "ruleset"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
lockPath := filepath.Join(root, "topdata", "data", "ruleset", "lock.json")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "ruleset", "base.json"), `{
|
||||
"output": "ruleset.2da",
|
||||
"columns": ["Name", "Value"],
|
||||
"rows": [
|
||||
{"id": 0, "key": "ruleset:test_rule", "Name": "TEST_RULE", "Value": "1"}
|
||||
]
|
||||
}`+"\n")
|
||||
writeFile(t, lockPath, "{}\n")
|
||||
|
||||
before, err := os.ReadFile(lockPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read initial lockfile: %v", err)
|
||||
}
|
||||
|
||||
report := ValidateProject(testProject(root))
|
||||
if report.HasErrors() {
|
||||
t.Fatalf("expected validation to succeed, got:\n%s", diagnosticsText(report.Diagnostics))
|
||||
}
|
||||
|
||||
after, err := os.ReadFile(lockPath)
|
||||
if err != nil {
|
||||
t.Fatalf("read lockfile after validation: %v", err)
|
||||
}
|
||||
if string(after) != string(before) {
|
||||
t.Fatalf("expected validation to leave plain dataset lockfile unchanged, got:\n%s", string(after))
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectErrorsOnTopPackageAssetCollision(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "repadjust"))
|
||||
|
||||
Reference in New Issue
Block a user