Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ platforms: "SQL Server, Azure SQL DB, Fabric, Fabric DW, VNext"

This skill helps add new T-SQL features to the ScriptDOM parser by:
1. **Interviewing** you about the feature and target platform (SQL Server, Azure SQL DB, Fabric, Fabric DW, VNext)
2. **Determining the latest parser version** from `SqlVersionFlags.cs` (currently TSql170)
2. **Determining the latest parser version** from `SqlVersionFlags.cs`
3. **Routing** you to the appropriate parser:
- SQL Server → version-specific parser (TSql120-170)
- SQL Server → version-specific parser (TSql120-180)
- Azure SQL DB/Fabric/VNext → latest parser version
- Fabric DW → separate TSqlFabricDW parser
4. **Classifying** the change type (grammar, validation, function, data type, etc.)
Expand All @@ -33,7 +33,7 @@ Ask the user these questions to understand the feature:
- **Azure SQL Database** (uses latest parser version)
- **Fabric** (uses latest parser version)
- **Fabric DW** (uses separate TSqlFabricDW parser)
- **VNext** (future version, uses latest parser version)
- **VNext** (future version, uses latest parser version unless repo instructions say otherwise)

3. **If SQL Server, which version introduced this feature?**
- SQL Server 2014 (TSql120)
Expand All @@ -42,7 +42,8 @@ Ask the user these questions to understand the feature:
- SQL Server 2019 (TSql150)
- SQL Server 2022 (TSql160)
- SQL Server 2025 (TSql170)
- *(Skip if Azure SQL DB, Fabric, or VNext - these use latest version)*
- SQL Server vNext (TSql180)
- *(Skip if Azure SQL DB, Fabric, or VNext - these use TSql180 by default)*

4. **Do you have example T-SQL syntax or Microsoft documentation links?**
- This helps verify the exact syntax requirements
Expand Down Expand Up @@ -124,7 +125,7 @@ For grammar changes (Types B, C, D, E, G), follow this workflow:
### 3.1 Identify Target Grammar File

**First, determine the latest parser version:**
Check `SqlScriptDom/Parser/TSql/SqlVersionFlags.cs` for the highest TSql version enum value (currently TSql170).
Check `SqlScriptDom/Parser/TSql/SqlVersionFlags.cs` for the highest TSql version enum value.

**Then select the appropriate grammar file:**

Expand All @@ -135,9 +136,10 @@ Check `SqlScriptDom/Parser/TSql/SqlVersionFlags.cs` for the highest TSql version
- SQL 2019+: TSql150.g
- SQL 2022+: TSql160.g
- SQL 2025+: TSql170.g
- SQL Server vNext: TSql180.g

#### For Azure SQL Database, Fabric, VNext:
- Use the **latest parser version** (e.g., TSql170.g)
- Use the **latest parser version** (currently TSql180.g)
- Check `SqlVersionFlags.cs` to confirm the highest version

#### For Fabric DW:
Expand Down Expand Up @@ -174,7 +176,7 @@ If adding new AST nodes:

### 4.2 Add Test Method

#### For SQL Server versions (TSql120-170):
#### For SQL Server versions (TSql120-180):
In `Test/SqlDom/Only<version>SyntaxTests.cs`:

```csharp
Expand All @@ -191,8 +193,8 @@ Add to the `OnlyFabricDWTestInfos` array in `Test/SqlDom/OnlyFabricDWSyntaxTests
```csharp
new ParserTestFabricDW("YourFeatureFabricDW.sql",
nErrors80: X, nErrors90: Y, nErrors100: Z,
nErrors110: A, nErrors120: B, nErrors130: C,
nErrors140: D, nErrors150: E, nErrors160: F, nErrors170: G),
nErrors110: A, nErrors120: B, nErrors130: C,
nErrors140: D, nErrors150: E, nErrors160: F, nErrors170: G, nErrors180: H),
```
*(Set expected error counts for each parser version)*

Expand Down
115 changes: 115 additions & 0 deletions .agents/skills/verify-and-test-tsql-syntax/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
name: verify-and-test-tsql-syntax
description: Verify whether an exact T-SQL script is already supported by SqlScriptDOM, then add or update the correct parser tests and baselines. Use when a user asks if syntax already works, or when adding regression coverage for a specific script.
argument-hint: "Exact T-SQL script or syntax to verify"
user-invocable: true
---

## Overview

This skill determines whether a specific T-SQL script is already supported and then guides the follow-up testing work.

