# Test a command-line program

Source: https://testis.dev/docs/cli-app-testing

> Run your program like a user would: arguments, input, exit codes, output, files, even full-screen menus.

The AI tester uses a command-line program the way a person does: it runs commands with arguments and input, reads the output and exit code, and drives interactive prompts and full-screen terminal menus by typing and pressing keys.

## Set up

```bash
testis init --cli notes="node dist/cli.js"
```

`alias=command` gives the program a name tests can use. In `.testis/config.yaml`:

```yaml
targets:
  - kind: cli
    alias: notes                        # the name tests use
    binary: node dist/cli.js            # what it runs (never through a shell)
    buildCommand: npm run build         # optional: run once before the tests
```

### Test the released package

To test what users actually install rather than your local build:

```yaml
  - kind: cli
    alias: notes
    binary: notes                       # the program the package installs (its "bin")
    installFrom: { source: npm, spec: "@acme/notes@1.4.0" }   # or a tarball path from `npm pack`
```

Testis installs it into a clean folder under `.testis/cache/installs/` and runs the tests against that copy. This catches files left out of the published package, a wrong `bin`, and undeclared dependencies, which a local build hides. npm is supported today.

## Test it

```bash
testis test --cli
testis test --cli "the import command"
```

The tester reads each program's `--help` and your PRD, then tests each command: right and wrong arguments, missing files, empty input, what is printed and the exit code. For an interactive program it starts it in a real terminal, types, presses keys (Enter, arrows, Tab, Ctrl-C) and reads the screen. It can create the files a command needs in its working folder. Every bug quotes the output it saw.

## How the program is run

- Only the aliases you declared can run, and **never through a shell**, so there is no `echo x | notes`. Use `stdin` instead.
- Each area gets an **empty temporary directory** that is also the program's `HOME`. Files the tester makes stay inside it.
- The program gets a **minimal environment**: your secrets are not passed in. Add what it needs under `env`.
- A run that exceeds its timeout is killed.
