core: typing for tsdoc#1164
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughAdds concrete contest/training status types (ContestJournalEntry, ContestDetailEntry, ContestStatusDoc, TrainingStatusDoc), updates ContestRule signatures to use ContestStatusDoc and journal arrays, propagates these types through handlers and models, stringifies scoreboard/export cells, keys several maps by ObjectId.toHexString(), and updates XCPCIO submission/journal handling and an upgrade script for type compatibility. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
packages/hydrooj/src/handler/homework.tsESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox. packages/hydrooj/src/handler/training.tsESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/hydrooj/src/model/contest.ts`:
- Around line 762-765: The code turns a valid 0 time into an empty string by
using || when building colTime; change the expression that defines colTime to
use nullish coalescing so zero is preserved (replace (tsddict[pid]?.time ||
'').toString() with (tsddict[pid]?.time ?? '').toString()). Update the related
variables (colTime, colTimeStr) usage so formatSeconds(colTime, false) still
receives the expected value; locate this in the block referencing tsddict, pid,
colTime, colTimeStr and formatSeconds in contest.ts and make the ?? change.
In `@packages/scoreboard-xcpcio/index.ts`:
- Line 50: The expression building teamId uses logical OR which treats 0 as
falsy and can result in undefined if ContestJournalEntry lacks uid; change the
fallback to use nullish coalescing so zero is preserved, e.g. compute teamId
from (uid ?? (rdoc as RecordDoc).uid) and then call toString() (or String(...))
to ensure a defined value; update the line that assigns teamId and ensure the
cast/rdoc access remains the same.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ef419a1b-cd2b-43db-bc48-a0da950579ae
📒 Files selected for processing (9)
packages/hydrooj/src/handler/contest.tspackages/hydrooj/src/handler/problem.tspackages/hydrooj/src/handler/record.tspackages/hydrooj/src/interface.tspackages/hydrooj/src/model/contest.tspackages/hydrooj/src/model/document.tspackages/hydrooj/src/model/training.tspackages/hydrooj/src/upgrade.tspackages/scoreboard-xcpcio/index.ts
| const colScore = (tsddict[pid]?.penaltyScore ?? '').toString(); | ||
| const colOriginalScore = (tsddict[pid]?.score ?? '').toString(); | ||
| const colTime = (tsddict[pid]?.time || '').toString(); | ||
| const colTimeStr = colTime ? formatSeconds(colTime, false) : ''; |
There was a problem hiding this comment.
Preserve zero-second submission times in homework rows.
At Line 764, || '' turns a valid 0 into an empty value, so exact-start submissions can lose time display/export data.
Suggested fix
- const colScore = (tsddict[pid]?.penaltyScore ?? '').toString();
- const colOriginalScore = (tsddict[pid]?.score ?? '').toString();
- const colTime = (tsddict[pid]?.time || '').toString();
- const colTimeStr = colTime ? formatSeconds(colTime, false) : '';
+ const colScore = (tsddict[pid]?.penaltyScore ?? '').toString();
+ const colOriginalScore = (tsddict[pid]?.score ?? '').toString();
+ const colTimeRaw = tsddict[pid]?.time;
+ const colTime = (colTimeRaw ?? '').toString();
+ const colTimeStr = colTimeRaw == null ? '' : formatSeconds(colTimeRaw, false);📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const colScore = (tsddict[pid]?.penaltyScore ?? '').toString(); | |
| const colOriginalScore = (tsddict[pid]?.score ?? '').toString(); | |
| const colTime = (tsddict[pid]?.time || '').toString(); | |
| const colTimeStr = colTime ? formatSeconds(colTime, false) : ''; | |
| const colScore = (tsddict[pid]?.penaltyScore ?? '').toString(); | |
| const colOriginalScore = (tsddict[pid]?.score ?? '').toString(); | |
| const colTimeRaw = tsddict[pid]?.time; | |
| const colTime = (colTimeRaw ?? '').toString(); | |
| const colTimeStr = colTimeRaw == null ? '' : formatSeconds(colTimeRaw, false); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/hydrooj/src/model/contest.ts` around lines 762 - 765, The code turns
a valid 0 time into an empty string by using || when building colTime; change
the expression that defines colTime to use nullish coalescing so zero is
preserved (replace (tsddict[pid]?.time || '').toString() with
(tsddict[pid]?.time ?? '').toString()). Update the related variables (colTime,
colTimeStr) usage so formatSeconds(colTime, false) still receives the expected
value; locate this in the block referencing tsddict, pid, colTime, colTimeStr
and formatSeconds in contest.ts and make the ?? change.
| const submit = new ObjectId(rdoc._id || (rdoc as any).rid).getTimestamp().getTime(); | ||
| const id: ObjectId = '_id' in rdoc ? rdoc._id : rdoc.rid; | ||
| const submit = new ObjectId(id).getTimestamp().getTime(); | ||
| const teamId = (uid || (rdoc as RecordDoc).uid).toString(); |
There was a problem hiding this comment.
Use nullish coalescing for team UID fallback to prevent runtime failure.
Line 50 can crash when uid is 0: uid || ... falls through, and ContestJournalEntry has no uid, so .toString() can run on undefined.
Proposed fix
- const teamId = (uid || (rdoc as RecordDoc).uid).toString();
+ const teamUid = uid ?? ('uid' in rdoc ? rdoc.uid : undefined);
+ if (teamUid == null) throw new Error('Missing team uid for submission');
+ const teamId = teamUid.toString();🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/scoreboard-xcpcio/index.ts` at line 50, The expression building
teamId uses logical OR which treats 0 as falsy and can result in undefined if
ContestJournalEntry lacks uid; change the fallback to use nullish coalescing so
zero is preserved, e.g. compute teamId from (uid ?? (rdoc as RecordDoc).uid) and
then call toString() (or String(...)) to ensure a defined value; update the line
that assigns teamId and ensure the cast/rdoc access remains the same.
Summary by CodeRabbit
Refactor
Bug Fixes