mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
core: 修复自测不提供输入数据会进入评测流程的问题
This commit is contained in:
1 parent
bb856bacce
commit
33aaf1f2ea
8 files changed
+19
-44
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"bin": "bin/hydrojudge.js",
|
"bin": "bin/hydrojudge.js",
|
||||||
"version": "2.3.5",
|
"version": "2.3.6",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "undefined <i@undefined.moe>",
|
"author": "undefined <i@undefined.moe>",
|
||||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class JudgeTask {
|
|||||||
lang: string;
|
lang: string;
|
||||||
code: string;
|
code: string;
|
||||||
tmpdir: string;
|
tmpdir: string;
|
||||||
|
input?: string;
|
||||||
clean: Function[];
|
clean: Function[];
|
||||||
data: any[];
|
data: any[];
|
||||||
folder: string;
|
folder: string;
|
||||||
@@ -57,6 +58,7 @@ class JudgeTask {
|
|||||||
this.lang = this.request.lang;
|
this.lang = this.request.lang;
|
||||||
this.code = this.request.code;
|
this.code = this.request.code;
|
||||||
this.config = this.request.config;
|
this.config = this.request.config;
|
||||||
|
this.input = this.request.input;
|
||||||
this.data = this.request.data;
|
this.data = this.request.data;
|
||||||
this.tmpdir = path.resolve(getConfig('tmp_dir'), this.host, this.rid);
|
this.tmpdir = path.resolve(getConfig('tmp_dir'), this.host, this.rid);
|
||||||
this.clean = [];
|
this.clean = [];
|
||||||
@@ -64,9 +66,8 @@ class JudgeTask {
|
|||||||
tmpfs.mount(this.tmpdir, '512m');
|
tmpfs.mount(this.tmpdir, '512m');
|
||||||
log.info('Submission: %s/%s/%s pid=%s', this.host, this.domainId, this.rid, this.pid);
|
log.info('Submission: %s/%s/%s pid=%s', this.host, this.domainId, this.rid, this.pid);
|
||||||
try {
|
try {
|
||||||
if (this.type === 'judge') await this.doSubmission();
|
if (this.input) await this.doPretest();
|
||||||
else if (this.type === 1) await this.doPretest();
|
else await this.doSubmission();
|
||||||
else throw new SystemError(`Unsupported type: ${this.type}`);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof CompileError) {
|
if (e instanceof CompileError) {
|
||||||
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
|
this.next({ compiler_text: compilerText(e.stdout, e.stderr) });
|
||||||
|
|||||||
@@ -55,10 +55,10 @@ export const judge = async (ctx) => {
|
|||||||
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
||||||
const copyIn = { ...ctx.execute.copyIn };
|
const copyIn = { ...ctx.execute.copyIn };
|
||||||
const { filename } = ctx.config;
|
const { filename } = ctx.config;
|
||||||
if (filename) copyIn[`${filename}.in`] = { content: ctx.config.input };
|
if (filename) copyIn[`${filename}.in`] = { content: ctx.input };
|
||||||
const copyOut = filename ? [`${filename}.out`] : [];
|
const copyOut = filename ? [`${filename}.out`] : [];
|
||||||
const stdin = path.resolve(ctx.tmpdir, '0.in');
|
const stdin = path.resolve(ctx.tmpdir, '0.in');
|
||||||
await fs.writeFile(stdin, ctx.config.input || '');
|
await fs.writeFile(stdin, ctx.input || '');
|
||||||
const stdout = path.resolve(ctx.tmpdir, '0.out');
|
const stdout = path.resolve(ctx.tmpdir, '0.out');
|
||||||
const stderr = path.resolve(ctx.tmpdir, '0.err');
|
const stderr = path.resolve(ctx.tmpdir, '0.err');
|
||||||
const res = await run(
|
const res = await run(
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ async function postInit() {
|
|||||||
code: string;
|
code: string;
|
||||||
data: any[];
|
data: any[];
|
||||||
config: any;
|
config: any;
|
||||||
|
input?: string;
|
||||||
next: (data: any, id?: number) => void;
|
next: (data: any, id?: number) => void;
|
||||||
end: (data: any) => void;
|
end: (data: any) => void;
|
||||||
tmpdir: string;
|
tmpdir: string;
|
||||||
@@ -178,6 +179,7 @@ async function postInit() {
|
|||||||
this.code = this.request.code;
|
this.code = this.request.code;
|
||||||
this.data = this.request.data;
|
this.data = this.request.data;
|
||||||
this.config = this.request.config;
|
this.config = this.request.config;
|
||||||
|
this.input = this.request.input;
|
||||||
this.next = getNext(this);
|
this.next = getNext(this);
|
||||||
this.end = getEnd(this.domainId, this.rid);
|
this.end = getEnd(this.domainId, this.rid);
|
||||||
this.tmpdir = path.resolve(getConfig('tmp_dir'), this.rid);
|
this.tmpdir = path.resolve(getConfig('tmp_dir'), this.rid);
|
||||||
@@ -185,8 +187,7 @@ async function postInit() {
|
|||||||
fs.ensureDirSync(this.tmpdir);
|
fs.ensureDirSync(this.tmpdir);
|
||||||
tmpfs.mount(this.tmpdir, getConfig('tmpfs_size'));
|
tmpfs.mount(this.tmpdir, getConfig('tmpfs_size'));
|
||||||
logger.info(`Submission: ${this.rid}`, { pid: this.pid });
|
logger.info(`Submission: ${this.rid}`, { pid: this.pid });
|
||||||
if (this.config.input) await this.run();
|
if (typeof this.input === 'string') await this.run();
|
||||||
else if (this.config.hack) await this.hack();
|
|
||||||
else await this.submission();
|
else await this.submission();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof CompileError) {
|
if (e instanceof CompileError) {
|
||||||
@@ -226,19 +227,6 @@ async function postInit() {
|
|||||||
await judge[this.config.type || 'default'].judge(this);
|
await judge[this.config.type || 'default'].judge(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async hack() {
|
|
||||||
this.stat.cache_start = new Date();
|
|
||||||
this.folder = await cacheOpen(this.domainId, this.pid, this.data);
|
|
||||||
this.stat.read_cases = new Date();
|
|
||||||
this.config = await readYamlCases(
|
|
||||||
this.folder,
|
|
||||||
this.config,
|
|
||||||
{ next: this.next },
|
|
||||||
);
|
|
||||||
this.stat.judge = new Date();
|
|
||||||
await judge.hack.judge(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
async run() {
|
async run() {
|
||||||
this.stat.judge = new Date();
|
this.stat.judge = new Date();
|
||||||
await judge.run.judge(this);
|
await judge.run.judge(this);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hydrooj",
|
"name": "hydrooj",
|
||||||
"version": "2.17.11",
|
"version": "2.17.12",
|
||||||
"bin": "bin/hydrooj.js",
|
"bin": "bin/hydrooj.js",
|
||||||
"main": "dist/loader.js",
|
"main": "dist/loader.js",
|
||||||
"typings": "dist/loader.d.ts",
|
"typings": "dist/loader.d.ts",
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
const logger = new Logger('judge');
|
const logger = new Logger('judge');
|
||||||
|
|
||||||
async function _postJudge(rdoc: Rdoc) {
|
async function _postJudge(rdoc: Rdoc) {
|
||||||
|
if (typeof rdoc.input === 'string') return;
|
||||||
const accept = rdoc.status === builtin.STATUS.STATUS_ACCEPTED;
|
const accept = rdoc.status === builtin.STATUS.STATUS_ACCEPTED;
|
||||||
const tasks = [];
|
const tasks = [];
|
||||||
if (rdoc.contest) {
|
if (rdoc.contest) {
|
||||||
|
|||||||
@@ -226,18 +226,6 @@ export interface TestCase {
|
|||||||
message: string,
|
message: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HackConfig {
|
|
||||||
hack: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PretestConfig {
|
|
||||||
time?: string,
|
|
||||||
memory?: string,
|
|
||||||
input: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
export type RunConfig = HackConfig | PretestConfig;
|
|
||||||
|
|
||||||
export interface ContestInfo {
|
export interface ContestInfo {
|
||||||
type: 30 | 60,
|
type: 30 | 60,
|
||||||
tid: ObjectID,
|
tid: ObjectID,
|
||||||
@@ -262,7 +250,7 @@ export interface Rdoc {
|
|||||||
status: number,
|
status: number,
|
||||||
hidden: boolean,
|
hidden: boolean,
|
||||||
progress?: number,
|
progress?: number,
|
||||||
config?: RunConfig,
|
input?: string,
|
||||||
contest?: ContestInfo,
|
contest?: ContestInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { STATUS } from './builtin';
|
|||||||
import * as task from './task';
|
import * as task from './task';
|
||||||
import * as problem from './problem';
|
import * as problem from './problem';
|
||||||
import {
|
import {
|
||||||
Rdoc, TestCase, RunConfig, ContestInfo, ProblemConfig,
|
Rdoc, TestCase, ContestInfo, ProblemConfig,
|
||||||
} from '../interface';
|
} from '../interface';
|
||||||
import { Time } from '../utils';
|
import { Time } from '../utils';
|
||||||
import * as bus from '../service/bus';
|
import * as bus from '../service/bus';
|
||||||
@@ -94,7 +94,7 @@ export async function judge(domainId: string, rid: ObjectID, priority = 1) {
|
|||||||
|
|
||||||
export async function add(
|
export async function add(
|
||||||
domainId: string, pid: number, uid: number,
|
domainId: string, pid: number, uid: number,
|
||||||
lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | RunConfig,
|
lang: string, code: string, addTask: boolean, contestOrConfig?: ContestInfo | string,
|
||||||
) {
|
) {
|
||||||
const data: Rdoc = {
|
const data: Rdoc = {
|
||||||
status: STATUS.STATUS_WAITING,
|
status: STATUS.STATUS_WAITING,
|
||||||
@@ -115,14 +115,11 @@ export async function add(
|
|||||||
judgeAt: null,
|
judgeAt: null,
|
||||||
rejudged: false,
|
rejudged: false,
|
||||||
};
|
};
|
||||||
if (contestOrConfig) {
|
if (typeof contestOrConfig === 'string') {
|
||||||
if ((contestOrConfig as ContestInfo).type) {
|
// is Run
|
||||||
data.contest = contestOrConfig as ContestInfo;
|
data.input = contestOrConfig;
|
||||||
} else {
|
|
||||||
data.config = contestOrConfig as RunConfig;
|
|
||||||
data.hidden = true;
|
data.hidden = true;
|
||||||
}
|
} else data.contest = contestOrConfig;
|
||||||
}
|
|
||||||
const res = await coll.insertOne(data);
|
const res = await coll.insertOne(data);
|
||||||
if (addTask) await judge(domainId, res.insertedId);
|
if (addTask) await judge(domainId, res.insertedId);
|
||||||
return res.insertedId;
|
return res.insertedId;
|
||||||
|
|||||||
Reference in new issue
Block a user