Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion loopx/domain_packs/ml_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from ..control_plane.runtime.public_safety import REMOTE_LOCATION_SURFACE_PATTERN
from ..domain_state import default_domain_state_file_path, upsert_domain_state_jsonl
from ..public_safe_text import (
LETTER_LED_COMPACT_TOKEN_PATTERN as _TOKEN_RE,
)


DOMAIN_PACK_CONTRACT_SCHEMA_VERSION = "domain_pack_contract_v0"
Expand Down Expand Up @@ -35,7 +38,6 @@
"Unknown",
)

_TOKEN_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_.:-]{0,79}$")
_ABSOLUTE_PATH_RE = re.compile(
r"(^|[\s:=])(?:"
+ "/" + "Users/"
Expand Down
7 changes: 3 additions & 4 deletions loopx/domain_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import json
import os
import re
import tempfile
from pathlib import Path
from typing import Any, Callable

from .file_lock import exclusive_file_lock


_DOMAIN_STATE_TOKEN_RE = re.compile(r"^[A-Za-z][A-Za-z0-9_.:-]{0,79}$")
from .public_safe_text import (
LETTER_LED_COMPACT_TOKEN_PATTERN as _DOMAIN_STATE_TOKEN_RE,
)


def _domain_state_token(value: str, *, field: str) -> str:
Expand Down
6 changes: 6 additions & 0 deletions loopx/public_safe_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@
r"^[A-Za-z0-9][A-Za-z0-9._:/#-]{0,199}$"
)
COMPACT_TOKEN_PATTERN = re.compile(r"^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$")
# One definition for "a compact token that must start with a letter". The
# domain-state key validator and the ML-experiment public-token validator each
# compiled this body under their own name; both now import this object, and
# tests/control_plane/test_compact_identifier_shape_owner.py rejects a new local
# copy. Each consumer keeps its own field names and error text.
LETTER_LED_COMPACT_TOKEN_PATTERN = re.compile(r"^[A-Za-z][A-Za-z0-9_.:-]{0,79}$")
# One definition for "a compact, path-safe opaque identifier". Four contracts each
# compiled this body under their own name -- the Chat action surface, the Chat
# action store, a Goal reference validator and the BotMux runtime -- and a fifth
Expand Down
21 changes: 20 additions & 1 deletion tests/control_plane/test_compact_identifier_shape_owner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from loopx import chat_action_normalization, chat_actions, chat_action_store
from loopx import chat_action_normalization, chat_actions, chat_action_store, domain_state
from loopx.capabilities.benchmark_toolkit import integrity
from loopx.capabilities.decision_context import packets, profile, sources
from loopx.capabilities.material_lifecycle import _validation
Expand All @@ -20,6 +20,7 @@
registry,
)
from loopx.capabilities.semantic_preference import contract
from loopx.domain_packs import ml_experiment
from loopx.control_plane.goals import (
botmux_runtime,
deletion_service,
Expand All @@ -28,6 +29,7 @@
from loopx.extensions import presentation
from loopx.public_safe_text import (
COMPACT_TOKEN_PATTERN,
LETTER_LED_COMPACT_TOKEN_PATTERN,
OPAQUE_ID_PATTERN as PUBLIC_OPAQUE_ID,
MODULE_QUALIFIED_SURFACE_PATTERN,
PUBLIC_SAFE_REFERENCE_PATTERN,
Expand All @@ -37,6 +39,7 @@
OWNER_MODULE = "loopx/public_safe_text.py"
REFERENCE_SHAPE = "^[A-Za-z0-9][A-Za-z0-9._:/#-]{0,199}$"
COMPACT_SHAPE = "^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$"
LETTER_LED_SHAPE = "^[A-Za-z][A-Za-z0-9_.:-]{0,79}$"
SURFACE_SHAPE = "^[a-z][a-z0-9_-]*(?:\\.[a-z][a-z0-9_-]*)+$"
OPAQUE_SHAPE = "^[A-Za-z0-9._:-]{1,200}$"

Expand All @@ -45,6 +48,7 @@
# an entry whose site has already been converted, fails the census.
OPEN_OPAQUE_SITES: dict[str, int] = {}
OPEN_COMPACT_SITES: dict[str, int] = {}
OPEN_LETTER_LED_SITES: dict[str, int] = {}


SHAPE_CONSUMERS = {
Expand Down Expand Up @@ -125,6 +129,21 @@ def test_the_compact_token_body_is_compiled_only_by_the_owner_and_declared_sites
assert found == {OWNER_MODULE: 1, **OPEN_COMPACT_SITES}


def test_the_letter_led_token_body_is_compiled_only_by_the_owner_and_declared_sites() -> None:
found: dict[str, int] = {}
for path in sorted(REPOSITORY_ROOT.glob("loopx/**/*.py")):
relative = path.relative_to(REPOSITORY_ROOT).as_posix()
count = path.read_text(encoding="utf-8").count(LETTER_LED_SHAPE)
if count:
found[relative] = count
assert found == {OWNER_MODULE: 1, **OPEN_LETTER_LED_SITES}


def test_domain_state_and_ml_experiment_share_the_letter_led_token_shape() -> None:
assert domain_state._DOMAIN_STATE_TOKEN_RE is LETTER_LED_COMPACT_TOKEN_PATTERN
assert ml_experiment._TOKEN_RE is LETTER_LED_COMPACT_TOKEN_PATTERN


def test_each_contract_holds_the_owners_object_and_reports_its_own_field() -> None:
assert chat_actions._OPAQUE_ID is PUBLIC_OPAQUE_ID
assert chat_action_store._OPAQUE_ID is PUBLIC_OPAQUE_ID
Expand Down
Loading