Conversation
- Create backend/schemas.py with canonical Pydantic v2 request models - Update unified_server.py handlers to use typed schemas instead of dict - Update transparency_endpoints.py ProvenanceQuery/ProvenanceSnapshot models - Fix frontend createKnowledgeSnapshot to send required fields Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
Remove stray test output JSON files and add gitignore pattern. Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Aligns FastAPI request validation with the actual Svelte frontend payloads by introducing shared Pydantic v2 schemas, updating several POST handlers to use typed models, and adding integration tests to prevent 422s from contract drift.
Changes:
- Added
backend/schemas.pyas a shared set of request models for frontend-facing POST endpoints. - Updated multiple handlers in
backend/unified_server.pyto accept typed schema models instead of rawdict. - Expanded provenance request models and adjusted the frontend provenance snapshot payload; added integration tests asserting no 422s for frontend-shaped requests.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
backend/schemas.py |
Adds canonical Pydantic request schemas intended to be reused across route handlers. |
backend/unified_server.py |
Switches several endpoints to typed request models (Wikipedia/URL/Text/Batch imports, add knowledge, enhanced cognitive query). |
backend/transparency_endpoints.py |
Updates provenance request models to accept frontend fields and allow empty snapshot bodies. |
svelte-frontend/src/utils/api.js |
Sends explicit provenance snapshot fields (description, include_quality_metrics). |
tests/integration/test_api_schema_contracts.py |
Adds in-process TestClient tests using frontend payload shapes to catch schema 422s. |
.gitignore |
Ignores generated query test JSON artifacts; removes previously committed test output files from tracking via deletion. |
| query = query_request.query | ||
| reasoning_trace = query_request.reasoning_trace | ||
| context = query_request.context or {} |
There was a problem hiding this comment.
In enhanced_cognitive_query, query_request is now a Pydantic model, but the fallback path later still calls query_request.get("context", {}). That will raise AttributeError and prevents the intended godelos_integration.process_query(...) fallback from ever using the provided context. Use query_request.context (or the already-derived context variable) instead of .get(...) throughout this handler.
| class ProvenanceQuery(BaseModel): | ||
| """Provenance query model.""" | ||
| query_type: str | ||
| target_id: str | ||
| """Provenance query model. | ||
|
|
||
| Accepts the full set of fields sent by the frontend (max_depth, | ||
| time_window_start, time_window_end) as well as the original backend | ||
| fields (include_derivation_chain). | ||
| """ | ||
| query_type: str = "backward_trace" | ||
| target_id: str = "default" | ||
| max_depth: int = 5 | ||
| time_window_start: Optional[float] = None | ||
| time_window_end: Optional[float] = None | ||
| include_derivation_chain: bool = True | ||
|
|
||
| class ProvenanceSnapshot(BaseModel): | ||
| """Provenance snapshot model.""" | ||
| description: str | ||
| """Provenance snapshot model. | ||
|
|
||
| ``description`` defaults to empty string so the frontend can POST ``{}`` | ||
| without triggering a 422 validation error. | ||
| """ | ||
| description: str = "" | ||
| include_quality_metrics: bool = True |
There was a problem hiding this comment.
This file now expands ProvenanceQuery/ProvenanceSnapshot to match frontend payloads, but the PR also introduces equivalent “canonical” provenance schemas in backend/schemas.py. Having two independent request-model definitions for the same endpoints risks contract drift. Consider importing and using the shared schema models here (or removing the unused canonical versions) so there is a single source of truth.
| @pytest.fixture(scope="module") | ||
| def client(): | ||
| """Create a TestClient bound to the unified FastAPI app.""" | ||
| from backend.unified_server import app | ||
| return TestClient(app, raise_server_exceptions=False) | ||
|
|
There was a problem hiding this comment.
These tests claim to confirm requests are “accepted”, but they only assert status_code != 422 while also using raise_server_exceptions=False. This means 404/500 responses (route missing or handler crash) would still pass, which can hide real regressions unrelated to schema validation. Consider either tightening assertions per-endpoint (e.g., allow 200/400/404/503 as appropriate but fail on unexpected 5xx), or update the module docstring/comments to clearly state the tests only guard against 422 validation failures.
…orkspace), #118 (EmergenceDetector), #119 (transparency), #120 (ChromaDB) Resolve .gitignore conflict (keep both gitignore entries). unified_consciousness_engine.py auto-merged cleanly: IIT φ calculator coexists with GlobalWorkspace broadcaster. All 51 tests pass (30 IIT + 21 GlobalWorkspace). Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
- Use BatchImportSchema from shared schemas for batch endpoint - Fix file_type response to return determined_file_type - Fix over-indented except block in file import handler - Add per-item results to batch response - Remove unused asyncio import from test module - Update validation tests: expect 422 for Pydantic validation errors Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
…#116) * Initial plan * feat(iit): implement bipartition MI approximation for calculate_phi and add unit tests Replace the heuristic-based InformationIntegrationTheory.calculate_phi() with a tractable bipartition mutual-information approximation (Tononi 2004): - Convert subsystem dicts to numeric vectors via recursive flattening - Enumerate all non-trivial bipartitions at subsystem level (63 cuts) - φ = min MI across all cuts, with noise-floor suppression for idle states - Preserve contradiction penalty from self-model validator - Add 'phi' field to WebSocket broadcast payload for acceptance criteria - 27 unit tests: idle→φ=0, active→φ>0, penalty, helpers, performance <50ms Co-authored-by: Steake <530040+Steake@users.noreply.github.com> * address code review: document magic numbers, add division guard, expand test coverage Co-authored-by: Steake <530040+Steake@users.noreply.github.com> * merge: integrate main with PRs #114 (schema contracts), #117 (GlobalWorkspace), #118 (EmergenceDetector), #119 (transparency), #120 (ChromaDB) Resolve .gitignore conflict (keep both gitignore entries). unified_consciousness_engine.py auto-merged cleanly: IIT φ calculator coexists with GlobalWorkspace broadcaster. All 51 tests pass (30 IIT + 21 GlobalWorkspace). Co-authored-by: Steake <530040+Steake@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Steake <530040+Steake@users.noreply.github.com>
…owledge-endpoints # Conflicts: # backend/unified_server.py # godelOS/core_kr/knowledge_store/__init__.py
Description
Backend endpoint handlers accepted raw
dictwith no validation, field names diverged from what the frontend actually sends, and there was no shared schema layer. Example: frontend sends{title}for Wikipedia import but the formal model expectspage_title; frontend sends{}for provenance snapshots butdescriptionwas required.Changes
backend/schemas.py(new) — Canonical Pydantic v2 request models for all frontend-facing POST endpoints. Single source of truth for the API contract.backend/unified_server.py— 6 endpoint handlers (/api/knowledge,/api/knowledge/import/{wikipedia,url,text,batch},/api/enhanced-cognitive/query) changed fromdictto typed schema models.backend/transparency_endpoints.py—ProvenanceQuerygainsmax_depth,time_window_start/endfields the frontend sends.ProvenanceSnapshot.descriptiondefaults to""so{}doesn't 422.svelte-frontend/src/utils/api.js—createKnowledgeSnapshot()sends explicitdescriptionfield.tests/integration/test_api_schema_contracts.py(new) — 19 in-process tests sending exact frontend payloads viaTestClient, asserting zero 422s.Related Issues
Test Evidence
Checklist
pytest tests/)black .andisort .)Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.