Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cf016d3
Moved validate methods to an interface. Added import testing
kevinwang5658 Nov 14, 2024
67c02a6
Made options optional and removed detached (breaking ssh)
kevinwang5658 Nov 14, 2024
833ae6e
Fixed import bugs by making import use refresh() instead of a custom …
kevinwang5658 Nov 19, 2024
ed51ea6
Added ability to test modify in full tests
kevinwang5658 Nov 19, 2024
f7035c5
Improved naming + fixed destroy after modify
kevinwang5658 Nov 19, 2024
7027c5a
Fixed bug with resources not being destroyed
kevinwang5658 Nov 22, 2024
bfe16eb
feat: Updated to latest schema and library. Adds support for requestI…
kevinwang5658 Dec 31, 2024
357d385
fix: Removed modify plan
kevinwang5658 Dec 31, 2024
c062f4f
feat: Added colored text to highlight info sect6ions
kevinwang5658 Jan 1, 2025
2466ae7
fix: Added separate plugins for each stage of the full test
kevinwang5658 Jan 1, 2025
9403130
feat: Added debug flag checking so inspect-brk can be used
kevinwang5658 Jan 7, 2025
7df9e6c
feat: Updated to latest schemas which separates core and parameters
kevinwang5658 Jan 14, 2025
c4c9bba
feat: Made output verbose to help with debugging
kevinwang5658 Mar 16, 2025
9c2edf8
feat: Added message handlers for press key to continue and codify cre…
kevinwang5658 Oct 25, 2025
146df49
chore: bumped package version
kevinwang5658 Oct 25, 2025
90e0621
feat: Added ability to read codify test jwt from environment
kevinwang5658 Oct 26, 2025
a970a4b
feat: Added proper spawn. Fixed missing initialize calls for subseque…
kevinwang5658 Dec 26, 2025
d6e90b2
feat: Added os support
kevinwang5658 Jan 3, 2026
a9b612d
feat: Added testSpawn and filter tests by OS
kevinwang5658 Jan 4, 2026
6377346
feat: Testing improvements
kevinwang5658 Jan 7, 2026
3912a6a
chore: Update to the latest @codifycli packages.
kevinwang5658 Mar 7, 2026
9cd412e
feat: Added CLAUDE.md and README.md. Commit the package-lock.json file.
kevinwang5658 Mar 7, 2026
718f0a4
feat: Add github actions CI
kevinwang5658 Mar 7, 2026
932cbd8
feat: Updated the description, keywords and author
kevinwang5658 Mar 7, 2026
9d01f43
chore: Add repository section to package.json
kevinwang5658 Mar 7, 2026
afb3797
chore: Update @codifycli/plugin-core library and bump version to 1.0.0
kevinwang5658 Mar 7, 2026
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
24 changes: 24 additions & 0 deletions .github/workflows/unit-test-ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on: [ 'push' ]

jobs:
build-and-test:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]

steps:
- uses: actions/checkout@v4
- name: Use Node.js 22
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'npm'
- run: npm ci
- run: npm run test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/.nyc_output
/dist
/lib
/package-lock.json
/tmp
/yarn.lock
node_modules
Expand Down
126 changes: 126 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is `@codifycli/plugin-test`, a testing framework for Codify plugins. It provides utilities to test plugin lifecycle operations (initialize, validate, plan, apply, import, destroy) by spawning plugin processes and communicating via IPC messages.

## Build and Test Commands

```bash
# Run tests
npm test

# Build the project
npm run prepublishOnly

# Start the project (for testing)
npm start
```

### Running Single Tests

Tests use Vitest. To run a specific test file:
```bash
npx vitest src/test-utils.test.ts
```

To run tests matching a pattern:
```bash
npx vitest --grep "pattern"
```

## Architecture

### Core Components

