feat: complete mock API layer implementation#432
feat: complete mock API layer implementation#432revaarathore11 wants to merge 1 commit intoelixir-cloud-aai:mainfrom
Conversation
|
@revaarathore11 is attempting to deploy a commit to the elixir-cloud-aai Team on Vercel. A member of the Team first needs to authorize it. |
Reviewer's GuideIntroduces a centralized mock-aware fetcher utility and refactors all remaining direct fetch usages in GA4GH/ELIXIR client providers and components to use it, wiring them to a structured mocks/ directory and documenting how to enable the mock API layer. Sequence diagram for API call with mock interception and fallbacksequenceDiagram
actor Dev as Developer
participant UI as WebComponent
participant Provider as RestProvider
participant Fetcher as fetcher
participant Mocks as MockFiles
participant API as LiveService
Dev->>UI: Load docs/app with VITE_USE_MOCK_API=true
UI->>Provider: getTool(id)
Provider->>Fetcher: fetcher(url, options, mockPath)
Fetcher->>Fetcher: Check env vars for mock flag
alt Mock enabled
Fetcher->>Mocks: fetch(/mocks/mockPath.json)
alt Mock file found (200 OK)
Mocks-->>Fetcher: Mock JSON response
Fetcher-->>Provider: Response (mock)
Provider-->>UI: Parsed data from mock
else Mock missing or error
Mocks-->>Fetcher: Error or non-OK
Fetcher->>Fetcher: Log warning, fall back
Fetcher->>API: fetch(url, options)
API-->>Fetcher: Live HTTP response
Fetcher-->>Provider: Response (live)
Provider-->>UI: Parsed data from live API
end
else Mock disabled
Fetcher->>API: fetch(url, options)
API-->>Fetcher: Live HTTP response
Fetcher-->>Provider: Response (live)
Provider-->>UI: Parsed data from live API
end
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues, and left some high level feedback:
- The mock-generation scripts under
scripts/use absolute, user-specific filesystem paths; consider switching to paths relative to the repo root or a configurable base directory so they can be run on other machines and CI. - The
fetcherutility logs toconsole.log/console.warnon every mocked or failed mock fetch; you may want to guard these behind a debug flag or environment check to avoid noisy logs in production environments.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The mock-generation scripts under `scripts/` use absolute, user-specific filesystem paths; consider switching to paths relative to the repo root or a configurable base directory so they can be run on other machines and CI.
- The `fetcher` utility logs to `console.log`/`console.warn` on every mocked or failed mock fetch; you may want to guard these behind a debug flag or environment check to avoid noisy logs in production environments.
## Individual Comments
### Comment 1
<location> `scripts/create_trs_mocks.js:4` </location>
<code_context>
+const fs = require('fs');
+const path = require('path');
+
+const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/elixir-trs-filer';
+
+const files = {
</code_context>
<issue_to_address>
**issue (bug_risk):** Using an absolute, user-specific path for `mockDir` makes this script non-portable.
To keep this usable in CI and for other developers, derive `mockDir` from the repo instead, e.g. `path.join(__dirname, '..', 'mocks', 'elixir-trs-filer')`, or read it from an environment variable. This also helps avoid accidental writes outside the repo when local paths differ.
</issue_to_address>
### Comment 2
<location> `scripts/create_ga4gh_trs_mocks.js:4` </location>
<code_context>
+const fs = require('fs');
+const path = require('path');
+
+const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-trs';
+
+const files = {
</code_context>
<issue_to_address>
**issue (bug_risk):** The GA4GH TRS mock generator also uses a hard-coded absolute path, which should be made relative.
You can mirror the approach from `create_trs_mocks.js` using something like `path.join(__dirname, '..', 'mocks', 'ga4gh-trs')` so this runs correctly in CI and on other developers’ machines.
</issue_to_address>
### Comment 3
<location> `scripts/create_drs_mocks.js:4` </location>
<code_context>
+const fs = require('fs');
+const path = require('path');
+
+const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-drs';
+
+const files = {
</code_context>
<issue_to_address>
**issue (bug_risk):** The DRS mock generator also hard-codes a user-specific path for the mocks directory.
Please derive `mockDir` from the script location or project root (e.g., via `__dirname` and `path.join`) instead of using an absolute path, so the script works on other machines and in CI.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/elixir-trs-filer'; |
There was a problem hiding this comment.
issue (bug_risk): Using an absolute, user-specific path for mockDir makes this script non-portable.
To keep this usable in CI and for other developers, derive mockDir from the repo instead, e.g. path.join(__dirname, '..', 'mocks', 'elixir-trs-filer'), or read it from an environment variable. This also helps avoid accidental writes outside the repo when local paths differ.
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-trs'; |
There was a problem hiding this comment.
issue (bug_risk): The GA4GH TRS mock generator also uses a hard-coded absolute path, which should be made relative.
You can mirror the approach from create_trs_mocks.js using something like path.join(__dirname, '..', 'mocks', 'ga4gh-trs') so this runs correctly in CI and on other developers’ machines.
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const mockDir = '/Users/revaa/Desktop/orgs/cloud-component/cloud-components/mocks/ga4gh-drs'; |
There was a problem hiding this comment.
issue (bug_risk): The DRS mock generator also hard-codes a user-specific path for the mocks directory.
Please derive mockDir from the script location or project root (e.g., via __dirname and path.join) instead of using an absolute path, so the script works on other machines and in CI.
fixes #419
Description
This PR completes the implementation of the mock API layer for cloud components.
Summary of changes
.gitignoreto prevent mock artifacts/symlinks from being trackedThis improves development reliability, testability, and decouples components from live backend dependencies.
Fixes #(issue) (if applicable)
Checklist
Comments
This PR focuses on mock infrastructure and development-time behavior.
No production logic is affected.
Summary by Sourcery
Introduce a centralized fetcher utility to support environment-controlled mock API responses and wire it through all GA4GH/ELIXIR client providers and components.
New Features:
Enhancements:
Build:
Documentation:
Chores: