-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Report schema source in validation output #269
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
Draft
yarikoptic
wants to merge
9
commits into
bids-standard:main
Choose a base branch
from
yarikoptic:enh-schema-uri
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.
Draft
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5810730
feat: Report schema source in validation output
yarikoptic abecd73
refactor: Maintain backward compatibility for loadSchema
yarikoptic 1e251a7
docs: Add changelog entry for schema source reporting
yarikoptic 916fccc
test: Add comprehensive tests for schemaSource reporting
yarikoptic b9cb09a
Merge branch 'main' into enh-schema-uri
effigies 2d39a99
Two suggestions from review to reflect changes in main and optimize TS
yarikoptic fb22b2f
test: Update tests to handle error-throwing schema loader
yarikoptic 5e1e2c9
test: Fix CI test failures for schema error handling
yarikoptic 7c92504
Merge branch 'main' into enh-schema-uri
effigies 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,10 @@ | ||
<!-- | ||
A new scriv changelog fragment. | ||
|
||
Uncomment the section that is right (remove the HTML comment wrapper). | ||
For top level release notes, leave all the headers commented out. | ||
--> | ||
|
||
### Added | ||
|
||
- Schema source reporting in validation output. The validator now includes `schemaSource` field in JSON output and displays schema information (version and source) in console output, helping users understand which schema was used for validation (URL, file path, or version tag). |
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 |
---|---|---|
@@ -1,36 +1,48 @@ | ||
import { assert, assertObjectMatch } from '@std/assert' | ||
import { loadSchema } from './loadSchema.ts' | ||
import { assertEquals, assert } from '@std/assert' | ||
import { loadSchemaWithSource, loadSchema } from './loadSchema.ts' | ||
|
||
Deno.test('schema loader', async (t) => { | ||
await t.step('reads in top level files document', async () => { | ||
const schemaDefs = await loadSchema() | ||
// Look for some stable fields in top level files | ||
if ( | ||
typeof schemaDefs.rules.files.common === 'object' && | ||
schemaDefs.rules.files.common.core !== null | ||
) { | ||
const top_level = schemaDefs.rules.files.common.core as Record< | ||
string, | ||
any | ||
> | ||
if (top_level.hasOwnProperty('README')) { | ||
assertObjectMatch(top_level.README, { | ||
level: 'recommended', | ||
stem: 'README', | ||
extensions: ['', '.md', '.rst', '.txt'], | ||
}) | ||
} | ||
} else { | ||
assert(false, 'failed to test schema defs') | ||
} | ||
Deno.test('loadSchemaWithSource function', async (t) => { | ||
await t.step('loadSchema returns just Schema for backward compatibility', async () => { | ||
const schema = await loadSchema() | ||
assert(schema.schema_version) | ||
assert(!('source' in schema)) | ||
}) | ||
await t.step('loads all schema files', async () => { | ||
const schemaDefs = await loadSchema() | ||
if ( | ||
!(typeof schemaDefs.objects === 'object') || | ||
!(typeof schemaDefs.rules === 'object') | ||
) { | ||
assert(false, 'failed to load objects/rules') | ||
|
||
await t.step('loadSchemaWithSource returns SchemaWithSource', async () => { | ||
const result = await loadSchemaWithSource() | ||
assert(result.schema) | ||
assert(result.schema.schema_version) | ||
// When no custom schema is provided, source should be undefined | ||
assertEquals(result.source, undefined) | ||
}) | ||
|
||
await t.step('loadSchemaWithSource tracks source when custom URL provided', async () => { | ||
// This test validates the structure even though network fetch will fail | ||
const customUrl = 'https://example.com/custom-schema.json' | ||
const result = await loadSchemaWithSource(customUrl) | ||
assert(result.schema) | ||
assert(result.schema.schema_version) | ||
// Since network fetch fails, it falls back to default schema and source is undefined | ||
assertEquals(result.source, undefined) | ||
}) | ||
|
||
await t.step('loadSchemaWithSource handles environment variable', async () => { | ||
const originalEnv = Deno.env.get('BIDS_SCHEMA') | ||
try { | ||
const customUrl = 'https://env-schema.example.com/schema.json' | ||
Deno.env.set('BIDS_SCHEMA', customUrl) | ||
|
||
const result = await loadSchemaWithSource() | ||
assert(result.schema) | ||
assert(result.schema.schema_version) | ||
// Since network fetch fails, source should be undefined | ||
assertEquals(result.source, undefined) | ||
} finally { | ||
if (originalEnv !== undefined) { | ||
Deno.env.set('BIDS_SCHEMA', originalEnv) | ||
} else { | ||
Deno.env.delete('BIDS_SCHEMA') | ||
} | ||
} | ||
}) | ||
}) | ||
}) |
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
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
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.