name: Notebook CI

on:
  push:
    paths:
      - 'notebooks/**'
  pull_request:
    paths:
      - 'notebooks/**'

jobs:
  notebook-smoke:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Install dependencies
        run: |
          pip install papermill jupytext nbformat
          python -m ipykernel install --user --name python3

      - name: Execute system health notebook
        run: |
          papermill notebooks/agent_task_system_health.ipynb /tmp/output.ipynb \
            -p threshold 0.5 \
            -p hostname ci-runner

      - name: Verify output has results
        run: |
          python -c "
          import json
          nb = json.load(open('/tmp/output.ipynb'))
          code_cells = [c for c in nb['cells'] if c['cell_type'] == 'code']
          outputs = [c.get('outputs', []) for c in code_cells]
          total_outputs = sum(len(o) for o in outputs)
          assert total_outputs > 0, 'Notebook produced no outputs'
          print(f'Notebook executed successfully with {total_outputs} output(s)')
          "
