refactor(契约): 判题状态码收进契约唯一一份,并收紧 18 处 as any
- 状态码常量与 judgeStatusSchema 移到 packages/contract/src/judge-status.ts, 后端 judge/status.ts 只再导出;前端 SubmissionStatus 枚举加编译期断言对齐契约 (实测改坏一个码会当场类型检查失败) - 类型逃逸 22 处降到 4 处:collab/handler、pagination、configUpdate、 ExerciseManager、ProblemSubmission、pk.vue tooltip;剩下的是词云插件无类型、 生成的 .d.ts、skulpt 和 TextEditor Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -198,6 +198,7 @@ export async function handleCollabMessage(ws: CollabSocket, raw: string) {
|
||||
studentId?: unknown
|
||||
language?: unknown
|
||||
reason?: unknown
|
||||
timestamp?: unknown
|
||||
}
|
||||
try {
|
||||
message = JSON.parse(raw) as typeof message
|
||||
@@ -213,9 +214,7 @@ export async function handleCollabMessage(ws: CollabSocket, raw: string) {
|
||||
|
||||
// 心跳不查库,和 /ws/submissions 的处理一致
|
||||
if (message.type === "ping") {
|
||||
ws.send(
|
||||
JSON.stringify({ type: "pong", timestamp: (message as any).timestamp }),
|
||||
)
|
||||
ws.send(JSON.stringify({ type: "pong", timestamp: message.timestamp }))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,8 @@
|
||||
export const JudgeStatus = {
|
||||
COMPILE_ERROR: -2,
|
||||
WRONG_ANSWER: -1,
|
||||
ACCEPTED: 0,
|
||||
CPU_TIME_LIMIT_EXCEEDED: 1,
|
||||
REAL_TIME_LIMIT_EXCEEDED: 2,
|
||||
MEMORY_LIMIT_EXCEEDED: 3,
|
||||
RUNTIME_ERROR: 4,
|
||||
SYSTEM_ERROR: 5,
|
||||
PENDING: 6,
|
||||
JUDGING: 7,
|
||||
PARTIALLY_ACCEPTED: 8,
|
||||
AST_CHECK_FAILED: 10,
|
||||
} as const
|
||||
import { JudgeStatus, type JudgeStatusValue } from "@oj2/contract"
|
||||
|
||||
export type JudgeStatusValue = (typeof JudgeStatus)[keyof typeof JudgeStatus]
|
||||
// 状态码的唯一一份在 packages/contract/src/judge-status.ts,这里只再导出,
|
||||
// 省得二十几处 import 一起改
|
||||
export { JudgeStatus, type JudgeStatusValue }
|
||||
|
||||
export function isAccepted(result: number) {
|
||||
return (
|
||||
@@ -22,7 +11,7 @@ export function isAccepted(result: number) {
|
||||
}
|
||||
|
||||
/**
|
||||
* 判题状态的中文名,和前端 `utils/constants.ts` 的 `JUDGE_STATUS` 一致,两边必须同步。
|
||||
* 判题状态的中文名,和前端 `utils/constants.ts` 的 `JUDGE_STATUS` 措辞对应(状态码本身已收进契约,名字仍是两份)。
|
||||
* 目前只用在喂给模型的 prompt 里 —— 原来那里拼的是裸状态码(`结果:-1`),
|
||||
* 模型根本不知道 -1 是「答案错误」还是别的什么,等于白给一条信息。
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user