**PluginTester** (`src/plugin-tester.ts`)
- Main API for testing plugins end-to-end
- `fullTest()`: Executes complete plugin lifecycle (validate → plan → apply → import → modify → destroy)
- `install()`: Tests only installation flow (validate → plan → apply)
- `uninstall()`: Tests destroy operations
- Automatically filters configs by OS using `ResourceConfig.os` field
- Handles multiple configs by adding unique names when needed

**PluginProcess** (`src/plugin-process.ts`)
- Manages individual plugin process lifecycle
- Spawns plugin using `fork()` with tsx loader (`--import tsx/esm`)
- Handles bidirectional IPC communication
- Responds to plugin requests: `COMMAND_REQUEST`, `PRESS_KEY_TO_CONTINUE_REQUEST`, `CODIFY_CREDENTIALS_REQUEST`
- Methods mirror plugin API: `initialize()`, `validate()`, `plan()`, `apply()`, `import()`
- Debug mode: Set `DEBUG` env var to enable `--inspect-brk=9221`

**Spawn Utilities** (`src/spawn.ts`)
- `testSpawn()`: Execute commands interactively in PTY (for testing)
- `spawnSafe()`: Low-level command execution with security checks
- Blocks direct `sudo` usage (must use `requiresRoot` option)
- Strips ANSI codes from output
- Supports stdin passthrough, custom env vars, cwd

**TestUtils** (`src/test-utils.ts`)
- `sendMessageAndAwaitResponse()`: Helper for IPC request/response pattern
- Shell utilities: Detects bash/zsh, provides shell rc paths and source commands
- Platform helpers: `isMacOS()`, `isLinux()`
- Prerequisite installers: `ensureHomebrewInstalledOnMacOs()`, `ensureXcodeInstalledOnMacOs()`

### IPC Communication Flow

1. Test creates `PluginProcess` which forks plugin with IPC enabled
2. Test sends IPC messages (e.g., `{cmd: 'plan', data: {...}, requestId: '...'}`
3. Plugin processes request and may send request messages back (e.g., `COMMAND_REQUEST`)
4. `PluginProcess` intercepts requests, executes via `spawnSafe()`, sends response
5. Plugin completes and sends final response matching original `requestId`

### Plugin Testing Pattern

Typical test structure:
```typescript
// Filter configs by OS automatically
const configs: ResourceConfig[] = [
{ type: 'my-resource', param: 'value', os: [ResourceOs.MACOS] }
];

await PluginTester.fullTest('/path/to/plugin', configs, {
validatePlan: (plans) => {
// Custom assertions on plan results
},
validateApply: (plans) => {
// Custom assertions after apply
},
testModify: {
modifiedConfigs: [/* updated configs */],
validateModify: (plans) => {
// Verify modify operation
}
}
});
```

### OS Filtering

Tests automatically filter configs by OS:
- Configs with `os: [ResourceOs.MACOS]` only run on macOS
- Configs with `os: [ResourceOs.LINUX]` only run on Linux
- No `os` field means runs on all platforms
- Implemented in `PluginTester.fullTest()` using `getPlatformOs()`

## Key Technical Details

- **Module System**: ESM with NodeNext module resolution
- **TypeScript**: Strict mode with decorators support
- **Output**: Compiled to `dist/` directory
- **Node Version**: Requires Node 18+ (configured via `codify.json` for NVM)
- **IPC Validation**: All messages validated against schemas from `@codifycli/schemas` using AJV
- **Security**: Plugins spawned without direct sudo access; must request via `COMMAND_REQUEST`
- **PTY Support**: Uses `@homebridge/node-pty-prebuilt-multiarch` for interactive command execution
- **Shell History**: Commands run with `HISTORY_IGNORE` (bash) or `HISTIGNORE` (zsh) set

## Dependencies

Runtime dependencies (`@codifycli/schemas`, validation libraries, PTY) vs dev dependencies (`@codifycli/plugin-core` for development).

## Environment Variables

- `DEBUG`: Enable plugin debug mode with breakpoint
- `VITE_CODIFY_TEST_JWT`: Required for tests that need Codify credentials
Loading