From bdb0d5e302b70065346da05a893d6209f401b8a1 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 31 Dec 2025 14:06:10 +0000 Subject: [PATCH 1/3] Add -check-todo flag to auto-update metadata.json for passing tests The new -check-todo flag runs todo tests and automatically removes the `todo: true` flag from metadata.json for any tests that pass. This streamlines the workflow of enabling tests after parser changes. --- CLAUDE.md | 15 ++++++++++----- parser/parser_test.go | 21 ++++++++++++++++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index f04d7e51..7284e3fe 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,21 +18,26 @@ This tool finds all tests with `todo: true` in their metadata and returns the on 4. Implement the necessary AST types in `ast/` 5. Add parser logic in `parser/parser.go` 6. Add JSON marshaling functions in `parser/parser.go` -7. Enable the test by removing `todo: true` from its `metadata.json` (set it to `{}`) -8. Run `go test ./parser/...` to verify -9. **Check if other todo tests now pass** (see below) +7. Run `go test ./parser/... -check-todo -v` to auto-enable passing todo tests +8. Run `go test ./parser/...` to verify all enabled tests pass ## Checking for Newly Passing Todo Tests After implementing parser changes, run: ```bash -go test ./parser/... -only-todo -v 2>&1 | grep "PASS:" +go test ./parser/... -check-todo -v ``` -This shows any todo tests that now pass. Enable those tests by removing `todo: true` from their `metadata.json`. +This runs todo tests and **automatically updates `metadata.json`** for any tests that now pass (removes the `todo: true` flag). Look for "ENABLED:" in the output to see which tests were updated. + +To just see which tests pass without updating files: +```bash +go test ./parser/... -only-todo -v 2>&1 | grep "PASS:" +``` Available test flags: +- `-check-todo` - Run todo tests and auto-update metadata.json for passing tests - `-only-todo` - Run only todo/invalid_syntax tests (find newly passing tests) - `-run-todo` - Run todo/invalid_syntax tests along with normal tests diff --git a/parser/parser_test.go b/parser/parser_test.go index 037af9f6..e2d1d926 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -18,8 +18,10 @@ type testMetadata struct { // Test flags for running todo/invalid_syntax tests // Usage: go test ./parser/... -run-todo # run all tests including todo tests // Usage: go test ./parser/... -only-todo # run only todo tests (find newly passing tests) +// Usage: go test ./parser/... -check-todo # run todo tests and auto-update metadata.json for passing tests var runTodoTests = flag.Bool("run-todo", false, "run todo tests along with normal tests") var onlyTodoTests = flag.Bool("only-todo", false, "run only todo tests (useful to find tests that now pass)") +var checkTodoTests = flag.Bool("check-todo", false, "run todo tests and auto-update metadata.json for passing tests") func TestParse(t *testing.T) { entries, err := os.ReadDir("testdata") @@ -48,15 +50,18 @@ func TestParse(t *testing.T) { t.Fatalf("failed to parse metadata.json: %v", err) } - // Skip tests marked with todo or invalid_syntax unless running with -run-todo or -only-todo + // Skip tests marked with todo or invalid_syntax unless running with -run-todo, -only-todo, or -check-todo shouldSkip := metadata.Todo || metadata.InvalidSyntax - if shouldSkip && !*runTodoTests && !*onlyTodoTests { + if shouldSkip && !*runTodoTests && !*onlyTodoTests && !*checkTodoTests { t.Skip("skipped via metadata.json (todo or invalid_syntax)") } - if !shouldSkip && *onlyTodoTests { + if !shouldSkip && (*onlyTodoTests || *checkTodoTests) { t.Skip("not a todo/invalid_syntax test") } + // For -check-todo, we need to track if the test passes to update metadata + checkTodoMode := *checkTodoTests && metadata.Todo && !metadata.InvalidSyntax + // Read the test SQL file sqlPath := filepath.Join(testDir, "query.sql") sqlData, err := os.ReadFile(sqlPath) @@ -100,6 +105,16 @@ func TestParse(t *testing.T) { if string(gotNormalized) != string(expectedNormalized) { t.Errorf("JSON mismatch:\ngot:\n%s\n\nexpected:\n%s", gotNormalized, expectedNormalized) } + + // If running with -check-todo and the test passed, update metadata.json to remove todo flag + if checkTodoMode && !t.Failed() { + newMetadata := "{}\n" + if err := os.WriteFile(metadataPath, []byte(newMetadata), 0644); err != nil { + t.Errorf("failed to update metadata.json: %v", err) + } else { + t.Logf("ENABLED: updated %s (removed todo flag)", metadataPath) + } + } }) } } From 1630d616ff6ef5229bedbe6dae7a457f46fb8463 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 31 Dec 2025 14:09:35 +0000 Subject: [PATCH 2/3] Remove -run-todo and -only-todo flags Simplify test flags to just -check-todo which handles the common use case of running todo tests and auto-enabling passing ones. --- CLAUDE.md | 10 ---------- parser/parser_test.go | 14 +++++--------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 7284e3fe..4a7ab24f 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -31,16 +31,6 @@ go test ./parser/... -check-todo -v This runs todo tests and **automatically updates `metadata.json`** for any tests that now pass (removes the `todo: true` flag). Look for "ENABLED:" in the output to see which tests were updated. -To just see which tests pass without updating files: -```bash -go test ./parser/... -only-todo -v 2>&1 | grep "PASS:" -``` - -Available test flags: -- `-check-todo` - Run todo tests and auto-update metadata.json for passing tests -- `-only-todo` - Run only todo/invalid_syntax tests (find newly passing tests) -- `-run-todo` - Run todo/invalid_syntax tests along with normal tests - ## Test Structure Each test in `parser/testdata/` contains: diff --git a/parser/parser_test.go b/parser/parser_test.go index e2d1d926..ba7a59f0 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -15,12 +15,8 @@ type testMetadata struct { InvalidSyntax bool `json:"invalid_syntax"` } -// Test flags for running todo/invalid_syntax tests -// Usage: go test ./parser/... -run-todo # run all tests including todo tests -// Usage: go test ./parser/... -only-todo # run only todo tests (find newly passing tests) +// Test flag for running todo tests and auto-enabling passing ones // Usage: go test ./parser/... -check-todo # run todo tests and auto-update metadata.json for passing tests -var runTodoTests = flag.Bool("run-todo", false, "run todo tests along with normal tests") -var onlyTodoTests = flag.Bool("only-todo", false, "run only todo tests (useful to find tests that now pass)") var checkTodoTests = flag.Bool("check-todo", false, "run todo tests and auto-update metadata.json for passing tests") func TestParse(t *testing.T) { @@ -50,16 +46,16 @@ func TestParse(t *testing.T) { t.Fatalf("failed to parse metadata.json: %v", err) } - // Skip tests marked with todo or invalid_syntax unless running with -run-todo, -only-todo, or -check-todo + // Skip tests marked with todo or invalid_syntax unless running with -check-todo shouldSkip := metadata.Todo || metadata.InvalidSyntax - if shouldSkip && !*runTodoTests && !*onlyTodoTests && !*checkTodoTests { + if shouldSkip && !*checkTodoTests { t.Skip("skipped via metadata.json (todo or invalid_syntax)") } - if !shouldSkip && (*onlyTodoTests || *checkTodoTests) { + if !shouldSkip && *checkTodoTests { t.Skip("not a todo/invalid_syntax test") } - // For -check-todo, we need to track if the test passes to update metadata + // For -check-todo, track if the test passes to update metadata (only for todo, not invalid_syntax) checkTodoMode := *checkTodoTests && metadata.Todo && !metadata.InvalidSyntax // Read the test SQL file From e110b3f5a9e8d89b39b4a9384ee4d89b4c6f7d7e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 31 Dec 2025 14:18:45 +0000 Subject: [PATCH 3/3] Preserve other metadata fields when removing todo flag Use a map to parse and update metadata.json, preserving any extra fields that may exist beyond todo and invalid_syntax. --- parser/parser_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/parser/parser_test.go b/parser/parser_test.go index ba7a59f0..cc9232ae 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -104,11 +104,20 @@ func TestParse(t *testing.T) { // If running with -check-todo and the test passed, update metadata.json to remove todo flag if checkTodoMode && !t.Failed() { - newMetadata := "{}\n" - if err := os.WriteFile(metadataPath, []byte(newMetadata), 0644); err != nil { - t.Errorf("failed to update metadata.json: %v", err) + // Re-parse as map to preserve any extra fields + var metadataMap map[string]any + if err := json.Unmarshal(metadataData, &metadataMap); err != nil { + t.Errorf("failed to parse metadata.json as map: %v", err) } else { - t.Logf("ENABLED: updated %s (removed todo flag)", metadataPath) + delete(metadataMap, "todo") + updatedMetadata, err := json.MarshalIndent(metadataMap, "", " ") + if err != nil { + t.Errorf("failed to marshal metadata: %v", err) + } else if err := os.WriteFile(metadataPath, append(updatedMetadata, '\n'), 0644); err != nil { + t.Errorf("failed to update metadata.json: %v", err) + } else { + t.Logf("ENABLED: updated %s (removed todo flag)", metadataPath) + } } } })