Enable plain TTY logging mode + loose-data processing
This commit is contained in:
+39
-16
@@ -503,6 +503,27 @@ func countModuleFiles(dir string) int {
|
||||
|
||||
func discoverNativeDatasets(dataDir string) ([]nativeDataset, error) {
|
||||
var datasets []nativeDataset
|
||||
appendPlainDataset := func(rootPath, filePath, relName string) error {
|
||||
tableData, err := loadJSONObject(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
outputName, _ := tableData["output"].(string)
|
||||
if strings.TrimSpace(outputName) == "" {
|
||||
outputName = nativeDatasetDefaultOutputName(filePath, nativeDatasetPlain)
|
||||
}
|
||||
datasets = append(datasets, nativeDataset{
|
||||
Kind: nativeDatasetPlain,
|
||||
Name: filepath.ToSlash(relName),
|
||||
RootPath: rootPath,
|
||||
BasePath: filePath,
|
||||
LockPath: filepath.Join(rootPath, "lock.json"),
|
||||
OutputName: outputName,
|
||||
Spec: specForDataset(filepath.ToSlash(relName)),
|
||||
CompareReference: optionalBool(tableData["compare_reference"], true),
|
||||
})
|
||||
return nil
|
||||
}
|
||||
err := filepath.WalkDir(dataDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -519,6 +540,23 @@ func discoverNativeDatasets(dataDir string) ([]nativeDataset, error) {
|
||||
return err
|
||||
}
|
||||
if rel == "." {
|
||||
entries, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
name := entry.Name()
|
||||
if !strings.HasSuffix(strings.ToLower(name), ".json") || name == "lock.json" || name == "base.json" {
|
||||
continue
|
||||
}
|
||||
filePath := filepath.Join(path, name)
|
||||
if err := appendPlainDataset(path, filePath, strings.TrimSuffix(name, filepath.Ext(name))); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if filepath.ToSlash(rel) == "parts/overrides" {
|
||||
@@ -564,24 +602,9 @@ func discoverNativeDatasets(dataDir string) ([]nativeDataset, error) {
|
||||
name := entry.Name()
|
||||
if strings.HasSuffix(strings.ToLower(name), ".json") && name != "lock.json" {
|
||||
filePath := filepath.Join(path, name)
|
||||
tableData, err := loadJSONObject(filePath)
|
||||
if err != nil {
|
||||
if err := appendPlainDataset(path, filePath, filepath.Join(rel, strings.TrimSuffix(name, filepath.Ext(name)))); err != nil {
|
||||
return err
|
||||
}
|
||||
outputName, _ := tableData["output"].(string)
|
||||
if strings.TrimSpace(outputName) == "" {
|
||||
outputName = nativeDatasetDefaultOutputName(filePath, nativeDatasetPlain)
|
||||
}
|
||||
datasets = append(datasets, nativeDataset{
|
||||
Kind: nativeDatasetPlain,
|
||||
Name: filepath.ToSlash(filepath.Join(rel, strings.TrimSuffix(name, filepath.Ext(name)))),
|
||||
RootPath: path,
|
||||
BasePath: filePath,
|
||||
LockPath: filepath.Join(path, "lock.json"),
|
||||
OutputName: outputName,
|
||||
Spec: specForDataset(filepath.ToSlash(filepath.Join(rel, strings.TrimSuffix(name, filepath.Ext(name))))),
|
||||
CompareReference: optionalBool(tableData["compare_reference"], true),
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -267,6 +267,9 @@ func newestTopDataSource(p *project.Project) (time.Time, string, error) {
|
||||
if d.IsDir() && shouldSkipTopDataSourceDir(path, skipDirs) {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
if path == sourceDir {
|
||||
return nil
|
||||
}
|
||||
info, err := d.Info()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -6892,7 +6892,7 @@ func TestBuildGeneratedApplyAfterPrunesLowLockedID(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildOverrideNullValueKeyNullifiesEntireRow(t *testing.T) {
|
||||
func TestBuildOverrideAsteriskKeyRemovesIdentityWithoutNullingRow(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "dense", "modules"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
@@ -6925,8 +6925,8 @@ func TestBuildOverrideNullValueKeyNullifiesEntireRow(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("read dense.2da: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(got), "7\t****\t****\n") {
|
||||
t.Fatalf("expected override key \"****\" to nullify row 7, got:\n%s", string(got))
|
||||
if !strings.Contains(string(got), "7\tShouldNotLeak\tstill-not-kept\n") {
|
||||
t.Fatalf("expected override key \"****\" to remove identity without blanking row 7, got:\n%s", string(got))
|
||||
}
|
||||
lockRaw, err := os.ReadFile(filepath.Join(root, "topdata", "data", "dense", "lock.json"))
|
||||
if err != nil {
|
||||
@@ -11084,13 +11084,13 @@ func setTreeFileTimes(t *testing.T, root string, modTime time.Time) {
|
||||
if walkErr != nil {
|
||||
return walkErr
|
||||
}
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
if err := os.Chtimes(path, modTime, modTime); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Chtimes(path, modTime, modTime)
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("set file times under %s: %v", root, err)
|
||||
t.Fatalf("set tree times under %s: %v", root, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11302,6 +11302,34 @@ func TestValidateProjectWarnsWhenLockKeepsNormalizedEquivalentKeysAlive(t *testi
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildNativeSupportsLoosePlainTableAtTopdataDataRoot(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data"))
|
||||
writeFile(t, filepath.Join(root, "topdata", "base_dialog.json"), "{}\n")
|
||||
writeFile(t, filepath.Join(root, "topdata", "data", "ruleset.json"), `{
|
||||
"columns": ["Name", "Value"],
|
||||
"rows": [
|
||||
{"id": 0, "Name": "TEST_RULE", "Value": "1"}
|
||||
]
|
||||
}`+"\n")
|
||||
|
||||
proj := testProject(root)
|
||||
proj.Config.TopData.ReferenceBuilder = ""
|
||||
|
||||
report := ValidateProject(proj)
|
||||
if report.HasErrors() {
|
||||
t.Fatalf("expected loose root table to validate cleanly, got:\n%s", diagnosticsText(report.Diagnostics))
|
||||
}
|
||||
|
||||
result, err := BuildNativeWithOptions(proj, NativeBuildOptions{BuildWiki: false}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("expected loose root table to build: %v", err)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(result.Output2DADir, "ruleset.2da")); err != nil {
|
||||
t.Fatalf("expected ruleset.2da output for loose root table: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateProjectErrorsOnTopPackageAssetCollision(t *testing.T) {
|
||||
root := testProjectRoot(t)
|
||||
mkdirAll(t, filepath.Join(root, "topdata", "data", "repadjust"))
|
||||
|
||||
Reference in New Issue
Block a user