robert 2.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- robert/__init__.py +9 -0
- robert/__main__.py +20 -0
- robert/_version.py +3 -0
- robert/api.py +646 -0
- robert/aqme.py +280 -0
- robert/argument_parser.py +98 -0
- robert/checkml.py +433 -0
- robert/checkml_score.py +50 -0
- robert/curate.py +217 -0
- robert/evaluate_bot_retrieval.py +125 -0
- robert/evaluate_bot_support.py +102 -0
- robert/evaluate_workflow_summaries.py +87 -0
- robert/export_bot_docs_knowledge.py +1632 -0
- robert/generate.py +249 -0
- robert/generate_utils.py +311 -0
- robert/gui_easyrob/__init__.py +0 -0
- robert/gui_easyrob/assets/gif_easyrob.gif +0 -0
- robert/gui_easyrob/bot/__init__.py +47 -0
- robert/gui_easyrob/bot/answer_metadata.py +198 -0
- robert/gui_easyrob/bot/bot_context.py +679 -0
- robert/gui_easyrob/bot/bot_engine.py +1100 -0
- robert/gui_easyrob/bot/bot_panel.py +1231 -0
- robert/gui_easyrob/bot/bot_rag.py +1178 -0
- robert/gui_easyrob/bot/bot_window.py +39 -0
- robert/gui_easyrob/bot/bot_worker.py +149 -0
- robert/gui_easyrob/bot/credential_store.py +143 -0
- robert/gui_easyrob/bot/error_parser.py +105 -0
- robert/gui_easyrob/bot/evidence_policy.py +164 -0
- robert/gui_easyrob/bot/heuristics.py +859 -0
- robert/gui_easyrob/bot/icons.py +56 -0
- robert/gui_easyrob/bot/input_csv_audit.py +212 -0
- robert/gui_easyrob/bot/knowledge/aqme_context.json +5907 -0
- robert/gui_easyrob/bot/knowledge/robert_context.json +4817 -0
- robert/gui_easyrob/bot/knowledge/ui_context.json +8293 -0
- robert/gui_easyrob/bot/knowledge_schema.py +1252 -0
- robert/gui_easyrob/bot/knowledge_sources/aqme_user_guidance.json +442 -0
- robert/gui_easyrob/bot/knowledge_sources/coverage_manifest.json +95 -0
- robert/gui_easyrob/bot/knowledge_sources/robert_user_guidance.json +471 -0
- robert/gui_easyrob/bot/knowledge_sources/ui_user_guidance.json +1312 -0
- robert/gui_easyrob/bot/llm_providers.py +1573 -0
- robert/gui_easyrob/bot/online_docs.py +105 -0
- robert/gui_easyrob/bot/prompt_policy.py +575 -0
- robert/gui_easyrob/bot/question_intent.py +562 -0
- robert/gui_easyrob/bot/response_quality.py +104 -0
- robert/gui_easyrob/bot/result_insights.py +225 -0
- robert/gui_easyrob/bot/token_usage.py +75 -0
- robert/gui_easyrob/bot/workflow_results.py +1396 -0
- robert/gui_easyrob/checkml_launcher.py +15 -0
- robert/gui_easyrob/easyrob.py +29 -0
- robert/gui_easyrob/easyrob_launcher.py +113 -0
- robert/gui_easyrob/main/__init__.py +9 -0
- robert/gui_easyrob/main/window.py +5152 -0
- robert/gui_easyrob/result_navigation.py +14 -0
- robert/gui_easyrob/tabs/__init__.py +23 -0
- robert/gui_easyrob/tabs/advanced_options.py +370 -0
- robert/gui_easyrob/tabs/aqme.py +1234 -0
- robert/gui_easyrob/tabs/checkml.py +898 -0
- robert/gui_easyrob/tabs/images.py +427 -0
- robert/gui_easyrob/tabs/interactive_predictions.py +555 -0
- robert/gui_easyrob/tabs/molssi.py +447 -0
- robert/gui_easyrob/tabs/predictions.py +484 -0
- robert/gui_easyrob/tabs/result_catalog.py +170 -0
- robert/gui_easyrob/tabs/results.py +490 -0
- robert/gui_easyrob/tabs/results_workspace.py +120 -0
- robert/gui_easyrob/test_bot_input_csv_audit.py +152 -0
- robert/gui_easyrob/test_bot_question_routing.py +383 -0
- robert/gui_easyrob/test_bot_result_analysis.py +356 -0
- robert/gui_easyrob/test_bot_retrieval_evaluation.py +110 -0
- robert/gui_easyrob/test_bot_ui_integration.py +278 -0
- robert/gui_easyrob/test_checkml_app_mode.py +124 -0
- robert/gui_easyrob/test_checkml_completion.py +57 -0
- robert/gui_easyrob/test_checkml_defaults.py +37 -0
- robert/gui_easyrob/test_checkml_result_summary.py +113 -0
- robert/gui_easyrob/test_checkml_web_mode.py +57 -0
- robert/gui_easyrob/test_dialog_layout.py +33 -0
- robert/gui_easyrob/test_gui_bot_regressions.py +320 -0
- robert/gui_easyrob/test_molssi_auto.py +569 -0
- robert/gui_easyrob/test_tutorial_view.py +215 -0
- robert/gui_easyrob/tutorials/check_model.md +25 -0
- robert/gui_easyrob/tutorials/chemdraw.md +49 -0
- robert/gui_easyrob/tutorials/csv.md +53 -0
- robert/gui_easyrob/tutorials/descriptors.md +21 -0
- robert/gui_easyrob/tutorials/overview.md +65 -0
- robert/gui_easyrob/tutorials/predictions.md +25 -0
- robert/gui_easyrob/tutorials/robbot.md +29 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/check_model/check_model_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_10.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_11.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_12.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_13.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/chemdraw/chemdraw_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/csv/csv_9.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/descriptors/descriptors_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_1_8.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_5_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/overview/overview_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_1_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/predictions/predictions_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_1.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_2.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_3.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_4.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_5.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_6.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_7.png +0 -0
- robert/gui_easyrob/tutorials/tutorial_images/robbot/robbot_8.png +0 -0
- robert/gui_easyrob/utils/__init__.py +0 -0
- robert/gui_easyrob/utils/aqme_utils.py +238 -0
- robert/gui_easyrob/utils/molssi_utils.py +584 -0
- robert/gui_easyrob/utils/predictions_utils.py +985 -0
- robert/gui_easyrob/utils/utils_gui.py +738 -0
- robert/gui_easyrob/version.py +68 -0
- robert/gui_easyrob/web/app.css +484 -0
- robert/gui_easyrob/web/app.html +134 -0
- robert/gui_easyrob/web/app.js +764 -0
- robert/gui_easyrob/web/checkml_brand.png +0 -0
- robert/gui_easyrob/web/easyrob_background.gif +0 -0
- robert/gui_easyrob/web/easyrob_background.png +0 -0
- robert/gui_easyrob/web/images.css +89 -0
- robert/gui_easyrob/web/images.html +39 -0
- robert/gui_easyrob/web/images.js +101 -0
- robert/gui_easyrob/web/results.js +499 -0
- robert/gui_easyrob/web/robert_brand.png +0 -0
- robert/gui_easyrob/web_dialogs.py +64 -0
- robert/gui_easyrob/web_results.py +253 -0
- robert/gui_easyrob/web_shell.py +684 -0
- robert/gui_easyrob/workflow_progress.py +89 -0
- robert/gui_easyrob/workflow_run_lock.py +27 -0
- robert/icons/CheckML_icon.png +0 -0
- robert/icons/Robert_icon.png +0 -0
- robert/icons/Robert_logo.jpg +0 -0
- robert/icons/Robert_logo_transparent.png +0 -0
- robert/icons/documentation_icon.png +0 -0
- robert/icons/info_icon.png +0 -0
- robert/icons/pdf_icon.png +0 -0
- robert/icons/play_icon.png +0 -0
- robert/icons/stop_icon.png +0 -0
- robert/icons/youtube_icon.ico +0 -0
- robert/predict.py +193 -0
- robert/predict_utils.py +410 -0
- robert/report/CheckML_logo.jpg +0 -0
- robert/report/GENERATE.png +0 -0
- robert/report/Robert_icon.ico +0 -0
- robert/report/Robert_logo.jpg +0 -0
- robert/report/Robert_logo1.jpg +0 -0
- robert/report/abbrev.png +0 -0
- robert/report/adv_anal.png +0 -0
- robert/report/checkml_pass.svg +3 -0
- robert/report/checkml_unclear.svg +3 -0
- robert/report/checkml_warning.svg +3 -0
- robert/report/features.png +0 -0
- robert/report/outliers.png +0 -0
- robert/report/pred.png +0 -0
- robert/report/repro.png +0 -0
- robert/report/robust_x.png +0 -0
- robert/report/robust_y_high.png +0 -0
- robert/report/robust_y_low.png +0 -0
- robert/report/score.png +0 -0
- robert/report/score_0.jpg +0 -0
- robert/report/score_1.jpg +0 -0
- robert/report/score_10.jpg +0 -0
- robert/report/score_2.jpg +0 -0
- robert/report/score_3.jpg +0 -0
- robert/report/score_4.jpg +0 -0
- robert/report/score_5.jpg +0 -0
- robert/report/score_6.jpg +0 -0
- robert/report/score_7.jpg +0 -0
- robert/report/score_8.jpg +0 -0
- robert/report/score_9.jpg +0 -0
- robert/report/score_gray_0.jpg +0 -0
- robert/report/score_gray_1.jpg +0 -0
- robert/report/score_gray_10.jpg +0 -0
- robert/report/score_gray_2.jpg +0 -0
- robert/report/score_gray_3.jpg +0 -0
- robert/report/score_gray_4.jpg +0 -0
- robert/report/score_gray_5.jpg +0 -0
- robert/report/score_gray_6.jpg +0 -0
- robert/report/score_gray_7.jpg +0 -0
- robert/report/score_gray_8.jpg +0 -0
- robert/report/score_gray_9.jpg +0 -0
- robert/report/score_w_1_0.jpg +0 -0
- robert/report/score_w_1_1.jpg +0 -0
- robert/report/score_w_2_0.jpg +0 -0
- robert/report/score_w_2_1.jpg +0 -0
- robert/report/score_w_2_2.jpg +0 -0
- robert/report/score_w_2_gray_0.jpg +0 -0
- robert/report/score_w_2_gray_1.jpg +0 -0
- robert/report/score_w_2_gray_2.jpg +0 -0
- robert/report/score_w_3_0.jpg +0 -0
- robert/report/score_w_3_1.jpg +0 -0
- robert/report/score_w_3_2.jpg +0 -0
- robert/report/score_w_3_3.jpg +0 -0
- robert/report/score_w_4_0.jpg +0 -0
- robert/report/score_w_4_1.JPG +0 -0
- robert/report/score_w_4_2.jpg +0 -0
- robert/report/score_w_4_3.jpg +0 -0
- robert/report/score_w_4_4.jpg +0 -0
- robert/report/transpa.png +0 -0
- robert/report/y_distrib.png +0 -0
- robert/report.py +2880 -0
- robert/report_utils.py +2270 -0
- robert/robert.py +181 -0
- robert/utils.py +4763 -0
- robert/verify.py +606 -0
- robert-2.2.0.dist-info/METADATA +55 -0
- robert-2.2.0.dist-info/RECORD +261 -0
- robert-2.2.0.dist-info/WHEEL +5 -0
- robert-2.2.0.dist-info/entry_points.txt +3 -0
- robert-2.2.0.dist-info/licenses/LICENSE +21 -0
- robert-2.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1252 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass
|
|
4
|
+
import math
|
|
5
|
+
import re
|
|
6
|
+
from typing import Mapping, Sequence
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
SCHEMA_VERSION = 1
|
|
10
|
+
CONTEXT_VERSION = "2026-07-10"
|
|
11
|
+
DOMAINS = ("robert", "aqme", "ui")
|
|
12
|
+
CONTEXT_SECTIONS = (
|
|
13
|
+
"workflows",
|
|
14
|
+
"modules",
|
|
15
|
+
"interface",
|
|
16
|
+
"parameters",
|
|
17
|
+
"concepts",
|
|
18
|
+
"inputs_outputs",
|
|
19
|
+
"tutorials",
|
|
20
|
+
"troubleshooting",
|
|
21
|
+
)
|
|
22
|
+
ALLOWED_KINDS = {
|
|
23
|
+
"concept",
|
|
24
|
+
"workflow",
|
|
25
|
+
"module",
|
|
26
|
+
"interface",
|
|
27
|
+
"parameter",
|
|
28
|
+
"output",
|
|
29
|
+
"tutorial",
|
|
30
|
+
"diagnostic",
|
|
31
|
+
"results",
|
|
32
|
+
}
|
|
33
|
+
ALLOWED_SOURCE_TIERS = {"curated", "tutorial", "reference", "generated"}
|
|
34
|
+
ALLOWED_AUDIENCES = {"end_user", "advanced_user", "developer_reference"}
|
|
35
|
+
ALLOWED_ENTITY_TYPES = {
|
|
36
|
+
"program",
|
|
37
|
+
"module",
|
|
38
|
+
"tab",
|
|
39
|
+
"button",
|
|
40
|
+
"selector",
|
|
41
|
+
"checkbox",
|
|
42
|
+
"dialog",
|
|
43
|
+
"status",
|
|
44
|
+
"workflow",
|
|
45
|
+
"tutorial",
|
|
46
|
+
}
|
|
47
|
+
ALLOWED_TABS = {
|
|
48
|
+
"",
|
|
49
|
+
"Workflow",
|
|
50
|
+
"ROBERT",
|
|
51
|
+
"AQME descriptors",
|
|
52
|
+
"AQME",
|
|
53
|
+
"Advanced options",
|
|
54
|
+
"Advanced Options",
|
|
55
|
+
"Results",
|
|
56
|
+
"Reports",
|
|
57
|
+
"Predictions",
|
|
58
|
+
"Evaluate",
|
|
59
|
+
"CheckML",
|
|
60
|
+
"Images",
|
|
61
|
+
"MolSSI Databases",
|
|
62
|
+
"MolSSI databases",
|
|
63
|
+
}
|
|
64
|
+
ISO_DATE_RE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
_ALLOWED_PROGRAMS = {"ROBERT", "AQME"}
|
|
68
|
+
_CONTEXT_TOP_LEVEL_KEYS = {
|
|
69
|
+
"schema_version",
|
|
70
|
+
"version",
|
|
71
|
+
"domain",
|
|
72
|
+
"overview",
|
|
73
|
+
*CONTEXT_SECTIONS,
|
|
74
|
+
}
|
|
75
|
+
_GUIDANCE_TOP_LEVEL_KEYS = {"schema_version", "version", "domain", "records"}
|
|
76
|
+
_MANIFEST_TOP_LEVEL_KEYS = {
|
|
77
|
+
"schema_version",
|
|
78
|
+
"version",
|
|
79
|
+
"required_entities",
|
|
80
|
+
"tutorial_files",
|
|
81
|
+
}
|
|
82
|
+
_REQUIRED_RECORD_STRINGS = (
|
|
83
|
+
"id",
|
|
84
|
+
"source",
|
|
85
|
+
"source_file",
|
|
86
|
+
"program",
|
|
87
|
+
"module",
|
|
88
|
+
"kind",
|
|
89
|
+
"topic",
|
|
90
|
+
"tab",
|
|
91
|
+
"title",
|
|
92
|
+
)
|
|
93
|
+
_GUIDANCE_LIST_FIELDS = (
|
|
94
|
+
"when_to_use",
|
|
95
|
+
"prerequisites",
|
|
96
|
+
"steps",
|
|
97
|
+
"next_steps",
|
|
98
|
+
"common_issues",
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@dataclass(frozen=True, slots=True)
|
|
103
|
+
class KnowledgeLoadIssue:
|
|
104
|
+
code: str
|
|
105
|
+
message: str
|
|
106
|
+
source: str = ""
|
|
107
|
+
record_id: str = ""
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class KnowledgeValidationError(ValueError):
|
|
111
|
+
def __init__(self, issues: Sequence[KnowledgeLoadIssue]):
|
|
112
|
+
self.issues = tuple(issues)
|
|
113
|
+
detail = "; ".join(
|
|
114
|
+
f"{issue.code}: {issue.message}" for issue in self.issues
|
|
115
|
+
)
|
|
116
|
+
super().__init__(detail or "knowledge validation failed")
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _add_issue(
|
|
120
|
+
issues: list[KnowledgeLoadIssue],
|
|
121
|
+
code: str,
|
|
122
|
+
message: str,
|
|
123
|
+
source: str,
|
|
124
|
+
record_id: str = "",
|
|
125
|
+
) -> None:
|
|
126
|
+
issues.append(
|
|
127
|
+
KnowledgeLoadIssue(
|
|
128
|
+
code=code,
|
|
129
|
+
message=message,
|
|
130
|
+
source=source,
|
|
131
|
+
record_id=record_id,
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def _is_nonempty_string(value: object) -> bool:
|
|
137
|
+
return isinstance(value, str) and bool(value.strip())
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def _is_string_list(value: object) -> bool:
|
|
141
|
+
return isinstance(value, list) and all(
|
|
142
|
+
_is_nonempty_string(item) for item in value
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def _valid_schema_version(value: object) -> bool:
|
|
147
|
+
return isinstance(value, int) and not isinstance(value, bool)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _valid_version(value: object) -> bool:
|
|
151
|
+
return isinstance(value, str) and ISO_DATE_RE.fullmatch(value) is not None
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _record_identifier(record: Mapping[object, object]) -> str:
|
|
155
|
+
value = record.get("id")
|
|
156
|
+
return value if _is_nonempty_string(value) else ""
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _validate_required_string(
|
|
160
|
+
record: Mapping[object, object],
|
|
161
|
+
field: str,
|
|
162
|
+
issues: list[KnowledgeLoadIssue],
|
|
163
|
+
source: str,
|
|
164
|
+
record_id: str,
|
|
165
|
+
*,
|
|
166
|
+
allow_empty: bool = False,
|
|
167
|
+
) -> object:
|
|
168
|
+
if field not in record:
|
|
169
|
+
_add_issue(
|
|
170
|
+
issues,
|
|
171
|
+
f"missing_{field}",
|
|
172
|
+
f"Record is missing required field '{field}'.",
|
|
173
|
+
source,
|
|
174
|
+
record_id,
|
|
175
|
+
)
|
|
176
|
+
return None
|
|
177
|
+
|
|
178
|
+
value = record[field]
|
|
179
|
+
valid = isinstance(value, str) and (allow_empty or bool(value.strip()))
|
|
180
|
+
if not valid:
|
|
181
|
+
_add_issue(
|
|
182
|
+
issues,
|
|
183
|
+
f"invalid_{field}",
|
|
184
|
+
f"Record field '{field}' must be "
|
|
185
|
+
+ ("a string." if allow_empty else "a non-empty string."),
|
|
186
|
+
source,
|
|
187
|
+
record_id,
|
|
188
|
+
)
|
|
189
|
+
return value
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _validate_string_list(
|
|
193
|
+
record: Mapping[object, object],
|
|
194
|
+
field: str,
|
|
195
|
+
issues: list[KnowledgeLoadIssue],
|
|
196
|
+
source: str,
|
|
197
|
+
record_id: str,
|
|
198
|
+
*,
|
|
199
|
+
required: bool,
|
|
200
|
+
) -> object:
|
|
201
|
+
if field not in record:
|
|
202
|
+
if required:
|
|
203
|
+
_add_issue(
|
|
204
|
+
issues,
|
|
205
|
+
f"missing_{field}",
|
|
206
|
+
f"Record is missing required list field '{field}'.",
|
|
207
|
+
source,
|
|
208
|
+
record_id,
|
|
209
|
+
)
|
|
210
|
+
return None
|
|
211
|
+
|
|
212
|
+
value = record[field]
|
|
213
|
+
if not _is_string_list(value):
|
|
214
|
+
_add_issue(
|
|
215
|
+
issues,
|
|
216
|
+
f"invalid_{field}",
|
|
217
|
+
f"Record field '{field}' must be a list of non-empty strings.",
|
|
218
|
+
source,
|
|
219
|
+
record_id,
|
|
220
|
+
)
|
|
221
|
+
return value
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def _validate_user_guidance(
|
|
225
|
+
guidance: object,
|
|
226
|
+
entity_type: object,
|
|
227
|
+
kind: object,
|
|
228
|
+
issues: list[KnowledgeLoadIssue],
|
|
229
|
+
source: str,
|
|
230
|
+
record_id: str,
|
|
231
|
+
) -> None:
|
|
232
|
+
if not isinstance(guidance, Mapping):
|
|
233
|
+
_add_issue(
|
|
234
|
+
issues,
|
|
235
|
+
"invalid_user_guidance",
|
|
236
|
+
"Curated record field 'user_guidance' must be an object.",
|
|
237
|
+
source,
|
|
238
|
+
record_id,
|
|
239
|
+
)
|
|
240
|
+
return
|
|
241
|
+
|
|
242
|
+
for field in ("purpose", "result"):
|
|
243
|
+
if field not in guidance:
|
|
244
|
+
_add_issue(
|
|
245
|
+
issues,
|
|
246
|
+
f"missing_{field}",
|
|
247
|
+
f"Curated guidance is missing required field '{field}'.",
|
|
248
|
+
source,
|
|
249
|
+
record_id,
|
|
250
|
+
)
|
|
251
|
+
elif not _is_nonempty_string(guidance[field]):
|
|
252
|
+
_add_issue(
|
|
253
|
+
issues,
|
|
254
|
+
f"invalid_{field}",
|
|
255
|
+
f"Curated guidance field '{field}' must be a non-empty string.",
|
|
256
|
+
source,
|
|
257
|
+
record_id,
|
|
258
|
+
)
|
|
259
|
+
|
|
260
|
+
valid_lists: dict[str, list[object]] = {}
|
|
261
|
+
for field in _GUIDANCE_LIST_FIELDS:
|
|
262
|
+
if field not in guidance:
|
|
263
|
+
_add_issue(
|
|
264
|
+
issues,
|
|
265
|
+
f"missing_{field}",
|
|
266
|
+
f"Curated guidance is missing required list field '{field}'.",
|
|
267
|
+
source,
|
|
268
|
+
record_id,
|
|
269
|
+
)
|
|
270
|
+
continue
|
|
271
|
+
value = guidance[field]
|
|
272
|
+
if not _is_string_list(value):
|
|
273
|
+
_add_issue(
|
|
274
|
+
issues,
|
|
275
|
+
f"invalid_{field}",
|
|
276
|
+
f"Curated guidance field '{field}' must be a list of "
|
|
277
|
+
"non-empty strings.",
|
|
278
|
+
source,
|
|
279
|
+
record_id,
|
|
280
|
+
)
|
|
281
|
+
continue
|
|
282
|
+
valid_lists[field] = value
|
|
283
|
+
|
|
284
|
+
guidance_type = ""
|
|
285
|
+
if isinstance(entity_type, str) and entity_type in {"workflow", "tutorial"}:
|
|
286
|
+
guidance_type = entity_type
|
|
287
|
+
elif isinstance(kind, str) and kind in {"workflow", "tutorial"}:
|
|
288
|
+
guidance_type = kind
|
|
289
|
+
if guidance_type:
|
|
290
|
+
for field in ("steps", "next_steps"):
|
|
291
|
+
if field in valid_lists and not valid_lists[field]:
|
|
292
|
+
_add_issue(
|
|
293
|
+
issues,
|
|
294
|
+
f"missing_{field}",
|
|
295
|
+
f"{guidance_type.title()} guidance requires at least one "
|
|
296
|
+
f"'{field}' item.",
|
|
297
|
+
source,
|
|
298
|
+
record_id,
|
|
299
|
+
)
|
|
300
|
+
|
|
301
|
+
if kind == "diagnostic" and "common_issues" in valid_lists:
|
|
302
|
+
if not valid_lists["common_issues"]:
|
|
303
|
+
_add_issue(
|
|
304
|
+
issues,
|
|
305
|
+
"missing_common_issues",
|
|
306
|
+
"Diagnostic guidance requires at least one common issue.",
|
|
307
|
+
source,
|
|
308
|
+
record_id,
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
def _validate_record(
|
|
313
|
+
record: Mapping[object, object],
|
|
314
|
+
issues: list[KnowledgeLoadIssue],
|
|
315
|
+
source: str,
|
|
316
|
+
*,
|
|
317
|
+
require_text: bool,
|
|
318
|
+
require_curated: bool,
|
|
319
|
+
) -> None:
|
|
320
|
+
record_id = _record_identifier(record)
|
|
321
|
+
|
|
322
|
+
for field in _REQUIRED_RECORD_STRINGS:
|
|
323
|
+
_validate_required_string(
|
|
324
|
+
record,
|
|
325
|
+
field,
|
|
326
|
+
issues,
|
|
327
|
+
source,
|
|
328
|
+
record_id,
|
|
329
|
+
allow_empty=field == "tab",
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
if require_text or "text" in record:
|
|
333
|
+
_validate_required_string(
|
|
334
|
+
record,
|
|
335
|
+
"text",
|
|
336
|
+
issues,
|
|
337
|
+
source,
|
|
338
|
+
record_id,
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
program = record.get("program")
|
|
342
|
+
if isinstance(program, str) and program not in _ALLOWED_PROGRAMS:
|
|
343
|
+
_add_issue(
|
|
344
|
+
issues,
|
|
345
|
+
"invalid_program",
|
|
346
|
+
"Record field 'program' must be 'ROBERT' or 'AQME'.",
|
|
347
|
+
source,
|
|
348
|
+
record_id,
|
|
349
|
+
)
|
|
350
|
+
|
|
351
|
+
kind = record.get("kind")
|
|
352
|
+
if isinstance(kind, str) and kind not in ALLOWED_KINDS:
|
|
353
|
+
_add_issue(
|
|
354
|
+
issues,
|
|
355
|
+
"invalid_kind",
|
|
356
|
+
f"Unsupported knowledge kind '{kind}'.",
|
|
357
|
+
source,
|
|
358
|
+
record_id,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
tab = record.get("tab")
|
|
362
|
+
if isinstance(tab, str) and tab not in ALLOWED_TABS:
|
|
363
|
+
_add_issue(
|
|
364
|
+
issues,
|
|
365
|
+
"invalid_tab",
|
|
366
|
+
f"Unsupported EasyROB tab '{tab}'.",
|
|
367
|
+
source,
|
|
368
|
+
record_id,
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
source_tier = record.get("source_tier")
|
|
372
|
+
if "source_tier" not in record:
|
|
373
|
+
_add_issue(
|
|
374
|
+
issues,
|
|
375
|
+
"missing_source_tier",
|
|
376
|
+
"Record is missing required field 'source_tier'.",
|
|
377
|
+
source,
|
|
378
|
+
record_id,
|
|
379
|
+
)
|
|
380
|
+
elif not isinstance(source_tier, str) or source_tier not in ALLOWED_SOURCE_TIERS:
|
|
381
|
+
_add_issue(
|
|
382
|
+
issues,
|
|
383
|
+
"invalid_source_tier",
|
|
384
|
+
"Record field 'source_tier' is not supported.",
|
|
385
|
+
source,
|
|
386
|
+
record_id,
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
audience = record.get("audience")
|
|
390
|
+
if "audience" not in record:
|
|
391
|
+
_add_issue(
|
|
392
|
+
issues,
|
|
393
|
+
"missing_audience",
|
|
394
|
+
"Record is missing required field 'audience'.",
|
|
395
|
+
source,
|
|
396
|
+
record_id,
|
|
397
|
+
)
|
|
398
|
+
elif not isinstance(audience, str) or audience not in ALLOWED_AUDIENCES:
|
|
399
|
+
_add_issue(
|
|
400
|
+
issues,
|
|
401
|
+
"invalid_audience",
|
|
402
|
+
"Record field 'audience' is not supported.",
|
|
403
|
+
source,
|
|
404
|
+
record_id,
|
|
405
|
+
)
|
|
406
|
+
|
|
407
|
+
if "priority" not in record:
|
|
408
|
+
_add_issue(
|
|
409
|
+
issues,
|
|
410
|
+
"missing_priority",
|
|
411
|
+
"Record is missing required field 'priority'.",
|
|
412
|
+
source,
|
|
413
|
+
record_id,
|
|
414
|
+
)
|
|
415
|
+
else:
|
|
416
|
+
priority = record["priority"]
|
|
417
|
+
if isinstance(priority, bool):
|
|
418
|
+
valid_priority = False
|
|
419
|
+
elif isinstance(priority, int):
|
|
420
|
+
valid_priority = 0 <= priority <= 1
|
|
421
|
+
elif isinstance(priority, float):
|
|
422
|
+
valid_priority = math.isfinite(priority) and 0.0 <= priority <= 1.0
|
|
423
|
+
else:
|
|
424
|
+
valid_priority = False
|
|
425
|
+
if not valid_priority:
|
|
426
|
+
_add_issue(
|
|
427
|
+
issues,
|
|
428
|
+
"invalid_priority",
|
|
429
|
+
"Record priority must be finite and within 0.0 through 1.0.",
|
|
430
|
+
source,
|
|
431
|
+
record_id,
|
|
432
|
+
)
|
|
433
|
+
|
|
434
|
+
for field in ("keywords", "question_patterns"):
|
|
435
|
+
_validate_string_list(
|
|
436
|
+
record,
|
|
437
|
+
field,
|
|
438
|
+
issues,
|
|
439
|
+
source,
|
|
440
|
+
record_id,
|
|
441
|
+
required=True,
|
|
442
|
+
)
|
|
443
|
+
for field in ("aliases", "related_ids"):
|
|
444
|
+
_validate_string_list(
|
|
445
|
+
record,
|
|
446
|
+
field,
|
|
447
|
+
issues,
|
|
448
|
+
source,
|
|
449
|
+
record_id,
|
|
450
|
+
required=False,
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
has_curated_metadata = require_curated or source_tier == "curated" or any(
|
|
454
|
+
field in record for field in ("entity_type", "entity_id", "user_guidance")
|
|
455
|
+
)
|
|
456
|
+
if not has_curated_metadata:
|
|
457
|
+
return
|
|
458
|
+
|
|
459
|
+
if source_tier != "curated":
|
|
460
|
+
_add_issue(
|
|
461
|
+
issues,
|
|
462
|
+
"invalid_curated_source_tier",
|
|
463
|
+
"Curated guidance records require source_tier='curated'.",
|
|
464
|
+
source,
|
|
465
|
+
record_id,
|
|
466
|
+
)
|
|
467
|
+
if audience != "end_user":
|
|
468
|
+
_add_issue(
|
|
469
|
+
issues,
|
|
470
|
+
"invalid_curated_audience",
|
|
471
|
+
"Curated guidance records require audience='end_user'.",
|
|
472
|
+
source,
|
|
473
|
+
record_id,
|
|
474
|
+
)
|
|
475
|
+
|
|
476
|
+
entity_type = record.get("entity_type")
|
|
477
|
+
if "entity_type" not in record:
|
|
478
|
+
_add_issue(
|
|
479
|
+
issues,
|
|
480
|
+
"missing_entity_type",
|
|
481
|
+
"Curated record is missing required field 'entity_type'.",
|
|
482
|
+
source,
|
|
483
|
+
record_id,
|
|
484
|
+
)
|
|
485
|
+
elif not isinstance(entity_type, str) or entity_type not in ALLOWED_ENTITY_TYPES:
|
|
486
|
+
_add_issue(
|
|
487
|
+
issues,
|
|
488
|
+
"invalid_entity_type",
|
|
489
|
+
"Curated record field 'entity_type' is not supported.",
|
|
490
|
+
source,
|
|
491
|
+
record_id,
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
_validate_required_string(
|
|
495
|
+
record,
|
|
496
|
+
"entity_id",
|
|
497
|
+
issues,
|
|
498
|
+
source,
|
|
499
|
+
record_id,
|
|
500
|
+
)
|
|
501
|
+
for field in ("aliases", "related_ids"):
|
|
502
|
+
if field not in record:
|
|
503
|
+
_validate_string_list(
|
|
504
|
+
record,
|
|
505
|
+
field,
|
|
506
|
+
issues,
|
|
507
|
+
source,
|
|
508
|
+
record_id,
|
|
509
|
+
required=True,
|
|
510
|
+
)
|
|
511
|
+
|
|
512
|
+
if isinstance(entity_type, str) and entity_type in {
|
|
513
|
+
"tab",
|
|
514
|
+
"button",
|
|
515
|
+
"selector",
|
|
516
|
+
"checkbox",
|
|
517
|
+
}:
|
|
518
|
+
if not _is_nonempty_string(tab):
|
|
519
|
+
_add_issue(
|
|
520
|
+
issues,
|
|
521
|
+
"missing_tab",
|
|
522
|
+
f"Curated {entity_type} records require a non-empty tab.",
|
|
523
|
+
source,
|
|
524
|
+
record_id,
|
|
525
|
+
)
|
|
526
|
+
|
|
527
|
+
if "user_guidance" not in record:
|
|
528
|
+
_add_issue(
|
|
529
|
+
issues,
|
|
530
|
+
"missing_user_guidance",
|
|
531
|
+
"Curated record is missing required field 'user_guidance'.",
|
|
532
|
+
source,
|
|
533
|
+
record_id,
|
|
534
|
+
)
|
|
535
|
+
else:
|
|
536
|
+
_validate_user_guidance(
|
|
537
|
+
record["user_guidance"],
|
|
538
|
+
entity_type,
|
|
539
|
+
kind,
|
|
540
|
+
issues,
|
|
541
|
+
source,
|
|
542
|
+
record_id,
|
|
543
|
+
)
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
def validate_context_payload(
|
|
547
|
+
payload: object,
|
|
548
|
+
expected_domain: str,
|
|
549
|
+
source: str,
|
|
550
|
+
) -> tuple[KnowledgeLoadIssue, ...]:
|
|
551
|
+
issues: list[KnowledgeLoadIssue] = []
|
|
552
|
+
if not isinstance(payload, Mapping):
|
|
553
|
+
_add_issue(
|
|
554
|
+
issues,
|
|
555
|
+
"invalid_payload",
|
|
556
|
+
"Knowledge context payload must be an object.",
|
|
557
|
+
source,
|
|
558
|
+
)
|
|
559
|
+
return tuple(issues)
|
|
560
|
+
|
|
561
|
+
for key in sorted(
|
|
562
|
+
(key for key in payload if key not in _CONTEXT_TOP_LEVEL_KEYS),
|
|
563
|
+
key=str,
|
|
564
|
+
):
|
|
565
|
+
_add_issue(
|
|
566
|
+
issues,
|
|
567
|
+
"unexpected_top_level_key",
|
|
568
|
+
f"Unexpected context field {key!r}.",
|
|
569
|
+
source,
|
|
570
|
+
)
|
|
571
|
+
|
|
572
|
+
if "schema_version" not in payload:
|
|
573
|
+
_add_issue(
|
|
574
|
+
issues,
|
|
575
|
+
"missing_schema_version",
|
|
576
|
+
"Context is missing 'schema_version'.",
|
|
577
|
+
source,
|
|
578
|
+
)
|
|
579
|
+
elif not _valid_schema_version(payload["schema_version"]) or payload[
|
|
580
|
+
"schema_version"
|
|
581
|
+
] != SCHEMA_VERSION:
|
|
582
|
+
_add_issue(
|
|
583
|
+
issues,
|
|
584
|
+
"invalid_schema_version",
|
|
585
|
+
f"Context schema_version must be {SCHEMA_VERSION}.",
|
|
586
|
+
source,
|
|
587
|
+
)
|
|
588
|
+
|
|
589
|
+
if "version" not in payload:
|
|
590
|
+
_add_issue(
|
|
591
|
+
issues,
|
|
592
|
+
"missing_version",
|
|
593
|
+
"Context is missing 'version'.",
|
|
594
|
+
source,
|
|
595
|
+
)
|
|
596
|
+
elif not _valid_version(payload["version"]):
|
|
597
|
+
_add_issue(
|
|
598
|
+
issues,
|
|
599
|
+
"invalid_version",
|
|
600
|
+
"Context version must use ISO YYYY-MM-DD format.",
|
|
601
|
+
source,
|
|
602
|
+
)
|
|
603
|
+
|
|
604
|
+
if "domain" not in payload:
|
|
605
|
+
_add_issue(
|
|
606
|
+
issues,
|
|
607
|
+
"missing_domain",
|
|
608
|
+
"Context is missing 'domain'.",
|
|
609
|
+
source,
|
|
610
|
+
)
|
|
611
|
+
else:
|
|
612
|
+
domain = payload["domain"]
|
|
613
|
+
if not isinstance(domain, str) or domain not in DOMAINS:
|
|
614
|
+
_add_issue(
|
|
615
|
+
issues,
|
|
616
|
+
"invalid_domain",
|
|
617
|
+
"Context domain is not supported.",
|
|
618
|
+
source,
|
|
619
|
+
)
|
|
620
|
+
if domain != expected_domain:
|
|
621
|
+
_add_issue(
|
|
622
|
+
issues,
|
|
623
|
+
"domain_mismatch",
|
|
624
|
+
f"Expected domain '{expected_domain}', found {domain!r}.",
|
|
625
|
+
source,
|
|
626
|
+
)
|
|
627
|
+
|
|
628
|
+
if "overview" not in payload:
|
|
629
|
+
_add_issue(
|
|
630
|
+
issues,
|
|
631
|
+
"missing_overview",
|
|
632
|
+
"Context is missing 'overview'.",
|
|
633
|
+
source,
|
|
634
|
+
)
|
|
635
|
+
else:
|
|
636
|
+
overview = payload["overview"]
|
|
637
|
+
if not isinstance(overview, Mapping):
|
|
638
|
+
_add_issue(
|
|
639
|
+
issues,
|
|
640
|
+
"invalid_overview",
|
|
641
|
+
"Context overview must be an object.",
|
|
642
|
+
source,
|
|
643
|
+
)
|
|
644
|
+
else:
|
|
645
|
+
for field in ("title", "text"):
|
|
646
|
+
if field not in overview:
|
|
647
|
+
_add_issue(
|
|
648
|
+
issues,
|
|
649
|
+
f"missing_overview_{field}",
|
|
650
|
+
f"Context overview is missing '{field}'.",
|
|
651
|
+
source,
|
|
652
|
+
)
|
|
653
|
+
elif not _is_nonempty_string(overview[field]):
|
|
654
|
+
_add_issue(
|
|
655
|
+
issues,
|
|
656
|
+
f"invalid_overview_{field}",
|
|
657
|
+
f"Context overview '{field}' must be a non-empty string.",
|
|
658
|
+
source,
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
for section in CONTEXT_SECTIONS:
|
|
662
|
+
if section not in payload:
|
|
663
|
+
_add_issue(
|
|
664
|
+
issues,
|
|
665
|
+
"missing_section",
|
|
666
|
+
f"Context is missing required list section '{section}'.",
|
|
667
|
+
source,
|
|
668
|
+
)
|
|
669
|
+
continue
|
|
670
|
+
records = payload[section]
|
|
671
|
+
if not isinstance(records, list):
|
|
672
|
+
_add_issue(
|
|
673
|
+
issues,
|
|
674
|
+
"invalid_section",
|
|
675
|
+
f"Context section '{section}' must be a list.",
|
|
676
|
+
source,
|
|
677
|
+
)
|
|
678
|
+
continue
|
|
679
|
+
for index, record in enumerate(records):
|
|
680
|
+
if not isinstance(record, Mapping):
|
|
681
|
+
_add_issue(
|
|
682
|
+
issues,
|
|
683
|
+
"invalid_record",
|
|
684
|
+
f"Context section '{section}' record {index} must be an object.",
|
|
685
|
+
source,
|
|
686
|
+
)
|
|
687
|
+
continue
|
|
688
|
+
_validate_record(
|
|
689
|
+
record,
|
|
690
|
+
issues,
|
|
691
|
+
source,
|
|
692
|
+
require_text=True,
|
|
693
|
+
require_curated=False,
|
|
694
|
+
)
|
|
695
|
+
|
|
696
|
+
return tuple(issues)
|
|
697
|
+
|
|
698
|
+
|
|
699
|
+
def _context_records(
|
|
700
|
+
payloads: Mapping[str, object],
|
|
701
|
+
) -> list[tuple[str, str, Mapping[object, object]]]:
|
|
702
|
+
records: list[tuple[str, str, Mapping[object, object]]] = []
|
|
703
|
+
for domain in DOMAINS:
|
|
704
|
+
payload = payloads.get(domain)
|
|
705
|
+
if not isinstance(payload, Mapping):
|
|
706
|
+
continue
|
|
707
|
+
source = f"{domain}_context.json"
|
|
708
|
+
for section in CONTEXT_SECTIONS:
|
|
709
|
+
section_records = payload.get(section)
|
|
710
|
+
if not isinstance(section_records, list):
|
|
711
|
+
continue
|
|
712
|
+
records.extend(
|
|
713
|
+
(domain, source, record)
|
|
714
|
+
for record in section_records
|
|
715
|
+
if isinstance(record, Mapping)
|
|
716
|
+
)
|
|
717
|
+
return records
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
def validate_context_set(
|
|
721
|
+
payloads: Mapping[str, object],
|
|
722
|
+
) -> tuple[KnowledgeLoadIssue, ...]:
|
|
723
|
+
issues: list[KnowledgeLoadIssue] = []
|
|
724
|
+
if not isinstance(payloads, Mapping):
|
|
725
|
+
_add_issue(
|
|
726
|
+
issues,
|
|
727
|
+
"invalid_context_set",
|
|
728
|
+
"Knowledge contexts must be supplied as a domain mapping.",
|
|
729
|
+
"context set",
|
|
730
|
+
)
|
|
731
|
+
return tuple(issues)
|
|
732
|
+
|
|
733
|
+
for domain in DOMAINS:
|
|
734
|
+
if domain not in payloads:
|
|
735
|
+
_add_issue(
|
|
736
|
+
issues,
|
|
737
|
+
"missing_context_domain",
|
|
738
|
+
f"Context set is missing domain '{domain}'.",
|
|
739
|
+
"context set",
|
|
740
|
+
)
|
|
741
|
+
continue
|
|
742
|
+
issues.extend(
|
|
743
|
+
validate_context_payload(
|
|
744
|
+
payloads[domain],
|
|
745
|
+
expected_domain=domain,
|
|
746
|
+
source=f"{domain}_context.json",
|
|
747
|
+
)
|
|
748
|
+
)
|
|
749
|
+
|
|
750
|
+
for domain in sorted(
|
|
751
|
+
(domain for domain in payloads if domain not in DOMAINS), key=str
|
|
752
|
+
):
|
|
753
|
+
_add_issue(
|
|
754
|
+
issues,
|
|
755
|
+
"unexpected_context_domain",
|
|
756
|
+
f"Context set contains unexpected domain {domain!r}.",
|
|
757
|
+
"context set",
|
|
758
|
+
)
|
|
759
|
+
|
|
760
|
+
schema_versions = [
|
|
761
|
+
payload["schema_version"]
|
|
762
|
+
for domain in DOMAINS
|
|
763
|
+
if isinstance((payload := payloads.get(domain)), Mapping)
|
|
764
|
+
and "schema_version" in payload
|
|
765
|
+
]
|
|
766
|
+
if schema_versions and any(
|
|
767
|
+
value != schema_versions[0] for value in schema_versions[1:]
|
|
768
|
+
):
|
|
769
|
+
_add_issue(
|
|
770
|
+
issues,
|
|
771
|
+
"schema_version_mismatch",
|
|
772
|
+
"All knowledge contexts must share one schema_version.",
|
|
773
|
+
"context set",
|
|
774
|
+
)
|
|
775
|
+
|
|
776
|
+
versions = [
|
|
777
|
+
payload["version"]
|
|
778
|
+
for domain in DOMAINS
|
|
779
|
+
if isinstance((payload := payloads.get(domain)), Mapping)
|
|
780
|
+
and "version" in payload
|
|
781
|
+
]
|
|
782
|
+
if versions and any(value != versions[0] for value in versions[1:]):
|
|
783
|
+
_add_issue(
|
|
784
|
+
issues,
|
|
785
|
+
"version_mismatch",
|
|
786
|
+
"All knowledge contexts must share one version.",
|
|
787
|
+
"context set",
|
|
788
|
+
)
|
|
789
|
+
|
|
790
|
+
records = _context_records(payloads)
|
|
791
|
+
identifier_registry: dict[str, tuple[str, str, str]] = {}
|
|
792
|
+
for _domain, record_source, record in records:
|
|
793
|
+
record_id = _record_identifier(record)
|
|
794
|
+
entity_id = record.get("entity_id")
|
|
795
|
+
record_identifiers = (
|
|
796
|
+
("record id", record_id),
|
|
797
|
+
("entity_id", entity_id if _is_nonempty_string(entity_id) else ""),
|
|
798
|
+
)
|
|
799
|
+
for identifier_kind, identifier in record_identifiers:
|
|
800
|
+
if not identifier:
|
|
801
|
+
continue
|
|
802
|
+
previous = identifier_registry.get(identifier)
|
|
803
|
+
if previous is not None:
|
|
804
|
+
previous_kind, previous_source, previous_record_id = previous
|
|
805
|
+
code = (
|
|
806
|
+
"duplicate_entity_id"
|
|
807
|
+
if previous_kind == identifier_kind == "entity_id"
|
|
808
|
+
else "duplicate_id"
|
|
809
|
+
)
|
|
810
|
+
_add_issue(
|
|
811
|
+
issues,
|
|
812
|
+
code,
|
|
813
|
+
f"Knowledge identifier '{identifier}' used as {identifier_kind} "
|
|
814
|
+
f"conflicts with {previous_kind} from record "
|
|
815
|
+
f"'{previous_record_id}' in '{previous_source}'.",
|
|
816
|
+
record_source,
|
|
817
|
+
record_id,
|
|
818
|
+
)
|
|
819
|
+
else:
|
|
820
|
+
identifier_registry[identifier] = (
|
|
821
|
+
identifier_kind,
|
|
822
|
+
record_source,
|
|
823
|
+
record_id,
|
|
824
|
+
)
|
|
825
|
+
|
|
826
|
+
resolvable_ids = set(identifier_registry)
|
|
827
|
+
for _domain, record_source, record in records:
|
|
828
|
+
related_ids = record.get("related_ids")
|
|
829
|
+
if not _is_string_list(related_ids):
|
|
830
|
+
continue
|
|
831
|
+
record_id = _record_identifier(record)
|
|
832
|
+
for related_id in related_ids:
|
|
833
|
+
if related_id not in resolvable_ids:
|
|
834
|
+
_add_issue(
|
|
835
|
+
issues,
|
|
836
|
+
"unresolved_related_id",
|
|
837
|
+
f"Related ID '{related_id}' does not resolve to a knowledge record.",
|
|
838
|
+
record_source,
|
|
839
|
+
record_id,
|
|
840
|
+
)
|
|
841
|
+
|
|
842
|
+
return tuple(issues)
|
|
843
|
+
|
|
844
|
+
|
|
845
|
+
def _validate_guidance_payload(
|
|
846
|
+
payload: object,
|
|
847
|
+
expected_domain: str,
|
|
848
|
+
source: str,
|
|
849
|
+
issues: list[KnowledgeLoadIssue],
|
|
850
|
+
) -> list[Mapping[object, object]]:
|
|
851
|
+
if not isinstance(payload, Mapping):
|
|
852
|
+
_add_issue(
|
|
853
|
+
issues,
|
|
854
|
+
"invalid_guidance_payload",
|
|
855
|
+
f"Guidance payload for '{expected_domain}' must be an object.",
|
|
856
|
+
source,
|
|
857
|
+
)
|
|
858
|
+
return []
|
|
859
|
+
|
|
860
|
+
for key in sorted(
|
|
861
|
+
(key for key in payload if key not in _GUIDANCE_TOP_LEVEL_KEYS), key=str
|
|
862
|
+
):
|
|
863
|
+
_add_issue(
|
|
864
|
+
issues,
|
|
865
|
+
"unexpected_top_level_key",
|
|
866
|
+
f"Unexpected guidance source field {key!r}.",
|
|
867
|
+
source,
|
|
868
|
+
)
|
|
869
|
+
|
|
870
|
+
if "schema_version" not in payload:
|
|
871
|
+
_add_issue(
|
|
872
|
+
issues,
|
|
873
|
+
"missing_schema_version",
|
|
874
|
+
f"Guidance source '{expected_domain}' is missing 'schema_version'.",
|
|
875
|
+
source,
|
|
876
|
+
)
|
|
877
|
+
elif not _valid_schema_version(payload["schema_version"]) or payload[
|
|
878
|
+
"schema_version"
|
|
879
|
+
] != SCHEMA_VERSION:
|
|
880
|
+
_add_issue(
|
|
881
|
+
issues,
|
|
882
|
+
"invalid_schema_version",
|
|
883
|
+
f"Guidance schema_version must be {SCHEMA_VERSION}.",
|
|
884
|
+
source,
|
|
885
|
+
)
|
|
886
|
+
|
|
887
|
+
if "version" not in payload:
|
|
888
|
+
_add_issue(
|
|
889
|
+
issues,
|
|
890
|
+
"missing_version",
|
|
891
|
+
f"Guidance source '{expected_domain}' is missing 'version'.",
|
|
892
|
+
source,
|
|
893
|
+
)
|
|
894
|
+
elif not _valid_version(payload["version"]):
|
|
895
|
+
_add_issue(
|
|
896
|
+
issues,
|
|
897
|
+
"invalid_version",
|
|
898
|
+
"Guidance version must use ISO YYYY-MM-DD format.",
|
|
899
|
+
source,
|
|
900
|
+
)
|
|
901
|
+
|
|
902
|
+
if "domain" not in payload:
|
|
903
|
+
_add_issue(
|
|
904
|
+
issues,
|
|
905
|
+
"missing_domain",
|
|
906
|
+
f"Guidance source '{expected_domain}' is missing 'domain'.",
|
|
907
|
+
source,
|
|
908
|
+
)
|
|
909
|
+
else:
|
|
910
|
+
domain = payload["domain"]
|
|
911
|
+
if not isinstance(domain, str) or domain not in DOMAINS:
|
|
912
|
+
_add_issue(
|
|
913
|
+
issues,
|
|
914
|
+
"invalid_domain",
|
|
915
|
+
"Guidance domain is not supported.",
|
|
916
|
+
source,
|
|
917
|
+
)
|
|
918
|
+
if domain != expected_domain:
|
|
919
|
+
_add_issue(
|
|
920
|
+
issues,
|
|
921
|
+
"domain_mismatch",
|
|
922
|
+
f"Expected guidance domain '{expected_domain}', found {domain!r}.",
|
|
923
|
+
source,
|
|
924
|
+
)
|
|
925
|
+
|
|
926
|
+
if "records" not in payload:
|
|
927
|
+
_add_issue(
|
|
928
|
+
issues,
|
|
929
|
+
"missing_records",
|
|
930
|
+
f"Guidance source '{expected_domain}' is missing 'records'.",
|
|
931
|
+
source,
|
|
932
|
+
)
|
|
933
|
+
return []
|
|
934
|
+
payload_records = payload["records"]
|
|
935
|
+
if not isinstance(payload_records, list):
|
|
936
|
+
_add_issue(
|
|
937
|
+
issues,
|
|
938
|
+
"invalid_records",
|
|
939
|
+
f"Guidance records for '{expected_domain}' must be a list.",
|
|
940
|
+
source,
|
|
941
|
+
)
|
|
942
|
+
return []
|
|
943
|
+
|
|
944
|
+
records: list[Mapping[object, object]] = []
|
|
945
|
+
for index, record in enumerate(payload_records):
|
|
946
|
+
if not isinstance(record, Mapping):
|
|
947
|
+
_add_issue(
|
|
948
|
+
issues,
|
|
949
|
+
"invalid_record",
|
|
950
|
+
f"Guidance record {index} for '{expected_domain}' must be an object.",
|
|
951
|
+
source,
|
|
952
|
+
)
|
|
953
|
+
continue
|
|
954
|
+
records.append(record)
|
|
955
|
+
_validate_record(
|
|
956
|
+
record,
|
|
957
|
+
issues,
|
|
958
|
+
source,
|
|
959
|
+
require_text=False,
|
|
960
|
+
require_curated=True,
|
|
961
|
+
)
|
|
962
|
+
return records
|
|
963
|
+
|
|
964
|
+
|
|
965
|
+
def validate_guidance_source_set(
|
|
966
|
+
payloads: Mapping[str, object],
|
|
967
|
+
manifest: object,
|
|
968
|
+
source: str,
|
|
969
|
+
) -> tuple[KnowledgeLoadIssue, ...]:
|
|
970
|
+
issues: list[KnowledgeLoadIssue] = []
|
|
971
|
+
if not isinstance(payloads, Mapping):
|
|
972
|
+
_add_issue(
|
|
973
|
+
issues,
|
|
974
|
+
"invalid_guidance_source_set",
|
|
975
|
+
"Guidance sources must be supplied as a domain mapping.",
|
|
976
|
+
source,
|
|
977
|
+
)
|
|
978
|
+
return tuple(issues)
|
|
979
|
+
|
|
980
|
+
records_by_domain: dict[str, list[Mapping[object, object]]] = {}
|
|
981
|
+
for domain in DOMAINS:
|
|
982
|
+
if domain not in payloads:
|
|
983
|
+
_add_issue(
|
|
984
|
+
issues,
|
|
985
|
+
"missing_guidance_domain",
|
|
986
|
+
f"Guidance source set is missing domain '{domain}'.",
|
|
987
|
+
source,
|
|
988
|
+
)
|
|
989
|
+
records_by_domain[domain] = []
|
|
990
|
+
continue
|
|
991
|
+
records_by_domain[domain] = _validate_guidance_payload(
|
|
992
|
+
payloads[domain], domain, source, issues
|
|
993
|
+
)
|
|
994
|
+
|
|
995
|
+
for domain in sorted(
|
|
996
|
+
(domain for domain in payloads if domain not in DOMAINS), key=str
|
|
997
|
+
):
|
|
998
|
+
_add_issue(
|
|
999
|
+
issues,
|
|
1000
|
+
"unexpected_guidance_domain",
|
|
1001
|
+
f"Guidance source set contains unexpected domain {domain!r}.",
|
|
1002
|
+
source,
|
|
1003
|
+
)
|
|
1004
|
+
|
|
1005
|
+
required_by_domain: dict[str, list[str]] = {domain: [] for domain in DOMAINS}
|
|
1006
|
+
tutorial_files: dict[str, str] = {}
|
|
1007
|
+
if not isinstance(manifest, Mapping):
|
|
1008
|
+
_add_issue(
|
|
1009
|
+
issues,
|
|
1010
|
+
"invalid_manifest",
|
|
1011
|
+
"Coverage manifest must be an object.",
|
|
1012
|
+
source,
|
|
1013
|
+
)
|
|
1014
|
+
else:
|
|
1015
|
+
for key in sorted(
|
|
1016
|
+
(key for key in manifest if key not in _MANIFEST_TOP_LEVEL_KEYS), key=str
|
|
1017
|
+
):
|
|
1018
|
+
_add_issue(
|
|
1019
|
+
issues,
|
|
1020
|
+
"unexpected_manifest_key",
|
|
1021
|
+
f"Unexpected coverage manifest field {key!r}.",
|
|
1022
|
+
source,
|
|
1023
|
+
)
|
|
1024
|
+
|
|
1025
|
+
if "schema_version" not in manifest:
|
|
1026
|
+
_add_issue(
|
|
1027
|
+
issues,
|
|
1028
|
+
"missing_schema_version",
|
|
1029
|
+
"Coverage manifest is missing 'schema_version'.",
|
|
1030
|
+
source,
|
|
1031
|
+
)
|
|
1032
|
+
elif not _valid_schema_version(manifest["schema_version"]) or manifest[
|
|
1033
|
+
"schema_version"
|
|
1034
|
+
] != SCHEMA_VERSION:
|
|
1035
|
+
_add_issue(
|
|
1036
|
+
issues,
|
|
1037
|
+
"invalid_schema_version",
|
|
1038
|
+
f"Coverage manifest schema_version must be {SCHEMA_VERSION}.",
|
|
1039
|
+
source,
|
|
1040
|
+
)
|
|
1041
|
+
|
|
1042
|
+
if "version" not in manifest:
|
|
1043
|
+
_add_issue(
|
|
1044
|
+
issues,
|
|
1045
|
+
"missing_version",
|
|
1046
|
+
"Coverage manifest is missing 'version'.",
|
|
1047
|
+
source,
|
|
1048
|
+
)
|
|
1049
|
+
elif not _valid_version(manifest["version"]):
|
|
1050
|
+
_add_issue(
|
|
1051
|
+
issues,
|
|
1052
|
+
"invalid_version",
|
|
1053
|
+
"Coverage manifest version must use ISO YYYY-MM-DD format.",
|
|
1054
|
+
source,
|
|
1055
|
+
)
|
|
1056
|
+
|
|
1057
|
+
required_entities = manifest.get("required_entities")
|
|
1058
|
+
if not isinstance(required_entities, Mapping):
|
|
1059
|
+
_add_issue(
|
|
1060
|
+
issues,
|
|
1061
|
+
"invalid_required_entities",
|
|
1062
|
+
"Coverage manifest 'required_entities' must be an object.",
|
|
1063
|
+
source,
|
|
1064
|
+
)
|
|
1065
|
+
else:
|
|
1066
|
+
for domain in DOMAINS:
|
|
1067
|
+
value = required_entities.get(domain)
|
|
1068
|
+
if value is None:
|
|
1069
|
+
_add_issue(
|
|
1070
|
+
issues,
|
|
1071
|
+
"missing_manifest_domain",
|
|
1072
|
+
f"Coverage manifest is missing domain '{domain}'.",
|
|
1073
|
+
source,
|
|
1074
|
+
)
|
|
1075
|
+
elif not _is_string_list(value):
|
|
1076
|
+
_add_issue(
|
|
1077
|
+
issues,
|
|
1078
|
+
"invalid_required_entities",
|
|
1079
|
+
f"Required entities for '{domain}' must be a list of "
|
|
1080
|
+
"non-empty strings.",
|
|
1081
|
+
source,
|
|
1082
|
+
)
|
|
1083
|
+
else:
|
|
1084
|
+
required_by_domain[domain] = value
|
|
1085
|
+
for domain in sorted(
|
|
1086
|
+
(domain for domain in required_entities if domain not in DOMAINS),
|
|
1087
|
+
key=str,
|
|
1088
|
+
):
|
|
1089
|
+
_add_issue(
|
|
1090
|
+
issues,
|
|
1091
|
+
"unexpected_manifest_domain",
|
|
1092
|
+
f"Coverage manifest contains unexpected domain {domain!r}.",
|
|
1093
|
+
source,
|
|
1094
|
+
)
|
|
1095
|
+
|
|
1096
|
+
raw_tutorial_files = manifest.get("tutorial_files")
|
|
1097
|
+
if not isinstance(raw_tutorial_files, Mapping):
|
|
1098
|
+
_add_issue(
|
|
1099
|
+
issues,
|
|
1100
|
+
"invalid_tutorial_files",
|
|
1101
|
+
"Coverage manifest 'tutorial_files' must be an object.",
|
|
1102
|
+
source,
|
|
1103
|
+
)
|
|
1104
|
+
else:
|
|
1105
|
+
for entity_id, filename in raw_tutorial_files.items():
|
|
1106
|
+
if not _is_nonempty_string(entity_id) or not _is_nonempty_string(
|
|
1107
|
+
filename
|
|
1108
|
+
):
|
|
1109
|
+
_add_issue(
|
|
1110
|
+
issues,
|
|
1111
|
+
"invalid_tutorial_mapping",
|
|
1112
|
+
"Tutorial mappings require non-empty string IDs and filenames.",
|
|
1113
|
+
source,
|
|
1114
|
+
)
|
|
1115
|
+
continue
|
|
1116
|
+
tutorial_files[entity_id] = filename
|
|
1117
|
+
|
|
1118
|
+
header_values: list[tuple[object, object]] = []
|
|
1119
|
+
for domain in DOMAINS:
|
|
1120
|
+
payload = payloads.get(domain)
|
|
1121
|
+
if isinstance(payload, Mapping):
|
|
1122
|
+
header_values.append(
|
|
1123
|
+
(payload.get("schema_version"), payload.get("version"))
|
|
1124
|
+
)
|
|
1125
|
+
if isinstance(manifest, Mapping):
|
|
1126
|
+
header_values.append(
|
|
1127
|
+
(manifest.get("schema_version"), manifest.get("version"))
|
|
1128
|
+
)
|
|
1129
|
+
schema_values = [value[0] for value in header_values if value[0] is not None]
|
|
1130
|
+
version_values = [value[1] for value in header_values if value[1] is not None]
|
|
1131
|
+
if schema_values and any(
|
|
1132
|
+
value != schema_values[0] for value in schema_values[1:]
|
|
1133
|
+
):
|
|
1134
|
+
_add_issue(
|
|
1135
|
+
issues,
|
|
1136
|
+
"schema_version_mismatch",
|
|
1137
|
+
"Guidance sources and manifest must share one schema_version.",
|
|
1138
|
+
source,
|
|
1139
|
+
)
|
|
1140
|
+
if version_values and any(
|
|
1141
|
+
value != version_values[0] for value in version_values[1:]
|
|
1142
|
+
):
|
|
1143
|
+
_add_issue(
|
|
1144
|
+
issues,
|
|
1145
|
+
"version_mismatch",
|
|
1146
|
+
"Guidance sources and manifest must share one version.",
|
|
1147
|
+
source,
|
|
1148
|
+
)
|
|
1149
|
+
|
|
1150
|
+
entity_records: dict[str, tuple[str, Mapping[object, object]]] = {}
|
|
1151
|
+
actual_by_domain: dict[str, set[str]] = {domain: set() for domain in DOMAINS}
|
|
1152
|
+
for domain in DOMAINS:
|
|
1153
|
+
for record in records_by_domain[domain]:
|
|
1154
|
+
record_id = _record_identifier(record)
|
|
1155
|
+
entity_id = record.get("entity_id")
|
|
1156
|
+
if not _is_nonempty_string(entity_id):
|
|
1157
|
+
continue
|
|
1158
|
+
if entity_id in entity_records:
|
|
1159
|
+
_add_issue(
|
|
1160
|
+
issues,
|
|
1161
|
+
"duplicate_entity_id",
|
|
1162
|
+
f"Entity ID '{entity_id}' is not globally unique.",
|
|
1163
|
+
source,
|
|
1164
|
+
record_id,
|
|
1165
|
+
)
|
|
1166
|
+
else:
|
|
1167
|
+
entity_records[entity_id] = (domain, record)
|
|
1168
|
+
actual_by_domain[domain].add(entity_id)
|
|
1169
|
+
|
|
1170
|
+
required_domains: dict[str, str] = {}
|
|
1171
|
+
for domain in DOMAINS:
|
|
1172
|
+
required = set(required_by_domain[domain])
|
|
1173
|
+
actual = actual_by_domain[domain]
|
|
1174
|
+
for entity_id in sorted(required):
|
|
1175
|
+
previous_domain = required_domains.get(entity_id)
|
|
1176
|
+
if previous_domain is not None and previous_domain != domain:
|
|
1177
|
+
_add_issue(
|
|
1178
|
+
issues,
|
|
1179
|
+
"duplicate_required_entity",
|
|
1180
|
+
f"Entity ID '{entity_id}' is required by multiple domains.",
|
|
1181
|
+
source,
|
|
1182
|
+
)
|
|
1183
|
+
required_domains[entity_id] = domain
|
|
1184
|
+
if entity_id not in actual:
|
|
1185
|
+
actual_record = entity_records.get(entity_id)
|
|
1186
|
+
if actual_record is not None:
|
|
1187
|
+
_add_issue(
|
|
1188
|
+
issues,
|
|
1189
|
+
"entity_domain_mismatch",
|
|
1190
|
+
f"Entity ID '{entity_id}' belongs to '{actual_record[0]}', "
|
|
1191
|
+
f"not '{domain}'.",
|
|
1192
|
+
source,
|
|
1193
|
+
_record_identifier(actual_record[1]),
|
|
1194
|
+
)
|
|
1195
|
+
else:
|
|
1196
|
+
_add_issue(
|
|
1197
|
+
issues,
|
|
1198
|
+
"missing_required_entity",
|
|
1199
|
+
f"Required entity ID '{entity_id}' is missing from '{domain}'.",
|
|
1200
|
+
source,
|
|
1201
|
+
)
|
|
1202
|
+
for entity_id in sorted(actual - required):
|
|
1203
|
+
_add_issue(
|
|
1204
|
+
issues,
|
|
1205
|
+
"unexpected_entity",
|
|
1206
|
+
f"Entity ID '{entity_id}' is not listed for domain '{domain}'.",
|
|
1207
|
+
source,
|
|
1208
|
+
_record_identifier(entity_records[entity_id][1]),
|
|
1209
|
+
)
|
|
1210
|
+
|
|
1211
|
+
resolvable_entity_ids = set(entity_records)
|
|
1212
|
+
for domain in DOMAINS:
|
|
1213
|
+
for record in records_by_domain[domain]:
|
|
1214
|
+
related_ids = record.get("related_ids")
|
|
1215
|
+
if not _is_string_list(related_ids):
|
|
1216
|
+
continue
|
|
1217
|
+
record_id = _record_identifier(record)
|
|
1218
|
+
for related_id in related_ids:
|
|
1219
|
+
if related_id not in resolvable_entity_ids:
|
|
1220
|
+
_add_issue(
|
|
1221
|
+
issues,
|
|
1222
|
+
"unresolved_related_id",
|
|
1223
|
+
f"Related entity ID '{related_id}' does not resolve.",
|
|
1224
|
+
source,
|
|
1225
|
+
record_id,
|
|
1226
|
+
)
|
|
1227
|
+
|
|
1228
|
+
tutorial_entity_ids = {
|
|
1229
|
+
entity_id
|
|
1230
|
+
for entity_id, (_domain, record) in entity_records.items()
|
|
1231
|
+
if record.get("entity_type") == "tutorial"
|
|
1232
|
+
}
|
|
1233
|
+
for entity_id in sorted(tutorial_entity_ids - set(tutorial_files)):
|
|
1234
|
+
_add_issue(
|
|
1235
|
+
issues,
|
|
1236
|
+
"missing_tutorial_mapping",
|
|
1237
|
+
f"Tutorial entity ID '{entity_id}' has no Markdown mapping.",
|
|
1238
|
+
source,
|
|
1239
|
+
_record_identifier(entity_records[entity_id][1]),
|
|
1240
|
+
)
|
|
1241
|
+
for entity_id in sorted(set(tutorial_files) - tutorial_entity_ids):
|
|
1242
|
+
if entity_id not in entity_records:
|
|
1243
|
+
code = "unknown_tutorial_entity"
|
|
1244
|
+
message = f"Tutorial mapping ID '{entity_id}' does not resolve."
|
|
1245
|
+
record_id = ""
|
|
1246
|
+
else:
|
|
1247
|
+
code = "invalid_tutorial_entity"
|
|
1248
|
+
message = f"Tutorial mapping ID '{entity_id}' is not a tutorial entity."
|
|
1249
|
+
record_id = _record_identifier(entity_records[entity_id][1])
|
|
1250
|
+
_add_issue(issues, code, message, source, record_id)
|
|
1251
|
+
|
|
1252
|
+
return tuple(issues)
|