-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Turn on strict checks when parsing action schema (#562)
We already have strict checks on cached schemas. Turns it on when we first parse as well to have consistent behavior between parsing and loading from cache. Improve error message for entry comment error. Added test for some of the error conditions.
- Loading branch information
Showing
6 changed files
with
80 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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,66 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { parseActionSchemaSource } from "../src/parser.js"; | ||
|
||
describe("Action Schema Strict Checks", () => { | ||
it("Error on entry type not exported", async () => | ||
expect(async () => | ||
parseActionSchemaSource( | ||
`type SomeAction = { actionName: "someAction" }`, | ||
"test", | ||
"", | ||
"SomeAction", | ||
"", | ||
undefined, | ||
true, | ||
), | ||
).rejects.toThrow( | ||
"Error parsing test: Schema Error: test: Type 'SomeAction' must be exported", | ||
)); | ||
|
||
it("Error on entry type comment", async () => | ||
expect(async () => | ||
parseActionSchemaSource( | ||
`// comments\nexport type AllActions = SomeAction;\ntype SomeAction = { actionName: "someAction" }`, | ||
"test", | ||
"", | ||
"AllActions", | ||
"", | ||
undefined, | ||
true, | ||
), | ||
).rejects.toThrow( | ||
"Error parsing test: Schema Error: test: entry type comments for 'AllActions' are not used for prompts. Remove from the action schema file.", | ||
)); | ||
|
||
it("Error on duplicate action name", async () => | ||
expect(async () => | ||
parseActionSchemaSource( | ||
`export type AllActions = SomeAction | SomeAction2;\ntype SomeAction = { actionName: "someAction" }\ntype SomeAction2 = { actionName: "someAction" }`, | ||
"test", | ||
"", | ||
"AllActions", | ||
"", | ||
undefined, | ||
true, | ||
), | ||
).rejects.toThrow( | ||
"Error parsing test: Schema Error: test: Duplicate action name 'someAction'", | ||
)); | ||
|
||
it("Error on anonymous types", async () => | ||
expect(async () => | ||
parseActionSchemaSource( | ||
`export type AllActions = SomeAction | { actionName: "someAction2" };\ntype SomeAction = { actionName: "someAction" }`, | ||
"test", | ||
"", | ||
"AllActions", | ||
"", | ||
undefined, | ||
true, | ||
), | ||
).rejects.toThrow( | ||
"Error parsing test: Schema Error: test: expected type reference in the entry type union", | ||
)); | ||
}); |
This file contains 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 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 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 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