-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
don't try and use jsonschema for this
Jsonschema is a lot of things but one thing it isn't is a definer of schema behavior based on values in the document. That's the key to all of this - the document specifying a subschema for part of its content - so we're just going to do it in code instead. That means - In the protocol schema, dynamically subschema'd objects get typed as objects - We get a new typescript validator to handle it all - Also update python for this but it matters a bit less because the python defines what is acceptable anyway, so there's no point trying to be future proof here when downstream consumers will have to change
- Loading branch information
Showing
13 changed files
with
535 additions
and
91 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
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,85 @@ | ||
/** Ensure that we can parse all our fixture json protocols, which also | ||
Check failure on line 1 in shared-data/js/__tests__/protocolValidation.test.ts GitHub Actions / js checks
|
||
* ensures that our protocol schemas are correct*/ | ||
import path from 'path' | ||
import glob from 'glob' | ||
import { validate } from '../protocols' | ||
import { omit } from 'lodash' | ||
|
||
import type * as ProtocolSchemas from '../../protocol' | ||
Check failure on line 8 in shared-data/js/__tests__/protocolValidation.test.ts GitHub Actions / js checks
|
||
|
||
const relRoot = path.join(__dirname, '../../protocol/fixtures/') | ||
|
||
const protocolFixtures4 = glob.sync( | ||
path.join(__dirname, '../../protocol/fixtures/4/*.json') | ||
) | ||
const protocolFixtures5 = glob.sync( | ||
path.join(__dirname, '../../protocol/fixtures/5/*.json') | ||
) | ||
const protocolFixtures6 = glob.sync( | ||
path.join(__dirname, '../../protocol/fixtures/6/*.json') | ||
) | ||
const protocolFixtures7 = glob.sync( | ||
path.join(__dirname, '../../protocol/fixtures/7/*.json') | ||
) | ||
const protocolFixtures8 = glob.sync( | ||
path.join(__dirname, '../../protocol/fixtures/8/*.json') | ||
) | ||
|
||
describe('check that all fixtures can validate', () => { | ||
const protocolPaths = [ | ||
...protocolFixtures4, | ||
...protocolFixtures5, | ||
...protocolFixtures6, | ||
...protocolFixtures7, | ||
...protocolFixtures8, | ||
] | ||
protocolPaths.forEach(protocolPath => | ||
it(`${path.relative(relRoot, protocolPath)}`, () => { | ||
const protocol = require(protocolPath) | ||
return validate(protocol) | ||
}) | ||
) | ||
}) | ||
|
||
describe('test that mutating v8 fixtures causes failure', () => { | ||
const base = require('../../protocol/fixtures/8/simpleV8.json') | ||
it('should fail validation with no schema spec', () => { | ||
const mangled = omit(base, '$otSharedSchema') | ||
expect.assertions(1) | ||
return expect(validate(mangled)).rejects.toMatchObject([ | ||
{ keyword: 'Invalid protocol schema requested' }, | ||
]) | ||
}) | ||
it('should fail validation with a schema spec from the future', () => { | ||
const mangled = { ...base, $otSharedSchema: 'opentronsProtocolSchemaV9' } | ||
expect.assertions(1) | ||
return expect(validate(mangled)).rejects.toMatchObject([ | ||
{ keyword: 'Invalid protocol schema requested' }, | ||
]) | ||
}) | ||
it('should fail validation with a mangled schema spec', () => { | ||
const mangled = { ...base, $otSharedSchema: 'asdhasda' } | ||
expect.assertions(1) | ||
return expect(validate(mangled)).rejects.toMatchObject([ | ||
{ keyword: 'Invalid protocol schema requested' }, | ||
]) | ||
}) | ||
it('should fail validation with a mangled command schema spec', () => { | ||
const mangled = { ...base, commandSchemaId: 'asdasd' } | ||
return expect(validate(mangled)).rejects.toMatchObject([ | ||
{ keyword: 'Invalid command schema requested' }, | ||
]) | ||
}) | ||
it('should fail validation with a mangled liquid schema spec', () => { | ||
const mangled = { ...base, liquidSchemaId: 'asdhasdas' } | ||
return expect(validate(mangled)).rejects.toMatchObject([ | ||
{ keyword: 'Invalid liquid schema requested' }, | ||
]) | ||
}) | ||
it('should fail validation with a mangled command annotation schema spec', () => { | ||
const mangled = { ...base, commandAnnotationSchemaId: 'asdasd' } | ||
return expect(validate(mangled)).rejects.toMatchObject([ | ||
{ keyword: 'Invalid command annotation schema requested' }, | ||
]) | ||
}) | ||
}) |
Oops, something went wrong.