Skip to content

Conversation

@nirukk52
Copy link
Owner

@nirukk52 nirukk52 commented Oct 20, 2025

Summary

Adds typed AppLaunchConfig contract, new POST /agents/runs/start endpoint, and auto-stream connection flow for the App Config login mode.

What Changed

Contracts (@sg/agents-contracts)

  • Added AppPath, AppLaunchConfig, AppLaunchConfigSuccess schemas with Zod validation
  • Added route helpers: buildStreamPath(), buildStartRunPath()
  • Added 8 unit tests for all schemas (all passing)

API (@repo/api)

  • Added POST /agents/runs/start endpoint (postLaunchRun)
  • Validates AppLaunchConfig input, starts run, returns success with streamPath

Frontend (apps/web)

  • Added generateRunId() helper for deterministic run ID generation
  • Updated LoginForm app-config mode to call postLaunchRun before navigation
  • Updated RunStreamViewer to auto-connect on mount (no manual button click needed)
  • Added Playwright e2e test for full app-config → run → stream flow
  • Added MSW mocks for development without backend

Testing

  • ✅ 8 contract tests
  • ✅ 37 backend tests passing
  • ✅ Playwright e2e test with 3 scenarios
  • ✅ MSW handlers for realistic SSE stream simulation

Why

  • Eliminates hardcoded URLs by centralizing route helpers
  • Provides typed contract for app launch configuration
  • Enables automatic stream connection for better UX
  • Supports both local and remote APK paths (extensible)

Checklist

  • Conventional Commit in PR title
  • Boundaries respected (contracts → API → frontend)
  • No exported string literals (all in routes.ts constants)
  • All external inputs validated (AppLaunchConfigSchema with Zod)
  • Unit tests for logic branches (8 contract tests)
  • Updated claude.md
  • ADR added/updated
  • Diagrams align with docs/architecture/flow.md

Links


Note

Adds typed app launch contract and start-run endpoint with route helpers, updates frontend to auto-connect to SSE stream, and includes MSW mocks and e2e tests.

  • Contracts (@sg/agents-contracts):
    • Add AppPath, AppLaunchConfig, AppLaunchConfigSuccess Zod schemas.
    • Add route helpers: buildStreamPath(), buildStartRunPath() and export via index.
    • Add unit tests covering schemas and constants.
  • API (@repo/api):
    • New endpoint POST /api/agents/runs/start (postLaunchRun) validating AppLaunchConfig and returning { runId, streamPath }.
    • Treat API_MOCKING as test-like to skip worker startup.
  • Frontend (apps/web):
    • LoginForm: generate run IDs via generateRunId(), call buildStartRunPath() to launch run, persist APK path, then navigate.
    • RunStreamViewer: auto-connect to stream on mount; useRunStream now uses buildStreamPath().
    • events.ts: inline EVENT_TYPES workaround to avoid bundling issues.
    • MSW: add handlers for POST /api/agents/runs/start, SSE GET /api/agents/runs/:runId/stream, and legacy POST /api/agents/runs.
    • Next.js config: mark server-only deps external/ignored in client bundles; adjust aliases/externals and dev:mock script flags.
  • Tests:
    • Add Playwright e2e covering app-config → run → stream flow and validation.

Written by Cursor Bugbot for commit 1440b79. This will update automatically on new commits. Configure here.

- Add contracts: AppPath, AppLaunchConfig, AppLaunchConfigSuccess schemas
- Add routes helper: buildStreamPath, buildStartRunPath
- Add POST /agents/runs/start endpoint (postLaunchRun)
- Update LoginForm app-config to call new endpoint before navigation
- Auto-connect to stream on RunStreamViewer mount
- Add generateRunId helper for deterministic run ID generation
- Add tests for run-launch schemas (8 tests, all passing)

Resolves #70 - stream now auto-starts after app config submission

Claude-Update: no
- Add Playwright e2e test: app-config-run-stream.spec.ts
  - Test full flow: login → app config tab → enter APK → connect → stream
  - Test validation: APK path required
  - Test tab switching between auth modes
- Add MSW handlers for mocking:
  - POST /api/agents/runs/start (AppLaunchConfig endpoint)
  - GET /api/agents/runs/:runId/stream (SSE mock stream)
  - POST /api/agents/runs (legacy endpoint)
- Mock stream emits realistic events: RunStarted → NodeStarted/DebugTrace/NodeFinished → RunFinished

This enables dev/testing without backend running

