Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 54 additions & 0 deletions .github/workflows/test-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Created by GitHub Copilot CLI on 2026-02-06
name: Test Build

on:
workflow_dispatch:

jobs:
init:
name: Initialize build
runs-on: ubuntu-latest
outputs:
architectures: ${{ steps.info.outputs.architectures }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Get information
id: info
uses: home-assistant/actions/helpers/info@master

test-build:
name: Test build for ${{ matrix.architecture }}
needs: init
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
architecture: ${{ fromJson(needs.init.outputs.architectures) }}
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Get base image from build.yaml
id: image
shell: bash
run: |
if [ "${{ matrix.architecture }}" = "amd64" ]; then
BUILD_FROM=$(grep -A 2 "^build_from:" build.yaml | grep "amd64:" | awk '{print $2}' | tr -d '"')
elif [ "${{ matrix.architecture }}" = "aarch64" ]; then
BUILD_FROM=$(grep -A 2 "^build_from:" build.yaml | grep "aarch64:" | awk '{print $2}' | tr -d '"')
fi
echo "BUILD_FROM=$BUILD_FROM" >> $GITHUB_OUTPUT
- name: Build image for ${{ matrix.architecture }}
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
platforms: ${{ matrix.architecture == 'amd64' && 'linux/amd64' || 'linux/arm64' }}
build-args: |
BUILD_FROM=${{ steps.image.outputs.BUILD_FROM }}
push: false
tags: homedetector:test-${{ matrix.architecture }}
49 changes: 49 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Created by GitHub Copilot CLI on 2026-02-06
name: Python Tests

on:
workflow_dispatch:

jobs:
test:
name: Run Python tests with tox
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.13'
- name: Install tox
run: pip install tox
- name: Run tox tests
run: tox
- name: Upload test reports
if: always()
uses: actions/upload-artifact@v3
with:
name: test-reports
path: |
tests/admin/report.md
tests/admin/coverage.md
tests/dns/report.md
tests/dns/coverage.md
retention-days: 30
- name: Display test results
if: always()
shell: bash
run: |
echo "## Admin Tests"
echo "### Report"
cat tests/admin/report.md
echo ""
echo "### Coverage"
cat tests/admin/coverage.md
echo ""
echo "## DNS Tests"
echo "### Report"
cat tests/dns/report.md
echo ""
echo "### Coverage"
cat tests/dns/coverage.md
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Custom Project Ignores
*.db*

# For now, let's ignore VSCode settings
.vscode/

# Opencanry
twistd.pid
opencanary.log
Expand Down Expand Up @@ -57,6 +60,8 @@ coverage.xml
.hypothesis/
.pytest_cache/
cover/
coverage.md
tests/*/report.md

# Translations
*.mo
Expand Down
63 changes: 61 additions & 2 deletions Agents.md → AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Agent Instructions for HomeDetector
<!-- Created by Copilot using model Claude Haiku 4.5 on 2026-02-01 -->
<!-- Modified by Copilot using model GPT-5 mini on 2026-02-04 -->
<!-- Modified by GitHub Copilot CLI on 2026-02-06 -->

This document provides guidance for AI agents on how to understand, modify, and contribute to the HomeDetector project.

Expand Down Expand Up @@ -50,10 +51,21 @@ The system is composed of three main Python-based components that run concurrent

## Development Workflow

### Virtual Environment
<!-- Modified by Gemini using model gemini-1.5-pro-001 on 2026-02-05 -->
This project uses `uv` to manage the Python virtual environment. All `python` and `pip` commands MUST be executed using the project's virtual environment located in the `.venv` directory. This ensures consistency and avoids conflicts with system-wide packages.

For example, use `.venv/bin/python` and `.venv/bin/pip`.

### Setup

1. The application is designed to run in a Home Assistant environment or a Docker container.
2. Dependencies for each component are listed in `requirements.txt` files within their respective directories (`admin/`, `dns/`, `opencanary/`). To set up a local development environment, you would typically create a Python virtual environment and install these dependencies.
2. Dependencies for each component are listed in `requirements.txt` files within their respective directories (`admin/`, `dns/`, `opencanary/`). To set up a local development environment, you must create a Python virtual environment using `uv` and install these dependencies into it.

```bash
uv venv
uv pip install -r admin/requirements.txt -r dns/requirements.txt -r opencanary/requirements.txt
```
3. The central database is `hd.db`, located in the `/config/` directory in the container, or the project root during local development.

### Running the Application
Expand All @@ -76,6 +88,53 @@ The `run.sh` script is the main entry point. It launches the three key processes
* The main pages are `admin.j2` (Alerts), `dns.j2` (DNS logs), and `tuning.j2` (Network/Host configuration).
* JavaScript functionality relies heavily on jQuery and the `bootstrap-table` plugin, which fetches data from the JSON API endpoints defined in `admin/web.py` (e.g., `/admin/data/alerts`). To modify frontend behavior, you will likely need to interact with the `bootstrap-table` JavaScript API.

### Testing
<!-- Modified by Gemini using model gemini-1.5-pro-001 on 2026-02-05 -->
The project uses `pytest` for unit and integration testing, and `tox` to automate the process. Tests are located in the `tests/` directory, with subdirectories for each component (`admin`, `dns`).

* **Admin Tests (`tests/admin/`)**: These tests cover the `admin/web.py` component. They use `pytest-twisted` to handle the asynchronous nature of the `twisted` web server.
* **DNS Tests (`tests/dns/`)**: These tests cover the `dns/listener.py` component.

Each test directory contains its own `requirements.txt` to specify its Python dependencies.

To run all tests and generate coverage reports, simply run `tox` from the project root:
```bash
tox
```

This will create separate virtual environments for each test suite, install the necessary dependencies, and run the tests. Coverage reports will be generated in the `htmlcov/` directory.

You can also run a specific test environment:
```bash
tox -e test-admin
tox -e test-dns
```

If you want to run the tests manually, you can still do so:
```bash
# Example for running admin tests
cd tests/admin
pip install -r requirements.txt
pytest
```

### Building the Docker Image

To build the Docker image locally using podman, use the build script located in the `tests/` directory:

```bash
tests/build.sh
```

This script automatically:
1. Detects the system architecture (x86_64/amd64 or aarch64/arm64)
2. Reads the appropriate base image from `build.yaml` based on your architecture
3. Builds the Docker image with podman using the `homedetector:latest` tag and the correct `BUILD_FROM` argument

The base images are defined in `build.yaml`:
- **amd64**: `ghcr.io/home-assistant/amd64-base:3.22`
- **aarch64**: `ghcr.io/home-assistant/aarch64-base:3.22`

### Database

* The database schema is defined and initialized in both `dns/listener.py` and `admin/web.py`.
Expand All @@ -97,7 +156,7 @@ Placement guidelines by file type:
- Markdown: place the attribution HTML comment immediately below the main title heading (the top-level `#` line).
- Python: module docstring and/or function docstring.
- CSS/JavaScript: file header comment and/or function comment.
- Shell/YAML: file header comment.
- Shell/YAML (including GitHub Workflows): file header comment as the first line.

Examples:
- "Created by Copilot using model gpt-4o on 2026-01-28"
Expand Down
4 changes: 2 additions & 2 deletions admin/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Twisted==25.5.0
Jinja2==3.1.6
Twisted==24.11.0
Jinja2==3.0.1
2 changes: 1 addition & 1 deletion dns/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
dnslib==0.9.24
netaddr==1.2.1
requests==2.32.5
requests==2.31.0
4 changes: 4 additions & 0 deletions tests/admin/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pytest
pytest-twisted
pytest-cov
tox
Loading