Repository navigation
fix(mcpx/launcher): typo guard scans bodies and knows user-defined names (#1681) #2959
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
Merged
Changes from all commits
Commits
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
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 |
|---|---|---|
|
|
@@ -100,6 +100,121 @@ func TestAMisspelledPlaceholderIsCaughtWithSuggestions(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestAMisspelledUserDefinedPlaceholderIsCaught(t *testing.T) { | ||
| // #1681 BUG-A: the near-miss targets used to be only the built-ins, so | ||
| // a typo of a name the user defined themselves was never flagged. | ||
| _, err := launcher.Expand(tmpl("@bannner"), launcher.Fill{ | ||
| launcher.Entry: "E", "banner": "BANNER;", | ||
| }, launcher.Options{}) | ||
| if err == nil { | ||
| t.Fatal("a near-miss of a user-defined placeholder should be reported") | ||
| } | ||
| if !strings.Contains(err.Error(), "@bannner") || !strings.Contains(err.Error(), "@banner") { | ||
| t.Errorf("the message should name both the typo and the options: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestAMisspellingInsideAFillBodyIsCaught(t *testing.T) { | ||
| // #1681 BUG-B: only the template text used to be scanned, so a typo | ||
| // inside a fill body reached the generated launcher verbatim. | ||
| _, err := launcher.Expand(tmpl("@wrap"), launcher.Fill{ | ||
| launcher.Entry: "RUN();", "wrap": "try { @entyr } catch {}", | ||
| }, launcher.Options{}) | ||
| if err == nil { | ||
| t.Fatal("a near-miss inside a fill body should be reported") | ||
| } | ||
| if !strings.Contains(err.Error(), "@entyr") { | ||
| t.Errorf("the message should name the typo: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestAMisspellingInsideADefinitionBodyIsCaught(t *testing.T) { | ||
| // Definition bodies and their parameter names are user-defined text | ||
| // too: a typo of a parameter inside its own definition is the same | ||
| // failure as one in a fill. | ||
| _, err := launcher.Expand(tmpl("@wrap"), launcher.Fill{ | ||
| launcher.Entry: "RUN();", | ||
| }, launcher.Options{Defs: []launcher.Definition{ | ||
| {Name: "wrap", Params: []string{"message"}, Body: "log(@mesage);"}, | ||
| }}) | ||
| if err == nil { | ||
| t.Fatal("a near-miss of a definition parameter should be reported") | ||
| } | ||
| if !strings.Contains(err.Error(), "@mesage") { | ||
| t.Errorf("the message should name the typo: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestImplicitArgumentPlaceholdersAreNotMisspellings(t *testing.T) { | ||
| // Codex P2 on PR #2959: withArgs binds @args and the positional | ||
| // @1, @2, ... inside a definition body whether or not the | ||
| // declaration named its parameters. A parameter named arg makes | ||
| // @args a near miss, and one named x left @1 flagged, so valid | ||
| // parameterized definitions were refused. | ||
| for _, body := range []string{"run(@args);", "run(@1);"} { | ||
| _, err := launcher.Expand(tmpl("@wrap"), launcher.Fill{ | ||
| launcher.Entry: "RUN();", | ||
| }, launcher.Options{Defs: []launcher.Definition{ | ||
| {Name: "wrap", Params: []string{"arg", "x"}, Body: body}, | ||
| }}) | ||
| if err != nil { | ||
| t.Errorf("body %q should expand: %v", body, err) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestLiteralAtContentInAFillIsNotAMisspelling(t *testing.T) { | ||
| // Codex P2 on PR #2959: fills carry literal @-content -- a scoped | ||
| // package in an import, a quoted script path in the generated | ||
| // header. sentry is one edit from entry and entrypoints starts | ||
| // with entry, so both were refused as misspellings even though | ||
| // the @-names sit inside quoted strings, as data. | ||
| got, err := launcher.Expand(tmpl("@before @header"), launcher.Fill{ | ||
| launcher.Entry: "RUN();", | ||
| launcher.Before: `await import("@sentry/node");`, | ||
| launcher.Header: `const scriptPath = "/work/@entrypoints/foo.ts";`, | ||
| }, launcher.Options{}) | ||
| if err != nil { | ||
| t.Fatalf("literal @-content in fills should not trip the checker: %v", err) | ||
| } | ||
| if !strings.Contains(got, `"@sentry/node"`) || !strings.Contains(got, `@entrypoints/foo.ts`) { | ||
| t.Errorf("the literal content should survive verbatim: %q", got) | ||
| } | ||
| } | ||
|
|
||
| func TestDefinitionParametersDoNotExemptOtherTexts(t *testing.T) { | ||
| // Codex P2 on PR #2959: parameters bind only inside their own | ||
| // definition body. An unused definition declaring an entyr | ||
| // parameter must not silence the typo diagnostic for @entyr in | ||
| // the template itself. | ||
| _, err := launcher.Expand(tmpl("@entyr"), launcher.Fill{ | ||
| launcher.Entry: "RUN();", | ||
| }, launcher.Options{Defs: []launcher.Definition{ | ||
| {Name: "unused", Params: []string{"entyr"}, Body: "noop();"}, | ||
| }}) | ||
| if err == nil { | ||
| t.Fatal("a parameter of an unrelated definition should not exempt a template typo") | ||
| } | ||
| if !strings.Contains(err.Error(), "@entyr") { | ||
| t.Errorf("the message should name the typo: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestAnOrdinaryAtSignInAFillBodyIsLeftAlone(t *testing.T) { | ||
| // Widening the scan to bodies must not widen it past the near-miss | ||
| // bar: generated fills legitimately contain emails and decorators. | ||
| got, err := launcher.Expand(tmpl("@wrap"), launcher.Fill{ | ||
| launcher.Entry: "RUN();", | ||
| "wrap": `const email = "[email protected]"; // @Component({})`, | ||
| }, launcher.Options{}) | ||
| if err != nil { | ||
| t.Fatalf("an ordinary @word in a fill body should not trip the checker: %v", err) | ||
| } | ||
| if !strings.Contains(got, "[email protected]") { | ||
| t.Errorf("the body should survive verbatim: %q", got) | ||
| } | ||
| } | ||
|
|
||
| func TestAnOrdinaryAtSignIsLeftAlone(t *testing.T) { | ||
| // The cost of a false positive is refusing a valid launcher. | ||
| for _, text := range []string{ | ||
|
|
||
Oops, something went wrong.
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.