Skip to content

fix(judge): treat empty output files as existing#1186

Closed
Ujimatsu-Chiya wants to merge 1 commit into
hydro-dev:masterfrom
Ujimatsu-Chiya:master
Closed

fix(judge): treat empty output files as existing#1186
Ujimatsu-Chiya wants to merge 1 commit into
hydro-dev:masterfrom
Ujimatsu-Chiya:master

Conversation

@Ujimatsu-Chiya

@Ujimatsu-Chiya Ujimatsu-Chiya commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

fix(judge): treat empty output files as existing

When using file IO mode, HydroJudge checked output file existence with a truthy value check on ret.files[outname].

This caused a valid zero-byte output file, such as an empty user.out, to be treated as missing because an empty string is falsy in JavaScript. As a result, pretests with empty output incorrectly failed with Output file not found.

Check whether the output file key exists instead of checking whether its content is truthy, and preserve empty stdout/stderr with nullish coalescing.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of sandbox output files so missing results are reported more reliably.
    • Preserved empty stdout and stderr content instead of treating it as missing.
    • If an expected output file is not found, the run now surfaces a clearer runtime error.

@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b8884a43-ce02-4d5e-94f6-c1769cc6e33c

📥 Commits

Reviewing files that changed from the base of the PR and between 99ce691 and a93fb5a.

📒 Files selected for processing (1)
  • packages/hydrojudge/src/sandbox.ts

Walkthrough

adaptResult now distinguishes missing output entries from falsy values when checking output file IDs and files. It copies the output filename’s file ID into ret.fileIds.stdout when present, sets an output-not-found runtime error when neither output artifact exists, and uses nullish-coalescing to preserve empty-string stdout and stderr contents.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: treating empty judge output files as existing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/hydrojudge/src/sandbox.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Ujimatsu-Chiya

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@undefined-moe

Copy link
Copy Markdown
Member

Please provide a non-working example (problem package & code / hydro.ac submission link)

@Ujimatsu-Chiya

Ujimatsu-Chiya commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Please provide a non-working example (problem package & code / hydro.ac submission link)

https://hydro.ac/p/loj-P3891 这是一道需要文件freopen的题目,对于自测样例的空输出,它打印的是RE:Output file not found:

image

期望行为应该是空输出,而不是文件不存在。

https://hydro.ac/p/luogu-B4177 对于一个标准输入输出的题目,期望的自测样例的空输出应该是:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants