# Testing command-line tools and web apps

How command-line tools and web apps behave at runtime and how to test them, from exit codes and output streams to headless browsers.

Start here

## [How to test a command-line application](https://specstory.com/learning/cli-and-web/testing-command-line-applications)

Testing a command-line application means running it the way users and scripts do and checking its output, errors, exit codes, and behavior in pipes.

11 min read

## Concepts

### [What are exit codes?](https://specstory.com/learning/cli-and-web/exit-codes)

An exit code is the number a program returns when it finishes, where 0 usually means success and any other value signals an error that scripts can check.

### [What is a headless browser?](https://specstory.com/learning/cli-and-web/headless-browser)

A headless browser is a web browser that runs without a visible window, controlled by code, so tests and agents can load pages and act on them.

### [What is a browser test framework?](https://specstory.com/learning/cli-and-web/browser-test-frameworks)

A browser test framework is an open-source library that drives a real browser from test code, so a test can load pages, act on them, and check results.

### [What is Playwright MCP?](https://specstory.com/learning/cli-and-web/playwright-mcp)

Playwright MCP is a server that lets an AI agent drive a real browser through the Model Context Protocol, using page snapshots instead of screenshots.

## How-to guides

### [How to verify a CLI that a coding agent built](https://specstory.com/learning/cli-and-web/verifying-agent-built-cli)

Verifying a CLI that a coding agent built means installing it fresh, running the commands a user would, and checking exit codes, output, and files.

### [How to test a terminal UI (TUI)](https://specstory.com/learning/cli-and-web/testing-terminal-uis)

Testing a terminal UI (TUI) means running it in a pseudoterminal, sending keystrokes, and comparing the screen it draws with a reviewed snapshot.

### [How to test shell scripts](https://specstory.com/learning/cli-and-web/testing-shell-scripts)

Testing a shell script means running it with controlled input and environment, then checking its output, exit code, and the files it changes.

## Comparisons

### [What is the difference between stdout and stderr?](https://specstory.com/learning/cli-and-web/stdout-vs-stderr)

stdout is a program's standard output for results, and stderr is a separate stream for errors and diagnostics, so each can be redirected on its own.

## Common questions

### [Why does CLI output change when piped?](https://specstory.com/learning/cli-and-web/tty-vs-pipe)

CLI output changes when piped because programs and runtimes check whether stdout is a terminal (a TTY) and switch color, buffering, and layout if not.

## Failures and bugs

### [What is a broken pipe error (SIGPIPE)?](https://specstory.com/learning/cli-and-web/broken-pipe)

A broken pipe error happens when a program writes to a pipe or socket whose reader has closed, which sends it SIGPIPE and often ends it with exit code 141.

### [What is a hydration error?](https://specstory.com/learning/cli-and-web/hydration-error)

A hydration error happens when the HTML a server rendered does not match what the browser's JavaScript renders, so the framework warns or re-renders.

## Terms in this topic

**[Browser test framework](https://specstory.com/learning/glossary#browser-test-framework)**

A browser test framework is an open-source library that drives a real browser from test code, so a test can load pages, act on them, and check the results.

**[Command-line interface (CLI)](https://specstory.com/learning/glossary#command-line-interface)**

A command-line interface is a way of using a program that takes typed commands, flags, and input in a terminal or script, and returns output, errors, and an exit code.

**[Exit code](https://specstory.com/learning/glossary#exit-code)**

An exit code is the number that a program returns when it finishes, where 0 usually means success and any other value signals an error that scripts can check.

**[Headless browser](https://specstory.com/learning/glossary#headless-browser)**

A headless browser is a web browser that runs without a visible window and is controlled by code, so tests and agents can load pages and act on them.

**[Hydration error](https://specstory.com/learning/glossary#hydration-error)**

A hydration error is a web app failure that happens when the HTML a server rendered does not match what the browser's JavaScript renders on load.

**[Playwright MCP](https://specstory.com/learning/glossary#playwright-mcp)**

Playwright MCP is an open-source server that lets an AI agent control a real browser through the Model Context Protocol, using structured page snapshots instead of screenshots.

**[SIGPIPE](https://specstory.com/learning/glossary#sigpipe)**

SIGPIPE is the signal that a program receives when it writes to a pipe whose reader has closed. By default it ends the program, and shells report exit code 141.

**[Standard streams](https://specstory.com/learning/glossary#standard-streams)**

The standard streams are the three channels that every process gets by default, which are standard input for data in, standard output for results, and standard error for diagnostics.

**[stderr](https://specstory.com/learning/glossary#stderr)**

stderr is the standard error stream that a program writes errors and diagnostics to, so they stay separate from the results on standard output.

**[stdout](https://specstory.com/learning/glossary#stdout)**

stdout is the standard output stream that a program writes its normal results to, so another program, a file, or a terminal can read them.

**[TTY](https://specstory.com/learning/glossary#tty)**

A TTY is a terminal device that a program can detect, and many programs change their output, color, or prompts when they write to a pipe instead of a TTY.

11 terms from the [Learning Center glossary](https://specstory.com/learning/glossary).

---

Source: [Testing command-line tools and web apps | SpecStory](https://specstory.com/learning/cli-and-web)
