This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
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.
# Run tests
npm test
# Build the project
npm run prepublishOnly
# Start the project (for testing)
npm startTests use Vitest. To run a specific test file:
npx vitest src/test-utils.test.tsTo run tests matching a pattern:
npx vitest --grep "pattern"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.osfield - 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
DEBUGenv 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
sudousage (must userequiresRootoption) - 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()
- Test creates
PluginProcesswhich forks plugin with IPC enabled - Test sends IPC messages (e.g.,
{cmd: 'plan', data: {...}, requestId: '...'} - Plugin processes request and may send request messages back (e.g.,
COMMAND_REQUEST) PluginProcessintercepts requests, executes viaspawnSafe(), sends response- Plugin completes and sends final response matching original
requestId
Typical test structure:
// 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
}
}
});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
osfield means runs on all platforms - Implemented in
PluginTester.fullTest()usinggetPlatformOs()
- 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.jsonfor NVM) - IPC Validation: All messages validated against schemas from
@codifycli/schemasusing AJV - Security: Plugins spawned without direct sudo access; must request via
COMMAND_REQUEST - PTY Support: Uses
@homebridge/node-pty-prebuilt-multiarchfor interactive command execution - Shell History: Commands run with
HISTORY_IGNORE(bash) orHISTIGNORE(zsh) set
Runtime dependencies (@codifycli/schemas, validation libraries, PTY) vs dev dependencies (@codifycli/plugin-core for development).
DEBUG: Enable plugin debug mode with breakpointVITE_CODIFY_TEST_JWT: Required for tests that need Codify credentials