Testing Strategy and Verification Gates
Relevant source files
The following files were used as context for generating this wiki page:
The testing strategy for the oh-my-pi-plugin-morph project is built around a combination of static analysis, automated unit testing, and runtime verification gates. These gates ensure that code changes maintain functionality, security, and performance standards before they are integrated or released. The strategy specifically focuses on safeguarding file operations, validating AI-generated content, and maintaining strict release discipline for the plugin's lifecycle.
Verification gates are implemented both as pre-commit requirements for developers and as automated logic within the codebase itself. These gates prevent common issues such as "marker leakage" in AI edits, catastrophic code truncation during merges, and unauthorized file system access.
Developer Verification Gates
Developers are required to pass specific gates before pushing changes. These gates are exposed through native repository scripts and specialized scanning tools.
Core Command Gates
The project defines two primary commands for code verification:
- Typechecking:
bun run typecheck(executestsc --noEmit) to ensure type safety across the TypeScript codebase. - Unit Testing:
bun test ./test(executes the Bun test runner) to verify logic and regressions.
Sources: package.json:9-10, AGENTS.md:38-40
Documentation and Root Scans
For changes involving documentation or root-level files, specific scanning procedures are required:
- Markdown Scans: For files under
docs, useomp ttsr scan --json docs. - Root Document Scans: For
README.mdorCHANGELOG.md, a repo-root scan filtered formd-ai-formatting-tellsmust be used to catch AI-related formatting rules that standard single-file scans might miss.
Sources: AGENTS.md:43-45
Runtime Verification Gates
The plugin implements automated safety checks within its core tools, particularly within fast_edit, to prevent destructive or unsafe operations during execution.
Logic Flow of Edit Verification
When the fast_edit tool merges code, it passes through a series of verification gates before any data is written to the disk.
Sources: src/tools/morph-edit.ts:133-176
Key Verification Functions
| Function | Purpose | Logic/Criteria |
|---|---|---|
detectMarkerLeakage | Prevents AI from leaving literal placeholders in final code. | Triggers if mergedCode contains EXISTING_CODE_MARKER when the original file did not. |
detectCatastrophicTruncation | Prevents unintended massive code deletion. | Triggers if charLoss > 60% AND lineLoss > 50% simultaneously when markers are used. |
resolveFilepath | Ensures security and containment. | Rejects absolute paths, directory escapes (..), and unsafe symlink targets. |
Sources: src/format.ts:86-126, src/tools/morph-edit.ts:153-176
Code Snippet: Truncation Gate Logic
export function detectCatastrophicTruncation(
originalCode: string,
mergedCode: string,
hasMarkers: boolean,
): TruncationCheck {
const charLoss = (originalCode.length - mergedCode.length) / originalCode.length;
const lineLoss = (originalLineCount - mergedLineCount) / originalLineCount;
return {
triggered: hasMarkers && charLoss > 0.6 && lineLoss > 0.5,
charLoss,
lineLoss,
};
}
Sources: src/format.ts:110-123
Release Verification Gates
The project adheres to a "Release Discipline" contract to ensure metadata consistency across the package.
- Version Synchronisation: Every update must increment the
versioninpackage.jsonand thePLUGIN_VERSIONinsrc/config.tssimultaneously. - Changelog Requirement: The
CHANGELOG.mdmust be updated from an[Unreleased]heading to a dated version heading matching the code version before any commit or push.
Sources: AGENTS.md:5-7, src/config.ts:17
Automated Test Suites
The automated test suite in test/morph.test.ts provides comprehensive coverage for the verification logic.
Test Coverage Areas
- Format Helpers: Validates XML escaping for WarpGrep results to prevent markup injection and ensures markdown fence normalization.
- Path Resolution: Tests the
resolveFilepathfunction against absolute paths, escaping paths, and symlink containment (ensuring symlinks don't point outside the workspace). - Tool Execution: Mocks Morph API responses to test how tools like
fast_editandfastcompacthandle successful results, API errors, and abort signals. - Compaction Bridge: Verifies that the compaction hook correctly yields to native strategies when appropriate (e.g., when
remoteEnabledis false or during unfocusedsnapcompact).
Sources: test/morph.test.ts:182-320, test/morph.test.ts:397-440, CHANGELOG.md:12-14
Summary
The testing strategy for oh-my-pi-plugin-morph is designed to provide a layered defense against integration errors and destructive AI behaviors. By combining developer-led verification (typechecks, scans) with runtime safety logic (truncation checks, path resolution), the system ensures that the plugin remains reliable even when dealing with non-deterministic LLM outputs. Strict release discipline further ensures that the plugin's metadata remains a reliable contract for users and agents.