Skip to content

Commit

Permalink
Warn if a submission was judged by two different compiler/runner vers…
Browse files Browse the repository at this point in the history
…ions.
  • Loading branch information
meisterT committed Nov 24, 2023
1 parent df78c81 commit b83c31d
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 12 deletions.
40 changes: 40 additions & 0 deletions webapp/migrations/Version20231124133956.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231124133956 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add version reference to judgetask.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE judgetask ADD versionid INT UNSIGNED DEFAULT NULL COMMENT \'Version ID\'');
$this->addSql('ALTER TABLE judgetask ADD CONSTRAINT FK_83142B704034DFAF FOREIGN KEY (versionid) REFERENCES version (versionid) ON DELETE SET NULL');
$this->addSql('CREATE INDEX IDX_83142B704034DFAF ON judgetask (versionid)');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE judgetask DROP FOREIGN KEY FK_83142B704034DFAF');
$this->addSql('DROP INDEX IDX_83142B704034DFAF ON judgetask');
$this->addSql('ALTER TABLE judgetask DROP versionid');
}

public function isTransactional(): bool
{
return false;
}
}
17 changes: 11 additions & 6 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1284,27 +1284,29 @@ public function checkVersions(Request $request, string $judgetaskid): array
$this->em->wrapInTransaction(function () use (
$judgehost,
$reportedVersions,
$language
$language,
$judgeTask
) {
$activeVersion = $this->em->getRepository(Version::class)
->findOneBy(['language' => $language, 'judgehost' => $judgehost, 'active' => true]);

$newVersion = false;
$isNewVersion = false;
if (!$activeVersion) {
$newVersion = true;
$isNewVersion = true;
} else {
$reportedCompilerVersion = $reportedVersions['compiler'] ?? null;
if ($activeVersion->getCompilerVersion() !== $reportedCompilerVersion) {
$newVersion = true;
$isNewVersion = true;
}
$reportedRunnerVersion = $reportedVersions['runner'] ?? null;
if ($activeVersion->getRunnerVersion() !== $reportedRunnerVersion) {
$newVersion = true;
$isNewVersion = true;
}
}
if ($newVersion) {
if ($isNewVersion) {
if ($activeVersion) {
$activeVersion->setActive(false);
$this->em->flush();
}
$activeVersion = new Version();
$activeVersion
Expand All @@ -1326,6 +1328,9 @@ public function checkVersions(Request $request, string $judgetaskid): array
$this->em->persist($activeVersion);
$this->em->flush();
}

$judgeTask->setVersion($activeVersion);

// TODO: Optionally check version here against canonical version.
});
return [];
Expand Down
35 changes: 29 additions & 6 deletions webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ public function viewAction(
'claimWarning' => $claimWarning,
'combinedRunCompare' => $submission->getProblem()->getCombinedRunCompare(),
'requestedOutputCount' => $requestedOutputCount,
'version_warnings' => [],
];

if ($selectedJudging === null) {
Expand All @@ -527,21 +528,43 @@ public function viewAction(
];
} else {
$contestProblem = $submission->getContestProblem();
/** @var JudgeTask $judgeTask */
$judgeTask = $this->em->getRepository(JudgeTask::class)->findOneBy(['jobid' => $selectedJudging->getJudgingid()]);
if ($judgeTask !== null) {
/** @var JudgeTask[] $judgeTasks */
$judgeTasks = $this->em->getRepository(JudgeTask::class)->findBy(['jobid' => $selectedJudging->getJudgingid()]);
$unique_compiler_versions = [];
$unique_runner_versions = [];
$sampleJudgeTask = null;
foreach ($judgeTasks as $judgeTask) {
$sampleJudgeTask = $judgeTask;
$version = $judgeTask->getVersion();
if (!$version) {
continue;
}
if ($version->getCompilerVersion()) {
$unique_compiler_versions[$version->getCompilerVersion()] = true;
}
if ($version->getRunnerVersion()) {
$unique_runner_versions[$version->getRunnerVersion()] = true;
}
}
if (count($unique_compiler_versions) > 1) {
$twigData['version_warnings']['compiler'] = array_keys($unique_compiler_versions);
}
if (count($unique_runner_versions) > 1) {
$twigData['version_warnings']['runner'] = array_keys($unique_runner_versions);
}
if ($sampleJudgeTask !== null) {
$errors = [];
$this->maybeGetErrors('Compile config',
$this->dj->getCompileConfig($submission),
$judgeTask->getCompileConfig(),
$sampleJudgeTask->getCompileConfig(),
$errors);
$this->maybeGetErrors('Run config',
$this->dj->getRunConfig($contestProblem, $submission),
$judgeTask->getRunConfig(),
$sampleJudgeTask->getRunConfig(),
$errors);
$this->maybeGetErrors('Compare config',
$this->dj->getCompareConfig($contestProblem),
$judgeTask->getCompareConfig(),
$sampleJudgeTask->getCompareConfig(),
$errors);
if (!empty($errors)) {
if ($selectedJudging->getValid()) {
Expand Down
16 changes: 16 additions & 0 deletions webapp/src/Entity/JudgeTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public function getSubmitid(): ?int
#[Serializer\Exclude]
private Collection $judging_runs;

#[ORM\ManyToOne(inversedBy: 'judgetasks')]
#[ORM\JoinColumn(name: 'versionid', referencedColumnName: 'versionid', onDelete: 'SET NULL')]
#[Serializer\Exclude]
private ?Version $version = null;

public function __construct()
{
$this->judging_runs = new ArrayCollection();
Expand Down Expand Up @@ -379,4 +384,15 @@ public function getFirstJudgingRun(): ?JudgingRun
{
return $this->judging_runs->first() ?: null;
}

public function setVersion(Version $version): JudgeTask
{
$this->version = $version;
return $this;
}

public function getVersion(): ?Version
{
return $this->version;
}
}
6 changes: 6 additions & 0 deletions webapp/src/Entity/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Entity;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\PersistentCollection;
use JMS\Serializer\Annotation as Serializer;

/**
Expand Down Expand Up @@ -59,6 +61,10 @@ class Version
#[Serializer\Exclude]
private bool $active = true;

#[ORM\OneToMany(mappedBy: 'version', targetEntity: JudgeTask::class)]
#[Serializer\Exclude]
private Collection $judgeTasks;

public function getVersionid(): ?int
{
return $this->versionid;
Expand Down
17 changes: 17 additions & 0 deletions webapp/templates/jury/submission.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@
{% endif %}
{% endif %}

{% if version_warnings is not null and version_warnings is not empty %}
{% for type, versions in version_warnings %}
<div class="alert alert-warning">
<p>
This judging did not use the same {{ type}} version for all testcases.
This may lead to unexpected results. Versions used:
</p>
<p>
{% for version in versions %}
<pre class="output_text">{{ version }}</pre>
{% if not loop.last %}<hr />{% endif %}
{% endfor %}
</p>
</div>
{% endfor %}
{% endif %}

<div class="mb-3">
<h1 style="display: inline;">
Submission {{ submission.submitid }}
Expand Down

0 comments on commit b83c31d

Please sign in to comment.