Coverage for src/invariant/params.py: 100.00%

1"""Parameter markers for explicit dependency and expression references.

2

3 This module provides two marker types for node parameters:

4- ref(dep): References an upstream dependency artifact directly

5- cel(expr): Evaluates a CEL expression against dependency artifacts

6"""

7

8 from dataclasses import dataclass

9

10

11@dataclass(frozen=True)

12 class ref:

13 """Reference to an upstream dependency artifact.

14

15 When used in node params, resolves to the ICacheable object from the

16 specified dependency. The dependency must be declared in the node's deps list.

17

18 Example:

19 Node(

20 op_name="poly:add",

21 params={"a": ref("p"), "b": ref("q")},

22 deps=["p", "q"],

23 )

24 """

25

26 dep: str

27

28

29@dataclass(frozen=True)

30 class cel:

31 """CEL expression to evaluate against dependency artifacts.

32

33 When used in node params, evaluates the CEL expression with dependency

34 artifacts exposed as variables. Returns the computed value (int, str,

35 Decimal, etc.).

36

37 Example:

38 Node(

39 op_name="gfx:render_svg",

40 params={"width": cel("decimal(background.width) * decimal('0.75')")},

41 deps=["background"],

42 )

43 """

44

45 expr: str