Fuzz Testing #95
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
| name: Fuzz Testing | |
| on: | |
| schedule: | |
| - cron: '0 2 * * *' # Daily at 2 AM UTC | |
| push: | |
| branches: [ "main" ] | |
| paths: | |
| - 'src/**' | |
| - 'test/**' | |
| pull_request: | |
| branches: [ "main" ] | |
| paths: | |
| - 'src/**' | |
| - 'test/**' | |
| permissions: | |
| contents: read | |
| jobs: | |
| fuzz-test: | |
| name: Fuzz Testing | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| - name: Enable corepack and set npm version | |
| run: | | |
| corepack enable | |
| corepack prepare [email protected] --activate | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Install fast-check with lock file | |
| run: | | |
| echo '{"name":"fuzz-test","devDependencies":{"fast-check":"4.3.0"}}' > package.json | |
| npx [email protected] npm install --package-lock-only | |
| npm ci | |
| - name: Create fuzz test | |
| run: | | |
| cat << 'EOF' > test/fuzz.test.js | |
| const fc = require('fast-check'); | |
| const fs = require('fs'); | |
| const path = require('path'); | |
| // Import our utilities for fuzzing | |
| let utils; | |
| try { | |
| utils = require('../dist/utils.js'); | |
| } catch (e) { | |
| // Build first if dist doesn't exist | |
| const { execSync } = require('child_process'); | |
| execSync('npm run build', { stdio: 'inherit' }); | |
| utils = require('../dist/utils.js'); | |
| } | |
| describe('Fuzz Testing', () => { | |
| test('detectPackageManager handles arbitrary strings', () => { | |
| fc.assert(fc.property(fc.string(), (input) => { | |
| try { | |
| const result = utils.detectPackageManager(input); | |
| expect(typeof result).toBe('string'); | |
| expect(['npm', 'yarn', 'pnpm', 'bun'].includes(result)).toBe(true); | |
| } catch (error) { | |
| // Expected to handle gracefully | |
| expect(error).toBeInstanceOf(Error); | |
| } | |
| })); | |
| }); | |
| test('validateTemplateVariables handles arbitrary objects', () => { | |
| fc.assert(fc.property(fc.object(), (input) => { | |
| try { | |
| const result = utils.validateTemplateVariables(input, []); | |
| expect(typeof result).toBe('object'); | |
| } catch (error) { | |
| // Expected to handle gracefully | |
| expect(error).toBeInstanceOf(Error); | |
| } | |
| })); | |
| }); | |
| test('renderTemplate handles arbitrary template strings', () => { | |
| fc.assert(fc.property(fc.string(), fc.object(), (template, vars) => { | |
| try { | |
| const result = utils.renderTemplate(template, vars); | |
| expect(typeof result).toBe('string'); | |
| } catch (error) { | |
| // Expected to handle gracefully for malformed templates | |
| expect(error).toBeInstanceOf(Error); | |
| } | |
| })); | |
| }); | |
| }); | |
| EOF | |
| - name: Run fuzz tests | |
| run: npm test test/fuzz.test.js || true | |
| - name: Clean up | |
| run: rm -f test/fuzz.test.js && npm uninstall fast-check |