-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fetch secrets from <workspace>/.continue/.env folder before <workspace>/.env #5461
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
Merged
tomasz-stefaniak
merged 7 commits into
continuedev:main
from
uinstinct:workspace-continue-env
Jun 2, 2025
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
96254ab
get secrets from <workspace>/.continue folder
uinstinct fe6d55d
added localplatformclient test
uinstinct 42722ec
Merge branch 'main' into workspace-continue-env
uinstinct 16b1d3f
Merge branch 'main' into workspace-continue-env
uinstinct b6f2aa6
introduce vitest and pass LocalPlatformClient.test
uinstinct dd08321
run vitest for LocalPlatform in pr_checks
uinstinct 610814e
ignore LocalPlatformClient from jest tests
uinstinct 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,96 @@ | ||
import { FQSN, SecretResult, SecretType } from "@continuedev/config-yaml"; | ||
import { testControlPlaneClient, testIde } from "../../test/fixtures"; | ||
import { LocalPlatformClient } from "./LocalPlatformClient"; | ||
|
||
jest.mock("../../util/paths.ts", () => ({ | ||
...jest.requireActual("../../util/paths"), | ||
getContinueDotEnv: jest.fn(), | ||
})); | ||
|
||
describe("LocalPlatformClient", () => { | ||
const testFQSN: FQSN = { | ||
packageSlugs: [ | ||
{ | ||
ownerSlug: "test-owner-slug", | ||
packageSlug: "test-package-slug", | ||
}, | ||
], | ||
secretName: "TEST_CONTINUE_SECRET_KEY", | ||
}; | ||
const testResolvedFQSN: SecretResult = { | ||
found: true, | ||
fqsn: testFQSN, | ||
secretLocation: { | ||
secretName: testFQSN.secretName, | ||
secretType: SecretType.Organization, | ||
orgSlug: "test-org-slug", | ||
}, | ||
}; | ||
|
||
afterEach(() => jest.restoreAllMocks()); | ||
|
||
test("should not be able to resolve FQSNs if they do not exist", async () => { | ||
testControlPlaneClient.resolveFQSNs = jest.fn(async () => [ | ||
testResolvedFQSN, | ||
]); | ||
const localPlatformClient = new LocalPlatformClient( | ||
null, | ||
testControlPlaneClient, | ||
testIde, | ||
); | ||
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([testFQSN]); | ||
expect(testControlPlaneClient.resolveFQSNs).toHaveBeenCalled(); | ||
expect(resolvedFQSNs).toEqual([testResolvedFQSN]); | ||
}); | ||
|
||
test("should not be able to resolve FQSNs if they do not exist", async () => { | ||
const localPlatformClient = new LocalPlatformClient( | ||
null, | ||
testControlPlaneClient, | ||
testIde, | ||
); | ||
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([testFQSN]); | ||
|
||
expect(resolvedFQSNs.length).toBeGreaterThan(0); | ||
expect(resolvedFQSNs[0]?.found).toBe(false); | ||
}); | ||
|
||
describe.only("searches for secrets in local .env files", () => { | ||
const secretValue = Math.floor(Math.random() * 100) + ""; | ||
const envKeyValues = { | ||
TEST_CONTINUE_SECRET_KEY: secretValue, | ||
}; | ||
const getContinueDotEnv = jest.fn(() => envKeyValues); | ||
|
||
beforeEach(async () => { | ||
// const directoryExists = fs.existsSync("./_tests"); | ||
// if (directoryExists) { | ||
// fs.rmSync("./_tests", { force: true, recursive: true }); | ||
// } | ||
// const envFileContent = `TEST_CONTINUE_SECRET_KEY=${secretValue}`; | ||
// fs.writeFileSync("./_tests/.env", envFileContent); | ||
// utilPaths.getContinueDotEnv = getContinueDotEnv | ||
// const spy = jest.spyOn(utilPaths, 'getContinueDotEnv') | ||
// Object.defineProperty(utilPaths, 'getContinueDotEnv', { | ||
// writable: true, | ||
// configurable: true, | ||
// value: spy.mockImplementation(() => envKeyValues), | ||
// }); | ||
// jest.mock(utilPaths, () => ({ | ||
// ...jest.requireActual(utilPaths), | ||
// getContinueDotEnv: jest.fn().mockReturnValue(envKeyValues) | ||
// })) | ||
}); | ||
|
||
test("should be able to get secrets from global ~/.continue/.env files", async () => { | ||
const localPlatformClient = new LocalPlatformClient( | ||
null, | ||
testControlPlaneClient, | ||
testIde, | ||
); | ||
const resolvedFQSNs = await localPlatformClient.resolveFQSNs([testFQSN]); | ||
expect(getContinueDotEnv).toHaveBeenCalled(); | ||
console.log("resolved->", resolvedFQSNs); | ||
}); | ||
}); | ||
}); |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @tomasz-stefaniak
there is some problem when am trying to mock a local file as jest is unable to resolve it. it seems like a problem with how jest is setup. I tried various ways to get it working. Currently none of these work.
Any idea what should I do to a mock?
(I need to mock
utils/paths
for imported functions likegetContinueDotEnv()
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@uinstinct have you checked some existing instances of

jest.mock
we have in the codebase?I understand most of them are for node packages but maybe they can point you in the right direction. If you are still stuck, let me know and I can try to pull this into the sprint next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for replying Tomasz!
I had tried these actually but for some reason jest is unable to resolve it.
For alternative options, we can:
process.env.TEST
flag) insidegetContinueDotEnv
to produce a key value pair for testingUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spent some more time debugging this. Looks like the module resolution was starting from
core/test
folder since jest was declared as global incore/test/jest.setup-after-env.js
So,
../util/paths
would work but not../../util/paths
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Tried both
unstable_mockModule
andjest.mock('../util/paths')
both which resolve correctly but do not mock implementations for some reason.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: this is a huge pain, I'm exploring migrating to Vitest 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥲 Agree!!!
BTW, can i help in some way? I have some experience with migrating jest to vitest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great, actually! Do you think you'd be able to create a basic vitest setup? It could be on this branch, and it would be used to run LocalPlatformClient.test.ts. Once this proof of concept works we can migrate other tests to vitest.
This would also require adding an extra step here: https://github.com/continuedev/continue/blob/main/.github/workflows/pr_checks.yaml
Let me know what you think!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implemented!
Edit: Should I draft another PR to migrate core tests to vitest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that would be great. It's one of our more important tasks at the moment.