Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
conformance wip
Browse files Browse the repository at this point in the history
  • Loading branch information
leordev committed Sep 19, 2024
1 parent 4d482ad commit 8de42d2
Show file tree
Hide file tree
Showing 13 changed files with 2,084 additions and 89 deletions.
1,128 changes: 1,127 additions & 1 deletion .github/actions/specs-report/README.md

Large diffs are not rendered by default.

107 changes: 101 additions & 6 deletions .github/actions/specs-report/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import * as main from '../src/main'
import * as files from '../src/files'
import * as prComment from '../src/pr-comment'
import * as junit2json from 'junit2json'
import { TBDEX_TEST_VECTORS_FILES, SUCCESS_MOCK, FAILURE_MOCK } from './mocks'
import {
TBDEX_TEST_VECTORS_FILES,
SUCCESS_MOCK,
FAILURE_MOCK,
WEB5_TEST_VECTORS_FILES,
WEB5_TEST_VECTORS_FEATURES
} from './mocks'

// Mock the action's main function
const runMock = jest.spyOn(main, 'run')
Expand All @@ -29,19 +35,49 @@ let readJsonFileMock: jest.SpiedFunction<typeof files.readJsonFile>
let junitParseMock: jest.SpiedFunction<typeof junit2json.parse>
let addCommentToPrMock: jest.SpiedFunction<typeof prComment.addCommentToPr>

