Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split generate_report into smaller functions #147

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 67 additions & 63 deletions src/discord-cluster-manager/report.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pprint

import discord
from run_eval import FullResult
from run_eval import CompileResult, FullResult, RunResult


def _limit_length(text: str, maxlen: int):
Expand Down Expand Up @@ -34,91 +34,95 @@ async def _send_split_log(thread: discord.Thread, partial_message: str, header:

# now, format the chunks
for i, chunk in enumerate(chunks):
partial_message += f"\n\n## {header} ({i+1}/{len(chunks)}):\n"
partial_message = f"\n\n## {header} ({i+1}/{len(chunks)}):\n"
partial_message += f"```\n{_limit_length(chunk, 1900)}```"
await thread.send(partial_message)

return ""


async def generate_report(thread: discord.Thread, result: FullResult, has_tests: bool): # noqa: C901
async def _generate_compile_report(thread: discord.Thread, comp: CompileResult):
message = ""
if not result.success:
message += "# Failure\n"
message += result.error
if not comp.nvcc_found:
message += "# Compilation failed\nNVCC could not be found.\n"
message += "This indicates a bug in the runner configuration, _not in your code_.\n"
message += "Please notify the server admins of this problem"
await thread.send(message)
return

comp = result.compile
run = result.run
# ok, we found nvcc
message += "# Compilation failed\n"
message += "Command "
message += f"```bash\n>{_limit_length(comp.command, 1000)}```\n"
message += f"exited with code **{comp.exit_code}**."

message = ""
if comp is not None and not comp.success:
if not comp.nvcc_found:
message += "# Compilation failed\nNVCC could not be found.\n"
message += "This indicates a bug in the runner configuration, _not in your code_.\n"
message += "Please notify the server admins of this problem"
await thread.send(message)
return
message = await _send_split_log(thread, message, "Compiler stderr", comp.stderr.strip())

# ok, we found nvcc
message += "# Compilation failed\n"
message += "Command "
message += f"```bash\n>{_limit_length(comp.command, 1000)}```\n"
message += f"exited with code **{comp.exit_code}**."
if len(comp.stdout.strip()) > 0:
message = await _send_split_log(thread, message, "Compiler stdout", comp.stdout.strip())

message = await _send_split_log(thread, message, "Compiler stderr", comp.stderr.strip())
if len(message) != 0:
await thread.send(message)

if len(comp.stdout.strip()) > 0:
message = await _send_split_log(thread, message, "Compiler stdout", comp.stdout.strip())

if len(message) != 0:
await thread.send(message)
async def _generate_crash_report(thread: discord.Thread, run: RunResult):
message = "# Running failed\n"
message += "Command "
message += f"```bash\n{_limit_length(run.command, 1000)}```\n"
message += f"exited with error code **{run.exit_code}** after {run.duration:.2} seconds."

return
if len(run.stderr.strip()) > 0:
message = await _send_split_log(thread, message, "Program stderr", run.stderr.strip())

if not run.success:
message += "# Running failed\n"
message += "Command "
message += f"```bash\n{_limit_length(run.command, 1000)}```\n"
message += f"exited with error code **{run.exit_code}** after {run.duration:.2} seconds."
if len(run.stdout.strip()) > 0:
message = await _send_split_log(thread, message, "Program stdout", run.stdout.strip())

if len(message) != 0:
await thread.send(message)

if len(run.stderr.strip()) > 0:
message = await _send_split_log(thread, message, "Program stderr", run.stderr.strip())

if len(run.stdout.strip()) > 0:
message = await _send_split_log(thread, message, "Program stdout", run.stdout.strip())
async def _generate_test_report(thread: discord.Thread, run: RunResult):
message = "# Testing failed\n"
message += "Command "
message += f"```bash\n{_limit_length(run.command, 1000)}```\n"
message += f"ran successfully in {run.duration:.2} seconds, but did not pass all tests.\n"

if len(message) != 0:
await thread.send(message)
if len(run.stderr.strip()) > 0:
message = await _send_split_log(thread, message, "Program stderr", run.stderr.strip())

if len(run.stdout.strip()) > 0:
message = await _send_split_log(thread, message, "Program stdout", run.stdout.strip())

if len(message) != 0:
await thread.send(message)

# TODO dedicated "error" entry in our results that gets
# populated by check_implementation
return


async def generate_report(thread: discord.Thread, result: FullResult, has_tests: bool): # noqa: C901
if not result.success:
message = "# Failure\n"
message += result.error
await thread.send(message)
return

if has_tests:
if not run.passed:
message += "# Testing failed\n"
message += "Command "
message += f"```bash\n{_limit_length(run.command, 1000)}```\n"
message += (
f"ran successfully in {run.duration:.2} seconds, but did not pass all tests.\n"
)

if len(run.stderr.strip()) > 0:
message = await _send_split_log(
thread, message, "Program stderr", run.stderr.strip()
)

if len(run.stdout.strip()) > 0:
message = await _send_split_log(
thread, message, "Program stdout", run.stdout.strip()
)

if len(message) != 0:
await thread.send(message)

# TODO dedicated "error" entry in our results that gets
# populated by check_implementation
return
comp = result.compile
run = result.run

if comp is not None and not comp.success:
await _generate_compile_report(thread, comp)
return

if not run.success:
await _generate_crash_report(thread, run)
return

message = ""
if has_tests and not run.passed:
await _generate_test_report(thread, run)
return

# OK, we were successful
message += "# Success!\n"
Expand Down
Loading