Fix defects of build_response and the field-type check found in review #23

Closed
opened 2026-11-16 16:26:42 +01:00 by michael · 1 comment
Owner

Problem

A code review of build_response (response.lua) and the field-type check
(fieldtype.lua) found defects that were reproduced with small inputs on
Lua 5.1 and 5.4:

  1. multiple: only the list part of the value is checked. For a field
    with the values a, b the values { "a", extra = "bogus" },
    { x = "bogus" } and { "a", nil, "bogus" } give a valid response.
    {} and { "a", "a" } are accepted too, although cli.select
    refuses duplicates.
  2. The response keeps the table the caller passed in; a later change by
    the caller changes response.data.value (a response is never modified
    after creation).
  3. declared_values uses entry.value or entry: an entry
    { value = false, message = "No" } declares the entry table itself,
    not false, and an object without value is its own value.
  4. collection.values = { 0/0, "a" } raises a Lua error (table index is NaN) instead of returning nil, err; the check of the field does
    not look into values.
  5. A wrong cardinality value reports the rule #required-cardinality;
    the contract example invalid-cardinality-value expects
    #closed-cardinality-vocabulary.
  6. The closed vocabulary (collection.source, resource.kind,
    constraint keys) is only checked when selection is present.
  7. lang.lua (no_language_resolvable) has an error site without a
    resource_id.

Scope

Fix each defect with a test first. Keep the behaviour that the contract
and the existing tests define. Points 6 and 3 touch what the contract
says about values entries (DAW/daw-contracts#17); where the contract is
silent the code reports an error and does not guess.

Acceptance criteria

  • a failing test per defect, then the fix
  • fragjan code . and make test (Lua 5.1 and 5.4) pass

DAW/daw-modul-berhtjan-core#21, DAW/daw-contracts#17

## Problem A code review of `build_response` (response.lua) and the field-type check (fieldtype.lua) found defects that were reproduced with small inputs on Lua 5.1 and 5.4: 1. `multiple`: only the list part of the value is checked. For a field with the values `a`, `b` the values `{ "a", extra = "bogus" }`, `{ x = "bogus" }` and `{ "a", nil, "bogus" }` give a valid response. `{}` and `{ "a", "a" }` are accepted too, although `cli.select` refuses duplicates. 2. The response keeps the table the caller passed in; a later change by the caller changes `response.data.value` (a response is never modified after creation). 3. `declared_values` uses `entry.value or entry`: an entry `{ value = false, message = "No" }` declares the entry table itself, not `false`, and an object without `value` is its own value. 4. `collection.values = { 0/0, "a" }` raises a Lua error (`table index is NaN`) instead of returning `nil, err`; the check of the field does not look into `values`. 5. A wrong cardinality value reports the rule `#required-cardinality`; the contract example `invalid-cardinality-value` expects `#closed-cardinality-vocabulary`. 6. The closed vocabulary (`collection.source`, `resource.kind`, constraint keys) is only checked when `selection` is present. 7. `lang.lua` (`no_language_resolvable`) has an error site without a `resource_id`. ## Scope Fix each defect with a test first. Keep the behaviour that the contract and the existing tests define. Points 6 and 3 touch what the contract says about `values` entries (DAW/daw-contracts#17); where the contract is silent the code reports an error and does not guess. ## Acceptance criteria - [ ] a failing test per defect, then the fix - [ ] `fragjan code .` and `make test` (Lua 5.1 and 5.4) pass ## Related DAW/daw-modul-berhtjan-core#21, DAW/daw-contracts#17
Author
Owner

Implemented on main

Commits: bbb159c

Pushed. Follow-up points, if any, are tracked in their own issues.

## Implemented on main Commits: bbb159c Pushed. Follow-up points, if any, are tracked in their own issues.
michael 2026-11-18 11:57:40 +01:00
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#23
No description provided.