-
Notifications
You must be signed in to change notification settings - Fork 205
AGE-1831: enhance DaytonaSandboxProvider with build failure handling #258
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ec9500e
feat: enhance DaytonaSandboxProvider with build failure handling
thesujai a5e3078
feat: improve Daytona build failure handling and persistency
thesujai e2804df
refactor: remove outdated comments in sandboxProviders and providerUt…
thesujai 1be0367
fix: stringify Daytona response status in error message
thesujai e322fa0
Merge branch 'main' into bugfix/failed-on-build-failed
thesujai 1b16acf
Add changeset for Daytona snapshot register status fix.
thesujai 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
6 changes: 6 additions & 0 deletions
6
.changeset/20260817052904-daytona-snapshot-register-status.md
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,6 @@ | ||
| --- | ||
| '@truefoundry/trueforge-core': patch | ||
| '@truefoundry/trueforge': patch | ||
| --- | ||
|
|
||
| Await Daytona snapshot registration on sandbox provider configure so auth failures return 422 instead of a false pending status, and keep GET status refreshes persisted. |
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
80 changes: 80 additions & 0 deletions
80
packages/trueforge-core/tests/core/sandbox/daytonaSnapshotRegistration.test.ts
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,80 @@ | ||
| import { Daytona, DaytonaError } from '@daytona/sdk'; | ||
| import { DaytonaSandboxProvider } from '../../../src/core/sandbox/provider/DaytonaProvider'; | ||
| import { makeSilentLogger } from '../harnessMocks'; | ||
|
|
||
| const NOT_FOUND_STATUS = 404; | ||
| const CONFLICT_STATUS = 409; | ||
| const FORBIDDEN_STATUS = 403; | ||
| const API_URL = 'https://daytona.test/api'; | ||
|
|
||
| /** | ||
| * Builds a provider whose snapshot lookup reports "not built yet" so `buildImage` always reaches | ||
| * the register-only POST. | ||
| */ | ||
| function makeProvider(): DaytonaSandboxProvider { | ||
| // useDeprecatedPolling keeps the constructor from opening the event-stream WebSocket. | ||
| const client = new Daytona({ apiKey: 'dtn-test', useDeprecatedPolling: true }); | ||
| jest.spyOn(client.snapshot, 'get').mockRejectedValue(new DaytonaError('not found', NOT_FOUND_STATUS)); | ||
|
|
||
| return new DaytonaSandboxProvider({ | ||
| client, | ||
| apiKey: 'dtn-test', | ||
| apiUrl: API_URL, | ||
| tenantName: 'test-tenant', | ||
| sandboxImage: 'registry.example.com/sandbox:029ea5ff', | ||
| timeoutMs: 1000, | ||
| autoStopIntervalInMinutes: 5, | ||
| autoArchiveIntervalInMinutes: 60, | ||
| autoDeleteIntervalInMinutes: 7200, | ||
| fileMaxBytesForDownload: 1024, | ||
| logger: makeSilentLogger(), | ||
| }); | ||
| } | ||
|
|
||
| function mockFetch({ status, body }: { status: number; body: unknown }): jest.SpiedFunction<typeof globalThis.fetch> { | ||
| return jest | ||
| .spyOn(globalThis, 'fetch') | ||
| .mockResolvedValue(new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } })); | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| describe('DaytonaSandboxProvider register-only snapshot create', () => { | ||
| it('awaits the register POST and returns pending without polling to active', async () => { | ||
| const fetchMock = mockFetch({ | ||
| status: 200, | ||
| body: { id: 'snap-1', name: 'trueforge-build-029ea5ff', state: 'pending', errorReason: null }, | ||
| }); | ||
|
|
||
| const build = await makeProvider().buildImage(); | ||
|
|
||
| expect(build.status).toBe('pending'); | ||
| expect(fetchMock).toHaveBeenCalledTimes(1); | ||
| expect(fetchMock.mock.calls[0]?.[0]).toBe(`${API_URL}/snapshots`); | ||
| const init = fetchMock.mock.calls[0]?.[1]; | ||
| expect(init?.method).toBe('POST'); | ||
| expect(JSON.parse(String(init?.body))).toEqual({ | ||
| name: 'trueforge-build-029ea5ff', | ||
| imageName: 'registry.example.com/sandbox:029ea5ff', | ||
| }); | ||
| }); | ||
|
|
||
| it('treats a concurrent-create conflict as pending, not a thrown failure', async () => { | ||
| mockFetch({ status: CONFLICT_STATUS, body: { statusCode: CONFLICT_STATUS, message: 'Conflict' } }); | ||
|
|
||
| const build = await makeProvider().buildImage(); | ||
|
|
||
| expect(build.status).toBe('pending'); | ||
| }); | ||
|
|
||
| it('throws on Access denied so PUT can map it to 422', async () => { | ||
| mockFetch({ status: FORBIDDEN_STATUS, body: { statusCode: FORBIDDEN_STATUS, message: 'Access denied' } }); | ||
|
|
||
| await expect(makeProvider().buildImage()).rejects.toMatchObject({ | ||
| message: 'Access denied', | ||
| statusCode: FORBIDDEN_STATUS, | ||
| }); | ||
| }); | ||
| }); |
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.
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.