---
phase: 09-ci-pipeline
plan: 04
type: execute
wave: 3
depends_on: ["09-02", "09-03"]
files_modified:
  - .gitea/workflows/build.yaml
autonomous: false

user_setup:
  - service: slack
    why: "Pipeline failure notifications"
    env_vars:
      - name: SLACK_WEBHOOK_URL
        source: "Slack App settings -> Incoming Webhooks -> Create new webhook -> Copy URL"
    dashboard_config:
      - task: "Create Slack app with incoming webhook"
        location: "https://api.slack.com/apps -> Create New App -> From scratch -> Add Incoming Webhooks"

must_haves:
  truths:
    - "Pipeline runs type checking before Docker build"
    - "Pipeline runs unit tests with coverage before Docker build"
    - "Pipeline runs E2E tests before Docker build"
    - "Pipeline fails fast when tests or type checking fail"
    - "Slack notification sent on pipeline failure"
    - "Test artifacts (coverage, playwright report) are uploaded"
  artifacts:
    - path: ".gitea/workflows/build.yaml"
      provides: "CI pipeline with test jobs"
      contains: "npm run check"
    - path: ".gitea/workflows/build.yaml"
      provides: "Unit test step"
      contains: "npm run test:coverage"
    - path: ".gitea/workflows/build.yaml"
      provides: "E2E test step"
      contains: "npm run test:e2e"
  key_links:
    - from: ".gitea/workflows/build.yaml"
      to: "package.json scripts"
      via: "npm run commands"
      pattern: "npm run (check|test:coverage|test:e2e)"
    - from: "build job"
      to: "test job"
      via: "needs: test"
      pattern: "needs:\\s*test"
---

<objective>
Integrate tests into Gitea Actions pipeline with fail-fast behavior and Slack notifications.

Purpose: Ensure tests run automatically on every push/PR and block deployment when tests fail. This is the final piece that makes the test infrastructure actually protect production.

Output: Updated CI workflow with test job that runs before build, fail-fast on errors, and Slack notification on failure.
</objective>

<execution_context>
@/home/tho/.claude/get-shit-done/workflows/execute-plan.md
@/home/tho/.claude/get-shit-done/templates/summary.md
</execution_context>

<context>
@.planning/PROJECT.md
@.planning/phases/09-ci-pipeline/09-RESEARCH.md
@.planning/phases/09-ci-pipeline/09-02-SUMMARY.md
@.planning/phases/09-ci-pipeline/09-03-SUMMARY.md

@.gitea/workflows/build.yaml
@package.json
</context>

<tasks>

<task type="auto">
  <name>Task 1: Add test job to CI pipeline</name>
  <files>.gitea/workflows/build.yaml</files>
  <action>
Update .gitea/workflows/build.yaml to add a test job that runs BEFORE build:

1. Add new `test` job at the beginning of jobs section:
```yaml
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Run type check
        run: npm run check -- --output machine

      - name: Install Playwright browsers
        run: npx playwright install --with-deps chromium

      - name: Run unit tests with coverage
        run: npm run test:coverage

      - name: Run E2E tests
        run: npm run test:e2e
        env:
          CI: true

      - name: Upload test artifacts
        uses: actions/upload-artifact@v4
        if: always()
        with:
          name: test-results
          path: |
            coverage/
            playwright-report/
            test-results/
          retention-days: 7
```

2. Modify existing `build` job to depend on test:
```yaml
  build:
    needs: test
    runs-on: ubuntu-latest
    # ... existing steps ...
```

This ensures build only runs if tests pass (fail-fast behavior).
  </action>
  <verify>
YAML syntax is valid: `python3 -c "import yaml; yaml.safe_load(open('.gitea/workflows/build.yaml'))"`
Build job has `needs: test` dependency
  </verify>
  <done>Test job added to pipeline. Build job depends on test job (fail-fast).</done>
</task>

<task type="auto">
  <name>Task 2: Add Slack notification on failure</name>
  <files>.gitea/workflows/build.yaml</files>
  <action>
Add a notify job that runs on failure:

```yaml
  notify:
    needs: [test, build]
    runs-on: ubuntu-latest
    if: failure()
    steps:
      - name: Notify Slack on failure
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
        run: |
          curl -X POST -H 'Content-type: application/json' \
            --data "{\"text\":\"Pipeline failed for ${{ gitea.repository }} on ${{ gitea.ref }}\"}" \
            $SLACK_WEBHOOK_URL
```

Note: Using direct curl to Slack webhook rather than a GitHub Action for maximum Gitea compatibility (per RESEARCH.md recommendation).

The SLACK_WEBHOOK_URL secret must be configured in Gitea repository settings by the user (documented in user_setup frontmatter).
  </action>
  <verify>
YAML syntax is valid
Notify job has `if: failure()` condition
Notify job depends on both test and build
  </verify>
  <done>Slack notification configured for pipeline failures.</done>
</task>

<task type="checkpoint:human-verify" gate="blocking">
  <what-built>Complete CI pipeline with test job, fail-fast behavior, artifact upload, and Slack notification</what-built>
  <how-to-verify>
1. Review the updated .gitea/workflows/build.yaml file structure
2. Verify the job dependency chain: test -> build -> (notify on failure)
3. Confirm test job includes all required steps:
   - Type checking (svelte-check)
   - Unit tests with coverage (vitest)
   - E2E tests (playwright)
4. If ready to test in CI:
   - Push a commit to trigger the pipeline
   - Monitor Gitea Actions for the test job execution
   - Verify build job waits for test job to complete
5. (Optional) Set up SLACK_WEBHOOK_URL secret in Gitea to test failure notifications
  </how-to-verify>
  <resume-signal>Type "approved" to confirm CI pipeline is correctly configured, or describe any issues found</resume-signal>
</task>

</tasks>

<verification>
1. .gitea/workflows/build.yaml has test job with:
   - Type checking step
   - Unit test with coverage step
   - E2E test step
   - Artifact upload step
2. Build job has `needs: test` (fail-fast)
3. Notify job runs on failure with Slack webhook
4. YAML is valid syntax
5. Pipeline can be triggered on push/PR
</verification>

<success_criteria>
- CI-02 satisfied: Unit tests run in pipeline before build
- CI-03 satisfied: Type checking runs in pipeline
- CI-04 satisfied: E2E tests run in pipeline
- CI-05 satisfied: Pipeline fails fast on test/type errors (needs: test)
- Slack notification on failure (per CONTEXT.md decision)
- Test artifacts uploaded for debugging failed runs
</success_criteria>

<output>
After completion, create `.planning/phases/09-ci-pipeline/09-04-SUMMARY.md`
</output>
