feat: generate failure json for wrong toml files
All checks were successful
build / build (push) Successful in 2m41s
build / trigger-build-image (push) Successful in 10s

This commit is contained in:
张泊明518370910136 2025-11-27 21:15:45 -08:00
parent 6c3fb51385
commit 3c0195e605
GPG Key ID: D47306D7062CDA9D
3 changed files with 220 additions and 8 deletions

View File

@ -1,16 +1,18 @@
import os
from typing import Dict
from joj3_config_generator.models import answer, joj1, repo, result, task
from joj3_config_generator.models import answer, common, joj1, repo, result, task
from joj3_config_generator.models.const import (
ACTOR_CSV_PATH,
JOJ3_LOG_BASE_PATH,
JOJ3_LOG_FILENAME,
TEAPOT_CONFIG_ROOT,
)
from joj3_config_generator.transformers.answer import get_task_conf_from_answers
from joj3_config_generator.transformers.joj1 import get_task_conf_from_joj1
from joj3_config_generator.transformers.repo import (
get_health_check_stage,
get_teapot_env,
get_teapot_post_stage,
)
from joj3_config_generator.transformers.task import get_conf_stage
@ -46,3 +48,60 @@ def convert_joj3_conf(repo_conf: repo.Config, task_conf: task.Config) -> result.
result_conf.post_stages.append(get_teapot_post_stage(repo_conf, task_conf))
return result_conf
def create_joj3_convert_failure_conf() -> result.Config:
result_conf = result.Config(
name="Config generation failure",
log_path=str(JOJ3_LOG_BASE_PATH / JOJ3_LOG_FILENAME),
)
result_conf.stages.append(
result.StageDetail(
name="Error Message",
executor=result.Executor(name="dummy"),
parsers=[
result.Parser(
name="dummy",
with_=result.DummyConfig(
comment="Config generation failure. Contact teaching team to check course-joj repo actions for details.",
force_quit=True,
),
)
],
)
)
result_conf.post_stages.append(
result.StageDetail(
name="teapot",
executor=result.Executor(
name="local",
with_=result.ExecutorWith(
default=result.Cmd(
args=[
"/usr/local/bin/joint-teapot",
"joj3-all-env",
str(TEAPOT_CONFIG_ROOT / "teapot.env"),
"--skip-scoreboard",
"--skip-failed-table",
],
env=get_teapot_env(),
cpu_limit=common.Time("30s"),
clock_limit=common.Time("60s"),
),
cases=[],
),
),
parsers=[
result.Parser(
name="log",
with_=result.MsgConfig(
filename="stderr",
msg="joint-teapot stderr",
level=0,
),
),
result.Parser(name="debug"),
],
)
)
return result_conf

View File

@ -10,6 +10,7 @@ from joj3_config_generator import get_version
from joj3_config_generator.generator import (
convert_joj1_conf,
convert_joj3_conf,
create_joj3_convert_failure_conf,
create_joj3_task_conf,
)
from joj3_config_generator.loader import (
@ -119,18 +120,26 @@ def convert(
repo_conf, task_conf = load_joj3_toml(
root, repo_toml_path, task_toml_path
)
result_model = convert_joj3_conf(repo_conf, task_conf)
result_dict = result_model.model_dump(
mode="json", by_alias=True, exclude_none=True
)
with result_json_path.open("w", newline="") as result_file:
json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
result_file.write("\n")
is_json_generated = True
except Exception:
error_json_paths.append(result_json_path)
continue
result_model = convert_joj3_conf(repo_conf, task_conf)
result_dict = result_model.model_dump(
mode="json", by_alias=True, exclude_none=True
)
with result_json_path.open("w", newline="") as result_file:
if error_json_paths:
result_model = create_joj3_convert_failure_conf()
result_dict = result_model.model_dump(
mode="json", by_alias=True, exclude_none=True
)
for error_json_path in error_json_paths:
with error_json_path.open("w", newline="") as result_file:
json.dump(result_dict, result_file, ensure_ascii=False, indent=4)
result_file.write("\n")
is_json_generated = True
if error_json_paths:
logger.error(
f"Failed to convert {len(error_json_paths)} file(s): {', '.join(str(json_path) for json_path in error_json_paths)}. Check previous errors for details."
)

View File

@ -0,0 +1,144 @@
{
"name": "Config generation failure",
"logPath": "/home/tt/.cache/joj3/joj3.log",
"actorCsvPath": "",
"sandboxExecServer": "172.17.0.1:5051",
"sandboxToken": "",
"outputPath": "/tmp/joj3_result.json",
"preStages": [],
"stages": [
{
"name": "Error Message",
"groups": [],
"executor": {
"name": "dummy",
"with": {
"default": {
"args": [],
"env": [
"PATH=/usr/bin:/bin:/usr/local/bin"
],
"stdin": {
"content": ""
},
"stdout": {
"name": "stdout",
"max": 33554432,
"pipe": true
},
"stderr": {
"name": "stderr",
"max": 33554432,
"pipe": true
},
"cpuLimit": 1000000000,
"clockLimit": 2000000000,
"memoryLimit": 268435456,
"stackLimit": 0,
"procLimit": 50,
"cpuRateLimit": 0,
"cpuSetLimit": "",
"copyIn": {},
"copyInCached": {},
"copyInDir": ".",
"copyOut": [
"stdout",
"stderr"
],
"copyOutCached": [],
"copyOutMax": 0,
"copyOutDir": "",
"tty": false,
"strictMemoryLimit": false,
"dataSegmentLimit": false,
"addressSpaceLimit": false
},
"cases": []
}
},
"parsers": [
{
"name": "dummy",
"with": {
"score": 0,
"comment": "Config generation failure. Contact teaching team to check course-joj repo actions for details.",
"forceQuit": true
}
}
]
}
],
"postStages": [
{
"name": "teapot",
"groups": [],
"executor": {
"name": "local",
"with": {
"default": {
"args": [
"/usr/local/bin/joint-teapot",
"joj3-all-env",
"/home/tt/.config/teapot/teapot.env",
"--skip-scoreboard",
"--skip-failed-table"
],
"env": [
"REPOS_DIR=/home/tt/.cache",
"LOG_FILE_PATH=/home/tt/.cache/joint-teapot-debug.log"
],
"stdin": {
"content": ""
},
"stdout": {
"name": "stdout",
"max": 33554432,
"pipe": true
},
"stderr": {
"name": "stderr",
"max": 33554432,
"pipe": true
},
"cpuLimit": 30000000000,
"clockLimit": 60000000000,
"memoryLimit": 268435456,
"stackLimit": 0,
"procLimit": 50,
"cpuRateLimit": 0,
"cpuSetLimit": "",
"copyIn": {},
"copyInCached": {},
"copyInDir": ".",
"copyOut": [
"stdout",
"stderr"
],
"copyOutCached": [],
"copyOutMax": 0,
"copyOutDir": "",
"tty": false,
"strictMemoryLimit": false,
"dataSegmentLimit": false,
"addressSpaceLimit": false
},
"cases": []
}
},
"parsers": [
{
"name": "log",
"with": {
"filename": "stderr",
"msg": "joint-teapot stderr",
"level": 0
}
},
{
"name": "debug",
"with": {}
}
]
}
]
}