feat: ui program to cb connection #26
Reference in New Issue
Block a user
Delete Branch "feat/recieve-programs-ui"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
scheme for a program defined in the cb.
ui can now send /program messages to the cb.
To validate this merge do the following.
ref: N25B-198
changed the description
assigned to @2584433
Was aan het testen met een AI agent code review (ben het i.i.g. eens met het major punt):
Thanks for the contribution!
This MR introduces a new
/programendpoint for the control backend to receive program definitions from a UI. The code is well-structured, includes thorough tests, and successfully implements the core requirement.I have a few suggestions to improve the API design and code clarity.
Major
API contract could be more direct
In
src/control_backend/api/v1/endpoints/program.py, thereceive_messagefunction accepts a genericMessageobject and then parses a JSON string from within it.This makes the API contract less clear, as the actual data structure (
Program) is hidden within a string. By defining the endpoint to accept theProgrammodel directly, FastAPI will handle the JSON deserialization and validation automatically. This simplifies the code and makes the API self-documenting.Suggestion:
Refactor the endpoint to accept the
Programmodel directly.With this change, the client would send a JSON object matching the
Programschema directly in the request body, rather than wrapping it in another JSON object. The corresponding endpoint tests would also need to be updated.Minor
Variable naming in endpoint
In
src/control_backend/api/v1/endpoints/program.py, the input parameter is namedprogrambut is typed as aMessageobject. The nameprogramis then reused for the parsedProgramobject. This can be a bit confusing when reading the code.Suggestion:
Use a more descriptive name for the input message, for example
program_message.Nitpicks
Camel case in Pydantic models
In
src/control_backend/schemas/program.py, the Pydantic model fields use camelCase (e.g.,nextPhaseId,phaseData). While this might be to match an external schema (e.g., from the UI), the standard Python convention is snake_case. Pydantic can automatically handle the conversion.Suggestion:
Consider using
snake_casefor model fields and configure Pydantic to serialize to/fromcamelCaseif needed by the client.Testing
model_validateIn
test/integration/schemas/test_ui_program_message.py, the tests useProgram.model_validate(program)on an object that is already a Pydantic model instance (program = base_program()).model_validateis typically used for validating raw Python dicts. This test still works, but it's not testing the primary use case of validation from a plain dictionary.Suggestion:
To more accurately test the validation logic, create a dictionary fixture and use that for the validation test. The existing helper functions are a great starting point for this.
requested review from @9828273
marked the checklist item Make sure this branch is up to date with dev as completed
marked the checklist item Make sure this branch is up to date with dev as incomplete
marked the checklist item Integration tests run. as completed
If you have WSL installed, you can run this curl command to test the endpoint
for windows powershell inside VScode, try this:
Invoke-RestMethod -Uri "http://localhost:8000/program"
-Method Post-ContentType "application/json" `
-Body '{
"phases": [
{
"id": "phase1",
"name": "basephase",
"nextPhaseId": "phase2",
"phaseData": {
"norms": [ { "id": "n1", "name": "norm", "value": "be nice" } ],
"goals": [ { "id": "g1", "name": "goal", "description": "test", "achieved": false } ],
"triggers": [
{ "id": "t1", "label": "trigger", "type": "keyword", "value": ["stop", "exit"] }
]
}
}
]
}' | ConvertTo-Json -Depth 5
added 1 commit
39c07dd3- refactor: made pydantic check the input.Compare with previous version
changed the description
marked the checklist item When running the cb you can manually test a test case by inputting the comment into a new terminal. (this simulates a UI input) as completed
marked the checklist item Make sure this branch is up to date with dev as completed
approved this merge request
marked the checklist item Make sure this branch is up to date with dev as incomplete
added 21 commits
dev964997f8- Merge branch 'dev' of https://git.science.uu.nl/ics/sp/2025/n25b/pepperplus-cb...Compare with previous version
marked the checklist item Make sure this branch is up to date with dev as completed
approved this merge request
mentioned in commit
4fc3c2a1e1