aethis-cli 0.49.2__tar.gz → 0.50.0__tar.gz

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.
Files changed (117) hide show
  1. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/PKG-INFO +1 -1
  2. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/_version.py +1 -1
  3. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/fields_cmd.py +6 -1
  4. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/generate_cmd.py +50 -7
  5. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli.egg-info/PKG-INFO +1 -1
  6. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli.egg-info/SOURCES.txt +1 -0
  7. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/pyproject.toml +1 -1
  8. aethis_cli-0.50.0/tests/test_collection_computed_prerequisite_transport.py +172 -0
  9. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/LICENSE +0 -0
  10. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/README.md +0 -0
  11. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/__init__.py +0 -0
  12. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/__main__.py +0 -0
  13. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/_terminal_safe.py +0 -0
  14. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/auth.py +0 -0
  15. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/auth_helpers.py +0 -0
  16. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/auth_providers.py +0 -0
  17. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/client.py +0 -0
  18. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/__init__.py +0 -0
  19. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/_id_utils.py +0 -0
  20. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/account_cmd.py +0 -0
  21. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/cancel_cmd.py +0 -0
  22. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/decide_cmd.py +0 -0
  23. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/explain_cmd.py +0 -0
  24. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/guidance_cmd.py +0 -0
  25. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/init_cmd.py +0 -0
  26. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/login_cmd.py +0 -0
  27. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/mcp_cmd.py +0 -0
  28. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/profile_cmd.py +0 -0
  29. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/projects_cmd.py +0 -0
  30. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/publish_cmd.py +0 -0
  31. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/refine_cmd.py +0 -0
  32. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/review_cmd.py +0 -0
  33. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/rulebooks_cmd.py +0 -0
  34. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/rulesets_cmd.py +0 -0
  35. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/status_cmd.py +0 -0
  36. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/test_cmd.py +0 -0
  37. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/update_cmd.py +0 -0
  38. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/usage_cmd.py +0 -0
  39. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/commands/whoami_cmd.py +0 -0
  40. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/config.py +0 -0
  41. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/contract.py +0 -0
  42. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/decision_view.py +0 -0
  43. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/errors.py +0 -0
  44. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/generation_status.py +0 -0
  45. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/main.py +0 -0
  46. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/output.py +0 -0
  47. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/prompts.py +0 -0
  48. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/py.typed +0 -0
  49. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/render.py +0 -0
  50. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/source_safeguards.py +0 -0
  51. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/source_targets.py +0 -0
  52. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli/update_check.py +0 -0
  53. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli.egg-info/dependency_links.txt +0 -0
  54. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli.egg-info/entry_points.txt +0 -0
  55. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli.egg-info/requires.txt +0 -0
  56. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/aethis_cli.egg-info/top_level.txt +0 -0
  57. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/setup.cfg +0 -0
  58. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_acceptance_contract.py +0 -0
  59. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_account_cmd.py +0 -0
  60. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_auth.py +0 -0
  61. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_auth_providers.py +0 -0
  62. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_cancel_cmd.py +0 -0
  63. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_capability_boundary.py +0 -0
  64. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_client.py +0 -0
  65. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_config.py +0 -0
  66. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_contract_decide.py +0 -0
  67. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_contract_identity_and_sources.py +0 -0
  68. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_contract_request_surface.py +0 -0
  69. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_contract_rulebook_decide.py +0 -0
  70. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_credential_server.py +0 -0
  71. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_credential_url_parser.py +0 -0
  72. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_decide_cmd.py +0 -0
  73. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_documented_commands_run.py +0 -0
  74. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_empty_input_guards.py +0 -0
  75. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_explain_cmd.py +0 -0
  76. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_field_behaviour_metadata_transport.py +0 -0
  77. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_field_dependency_and_identity_transport.py +0 -0
  78. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_field_display_metadata_transport.py +0 -0
  79. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_field_notes_validation.py +0 -0
  80. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_fields_cmd.py +0 -0
  81. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_generate_display_name.py +0 -0
  82. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_generate_failure_reporting.py +0 -0
  83. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_generate_fields.py +0 -0
  84. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_generate_no_publish.py +0 -0
  85. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_generate_replace_tests.py +0 -0
  86. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_generation_models.py +0 -0
  87. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_generation_status.py +0 -0
  88. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_guidance_cli.py +0 -0
  89. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_id_utils.py +0 -0
  90. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_init.py +0 -0
  91. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_json_projection_pinning.py +0 -0
  92. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_lazy_auth.py +0 -0
  93. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_login_headless.py +0 -0
  94. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_main.py +0 -0
  95. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_mcp_cmd.py +0 -0
  96. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_output.py +0 -0
  97. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_profiles.py +0 -0
  98. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_project_file_trust.py +0 -0
  99. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_prompts.py +0 -0
  100. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_publish_display_name.py +0 -0
  101. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_publish_force.py +0 -0
  102. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_publish_rulebook_flags.py +0 -0
  103. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_publish_source_targets.py +0 -0
  104. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_release_tooling.py +0 -0
  105. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_render.py +0 -0
  106. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_review_cmd.py +0 -0
  107. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_rulebooks_cmd.py +0 -0
  108. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_rulesets_b1b_lifecycle.py +0 -0
  109. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_source_safeguards.py +0 -0
  110. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_spacecraft_example_pin.py +0 -0
  111. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_status_cmd.py +0 -0
  112. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_transport_error_rendering.py +0 -0
  113. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_update_check.py +0 -0
  114. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_update_cmd.py +0 -0
  115. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_usage.py +0 -0
  116. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_value_space_transport.py +0 -0
  117. {aethis_cli-0.49.2 → aethis_cli-0.50.0}/tests/test_whoami_cmd.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aethis-cli
