Skip to content

sb-dev/openquant / .agents/skills/node

Provides domain-specific best practices for Node.js development with TypeScript, covering type stripping, async patterns, error handling, streams, modules, testing, performance, caching, logging, and more. Use when setting up Node.js projects with native TypeScript support, configuring type stripping (--experimental-strip-types), writing Node 22+ TypeScript without a build step, or when the user mentions 'native TypeScript in Node', 'strip types', 'Node 22 TypeScript', '.ts files without compilation', 'ts-node alternative', or needs guidance on error handling, graceful shutdown, flaky tests, profiling, or environment configuration in Node.js. Helps configure tsconfig.json for type stripping, set up package.json scripts, handle module resolution and import extensions, and apply robust patterns across the full Node.js stack.

FileKindSize
SKILL.mdskill md6.3 KB
rules/assets/graceful-server.test.tsscript2.6 KB
rules/assets/graceful-server.tsscript2.2 KB
rules/async-patterns.mdmarkdown3.1 KB
rules/caching.mdmarkdown4.8 KB
rules/environment.mdmarkdown6.0 KB
rules/error-handling.mdmarkdown3.8 KB
rules/flaky-tests.mdmarkdown10.4 KB
rules/graceful-shutdown.mdmarkdown4.6 KB
rules/logging.mdmarkdown4.4 KB
rules/modules.mdmarkdown2.0 KB
rules/node-modules-exploration.mdmarkdown3.6 KB
rules/performance.mdmarkdown2.8 KB
rules/profiling.mdmarkdown3.9 KB
rules/streams.mdmarkdown5.1 KB
rules/stuck-processes-and-tests.mdmarkdown3.9 KB
rules/testing.mdmarkdown4.4 KB
rules/typescript.mdmarkdown5.5 KB
tile.jsonconfig1017 B

rules/assets/graceful-server.test.ts

View on GitHub
import { describe, it, before, after } from 'node:test';
import assert from 'node:assert/strict';
import { createServer, IncomingMessage, ServerResponse, Server } from 'node:http';

describe('graceful server shutdown', () => {
  let server: Server;
  let isShuttingDown = false;

  function createHandler() {
    return (req: IncomingMessage, res: ServerResponse) => {
      if (isShuttingDown) {
        res.setHeader('Connection', 'close');
      }

      if (req.url === '/health') {
        if (isShuttingDown) {
          res.writeHead(503, { 'Content-Type': 'application/json' });
          res.end(JSON.stringify({ status: 'shutting_down' }));
          return;
        }
        res.writeHead(200, { 'Content-Type': 'application/json' });
        res.end(JSON.stringify({ status: 'healthy' }));
        return;
      }

      res.writeHead(200, { 'Content-Type': 'application/json' });
      res.end(JSON.stringify({ message: 'Hello, World!' }));
    };
  }

  before(() => {
    server = createServer(createHandler());
    server.listen(0); // Random available port
  });

  after(async () => {
    await new Promise<void>((resolve) => server.close(() => resolve()));
  });

  function getPort(): number {
    const address = server.address();
    if (typeof address === 'object' && address !== null) {
      return address.port;
    }
    throw new Error('Server not listening');
  }

  it('should return healthy status when not shutting down', async () => {
    const port = getPort();
    const response = await fetch(`http://localhost:${port}/health`);

    assert.equal(response.status, 200);
    const body = await response.json();
    assert.deepEqual(body, { status: 'healthy' });
  });

  it('should return 503 and shutting_down status during shutdown', async () => {
    isShuttingDown = true;
    const port = getPort();

    const response = await fetch(`http://localhost:${port}/health`);

    assert.equal(response.status, 503);
    const body = await response.json();
    assert.deepEqual(body, { status: 'shutting_down' });

    isShuttingDown = false; // Reset for other tests
  });

  it('should set Connection: close header during shutdown', async () => {
    isShuttingDown = true;
    const port = getPort();

    const response = await fetch(`http://localhost:${port}/`);

    assert.equal(response.headers.get('connection'), 'close');

    isShuttingDown = false;
  });

  it('should not set Connection: close header when not shutting down', async () => {
    const port = getPort();

    const response = await fetch(`http://localhost:${port}/`);

    assert.notEqual(response.headers.get('connection'), 'close');
  });
});
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 319kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 319kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 319kUpdated Claude CodeCodexVerifiedInstall
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: 196kUpdated Claude CodeCodexVerifiedInstall