Repository navigation
fix: restore backend startup (could not import) + repair CLI syntax errors, add tests - #8
Merged
Merged
Conversation
The backend could not start at all. Fixes four defects that each block import or execution: 1. backend/config.py - Settings no longer defined OPENAI_API_KEY / OPENAI_MODEL, but the validation block read settings.OPENAI_API_KEY, raising AttributeError: 'Settings' object has no attribute 'OPENAI_API_KEY' at import. Regression introduced by 5e43b24, which deleted the two field definitions and in the same commit added the validation that reads them. Restored both fields. 2. backend/routers/chat.py:18 - docstring indented 8 spaces inside a 4-space function body -> IndentationError, blocking main.py. 3. scripts/cli.py:151 - string literal split across real newlines -> SyntaxError: unterminated string literal. Restored the \n escapes. 4. scripts/nethermind.py - main() read global API_BASE (line 251) before its global declaration (line 329) -> SyntaxError. Moved the declaration to the top of main(). Verified: import main -> OK with 67 routes; uvicorn serves / , /api/switches/, /api/dashboard/stats, /docs, /openapi.json all 200; scripts/nethermind.py --help runs; full tree compiles with 0 syntax errors.
The repo declared pytest config (testpaths=["tests"], python_files=["test_*.py"]) but shipped no tests — tests/ contained only a mock_switch.py helper. - tests/conftest.py — puts backend/ on sys.path and redirects DATABASE_URL to a temporary sqlite file *before* main is imported, so the real switches.db is never touched. Tests use a per-test TestClient fixture. - tests/test_api.py — 11 tests: app metadata, OpenAPI route presence, dashboard stats shape, switch list/create/read-back, dashboard count reflects a created switch, and 5 pure-logic unit tests of the ArubaOS/ProCurve running-config parser (scalars, role detection, services, VLAN block parsing, empty input). - frontend/package-lock.json — npm synced the stale package name "nethermind" to "netcore" while building; matches package.json. Verified: cd . && .venv/bin/python -m pytest tests/ -q -> 11 passed. DB isolation verified by mtime (real switches.db untouched). ruff clean on both new files. gitleaks clean.
Owner
Author
|
Superseded by #9, which was retargeted to This branch was stacked, and its CI showed Verified: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The backend cannot start at all.
import maindies with:Four separate defects each block import or execution.
N1 — CRITICAL: missing Settings fields break startup
backend/config.pyreadssettings.OPENAI_API_KEYin its validation block, but theSettingsmodel no longer defines that field (norOPENAI_MODEL).Git history pins it: commit
5e43b24deleted these linesand in the same commit added the validation
if not settings.OPENAI_API_KEY:. Everycommit up to
9d9c4b6defined the fields and was importable;5e43b24broke startupcompletely for API, CLI, Docker and docs alike.
N2 — syntax error in
backend/routers/chat.pyLine 18's docstring was indented 8 spaces inside a 4-space function →
IndentationError.This blocked
main.pyimmediately after N1 was cleared.N3 — syntax error in
scripts/cli.pyLine 151 held a string literal split by real newlines →
SyntaxError: unterminated string literal.N4 — syntax error in
scripts/nethermind.pymain()read module-globalAPI_BASE(line 251, in the--helpf-string) before itsglobal API_BASEdeclaration (line 329) →SyntaxError: name 'API_BASE' is used prior to global declaration.Changes
OPENAI_API_KEY/OPENAI_MODELtoSettings(+ comment so they aren't removed again).chat.py.\nescapes incli.py.global API_BASEto the top ofmain().frontend/package-lock.json: npm synced the stale namenethermind→netcore.AUDIT.mdandPERSONA.md.Verification (real commands)
import mainuvicorn main:appGET /,/api/switches/,/api/dashboard/stats,/docs,/openapi.jsonpytest tests/ -qscripts/nethermind.py --helpgitleaksnpm run build→ compiled, TypeScript clean, 12 pages.backend/switches.dbwas untouched.Not verified (honest gaps)
docker-compose.ymlwas not run.rufferrors (195 auto-fixable) are not touched here — that belongs in its own reviewed PR rather than mixed into a critical fix.AGENTS.mdandCLAUDE.mdare pre-existing untracked files in the repo root; deliberately left alone.Publishing mode is
draft: this PR is for review, nothing was released.