-
-
Notifications
You must be signed in to change notification settings - Fork 539
feat(mcp): add durable background jobs and runtime diagnostics subsystem #350
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
Open
PGupta-Git
wants to merge
5
commits into
Waishnav:main
Choose a base branch
from
PGupta-Git:feat/durable-background-jobs
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.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0fb8360
feat(mcp): add durable background jobs and runtime diagnostics subsystem
PGupta-Git 2245afc
fix(jobs): address review findings on restart reconciliation, fd owne…
PGupta-Git 9def76c
fix(jobs): use bash EXIT trap for completion marker, reload rows in l…
PGupta-Git 705b2d2
fix(env): resolve NVM LTS aliases dynamically from local alias metadata
PGupta-Git 90cfa46
feat(jobs): include tail logs in job_wait completion and optimize wai…
PGupta-Git 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,124 @@ | ||
| import test from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { mkdtempSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { DurableJobManager } from "./durable-jobs.js"; | ||
| import { resolveProjectEnvironment, getRuntimeDiagnostics } from "./runtime-env.js"; | ||
|
|
||
| function delay(ms: number): Promise<void> { | ||
| let timer: NodeJS.Timeout; | ||
| return new Promise<void>((resolve) => { | ||
| timer = setTimeout(resolve, ms); | ||
| }).finally(() => { | ||
| clearTimeout(timer); | ||
| }); | ||
| } | ||
|
|
||
| test("DurableJobManager: starts, tracks, and reads logs from detached job", async () => { | ||
| const tempDir = mkdtempSync(join(tmpdir(), "devspace-jobs-test-")); | ||
| const mgr = new DurableJobManager(tempDir); | ||
|
|
||
| try { | ||
| const job = mgr.startJob({ | ||
| workspaceId: "test_ws", | ||
| workspaceRoot: process.cwd(), | ||
| command: "echo line1; echo line2", | ||
| workingDirectory: process.cwd(), | ||
| }); | ||
|
|
||
| assert.ok(job.id.startsWith("job_")); | ||
| assert.equal(job.status, "running"); | ||
|
|
||
| // Wait for completion | ||
| let finalJob = mgr.getJob(job.id); | ||
| for (let i = 0; i < 20; i++) { | ||
| if (finalJob?.status !== "running") break; | ||
| await delay(100); | ||
| finalJob = mgr.getJob(job.id); | ||
| } | ||
|
|
||
| assert.equal(finalJob?.status, "succeeded"); | ||
| assert.equal(finalJob?.exitCode, 0); | ||
|
|
||
| const logs = mgr.readLogs(job.id); | ||
| assert.ok(logs.content.includes("line1")); | ||
| assert.ok(logs.content.includes("line2")); | ||
| assert.equal(logs.hasMore, false); | ||
| } finally { | ||
| mgr.close(); | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| test("DurableJobManager: cancels running job and updates record", async () => { | ||
| const tempDir = mkdtempSync(join(tmpdir(), "devspace-jobs-cancel-test-")); | ||
| const mgr = new DurableJobManager(tempDir); | ||
|
|
||
| try { | ||
| const job = mgr.startJob({ | ||
| workspaceId: "test_ws", | ||
| workspaceRoot: process.cwd(), | ||
| command: "sleep 60", | ||
| workingDirectory: process.cwd(), | ||
| }); | ||
|
|
||
| assert.equal(job.status, "running"); | ||
| const cancelRes = mgr.cancelJob(job.id); | ||
| assert.equal(cancelRes.success, true); | ||
|
|
||
| const postCancel = mgr.getJob(job.id); | ||
| assert.equal(postCancel?.status, "cancelled"); | ||
| } finally { | ||
| mgr.close(); | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| test("DurableJobManager: log pagination with maxLines preserves nextOffset", async () => { | ||
| const tempDir = mkdtempSync(join(tmpdir(), "devspace-jobs-pagination-test-")); | ||
| const mgr = new DurableJobManager(tempDir); | ||
|
|
||
| try { | ||
| const job = mgr.startJob({ | ||
| workspaceId: "test_ws", | ||
| workspaceRoot: process.cwd(), | ||
| command: "echo line-one; echo line-two; echo line-three", | ||
| workingDirectory: process.cwd(), | ||
| }); | ||
|
|
||
| for (let i = 0; i < 20; i++) { | ||
| const current = mgr.getJob(job.id); | ||
| if (current?.status !== "running") break; | ||
| await delay(100); | ||
| } | ||
|
|
||
| const chunk1 = mgr.readLogs(job.id, { maxLines: 1 }); | ||
| assert.equal(chunk1.content, "line-one"); | ||
| assert.equal(chunk1.hasMore, true); | ||
|
|
||
| const chunk2 = mgr.readLogs(job.id, { offset: chunk1.nextOffset }); | ||
| assert.ok(chunk2.content.includes("line-two")); | ||
| assert.ok(chunk2.content.includes("line-three")); | ||
| } finally { | ||
| mgr.close(); | ||
| rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| test("Runtime environment normalization and LTS alias discovery", () => { | ||
| const tempWs = mkdtempSync(join(tmpdir(), "devspace-env-test-")); | ||
| try { | ||
| writeFileSync(join(tempWs, ".nvmrc"), "lts/*", "utf8"); | ||
| const env = resolveProjectEnvironment(tempWs); | ||
| assert.ok(typeof env.PATH === "string"); | ||
| assert.ok(env.SHELL); | ||
|
|
||
| const diag = getRuntimeDiagnostics(tempWs); | ||
| assert.ok(diag.nodeVersion); | ||
| assert.ok(diag.gitVersion); | ||
| assert.ok(diag.shell); | ||
| } finally { | ||
| rmSync(tempWs, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
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.