-
Notifications
You must be signed in to change notification settings - Fork 128
chore: add arg validation test coverage #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
blva
wants to merge
13
commits into
main
Choose a base branch
from
args-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
93c27ec
chore: add arg validation test coverage
blva e5b2307
lint and update
blva 7848be5
wip
blva 0d92d0f
Merge remote-tracking branch 'origin/main' into args-tests
blva ba7dcbe
chore: stop waiting for cluster deletion (#607)
blva 3bd3d93
chore(ci): add cleanup script on CI for atlas envs (#608)
kmruiz b12b4b1
wip
blva 2d00859
reuse args
blva aedcdfd
update tests
blva 32aaee5
Merge branch 'main' into args-tests
blva 33e76b2
update request input
blva 6a7780c
Fix tests
blva 10a81a1
fix sleep import
blva File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
name: "Cleanup stale Atlas test environments" | ||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 0 * * *" | ||
|
||
permissions: {} | ||
|
||
jobs: | ||
cleanup-envs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: GitHubSecurityLab/actions-permissions/monitor@v1 | ||
- uses: actions/checkout@v5 | ||
- uses: actions/setup-node@v5 | ||
with: | ||
node-version-file: package.json | ||
cache: "npm" | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Run cleanup script | ||
env: | ||
MDB_MCP_API_CLIENT_ID: ${{ secrets.TEST_ATLAS_CLIENT_ID }} | ||
MDB_MCP_API_CLIENT_SECRET: ${{ secrets.TEST_ATLAS_CLIENT_SECRET }} | ||
MDB_MCP_API_BASE_URL: ${{ vars.TEST_ATLAS_BASE_URL }} | ||
run: npm run atlas:cleanup |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import type { Group, AtlasOrganization } from "../src/common/atlas/openapi.js"; | ||
import { ApiClient } from "../src/common/atlas/apiClient.js"; | ||
import { ConsoleLogger } from "../src/common/logger.js"; | ||
import { Keychain } from "../src/lib.js"; | ||
import { describe, it } from "vitest"; | ||
|
||
function isOlderThanADay(date: string): boolean { | ||
const oneDayInMs = 24 * 60 * 60 * 1000; | ||
const projectDate = new Date(date); | ||
const currentDate = new Date(); | ||
return currentDate.getTime() - projectDate.getTime() > oneDayInMs; | ||
} | ||
|
||
async function findTestOrganization(client: ApiClient): Promise<AtlasOrganization> { | ||
const orgs = await client.listOrganizations(); | ||
const testOrg = orgs?.results?.find((org) => org.name === "MongoDB MCP Test"); | ||
|
||
if (!testOrg) { | ||
throw new Error('Test organization "MongoDB MCP Test" not found.'); | ||
} | ||
|
||
return testOrg; | ||
} | ||
|
||
async function findAllTestProjects(client: ApiClient, orgId: string): Promise<Group[]> { | ||
const projects = await client.listOrganizationProjects({ | ||
params: { | ||
path: { | ||
orgId, | ||
}, | ||
}, | ||
}); | ||
|
||
const testProjects = projects?.results?.filter((proj) => proj.name.startsWith("testProj-")) || []; | ||
return testProjects.filter((proj) => isOlderThanADay(proj.created)); | ||
} | ||
|
||
async function deleteAllClustersOnStaleProject(client: ApiClient, projectId: string): Promise<void> { | ||
const allClusters = await client | ||
.listClusters({ | ||
params: { | ||
path: { | ||
groupId: projectId || "", | ||
}, | ||
}, | ||
}) | ||
.then((res) => res.results || []); | ||
|
||
await Promise.allSettled( | ||
allClusters.map((cluster) => | ||
client.deleteCluster({ params: { path: { groupId: projectId || "", clusterName: cluster.name || "" } } }) | ||
) | ||
); | ||
} | ||
|
||
async function main(): Promise<void> { | ||
const apiClient = new ApiClient( | ||
{ | ||
baseUrl: process.env.MDB_MCP_API_BASE_URL || "https://cloud-dev.mongodb.com", | ||
credentials: { | ||
clientId: process.env.MDB_MCP_API_CLIENT_ID || "", | ||
clientSecret: process.env.MDB_MCP_API_CLIENT_SECRET || "", | ||
}, | ||
}, | ||
new ConsoleLogger(Keychain.root) | ||
); | ||
|
||
const testOrg = await findTestOrganization(apiClient); | ||
const testProjects = await findAllTestProjects(apiClient, testOrg.id || ""); | ||
|
||
if (testProjects.length === 0) { | ||
console.log("No stale test projects found for cleanup."); | ||
} | ||
|
||
for (const project of testProjects) { | ||
console.log(`Cleaning up project: ${project.name} (${project.id})`); | ||
if (!project.id) { | ||
console.warn(`Skipping project with missing ID: ${project.name}`); | ||
continue; | ||
} | ||
|
||
await deleteAllClustersOnStaleProject(apiClient, project.id); | ||
await apiClient.deleteProject({ | ||
params: { | ||
path: { | ||
groupId: project.id, | ||
}, | ||
}, | ||
}); | ||
console.log(`Deleted project: ${project.name} (${project.id})`); | ||
} | ||
|
||
return; | ||
} | ||
|
||
describe("Cleanup Atlas Test Leftovers", () => { | ||
it("should clean up stale test projects", async () => { | ||
await main(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.