Skip to content
Merged
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
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: PredAI Tests

on:
pull_request:
branches: [ main, master, develop ]
push:
branches: [ main, master, develop ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Cache pip packages
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('predai/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r predai/requirements.txt
- name: Run unit tests
run: |
python -m unittest test_predai.py -v
- name: Test summary
if: always()
run: |
if [ $? -eq 0 ]; then
Comment on lines +37 to +42
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the issue in run_all script, this conditional references $? after other commands have executed (the echo statements on lines 43-45). The $? will reflect the exit status of the echo command, not the unittest command on line 37. The exit status should be captured immediately after the test command completes.

Suggested change
python -m unittest test_predai.py -v
- name: Test summary
if: always()
run: |
if [ $? -eq 0 ]; then
if python -m unittest test_predai.py -v; then

Copilot uses AI. Check for mistakes.
echo "✅ All tests passed successfully!"
else
echo "❌ Some tests failed"
exit 1
fi
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ wheels/
*.egg-info/
.installed.cfg
*.egg
.lr_find*
.pytest_cache/
events.out.*
lightning_logs/*

# Virtual environments
venv/
Expand Down
2 changes: 1 addition & 1 deletion predai/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
neuralprophet==0.9.0
neuralprophet
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from a pinned neuralprophet==0.9.0 to an unpinned neuralprophet introduces a supply-chain risk: future installs will always pull the latest version from PyPI, which could be compromised or contain breaking changes and will run with the same privileges as your test/build environment. An attacker who gains control over the neuralprophet package (or its latest release) could execute arbitrary code during pip install -r predai/requirements.txt in CI or developer environments. To reduce this risk, pin neuralprophet to a specific version (or a carefully managed range) and update it intentionally after review.

Copilot uses AI. Check for mistakes.
requests
aiohttp
pyyaml
17 changes: 15 additions & 2 deletions predai/rootfs/predai.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
import math
import yaml

# Fix for PyTorch 2.6 weights_only=True default
# Fix for PyTorch 2.6+ weights_only=True default
# Add NeuralProphet classes to safe globals for checkpoint loading
try:
import torch
import torch.serialization
from neuralprophet.configure import (
ConfigSeasonality,
Expand All @@ -27,6 +28,7 @@
ConfigEvents,
ConfigCountryHolidays,
)
from collections import OrderedDict

# Add all NeuralProphet configuration classes to safe globals
torch.serialization.add_safe_globals([
Expand All @@ -38,7 +40,17 @@
ConfigLagged,
ConfigEvents,
ConfigCountryHolidays,
OrderedDict,
])

# Monkey-patch torch.load to use weights_only=False by default
# This is needed for PyTorch 2.6+ compatibility with PyTorch Lightning
_original_torch_load = torch.load
def _patched_torch_load(*args, **kwargs):
if 'weights_only' not in kwargs:
kwargs['weights_only'] = False
return _original_torch_load(*args, **kwargs)
torch.load = _patched_torch_load
except (ImportError, AttributeError):
# If torch.serialization or classes are not available, continue without the fix
# This allows backward compatibility with older PyTorch versions
Expand Down Expand Up @@ -483,4 +495,5 @@ async def main():
break
await asyncio.sleep(60)

asyncio.run(main())
if __name__ == "__main__":
asyncio.run(main())
33 changes: 33 additions & 0 deletions run_all
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
# Run all PredAI unit tests

set -e

# Check if virtual environment exists
if [ ! -d "venv" ]; then
echo "Error: Virtual environment not found!"
echo "Please run ./setup.csh first to create the environment"
exit 1
fi

# Activate virtual environment
echo "Activating virtual environment..."
source venv/bin/activate

# Run the tests
echo ""
echo "Running PredAI unit tests..."
echo "================================"
python -m unittest test_predai.py -v

# Check test result
if [ $? -eq 0 ]; then
echo ""
echo "================================"
echo "✅ All tests passed successfully!"
else
echo ""
echo "================================"
echo "❌ Some tests failed"
exit 1
fi
Comment on lines +21 to +33
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The set -e flag on line 4 causes the script to exit immediately if any command fails. This means if the unittest command on line 21 fails, the script will exit before reaching this conditional block. The test result check (lines 24-33) will never execute in case of test failure. Either remove set -e or capture the exit status before the script exits (e.g., using || true after the unittest command and then checking $?).

Copilot uses AI. Check for mistakes.
21 changes: 21 additions & 0 deletions setup.csh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Setup script for PredAI test environment
# Creates a virtual environment and installs dependencies

echo "Creating Python virtual environment..."
python3 -m venv venv

echo "Activating virtual environment..."
source venv/bin/activate
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source command used here is a bash/sh command, but this is a csh script (indicated by the .csh extension). In csh/tcsh, you should use 'source venv/bin/activate.csh' instead of 'source venv/bin/activate'. The bash activation script won't work properly in a csh shell.

Suggested change
source venv/bin/activate
source venv/bin/activate.csh

Copilot uses AI. Check for mistakes.

echo "Installing dependencies..."
python -m pip install --upgrade pip
python -m pip install -r predai/requirements.txt

echo ""
echo "Setup complete!"
echo "To activate the environment manually, run:"
echo " source venv/bin/activate.csh"
echo ""
echo "To run tests, execute:"
echo " ./run_all"

Comment on lines +1 to +21
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses 'echo' commands which are bash/sh syntax, but the file has a .csh extension indicating it should be a C shell script. C shell uses different syntax for commands and doesn't support echo in the same way. Either rename this file to setup.sh and add a proper shebang (#!/bin/bash), or rewrite it using proper csh syntax.

Copilot uses AI. Check for mistakes.
Loading