Skip to content

fix(restore-jupyter-cache): refuse values outside each input's accepted set, and an empty path (#236) - #268

Merged
mmcky merged 2 commits into
mainfrom
fix/236-restore-input-checks
Nov 6, 2026
Merged

mmcky merged 2 commits into
mainfrom
fix/236-restore-input-checks

Conversation

@mmcky

@mmcky mmcky commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

restore-jupyter-cache checked none of its enumerated inputs (#236, finding L3 of the 2026-10-06 review). Its shell steps compare cache-type, save-cache and fail-on-miss exactly, but its if: conditions compare them case-insensitively, as GitHub's expressions compare strings. So a value that was nearly right half-worked, without a word. This PR makes the first step, Check inputs, which #265 added for key and path, also check these three on every call, a custom key's included, and refuse an empty path, before anything is restored or registered for saving.

Input Before After
save-cache: 'True' The if: registered the job-end save, but the key step read it as false and left the run ID off the key. The first run saved under the read-only key; every later run matched it exactly, saved nothing, and the pull request's cache stopped updating fails in Check inputs
cache-type: exec, or any other typo Restored the whole build cache, and the status report printed neither type's section fails
fail-on-miss: yes Treated as false fails
path: '' With cache-type: execution, restored into /.jupyter_cache. With build, failed inside actions/cache ("Input required and not supplied: path") fails, for both types
build, execution, 'true', 'false', or an unquoted true or True as documented unchanged

Each error names the input and the value, escaped as a workflow command's data, as #265's line-break check does: for example save-cache must be 'true' or 'false', got 'True'. Every bad input is reported in one run, not only the first.

Changes

File Change
restore-jupyter-cache/action.yml Check inputs reads cache-type, save-cache and fail-on-miss from env: and refuses anything outside build/execution and 'true'/'false'. It also refuses an empty path. The escaping is now one helper, shown, used by every message. Its comment says why: the if: comparisons are case-insensitive. The descriptions of cache-type, path, save-cache and fail-on-miss say what is accepted, and that anything else fails the run.
.github/workflows/test-actions.yml unit-input-values, beside unit-line-break, and in harness-summary's needs: beside it. See below.
docs/user/actions/restore-jupyter-cache.md The Inputs table is regenerated. Two Troubleshooting entries, one for the three value errors and one for the empty path.
docs/dev/TESTING.md The restore-jupyter-cache row lists unit-input-values. Same arrangement as #265's edit.
CHANGELOG.md One entry under [Unreleased], ### Changed, without the ⚠️ BREAKING marker. See below.

unit-input-values. Modelled on bjc-builders-parse: a control that must pass (build, read-only, a salted miss), then one step per refused value, each differing from the control in one input:

The job asserts each outcome, that cache-hit stays 'false', and that neither _build nor /.jupyter_cache exists. 'True' is quoted in the job, because YAML reads an unquoted True as the boolean.

Callers, and the ⚠️ BREAKING question

This can fail a caller's workflow that works today, if it passes one of these values. Before writing the entry, I looked for such callers:

  • Code search, across the QuantEcon org, for quantecon/actions/restore-jupyter-cache, restore-jupyter-cache, save-cache and fail-on-miss.
  • Every workflow of the two repositories PLAN lists as running the full chain.
Caller Inputs passed
lecture-dp ci.yml, publish.yml none: the defaults
test-actions-lecture-intro (canary) ci.yml cache-type: 'build', source-dir: 'lectures', save-cache: 'true'
templates/ci.yml cache-type: 'build', with save-cache: 'true' and fail-on-miss: 'false' as comments
the manual's examples 'true', execution and the defaults

Neither repository's cache.yml, nor the canary's publish.yml, uses the action. No other consumer in PLAN's table does either, and nothing passes path. So no known caller passes a refused value.

The runner reads workflow YAML with the YAML 1.2 core schema (MatchBoolean in actions/runner's YamlObjectReader.cs). So true, True and TRUE, unquoted, are booleans, and the action receives 'true'; the same goes for false. Only a quoted 'True', or a value such as yes, on or 1, which YAML 1.2 does not treat as a boolean, reaches the action as written and is refused.

The maintainer has decided: no marker, under Changed. No known caller is affected, and every refused value either half-worked or did something other than what it said.

What I checked, and how

The issue's premises, on ea01c01. #265 moved these values into env: without changing what they do, so #236's descriptions still hold, at new line numbers:

  • The key step tests [ "$SAVE_CACHE" = "true" ], and the save step if: inputs.save-cache == 'true'.
  • cache-type is compared only to execution in the key and path steps.
  • The status report tests execution and build separately.

Its pointer to deploy-cloudflare/action.yml:120-123 is stale. That action now validates in a fail() helper from line 114, with visibility beside the deprecated require-access, and the messages here follow its wording.

The new job fails on main. I pushed the harness commit on its own first, da0caa0, on top of ea01c01, and dispatched the harness on it. unit-input-values failed: the control passed, and all five refused cases passed too. In the log:

  • exec restored with path: _build and the report said Cache Type: exec.
  • Both save-cache: 'True' cases ran "Register job-end cache save".
  • fail-on-miss: 'yes' carried on.
  • The empty path restored with path: /.jupyter_cache.

This PR's own run is the same job on the fixed action.

Check inputs, locally. I ran it in isolation under bash 3.2, with each case's values in env:. In 16 cases, it:

  • passes the defaults, every accepted combination, and a custom key with a path holding a space and a $;
  • refuses exec, Build, an empty cache-type, 'True' with and without a custom key, yes, an empty fail-on-miss, an empty path for each type, a line break in cache-type, key or path, and a value with spaces and a glob;
  • writes the exact expected ::error:: lines, and nothing to $GITHUB_OUTPUT, with %, CR and LF escaped;
  • reports all five problems when every input is wrong at once.

The first run of these tests caught a bug in my own escaping: inside double quotes, bash 3.2 kept the single quotes of "${s//$'\n'/'%0A'}" literally. Each substitution is now a plain assignment, as in build-lectures.

Nothing else changed. The same comparison as #265's, main's steps against this branch's for valid inputs, still gives 56 cases and 0 differences: no step other than Check inputs changed.

Lint. actionlint run as the gate runs it, over .github/workflows/ with shellcheck 0.11.0 at its default severity, reports nothing. shellcheck finds nothing in restore-jupyter-cache's run: blocks, and no run: text has a ${{, which lint's #266 will enforce. python3 scripts/generate-docs.py --check --check-examples --actionlint … passes.

What to watch after merge

This changes what restore-jupyter-cache accepts, so it ships in a staged release (CONTRIBUTING, Staged Releases). In a canary branch with every quantecon/actions/...@v0 changed to the staged tag:

  1. ci.yml on a canary pull request, as it is: cache-type: 'build', save-cache: 'true'. The restore finds the cache, and the job-end save happens, with the run ID in its key.
  2. The same run, with save-cache: 'True' (quoted). The job fails at restore-jupyter-cache's first step, with save-cache must be 'true' or 'false', got 'True', and nothing is restored.
  3. publish.yml on a test tag is unchanged, since it doesn't use the action, but a run confirms the chain.

#160

This makes #160 safer. If cache-type: execution becomes the templates' default to avoid stale pages, a mistyped value can no longer bring the whole build cache back without a word. #160's decision itself is not in this PR.

Not in this PR

Closes #236

🤖 Generated with Claude Code

https://claude.ai/code/session_01WT8bMavcZNRwucF4FkV3fo

mmcky and others added 2 commits November 6, 2026 21:36
…ed set (#236)

unit-input-values runs a control that must pass, then one case per
refused value, each differing from the control in one input: cache-type
'exec', save-cache 'True' with the generated keys and with a custom key,
fail-on-miss 'yes', and an empty path with the execution cache.

On its own, against restore-jupyter-cache as it is before the next
commit, every refused case passes, so the job fails.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMavcZNRwucF4FkV3fo
…ed set, and an empty path (#236)

The first step, Check inputs, now also reads cache-type, save-cache and
fail-on-miss on every call, a custom key's included, and fails with an
::error:: on anything but build or execution and 'true' or 'false', and
on an empty path. The steps compared these values exactly but their if:
conditions case-insensitively, so save-cache 'True' registered the
job-end save under the read-only key and the cache stopped updating
without a word, cache-type 'exec' restored the build cache, and
fail-on-miss 'yes' was false. An empty path put the execution cache in
/.jupyter_cache.

Each input's description names its accepted values, and the manual's
Troubleshooting lists the new errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01WT8bMavcZNRwucF4FkV3fo
Copilot AI balanced review requested due to automatic review settings November 6, 2026 10:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟢 Approval recommended

The change adds strict upfront input validation (including rejecting empty paths) and includes a dedicated CI harness plus updated docs/changelog, with no unresolved issues noted in the review evidence.

No open issues 🎉

What changed in this PR

This pull request hardens the restore-jupyter-cache composite action by validating enumerated inputs up front (and rejecting an empty path) so near-miss values that previously “half-worked” now fail fast before any cache restore/save side effects occur.

Changes:

  • Extend restore-jupyter-cache’s Check inputs step to strictly validate cache-type, save-cache, and fail-on-miss, and to refuse an empty path, with workflow-command-safe escaping in error messages.
  • Add a harness CI job (unit-input-values) to prove invalid inputs fail early and do not restore/create cache artifacts.
  • Regenerate/update user docs, developer testing docs, and the changelog to reflect the stricter accepted-value contract.

This pull request is ready to be approved.

File Summary
restore-jupyter-cache/​action.yml Adds strict early validation for enumerated inputs and empty path, centralizing safe value rendering for error messages.
docs/​user/​actions/​restore-jupyter-cache.md Regenerates the inputs table and documents troubleshooting for invalid values and empty path.
docs/​dev/​TESTING.md Updates the testing matrix to include the new unit-input-values coverage for restore-jupyter-cache.
CHANGELOG.md Records the behavior change under [Unreleased] → Changed.
.github/​workflows/​test-actions.yml Introduces the unit-input-values harness job and wires it into the workflow dependencies/summary.

Review effort: Balanced

@mmcky
mmcky merged commit 8c12d4f into main Nov 6, 2026
55 checks passed
@mmcky
mmcky deleted the fix/236-restore-input-checks branch November 6, 2026 10:45
mmcky added a commit that referenced this pull request Nov 7, 2026
Move [Unreleased] into a dated 0.16.0 section, carrying waves 3 and 4 of
#246: every value reaches a run: script through env: (#228), each action
refuses a line break in a single-value input and escapes what it prints
(#267), restore-jupyter-cache refuses unknown values (#236) and removes
the restored HTML after a build-cache restore (#160), html-copy-notebooks
keeps each notebook's path (#217), build-jupyter-cache's failure alert
lands on an issue and its repro commands build into ./_build (#229, #238),
and deploy-cloudflare's require-access is removed, the release's one
breaking change (#177). CI gains actionlint and shellcheck (#100).

PLAN drops #236, which #268 closed, and says #18 is parked until a
repository passes environment-update. The release changes what every
action does, so it is staged on the canary before v0 moves.


Claude-Session: https://claude.ai/code/session_01WT8bMbMmeUUEj8EjiweB6S

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

restore-jupyter-cache: a mis-cased save-cache value silently stops the cache updating, and unknown input values are accepted

2 participants