-
Notifications
You must be signed in to change notification settings - Fork 0
test: add comprehensive E2E test suite for CLI wrapper #30
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
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6da6b05
test: add comprehensive E2E test suite for CLI wrapper
beonde 8574cf6
fix(ci): add GHCR credentials for capiscio-server image pull
beonde fb6b5dc
fix(ci): build capiscio-server from source instead of GHCR pull
beonde 5120a0e
fix(e2e): remove tests for non-existent CLI commands
beonde aab4517
fix(e2e): remove setupFiles reference in vitest.config.e2e.ts
beonde 7e7187f
fix(e2e): handle CLI download messages in badge tests
beonde 8bbe2f1
refactor(e2e): address copilot review feedback
beonde 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
Some comments aren't visible on the classic Files Changed page.
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,40 @@ | ||
| name: E2E Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main, develop] | ||
| pull_request: | ||
| branches: [main, develop] | ||
|
|
||
| jobs: | ||
| e2e-tests: | ||
| name: E2E Tests (Node ${{ matrix.node-version }}) | ||
| runs-on: ubuntu-latest | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| node-version: ['18', '20', '22'] | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js ${{ matrix.node-version }} | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: ${{ matrix.node-version }} | ||
|
|
||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9 | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install | ||
|
|
||
| - name: Build project | ||
| run: pnpm build | ||
|
|
||
| - name: Run E2E tests | ||
| run: pnpm test:e2e |
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,116 @@ | ||
| # Tests for capiscio-node CLI | ||
|
|
||
| This directory contains unit and E2E tests for the `capiscio` CLI wrapper. | ||
|
|
||
| ## Directory Structure | ||
|
|
||
| ``` | ||
| tests/ | ||
| ├── unit/ # Unit tests with mocks (no server required) | ||
| │ └── cli.test.ts | ||
| └── e2e/ # E2E tests (offline mode, no server required) | ||
| ├── fixtures/ # Test data files | ||
| │ ├── valid-agent-card.json | ||
| │ ├── invalid-agent-card.json | ||
| │ └── malformed.json | ||
| ├── validate.e2e.test.ts # Validation command tests | ||
| └── badge.e2e.test.ts # Badge issuance/verification tests | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ### Run All Tests | ||
|
|
||
| ```bash | ||
| pnpm test # Unit tests only (default) | ||
| pnpm test:all # Both unit and E2E tests | ||
| ``` | ||
|
|
||
| ### Run Only Unit Tests | ||
|
|
||
| ```bash | ||
| pnpm test:unit | ||
| ``` | ||
|
|
||
| ### Run Only E2E Tests | ||
|
|
||
| ```bash | ||
| pnpm test:e2e | ||
| ``` | ||
|
|
||
| ### Run with Watch Mode | ||
|
|
||
| ```bash | ||
| pnpm test:watch | ||
| ``` | ||
|
|
||
| ### Run with Coverage | ||
|
|
||
| ```bash | ||
| pnpm test:coverage | ||
| ``` | ||
|
|
||
| ## E2E Test Design | ||
|
|
||
| The E2E tests are designed to run **offline** without requiring a server: | ||
|
|
||
| - **Validate tests**: Use `--schema-only` flag for local schema validation | ||
| - **Badge tests**: Use `--self-sign` for issuance and `--accept-self-signed --offline` for verification | ||
|
|
||
| This approach allows E2E tests to run in CI without complex server infrastructure. | ||
|
|
||
| ## Test Coverage | ||
|
|
||
| ### Validate Command (`validate.e2e.test.ts`) | ||
|
|
||
| - ✅ Valid local agent card file (schema-only mode) | ||
| - ✅ Invalid local agent card file | ||
| - ✅ Malformed JSON file | ||
| - ✅ Nonexistent file | ||
| - ✅ JSON output format | ||
| - ✅ Help command | ||
|
|
||
| ### Badge Commands (`badge.e2e.test.ts`) | ||
|
|
||
| - ✅ Issue self-signed badge | ||
| - ✅ Issue badge with custom expiration | ||
| - ✅ Issue badge with audience restriction | ||
| - ✅ Verify self-signed badge (offline) | ||
| - ✅ Verify invalid token (error handling) | ||
| - ✅ Help commands (badge, issue, verify) | ||
|
|
||
| ## CI/CD Integration | ||
|
|
||
| The E2E tests run in GitHub Actions without server dependencies: | ||
|
|
||
| ```yaml | ||
| # See .github/workflows/e2e.yml | ||
| - name: Run E2E tests | ||
| run: pnpm test:e2e | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - **Offline Mode**: All E2E tests run offline without server dependencies | ||
| - **Timeouts**: Tests have 15-second timeouts to prevent hanging | ||
| - **Download Messages**: On first run, the CLI may download the capiscio-core binary; tests handle this gracefully | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### TypeScript Build Errors | ||
|
|
||
| Ensure the project is built before running E2E tests: | ||
|
|
||
| ```bash | ||
| pnpm build | ||
| pnpm test:e2e | ||
| ``` | ||
|
|
||
| ### Path Issues | ||
|
|
||
| Ensure you're running tests from the project root: | ||
|
|
||
| ```bash | ||
| cd /path/to/capiscio-node | ||
| pnpm test:e2e | ||
| ``` |
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,114 @@ | ||
| /** | ||
| * E2E tests for capiscio badge commands. | ||
| * | ||
| * Tests badge issuance and verification commands against the CLI. | ||
| * These tests focus on the CLI interface itself, not the server. | ||
| */ | ||
|
|
||
| import { describe, it, expect } from 'vitest'; | ||
| import { runCapiscio, extractToken } from './helpers'; | ||
|
|
||
| describe('badge commands', () => { | ||
| describe('badge issue', () => { | ||
| it('should issue a self-signed badge', async () => { | ||
| const result = await runCapiscio([ | ||
| 'badge', 'issue', '--self-sign', '--domain', 'test.example.com' | ||
| ]); | ||
|
|
||
| // Self-signed badge issuance should succeed | ||
| expect(result.exitCode).toBe(0); | ||
|
|
||
| // Output should contain a JWT token (has dots for header.payload.signature) | ||
| // Get last line in case there are download messages | ||
| const token = extractToken(result.stdout); | ||
| expect(token.split('.').length).toBe(3); // JWT format | ||
| }, 15000); | ||
|
|
||
| it('should issue badge with custom expiration', async () => { | ||
| const result = await runCapiscio([ | ||
| 'badge', 'issue', '--self-sign', '--exp', '10m' | ||
| ]); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| const token = extractToken(result.stdout); | ||
| expect(token.split('.').length).toBe(3); | ||
| }, 15000); | ||
|
|
||
beonde marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| it('should issue badge with audience restriction', async () => { | ||
| const result = await runCapiscio([ | ||
| 'badge', 'issue', '--self-sign', '--aud', 'https://api.example.com' | ||
| ]); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| const token = extractToken(result.stdout); | ||
| expect(token.split('.').length).toBe(3); | ||
| }, 15000); | ||
|
|
||
| it('should display help for badge issue', async () => { | ||
| const result = await runCapiscio(['badge', 'issue', '--help']); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| const helpText = result.stdout.toLowerCase(); | ||
| expect(helpText.includes('issue')).toBe(true); | ||
| expect(helpText.includes('self-sign') || helpText.includes('level')).toBe(true); | ||
| }, 15000); | ||
| }); | ||
|
|
||
| describe('badge verify', () => { | ||
| it('should verify a self-signed badge', async () => { | ||
| // First issue a badge | ||
| const issueResult = await runCapiscio([ | ||
| 'badge', 'issue', '--self-sign', '--domain', 'test.example.com' | ||
| ]); | ||
| expect(issueResult.exitCode).toBe(0); | ||
| const token = extractToken(issueResult.stdout); | ||
|
|
||
| // Then verify it with --accept-self-signed | ||
| const verifyResult = await runCapiscio([ | ||
| 'badge', 'verify', token, '--accept-self-signed', '--offline' | ||
| ]); | ||
|
|
||
| expect(verifyResult.exitCode).toBe(0); | ||
| const output = verifyResult.stdout.toLowerCase(); | ||
| expect( | ||
| output.includes('valid') || output.includes('verified') || output.includes('ok') | ||
| ).toBe(true); | ||
| }, 15000); | ||
|
|
||
| it('should fail for invalid token', async () => { | ||
| const invalidToken = 'invalid.jwt.token'; | ||
| const result = await runCapiscio(['badge', 'verify', invalidToken, '--accept-self-signed']); | ||
|
|
||
| expect(result.exitCode).not.toBe(0); | ||
| const errorOutput = (result.stderr + result.stdout).toLowerCase(); | ||
| expect( | ||
| errorOutput.includes('invalid') || | ||
| errorOutput.includes('verify') || | ||
| errorOutput.includes('failed') || | ||
| errorOutput.includes('malformed') || | ||
| errorOutput.includes('error') | ||
| ).toBe(true); | ||
| }, 15000); | ||
|
|
||
| it('should display help for badge verify', async () => { | ||
| const result = await runCapiscio(['badge', 'verify', '--help']); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| const helpText = result.stdout.toLowerCase(); | ||
| expect(helpText.includes('verify') || helpText.includes('token')).toBe(true); | ||
| }, 15000); | ||
| }); | ||
|
|
||
| describe('badge help', () => { | ||
| it('should display help for badge command', async () => { | ||
| const result = await runCapiscio(['badge', '--help']); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| const helpText = result.stdout.toLowerCase(); | ||
| expect(helpText.includes('badge')).toBe(true); | ||
| expect( | ||
| helpText.includes('issue') || helpText.includes('verify') || helpText.includes('usage') | ||
| ).toBe(true); | ||
| }, 15000); | ||
| }); | ||
| }); | ||
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,9 @@ | ||
| { | ||
| "version": "1.0", | ||
| "did": "invalid-did-format", | ||
| "name": "Invalid Agent", | ||
| "publicKey": { | ||
| "kty": "WRONG", | ||
| "x": "invalid-key-data" | ||
| } | ||
| } |
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,5 @@ | ||
| { | ||
| "version": "1.0", | ||
| "did": "did:web:example.com", | ||
| "trailing": "comma", | ||
| } |
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,26 @@ | ||
| { | ||
| "protocolVersion": "1.3.0", | ||
| "version": "1.0.0", | ||
| "name": "Test Agent", | ||
| "description": "A test agent for E2E validation tests", | ||
| "url": "https://example.com/.well-known/agent.json", | ||
| "capabilities": { | ||
| "streaming": false, | ||
| "pushNotifications": false | ||
| }, | ||
| "skills": [ | ||
| { | ||
| "id": "test-skill", | ||
| "name": "Test Skill", | ||
| "description": "A skill for testing", | ||
| "tags": ["test", "validation"] | ||
| } | ||
| ], | ||
| "provider": { | ||
| "organization": "Test Organization", | ||
| "url": "https://example.com" | ||
| }, | ||
| "authentication": { | ||
| "schemes": ["none"] | ||
| } | ||
| } |
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,43 @@ | ||
| /** | ||
| * Shared test helpers for E2E tests. | ||
| */ | ||
|
|
||
| import { exec } from 'child_process'; | ||
| import { promisify } from 'util'; | ||
| import path from 'path'; | ||
|
|
||
| const execAsync = promisify(exec); | ||
|
|
||
| export const CLI_PATH = path.join(__dirname, '../../bin/capiscio.js'); | ||
| export const FIXTURES_DIR = path.join(__dirname, 'fixtures'); | ||
|
|
||
| /** | ||
| * Run the capiscio CLI with the given arguments. | ||
| */ | ||
| export async function runCapiscio( | ||
| args: string[], | ||
| env?: Record<string, string> | ||
| ): Promise<{ stdout: string; stderr: string; exitCode: number }> { | ||
| try { | ||
| const { stdout, stderr } = await execAsync(`node "${CLI_PATH}" ${args.join(' ')}`, { | ||
| env: { ...process.env, ...env }, | ||
| }); | ||
| return { stdout, stderr, exitCode: 0 }; | ||
| } catch (error: unknown) { | ||
| const err = error as { stdout?: string; stderr?: string; code?: number }; | ||
| return { | ||
| stdout: err.stdout || '', | ||
| stderr: err.stderr || '', | ||
| exitCode: err.code || 1, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extract token from CLI output - handles potential download messages on first run. | ||
| * The CLI may print download progress before the actual output. | ||
| */ | ||
| export function extractToken(stdout: string): string { | ||
| const lines = stdout.trim().split('\n'); | ||
| return lines[lines.length - 1].trim(); | ||
| } |
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.