docs: verify structured semantic contracts
This commit is contained in:
@@ -105,6 +105,56 @@ for token in tokens:
|
||||
PY
|
||||
}
|
||||
|
||||
verify_markdown_table_relationships() {
|
||||
local source="$1" label="$2" heading="$3" spec_json="$4"
|
||||
python3 - "$source" "$label" "$heading" "$spec_json" <<'PY'
|
||||
import json, pathlib, re, sys
|
||||
path = pathlib.Path(sys.argv[1])
|
||||
label = sys.argv[2]
|
||||
heading = sys.argv[3]
|
||||
spec = json.loads(sys.argv[4])
|
||||
text = path.read_text()
|
||||
match = re.search(rf"^##+\s+{re.escape(heading)}\s*$", text, re.MULTILINE)
|
||||
if not match:
|
||||
raise SystemExit(f"{label}: missing structured section '{heading}'")
|
||||
lines = text[match.end():].splitlines()
|
||||
table = []
|
||||
for line in lines:
|
||||
if not line.strip():
|
||||
if table:
|
||||
break
|
||||
continue
|
||||
if not line.lstrip().startswith("|"):
|
||||
if table:
|
||||
break
|
||||
continue
|
||||
table.append(line.rstrip())
|
||||
if len(table) < 3:
|
||||
raise SystemExit(f"{label}: structured table '{heading}' is incomplete")
|
||||
headers = [cell.strip().lower() for cell in table[0].strip().strip("|").split("|")]
|
||||
rows = []
|
||||
for raw in table[2:]:
|
||||
cells = [cell.strip() for cell in raw.strip().strip("|").split("|")]
|
||||
if len(cells) != len(headers):
|
||||
raise SystemExit(f"{label}: malformed row in '{heading}'")
|
||||
rows.append(dict(zip(headers, cells)))
|
||||
for row_spec in spec["rows"]:
|
||||
found = False
|
||||
for row in rows:
|
||||
ok = True
|
||||
for column, pattern in row_spec.items():
|
||||
value = row.get(column.lower(), "")
|
||||
if not re.search(pattern, value, re.IGNORECASE | re.DOTALL):
|
||||
ok = False
|
||||
break
|
||||
if ok:
|
||||
found = True
|
||||
break
|
||||
if not found:
|
||||
raise SystemExit(f"{label}: missing relationship in '{heading}': {row_spec}")
|
||||
PY
|
||||
}
|
||||
|
||||
verify_compose_internal_semantic_contract() {
|
||||
python3 - "$root/compose.yaml" <<'PY'
|
||||
import sys, yaml, pathlib
|
||||
@@ -251,6 +301,29 @@ verify_internal_semantic_infrastructure_docs() {
|
||||
verify_vector_helper_interfaces || return 1
|
||||
verify_project_state_current_contract "$root/PROJECT_STATE.md" "PROJECT_STATE.md" || return 1
|
||||
|
||||
local ownership_spec semantic_index_spec compact_spec
|
||||
ownership_spec='{"rows":[
|
||||
{"component":"^DWH$","ownership":"^External$","operator contract":"external|endpoint|installation"},
|
||||
{"component":"^LLM$","ownership":"^External$","operator contract":"external|endpoint|policy"},
|
||||
{"component":"^Qdrant$","ownership":"^Internal$","operator contract":"internal|Compose|qdrant-data"},
|
||||
{"component":"^Ollama embedding$","ownership":"^Internal$","operator contract":"internal|Compose|qwen3-embedding:0\\.6b"}
|
||||
]}'
|
||||
semantic_index_spec='{"rows":[
|
||||
{"scope":"workspace semantic index","ownership rule":"(each|one|single).*(workspace).*(single|one).*(Qdrant).*(collection)|(each workspace reserves a single qdrant collection)","isolation rule":"schema.*evidence.*memory.*(one|that).*(collection).*(kind|payload)"}
|
||||
]}'
|
||||
compact_spec='{"rows":[
|
||||
{"componente":"^DWH$","ownership":"^Esterno$","contratto operativo":"endpoint.*estern"},
|
||||
{"componente":"^LLM$","ownership":"^Esterno$","contratto operativo":"esterna|esterno"},
|
||||
{"componente":"^Qdrant$","ownership":"^Interno$","contratto operativo":"interno.*obbligatorio.*qdrant-data"},
|
||||
{"componente":"^Ollama embedding$","ownership":"^Interno$","contratto operativo":"interno.*obbligatorio.*qwen3-embedding:0\\.6b"}
|
||||
]}'
|
||||
|
||||
verify_markdown_table_relationships "$local_manual" "local workspace manual" "Architecture ownership contract" "$ownership_spec" || return 1
|
||||
verify_markdown_table_relationships "$server_manual" "server workspace manual" "Architecture ownership contract" "$ownership_spec" || return 1
|
||||
verify_markdown_table_relationships "$local_manual" "local workspace manual" "Semantic index ownership contract" "$semantic_index_spec" || return 1
|
||||
verify_markdown_table_relationships "$server_manual" "server workspace manual" "Semantic index ownership contract" "$semantic_index_spec" || return 1
|
||||
verify_markdown_table_relationships "$compact_manual" "four-context install note" "Contratto sintetico di ownership" "$compact_spec" || return 1
|
||||
|
||||
require_pattern "$readme" "README" 'mandatory stack.+qdrant.+embedding.+embedding-model-init' || return 1
|
||||
require_pattern "$readme" "README" 'qwen3-embedding:0\.6b' || return 1
|
||||
require_pattern "$readme" "README" 'qdrant-data.+embedding-models' || return 1
|
||||
@@ -260,19 +333,10 @@ verify_internal_semantic_infrastructure_docs() {
|
||||
for manual in "$local_manual" "$server_manual"; do
|
||||
require_pattern "$manual" "$(basename "$manual")" 'qwen3-embedding:0\.6b' || return 1
|
||||
require_pattern "$manual" "$(basename "$manual")" 'migration_required' || return 1
|
||||
require_concept_tokens "$manual" "$(basename "$manual")" \
|
||||
"workspace" "qdrant" "collection" || return 1
|
||||
require_pattern "$manual" "$(basename "$manual")" '(?is)(one|single|each).{0,120}(workspace|qdrant|collection).{0,120}(owns|reserve|reserved|single)' || return 1
|
||||
done
|
||||
require_pattern "$local_manual" "local workspace manual" 'CPU-first' || return 1
|
||||
require_pattern "$local_manual" "local workspace manual" 'THOTH_ENABLE_EMBEDDING_GPU=1' || return 1
|
||||
require_pattern "$server_manual" "server workspace manual" 'Qdrant backup/restore' || return 1
|
||||
require_pattern "$server_manual" "server workspace manual" '(Git remote|DWH|LLM|bastion)' || return 1
|
||||
require_pattern "$server_manual" "server workspace manual" '(stay external|remain external|sono esterni)' || return 1
|
||||
require_concept_tokens "$compact_manual" "four-context install note" \
|
||||
"qdrant" "ollama" "dwh" "llm" || return 1
|
||||
require_pattern "$compact_manual" "four-context install note" '(?is)(interni obbligatori|servizi interni obbligatori|interni al progetto compose)' || return 1
|
||||
require_pattern "$compact_manual" "four-context install note" '(?is)(esterni solo|solo esterni|restano esterni|unici servizi esterni|unici esterni)' || return 1
|
||||
require_pattern "$compact_manual" "four-context install note" '1024 dimensioni' || return 1
|
||||
require_pattern "$diagnostics" "workspace diagnostic protocol" 'schema version 3' || return 1
|
||||
require_pattern "$diagnostics" "workspace diagnostic protocol" 'semantic_index_incompatible' || return 1
|
||||
|
||||
Reference in New Issue
Block a user