From 903f550d3cfa320f659b887d4f4d22eb8fd36985 Mon Sep 17 00:00:00 2001 From: mapxn <16299874+mapxn@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:46:47 +0800 Subject: [PATCH] chore: checkpoint mrpt0PxO_RmYYKcZfBqDB --- .github/scripts/test-deploy-checks.mjs | 44 +++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/.github/scripts/test-deploy-checks.mjs b/.github/scripts/test-deploy-checks.mjs index 8b8042d..882eb7f 100644 --- a/.github/scripts/test-deploy-checks.mjs +++ b/.github/scripts/test-deploy-checks.mjs @@ -71,6 +71,15 @@ const requiredKeys = (() => { const script = runBody(body) +// Optional-key names the step includes only when configured: `if [ -n "${NAME:-}" ]; then`. +const optionalKeys = (() => { + return script + .split('\n') + .map((line) => line.match(/if \[ -n "\$\{([A-Za-z0-9_]+):-\}" \]/)) + .filter(Boolean) + .map((match) => match[1]) +})() + const SECRET_VALUE = 'test-value-not-a-real-secret' const sandboxes = [] @@ -111,11 +120,36 @@ describe(`${STEP_NAME} step`, () => { ) }) - it('fail-closes on every secret it injects', () => { - assert.deepEqual( - [...requiredKeys].sort(), - Object.keys(declaredSecrets).sort(), - 'every injected secret must be validated, and every validated secret injected' + it('fail-closes on required secrets and conditionally writes optional secrets', () => { + // Every fail-closed (required) secret must come from the repository secret of the same name. + for (const name of requiredKeys) { + assert.ok( + Object.hasOwn(declaredSecrets, name), + `required secret ${name} must be injected from a repository secret of the same name` + ) + } + // Every injected secret is either fail-closed (required) or conditionally written (optional). + for (const name of Object.keys(declaredSecrets)) { + assert.ok( + requiredKeys.includes(name) || optionalKeys.includes(name), + `injected secret ${name} must be either fail-closed (required) or conditionally written (optional)` + ) + } + // Every optional secret must be injected and written through the `if [ -n ... ]` block, never fail-closed. + for (const name of optionalKeys) { + assert.ok( + Object.hasOwn(declaredSecrets, name), + `optional secret ${name} must be injected from a repository secret of the same name` + ) + assert.ok( + !requiredKeys.includes(name), + `optional secret ${name} must not be fail-closed in the required for loop` + ) + } + // WAKER_SIGNING_KEY stays optional: unset -> official Cron, truthy -> waker, `false` -> no schedule. + assert.ok( + optionalKeys.includes('WAKER_SIGNING_KEY'), + 'WAKER_SIGNING_KEY must be conditionally written, never fail-closed' ) })