|
| 1 | +"""Integration tests for retainer context-specific args/flags/axis values.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from tests.conftest import MudylaRunner |
| 6 | + |
| 7 | + |
| 8 | +@pytest.mark.integration |
| 9 | +class TestRetainerContext: |
| 10 | + """Test that retainers receive correct context-specific values.""" |
| 11 | + |
| 12 | + def test_retainer_receives_context_specific_args_flags_axis( |
| 13 | + self, mdl: MudylaRunner, clean_test_output |
| 14 | + ): |
| 15 | + """Test retainer receives context-specific args, flags, and axis values. |
| 16 | +
|
| 17 | + This test runs three :all goals with different configurations: |
| 18 | + 1. --test-flag-global --message-global="God is in his heaven" |
| 19 | + 2. --test-flag-local --message-local="Thanks for the fish" |
| 20 | + 3. --ml="short-arg" (alias for --message-local) |
| 21 | +
|
| 22 | + Each retainer should see its context-specific values, not just global ones. |
| 23 | + """ |
| 24 | + result = mdl.run_success([ |
| 25 | + "--defs", "./extended-tests/*", |
| 26 | + "--verbose", |
| 27 | + "--test-flag-global", |
| 28 | + "--message-global=God is in his heaven", |
| 29 | + ":all", |
| 30 | + "--test-flag-local", |
| 31 | + "--message-local=Thanks for the fish", |
| 32 | + ":all", |
| 33 | + "--ml=short-arg", |
| 34 | + ":all", |
| 35 | + ]) |
| 36 | + |
| 37 | + output = result.stdout + result.stderr |
| 38 | + |
| 39 | + # Verify execution completed successfully |
| 40 | + mdl.assert_in_output(result, "Execution completed successfully") |
| 41 | + |
| 42 | + # Verify there are multiple retainer executions with different contexts |
| 43 | + assert output.count("#soft-provider ran in") >= 3, ( |
| 44 | + "Expected at least 3 retainer executions for different contexts" |
| 45 | + ) |
| 46 | + |
| 47 | + # Verify retainer with --test-flag-local sees the flag |
| 48 | + # This context should have Local flag: 1 |
| 49 | + assert "Local flag: 1" in output, ( |
| 50 | + "Expected retainer to see Local flag: 1 for context with --test-flag-local" |
| 51 | + ) |
| 52 | + |
| 53 | + # Verify retainer with --message-local="Thanks for the fish" sees the arg |
| 54 | + assert "Local arg: Thanks for the fish" in output, ( |
| 55 | + "Expected retainer to see 'Thanks for the fish' for context with --message-local" |
| 56 | + ) |
| 57 | + |
| 58 | + # Verify retainer with --ml="short-arg" (alias) sees the resolved arg |
| 59 | + assert "Local arg: short-arg" in output, ( |
| 60 | + "Expected retainer to see 'short-arg' for context with --ml alias" |
| 61 | + ) |
| 62 | + |
| 63 | + # Verify global arg is visible to all retainers |
| 64 | + assert output.count("Global arg: God is in his heaven") >= 3, ( |
| 65 | + "Expected all retainers to see the global arg" |
| 66 | + ) |
| 67 | + |
| 68 | + # Verify axis value is visible to retainers |
| 69 | + assert "Axis value: value1" in output, ( |
| 70 | + "Expected retainer to see axis value" |
| 71 | + ) |
| 72 | + |
| 73 | + def test_argument_alias_resolution(self, mdl: MudylaRunner, clean_test_output): |
| 74 | + """Test that argument aliases are resolved correctly.""" |
| 75 | + result = mdl.run_success([ |
| 76 | + "--defs", "./extended-tests/*", |
| 77 | + "--verbose", |
| 78 | + "--test-flag-global", |
| 79 | + "--ml=alias-test-value", |
| 80 | + ":all", |
| 81 | + ]) |
| 82 | + |
| 83 | + output = result.stdout + result.stderr |
| 84 | + |
| 85 | + # Verify execution completed |
| 86 | + mdl.assert_in_output(result, "Execution completed successfully") |
| 87 | + |
| 88 | + # Verify the alias was resolved and the retainer sees the value |
| 89 | + assert "Local arg: alias-test-value" in output, ( |
| 90 | + "Expected --ml alias to resolve to message-local" |
| 91 | + ) |
| 92 | + |
| 93 | + def test_retainer_context_isolation(self, mdl: MudylaRunner, clean_test_output): |
| 94 | + """Test that different contexts don't leak values to each other.""" |
| 95 | + result = mdl.run_success([ |
| 96 | + "--defs", "./extended-tests/*", |
| 97 | + "--verbose", |
| 98 | + "--test-flag-global", |
| 99 | + ":all", |
| 100 | + "--test-flag-local", |
| 101 | + "--message-local=context-two-value", |
| 102 | + ":all", |
| 103 | + ]) |
| 104 | + |
| 105 | + output = result.stdout + result.stderr |
| 106 | + |
| 107 | + # Verify execution completed |
| 108 | + mdl.assert_in_output(result, "Execution completed successfully") |
| 109 | + |
| 110 | + # Find all retainer output blocks |
| 111 | + lines = output.split('\n') |
| 112 | + retainer_blocks = [] |
| 113 | + current_block = [] |
| 114 | + in_retainer = False |
| 115 | + |
| 116 | + for line in lines: |
| 117 | + if "#soft-provider ran in" in line: |
| 118 | + if current_block: |
| 119 | + retainer_blocks.append('\n'.join(current_block)) |
| 120 | + current_block = [line] |
| 121 | + in_retainer = True |
| 122 | + elif in_retainer: |
| 123 | + if line.strip().startswith("stdout:") or line.strip().startswith("stderr:"): |
| 124 | + current_block.append(line) |
| 125 | + elif line.strip() and not line.strip().startswith("stdout:") and not line.strip().startswith("stderr:"): |
| 126 | + in_retainer = False |
| 127 | + if current_block: |
| 128 | + retainer_blocks.append('\n'.join(current_block)) |
| 129 | + current_block = [] |
| 130 | + |
| 131 | + if current_block: |
| 132 | + retainer_blocks.append('\n'.join(current_block)) |
| 133 | + |
| 134 | + # Verify we have multiple retainer blocks |
| 135 | + assert len(retainer_blocks) >= 2, f"Expected at least 2 retainer blocks, got {len(retainer_blocks)}" |
| 136 | + |
| 137 | + # Verify that context-two-value appears in exactly one block |
| 138 | + blocks_with_context_two = [b for b in retainer_blocks if "context-two-value" in b] |
| 139 | + assert len(blocks_with_context_two) == 1, ( |
| 140 | + f"Expected 'context-two-value' in exactly one retainer block, " |
| 141 | + f"found in {len(blocks_with_context_two)}" |
| 142 | + ) |
| 143 | + |
| 144 | + # Verify that DEFAULT:BAWW (default) appears in at least one block |
| 145 | + blocks_with_default = [b for b in retainer_blocks if "DEFAULT:BAWW" in b] |
| 146 | + assert len(blocks_with_default) >= 1, ( |
| 147 | + "Expected at least one retainer to see the default value" |
| 148 | + ) |
0 commit comments