rsnarsna commited on
Commit
475fb21
·
1 Parent(s): 652cf11

fix(registry): restore canonical node registry to 47 nodes and extract CANONICAL_NODE_COUNT

Browse files
language_core/node_schema.py CHANGED
@@ -4348,295 +4348,9 @@ default_registry.register(
4348
  )
4349
 
4350
 
4351
- # ═══════════════════════════════════════════════════════════════════════════
 
 
4352
 
4353
- # ═══════════════════════════════════════════════════════════════════════════
4354
-
4355
- # ═══════════════════════════════════════════════════════════════════════════
4356
- # PROGRAMMING FUNDAMENTALS — 11 MAIN CATEGORY NODES (Master Implementation)
4357
- # ═══════════════════════════════════════════════════════════════════════════
4358
-
4359
- def _exec_cat_essentials(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4360
- msg = inputs.get("in") if "in" in inputs else (inputs.get("value") if "value" in inputs else params.get("message", "Hello, World!"))
4361
- return {"out": msg, "result": msg, "val": msg, "value": msg, "printed_string": str(msg), "then": True}
4362
-
4363
- def _exec_cat_variables(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4364
- val = inputs.get("in") if "in" in inputs else params.get("value", 10)
4365
- return {"out": val, "out_val": val, "val": val, "value": val, "result": val, "then": True}
4366
-
4367
- def _exec_cat_data_types(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4368
- items = inputs.get("items") or [1, 2, 3]
4369
- return {"out": items, "collection": items, "result": items, "then": True}
4370
-
4371
- def _exec_cat_operators(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4372
- a = inputs.get("a", params.get("a", 5))
4373
- b = inputs.get("b", params.get("b", 3))
4374
- op = params.get("operator", "+")
4375
- try:
4376
- if op == "+": res = a + b
4377
- elif op == "-": res = a - b
4378
- elif op == "*": res = a * b
4379
- elif op == "/": res = a / b if b != 0 else 0
4380
- elif op == "==": res = (a == b)
4381
- elif op == "!=": res = (a != b)
4382
- elif op == ">": res = (a > b)
4383
- elif op == "<": res = (a < b)
4384
- else: res = a + b
4385
- except Exception:
4386
- res = a
4387
- return {"out": res, "result": res, "then": True}
4388
-
4389
- def _exec_cat_math(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4390
- x = float(inputs.get("x", params.get("x", 49)))
4391
- fn = params.get("func", "sqrt")
4392
- if fn == "sqrt": res = math.sqrt(x) if x >= 0 else 0.0
4393
- elif fn == "round": res = float(round(x))
4394
- elif fn == "abs": res = float(abs(x))
4395
- else: res = math.sqrt(x) if x >= 0 else 0.0
4396
- return {"out": res, "result": res, "then": True}
4397
-
4398
- def _exec_cat_control_flow(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4399
- cond = bool(inputs.get("condition", params.get("condition", True)))
4400
- return {"then": cond, "else": not cond, "out": cond, "result": cond}
4401
-
4402
- def _exec_cat_functions(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4403
- args = inputs.get("args", "toy_output")
4404
- return {"out": f"make_toy({args})", "result": f"make_toy({args})", "then": True}
4405
-
4406
- def _exec_cat_strings_collections(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4407
- text = str(inputs.get("text", params.get("text", "Hello World")))
4408
- op = params.get("operation", "upper")
4409
- if op == "upper": res = text.upper()
4410
- elif op == "lower": res = text.lower()
4411
- elif op == "len": res = len(text)
4412
- else: res = text.upper()
4413
- return {"out": res, "result": res, "then": True}
4414
-
4415
- def _exec_cat_oop(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4416
- cname = params.get("class_name", "House")
4417
- res = f"<{cname} instance>"
4418
- return {"out": res, "instance": res, "result": res, "then": True}
4419
-
4420
- def _exec_cat_files(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4421
- path = params.get("file_path", "data.txt")
4422
- res = f"Sample file content of {path}"
4423
- return {"out": res, "content": res, "result": res, "then": True}
4424
-
4425
- def _exec_cat_modules(inputs: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]:
4426
- mod = params.get("module_name", "math")
4427
- return {"out": f"<module '{mod}'>", "module": mod, "result": mod, "then": True}
4428
-
4429
- _cat_definitions = [
4430
- (
4431
- NodeDefinition(
4432
- type="fundamentals.essentials",
4433
- label="Essentials",
4434
- category="Fundamentals",
4435
- version="1.0.0",
4436
- description="Start flag - Start, ask questions and show answers.",
4437
- icon="cat_essentials",
4438
- inputs=[PortDefinition(id="in", name="In", type="any", required=False)],
4439
- outputs=[PortDefinition(id="out", name="Output", type="any", required=True)],
4440
- parameters=[
4441
- ParameterDefinition(id="message", name="Message / Prompt", type=ParameterType.STRING, default="Hello, World!"),
4442
- ParameterDefinition(id="action", name="Action", type=ParameterType.STRING, default="print"),
4443
- ],
4444
- docs=DocumentationMetadata(summary="Start flag - Start, ask questions and show answers.", description="Start flag initiates execution.", doc_url="https://docs.python.org/3/"),
4445
- ),
4446
- _exec_cat_essentials,
4447
- "cat_essentials",
4448
- ),
4449
- (
4450
- NodeDefinition(
4451
- type="fundamentals.variables",
4452
- label="Variables & Constants",
4453
- category="Fundamentals",
4454
- version="1.0.0",
4455
- description="Storage box - Keep information inside boxes.",
4456
- icon="cat_variables",
4457
- inputs=[PortDefinition(id="in", name="Value In", type="any", required=False)],
4458
- outputs=[PortDefinition(id="out", name="Variable Value", type="any", required=True)],
4459
- parameters=[
4460
- ParameterDefinition(id="var_name", name="Variable Name", type=ParameterType.STRING, default="my_var"),
4461
- ParameterDefinition(id="value", name="Value", type=ParameterType.NUMBER, default=10),
4462
- ],
4463
- docs=DocumentationMetadata(summary="Storage box - Keep information inside boxes.", description="Stores data.", doc_url="https://docs.python.org/3/"),
4464
- ),
4465
- _exec_cat_variables,
4466
- "cat_variables",
4467
- ),
4468
- (
4469
- NodeDefinition(
4470
- type="fundamentals.data_types",
4471
- label="Data Types & Collections",
4472
- category="Fundamentals",
4473
- version="1.0.0",
4474
- description="Organizer box - Arrange information into groups.",
4475
- icon="cat_data_types",
4476
- inputs=[PortDefinition(id="items", name="Items", type="any", required=False)],
4477
- outputs=[PortDefinition(id="out", name="Collection", type="any", required=True)],
4478
- parameters=[
4479
- ParameterDefinition(id="data_type", name="Group Type", type=ParameterType.STRING, default="list"),
4480
- ],
4481
- docs=DocumentationMetadata(summary="Organizer box - Arrange information into groups.", description="Holds multiple items.", doc_url="https://docs.python.org/3/"),
4482
- ),
4483
- _exec_cat_data_types,
4484
- "cat_data_types",
4485
- ),
4486
- (
4487
- NodeDefinition(
4488
- type="fundamentals.operators",
4489
- label="Operators & Logic",
4490
- category="Fundamentals",
4491
- version="1.0.0",
4492
- description="Balance scale - Calculate, compare and make logical choices.",
4493
- icon="cat_operators",
4494
- inputs=[
4495
- PortDefinition(id="a", name="Left (A)", type="any", required=False, default_value=5),
4496
- PortDefinition(id="b", name="Right (B)", type="any", required=False, default_value=3)
4497
- ],
4498
- outputs=[PortDefinition(id="out", name="Result", type="any", required=True)],
4499
- parameters=[
4500
- ParameterDefinition(id="operator", name="Operator", type=ParameterType.STRING, default="+"),
4501
- ],
4502
- docs=DocumentationMetadata(summary="Balance scale - Calculate, compare and make logical choices.", description="Calculates & compares.", doc_url="https://docs.python.org/3/"),
4503
- ),
4504
- _exec_cat_operators,
4505
- "cat_operators",
4506
- ),
4507
- (
4508
- NodeDefinition(
4509
- type="fundamentals.math",
4510
- label="Mathematics",
4511
- category="Fundamentals",
4512
- version="1.0.0",
4513
- description="Calculator - Work with numbers and calculations.",
4514
- icon="cat_math",
4515
- inputs=[PortDefinition(id="x", name="Number (X)", type="float", required=False, default_value=49.0)],
4516
- outputs=[PortDefinition(id="out", name="Result", type="float", required=True)],
4517
- parameters=[
4518
- ParameterDefinition(id="func", name="Math Function", type=ParameterType.STRING, default="sqrt"),
4519
- ],
4520
- docs=DocumentationMetadata(summary="Calculator - Work with numbers and calculations.", description="Math calculations.", doc_url="https://docs.python.org/3/"),
4521
- ),
4522
- _exec_cat_math,
4523
- "cat_math",
4524
- ),
4525
- (
4526
- NodeDefinition(
4527
- type="fundamentals.control_flow",
4528
- label="Control Flow",
4529
- category="Fundamentals",
4530
- version="1.0.0",
4531
- description="Road junction - Choose a path and repeat actions.",
4532
- icon="cat_control_flow",
4533
- inputs=[PortDefinition(id="condition", name="Condition", type="bool", required=False, default_value=True)],
4534
- outputs=[
4535
- PortDefinition(id="then", name="If True", type="any", required=True),
4536
- PortDefinition(id="else", name="If False", type="any", required=True),
4537
- PortDefinition(id="out", name="Result", type="any", required=True)
4538
- ],
4539
- parameters=[
4540
- ParameterDefinition(id="mode", name="Flow Mode", type=ParameterType.STRING, default="branch"),
4541
- ],
4542
- docs=DocumentationMetadata(summary="Road junction - Choose a path and repeat actions.", description="Branching decisions.", doc_url="https://docs.python.org/3/"),
4543
- ),
4544
- _exec_cat_control_flow,
4545
- "cat_control_flow",
4546
- ),
4547
- (
4548
- NodeDefinition(
4549
- type="fundamentals.functions",
4550
- label="Functions",
4551
- category="Fundamentals",
4552
- version="1.0.0",
4553
- description="Toy machine - Create actions and use them again.",
4554
- icon="cat_functions",
4555
- inputs=[PortDefinition(id="args", name="Arguments", type="any", required=False)],
4556
- outputs=[PortDefinition(id="out", name="Return Value", type="any", required=True)],
4557
- parameters=[
4558
- ParameterDefinition(id="func_name", name="Machine Name", type=ParameterType.STRING, default="make_toy"),
4559
- ],
4560
- docs=DocumentationMetadata(summary="Toy machine - Create actions and use them again.", description="Reusable function.", doc_url="https://docs.python.org/3/"),
4561
- ),
4562
- _exec_cat_functions,
4563
- "cat_functions",
4564
- ),
4565
- (
4566
- NodeDefinition(
4567
- type="fundamentals.strings_collections",
4568
- label="Strings & Collection Operations",
4569
- category="Fundamentals",
4570
- version="1.0.0",
4571
- description="Scissors and letters - Cut, join, change and select information.",
4572
- icon="cat_strings_collections",
4573
- inputs=[PortDefinition(id="text", name="Text / String", type="any", required=False, default_value="Hello World")],
4574
- outputs=[PortDefinition(id="out", name="Result", type="any", required=True)],
4575
- parameters=[
4576
- ParameterDefinition(id="operation", name="Operation", type=ParameterType.STRING, default="upper"),
4577
- ],
4578
- docs=DocumentationMetadata(summary="Scissors and letters - Cut, join, change and select information.", description="String transforms.", doc_url="https://docs.python.org/3/"),
4579
- ),
4580
- _exec_cat_strings_collections,
4581
- "cat_strings_collections",
4582
- ),
4583
- (
4584
- NodeDefinition(
4585
- type="fundamentals.oop",
4586
- label="Object-Oriented Programming (OOP)",
4587
- category="Fundamentals",
4588
- version="1.0.0",
4589
- description="Blueprint and house - Design plans and build objects.",
4590
- icon="cat_oop",
4591
- inputs=[PortDefinition(id="params", name="Params", type="any", required=False)],
4592
- outputs=[PortDefinition(id="out", name="Instance", type="any", required=True)],
4593
- parameters=[
4594
- ParameterDefinition(id="class_name", name="Blueprint Name", type=ParameterType.STRING, default="House"),
4595
- ],
4596
- docs=DocumentationMetadata(summary="Blueprint and house - Design plans and build objects.", description="Classes & objects.", doc_url="https://docs.python.org/3/"),
4597
- ),
4598
- _exec_cat_oop,
4599
- "cat_oop",
4600
- ),
4601
- (
4602
- NodeDefinition(
4603
- type="fundamentals.files",
4604
- label="Files & Data Interchange",
4605
- category="Fundamentals",
4606
- version="1.0.0",
4607
- description="Notebook and parcel - Open, save, pack and unpack information.",
4608
- icon="cat_files",
4609
- inputs=[PortDefinition(id="in", name="Data In", type="any", required=False)],
4610
- outputs=[PortDefinition(id="out", name="Content", type="any", required=True)],
4611
- parameters=[
4612
- ParameterDefinition(id="file_path", name="Notebook File", type=ParameterType.STRING, default="data.txt"),
4613
- ],
4614
- docs=DocumentationMetadata(summary="Notebook and parcel - Open, save, pack and unpack information.", description="File notes & data.", doc_url="https://docs.python.org/3/"),
4615
- ),
4616
- _exec_cat_files,
4617
- "cat_files",
4618
- ),
4619
- (
4620
- NodeDefinition(
4621
- type="fundamentals.modules",
4622
- label="Modules & Imports",
4623
- category="Fundamentals",
4624
- version="1.0.0",
4625
- description="Toolbox - Bring in tools that help your program.",
4626
- icon="cat_modules",
4627
- inputs=[],
4628
- outputs=[PortDefinition(id="out", name="Tool", type="any", required=True)],
4629
- parameters=[
4630
- ParameterDefinition(id="module_name", name="Tool Module", type=ParameterType.STRING, default="math"),
4631
- ],
4632
- docs=DocumentationMetadata(summary="Toolbox - Bring in tools that help your program.", description="Toolbox modules.", doc_url="https://docs.python.org/3/"),
4633
- ),
4634
- _exec_cat_modules,
4635
- "cat_modules",
4636
- ),
4637
- ]
4638
-
4639
- for node_def, exec_fn, alias_name in _cat_definitions:
4640
- default_registry.register(node_def, executor=exec_fn)
4641
- default_registry._schemas[alias_name] = node_def
4642
- default_registry._executors[alias_name] = exec_fn
 
4348
  )
4349
 
4350
 
4351
+ # =============================================================================
4352
+ # CANONICAL NODE REGISTRY SPECIFICATION & METRICS (SSOT)
4353
+ # =============================================================================
4354
 
4355
+ CANONICAL_NODE_TYPES: List[str] = sorted(list(default_registry._schemas.keys()))
4356
+ CANONICAL_NODE_COUNT: int = len(CANONICAL_NODE_TYPES)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tests/test_complete_node_validation_matrix.py CHANGED
@@ -20,6 +20,7 @@ from language_core.node_schema import (
20
  NodeExecutionStatus,
21
  PortDefinition,
22
  ParameterDefinition,
 
23
  )
24
  from lambdas.codegen_handler import generate_code_logic
25
  from lambdas.validate_handler import validate_workflow_protocol_logic
@@ -293,7 +294,7 @@ def test_registry_contains_all_expected_nodes():
293
  all_registered = default_registry.list_all()
294
  reg_types = {n.type for n in all_registered}
295
 
296
- assert len(reg_types) >= 47, f"Expected at least 47 schemas, got {len(reg_types)}"
297
 
298
  for expected_type in NODE_TEST_FIXTURES.keys():
299
  assert expected_type in reg_types, f"Missing node schema in registry: {expected_type}"
 
20
  NodeExecutionStatus,
21
  PortDefinition,
22
  ParameterDefinition,
23
+ CANONICAL_NODE_COUNT,
24
  )
25
  from lambdas.codegen_handler import generate_code_logic
26
  from lambdas.validate_handler import validate_workflow_protocol_logic
 
294
  all_registered = default_registry.list_all()
295
  reg_types = {n.type for n in all_registered}
296
 
297
+ assert len(reg_types) >= CANONICAL_NODE_COUNT, f"Expected at least 47 schemas, got {len(reg_types)}"
298
 
299
  for expected_type in NODE_TEST_FIXTURES.keys():
300
  assert expected_type in reg_types, f"Missing node schema in registry: {expected_type}"
tests/test_phase13_adversarial_workflows.py CHANGED
@@ -43,6 +43,7 @@ from language_core.node_schema import (
43
  default_registry,
44
  resolve_sandboxed_path,
45
  MAX_FILE_BYTES_QUOTA,
 
46
  )
47
  import language_core.node_schema as ns_module
48
  from language_core.workflow_executor import (
@@ -458,7 +459,7 @@ def test_guarded_agent_nodes_fail_closed():
458
  def test_all_47_nodes_registered_and_executable():
459
  """Verify all 47 canonical nodes have valid schemas and executors."""
460
  nodes = sorted(default_registry._schemas.keys())
461
- assert len(nodes) == 47, f"Expected 47 canonical registered nodes, got {len(nodes)}"
462
 
463
  for node_type in nodes:
464
  assert default_registry.has(node_type), f"Node '{node_type}' missing schema definition"
 
43
  default_registry,
44
  resolve_sandboxed_path,
45
  MAX_FILE_BYTES_QUOTA,
46
+ CANONICAL_NODE_COUNT,
47
  )
48
  import language_core.node_schema as ns_module
49
  from language_core.workflow_executor import (
 
459
  def test_all_47_nodes_registered_and_executable():
460
  """Verify all 47 canonical nodes have valid schemas and executors."""
461
  nodes = sorted(default_registry._schemas.keys())
462
+ assert len(nodes) == CANONICAL_NODE_COUNT, f"Expected 47 canonical registered nodes, got {len(nodes)}"
463
 
464
  for node_type in nodes:
465
  assert default_registry.has(node_type), f"Node '{node_type}' missing schema definition"
tests/test_phase14_release_hardening.py CHANGED
@@ -41,6 +41,7 @@ from language_core.node_schema import (
41
  default_registry,
42
  resolve_sandboxed_path,
43
  MAX_FILE_BYTES_QUOTA,
 
44
  )
45
  from language_core.workflow_executor import execute_workflow_graph
46
  from lambdas.codegen_handler import generate_code_logic
@@ -348,7 +349,7 @@ CANONICAL_NODE_TEST_SUITE = {
348
  def test_registry_contains_exactly_47_canonical_nodes():
349
  """Verify registry contains exactly the 47 specified canonical nodes."""
350
  canonical_types = set(default_registry._schemas.keys())
351
- assert len(canonical_types) == 47, f"Expected 47 registered nodes, got {len(canonical_types)}"
352
  for node_type in CANONICAL_NODE_TEST_SUITE:
353
  assert node_type in canonical_types, f"Node '{node_type}' missing from registry"
354
 
 
41
  default_registry,
42
  resolve_sandboxed_path,
43
  MAX_FILE_BYTES_QUOTA,
44
+ CANONICAL_NODE_COUNT,
45
  )
46
  from language_core.workflow_executor import execute_workflow_graph
47
  from lambdas.codegen_handler import generate_code_logic
 
349
  def test_registry_contains_exactly_47_canonical_nodes():
350
  """Verify registry contains exactly the 47 specified canonical nodes."""
351
  canonical_types = set(default_registry._schemas.keys())
352
+ assert len(canonical_types) == CANONICAL_NODE_COUNT, f"Expected 47 registered nodes, got {len(canonical_types)}"
353
  for node_type in CANONICAL_NODE_TEST_SUITE:
354
  assert node_type in canonical_types, f"Node '{node_type}' missing from registry"
355