kcli-testing
Skill658 starsChanged 13 days agoApache-2.0View on GitHub
Guides testing and code quality for kcli. Use when writing tests, running linting, or validating changes before committing.
- Reads credentials
- Installs packages
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 63
Default storage pool configured
- Very specific: line 229
Use the TestK class pattern
- Distinctive: line 232
Use unique names to avoid conflicts
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
kcli Testing and Code Quality
Development Setup
# Create virtual environment
python3 -m venv venv
. venv/bin/activate
# Install in development mode
pip install -e .
# Install with all provider dependencies
pip install -e ".[all]"Linting
pycodestyle (PEP8)
# Lint all Python files
pycodestyle --ignore=E402,W504,E721,E722,E741 --max-line-length=120 kvirt/
# Lint specific file
pycodestyle --ignore=E402,W504,E721,E722,E741 --max-line-length=120 kvirt/config.pyIgnored codes:
E402: Module level import not at top of fileW504: Line break after binary operatorE721: Do not compare types, use isinstance()E722: Do not use bare exceptE741: Ambiguous variable name
Max line length: 120 characters
codespell (Spelling)
# Check spelling
codespell kvirt/ -L "aks"
# The -L flag ignores specific words (aks is Azure Kubernetes Service)Combined Linting (CI Script)
# Run the same linting as CI
.github/linting.shNote: The linting script excludes kvirt/bottle.py (vendored web framework) from checks.
Running Tests
Prerequisites
Tests require:
- libvirt running locally
- Default storage pool configured
- SSH keypair in
~/.kcli/
# Setup for testing
sudo mkdir -p /var/lib/libvirt/images
sudo setfacl -m u:$(id -un):rwx /var/lib/libvirt/images
mkdir -p ~/.kcli
ssh-keygen -t rsa -N '' -f ~/.kcli/id_rsa
kcli create pool -p /var/lib/libvirt/images defaultpytest Commands
# Run all tests
python -m pytest tests/test_kvirt.py -v
# Run specific test class
python -m pytest tests/test_kvirt.py::TestK -v
# Run specific test method
python -m pytest tests/test_kvirt.py::TestK::test_create_vm -v
# Run with output capture disabled
python -m pytest tests/test_kvirt.py -v -sIntegration Test Script
# Full integration test (used in CI)
.github/testing.shTest Structure
Tests are in tests/test_kvirt.py:
class TestK:
@classmethod
def setup_class(self):
# Initialize Kconfig and provider
self.config = Kconfig()
self.k = self.config.k
def test_list(self):
result = self.k.list()
assert result is not None
def test_create_vm(self):
result = self.config.create_vm(...)
assert result["result"] == "success"
@classmethod
def teardown_class(self):
# Cleanup resources
self.k.delete_network(...)
self.k.delete_pool(...)Test Plan Example
The CI uses .github/test_plan.yml for integration testing:
parameters:
pool: default
image: cirros
network: mynetwork
profile: myprofile
{{ image }}:
type: image
pool: {{ pool }}
{{ network }}:
type: network
cidr: 192.168.125.0/24
dhcp: true
{{ profile }}:
type: profile
image: {{ image }}
memory: 2048
numcpus: 2
myvm:
profile: {{ profile }}
pool: {{ pool }}Run it:
kcli create plan -f .github/test_plan.yml test_plan
kcli list plan | grep test_plan
kcli delete plan --yes test_planValidating Changes
Before Committing
# 1. Run linting
pycodestyle --ignore=E402,W504,E721,E722,E741 --max-line-length=120 kvirt/
# 2. Check spelling
codespell kvirt/ -L "aks"
# 3. Run tests (if libvirt available)
python -m pytest tests/test_kvirt.py -v
# 4. Test your specific change manually
kcli <your-command>Manual Testing Patterns
Testing Provider Changes:
# Test with debug output
kcli -d list vm
kcli -d create vm -i cirros testvm
kcli -d delete vm --yes testvmTesting Plan Changes:
# Create minimal test plan
cat > /tmp/test.yml << 'EOF'
testvm:
image: cirros
memory: 512
EOF
kcli create plan -f /tmp/test.yml mytest
kcli info plan mytest
kcli delete plan --yes mytestCI/CD Pipeline
The GitHub Actions workflow (.github/workflows/ci.yml) runs:
- Lint - pycodestyle + codespell
- Test - Integration tests with libvirt
- Release (main branch only):
- RPM via Copr
- DEB via Cloudsmith
- PyPI package
- Container image to Quay.io
Flake8 Configuration
Project uses .flake8:
[flake8]
max-line-length = 120
ignore = E722,E402,E741,W504,E721,E501Note: Flake8 config also ignores E501 (line too long) which is stricter than the CI linting script. The CI script uses pycodestyle directly without E501 ignore.
Writing New Tests
When adding tests:
- Use the
TestKclass pattern - Return
{'result': 'success'}or{'result': 'failure', 'reason': ...} - Clean up resources in
teardown_class - Use unique names to avoid conflicts
def test_new_feature(self):
# Setup
result = self.k.create_something(name="test-unique-name")
# Assert
assert result["result"] == "success"
# Cleanup (or use teardown_class)
self.k.delete_something("test-unique-name")In this repository7 other files it gives its agents.
- kcli-cluster-deploymentSkill
- kcli-configurationSkill
- kcli-ksushySkill
- kcli-plan-authoringSkill
- kcli-provider-developmentSkill
- kcliSkill
- kcli-vm-operationsSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

