SIDDARTHA577/envguard-node / .agents/skills/envguard-load-test
envguard-load-test
VerifiedGuides capacity planning, workload profile design, local performance benchmarking, and threshold validation without fabricating production metrics or executing unauthorized traffic.
scripts/readiness/deployment/reliability-validator.mjs
View on GitHubimport fs from 'node:fs';
import path from 'node:path';
/**
* Validates operational reliability and resilience safeguards.
* Evaluates graceful shutdown, downstream timeouts, retry storm safeguards,
* message queue dead-letter configurations, database migration reversibility,
* and disaster recovery restore verification.
*
* @param {string} projectDir - Root project directory
* @param {string[]} [files=[]] - Relative project files list
* @param {object} [inventory=null] - Architecture inventory
* @returns {object[]} Array of reliability findings
*/
export function validateOperationalReliability(projectDir, files = [], inventory = null) {
const findings = [];
const codeFiles = files.filter((f) => {
const ext = path.extname(f).toLowerCase();
return (
(ext === '.js' ||
ext === '.ts' ||
ext === '.mjs' ||
ext === '.py' ||
ext === '.java' ||
ext === '.go') &&
!f.includes('.test.') &&
!f.includes('.spec.') &&
!f.includes('tests/')
);
});
// 1. Graceful Shutdown (DEP-REL-001)
let shutdownFound = false;
let shutdownFile = null;
for (const relPath of codeFiles) {
const fullPath = path.join(projectDir, relPath);
try {
const content = fs.readFileSync(fullPath, 'utf8');
if (
content.includes('SIGTERM') ||
content.includes('SIGINT') ||
content.includes('gracefulShutdown') ||
content.includes('server.close(') ||
content.includes('app.stop(')
) {
shutdownFound = true;
shutdownFile = relPath;
break;
}
} catch { /* ignore non-critical read/parse error */ }
}
if (shutdownFound) {
findings.push({
id: 'DEP-REL-001',
category: 'deployment',
status: 'PASS',
severity: 'info',
title: 'Graceful Process Shutdown Handlers Detected',
explanation: `Found shutdown signal handling in "${shutdownFile}". Active requests will be allowed to finish during rolling deployments.`,
evidence: { file: shutdownFile },
checkMethod: 'static_analysis',
recommendation: 'Ensure database pools and active sockets are drained with a bounded 15-30s timeout on SIGTERM.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
} else {
findings.push({
id: 'DEP-REL-001',
category: 'deployment',
status: 'WARNING',
severity: 'high',
title: 'Missing Graceful Process Shutdown Handlers',
explanation: 'No SIGTERM or SIGINT handlers detected in application entry points. During rolling updates or pod terminations, in-flight HTTP requests may be dropped abruptly with 502/504 errors.',
evidence: { file: 'src/' },
checkMethod: 'static_analysis',
recommendation: 'Register process.on("SIGTERM", async () => { server.close(); await db.disconnect(); }) in main server file.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
}
// 2. Downstream Network Timeout Enforcement (DEP-REL-002)
let outboundCallFound = false;
let hasTimeoutEnforcement = false;
let outboundFile = null;
for (const relPath of codeFiles) {
const fullPath = path.join(projectDir, relPath);
try {
const content = fs.readFileSync(fullPath, 'utf8');
if (content.includes('fetch(') || content.includes('axios.') || content.includes('http.request(')) {
outboundCallFound = true;
outboundFile = relPath;
if (
content.includes('timeout:') ||
content.includes('AbortSignal.timeout(') ||
content.includes('signal:') ||
content.includes('connectTimeout')
) {
hasTimeoutEnforcement = true;
break;
}
}
} catch { /* ignore non-critical read/parse error */ }
}
if (outboundCallFound) {
if (hasTimeoutEnforcement) {
findings.push({
id: 'DEP-REL-002',
category: 'deployment',
status: 'PASS',
severity: 'info',
title: 'Downstream HTTP Call Timeouts Enforced',
explanation: `Outbound network clients in "${outboundFile}" configure explicit timeouts or abort signals.`,
evidence: { file: outboundFile },
checkMethod: 'static_analysis',
recommendation: 'Keep network call timeouts under 5000ms for user-facing API routes.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
} else {
findings.push({
id: 'DEP-REL-002',
category: 'deployment',
status: 'WARNING',
severity: 'high',
title: 'Unbounded Outbound Network Request Timeouts',
explanation: `Outbound HTTP requests detected in "${outboundFile}" without explicit timeout bounds. A slow or hanging downstream service can tie up server connection pools indefinitely.`,
evidence: { file: outboundFile },
checkMethod: 'static_analysis',
recommendation: 'Pass signal: AbortSignal.timeout(3000) or configure client timeout to prevent indefinite socket hangs.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
}
}
// 3. Database Migration Reversibility (DEP-REL-005)
const migrationFiles = files.filter((f) => {
const lower = f.toLowerCase();
return (
(lower.includes('migration') || lower.includes('migrations/')) &&
(lower.endsWith('.sql') || lower.endsWith('.js') || lower.endsWith('.ts'))
);
});
if (migrationFiles.length > 0) {
let hasDownMigrations = false;
for (const relPath of migrationFiles) {
const fullPath = path.join(projectDir, relPath);
try {
const content = fs.readFileSync(fullPath, 'utf8');
if (
content.includes('down =') ||
content.includes('exports.down') ||
content.includes('DROP TABLE') ||
content.includes('DROP COLUMN') ||
content.includes('-- Down') ||
content.includes('def down')
) {
hasDownMigrations = true;
break;
}
} catch { /* ignore non-critical read/parse error */ }
}
if (hasDownMigrations) {
findings.push({
id: 'DEP-REL-005',
category: 'database',
status: 'PASS',
severity: 'info',
title: 'Reversible Database Migration Scripts Configured',
explanation: `Database migration files include automated down/rollback definitions across ${migrationFiles.length} migrations.`,
evidence: { migrationCount: migrationFiles.length },
checkMethod: 'static_analysis',
recommendation: 'Always follow the Expand/Contract pattern for schema changes to support zero-downtime rollbacks.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
} else {
findings.push({
id: 'DEP-REL-005',
category: 'database',
status: 'WARNING',
severity: 'high',
title: 'Non-Reversible Database Migrations Detected',
explanation: 'Database migration files lack automated down/rollback scripts. Failed deployments cannot safely roll back database schema changes.',
evidence: { migrationCount: migrationFiles.length },
checkMethod: 'static_analysis',
recommendation: 'Provide explicit down/rollback scripts or adopt an expand/contract migration protocol.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
}
}
// 4. Dead Letter Queue & Backlog Handling (DEP-REL-004)
const isQueueDetected =
inventory?.detectedTechnologies?.includes('message-queue') ||
files.some((f) => f.includes('bull') || f.includes('rabbit') || f.includes('sqs') || f.includes('kafka'));
if (isQueueDetected) {
let dlqFound = false;
for (const relPath of codeFiles) {
const fullPath = path.join(projectDir, relPath);
try {
const content = fs.readFileSync(fullPath, 'utf8');
if (
content.includes('deadLetterTargetArn') ||
content.includes('deadLetterQueue') ||
content.includes('dlq') ||
content.includes('attempts:') ||
content.includes('backoff:')
) {
dlqFound = true;
break;
}
} catch { /* ignore non-critical read/parse error */ }
}
if (dlqFound) {
findings.push({
id: 'DEP-REL-004',
category: 'deployment',
status: 'PASS',
severity: 'info',
title: 'Queue Poison Message Protection (DLQ / Bounded Retries)',
explanation: 'Background worker / queue consumer configures Dead Letter Queue or bounded retry policies.',
evidence: { detected: true },
checkMethod: 'static_analysis',
recommendation: 'Monitor DLQ message depth and alert if messages accumulate.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
} else {
findings.push({
id: 'DEP-REL-004',
category: 'deployment',
status: 'WARNING',
severity: 'high',
title: 'Missing Dead-Letter Queue (DLQ) Safeguard',
explanation: 'Message queue consumers detected without explicit Dead-Letter Queue or bounded retry policies. A poison pill message could cause infinite worker crash loops.',
evidence: { detected: true },
checkMethod: 'static_analysis',
recommendation: 'Configure max retries (maxAttempts: 3) and route persistently failing messages to a Dead-Letter Queue.',
manualVerificationRequired: false,
confidence: 'verified_fact',
});
}
}
return findings;
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the work | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixes | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation code | Stars: 319k | Updated | Claude CodeCodex | Verified | Install |
| skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |