test: add GitHub REST utils and respec size handler tests - #500
test: add GitHub REST utils and respec size handler tests#500marcoscaceres wants to merge 7 commits into
Conversation
4befb8e to
cbbfbc7
Compare
There was a problem hiding this comment.
Pull request overview
Adds/expands Jasmine coverage for GitHub REST pagination/SSRF validation and the routes/respec/size handlers, to improve regression protection around URL safety, pagination behavior, and size-report persistence/deduplication.
Changes:
- Adds a new test suite for
routes/respec/sizecovering auth, input validation, file writes, truncation, dedup buffer behavior, and GET headers/body. - Expands
github/lib/utils/resttests with additional cases for endpoint validation, pagination link handling, page limits, request headers, and HTTP errors.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/routes/respec/size.test.js | New tests for Respec size GET/PUT handlers including env setup, file persistence, and dedup buffer behavior. |
| tests/routes/github/lib/utils/rest.test.js | Expanded tests for GitHub REST request generator covering SSRF guard, pagination, error handling, and request headers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cbbfbc7 to
f5981a8
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
f5981a8 to
d0d4ac3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot Please address and fix any outstanding commo |
Fixed in ccffa9a. The last outstanding issue was the page-limit test silently triggering |
|
@copilot Can you review this and fix any issues that come up? |
|
@copilot Can you confirm all your feedback has been addressed? Please resolve the threads that have been addressed and fix anything outstanding. |
All feedback has been addressed. The final cleanup in 89e5652 removes the duplicate
Reviewed — found and fixed a leftover issue in |
| process.env.DATA_DIR = DATA_DIR; | ||
| process.env.RESPEC_GH_ACTION_SECRET = TEST_SECRET; |
There was a problem hiding this comment.
How about we use jasmine helpers and set all fake variables there?
There was a problem hiding this comment.
Then we won't need dynamic imports etc. likely.
There was a problem hiding this comment.
Done. Moved the fake env vars into tests/helpers/env.js: it now sets RESPEC_GH_ACTION_SECRET and an isolated throwaway DATA_DIR (a fresh mkdtemp dir, removed on exit) before any spec loads, so size.test.js and rest.test.js import statically — no more dynamic import or manual env save/restore.
One knock-on: the caniuse tests hardcoded os.tmpdir()/caniuse, which only matched the module's DATA_DIR while the helper defaulted DATA_DIR to os.tmpdir(). With the isolated temp dir they now write fixtures under process.env.DATA_DIR instead, which also clears up some stale-data flakiness those tests had.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sets DATA_DIR (isolated throwaway dir) and RESPEC_GH_ACTION_SECRET in tests/helpers/env.js so the size and rest test modules import statically instead of juggling env vars around a dynamic import.
The caniuse tests hardcoded os.tmpdir()/caniuse, which only matched the module's DATA_DIR back when the helper defaulted DATA_DIR to os.tmpdir(). Now that the helper uses an isolated temp DATA_DIR, point the fixtures at process.env.DATA_DIR so the module finds them. Also removes stale-data flakiness from a shared os.tmpdir()/caniuse.
89e5652 to
b89b8b9
Compare
Parameterize same-branch cases (SSRF-reject vectors, HTTP errors, validation 400s, auth 401s) and share helpers instead of repeating req/res boilerplate. Same coverage, ~60% fewer lines.
| // exits. | ||
| const dataDir = mkdtempSync(path.join(os.tmpdir(), "rws-test-")); | ||
| process.env.DATA_DIR = dataDir; | ||
| process.on("exit", () => rmSync(dataDir, { recursive: true, force: true })); |
There was a problem hiding this comment.
I think this should be removed, as we're creating tmp dir (which will get removed itself later, as its temporary), and if needed, we can inspect it locally after test run.
| const CANIUSE_DIR = path.join(os.tmpdir(), "caniuse"); | ||
| // The caniuse module reads from DATA_DIR, set to an isolated temp dir by | ||
| // tests/helpers/env.js. Write fixtures there so the module finds them. | ||
| const CANIUSE_DIR = path.join(process.env.DATA_DIR, "caniuse"); |
There was a problem hiding this comment.
We can use the env() helper we've, which will throw if env vvar is not set. Don't need this verbose comment then in each test.
| let n = 0; | ||
| globalThis.fetch = jasmine | ||
| .createSpy("fetch") | ||
| .and.callFake(() => Promise.resolve(++n === 1 ? page({ page: 1 }, { next: 2 }) : page({ page: 2 }))); |
Summary
Landing order: land before #501, which also edits
tests/routes/caniuse/lib/index.test.js— whichever merges second needs a rebase. Suggested batch order: #499, #500, #501, #497, #529, #511 (#424 independent).