@@ -59,5 +59,57 @@ def test_job_level_uses_ignores_comments_and_step_payloads(self) -> None:
5959 self .assertEqual (contract ._job_level_uses_values (path ), [])
6060
6161
62+ def test_block_scalar_cannot_impersonate_checkout (self ) -> None :
63+ path = self .fixture (
64+ "jobs:\n test:\n runs-on: ubuntu-latest\n steps:\n "
65+ " - run: |\n "
66+ " uses: actions/checkout@deadbeef\n "
67+ " with:\n "
68+ f" ref: { contract .PR_HEAD_REF } \n "
69+ )
70+ self .assertEqual (contract ._checkout_ref_values (path ), [])
71+
72+ def test_required_merge_job_cannot_be_replaced_by_skipped_job (self ) -> None :
73+ path = self .fixture (
74+ "jobs:\n "
75+ " test:\n "
76+ " if: \${{ github.event_name == 'push' }}\n "
77+ " steps:\n "
78+ " - uses: actions/checkout@deadbeef\n "
79+ " with:\n persist-credentials: false\n "
80+ " test-head:\n "
81+ f" if: { contract .PR_ONLY_IF } \n "
82+ " steps:\n "
83+ " - uses: actions/checkout@deadbeef\n "
84+ f" with:\n ref: { contract .PR_HEAD_REF } \n "
85+ )
86+ old = contract .EVIDENCE_JOBS .get (path .name )
87+ contract .EVIDENCE_JOBS [path .name ] = ("test" , "test-head" )
88+ self .addCleanup (
89+ lambda : contract .EVIDENCE_JOBS .__setitem__ (path .name , old )
90+ if old is not None
91+ else contract .EVIDENCE_JOBS .pop (path .name , None )
92+ )
93+ errors = contract ._evidence_job_errors (path )
94+ self .assertTrue (any ("required job must not be conditional" in e for e in errors ))
95+
96+ def test_job_parser_binds_default_and_head_checkout_to_distinct_jobs (self ) -> None :
97+ path = self .fixture (
98+ "jobs:\n "
99+ " test:\n "
100+ " steps:\n "
101+ " - uses: actions/checkout@deadbeef\n "
102+ " with:\n persist-credentials: false\n "
103+ " test-head:\n "
104+ f" if: { contract .PR_ONLY_IF } \n "
105+ " steps:\n "
106+ " - uses: actions/checkout@deadbeef\n "
107+ f" with:\n ref: { contract .PR_HEAD_REF } \n "
108+ )
109+ specs = contract ._job_specs (path )
110+ self .assertEqual (specs ["test" ]["refs" ], [None ])
111+ self .assertEqual (specs ["test-head" ]["refs" ], [contract .PR_HEAD_REF ])
112+
113+
62114if __name__ == "__main__" :
63115 unittest .main ()
0 commit comments