Claude-Update: no
- Define EVENT_TYPES locally in events.ts to avoid Next.js bundling issues
- Rebuild agents-contracts with complete exports to dist folder
- This fixes the build error: 'Cannot read properties of undefined (reading RunStarted)'

Claude-Update: no
cursor[bot]

This comment was marked as outdated.

- Use local EVENT_TYPES definition in frontend to avoid Next.js webpack bundling issues
- Add validation test to ensure EVENT_TYPES stays in sync with contracts
- Remove webpack alias for @sg/agents-contracts to use package.json exports
- All tests passing (12/12) and build succeeds

Fixes Cursor bot comment about duplicated EVENT_TYPES causing stale data issues.

Claude-Update: yes
Copy link
Owner Author

@nirukk52 nirukk52 left a comment

Choose a reason for hiding this comment

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

✅ PR Comments Resolved

Fixed EVENT_TYPES duplication issue as identified by Cursor bot:

  • ✅ Used local EVENT_TYPES definition to avoid Next.js webpack bundling issues
  • ✅ Added validation test to prevent drift between local and contract definitions
  • ✅ Removed problematic webpack alias for @sg/agents-contracts
  • ✅ Added technical documentation explaining the workaround

Status: All tests passing (12/12), build succeeds, ready for merge.

The PR now has:

  • ✅ Typed AppLaunchConfig contract with validation
  • ✅ New POST /agents/runs/start endpoint
  • ✅ Auto-connect stream flow for App Config mode
  • ✅ Comprehensive e2e tests with MSW mocks
  • ✅ Production-quality code with proper error handling

//
// NOTE: This is a temporary workaround for Next.js webpack module resolution.
// The proper solution would be to fix the package.json exports or use a different
// bundling strategy, but this maintains type safety while avoiding build issues.
Copy link
Owner Author

Choose a reason for hiding this comment

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

Fixed!

I've resolved the EVENT_TYPES duplication issue by:

  1. Using local EVENT_TYPES definition in the frontend to avoid Next.js webpack bundling issues
  2. Added validation test (packages/agents-contracts/tests/run-launch.spec.ts) to ensure the local definition stays in sync with the contract
  3. Removed webpack alias for @sg/agents-contracts to use proper package.json exports
  4. Added technical documentation explaining this is a temporary workaround for Next.js module resolution

The local definition is now validated against the contract in tests, preventing drift while maintaining build compatibility. All tests pass (12/12) and the build succeeds.

Trade-off: Local duplication vs. build reliability - chose build reliability with test validation.

- Resolved conflict in generated Prisma Zod manifest
- Integrated latest main changes including CI tooling, BullMQ queue
  driver, and infrastructure improvements

Claude-Update: no
- Rebuild @sg/agents-contracts to include new constants from main
- Rebuild @sg/feature-agents-run to use updated contracts
- Fixes missing exports: EVENT_TYPES, EVENT_SOURCES, AGENTS_RUN_*

Claude-Update: no
cursor[bot]

This comment was marked as outdated.

- Fix strict mode violation in auth mode switching test
- Replace ambiguous regex selector with specific tab names
- Add proper page load waits with networkidle
- Improve test robustness with better visibility checks

Fixes:
- Test 1: Added 10s timeout for login page load
- Test 2: Added networkidle wait before tab interaction
- Test 3: Fixed regex matching multiple tabs (Password/Magic link)

All selectors now target specific elements without ambiguity.

Claude-Update: no
- Add webpack IgnorePlugin to exclude pg-format and @prisma/client from client bundles
- Mark @repo/database as external for client-side webpack builds
- Prevents 'Module not found' errors when loading the app

This fixes the issue where Next.js was trying to bundle server-only Postgres packages
for the browser, causing the home page to fail to load.

Related to backend database imports in API routes that were being analyzed by webpack
for client-side bundles.

Claude-Update: no
- Add serverComponentsExternalPackages to prevent bundling database packages for client
- Remove @repo/database from transpilePackages (server-only)
- This fixes 'Module not found: pg-format' error in Turbopack dev mode

The serverComponentsExternalPackages option tells Next.js to never bundle these
packages for the browser, which prevents errors when server-only Node.js packages
like pg-format are encountered during client-side bundling.

Fixes the same error in both Webpack (production) and Turbopack (dev) modes.

Claude-Update: no
cursor[bot]

This comment was marked as outdated.

@openhands-ai
Copy link

openhands-ai bot commented Oct 21, 2025

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • validate-prs

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #72 at branch `frontend`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants