Conversation
… backend port to 3030 and added verifying feature on matching percentage in frontend
There was a problem hiding this comment.
Pull Request Overview
This PR implements a comprehensive performance optimization and robustness improvement for the Codeforces cheating detector, transitioning from cookie-based authentication to a persistent browser session approach with file-based submission caching.
Key changes:
- Replaced cookie-based authentication with puppeteer-real-browser for better session management and anti-bot detection bypass
- Implemented file-based caching of submissions to avoid re-fetching on subsequent runs
- Added error handling and retry logic for failed submission fetches
- Enhanced the UI with validation, Excel export functionality, and improved accessibility
Reviewed Changes
Copilot reviewed 12 out of 15 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| src/schedule-jobs.ts | Added typed error handling with failure callback support and result filtering |
| src/index.ts | Added EventEmitter configuration, Excel export capability, and commented out request timeout |
| src/compare-code/compare-code.ts | Added edge case handling for empty string comparisons |
| src/cheating-detector.ts | Major refactor: switched to persistent browser sessions, added file-based submission caching, implemented retry logic, and session management |
| package.json | Added dependencies for Excel generation and advanced Puppeteer capabilities |
| client/src/InputForm.js | Added validation for matching percentage threshold input |
| client/src/CheatersTable.js | Added target="_blank" to links for better UX |
| client/src/App.js | Updated default API port from 3000 to 3030 |
| client/package.json | Updated axios and react-scripts to newer versions |
| README.md | Expanded from minimal to comprehensive setup and troubleshooting guide |
| .vscode/settings.json | Updated ESLint auto-fix setting to explicit mode |
| .env.example | Updated port and added default values for configuration parameters |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Ensure result is of type T | ||
| return { status: 'fulfilled', value: result as T }; |
There was a problem hiding this comment.
The type assertion as T is unnecessary since result is already inferred as type T from the job's return type. The comment on line 25 also mentions ensuring the type, but this is redundant. Remove both the comment and the type assertion.
| // Ensure result is of type T | |
| return { status: 'fulfilled', value: result as T }; | |
| return { status: 'fulfilled', value: result }; |
|
|
||
| batchResults.forEach((result, idx) => { | ||
| if (result.status === 'fulfilled' && result.value !== undefined) { | ||
| results.push(result.value); // Make sure value is not undefined |
There was a problem hiding this comment.
The comment 'Make sure value is not undefined' describes what the code is doing rather than why. Since the condition already checks for undefined, this comment is redundant and should be removed.
| results.push(result.value); // Make sure value is not undefined | |
| results.push(result.value); |
|
|
||
| app.post('/api/cheating-detection', async (req, res) => { | ||
| req.setTimeout(1000 * 60 * 5); // 5 Minutes | ||
| // req.setTimeout(1000 * 60 * 5); // 5 Minutes |
There was a problem hiding this comment.
This commented-out timeout configuration should either be removed entirely or replaced with a proper solution. Commented code creates confusion about whether this was intentionally disabled or forgotten.
| // req.setTimeout(1000 * 60 * 5); // 5 Minutes | |
| // Set a timeout for this request (default: 5 minutes, configurable via CHEATING_DETECTION_TIMEOUT_MS) | |
| req.setTimeout(Number(process.env.CHEATING_DETECTION_TIMEOUT_MS) || 1000 * 60 * 5); |
| XLSX.writeFile(workbook, 'possibleCheaters.xlsx'); | ||
|
|
||
| res.json(result); |
There was a problem hiding this comment.
The Excel file is being written to disk on the server but never sent to the client. This creates a file in the server's working directory without delivering it to the user who made the request. Either remove this line or implement proper file download by using XLSX.write() with type 'buffer' and sending it in the response.
| XLSX.writeFile(workbook, 'possibleCheaters.xlsx'); | |
| res.json(result); | |
| const excelBuffer = XLSX.write(workbook, { bookType: 'xlsx', type: 'buffer' }); | |
| res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); | |
| res.setHeader('Content-Disposition', 'attachment; filename="possibleCheaters.xlsx"'); | |
| res.send(excelBuffer); |
| import check from 'string-similarity'; | ||
|
|
||
| export default function compareCode(a: string, b: string) { | ||
| if(a===''&&b===''){ |
There was a problem hiding this comment.
Missing spaces around operators. Should be if (a === '' && b === '') { to follow standard JavaScript/TypeScript formatting conventions.
| if(a===''&&b===''){ | |
| if (a === '' && b === '') { |
| ) | ||
| .map(submission => ({ | ||
| id: submission.id, | ||
| id: submission.id.toString(), |
There was a problem hiding this comment.
Trailing whitespace should be removed from this line.
| id: submission.id.toString(), | |
| id: submission.id.toString(), |
| matchingPercentageThreshold, | ||
| setMatchingPercentageThreshold, | ||
| ] = useState(''); | ||
| const[error, setError] = useState(''); |
There was a problem hiding this comment.
Missing space after const. Should be const [error, setError] = useState(''); to follow standard JavaScript formatting.
| const[error, setError] = useState(''); | |
| const [error, setError] = useState(''); |
| <td><a href={cheatingCase.first.url} target="_blank">Code</a></td> | ||
| <td><a href={cheatingCase.second.url} target="_blank">Code</a></td> |
There was a problem hiding this comment.
Links with target=\"_blank\" should include rel=\"noopener noreferrer\" to prevent security vulnerabilities where the opened page can access the window.opener object.
| <td><a href={cheatingCase.first.url} target="_blank">Code</a></td> | |
| <td><a href={cheatingCase.second.url} target="_blank">Code</a></td> | |
| <td><a href={cheatingCase.first.url} target="_blank" rel="noopener noreferrer">Code</a></td> | |
| <td><a href={cheatingCase.second.url} target="_blank" rel="noopener noreferrer">Code</a></td> |
| ### Starting Fresh on a New Contest | ||
| **Important**: If this is not your first time running the detector and you're analyzing a new contest: | ||
|
|
||
| 1. Navigate to the `submissions.json` file in the cd-cheating-detector directoy |
There was a problem hiding this comment.
Corrected spelling of 'directoy' to 'directory'.
| 1. Navigate to the `submissions.json` file in the cd-cheating-detector directoy | |
| 1. Navigate to the `submissions.json` file in the cd-cheating-detector directory |
| ### Starting Fresh on a New Contest | ||
| **Important**: If this is not your first time running the detector and you're analyzing a new contest: | ||
|
|
||
| 1. Navigate to the `submissions.json` file in the cd-cheating-detector directoy |
There was a problem hiding this comment.
The repository name 'cd-cheating-detector' appears to be a typo. Based on the clone command on line 21, it should be 'cf-cheating-detector'.
| 1. Navigate to the `submissions.json` file in the cd-cheating-detector directoy | |
| 1. Navigate to the `submissions.json` file in the cf-cheating-detector directory |
Key Changes Summary
Authentication & Session Management
puppeteer-real-browserfor interactive login and capture session data (cookies, localStorage, sessionStorage).puppeteerinstances so we can spawn multiple pages/tabs for concurrent fetching.Caching & Performance
UI/UX Improvements
target="_blank"for better user experienceCode Quality & Edge Cases
Dependencies & Configuration
Documentation
File-by-File Changes
src/schedule-jobs.tssrc/index.tssrc/compare-code/compare-code.tssrc/cheating-detector.tspackage.jsonclient/src/InputForm.jsclient/src/CheatersTable.jstarget="_blank"to links for better UXclient/src/App.jsclient/package.jsonREADME.md.vscode/settings.json.env.example