core&ui&judge: allow run multiple pretests in single request (#1098)

This commit is contained in:
undefined authored and GitHub committed 2025-12-28 06:07:45 +08:00
1 parent c45975ae33
commit 114be2848b
8 files changed
+53 -39

No files matched your search

+1 -1
View File
@@ -29,7 +29,7 @@ export const judge = async (ctx: JudgeTask) => {
await using res = await runQueued(
`${executeGenerator.execute} ${i}`,
{
stdin: { content: ctx.input || '' },
stdin: { content: (ctx.input || [])[i - 1] || '' },
copyIn: executeGenerator.copyIn,
copyOut: ['stderr'],
copyOutCached: ['stdout'],
+42 -29
View File
@@ -1,19 +1,17 @@
import { STATUS } from '@hydrooj/common';
import { NormalizedCase, STATUS } from '@hydrooj/common';
import { parseMemoryMB, parseTimeMS } from '@hydrooj/utils';
import { runFlow } from '../flow';
import { runQueued } from '../sandbox';
import signals from '../signals';
import { JudgeTask } from '../task';
import { Context } from './interface';
export const judge = async (ctx: JudgeTask) => {
ctx.next({ status: STATUS.STATUS_COMPILING });
const execute = await ctx.compile(ctx.lang, ctx.code);
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
const judgeCase = (c: NormalizedCase) => async (ctx: Context) => {
const { address_space_limit, process_limit } = ctx.session.getLang(ctx.lang);
const res = await runQueued(
execute.execute,
ctx.execute.execute,
{
stdin: { content: ctx.input },
copyIn: execute.copyIn,
stdin: { content: c.input },
copyIn: ctx.execute.copyIn,
// Allow 2x limits for better debugging
time: parseTimeMS(ctx.config.time || '1s') * 2,
memory: parseMemoryMB(ctx.config.memory || '256m'),
@@ -21,7 +19,7 @@ export const judge = async (ctx: JudgeTask) => {
addressSpaceLimit: address_space_limit,
processLimit: process_limit,
},
`judge[${ctx.rid}]`,
`pretest[${c.id}]<${ctx.rid}>`,
1,
);
const {
@@ -39,27 +37,42 @@ export const judge = async (ctx: JudgeTask) => {
else message.push(`ExitCode: ${code}`);
}
message.push(res.stdout, res.stderr);
ctx.next({
status,
time: Math.floor(time * 1000000) / 1000000,
memory,
score: status === STATUS.STATUS_ACCEPTED ? 100 : 0,
case: {
subtaskId: 0,
status,
score: 100,
time,
memory,
message: message.join('\n').substring(0, 102400),
},
});
if ([STATUS.STATUS_WRONG_ANSWER, STATUS.STATUS_RUNTIME_ERROR].includes(status)) {
await ctx.runAnalysis(execute, { content: ctx.input });
if (!ctx.analysis && [STATUS.STATUS_WRONG_ANSWER, STATUS.STATUS_RUNTIME_ERROR].includes(status)) {
ctx.analysis = true;
await ctx.runAnalysis(ctx.execute, { content: c.input });
}
ctx.end({
return {
id: c.id,
subtaskId: 1,
status,
time: Math.floor(time * 1000000) / 1000000,
score: 1,
time,
memory,
score: status === STATUS.STATUS_ACCEPTED ? 100 : 0,
message: message.join('\n').substring(0, 102400),
};
};
export const judge = async (ctx: Context) => {
ctx.config.subtasks = [{
id: 1,
type: 'sum',
score: 100,
time: ctx.config.time,
memory: ctx.config.memory,
if: [],
cases: ctx.input.map((i, idx) => ({
id: idx + 1,
time: ctx.config.time,
memory: ctx.config.memory,
input: i,
output: '',
score: 1,
})),
}];
await runFlow(ctx, {
compile: async () => {
ctx.execute = await ctx.compile(ctx.lang, ctx.code);
},
judgeCase,
});
};
+2 -2
View File
@@ -30,7 +30,7 @@ export class JudgeTask {
rid: string;
lang: string;
code: CopyInFile;
input?: string;
input?: string[];
finished: boolean = false;
clean: (() => Promise<any>)[] = [];
data: FileInfo[];
@@ -67,7 +67,7 @@ export class JudgeTask {
this.source = this.request.source;
this.meta = this.request.meta;
this.files = this.request.files;
this.input = this.request.input;
this.input = Array.isArray(this.request.input) ? this.request.input : [this.request.input || ''];
let tid = this.request.contest?.toString() || '';
if (tid === '000000000000000000000000') tid = '';
this.env = {