const defaultGetInputMockImplementation = (): void => {
// Mock Octokit
const mockOctokit = {
rest: {
repos: {
createOrUpdateFileContents: jest.fn()
}
}
}

// Mock fetch
const mockFetch = jest.fn()
global.fetch = mockFetch

jest.mock('@actions/github', () => ({
getOctokit: jest.fn().mockImplementation(() => mockOctokit),
context: {
eventName: 'pull_request',
payload: { pull_request: { number: 123 } },
repo: { owner: 'test-owner', repo: 'test-repo' }
}
}))

const defaultGetInputMockImplementation = (
releaseMode?: 'spec' | 'sdk',
releaseParams?: {
releaseRepo?: string
releaseTag?: string
specName?: string
specTag?: string
}
): void => {
getInputMock.mockImplementation(name => {
switch (name) {
case 'junit-report-paths':
return '500'
return './whatever'
case 'suite-name-regex':
return 'TbdexTestVector' // or 'Web5TestVector' for Web5
case 'feature-regex':
return 'TbdexTestVectors(\\w+)'
case 'vector-regex':
return 'TbdexTestVectors(\\w+) (\\w+)'
case 'spec-path':
return '500'
return './whatever'
case 'git-token':
return 'fake-token'
case 'comment-on-pr':
Expand All @@ -50,6 +86,16 @@ const defaultGetInputMockImplementation = (): void => {
return 'false'
case 'fail-on-failed-test-cases':
return 'true'
case 'release-mode':
return releaseMode || ''
case 'release-repo':
return releaseParams?.releaseRepo || ''
case 'release-tag':
return releaseParams?.releaseTag || ''
case 'spec-name':
return releaseParams?.specName || ''
case 'spec-tag':
return releaseParams?.specTag || ''
default:
return ''
}
Expand Down Expand Up @@ -79,6 +125,7 @@ describe('action', () => {

getFilesMock = jest.spyOn(files, 'getFiles').mockImplementation()
readJsonFileMock = jest.spyOn(files, 'readJsonFile').mockImplementation()
readJsonFileMock.mockReturnValue(VALID_SPEC_JSON_BODY)

addCommentToPrMock = jest
.spyOn(prComment, 'addCommentToPr')
Expand All @@ -94,7 +141,6 @@ describe('action', () => {
.mockReturnValueOnce(Promise.resolve(SUCCESS_MOCK.junitFiles))
// get test vector json
.mockReturnValueOnce(Promise.resolve(TBDEX_TEST_VECTORS_FILES))
readJsonFileMock.mockReturnValue(VALID_SPEC_JSON_BODY)

const rawJunitFile = files.readFile(SUCCESS_MOCK.junitFiles[0])

Expand Down Expand Up @@ -139,7 +185,6 @@ describe('action', () => {
.mockReturnValueOnce(Promise.resolve(FAILURE_MOCK.junitFiles))
// get test vector json
.mockReturnValueOnce(Promise.resolve(TBDEX_TEST_VECTORS_FILES))
readJsonFileMock.mockReturnValue(VALID_SPEC_JSON_BODY)

const rawJunitFile = files.readFile(FAILURE_MOCK.junitFiles[0])

Expand Down Expand Up @@ -172,4 +217,54 @@ describe('action', () => {
const testVectorReport = JSON.parse(output['test-vector-report'])
expect(testVectorReport).toEqual(expectedReport)
})

it('generates a spec release json file successfully', async () => {
defaultGetInputMockImplementation('spec', {
releaseRepo: 'TBD54566975/web5-spec',
specName: 'web5-spec',
specTag: 'v2.0'
})

getFilesMock
// get test vector json
.mockReturnValueOnce(Promise.resolve(WEB5_TEST_VECTORS_FILES))

const expectedConformanceData = {
version: 'v2.0',
releaseLink: 'https://github.com/TBD54566975/web5-spec/releases/tag/v2.0',
testVectors: WEB5_TEST_VECTORS_FEATURES,
sdks: {}
}

mockFetch.mockReturnValue(
Promise.resolve({
status: 404
})
)

expect(
mockOctokit.rest.repos.createOrUpdateFileContents
).toHaveBeenCalledTimes(1)
expect(
mockOctokit.rest.repos.createOrUpdateFileContents
).toHaveBeenCalledWith({
owner: 'TBD54566975',
repo: 'sdk-report-runner',
path: 'spec-conformance-web5-spec.json',
message: `[ci] Update spec-conformance-web5-spec.json: TBD54566975/[email protected]`,
content: Buffer.from(
JSON.stringify(expectedConformanceData, null, 2)
).toString('base64'),
branch: 'gh-pages'
})
})

it('generates a sdk release json file successfully', async () => {
defaultGetInputMockImplementation('sdk', {
releaseRepo: 'TBD54566975/web5-kt',
releaseTag: 'v1.9.3',
specName: 'web5-spec',
specTag: 'v2.0'
})
})
})
18 changes: 18 additions & 0 deletions .github/actions/specs-report/__tests__/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,21 @@ export const WEB5_TEST_VECTORS_FILES = [
'/home/runner/work/web5-kt/web5-kt/web5-spec/test-vectors/vc_jwt/verify.json',
'/home/runner/work/web5-kt/web5-kt/web5-spec/test-vectors/vectors.schema.json'
]

export const WEB5_TEST_VECTORS_FEATURES = {
credentials: ['create', 'verify'],
crypto_ed25519: ['sign', 'verify'],
crypto_es256k: ['sign', 'verify'],
did_dht: ['create', 'resolve'],
did_jwk: ['resolve'],
did_web: ['resolve'],
portable_did: ['parse'],
presentation_exchange: [
'create_presentation_from_credentials',
'evaluate_presentation',
'select_credentials',
'validate_definition',
'validate_submission'
],
vc_jwt: ['decode', 'verify']
}
11 changes: 9 additions & 2 deletions .github/actions/specs-report/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ inputs:
description:
'Glob Path with the JUnit test vectors report, can be a single path or a
list of paths in an array'
required: true
required: true # required if release-mode is "none"
spec-path:
description: 'The relative path to the tbd spec submodule folder'
required: true
required: true # required if release-mode is "none"
suite-name-regex:
description: 'The regex to filter the suite name'
required: false
Expand All @@ -33,6 +33,13 @@ inputs:
fail-on-failed-test-cases:
description: 'Whether to fail the job if failed test cases are found'
required: false
release-mode:
description: 'Set to "spec" or "sdk" to handle release updates'
required: false
default: 'none'
spec-release-tag:
description: 'The tag of the spec release'
required: false # required if release-mode is "spec"

# Define your outputs here.
outputs:
Expand Down
Loading

0 comments on commit 8de42d2

Please sign in to comment.