-
Notifications
You must be signed in to change notification settings - Fork 6
ci: add subprocess-based tutorial tests #58
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
Merged
Changes from all commits
Commits
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,65 @@ | ||
| name: Tutorial Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
| workflow_dispatch: | ||
| inputs: | ||
| test_suite: | ||
| description: 'Which tests to run' | ||
| type: choice | ||
| options: | ||
| - read-only | ||
| - read-write | ||
| - all | ||
| default: read-only | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: tutorial-tests-${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| test-read-only: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| if: > | ||
| github.event_name != 'workflow_dispatch' || | ||
| inputs.test_suite == 'read-only' || | ||
| inputs.test_suite == 'all' | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 | ||
| with: | ||
| node-version: '20' | ||
| - run: npm ci | ||
| - name: Run read-only tutorial tests | ||
| env: | ||
| NETWORK: testnet | ||
| PLATFORM_MNEMONIC: ${{ secrets.PLATFORM_MNEMONIC }} | ||
| run: npm run test:read-only | ||
|
|
||
| test-read-write: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| if: > | ||
| github.event_name == 'workflow_dispatch' && | ||
| (inputs.test_suite == 'read-write' || inputs.test_suite == 'all') | ||
| concurrency: | ||
| group: tutorial-read-write | ||
| cancel-in-progress: false | ||
| steps: | ||
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | ||
| - uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0 | ||
| with: | ||
| node-version: '20' | ||
| - run: npm ci | ||
| - name: Run read-write tutorial tests | ||
| env: | ||
| NETWORK: testnet | ||
| PLATFORM_MNEMONIC: ${{ secrets.PLATFORM_MNEMONIC }} | ||
| run: npm run test:read-write | ||
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,70 @@ | ||
| import assert from 'node:assert/strict'; | ||
|
|
||
| /** | ||
| * Assert that a tutorial run succeeded: | ||
| * - Process was not killed (timeout) | ||
| * - Exit code is 0 | ||
| * - No error patterns found in stdout or stderr | ||
| * - All expected patterns found in stdout | ||
| */ | ||
| export function assertTutorialSuccess(result, entry) { | ||
| assert.equal( | ||
| result.killed, | ||
| false, | ||
| `Tutorial "${entry.name}" was killed (timeout)`, | ||
| ); | ||
|
|
||
| assert.equal( | ||
| result.exitCode, | ||
| 0, | ||
| `Tutorial "${entry.name}" exited with code ${result.exitCode}.\n` + | ||
| `STDERR: ${result.stderr}\nSTDOUT: ${result.stdout}`, | ||
| ); | ||
|
|
||
| if (entry.errorPatterns) { | ||
| for (const pat of entry.errorPatterns) { | ||
| const re = new RegExp(pat); | ||
| assert.equal( | ||
| re.test(result.stderr) || re.test(result.stdout), | ||
| false, | ||
| `Tutorial "${entry.name}" output matched error pattern: ${pat}\n` + | ||
| `STDERR: ${result.stderr}\nSTDOUT: ${result.stdout}`, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| if (entry.expectedPatterns) { | ||
| for (const pat of entry.expectedPatterns) { | ||
| assert.match( | ||
| result.stdout, | ||
| new RegExp(pat), | ||
| `Tutorial "${entry.name}" stdout missing expected pattern: ${pat}\n` + | ||
| `STDOUT: ${result.stdout}`, | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extract a captured value from tutorial stdout using a regex with a capture group. | ||
| * Returns the first capture group match, or null if no match. | ||
| */ | ||
| export function extractFromOutput(stdout, regex) { | ||
| const match = stdout.match(regex); | ||
| return match ? match[1] : null; | ||
| } | ||
|
|
||
| /** | ||
| * Extract an `id` or `$id` field from util.inspect or JSON output. | ||
| * Handles `'$id': 'VALUE'` (inspect), `"$id": "VALUE"` (JSON), | ||
| * `id: 'VALUE'` (inspect), and `"id": "VALUE"` (JSON). | ||
| * Tries `$id` first since it's more specific. | ||
| */ | ||
| export function extractId(stdout) { | ||
| return ( | ||
| extractFromOutput(stdout, /'\$id':\s*'([^']+)'/) ?? | ||
| extractFromOutput(stdout, /"\$id"\s*:\s*"([^"]+)"/) ?? | ||
| extractFromOutput(stdout, /"id"\s*:\s*"([^"]+)"/) ?? | ||
| extractFromOutput(stdout, /id:\s*'([^']+)'/) | ||
| ); | ||
| } |
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,74 @@ | ||
| import { describe, it } from 'node:test'; | ||
| import { runTutorial } from './run-tutorial.mjs'; | ||
| import { assertTutorialSuccess } from './assertions.mjs'; | ||
|
|
||
| const tutorials = [ | ||
| { | ||
| path: 'connect.mjs', | ||
| name: 'connect', | ||
| expectedPatterns: ['Connected\\. System status:'], | ||
| errorPatterns: ['Failed to fetch'], | ||
| timeoutMs: 30_000, | ||
| }, | ||
| { | ||
| path: 'create-wallet.mjs', | ||
| name: 'create-wallet', | ||
| expectedPatterns: ['Mnemonic:', 'Platform address:'], | ||
| errorPatterns: ['Something went wrong'], | ||
| timeoutMs: 30_000, | ||
| }, | ||
| { | ||
| path: '1-Identities-and-Names/identity-retrieve.mjs', | ||
| name: 'identity-retrieve', | ||
| expectedPatterns: ['Identity retrieved:'], | ||
| errorPatterns: ['Something went wrong'], | ||
| }, | ||
| { | ||
| path: '1-Identities-and-Names/name-resolve-by-name.mjs', | ||
| name: 'name-resolve-by-name', | ||
| expectedPatterns: ['Identity ID for'], | ||
| errorPatterns: ['Something went wrong'], | ||
| }, | ||
| { | ||
| path: '1-Identities-and-Names/name-search-by-name.mjs', | ||
| name: 'name-search-by-name', | ||
| expectedPatterns: ['\\.dash'], | ||
| errorPatterns: ['Something went wrong'], | ||
| }, | ||
| { | ||
| path: '1-Identities-and-Names/name-get-identity-names.mjs', | ||
| name: 'name-get-identity-names', | ||
| expectedPatterns: ['Name\\(s\\) retrieved'], | ||
| errorPatterns: ['Something went wrong'], | ||
| }, | ||
| { | ||
| path: '2-Contracts-and-Documents/contract-retrieve.mjs', | ||
| name: 'contract-retrieve', | ||
| expectedPatterns: ['Contract retrieved:'], | ||
| errorPatterns: ['Something went wrong'], | ||
| }, | ||
| { | ||
| path: '2-Contracts-and-Documents/contract-retrieve-history.mjs', | ||
| name: 'contract-retrieve-history', | ||
| expectedPatterns: ['Version at'], | ||
| errorPatterns: ['Something went wrong'], | ||
| }, | ||
| { | ||
| path: '2-Contracts-and-Documents/document-retrieve.mjs', | ||
| name: 'document-retrieve', | ||
| expectedPatterns: ['Document:'], | ||
| errorPatterns: ['Something went wrong'], | ||
| }, | ||
| ]; | ||
|
|
||
| describe('Read-only tutorials', () => { | ||
| for (const entry of tutorials) { | ||
| it(entry.name, { timeout: entry.timeoutMs ?? 120_000 }, async () => { | ||
| const result = await runTutorial(entry.path, { | ||
| env: entry.env, | ||
| timeoutMs: entry.timeoutMs, | ||
| }); | ||
| assertTutorialSuccess(result, entry); | ||
| }); | ||
| } | ||
| }); |
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.