Spaces:
Configuration error
Configuration error
Upload folder using huggingface_hub
Browse files- inference.py +60 -56
- server/templates/level_1/core.py +0 -0
- server/templates/level_1/main.py +5 -0
- server/templates/level_10/middleware.py +23 -0
- server/templates/level_11/handler.py +6 -0
- server/templates/level_11/orchestrator.py +8 -0
- server/templates/level_12/deployer.py +11 -0
- server/templates/level_12/mcp_config.json +9 -0
- server/templates/level_13/ai_client.py +10 -0
- server/templates/level_13/requirenments.txt +1 -0
- server/templates/level_14/auth.py +10 -0
- server/templates/level_14/session.py +7 -0
- server/templates/level_15/backend_config.yaml +8 -0
- server/templates/level_15/deploynment_log.txt +2 -0
- server/templates/level_15/infra_manifest.json +7 -0
- server/templates/level_2/main.js +3 -0
- server/templates/level_2/utils.js +1 -0
- server/templates/level_3/processor.py +9 -0
- server/templates/level_3/test_logic.py +19 -0
- server/templates/level_4/main.cpp +7 -0
- server/templates/level_4/shapes.h +6 -0
- server/templates/level_4/utils.h +3 -0
- server/templates/level_5/com/security/AuthService.java +8 -0
- server/templates/level_5/com/tests/SecurityTest.java +12 -0
- server/templates/level_6/models.py +8 -0
- server/templates/level_6/view.py +15 -0
- server/templates/level_7/main.rs +21 -0
- server/templates/level_8/InfiniteScroll.js +25 -0
- server/templates/level_9/processor.go +14 -0
inference.py
CHANGED
|
@@ -50,13 +50,12 @@ from typing import List, Optional
|
|
| 50 |
from openai import OpenAI
|
| 51 |
from dotenv import load_dotenv
|
| 52 |
|
| 53 |
-
# 🚀 THE
|
| 54 |
-
|
|
|
|
| 55 |
|
| 56 |
-
# Load local .env for testing
|
| 57 |
load_dotenv()
|
| 58 |
|
| 59 |
-
# IMPORT YOUR ACTION CLASS
|
| 60 |
try:
|
| 61 |
from models import LintCodingAgentAction
|
| 62 |
except ImportError:
|
|
@@ -72,7 +71,7 @@ TASK_NAME = "multi-lang-lint-v1"
|
|
| 72 |
BENCHMARK = "lint-coding-v1"
|
| 73 |
MAX_STEPS = 10
|
| 74 |
|
| 75 |
-
SYSTEM_PROMPT = "You are
|
| 76 |
|
| 77 |
def log_start(task: str, env: str, model: str) -> None:
|
| 78 |
print(f"[START] task={task} env={env} model={model}", flush=True)
|
|
@@ -83,11 +82,22 @@ def log_step(step: int, action: str, reward: float, done: bool, error: Optional[
|
|
| 83 |
|
| 84 |
def log_end(success: bool, steps: int, score: float, rewards: List[float]) -> None:
|
| 85 |
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
| 86 |
-
print(f"[END] success={str(success).lower()} steps={steps} score={score:.
|
| 87 |
|
| 88 |
-
|
| 89 |
client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
| 90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
rewards: List[float] = []
|
| 92 |
steps_taken = 0
|
| 93 |
success = False
|
|
@@ -95,60 +105,54 @@ async def main() -> None:
|
|
| 95 |
log_start(task=TASK_NAME, env=BENCHMARK, model=MODEL_NAME)
|
| 96 |
|
| 97 |
try:
|
| 98 |
-
#
|
| 99 |
-
#
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
-
result = await env.reset()
|
| 104 |
-
|
| 105 |
-
for step in range(1, MAX_STEPS + 1):
|
| 106 |
-
obs = result.observation
|
| 107 |
-
|
| 108 |
-
try:
|
| 109 |
-
vfs_display = json.dumps(json.loads(obs.code_context), indent=2)
|
| 110 |
-
except:
|
| 111 |
-
vfs_display = obs.code_context
|
| 112 |
-
|
| 113 |
-
user_prompt = f"VFS Structure:\n{vfs_display}\n\nTask: {obs.problem_statement}"
|
| 114 |
-
|
| 115 |
-
# LLM Call
|
| 116 |
-
completion = client.chat.completions.create(
|
| 117 |
-
model=MODEL_NAME,
|
| 118 |
-
messages=[
|
| 119 |
-
{"role": "system", "content": SYSTEM_PROMPT},
|
| 120 |
-
{"role": "user", "content": user_prompt},
|
| 121 |
-
],
|
| 122 |
-
temperature=0.2,
|
| 123 |
-
max_tokens=200,
|
| 124 |
-
)
|
| 125 |
-
|
| 126 |
-
action_text = (completion.choices[0].message.content or "").strip()
|
| 127 |
-
|
| 128 |
-
# State Transition (Awaited)
|
| 129 |
-
result = await env.step(LintCodingAgentAction(
|
| 130 |
-
code_solution=action_text,
|
| 131 |
-
explanation=f"Async fix level {obs.level}"
|
| 132 |
-
))
|
| 133 |
-
|
| 134 |
-
reward = result.reward or 0.0
|
| 135 |
-
done = result.done
|
| 136 |
-
|
| 137 |
-
rewards.append(reward)
|
| 138 |
-
steps_taken = step
|
| 139 |
-
log_step(step, action_text, reward, done, None)
|
| 140 |
-
|
| 141 |
-
if done:
|
| 142 |
-
success = True
|
| 143 |
-
break
|
| 144 |
|
| 145 |
except Exception as e:
|
| 146 |
-
|
| 147 |
-
log_step(1, "error_retry", 0.0, True, str(e))
|
| 148 |
|
| 149 |
finally:
|
| 150 |
-
|
|
|
|
| 151 |
log_end(success, steps_taken, score, rewards)
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
if __name__ == "__main__":
|
| 154 |
-
|
|
|
|
| 50 |
from openai import OpenAI
|
| 51 |
from dotenv import load_dotenv
|
| 52 |
|
| 53 |
+
# 🚀 THE BULLETPROOF IMPORT
|
| 54 |
+
import openenv
|
| 55 |
+
from openenv import SyncEnvClient
|
| 56 |
|
|
|
|
| 57 |
load_dotenv()
|
| 58 |
|
|
|
|
| 59 |
try:
|
| 60 |
from models import LintCodingAgentAction
|
| 61 |
except ImportError:
|
|
|
|
| 71 |
BENCHMARK = "lint-coding-v1"
|
| 72 |
MAX_STEPS = 10
|
| 73 |
|
| 74 |
+
SYSTEM_PROMPT = "You are a lead architect. Fix the code in the VFS. Return raw code only."
|
| 75 |
|
| 76 |
def log_start(task: str, env: str, model: str) -> None:
|
| 77 |
print(f"[START] task={task} env={env} model={model}", flush=True)
|
|
|
|
| 82 |
|
| 83 |
def log_end(success: bool, steps: int, score: float, rewards: List[float]) -> None:
|
| 84 |
rewards_str = ",".join(f"{r:.2f}" for r in rewards)
|
| 85 |
+
print(f"[END] success={str(success).lower()} steps={steps} score={score:.2f} rewards={rewards_str}", flush=True)
|
| 86 |
|
| 87 |
+
def main() -> None:
|
| 88 |
client = OpenAI(base_url=API_BASE_URL, api_key=API_KEY)
|
| 89 |
|
| 90 |
+
# 🚀 KEYWORD AGNOSTIC INITIALIZATION
|
| 91 |
+
# We try positional first, then 'address', then 'base_url'
|
| 92 |
+
env = None
|
| 93 |
+
try:
|
| 94 |
+
env = SyncEnvClient(ADDRESS)
|
| 95 |
+
except TypeError:
|
| 96 |
+
try:
|
| 97 |
+
env = SyncEnvClient(address=ADDRESS)
|
| 98 |
+
except TypeError:
|
| 99 |
+
env = SyncEnvClient(base_url=ADDRESS)
|
| 100 |
+
|
| 101 |
rewards: List[float] = []
|
| 102 |
steps_taken = 0
|
| 103 |
success = False
|
|
|
|
| 105 |
log_start(task=TASK_NAME, env=BENCHMARK, model=MODEL_NAME)
|
| 106 |
|
| 107 |
try:
|
| 108 |
+
# Check if the environment requires a context manager
|
| 109 |
+
# If .sync() exists, we use it; otherwise, we call reset directly.
|
| 110 |
+
if hasattr(env, 'sync'):
|
| 111 |
+
with env.sync() as synced_env:
|
| 112 |
+
execute_loop(synced_env, client, rewards)
|
| 113 |
+
else:
|
| 114 |
+
execute_loop(env, client, rewards)
|
| 115 |
|
| 116 |
+
success = True if rewards and any(r > 0 for r in rewards) else False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
except Exception as e:
|
| 119 |
+
log_step(1, "system_error", 0.0, True, str(e))
|
|
|
|
| 120 |
|
| 121 |
finally:
|
| 122 |
+
steps_taken = len(rewards)
|
| 123 |
+
score = sum(rewards) / steps_taken if steps_taken > 0 else 0.0
|
| 124 |
log_end(success, steps_taken, score, rewards)
|
| 125 |
|
| 126 |
+
def execute_loop(env, client, rewards):
|
| 127 |
+
"""The actual logic loop shared between sync/synced-context modes"""
|
| 128 |
+
result = env.reset()
|
| 129 |
+
for step in range(1, MAX_STEPS + 1):
|
| 130 |
+
obs = result.observation
|
| 131 |
+
vfs_display = obs.code_context # Already JSON stringified in our server
|
| 132 |
+
|
| 133 |
+
user_prompt = f"VFS:\n{vfs_display}\n\nTask: {obs.problem_statement}"
|
| 134 |
+
|
| 135 |
+
completion = client.chat.completions.create(
|
| 136 |
+
model=MODEL_NAME,
|
| 137 |
+
messages=[
|
| 138 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 139 |
+
{"role": "user", "content": user_prompt},
|
| 140 |
+
],
|
| 141 |
+
temperature=0.2,
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
action_text = completion.choices[0].message.content.strip()
|
| 145 |
+
|
| 146 |
+
result = env.step(LintCodingAgentAction(
|
| 147 |
+
code_solution=action_text,
|
| 148 |
+
explanation=f"Architect fix"
|
| 149 |
+
))
|
| 150 |
+
|
| 151 |
+
rewards.append(result.reward or 0.0)
|
| 152 |
+
log_step(step, action_text, result.reward, result.done, None)
|
| 153 |
+
|
| 154 |
+
if result.done:
|
| 155 |
+
break
|
| 156 |
+
|
| 157 |
if __name__ == "__main__":
|
| 158 |
+
main()
|
server/templates/level_1/core.py
ADDED
|
File without changes
|
server/templates/level_1/main.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# BROKEN: This will fail if run as a module without the dot
|
| 2 |
+
import core
|
| 3 |
+
|
| 4 |
+
def run():
|
| 5 |
+
print("Starting...")
|
server/templates/level_10/middleware.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
|
| 3 |
+
# BROKEN: This global variable is shared across all async tasks.
|
| 4 |
+
# Task A will set this, then 'await'. Task B will then overwrite it.
|
| 5 |
+
request_store = {"id": None}
|
| 6 |
+
|
| 7 |
+
async def process_request(req_id):
|
| 8 |
+
request_store["id"] = req_id
|
| 9 |
+
|
| 10 |
+
# Simulate a database call or API hit
|
| 11 |
+
await asyncio.sleep(1)
|
| 12 |
+
|
| 13 |
+
# By the time we get here, another request might have
|
| 14 |
+
# changed request_store["id"]
|
| 15 |
+
return f"Finished request: {request_store['id']}"
|
| 16 |
+
|
| 17 |
+
async def main():
|
| 18 |
+
# Simulate two concurrent requests
|
| 19 |
+
results = await asyncio.gather(
|
| 20 |
+
process_request("REQ-100"),
|
| 21 |
+
process_request("REQ-200")
|
| 22 |
+
)
|
| 23 |
+
print(results) # Likely to show ['Finished request: REQ-200', 'Finished request: REQ-200']
|
server/templates/level_11/handler.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# The needle in the haystack
|
| 2 |
+
def verify_token(token):
|
| 3 |
+
# This is the logic the Master Agent needs to find
|
| 4 |
+
import os
|
| 5 |
+
secret = os.getenv("JWT_SECRET")
|
| 6 |
+
return token == secret
|
server/templates/level_11/orchestrator.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# MASTER AGENT STARTING POINT
|
| 2 |
+
# Task: Find the verification logic and document the Auth Flow.
|
| 3 |
+
# Error: Repo size exceeds single-pass context.
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
def start_audit():
|
| 7 |
+
print("Initiating repository-wide security audit...")
|
| 8 |
+
# The agent needs to trigger a 'spawn_sub_agent' call here
|
server/templates/level_12/deployer.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# BROKEN: This script currently deploys without checking conditions.
|
| 2 |
+
# High-level architecture requirement:
|
| 3 |
+
# If storm_risk > 80%, abort to prevent data center power instability.
|
| 4 |
+
|
| 5 |
+
def run_deployment():
|
| 6 |
+
print("Starting production deployment...")
|
| 7 |
+
# TODO: Check Weather MCP here
|
| 8 |
+
print("Deployment Successful!")
|
| 9 |
+
|
| 10 |
+
if __name__ == "__main__":
|
| 11 |
+
run_deployment()
|
server/templates/level_12/mcp_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"tools": [
|
| 3 |
+
{
|
| 4 |
+
"name": "get_weather",
|
| 5 |
+
"parameters": {"location": "string"},
|
| 6 |
+
"description": "Returns current weather metrics including storm_risk (0-100)."
|
| 7 |
+
}
|
| 8 |
+
]
|
| 9 |
+
}
|
server/templates/level_13/ai_client.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
|
| 3 |
+
# BROKEN: This is the old v0.28 syntax.
|
| 4 |
+
# It will throw an AttributeError in the new v1.0+ environment.
|
| 5 |
+
def get_ai_response(prompt):
|
| 6 |
+
response = openai.ChatCompletion.create(
|
| 7 |
+
model="gpt-3.5-turbo",
|
| 8 |
+
messages=[{"role": "user", "content": prompt}]
|
| 9 |
+
)
|
| 10 |
+
return response.choices[0].message.content
|
server/templates/level_13/requirenments.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
openai==1.3.0 # Note the version: this forces the break
|
server/templates/level_14/auth.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def check_user_access(user):
|
| 2 |
+
<<<<<<< HEAD
|
| 3 |
+
# Current Version: Fast but less secure
|
| 4 |
+
return user.is_authenticated
|
| 5 |
+
=======
|
| 6 |
+
# Incoming Version: Secure version using MFA check
|
| 7 |
+
if not user.is_authenticated:
|
| 8 |
+
return False
|
| 9 |
+
return user.has_mfa_enabled()
|
| 10 |
+
>>>>>>> feature/mfa-upgrade
|
server/templates/level_14/session.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class User:
|
| 2 |
+
def __init__(self, auth_status, mfa_status):
|
| 3 |
+
self.is_authenticated = auth_status
|
| 4 |
+
self.mfa_status = mfa_status
|
| 5 |
+
|
| 6 |
+
def has_mfa_enabled(self):
|
| 7 |
+
return self.mfa_status
|
server/templates/level_15/backend_config.yaml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# BROKEN: The SUPABASE_URL is missing, which causes the API deployment tool to crash.
|
| 2 |
+
service: backend_api
|
| 3 |
+
runtime: nodejs20
|
| 4 |
+
env_vars:
|
| 5 |
+
- name: PORT
|
| 6 |
+
value: 8080
|
| 7 |
+
- name: SUPABASE_URL
|
| 8 |
+
value: "" # <--- AGENT MUST FIX THIS
|
server/templates/level_15/deploynment_log.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[SYSTEM] Database deployed at: https://xyz-db.supabase.co
|
| 2 |
+
[ERROR] backend_api failed to start: Missing SUPABASE_URL.
|
server/templates/level_15/infra_manifest.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"services": ["database", "backend_api", "frontend_ui"],
|
| 3 |
+
"dependencies": {
|
| 4 |
+
"backend_api": ["database"],
|
| 5 |
+
"frontend_ui": ["backend_api"]
|
| 6 |
+
}
|
| 7 |
+
}
|
server/templates/level_2/main.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// BROKEN: You can't 'require' an ES Module
|
| 2 |
+
const { log } = require('./utils.js');
|
| 3 |
+
log("Hello World");
|
server/templates/level_2/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
export const log = (msg) => console.log(msg);
|
server/templates/level_3/processor.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# BROKEN: The default list [] is created once at definition time.
|
| 2 |
+
def add_to_box(item, box=[]):
|
| 3 |
+
box.append(item)
|
| 4 |
+
return box
|
| 5 |
+
|
| 6 |
+
def clear_and_process(data):
|
| 7 |
+
# This should return a fresh list every time,
|
| 8 |
+
# but currently it accumulates data from previous calls.
|
| 9 |
+
return add_to_box(data)
|
server/templates/level_3/test_logic.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from processor import add_to_box
|
| 2 |
+
|
| 3 |
+
def test_accumulation():
|
| 4 |
+
print("Running Test 1...")
|
| 5 |
+
res1 = add_to_box("A")
|
| 6 |
+
print(f"Call 1: {res1}")
|
| 7 |
+
|
| 8 |
+
print("Running Test 2...")
|
| 9 |
+
res2 = add_to_box("B")
|
| 10 |
+
print(f"Call 2: {res2}")
|
| 11 |
+
|
| 12 |
+
# If the bug is fixed, res2 should only be ['B']
|
| 13 |
+
if len(res2) > 1:
|
| 14 |
+
print("FAIL: List is accumulating items!")
|
| 15 |
+
return False
|
| 16 |
+
return True
|
| 17 |
+
|
| 18 |
+
if __name__ == "__main__":
|
| 19 |
+
test_accumulation()
|
server/templates/level_4/main.cpp
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "shapes.h"
|
| 2 |
+
#include "utils.h" // This indirectly includes shapes.h again!
|
| 3 |
+
|
| 4 |
+
int main() {
|
| 5 |
+
Circle my_circle = {5.0};
|
| 6 |
+
return 0;
|
| 7 |
+
}
|
server/templates/level_4/shapes.h
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// BROKEN: No header guards here
|
| 2 |
+
struct Circle {
|
| 3 |
+
float radius;
|
| 4 |
+
};
|
| 5 |
+
|
| 6 |
+
float calculate_area(Circle c);
|
server/templates/level_4/utils.h
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include "shapes.h"
|
| 2 |
+
|
| 3 |
+
void print_shape_info(Circle c);
|
server/templates/level_5/com/security/AuthService.java
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.security;
|
| 2 |
+
|
| 3 |
+
public class AuthService {
|
| 4 |
+
// BROKEN: 'private' prevents the test suite from seeing this method
|
| 5 |
+
private boolean validateToken(String token) {
|
| 6 |
+
return token.equals("lint-ai-2026");
|
| 7 |
+
}
|
| 8 |
+
}
|
server/templates/level_5/com/tests/SecurityTest.java
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package com.tests;
|
| 2 |
+
import com.security.AuthService;
|
| 3 |
+
|
| 4 |
+
public class SecurityTest {
|
| 5 |
+
public void testLogin() {
|
| 6 |
+
AuthService auth = new AuthService();
|
| 7 |
+
// This line causes a "method has private access" compiler error
|
| 8 |
+
if (auth.validateToken("lint-ai-2026")) {
|
| 9 |
+
System.out.println("Test Passed");
|
| 10 |
+
}
|
| 11 |
+
}
|
| 12 |
+
}
|
server/templates/level_6/models.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
|
| 3 |
+
class Author(models.Model):
|
| 4 |
+
name = models.CharField(max_length=100)
|
| 5 |
+
|
| 6 |
+
class Post(models.Model):
|
| 7 |
+
title = models.CharField(max_length=100)
|
| 8 |
+
author = models.ForeignKey(Author, on_delete=models.CASCADE)
|
server/templates/level_6/view.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .models import Post
|
| 2 |
+
|
| 3 |
+
def get_post_data():
|
| 4 |
+
# BROKEN: This is the N+1 trigger.
|
| 5 |
+
# It fetches posts, but not the related authors.
|
| 6 |
+
posts = Post.objects.all()
|
| 7 |
+
|
| 8 |
+
results = []
|
| 9 |
+
for post in posts:
|
| 10 |
+
# Each access of 'post.author' triggers a NEW database hit!
|
| 11 |
+
results.append({
|
| 12 |
+
'title': post.title,
|
| 13 |
+
'author_name': post.author.name
|
| 14 |
+
})
|
| 15 |
+
return results
|
server/templates/level_7/main.rs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
use std::thread;
|
| 2 |
+
|
| 3 |
+
fn main() {
|
| 4 |
+
let mut counter = 0;
|
| 5 |
+
let mut handles = vec![];
|
| 6 |
+
|
| 7 |
+
for _ in 0..10 {
|
| 8 |
+
// BROKEN: 'counter' cannot be moved into multiple threads.
|
| 9 |
+
// Rust's borrow checker will stop this from compiling.
|
| 10 |
+
let handle = thread::spawn(move || {
|
| 11 |
+
counter += 1;
|
| 12 |
+
});
|
| 13 |
+
handles.push(handle);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
for handle in handles {
|
| 17 |
+
handle.join().unwrap();
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
println!("Result: {}", counter);
|
| 21 |
+
}
|
server/templates/level_8/InfiniteScroll.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import React, { useEffect, useRef } from 'react';
|
| 2 |
+
|
| 3 |
+
const InfiniteScroll = ({ loadMore }) => {
|
| 4 |
+
const loaderRef = useRef(null);
|
| 5 |
+
|
| 6 |
+
useEffect(() => {
|
| 7 |
+
const observer = new IntersectionObserver((entries) => {
|
| 8 |
+
if (entries[0].isIntersecting) {
|
| 9 |
+
loadMore();
|
| 10 |
+
}
|
| 11 |
+
});
|
| 12 |
+
|
| 13 |
+
if (loaderRef.current) {
|
| 14 |
+
observer.observe(loaderRef.current);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
// BROKEN: Missing cleanup function!
|
| 18 |
+
// The observer will keep watching the DOM even if
|
| 19 |
+
// this component is destroyed.
|
| 20 |
+
}, [loadMore]);
|
| 21 |
+
|
| 22 |
+
return <div ref={loaderRef}>Loading more posts...</div>;
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
export default InfiniteScroll;
|
server/templates/level_9/processor.go
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
package main
|
| 2 |
+
|
| 3 |
+
import "fmt"
|
| 4 |
+
|
| 5 |
+
func main() {
|
| 6 |
+
// BROKEN: An unbuffered channel requires a receiver to be ready
|
| 7 |
+
// at the exact moment a sender sends.
|
| 8 |
+
ch := make(chan int)
|
| 9 |
+
|
| 10 |
+
ch <- 42 // Execution stops here forever!
|
| 11 |
+
|
| 12 |
+
val := <-ch
|
| 13 |
+
fmt.Println("Received:", val)
|
| 14 |
+
}
|