cg-isolate-os-tests

Audits and refactors unit tests to prevent real OS shutdown and destructive system calls.

Updated May 16, 2026
One-click install
npx skills add https://github.com/alimtvnetwork/img-pdf-v2 --skill cg-isolate-os-tests-alimtvnetwork
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cg-isolate-os-tests
Source: https://github.com/alimtvnetwork/img-pdf-v2/tree/main/.agents/skills/cg-isolate-os-tests
Command: npx skills add https://github.com/alimtvnetwork/img-pdf-v2 --skill cg-isolate-os-tests-alimtvnetwork

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Unit tests that accidentally invoke real OS commands like shutdown, reboot, poweroff, or package managers can damage developer workstations and CI runners. This Skill audits, refactors, and validates test suites so destructive host commands are always intercepted by injectable mock executors. ## Core Features & Use Cases - Destructive Command Detection: Scans tests for direct invocations of shutdown, reboot, poweroff, init, systemctl power commands, and package managers like apt-get or Get-WindowsUpdate. - Injectable Executor Enforcement: Refactors production code to expose injectable executor functions (OSActionExecutor, FileRemover, TempDirResolver, OSCommandRunner) that tests can substitute. - Hermetic Mock Patterns: Provides before/after Go code patterns using defer-based mock restoration and fast 1s/2s duration math instead of real timers. - Use Case: A Go CLI tool schedules system shutdowns; use this Skill to refactor its tests so every power command routes through a mock executor, verifying parameters without ever touching the host OS. ## Quick Start Audit my repository's unit tests and refactor any test that could trigger a real OS shutdown, reboot, or file deletion to use injectable mock executors.

Frequently Asked Questions about cg-isolate-os-tests

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent unit tests from shutting down my machine?

Route all power commands through an injectable executor function such as DefaultOSActionExecutor, then substitute it with a mock inside tests using a defer restoration block. The mock captures parameters without invoking the host OS.

How to mock exec.Command calls in Go tests?

Define an OSCommandRunner function type wrapping cmd.Run() and expose it as a replaceable package-level variable. In tests, swap it with a mock that records the command and arguments, then restore the original with defer cleanup.

Which OS commands must never run in unit tests?

Tests must never execute shutdown, reboot, poweroff, halt, init 0 or 6, systemctl poweroff or reboot, or package managers like apt-get upgrade, Get-WindowsUpdate, and softwareupdate. These commands modify or destroy the host system state.

How do I test countdown timers without sleeping in tests?

Test duration string parsing and target time arithmetic directly, then use fast simulated delays of 1s or 2s with mock tick callbacks. Never arm real host OS timers or sleep for the full scheduled duration.

Can this approach work outside Go projects?

The skill targets polyglot stacks, but its concrete patterns and code examples are written for Go. The core principle of injectable executors and hermetic mocks applies to any language with dependency injection support.