src/actionsCache.ts — cache paths + cache-first read/write #113
Labels
No labels
bug
chore
documentation
enhancement
feature
ready
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
david/pi-extensions-and-skills#113
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
New module
src/actionsCache.tsproviding deterministic cache paths and cache-first read/write for downloaded job logs and run-log ZIPs, so repeated tool calls don't re-download.Background
Part of the Forgejo Actions tooling feature (tracking issue #111 — branch
feature/issue-111/forgejo-actions-tools, commitsissue-111: ...). Theforgejo_action_job_logandforgejo_action_run_logstools are cache-first: they must not hit the network when the computed cache path already exists (unlessrefreshis passed). This module is the pure, unit-testable core of that behavior — it must not importfetchor do any HTTP. It builds on the existing project structure (src/ + tests/, jest, ts-jest). Reuse the existingResulttypes fromsrc/errors.tswhere needed; do not reinvent error helpers.Implementation Details
cacheRoot(env?)):$FORGEJO_ACTIONS_CACHE_DIR(also used by tests to point at a temp dir)$XDG_CACHE_HOME/forgejo-actions(Unix) / platform-appropriate equivalent elsewhere~/.cache/forgejo-actions<root>/<owner>/<repo>/<run_id>/<job_id>[-attempt-<n>][-step-<s>].log— attempt/step are part of the key so historical attempts never collide.<root>/<owner>/<repo>/<run_id>/run.zipcachedLogPath({root, owner, repo, runId, jobId, attempt?, step?}) -> stringrunZipPath({root, owner, repo, runId}) -> stringreadCachedLog(path) -> string | null(null when missing/unreadable)writeLog(path, content)withmkdir -pof parent dirsany).Acceptance Criteria
cacheRoot()resolves$FORGEJO_ACTIONS_CACHE_DIR→$XDG_CACHE_HOME/forgejo-actions→~/.cache/forgejo-actionsin that priority, honoring an injected env for tests.cachedLogPath()embeds attempt/step in the key soattempt=2andattempt=3(and different steps) map to distinct paths; omitting attempt/step yields the base.logpath.runZipPath()returns<root>/<owner>/<repo>/<run_id>/run.zip.readCachedLog()returns file content when present andnullwhen absent.writeLog()creates parent directories (mkdir -p) and writes content.os.tmpdir()subdir (per the plan's 7.2/7.5 pattern).npm run checkpasses.Test Plan
cd extensions/forgejo && npm test— new tests intests/actionsCache.test.ts(path math is pure; I/O tests useos.tmpdir()subdirs, cleaned up in teardown).FORGEJO_ACTIONS_CACHE_DIR=/tmp/fjcache node -e "..."sanity-check the resolved root.pi-loop opened and merged a pull request for this issue: #125