Spaces:
Sleeping
Sleeping
Publish unsolved challenge snapshots and fix keyless notice
Browse filesFiles changed (7)
977 unmodified lines978979980981982983984977 unmodified lines_require_idle_session(session)valid, message = validate_api_key(payload.api_key)if not valid:raise HTTPException(status_code=401, detail=message)with session.thread_lock:if session.active_job_id:raise HTTPException(status_code=409, detail="Finish the active operation before changing your API key")977 unmodified lines978979980981982983984977 unmodified lines_require_idle_session(session)valid, message = validate_api_key(payload.api_key)if not valid:raise HTTPException(status_code=422, detail=message)with session.thread_lock:if session.active_job_id:raise HTTPException(status_code=409, detail="Finish the active operation before changing your API key")
665 unmodified lines666667668669670671665 unmodified linesself.assertEqual(session.api_key, "current-key")validate.assert_not_called()def test_queued_submission_scores_with_key_captured_at_enqueue(self):from llm_config import _LLM_CREDENTIALS665 unmodified lines666667668669670671672673674675676677678679680681682665 unmodified linesself.assertEqual(session.api_key, "current-key")validate.assert_not_called()def test_invalid_model_key_keeps_authenticated_session_active(self):session = self.add_session(api_key="")with patch.object(api, "validate_api_key", return_value=(False, "Invalid model API key")):response = self.client.post("/api/session/model-key", json={"api_key": "invalid-key"})self.assertEqual(response.status_code, 422)self.assertEqual(response.json()["detail"], "Invalid model API key")self.assertEqual(self.client.get("/api/session").status_code, 200)self.assertTrue(self.client.get("/api/session").json()["authenticated"])self.assertEqual(session.api_key, "")def test_queued_submission_scores_with_key_captured_at_enqueue(self):from llm_config import _LLM_CREDENTIALS
245 unmodified lines246247248249250251245 unmodified linesprivate_state_path.write_text(json.dumps(private_state, indent=2, ensure_ascii=False), encoding="utf-8")private_state_path.chmod(0o600)state_path.write_text(json.dumps(_student_visible_state(private_state), indent=2, ensure_ascii=False), encoding="utf-8")(template / "detailed_explanation.txt").unlink(missing_ok=True)artifact_hash, tests_hash = _round_hashes(template, private_workspace_dir(template))manifest: dict[str, str | int] = {245 unmodified lines246247248249250251252253254255256257245 unmodified linesprivate_state_path.write_text(json.dumps(private_state, indent=2, ensure_ascii=False), encoding="utf-8")private_state_path.chmod(0o600)state_path.write_text(json.dumps(_student_visible_state(private_state), indent=2, ensure_ascii=False), encoding="utf-8")round_workspace = ChallengeWorkspace(template)if challenge.sabotaged_files:for relative_path, received_code in challenge.sabotaged_files.items():round_workspace.write_file(relative_path, received_code)else:round_workspace.reset_target()(template / "detailed_explanation.txt").unlink(missing_ok=True)artifact_hash, tests_hash = _round_hashes(template, private_workspace_dir(template))manifest: dict[str, str | int] = {
198 unmodified lines19920020120220320420520620720820925 unmodified lines235236237238239240198 unmodified linesexpect(screen.getByText(/without a key, access is very limited/i)).toBeTruthy();await user.click(screen.getByRole("button", { name: /continue with limited access/i }));expect(await screen.findByRole("button", { name: /join round/i })).toBeTruthy();expect(screen.getByText("Limited access without a model key")).toBeTruthy();expect(screen.getByText(/you can join existing challenges, run tests and submit/i)).toBeTruthy();expect(screen.queryByLabelText(/public github repository/i)).toBeNull();expect(screen.getByText(/challenge creation, ai chat\/hints, and ai review are disabled/i)).toBeTruthy();cleanup();render(<App />);expect(await screen.findByRole("button", { name: /join round/i })).toBeTruthy();25 unmodified linesexpect(await screen.findByLabelText(/public github repository/i)).toBeTruthy();});it("lets instructors manage rounds and choose only approved repositories", async () => {const user = userEvent.setup();mocks.config.mockResolvedValue({ hf_oauth: false, google_oauth: true, dev_login: false, dev_diagnostics: false, model_key_configured: true, course_mode: true, approved_repositories: ["https://github.com/acme/approved"] });198 unmodified lines19920020120220320420520620720820921021121221321421525 unmodified lines241242243244245246247248249250251252253254255256257258259260261262263198 unmodified linesexpect(screen.getByText(/without a key, access is very limited/i)).toBeTruthy();await user.click(screen.getByRole("button", { name: /continue with limited access/i }));expect(await screen.findByRole("button", { name: /join round/i })).toBeTruthy();const limitedNoticeTitle = screen.getByText("Limited access without a model key");expect(limitedNoticeTitle.closest(".keyless-notice")?.classList.contains("global-notice")).toBe(false);expect(screen.getByText(/you can join existing challenges, run tests and submit/i)).toBeTruthy();expect(screen.queryByLabelText(/public github repository/i)).toBeNull();expect(screen.getByText(/challenge creation, ai chat\/hints, and ai review are disabled/i)).toBeTruthy();await user.click(screen.getByRole("button", { name: /connect model key/i }));expect(await screen.findByLabelText("OpenAI API key")).toBeTruthy();expect(screen.getByPlaceholderText("Paste round code")).toBeTruthy();await user.click(screen.getByRole("button", { name: "Cancel" }));cleanup();render(<App />);expect(await screen.findByRole("button", { name: /join round/i })).toBeTruthy();25 unmodified linesexpect(await screen.findByLabelText(/public github repository/i)).toBeTruthy();});it("keeps keyless access active when the entered model key is rejected", async () => {const user = userEvent.setup();mocks.config.mockResolvedValue({ hf_oauth: true, google_oauth: false, dev_login: false, dev_diagnostics: false, model_key_configured: false, course_mode: false, approved_repositories: [] });mocks.session.mockResolvedValue({ authenticated: true, identity, role: "student", has_model_key: false, workspace_id: null });mocks.saveModelKey.mockRejectedValue(new Error("Invalid model API key"));render(<App />);await user.click(await screen.findByRole("button", { name: /continue with limited access/i }));await user.click(screen.getByRole("button", { name: /connect model key/i }));await user.type(screen.getByLabelText("OpenAI API key"), "invalid-key");await user.click(screen.getByRole("button", { name: /validate and connect/i }));expect((await screen.findByRole("alert")).textContent).toContain("Invalid model API key");expect(screen.getByRole("button", { name: /join round/i })).toBeTruthy();expect(screen.queryByRole("heading", { name: "Enter the lab" })).toBeNull();});it("lets instructors manage rounds and choose only approved repositories", async () => {const user = userEvent.setup();mocks.config.mockResolvedValue({ hf_oauth: false, google_oauth: true, dev_login: false, dev_diagnostics: false, model_key_configured: true, course_mode: true, approved_repositories: ["https://github.com/acme/approved"] });
924 unmodified lines925926927928929930931924 unmodified lines</header>{error && <div className="global-notice notice-error" role="alert"><AlertCircle size={17} />{error}<button className="notice-dismiss" onClick={() => setError("")} aria-label="Dismiss"><XCircle size={16} /></button></div>}{!hasModelAccess && <div className="global-notice notice-warning keyless-notice" role="status"><span className="keyless-notice-icon"><KeyRound size={18} /></span><div className="keyless-notice-copy"><strong>Limited access without a model key</strong>924 unmodified lines925926927928929930931924 unmodified lines</header>{error && <div className="global-notice notice-error" role="alert"><AlertCircle size={17} />{error}<button className="notice-dismiss" onClick={() => setError("")} aria-label="Dismiss"><XCircle size={16} /></button></div>}{!hasModelAccess && <div className="keyless-notice notice notice-warning" role="status"><span className="keyless-notice-icon"><KeyRound size={18} /></span><div className="keyless-notice-copy"><strong>Limited access without a model key</strong>
97 unmodified lines989910010110210310497 unmodified lines.icon-button { display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid transparent; border-radius: 6px; color: #617282; background: transparent; }.icon-button:hover { border-color: var(--line); color: var(--coral); background: #fff; }.global-notice { position: fixed; z-index: 30; top: 70px; right: 24px; left: 24px; max-width: 850px; margin: auto; box-shadow: 0 6px 24px #17243618; }.keyless-notice { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 13px; padding: 14px 16px; }.keyless-notice-icon { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid #e8cf98; border-radius: 8px; color: #885d1b; background: #fff8e9; }.keyless-notice-copy { display: grid; min-width: 0; gap: 4px; }.keyless-notice-copy strong { color: #61450f; font-size: 13px; }97 unmodified lines989910010110210310497 unmodified lines.icon-button { display: grid; width: 32px; height: 32px; place-items: center; border: 1px solid transparent; border-radius: 6px; color: #617282; background: transparent; }.icon-button:hover { border-color: var(--line); color: var(--coral); background: #fff; }.global-notice { position: fixed; z-index: 30; top: 70px; right: 24px; left: 24px; max-width: 850px; margin: auto; box-shadow: 0 6px 24px #17243618; }.keyless-notice { display: grid; width: min(calc(100% - 48px), 1480px); max-width: 1480px; align-items: center; grid-template-columns: auto minmax(0, 1fr) auto; gap: 13px; margin: 14px auto; padding: 14px 16px; box-shadow: 0 4px 16px #1724360d; }.keyless-notice-icon { display: grid; width: 38px; height: 38px; place-items: center; border: 1px solid #e8cf98; border-radius: 8px; color: #885d1b; background: #fff8e9; }.keyless-notice-copy { display: grid; min-width: 0; gap: 4px; }.keyless-notice-copy strong { color: #61450f; font-size: 13px; }
76 unmodified lines7778798081826 unmodified lines89909192939476 unmodified lines(source_private / "challenge_run_public.py").write_text("public runner\n", encoding="utf-8")(source_private / "challenge_run_secret.py").write_text("secret runner\n", encoding="utf-8")(source_private / "secret_tests.json").write_text('{"secret_tests": []}', encoding="utf-8")round_info = create_challenge_round(source, timer_minutes=30)first_path, first_round = create_challenge_from_round(round_info["round_id"], str(uuid4()))6 unmodified linesself.assertNotIn("original_bug_func_source", visible_state)self.assertFalse((Path(first_path) / "detailed_explanation.txt").exists())self.assertEqual(first_workspace.original_code, "def broken(): return 1\n")self.assertEqual(first_round["artifact_hash"], second_round["artifact_hash"])self.assertEqual(first_round["tests_hash"], second_round["tests_hash"])76 unmodified lines777879808182836 unmodified lines909192939495969776 unmodified lines(source_private / "challenge_run_public.py").write_text("public runner\n", encoding="utf-8")(source_private / "challenge_run_secret.py").write_text("secret runner\n", encoding="utf-8")(source_private / "secret_tests.json").write_text('{"secret_tests": []}', encoding="utf-8")(source / "sample.py").write_text("def broken(): return 1\n", encoding="utf-8")round_info = create_challenge_round(source, timer_minutes=30)first_path, first_round = create_challenge_from_round(round_info["round_id"], str(uuid4()))6 unmodified linesself.assertNotIn("original_bug_func_source", visible_state)self.assertFalse((Path(first_path) / "detailed_explanation.txt").exists())self.assertEqual(first_workspace.original_code, "def broken(): return 1\n")self.assertEqual((source / "sample.py").read_text(encoding="utf-8"), "def broken(): return 1\n")self.assertEqual(first_workspace.read_file("sample.py"), "def broken(): return None\n")self.assertEqual(first_round["artifact_hash"], second_round["artifact_hash"])self.assertEqual(first_round["tests_hash"], second_round["tests_hash"])
backend/app.py+1-1
backend/test_api.py+11
challenge_runtime.py+6
frontend/src/App.test.tsx+24-1
frontend/src/App.tsx+1-1
frontend/src/styles.css+1-1
test_challenge_runtime.py+3