Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

jobs:
lint-and-test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18, 20, 22]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Drop unsupported Node 18 from lint/test matrix

The new CI matrix runs npm run lint on Node 18, but this commit also upgrades to eslint@10.0.3, whose lockfile entry requires node: ^20.19.0 || ^22.13.0 || >=24 (package-lock.json), so the Node 18 leg will fail consistently and keep the workflow red for pushes/PRs targeting main/master. Either remove Node 18 from the matrix or pin ESLint to a Node-18-compatible major.

Useful? React with 👍 / 👎.


steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm

- name: Install dependencies
run: npm ci

- name: Lint
run: npm run lint

- name: Test
run: npm test
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules/
.env
*.log
/tmp/
dist/
.DS_Store
86 changes: 86 additions & 0 deletions __tests__/server.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const request = require('supertest');
const { app, shellEscape } = require('../server');

describe('Health endpoint', () => {
test('GET /health returns healthy status', async () => {
const res = await request(app).get('/health');
expect(res.status).toBe(200);
expect(res.body.status).toBe('healthy');
expect(res.body.service).toBe('road-deploy');
expect(res.body.version).toBe('1.0.0');
expect(res.body.timestamp).toBeDefined();
});
});

describe('Deploy endpoint validation', () => {
test('POST /api/deploy rejects missing domain', async () => {
const res = await request(app)
.post('/api/deploy')
.send({ repo_url: 'https://github.com/test/repo.git' });
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
expect(res.body.error).toMatch(/domain.*required/i);
});

test('POST /api/deploy rejects missing repo_url', async () => {
const res = await request(app)
.post('/api/deploy')
.send({ domain: 'test.blackroad.io' });
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
expect(res.body.error).toMatch(/repo_url.*required/i);
});

test('POST /api/deploy rejects empty body', async () => {
const res = await request(app)
.post('/api/deploy')
.send({});
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
});
});

describe('Deployment status endpoint', () => {
test('GET /api/deploy/:id returns status for unknown id', async () => {
const res = await request(app).get('/api/deploy/nonexistent-id');
expect(res.status).toBe(200);
expect(res.body.success).toBe(true);
expect(res.body.deployment_id).toBe('nonexistent-id');
expect(res.body.status).toBe('completed_or_failed');
});
});

describe('Webhook validation', () => {
test('POST /api/webhook/github rejects invalid payload', async () => {
const res = await request(app)
.post('/api/webhook/github')
.send({});
expect(res.status).toBe(400);
expect(res.body.success).toBe(false);
});
});

describe('shellEscape', () => {
test('escapes single quotes', () => {
expect(shellEscape("it's")).toBe("'it'\\''s'");
});

test('wraps normal strings in single quotes', () => {
expect(shellEscape('hello')).toBe("'hello'");
});

test('handles empty string', () => {
expect(shellEscape('')).toBe("''");
});

test('returns empty string for non-string input', () => {
expect(shellEscape(undefined)).toBe('');
expect(shellEscape(null)).toBe('');
});

test('escapes command injection attempts', () => {
const malicious = '; rm -rf /';
const escaped = shellEscape(malicious);
expect(escaped).toBe("'; rm -rf /'");
});
});
40 changes: 40 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const js = require('@eslint/js');

module.exports = [
js.configs.recommended,
{
languageOptions: {
ecmaVersion: 2022,
sourceType: 'commonjs',
globals: {
console: 'readonly',
process: 'readonly',
require: 'readonly',
module: 'readonly',
__dirname: 'readonly',
__filename: 'readonly',
setTimeout: 'readonly',
clearTimeout: 'readonly',
setInterval: 'readonly',
clearInterval: 'readonly',
Buffer: 'readonly',
describe: 'readonly',
it: 'readonly',
test: 'readonly',
expect: 'readonly',
beforeAll: 'readonly',
afterAll: 'readonly',
beforeEach: 'readonly',
afterEach: 'readonly',
},
Comment on lines +21 to +29

Copilot AI Mar 10, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Jest globals (describe, it, expect, etc.) are configured as globals for all files, which reduces lint effectiveness in non-test code (production files can accidentally reference test globals without a lint error). Scope these globals to test files only (e.g., a config entry with files: ['**/__tests__/**', '**/*.test.js']) or use the Jest ESLint plugin/env for those patterns.

Copilot uses AI. Check for mistakes.
},
rules: {
'no-unused-vars': ['error', { argsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }],
'no-console': 'off',
'no-empty': ['error', { allowEmptyCatch: true }],
},
},
{
ignores: ['node_modules/', 'coverage/'],
},
];
Loading
Loading