Skip to content

feat(validators): add study validator library and studyu_validator CLI#866

Draft
ibrahimozkn wants to merge 28 commits into
devfrom
feature/study-validator-clean
Draft

feat(validators): add study validator library and studyu_validator CLI#866
ibrahimozkn wants to merge 28 commits into
devfrom
feature/study-validator-clean

Conversation

@ibrahimozkn

@ibrahimozkn ibrahimozkn commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

Adds a composable study validator to core, a standalone studyu_validator CLI package, and a deterministic docs generator for studyu_core models.

core — validator library:

  • ValidationLevel (draft / publish) and ValidationResult types
  • Nine entity validators: study_info, interventions, questionnaire, schedule, report, eligibility_consent, question_type, consent, observations
  • validateStudy() composes all validators; individual validators exported from core.dart
  • StudyFixtures with fullValid() and targeted invalid variants for each error code
  • consent.no_items and interventions.no_tasks are warnings, not errors

studyu_validator CLI:

  • validate <file> — parse JSON and run validateStudy, exit 0/1
  • validate --level publish — switch validation level
  • validate --section <name> — run a single entity validator
  • normalize <file> — round-trip through Study.fromJson/toJson

tools/study_data_docs — docs generator (PR 3b):

  • New tools/study_data_docs workspace package (pure Dart, package:analyzer 12.x)
  • --write generates core/docs/study-data/ from Dart source + .g.dart files
  • --check exits non-zero when docs drift from source; wired into qualitycheck
  • Scans inherited fields, filters private backing fields, extracts discriminator constants
  • Block markers: <!-- GENERATED:FIELDS START/END -->, <!-- GENERATED:DISCRIMINATORS START/END -->, <!-- GENERATED:LINKS START/END -->
  • 36 pages generated covering all in-scope studyu_core models
  • 25 unit tests, 0 analyzer warnings
  • Melos scripts: docs:study-data:write, docs:study-data:check

Visuals

N/A — CLI and library only, no UI changes.

Testing Steps

# Run core validator tests
fvm exec melos run test --scope studyu_core

# Run CLI tests
fvm exec melos run test --scope studyu_validator

# Run docs generator tests
cd tools/study_data_docs && fvm dart test

# Generate docs tree
fvm exec melos run docs:study-data:write

# Verify no drift
fvm exec melos run docs:study-data:check

# Full quality gate
fvm exec melos run qualitycheck

PR Checklist

  • fvm exec melos run qualitycheck passes
  • Screenshot or video of the changes attached
  • Description links related issues

@github-actions github-actions Bot added dependencies Pull requests that update a dependency file core labels Jun 30, 2026
@ibrahimozkn ibrahimozkn marked this pull request as draft June 30, 2026 19:06
@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown

Visit the preview URL for this PR (updated for commit 0894fe0):

(expires Fri, 10 Jul 2026 18:20:42 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 2149dad49ed83535217e50d5c18c0c8c90da629b

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 1, 2026
@ibrahimozkn ibrahimozkn force-pushed the feature/study-validator-clean branch from 0822e48 to 22b4ef7 Compare July 1, 2026 10:44
@github-actions github-actions Bot removed the documentation Improvements or additions to documentation label Jul 1, 2026
ibrahimozkn and others added 11 commits July 1, 2026 16:11
- field table: show `field (json_key)` when names differ; add Default
  column populated from field initializers and @jsonkey(defaultValue:)
- remove `<!-- Human prose goes here. -->` placeholder from skeleton
  and strip it from previously generated pages on next --write run
- dispatcher pages (Question, Expression): collect concrete subtype
  wire values scoped to the same directory, not all classes globally
- filter keyType constants so they are not misread as wire values
- drift check: fail when metadata describes a field absent from source
  (unless virtual: true) and when metadata is missing a title
- mark SliderQuestion.initial as virtual in _metadata.yaml (getter only)
- add doc_metadata_test.dart (7 tests) and expand generated_block_test
  and page_scope_test with discriminator and fieldLabel coverage
- 41 unit tests passing, 0 analyzer warnings
Replace blank default cells with - in generated field tables.
Add model_scanner_test.dart covering buildDispatcherDiscriminators
and ScannedField/ScannedClass data classes.
Regenerate all doc pages to reflect the new placeholder.
Empty consent at publish level must be an error, not a warning — the
CLI section flag test specifies this contract.
@johannesvedder johannesvedder force-pushed the feature/study-validator-clean branch from 768a5bf to b19d765 Compare July 2, 2026 07:32
@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Jul 3, 2026
Add a two-stage study-data validation pipeline: a fast JSON Schema gate
over raw decoded JSON, followed by the existing Study.fromJson plus
cross-entity Dart validators only when schema validation succeeds.

- core/tool/emit_schema.dart: standalone emitter generating
  core/lib/src/validators/schema/study.schema.json from the committed
  model serializers (Draft 7, additionalProperties: false, oneOf
  discriminators with const, nullable via type arrays/anyOf)
- studyu_validator: insert schema pass into validateJson and
  validateSection, add --schema-only flag and replace schema stub with
  schema subcommand printing the checked-in schema
- .github/workflows/schema-validate.yml: node-only CI validating the
  portable fixture against the schema with ajv-cli
- pubspec.yaml: add docs:study-data:schema melos script
- tests: 20 cases proving stage separation, schema-only mode, schema
  command, and conflicting flag rejection
ajv-cli does not include format validators, causing date-time format
in the schema to be rejected. Use ajv + ajv-formats directly instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core dependencies Pull requests that update a dependency file documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants