fix(fieldtype): closed contract lists and kind comparisons are fixed in code #26

Open
opened 2026-11-18 11:30:16 +01:00 by michael · 0 comments
Owner

Problem

Contract values are fixed in the code of berhtjan-core. There must be
no fixed values or comparisons in code: a program has to be adaptable by
data and configuration, without changing the program.

Found in a review of the DAW ecosystem against its contracts:

  • fieldtype.lua (lines 44-50) repeats closed lists that stand as
    allowed in the contract.json of daw_field_type/v1:
    ACQUISITION_KINDS, COLLECTION_SOURCES, CARDINALITIES,
    CONSTRAINT_KEYS
  • fieldtype.lua:91 and response.lua:126 compare entry.kind against
    the literal "selection"

Goal

The values come from data (the contract), not from literals in the code.
A change of a closed list in the contract needs no change of the code.

Questions for the implementation

  • the contract at run time or at build time (a file generated from it)?
    How does the module get the contract data?
  • the comparisons with "selection" decide which mechanism is used
    (selection). How does this relate to "no fixed comparisons"?
    To be decided before the implementation.

Acceptance criteria

  • tests first: a value that is only in the contract data is accepted
    without a code change; a value that is not in it is rejected
  • no literal contract value is left in fieldtype.lua and
    response.lua
  • a fixture test keeps the data and the contract in line
  • fragjan code . and make test (Lua 5.1 and 5.4) pass

DAW/daw-modul-berhtjan-cli (the same finding in answer.lua),
DAW/daw-contracts (daw_field_type/v1), DAW/fragjan#154, DAW/fragjan#155,
DAW/fragjan#156 (the same rule in fragjan)

## Problem Contract values are fixed in the code of `berhtjan-core`. There must be no fixed values or comparisons in code: a program has to be adaptable by data and configuration, without changing the program. Found in a review of the DAW ecosystem against its contracts: - `fieldtype.lua` (lines 44-50) repeats closed lists that stand as `allowed` in the `contract.json` of `daw_field_type/v1`: `ACQUISITION_KINDS`, `COLLECTION_SOURCES`, `CARDINALITIES`, `CONSTRAINT_KEYS` - `fieldtype.lua:91` and `response.lua:126` compare `entry.kind` against the literal `"selection"` ## Goal The values come from data (the contract), not from literals in the code. A change of a closed list in the contract needs no change of the code. ## Questions for the implementation - the contract at run time or at build time (a file generated from it)? How does the module get the contract data? - the comparisons with `"selection"` decide which mechanism is used (selection). How does this relate to "no fixed comparisons"? To be decided before the implementation. ## Acceptance criteria - [ ] tests first: a value that is only in the contract data is accepted without a code change; a value that is not in it is rejected - [ ] no literal contract value is left in `fieldtype.lua` and `response.lua` - [ ] a fixture test keeps the data and the contract in line - [ ] `fragjan code .` and `make test` (Lua 5.1 and 5.4) pass ## Related DAW/daw-modul-berhtjan-cli (the same finding in `answer.lua`), DAW/daw-contracts (`daw_field_type/v1`), DAW/fragjan#154, DAW/fragjan#155, DAW/fragjan#156 (the same rule in fragjan)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-modul-berhtjan-core#26
No description provided.