vineetshukla.work@gmail.com commited on
Commit
181b78a
Β·
1 Parent(s): 1adae3f

feat: add pre-submission compliance checker

Browse files
Files changed (1) hide show
  1. check_compliance.py +111 -0
check_compliance.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ CodeSensei Pre-Submission Compliance Checker
3
+ Validates inference.py against ALL hackathon requirements
4
+ """
5
+ import os
6
+ import sys
7
+
8
+ REPO = r"x:\scalerXmeta"
9
+ INF = os.path.join(REPO, "inference.py")
10
+
11
+ results = []
12
+
13
+ def check(name, condition):
14
+ status = "PASS" if condition else "FAIL"
15
+ results.append((name, status))
16
+ print(f" {'βœ…' if condition else '❌'} {name}: {status}")
17
+ return condition
18
+
19
+ print("=" * 60)
20
+ print("CODESENSEI SUBMISSION COMPLIANCE CHECK")
21
+ print("=" * 60)
22
+
23
+ # --- File existence ---
24
+ print("\nπŸ“ FILE STRUCTURE:")
25
+ check("inference.py exists in root", os.path.isfile(INF))
26
+ check("openenv.yaml exists", os.path.isfile(os.path.join(REPO, "openenv.yaml")))
27
+ check("Dockerfile exists in root", os.path.isfile(os.path.join(REPO, "Dockerfile")))
28
+ check("requirements.txt exists", os.path.isfile(os.path.join(REPO, "requirements.txt")))
29
+ check("env/data/bug_dataset.json exists", os.path.isfile(os.path.join(REPO, "env", "data", "bug_dataset.json")))
30
+
31
+ # --- Read inference.py ---
32
+ with open(INF, "r", encoding="utf-8") as f:
33
+ code = f.read()
34
+ lines = code.split("\n")
35
+
36
+ # --- OpenAI Client ---
37
+ print("\nπŸ”Œ OPENAI CLIENT:")
38
+ check("from openai import OpenAI", "from openai import OpenAI" in code)
39
+ check("client.chat.completions.create used", "client.chat.completions.create" in code)
40
+
41
+ # --- Env Vars ---
42
+ print("\nπŸ”‘ ENV VARS:")
43
+ check("API_BASE_URL has default", 'os.getenv("API_BASE_URL"' in code)
44
+ check("MODEL_NAME has default", 'os.getenv("MODEL_NAME"' in code)
45
+ check("HF_TOKEN has NO default", 'os.getenv("HF_TOKEN")' in code)
46
+
47
+ # Check HF_TOKEN does NOT have a default value
48
+ hf_lines = [l for l in lines if "HF_TOKEN" in l and "getenv" in l]
49
+ hf_no_default = any("HF_TOKEN\")" in l or "HF_TOKEN')" in l for l in hf_lines)
50
+ check("HF_TOKEN truly has no default (no 2nd arg)", hf_no_default)
51
+
52
+ check("LOCAL_IMAGE_NAME / IMAGE_NAME", "IMAGE_NAME" in code)
53
+
54
+ # --- Stdout Logging ---
55
+ print("\nπŸ“‹ STDOUT LOGGING FORMAT:")
56
+ check("[START] log line exists", "[START]" in code)
57
+ check("[STEP] log line exists", "[STEP]" in code)
58
+ check("[END] log line exists", "[END]" in code)
59
+
60
+ # Check exact format
61
+ check("[START] has task= env= model=", "task={" in code and "env={" in code and "model={" in code)
62
+ check("[STEP] has step= action= reward= done= error=",
63
+ "step={" in code and "action={" in code and "reward={" in code and "done={" in code and "error={" in code)
64
+ check("[END] has success= steps= score= rewards=",
65
+ "success={" in code and "steps={" in code and "score={" in code and "rewards={" in code)
66
+
67
+ # Check formatting
68
+ check("reward formatted to 2dp ({reward:.2f})", "reward:.2f" in code)
69
+ check("score formatted to 3dp ({score:.3f})", "score:.3f" in code)
70
+ check("done lowercase (str(done).lower())", "str(done).lower()" in code)
71
+ check("success lowercase (str(success).lower())", "str(success).lower()" in code)
72
+
73
+ # --- OpenEnv Pattern ---
74
+ print("\n🐳 OPENENV PATTERN:")
75
+ check("from_docker_image() used", "from_docker_image" in code)
76
+ check("await env.reset()", "await env.reset()" in code)
77
+ check("await env.step(", "await env.step(" in code)
78
+ check("result.observation accessed", "result.observation" in code)
79
+ check("result.done accessed", "result.done" in code)
80
+ check("result.reward accessed", "result.reward" in code)
81
+ check("await env.close() in finally", "await env.close()" in code)
82
+ check("asyncio.run(main())", "asyncio.run(main())" in code)
83
+
84
+ # --- Score ---
85
+ print("\nπŸ“Š SCORE NORMALIZATION:")
86
+ check("Score clamped to [0, 1]", "min(max(score" in code or "max(0.0, min(1.0" in code)
87
+
88
+ # --- requirements.txt ---
89
+ print("\nπŸ“¦ DEPENDENCIES:")
90
+ with open(os.path.join(REPO, "requirements.txt"), "r") as f:
91
+ reqs = f.read()
92
+ check("openai in requirements.txt", "openai" in reqs)
93
+
94
+ # --- Fallback return ---
95
+ print("\nπŸ”„ EDGE CASES:")
96
+ check('Fallback returns "hello"', '"hello"' in code)
97
+ check("Exception handled in model call", "except Exception" in code)
98
+
99
+ # --- Summary ---
100
+ print("\n" + "=" * 60)
101
+ passed = sum(1 for _, s in results if s == "PASS")
102
+ total = len(results)
103
+ if passed == total:
104
+ print(f"πŸŽ‰ ALL {total}/{total} CHECKS PASSED!")
105
+ print(" Your submission is READY!")
106
+ else:
107
+ failed = [(n, s) for n, s in results if s == "FAIL"]
108
+ print(f"⚠️ {passed}/{total} PASSED, {len(failed)} FAILED:")
109
+ for name, _ in failed:
110
+ print(f" ❌ {name}")
111
+ print("=" * 60)