-
Notifications
You must be signed in to change notification settings - Fork 275
feat(core): add an overridable seam for completed schema validation #1491
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
+507
−30
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,66 @@ | ||
| """Overridable seam for observing authoritative schema validation. | ||
|
|
||
| Validation is the only place that knows whether a note actually satisfies its | ||
| schema: nothing on the write path runs it, and no validation state is stored on | ||
| the entity. A deployment that needs to react to a validation result -- a hosted | ||
| one recording that a user structured a note successfully, say -- would otherwise | ||
| have to re-run validation itself and own a copy of this module's schema | ||
| resolution, which would then drift from the answer the API returns. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Sequence | ||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass(frozen=True, slots=True) | ||
| class ValidatedNoteOutcome: | ||
| """One note's validation result, reduced to identity and pass state. | ||
|
|
||
| Deliberately narrower than `NoteValidationResponse`: it carries no field | ||
| names, values, warnings or error text, so an observer cannot come to depend | ||
| on note content, and the note is named by its external id rather than by a | ||
| title. What is left is what an observer can legitimately act on -- which | ||
| schema, and whether the note satisfied it. | ||
|
|
||
| The two schema fields answer different questions and neither replaces the | ||
| other. `schema_entity` is the note type the schema covers, read from the | ||
| schema's own `entity:` frontmatter, so two schema notes that both cover | ||
| `person` report the same value. `schema_reference` is what the validated | ||
| note pointed at -- the string in its `schema:` frontmatter -- and is None | ||
| when the schema was declared inline and there was nothing to point at. An | ||
| observer that needs to tell two schemas for one entity apart needs the | ||
| reference; it is the reference as written and matched, not a stable id. | ||
| """ | ||
|
|
||
| note_external_id: str | ||
| schema_entity: str | ||
| schema_reference: str | None | ||
| passed: bool | ||
|
|
||
|
|
||
| class SchemaValidationObserver: | ||
| """Observes completed schema validations. A no-op in core.""" | ||
|
|
||
| async def on_notes_validated( | ||
| self, | ||
| *, | ||
| project_external_id: str, | ||
| outcomes: Sequence[ValidatedNoteOutcome], | ||
| ) -> None: | ||
| """React to a finished validation, after its report is complete. | ||
|
|
||
| Called once per request with every note the request actually validated, | ||
| which is not every note it looked at: entities whose frontmatter | ||
| resolves to no schema are skipped, exactly as they are skipped in the | ||
| report. | ||
|
|
||
| Unlike `NoteContentMutationService.on_accepted_mutation`, this runs | ||
| outside any transaction and has nothing to make atomic -- validation | ||
| reads. An implementation is therefore responsible for its own durability | ||
| and its own failures: raising here fails the caller's validation | ||
| request, which is virtually never the right trade for bookkeeping that | ||
| the user did not ask for. | ||
| """ | ||
| return None |
Oops, something went wrong.
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.