Use it for:
- verifying whether a script already parses
- confirming which parser version should support the syntax
- adding or updating regression coverage in the existing ScriptDOM test framework

Do not use it for broad feature design. If the verification shows missing parser support, route the implementation work to the appropriate repo instruction:
- [bug_fixing.guidelines.instructions.md](../../../.github/instructions/bug_fixing.guidelines.instructions.md)
- [grammar_validation.guidelines.instructions.md](../../../.github/instructions/grammar_validation.guidelines.instructions.md)
- [parser.guidelines.instructions.md](../../../.github/instructions/parser.guidelines.instructions.md)
- [testing.guidelines.instructions.md](../../../.github/instructions/testing.guidelines.instructions.md)

## Core Rules

- Always verify the exact T-SQL text first, character for character.
- For first-pass verification, add a debug unit test method to an existing test file such as `Only180SyntaxTests.cs` when the syntax targets vNext or the latest parser.
- Do not create standalone console apps, ad hoc parsers, or extra test projects.
- After verification, add proper test coverage through `TestScripts`, baselines, and the existing syntax test classes.
- Remove any temporary debug-only test methods once the result is confirmed.

## Workflow

### 1. Gather the minimum inputs

Ask for:
- the exact T-SQL script to verify
- the SQL Server version or parser version expected to support it
- the current behavior and the expected behavior

If the user has not supplied the exact script yet, stop and request it before continuing.

### 2. Verify the exact script first

Add a temporary debug unit test method to the appropriate existing test class and test the exact script as provided.

Use this sequence:

```bash
dotnet build SqlScriptDom/Microsoft.SqlServer.TransactSql.ScriptDom.csproj -c Debug
dotnet test --filter "DebugExactScriptTest" Test/SqlDom/UTSqlScriptDom.csproj -c Debug
```

Verification expectations:
- If parsing succeeds, move directly to comprehensive test coverage.
- If parsing fails, capture the exact parse errors and classify the failure.

### 3. Classify the gap if verification fails

Use the failure mode to route the next step:
- Grammar issue: parser does not recognize the syntax at all.
- Validation issue: syntax parses but is rejected as unsupported or invalid in context.
- Predicate recognition issue: identifier-based predicate fails in parentheses.

When similar syntax already works in another context, prefer validation analysis before changing grammar.

### 4. Add comprehensive coverage

After verification, create or update the proper permanent tests using the existing framework:

- Add the input script under `Test/SqlDom/TestScripts/`.
- Add the matching baseline under `Test/SqlDom/Baselines<version>/`.
- Add the `ParserTest` entry or permanent test method in the correct `Only<version>SyntaxTests.cs` file.
- Preserve the exact user syntax in the test script before adding broader coverage.

Determine the parser version using the repo mapping:
- SQL Server 2014 -> TSql120
- SQL Server 2016 -> TSql130
- SQL Server 2017 -> TSql140
- SQL Server 2019 -> TSql150
- SQL Server 2022 -> TSql160
- SQL Server 2025 -> TSql170
- SQL Server vNext/latest -> TSql180

### 5. Validate the testing slice

Run validation in this order:

```bash
dotnet test --filter "FullyQualifiedName~YourFeatureTest" Test/SqlDom/UTSqlScriptDom.csproj -c Debug
dotnet test Test/SqlDom/UTSqlScriptDom.csproj -c Debug
```

If the targeted test fails because of a baseline mismatch:
- use the generated output from the failure log to update the baseline
- rerun the same targeted test
- only then run the full suite

## File Targets

Use these repo paths when doing the work:
- Grammar files: `SqlScriptDom/Parser/TSql/TSql*.g`
- AST definition: `SqlScriptDom/Parser/TSql/Ast.xml`
- Validation code: `SqlScriptDom/Parser/TSql/TSql80ParserBaseInternal.cs`
- Test scripts: `Test/SqlDom/TestScripts/`
- Baselines: `Test/SqlDom/Baselines<version>/`
- Syntax tests: `Test/SqlDom/Only<version>SyntaxTests.cs`

## Completion Checklist

- [ ] Verified the exact script first in an existing test file
- [ ] Classified the result as already supported or missing support
- [ ] Added or updated permanent test coverage in the standard test framework
- [ ] Preserved the exact user syntax in the new test script
- [ ] Ran targeted validation for the touched test slice
- [ ] Ran the full `UTSqlScriptDom` suite before finishing
Loading
Loading