-
Notifications
You must be signed in to change notification settings - Fork 0
Staging #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Staging #98
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d3cac9a
feat: The AI backend will now intentionally target and disable specif…
Shashank0701-byte 4e81223
feat(chaos): add realistic AI timeout interactions and overtime UI
Shashank0701-byte 8c51862
fix(chaos): await route params to resolve Next.js 15 build failure
Shashank0701-byte 2f01055
Merge pull request #96 from Shashank0701-byte/feature/chaos
Shashank0701-byte 4ae144a
eat(simulation): add dynamic load engine and final validation phase
Shashank0701-byte 47b7a98
Merge pull request #97 from Shashank0701-byte/feature/chaos
Shashank0701-byte 85555bb
fix: Lint issues
Shashank0701-byte 8b41b76
Merge pull request #99 from Shashank0701-byte/feature/chaos
Shashank0701-byte dd9f9cb
fix: Lint and build issues
Shashank0701-byte f487e6f
Merge pull request #101 from Shashank0701-byte/feature/chaos
Shashank0701-byte b7cd350
fix: Lint and build issues
Shashank0701-byte 30bfc16
Merge pull request #102 from Shashank0701-byte/feature/chaos
Shashank0701-byte 4348409
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 737f734
Merge pull request #103 from Shashank0701-byte/coderabbitai/autofix/3…
Shashank0701-byte d14f3e1
fix: lint and build errors
Shashank0701-byte dea1543
Merge pull request #104 from Shashank0701-byte/feature/chaos
Shashank0701-byte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import dbConnect from '@/src/lib/db/mongoose'; | ||
| import InterviewSession from '@/src/lib/db/models/InterviewSession'; | ||
|
|
||
| export async function POST( | ||
| req: NextRequest, | ||
| context: { params: Promise<{ id: string }> } | ||
| ) { | ||
| try { | ||
| await dbConnect(); | ||
| const { id } = await context.params; | ||
| const { type, constraintId } = await req.json(); | ||
|
|
||
| // 1. Fetch Session | ||
| const session = await InterviewSession.findOne({ id }); | ||
| if (!session) { | ||
| return NextResponse.json({ error: 'Session not found' }, { status: 404 }); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // 2. Locate Constraint | ||
| const constraintChanges = session.constraintChanges || []; | ||
| const constraintIndex = constraintChanges.findIndex((c: { id: string }) => c.id === constraintId); | ||
| if (constraintIndex === -1) { | ||
| return NextResponse.json({ error: 'Constraint not found' }, { status: 404 }); | ||
| } | ||
|
|
||
| const constraint = constraintChanges[constraintIndex]; | ||
|
|
||
| // 3. Early Returns (already addressed or failed) | ||
| if (constraint.status === 'addressed' || (type === 'warning' && constraint.overtimeAt) || (type === 'penalty' && constraint.failedAt)) { | ||
| return NextResponse.json({ success: true, warning: 'Already processed' }); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (!session.aiMessages) session.aiMessages = []; | ||
|
|
||
| // 4. Update state depending on timeout type | ||
| if (type === 'warning') { | ||
| constraint.overtimeAt = new Date(); | ||
| session.aiMessages.push({ | ||
| role: 'interviewer', | ||
| content: `Hey, I noticed we still haven't addressed the ${constraint.title} issue. In a real-world scenario, leaving a failure like this unhandled could lead to a broader system outage. Could you walk me through how you'd mitigate this in the next 2 minutes? Let's treat this as a high-priority incident.`, | ||
| timestamp: new Date() | ||
| }); | ||
| session.markModified('constraintChanges'); | ||
| session.markModified('aiMessages'); | ||
| } else if (type === 'penalty') { | ||
| constraint.failedAt = new Date(); | ||
| // We keep status as 'active' so the UI node stays visibly broken | ||
| session.aiMessages.push({ | ||
| role: 'interviewer', | ||
| content: `Alright, time's up on the ${constraint.title} scenario. Since we weren't able to establish a complete mitigation plan in time, I'll be noting this gap in high-availability planning for the evaluation. That said, let's keep moving forward with the rest of your system design—what were you thinking for the next component?`, | ||
| timestamp: new Date() | ||
| }); | ||
| session.markModified('constraintChanges'); | ||
| session.markModified('aiMessages'); | ||
| } | ||
|
|
||
| await session.save(); | ||
|
|
||
| return NextResponse.json({ success: true, messages: session.aiMessages, constraintChanges: session.constraintChanges }); | ||
| } catch (error) { | ||
| console.error('Chaos Timeout Error:', error); | ||
| return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { NextRequest, NextResponse } from 'next/server'; | ||
| import dbConnect from '@/src/lib/db/mongoose'; | ||
| import InterviewSession from '@/src/lib/db/models/InterviewSession'; | ||
|
|
||
| export async function POST( | ||
| req: NextRequest, | ||
| context: { params: Promise<{ id: string }> } | ||
| ) { | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| await dbConnect(); | ||
| const { id } = await context.params; | ||
|
|
||
| const session = await InterviewSession.findOne({ id }); | ||
| if (!session) { | ||
| return NextResponse.json({ error: 'Session not found' }, { status: 404 }); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| if (!session.aiMessages) session.aiMessages = []; | ||
|
|
||
| // Idempotency check: Have we already sent it? | ||
| const alreadySent = session.aiMessages.some((m: { role: string; content: string }) => | ||
| m.role === 'interviewer' && m.content.includes("Final Validation Phase") | ||
| ); | ||
|
|
||
| if (alreadySent || session.status !== 'in_progress') { | ||
| return NextResponse.json({ success: true, messages: session.aiMessages }); | ||
| } | ||
|
|
||
| session.aiMessages.push({ | ||
| role: 'interviewer', | ||
| content: `**Final Validation Phase**: We have roughly 10 minutes left in the interview! It's time to test your architecture's resiliency. Please turn to the **Simulation Controls** panel, hit 'Run Test', and use the **Target Throughput** slider to simulate traffic. Talk me through how your system behaves under different load scenarios, and point out any bottlenecks.`, | ||
| timestamp: new Date() | ||
| }); | ||
| session.markModified('aiMessages'); | ||
| await session.save(); | ||
|
|
||
| return NextResponse.json({ success: true, messages: session.aiMessages }); | ||
| } catch (error) { | ||
| console.error('Final Validation Error:', error); | ||
| return NextResponse.json({ error: 'Internal server error' }, { status: 500 }); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.