-
Notifications
You must be signed in to change notification settings - Fork 764
Use go test -json in updateFailing, detect baseline errors
#2347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+114
−24
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f3705f8
Better updateFailing checker
jakebailey c9e6638
Do less in CI
jakebailey b5e386c
Stricter
jakebailey a30c831
Merge branch 'main' into jabaile/fourslash-failing-checker
jakebailey 929fed3
Merge branch 'main' into jabaile/fourslash-failing-checker
jakebailey 3e3d17a
includes
jakebailey 8ea5b68
Remove oops
jakebailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,137 @@ | ||
| import * as cp from "child_process"; | ||
| import * as fs from "fs"; | ||
| import path from "path"; | ||
| import * as readline from "readline"; | ||
| import which from "which"; | ||
|
|
||
| const failingTestsPath = path.join(import.meta.dirname, "failingTests.txt"); | ||
| const crashingTestsPath = path.join(import.meta.dirname, "crashingTests.txt"); | ||
|
|
||
| function main() { | ||
| interface TestEvent { | ||
| Time?: string; | ||
| Action: string; | ||
| Package?: string; | ||
| Test?: string; | ||
| Output?: string; | ||
| Elapsed?: number; | ||
| } | ||
|
|
||
| async function main() { | ||
| const go = which.sync("go"); | ||
| let testOutput: string; | ||
|
|
||
| let testProcess: cp.ChildProcess; | ||
| try { | ||
| // Run tests with TSGO_FOURSLASH_IGNORE_FAILING=1 to run all tests including those in failingTests.txt | ||
| testOutput = cp.execFileSync(go, ["test", "-v", "./internal/fourslash/tests/gen"], { | ||
| encoding: "utf-8", | ||
| testProcess = cp.spawn(go, ["test", "-json", "./internal/fourslash/tests/gen"], { | ||
| stdio: ["ignore", "pipe", "pipe"], | ||
| env: { ...process.env, TSGO_FOURSLASH_IGNORE_FAILING: "1" }, | ||
| }); | ||
| } | ||
| catch (error) { | ||
| testOutput = (error as { stdout: string; }).stdout as string; | ||
| throw new Error("Failed to spawn test process: " + error); | ||
| } | ||
| const panicRegex = /^panic/m; | ||
| if (panicRegex.test(testOutput)) { | ||
| throw new Error("Unrecovered panic detected in tests\n" + testOutput); | ||
|
|
||
| if (!testProcess.stdout || !testProcess.stderr) { | ||
| throw new Error("Test process stdout or stderr is null"); | ||
| } | ||
| const failRegex = /--- FAIL: ([\S]+)/gm; | ||
|
|
||
| const failingTests: string[] = []; | ||
| const crashingRegex = /^=== (?:NAME|CONT) ([\S]+)\n.*InternalError.*$/gm; | ||
| const crashingTests: string[] = []; | ||
| let match; | ||
| const testOutputs = new Map<string, string[]>(); | ||
| const allOutputs: string[] = []; | ||
| let hadPanic = false; | ||
|
|
||
| while ((match = failRegex.exec(testOutput)) !== null) { | ||
| failingTests.push(match[1]); | ||
| } | ||
| while ((match = crashingRegex.exec(testOutput)) !== null) { | ||
| crashingTests.push(match[1]); | ||
| } | ||
| const rl = readline.createInterface({ | ||
| input: testProcess.stdout, | ||
| crlfDelay: Infinity, | ||
| }); | ||
|
|
||
| rl.on("line", line => { | ||
| try { | ||
| const event: TestEvent = JSON.parse(line); | ||
|
|
||
| // Collect output for each test | ||
| if (event.Action === "output" && event.Output) { | ||
| allOutputs.push(event.Output); | ||
| if (event.Test) { | ||
| if (!testOutputs.has(event.Test)) { | ||
| testOutputs.set(event.Test, []); | ||
| } | ||
| testOutputs.get(event.Test)!.push(event.Output); | ||
| } | ||
|
|
||
| // Check for panics | ||
| if (/^panic/m.test(event.Output)) { | ||
| hadPanic = true; | ||
| } | ||
| } | ||
|
|
||
| // Process failed tests | ||
| if (event.Action === "fail" && event.Test) { | ||
| const outputs = testOutputs.get(event.Test) || []; | ||
|
|
||
| fs.writeFileSync(failingTestsPath, failingTests.sort((a, b) => a.localeCompare(b, "en-US")).join("\n") + "\n", "utf-8"); | ||
| fs.writeFileSync(crashingTestsPath, crashingTests.sort((a, b) => a.localeCompare(b, "en-US")).join("\n") + "\n", "utf-8"); | ||
| // Check if this is a crashing test (contains InternalError) | ||
| const hasCrash = outputs.some(line => line.includes("InternalError")); | ||
| if (hasCrash) { | ||
| crashingTests.push(event.Test); | ||
| } | ||
|
|
||
| // A test is only considered a baseline-only failure if ALL error messages | ||
| // are baseline-related. Any non-baseline error message means it's a real failure. | ||
| const baselineMessagePatterns = [ | ||
| /^\s*baseline\.go:\d+: the baseline file .* has changed\./, | ||
| /^\s*baseline\.go:\d+: new baseline created at /, | ||
| /^\s*baseline\.go:\d+: the baseline file .* does not exist in the TypeScript submodule/, | ||
| /^\s*baseline\.go:\d+: the baseline file .* does not match the reference in the TypeScript submodule/, | ||
| ]; | ||
|
|
||
| // Check each output line that looks like an error message | ||
| // Error messages from Go tests typically contain ".go:" with a line number | ||
| const errorLines = outputs.filter(line => /^\s*\w+\.go:\d+:/.test(line)); | ||
|
|
||
| // If there are no error lines, it's a real failure. | ||
| // If all error lines match baseline patterns, it's a baseline-only failure | ||
| const isBaselineOnlyFailure = errorLines.length > 0 && | ||
| errorLines.every(line => baselineMessagePatterns.some(pattern => pattern.test(line))); | ||
|
|
||
| if (!isBaselineOnlyFailure) { | ||
| failingTests.push(event.Test); | ||
| } | ||
| } | ||
| } | ||
| catch (e) { | ||
| // Not JSON, possibly stderr or other output - ignore | ||
| } | ||
| }); | ||
|
|
||
| testProcess.stderr.on("data", data => { | ||
| // Check stderr for panics too | ||
| const output = data.toString(); | ||
| allOutputs.push(output); | ||
| if (/^panic/m.test(output)) { | ||
| hadPanic = true; | ||
| } | ||
| }); | ||
|
|
||
| await new Promise<void>((resolve, reject) => { | ||
| testProcess.on("close", code => { | ||
| if (hadPanic) { | ||
| reject(new Error("Unrecovered panic detected in tests\n" + allOutputs.join(""))); | ||
| return; | ||
| } | ||
|
|
||
| fs.writeFileSync(failingTestsPath, failingTests.sort((a, b) => a.localeCompare(b, "en-US")).join("\n") + "\n", "utf-8"); | ||
| fs.writeFileSync(crashingTestsPath, crashingTests.sort((a, b) => a.localeCompare(b, "en-US")).join("\n") + "\n", "utf-8"); | ||
| resolve(); | ||
| }); | ||
|
|
||
| testProcess.on("error", error => { | ||
| reject(error); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| main(); | ||
| main().catch(error => { | ||
| console.error("Error:", error); | ||
| process.exit(1); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.