From 43cd3a93251e6f1e2bf285958b50013b4002e390 Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 13 Apr 2026 18:25:03 +0100 Subject: [PATCH] fix: ensure lazy types are loaded before reading version in save() paths modelRegistry.get() returns undefined for lazily-registered types that haven't been imported yet. Both YamlDefinitionRepository.save() and YamlEvaluatedDefinitionRepository.save() called get() without first awaiting ensureTypeLoaded(), silently falling back to a potentially stale typeVersion on the incoming Definition. Add the missing ensureTypeLoaded() call in both save methods, matching the established pattern in libswamp/models/get.ts and validation_service.ts. Closes swamp-club#90 --- src/infrastructure/persistence/yaml_definition_repository.ts | 1 + .../persistence/yaml_evaluated_definition_repository.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/src/infrastructure/persistence/yaml_definition_repository.ts b/src/infrastructure/persistence/yaml_definition_repository.ts index 6b62977b..9056150d 100644 --- a/src/infrastructure/persistence/yaml_definition_repository.ts +++ b/src/infrastructure/persistence/yaml_definition_repository.ts @@ -247,6 +247,7 @@ export class YamlDefinitionRepository implements DefinitionRepository { const data = definition.toData(); // Ensure type metadata is always present in persisted YAML data.type = type.normalized; + await modelRegistry.ensureTypeLoaded(type); const modelDef = modelRegistry.get(type); data.typeVersion = modelDef?.version ?? data.typeVersion; // Remove undefined values since YAML can't stringify them diff --git a/src/infrastructure/persistence/yaml_evaluated_definition_repository.ts b/src/infrastructure/persistence/yaml_evaluated_definition_repository.ts index 8deb91e0..31655311 100644 --- a/src/infrastructure/persistence/yaml_evaluated_definition_repository.ts +++ b/src/infrastructure/persistence/yaml_evaluated_definition_repository.ts @@ -243,6 +243,7 @@ export class YamlEvaluatedDefinitionRepository { const data = definition.toData(); // Ensure type metadata is always present in persisted YAML data.type = type.normalized; + await modelRegistry.ensureTypeLoaded(type); const modelDef = modelRegistry.get(type); data.typeVersion = modelDef?.version ?? data.typeVersion; // Remove undefined values since YAML can't stringify them