Tests — cache cycle, URL building, error mapping, ZIP guards #118

Closed
opened 2026-08-29 03:29:00 +00:00 by david · 1 comment
Owner

Summary

The jest test suite for the Actions tooling: cache cycle (exists/missing/refresh), URL/query building for every filter, error mapping, and ZIP extraction guards — real fs on os.tmpdir() subdirs, mocked fetch only.

Background

Part of the Forgejo Actions tooling feature (tracking issue #111 — branch feature/issue-111/forgejo-actions-tools, commits issue-111: ...). Depends on the registration step (#117). Consolidates and completes the tests sketched in the earlier steps (#113 path math + I/O, #114 URLs/errors, #115 cache cycle, #116 ZIP guards, #117 registration) into the repo's jest setup. TDD convention in this extension: RED → GREEN → REFACTOR per task. Existing tests (tests/issues.test.ts, tests/pulls.test.ts, tests/index.test.ts) mock forgejoApiCall/fetch — follow the same pattern.

Implementation Details

  • New/updated files: tests/actionsCache.test.ts (pure path math; real-fs read/write in os.tmpdir() subdirs with teardown cleanup), tests/actions.test.ts (mock fetch), plus tests/index.test.ts additions for the 5 registered tools.
  • Coverage checklist:
    1. Cache cycle: exists → return without fetch; missing → fetch → write; refresh → re-fetch (assert fetch call counts).
    2. URL/query building for every filter (status/event arrays, ref, head_sha, run_number, workflow_id, page, limit) — assert exact query strings.
    3. Error mapping: 404 unknown run/job, empty/never-run job log, network failure → ApiError.
    4. ZIP: unzip a fixture archive → files land in the per-job cache namespace; zip-bomb guard rejects oversized entries (per-entry, total, entry-count).
    5. Registration: 5 tools with correct schema shape + success/error passthrough.
  • No test may hit the real network; everything goes through mocked fetch. fs usage must be confined to os.tmpdir() subdirs, cleaned up after.

Acceptance Criteria

  • npm test green in extensions/forgejo/ with the full suite (existing + new) — no coverage regression.
  • npm run check (tsc --noEmit) passes.
  • Every checklist item above has at least one passing test.
  • No test performs a real HTTP call or writes outside os.tmpdir().

Test Plan

  • cd extensions/forgejo && npm test -- --coverage and eyeball the new files' coverage.
  • npm run check.
### Summary The jest test suite for the Actions tooling: cache cycle (exists/missing/refresh), URL/query building for every filter, error mapping, and ZIP extraction guards — real fs on `os.tmpdir()` subdirs, mocked `fetch` only. ### Background Part of the Forgejo Actions tooling feature (tracking issue **#111** — branch `feature/issue-111/forgejo-actions-tools`, commits `issue-111: ...`). Depends on the registration step (**#117**). Consolidates and completes the tests sketched in the earlier steps (#113 path math + I/O, #114 URLs/errors, #115 cache cycle, #116 ZIP guards, #117 registration) into the repo's jest setup. TDD convention in this extension: RED → GREEN → REFACTOR per task. Existing tests (`tests/issues.test.ts`, `tests/pulls.test.ts`, `tests/index.test.ts`) mock `forgejoApiCall`/`fetch` — follow the same pattern. ### Implementation Details - New/updated files: `tests/actionsCache.test.ts` (pure path math; real-fs read/write in `os.tmpdir()` subdirs with teardown cleanup), `tests/actions.test.ts` (mock `fetch`), plus `tests/index.test.ts` additions for the 5 registered tools. - Coverage checklist: 1. Cache cycle: exists → return without fetch; missing → fetch → write; `refresh` → re-fetch (assert fetch call counts). 2. URL/query building for every filter (status/event arrays, ref, head_sha, run_number, workflow_id, page, limit) — assert exact query strings. 3. Error mapping: 404 unknown run/job, empty/never-run job log, network failure → `ApiError`. 4. ZIP: unzip a fixture archive → files land in the per-job cache namespace; zip-bomb guard rejects oversized entries (per-entry, total, entry-count). 5. Registration: 5 tools with correct schema shape + success/error passthrough. - No test may hit the real network; everything goes through mocked fetch. fs usage must be confined to `os.tmpdir()` subdirs, cleaned up after. ### Acceptance Criteria - [ ] `npm test` green in `extensions/forgejo/` with the full suite (existing + new) — no coverage regression. - [ ] `npm run check` (tsc --noEmit) passes. - [ ] Every checklist item above has at least one passing test. - [ ] No test performs a real HTTP call or writes outside `os.tmpdir()`. ### Test Plan - `cd extensions/forgejo && npm test -- --coverage` and eyeball the new files' coverage. - `npm run check`.
Author
Owner

Verified complete — closing.

  • npm test in extensions/forgejo/: 259 tests passed (11 suites), including the new tests/actions.test.ts and tests/actionsCache.test.ts.
  • npm run check (tsc --noEmit): clean.
  • All five checklist items covered: cache cycle (exists/missing/refresh with fetch-call assertions), URL/query building for every filter, error mapping (404 unknown run/job, empty log, never-run job, network failure → ApiError), ZIP guards (entry-count, per-entry size, total size, rollback), and registration of the 5 forgejo_action_* tools in tests/index.test.ts.

Note: this work landed as part of the tracking-issue commits (ee2b5ac "111: Tracking…" plus the #115/#116 commits) rather than a dedicated issue-118: PR, which is why the issue was left open.

Verified complete — closing. - `npm test` in `extensions/forgejo/`: **259 tests passed** (11 suites), including the new `tests/actions.test.ts` and `tests/actionsCache.test.ts`. - `npm run check` (tsc --noEmit): clean. - All five checklist items covered: cache cycle (exists/missing/refresh with fetch-call assertions), URL/query building for every filter, error mapping (404 unknown run/job, empty log, never-run job, network failure → ApiError), ZIP guards (entry-count, per-entry size, total size, rollback), and registration of the 5 `forgejo_action_*` tools in `tests/index.test.ts`. Note: this work landed as part of the tracking-issue commits (`ee2b5ac` "111: Tracking…" plus the #115/#116 commits) rather than a dedicated `issue-118:` PR, which is why the issue was left open.
david closed this issue 2026-09-18 05:58:34 +00:00
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
david/pi-extensions-and-skills#118
No description provided.