File tree Expand file tree Collapse file tree 2 files changed +66
-0
lines changed
packages/jentic-openapi-validator-speclynx/tests Expand file tree Collapse file tree 2 files changed +66
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Test plugin that verifies parseResult is available in the toolbox.
3+ *
4+ * This plugin emits a diagnostic if parseResult is missing or doesn't contain
5+ * expected properties, helping catch regressions in toolbox wiring.
6+ */
7+
8+ export default ( toolbox ) => {
9+ const { diagnostics, deps, parseResult} = toolbox ;
10+ const { DiagnosticSeverity} = deps [ 'vscode-languageserver-types' ] ;
11+
12+ return {
13+ visitor : {
14+ InfoElement ( ) {
15+ // Verify parseResult is available
16+ if ( ! parseResult ) {
17+ diagnostics . push ( {
18+ severity : DiagnosticSeverity . Error ,
19+ message : 'toolbox.parseResult is missing' ,
20+ code : 'missing-parseresult' ,
21+ range : {
22+ start : { line : 0 , character : 0 } ,
23+ end : { line : 0 , character : 0 }
24+ } ,
25+ data : { path : [ ] }
26+ } ) ;
27+ return ;
28+ }
29+
30+ // For valid OpenAPI 3.x documents, parseResult.api should exist
31+ if ( parseResult . api ) {
32+ diagnostics . push ( {
33+ severity : DiagnosticSeverity . Information ,
34+ message : 'parseResult.api is available' ,
35+ code : 'parseresult-api-available' ,
36+ range : {
37+ start : { line : 0 , character : 0 } ,
38+ end : { line : 0 , character : 0 }
39+ } ,
40+ data : { path : [ ] }
41+ } ) ;
42+ }
43+ }
44+ }
45+ } ;
46+ } ;
Original file line number Diff line number Diff line change @@ -123,6 +123,26 @@ def test_both_default_and_custom_plugins_produce_diagnostics(
123123 # Custom plugin should detect integer version
124124 assert any ("version" in d .message .lower () for d in result .diagnostics )
125125
126+ def test_parseresult_available_in_toolbox (self , speclynx_validator_with_plugins ):
127+ """Test that parseResult is available to plugins via toolbox.
128+
129+ The parseresult-check.mjs plugin emits an informational diagnostic
130+ when parseResult.api is available, verifying the toolbox wiring.
131+ """
132+ document = {
133+ "openapi" : "3.0.0" ,
134+ "info" : {"title" : "Test API" , "version" : "1.0.0" },
135+ "paths" : {},
136+ }
137+ result = speclynx_validator_with_plugins .validate (document )
138+ assert result .valid is True
139+ # The parseresult-check plugin should emit info diagnostic confirming parseResult.api exists
140+ parseresult_diagnostic = next (
141+ (d for d in result .diagnostics if d .code == "parseresult-api-available" ), None
142+ )
143+ assert parseresult_diagnostic is not None , "parseResult should be available to plugins"
144+ assert "parseResult.api is available" in parseresult_diagnostic .message
145+
126146 def test_validate_empty_document_produces_error (self , speclynx_validator , tmp_path ):
127147 """Test that empty documents produce validation errors.
128148
You can’t perform that action at this time.
0 commit comments