3
- Version: 0.49.2
3
+ Version: 0.50.0
4
4
  Summary: CLI for the Aethis developer API — author, test, and publish rulesets
5
5
  Author-email: Aethis <eng@aethis.ai>
6
6
  License-Expression: MIT
@@ -1,3 +1,3 @@
1
1
  """Version info — updated per release."""
2
2
 
3
- __version__ = "0.49.2"
3
+ __version__ = "0.50.0"
@@ -234,7 +234,12 @@ def pull(
234
234
  entry = dict(field_map.get(key, {})) # preserve local label/hints
235
235
  existed = key in field_map
236
236
  entry["key"] = key
237
- entry["type"] = _safe_field_type(sf.get("field_type"), sf.get("enum_values"))
237
+ if (entry.get("type") or "").strip().lower() == "collection" and isinstance(entry.get("items"), dict):
238
+ # A pulled row carries no item shape, so it cannot express a
239
+ # collection; keep the locally authored declaration intact.
240
+ pass
241
+ else:
242
+ entry["type"] = _safe_field_type(sf.get("field_type"), sf.get("enum_values"))
238
243
  if entry.get("value_space"):
239
244
  # A field pinned to a named value space keeps the reference and
240
245
  # NEVER materialises members locally — writing the server's
@@ -655,7 +655,17 @@ def _field_guidance_lines(key: str, field: dict) -> list[str]:
655
655
 
656
656
  # The set of value types a ``fields.yaml`` entry may declare. Mirrors the
657
657
  # engine's accepted sorts (it normalises case + the long forms below).
658
- VALID_FIELD_TYPES = {"int", "bool", "string", "enum", "date", "duration"}
658
+ VALID_FIELD_TYPES = {"int", "bool", "string", "enum", "date", "duration", "collection"}
659
+
660
+ # Types whose members come from ``enum_values`` / a named ``value_space`` and so
661
+ # may carry ``enum_labels``. A collection's members are its items' members.
662
+ _MEMBERED_FIELD_TYPES = {"enum", "collection"}
663
+
664
+ # Structured declarations whose shape the ENGINE owns and validates (it
665
+ # advertises each on the field-spec schema). The CLI checks only that each is a
666
+ # mapping and sends it unchanged; a second copy of the engine's schema here
667
+ # would drift from it and reject declarations the engine accepts.
668
+ _ENGINE_SHAPED_FIELD_KEYS = ("items", "computed", "question_prerequisite")
659
669
 
660
670
  # The server speaks the long, public-facing type names; ``fields.yaml`` uses the
661
671
  # short canonical forms. Map server → on-disk so a pulled/discovered field reads
@@ -679,6 +689,9 @@ _FIELD_KEY_ORDER = (
679
689
  "enum_labels",
680
690
  "canonical_field",
681
691
  "options_by",
692
+ "items",
693
+ "computed",
694
+ "question_prerequisite",
682
695
  "weight",
683
696
  "elicitation_owner",
684
697
  "injection_source",
@@ -700,6 +713,12 @@ _ENGINE_GATED_FIELD_KEYS = (
700
713
  # ``{field, map}``: narrows this enum field's suggested options by the
701
714
  # answer to an earlier field. Opaque to the CLI; the engine validates it.
702
715
  "options_by",
716
+ # Collection item shape, engine-computed Bool declarations and the Boolean
717
+ # fact a question waits for. Shapes are the engine's; see
718
+ # ``_ENGINE_SHAPED_FIELD_KEYS``.
719
+ "items",
720
+ "computed",
721
+ "question_prerequisite",
703
722
  "label",
704
723
  "question",
705
724
  "weight",
@@ -740,7 +759,10 @@ def _safe_field_type(raw_type: Optional[str], enum_values: Optional[list]) -> st
740
759
  values (not a representable enum on disk). Both fall back to ``string``.
741
760
  """
742
761
  t = _normalise_field_type(raw_type)
743
- if t not in VALID_FIELD_TYPES:
762
+ # A pulled/discovered row carries no ``items``, and a collection without
763
+ # them is not a valid fields.yaml entry, so it falls back like any other
764
+ # type the file could not round-trip (unchanged from before collections).
765
+ if t not in VALID_FIELD_TYPES or t == "collection":
744
766
  return "string"
745
767
  if t == "enum" and not enum_values:
746
768
  return "string"
@@ -784,10 +806,19 @@ def validate_fields_list(fields: list) -> list[str]:
784
806
  f"mutually exclusive; the named reference is authoritative, so drop the "
785
807
  f"inline members."
786
808
  )
787
- if f.get("value_space") and ftype != "enum":
788
- errors.append(f"Field {key!r} declares value_space but is type {ftype!r} — only enum fields may.")
809
+ if f.get("value_space") and ftype not in _MEMBERED_FIELD_TYPES:
810
+ errors.append(
811
+ f"Field {key!r} declares value_space but is type {ftype!r} — only enum and collection fields may."
812
+ )
789
813
  if ftype == "enum" and not f.get("enum_values") and not f.get("value_space"):
790
814
  errors.append(f"Field {key!r} is type 'enum' but declares no enum_values (or value_space).")
815
+ for prop in _ENGINE_SHAPED_FIELD_KEYS:
816
+ if prop in f and f[prop] is not None and not isinstance(f[prop], dict):
817
+ errors.append(f"Field {key!r} declares {prop} but it is not a mapping.")
818
+ if ftype == "collection" and not isinstance(f.get("items"), dict):
819
+ errors.append(f"Field {key!r} is type 'collection' but declares no items mapping.")
820
+ if f.get("items") is not None and ftype != "collection":
821
+ errors.append(f"Field {key!r} declares items but is type {ftype!r} — only collection fields may.")
791
822
  errors.extend(_validate_display_metadata(key, f, ftype))
792
823
  errors.extend(_validate_field_notes(key, f))
793
824
  return errors
@@ -816,8 +847,10 @@ def _validate_display_metadata(key: str, f: dict, ftype: str) -> list[str]:
816
847
  else:
817
848
  # An empty map is a legitimate declaration — the engine keeps it —
818
849
  # so the checks below simply have nothing to say about it.
819
- if ftype != "enum":
820
- errors.append(f"Field {key!r} declares enum_labels but is type {ftype!r} — only enum fields may.")
850
+ if ftype not in _MEMBERED_FIELD_TYPES:
851
+ errors.append(
852
+ f"Field {key!r} declares enum_labels but is type {ftype!r} — only enum and collection fields may."
853
+ )
821
854
  # Members are compared as text, so a non-text key can never match
822
855
  # one and is reported as its own fault rather than as a member the
823
856
  # field does not declare.
@@ -1717,7 +1750,17 @@ def _report_field_diff(
1717
1750
  return
1718
1751
  schema_fields = schema.get("fields", []) or []
1719
1752
  produced = {f.get("field_id") for f in schema_fields if f.get("field_id")}
1720
- produced_members = {f["field_id"]: set(f.get("enum_values") or []) for f in schema_fields if f.get("field_id")}
1753
+ # A collection's members are its items' members; the engine never sets a
1754
+ # top-level enum_values on one.
1755
+ produced_members = {
1756
+ f["field_id"]: set(
1757
+ f.get("enum_values")
1758
+ or ((f.get("items") or {}).get("enum_values") if isinstance(f.get("items"), dict) else None)
1759
+ or []
1760
+ )
1761
+ for f in schema_fields
1762
+ if f.get("field_id")
1763
+ }
1721
1764
 
1722
1765
  missing = sorted(pinned - produced)
1723
1766
  extra = sorted(produced - pinned)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aethis-cli
3
- Version: 0.49.2
3
+ Version: 0.50.0
4
4
  Summary: CLI for the Aethis developer API — author, test, and publish rulesets
5
5
  Author-email: Aethis <eng@aethis.ai>
6
6
  License-Expression: MIT
@@ -59,6 +59,7 @@ tests/test_auth_providers.py
59
59
  tests/test_cancel_cmd.py
60
60
  tests/test_capability_boundary.py
61
61
  tests/test_client.py
62
+ tests/test_collection_computed_prerequisite_transport.py
62
63
  tests/test_config.py
63
64
  tests/test_contract_decide.py
64
65
  tests/test_contract_identity_and_sources.py
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "aethis-cli"
3
- version = "0.49.2"
3
+ version = "0.50.0"
4
4
  description = "CLI for the Aethis developer API — author, test, and publish rulesets"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
@@ -0,0 +1,172 @@
1
+ """Collection fields, computed declarations and question prerequisites reach the engine as authored.
2
+
3
+ The engine owns the shape of all three (it advertises them on the field-spec
4
+ schema and validates them strictly). The CLI's job is to send them unchanged
5
+ when the engine says it keeps them, and to refuse loudly when it does not.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from unittest.mock import MagicMock
11
+
12
+ import pytest
13
+ import typer
14
+
15
+ from aethis_cli.commands import generate_cmd
16
+
17
+
18
+ BASE = {"key", "sort", "enum_values", "value_space", "enum_labels", "label", "question"}
19
+ NEW = {"items", "computed", "question_prerequisite"}
20
+
21
+ FIELDS = """\
22
+ fields:
23
+ - key: owner.vehicles
24
+ type: collection
25
+ value_space: acme/vehicle-makes
26
+ enum_labels: {toyota: Toyota, ford: Ford}
27
+ items: {sort: Enum, min_items: 1, completion_question: "Is that every vehicle you own?"}
28
+ - key: owner.has_vehicles
29
+ type: bool
30
+ - key: owner.owns_listed_make
31
+ type: bool
32
+ question_prerequisite: {field: owner.has_vehicles, equals: true}
33
+ computed: {op: any_in, collection: owner.vehicles, values: [toyota]}
34
+ - key: owner.has_licence_a
35
+ type: bool
36
+ - key: owner.has_licence_b
37
+ type: bool
38
+ - key: owner.has_any_licence
39
+ type: bool
40
+ computed: {op: any_true, fields: [owner.has_licence_a, owner.has_licence_b]}
41
+ """
42
+
43
+
44
+ def _project(tmp_path, body: str = FIELDS):
45
+ fields = tmp_path / "fields" / "fields.yaml"
46
+ fields.parent.mkdir(parents=True)
47
+ fields.write_text(body)
48
+ return tmp_path
49
+
50
+
51
+ def _client(properties):
52
+ client = MagicMock()
53
+ client.expected_field_spec_properties.return_value = properties
54
+ client.base_url = "https://engine.example"
55
+ return client
56
+
57
+
58
+ def test_fields_file_with_all_three_is_valid(tmp_path):
59
+ import yaml
60
+
61
+ rows = yaml.safe_load(FIELDS)["fields"]
62
+ assert generate_cmd.validate_fields_list(rows) == []
63
+
64
+
65
+ def test_all_three_transported_exactly_as_authored(tmp_path, monkeypatch):
66
+ monkeypatch.setattr(generate_cmd, "_sync_value_spaces", lambda *a, **k: None)
67
+ client = _client(BASE | NEW)
68
+ generate_cmd._upload_field_vocabulary(client, "proj_1", _project(tmp_path))
69
+ sent = {f["key"]: f for f in client.set_field_spec.call_args.args[1]}
70
+
71
+ assert sent["owner.vehicles"]["sort"] == "collection"
72
+ assert sent["owner.vehicles"]["value_space"] == "acme/vehicle-makes"
73
+ assert sent["owner.vehicles"]["enum_labels"] == {"toyota": "Toyota", "ford": "Ford"}
74
+ assert sent["owner.vehicles"]["items"] == {
75
+ "sort": "Enum",
76
+ "min_items": 1,
77
+ "completion_question": "Is that every vehicle you own?",
78
+ }
79
+ assert sent["owner.owns_listed_make"]["computed"] == {
80
+ "op": "any_in",
81
+ "collection": "owner.vehicles",
82
+ "values": ["toyota"],
83
+ }
84
+ assert sent["owner.owns_listed_make"]["question_prerequisite"] == {
85
+ "field": "owner.has_vehicles",
86
+ "equals": True,
87
+ }
88
+ assert sent["owner.has_any_licence"]["computed"] == {
89
+ "op": "any_true",
90
+ "fields": ["owner.has_licence_a", "owner.has_licence_b"],
91
+ }
92
+ assert "computed" not in sent["owner.has_vehicles"]
93
+
94
+
95
+ @pytest.mark.parametrize("missing", sorted(NEW))
96
+ def test_engine_without_the_property_refuses_before_mutation(tmp_path, monkeypatch, missing):
97
+ monkeypatch.setattr(generate_cmd, "_sync_value_spaces", lambda *a, **k: None)
98
+ client = _client((BASE | NEW) - {missing})
99
+ with pytest.raises(typer.Exit):
100
+ generate_cmd._upload_field_vocabulary(client, "proj_1", _project(tmp_path))
101
+ client.set_field_spec.assert_not_called()
102
+
103
+
104
+ @pytest.mark.parametrize(
105
+ "row, expected",
106
+ [
107
+ (" - {key: a.list, type: collection, value_space: acme/x}\n", "declares no items"),
108
+ (" - {key: a.flag, type: bool, computed: [any_true]}\n", "computed"),
109
+ (" - {key: a.flag, type: bool, question_prerequisite: a.other}\n", "question_prerequisite"),
110
+ (" - {key: a.flag, type: bool, items: {sort: Enum}}\n", "items"),
111
+ ],
112
+ )
113
+ def test_malformed_declarations_are_reported_locally(row, expected):
114
+ import yaml
115
+
116
+ rows = yaml.safe_load("fields:\n" + row)["fields"]
117
+ errors = generate_cmd.validate_fields_list(rows)
118
+ assert any(expected in e for e in errors), errors
119
+
120
+
121
+ def test_value_space_collection_members_are_read_from_items_after_generation(tmp_path, capsys):
122
+ """A collection keeps its members under ``items``; reading only the top level reported false drift."""
123
+ project = _project(
124
+ tmp_path,
125
+ "fields:\n - {key: owner.vehicles, type: collection, value_space: acme/vehicle-makes, items: {sort: Enum}}\n",
126
+ )
127
+ client = MagicMock()
128
+ client.get_schema.return_value = {
129
+ "fields": [{"field_id": "owner.vehicles", "items": {"sort": "Enum", "enum_values": ["ford", "toyota"]}}]
130
+ }
131
+ client.get_value_space.return_value = {"members": ["toyota", "ford"]}
132
+
133
+ generate_cmd._report_field_diff(
134
+ client,
135
+ "rs_1",
136
+ project,
137
+ value_spaces_resolved={"owner.vehicles": {"space": "acme/vehicle-makes", "version": 1, "space_id": "vs_1"}},
138
+ )
139
+
140
+ out = " ".join(capsys.readouterr().out.split())
141
+ assert "members verified" in out, out
142
+ assert "differ" not in out, out
143
+
144
+
145
+ def test_fields_pull_keeps_a_local_collection_declaration(tmp_path, monkeypatch):
146
+ """A pulled row carries no item shape; overwriting a collection with ``string`` broke the file."""
147
+ from unittest.mock import patch
148
+
149
+ from typer.testing import CliRunner
150
+
151
+ from aethis_cli.main import app
152
+ from tests.test_fields_cmd import _cfg
153
+
154
+ monkeypatch.chdir(tmp_path)
155
+ _project(
156
+ tmp_path,
157
+ "fields:\n - {key: owner.vehicles, type: collection, value_space: acme/vehicle-makes, items: {sort: Enum}}\n",
158
+ )
159
+ client = MagicMock()
160
+ client.get_schema.return_value = {"fields": [{"field_id": "owner.vehicles", "field_type": "collection"}]}
161
+ with (
162
+ patch("aethis_cli.commands.fields_cmd.load_project_config", return_value=_cfg(tmp_path)),
163
+ patch("aethis_cli.commands.fields_cmd.resolve_api_key", return_value="ak"),
164
+ patch("aethis_cli.commands.fields_cmd.make_authed_client", return_value=client),
165
+ ):
166
+ result = CliRunner().invoke(app, ["fields", "pull", "-b", "rs_1"], catch_exceptions=False)
167
+
168
+ assert result.exit_code == 0, result.output
169
+ parsed = generate_cmd._parse_fields_yaml(tmp_path / "fields" / "fields.yaml")
170
+ assert parsed["owner.vehicles"]["type"] == "collection"
171
+ assert parsed["owner.vehicles"]["items"] == {"sort": "Enum"}
172
+ assert generate_cmd.validate_fields_list(list(parsed.values())) == []
File without changes
File without changes
File without changes