# Agent Task: Move index.html to /landing

## Branch Information

**Working branch:** `feature/remove-index-html`
**Base branch:** `main`
**Design document:** `docs/plans/2025-12-03-move-index-html-to-landing-design.md`

Clone or checkout this branch and read the design document before starting.

## Your Mission

Implement the changes described in the design document using Red-Green-Refactor (RGR) TDD methodology. The goal is to move the landing page from the project root to `/landing` and make the root an auth-aware redirect.

## RGR Implementation Process

### Phase 1: RED - Write Failing Tests First

Before making any code changes, write tests that verify the NEW expected behavior:

**Test file:** `app/__tests__/root-redirect.test.tsx` (create new)

```typescript
// Tests to write FIRST (these should FAIL initially):

describe('Root page redirect', () => {
  it('redirects authenticated users to /dashboard', async () => {
    // Mock getServerSession to return a user
    // Render RootPage
    // Assert redirect to /dashboard
  });

  it('redirects unauthenticated users to /api/auth/signin', async () => {
    // Mock getServerSession to return null
    // Render RootPage
    // Assert redirect to /api/auth/signin
  });
});
```

**Verify tests fail:** Run `npm test -- app/__tests__/root-redirect.test.tsx` - tests MUST fail before proceeding.

### Phase 2: GREEN - Implement Minimum Code to Pass

1. **Move the file:**
   ```bash
   mkdir -p public/landing
   mv index.html public/landing/index.html
   ```

2. **Replace `app/page.tsx`** with the auth redirect implementation from the design doc.

3. **Run tests again:** `npm test -- app/__tests__/root-redirect.test.tsx` - tests MUST pass.

### Phase 3: REFACTOR - Update Documentation

Update these files to reflect the new architecture:

1. **`CLAUDE.md`** - Change the constraint about index.html
2. **`docs/REGISTRATION_FLOW_MAP.md`** - Update landing page references
3. **`OAUTH_IMPLEMENTATION.md`** - Update index.html references

## Strict Success Conditions

You MUST verify ALL of the following before considering the task complete:

### 1. Build Success
```bash
npm run build
```
**Condition:** Exit code 0, no errors

### 2. Type Check
```bash
npx tsc --noEmit
```
**Condition:** Exit code 0, no type errors

### 3. Lint Check
```bash
npx eslint app/page.tsx
```
**Condition:** Exit code 0, no lint errors

### 4. Unit Tests Pass
```bash
npm test
```
**Condition:** All tests pass, including your new root redirect tests

### 5. Manual QA Verification

Start the dev server and verify each scenario:

```bash
npm run dev
```

| Test | Steps | Expected Result | Pass? |
|------|-------|-----------------|-------|
| Root redirect (signed out) | 1. Clear cookies/incognito 2. Visit `http://localhost:3000/` | Redirects to `/api/auth/signin` | [ ] |
| Root redirect (signed in) | 1. Sign in with Google/Apple 2. Visit `http://localhost:3000/` | Redirects to `/dashboard` | [ ] |
| Landing page accessible | 1. Visit `http://localhost:3000/landing/` | Shows marketing page with pricing cards | [ ] |
| Subscribe buttons work | 1. On `/landing/`, click any Subscribe button | Redirects to sign-in (if not signed in) or Stripe checkout | [ ] |
| No 404 on landing assets | 1. Check browser console on `/landing/` | No 404 errors for images/fonts | [ ] |
| Old root path gone | 1. Verify `index.html` no longer exists at project root | File should not exist | [ ] |

### 6. Git Status Clean
```bash
git status
```
**Condition:** All changes committed, working tree clean

## Files You Will Modify

| File | Action |
|------|--------|
| `index.html` | MOVE to `public/landing/index.html` |
| `app/page.tsx` | REPLACE with auth redirect |
| `app/__tests__/root-redirect.test.tsx` | CREATE new test file |
| `CLAUDE.md` | UPDATE constraint |
| `docs/REGISTRATION_FLOW_MAP.md` | UPDATE references |
| `OAUTH_IMPLEMENTATION.md` | UPDATE references |

## Files You Must NOT Modify

- `app/api/**/*` - API routes must remain unchanged
- `lib/auth.ts` - Auth configuration must remain unchanged
- `middleware.ts` - Middleware must remain unchanged
- Any Stripe-related files

## Commit Strategy

Make atomic commits as you progress:

1. `test: add root redirect tests (RED phase)`
2. `feat: move index.html to public/landing`
3. `feat: replace root page with auth redirect (GREEN phase)`
4. `docs: update documentation for new landing page location`

## When You're Done

1. Run the full verification checklist above
2. Ensure all 6 success conditions are met
3. Push the branch: `git push -u origin feature/remove-index-html`
4. Report back with:
   - Confirmation all tests pass
   - Confirmation all manual QA scenarios pass
   - Any issues encountered and how you resolved them

## Reference: Expected Final `app/page.tsx`

```typescript
import { redirect } from 'next/navigation';
import { getServerSession } from 'next-auth/next';
import { authOptions } from '@/lib/auth';

export default async function RootPage() {
  const session = await getServerSession(authOptions);

  if (session?.user) {
    redirect('/dashboard');
  } else {
    redirect('/api/auth/signin');
  }
}
```

---

**Important:** Do not skip the RED phase. Tests must fail first to prove they're actually testing the new behavior. If tests pass before you make changes, your tests are wrong.
