-
Notifications
You must be signed in to change notification settings - Fork 170
Add testing harness for grammar #570
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
Open
dncrews
wants to merge
6
commits into
github:main
Choose a base branch
from
dncrews:feat/grammar-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
778b260
Add syntax for if-expression blocks
cdce8p cb13d23
Create unified expression syntax pattern
cdce8p 0e62ee5
Add patterns for logical and comparison operators
cdce8p 809e22f
Allow inline expressions to span multiple lines
cdce8p d43c37c
Add testing harness for grammar
dncrews cfd9be2
Fix the bullet numbering
dncrews 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Language Grammars And Syntax Tests | ||
|
|
||
| Workflow grammar assets live in `language/syntaxes/`. | ||
|
|
||
| For syntax-highlighting triage guidance and fixture-based regression test patterns, see: | ||
|
|
||
| - `src/workflow/syntax/README.md` |
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
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 |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # Workflow Syntax Highlighting Triage & Tests | ||
|
|
||
| This note documents a lightweight process for triaging syntax-highlighting bugs in workflow files and turning them into fixture-based regression tests. | ||
|
|
||
| ## What this covers | ||
|
|
||
| This is for **TextMate grammar / tokenization** issues in: | ||
|
|
||
| - `language/syntaxes/yaml.tmLanguage.json` | ||
| - `language/syntaxes/expressions.tmGrammar.json` | ||
| - workflow syntax injection grammars (for embedded languages) | ||
|
|
||
| This is **not** the right path for: | ||
|
|
||
| - parser/validation diagnostics from language services | ||
| - schema/completion issues | ||
| - runtime extension behavior | ||
|
|
||
| ## Triage checklist (quick) | ||
|
|
||
| 1. Reproduce in `GitHub Actions Workflow` language mode. | ||
| 2. Run `Developer: Inspect Editor Tokens and Scopes`. | ||
| 3. Check whether the bug is: | ||
| - wrong token scopes/colors (grammar bug) | ||
| - a diagnostic/problem message (language service/parser bug) | ||
| 4. Identify likely grammar file: | ||
| - inline `${{ }}` / `if:` expression behavior: `language/syntaxes/expressions.tmGrammar.json` | ||
| - general YAML tokenization/comments/keys/scalars: `language/syntaxes/yaml.tmLanguage.json` | ||
| - embedded JS/shell/etc: injection grammar(s) | ||
| 5. Add a fixture and a focused regression test before patching. | ||
|
|
||
| ## What to ask for in a bug report | ||
|
|
||
| If the issue is syntax highlighting, ask for: | ||
|
|
||
| - a minimal workflow snippet (`.yml`) | ||
| - exact line/token that looks wrong | ||
| - screenshot (optional but helpful) | ||
| - token inspector output for the wrong token (`textmate scopes`) | ||
| - expected behavior (what scope/color should have happened) | ||
|
|
||
| Ideally, contributors can include a minimal repro snippet that can be copied directly into a fixture file. | ||
|
|
||
| ## Current test utilities | ||
|
|
||
| Shared helpers live in: | ||
|
|
||
| - `src/workflow/syntax/syntax-test-utils.ts` | ||
|
|
||
| Current tests live in: | ||
|
|
||
| - `src/workflow/syntax/*.test.ts` | ||
|
|
||
| Current fixture files live in: | ||
|
|
||
| - `src/workflow/syntax/fixtures/` | ||
|
|
||
| The helpers are intentionally lightweight and focus on grammar-regression behavior (not VS Code integration tests). | ||
|
|
||
| ## Which helper to use | ||
|
|
||
| - `readJson(relativePath)` | ||
| - Use to load grammar JSON files from `language/syntaxes/`. | ||
| - `readFixture(relativePath)` | ||
| - Use to load YAML fixture files from `src/workflow/syntax/fixtures/`. | ||
| - `analyzeSingleOuterEmbeddedBlockFixture(...)` | ||
| - Use when grammar has one outer context and one embedded block rule inside it (for example `github-script` + `with.script`). | ||
| - `analyzeTopLevelInjectionContexts(...)` | ||
| - Use when grammar has multiple top-level included contexts (for example `run` + `shell` per-shell contexts). | ||
| - `findGithubActionsInlineExpression(line)` | ||
| - Use in expression-regression tests that need to ensure `${{ ... }}` does not terminate on `}}` inside quoted strings (for example `#223`). | ||
|
|
||
| ## Fixture naming | ||
|
|
||
| Use behavior-based, kebab-case fixture names: | ||
|
|
||
| - format: `<behavior>.yml` | ||
| - examples: | ||
| - `if-comment-after-string.yml` | ||
| - `expression-nested-braces.yml` | ||
| - `run-shell-embedded.yml` | ||
|
|
||
| Avoid issue-number-only names in fixture filenames. Issue references should live in test comments or fixture comments. | ||
|
|
||
| ## Adding a new grammar regression test | ||
|
|
||
| 1. Add a minimal fixture file under `src/workflow/syntax/fixtures/` | ||
| 2. Add/extend a Jest test in `src/workflow/syntax/*.test.ts` | ||
| 3. Keep assertions narrow (what should be embedded, what should not be consumed, header/body boundaries, etc.) | ||
| 4. Run `npm test` | ||
|
|
||
| ## Example: `#531`-style triage (inline comment after `if:`) | ||
|
|
||
| Issue type: | ||
|
|
||
| - likely grammar tokenization bug in `language/syntaxes/expressions.tmGrammar.json` | ||
| - symptom: `if: ... 'string' # comment` does not highlight the comment as a YAML comment | ||
|
|
||
| Suggested test plan: | ||
|
|
||
| 1. Add a fixture with lines like: | ||
|
|
||
| ```yaml | ||
| jobs: | ||
| test: | ||
| if: matrix.os != 'macos-latest' # Cache causes errors on macOS | ||
| ``` | ||
|
|
||
| 2. Add a focused test for the `if-expression` rule behavior in `expressions.tmGrammar.json` | ||
| 3. Verify the expression matcher does not swallow the trailing comment, while preserving `#` inside quoted strings | ||
|
|
||
| Note: | ||
|
|
||
| - This kind of issue may need a new small helper in `syntax-test-utils.ts` for line/capture-level grammar matching, in addition to the embedded-block helpers already present. | ||
|
|
||
| ## Proposed pattern for community-submitted failing tests | ||
|
|
||
| For syntax-highlighting bugs in this area, contributors can submit: | ||
|
|
||
| 1. A fixture file in `src/workflow/syntax/fixtures/` | ||
| 2. A failing Jest assertion in `src/workflow/syntax/*.test.ts` | ||
| 3. A short comment linking the issue number and describing the expected scopes/behavior | ||
|
|
||
| That gives maintainers a reproducible regression case even before a fix is implemented. |
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.