Repository navigation
feat: add build ai diagnosis and fix pipeline #53
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0.3.0 | ||
| 0.4.0 |
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,23 @@ | ||
| FROM oven/bun:1 | ||
|
|
||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| ca-certificates \ | ||
| git \ | ||
| ripgrep \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| WORKDIR /runner | ||
| COPY package.sandbox.json ./package.json | ||
| RUN bun install --production | ||
|
|
||
| COPY src/fixdiag/sandbox-runner/ ./fixdiag/sandbox-runner/ | ||
| COPY src/fixdiag/types.ts ./fixdiag/types.ts | ||
| COPY src/fixdiag/llm.ts ./fixdiag/llm.ts | ||
| RUN rm -rf ./fixdiag/sandbox-runner/__tests__ | ||
|
|
||
| RUN mkdir -p /srv/jobs /srv/dequel-src /srv/project-src \ | ||
| && chown -R bun:bun /srv/jobs /srv/dequel-src /srv/project-src | ||
|
|
||
| USER bun | ||
|
|
||
| CMD ["sleep", "infinity"] | ||
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,7 @@ | ||
| { | ||
| "name": "dequel-diag-sandbox", | ||
| "private": true, | ||
| "dependencies": { | ||
| "@ax-llm/ax": "^25.0.0" | ||
| } | ||
| } |
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,118 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { | ||
| LLM_PROVIDERS, | ||
| deleteLlmKey, | ||
| getDecryptedLlmKey, | ||
| getLlmKeyStatus, | ||
| updateLlmModels, | ||
| upsertLlmKey, | ||
| } from "../../db/repo"; | ||
| import { fetchProviderModels, DEFAULT_PROVIDER_MODELS } from "../../fixdiag/provider-models"; | ||
| import { fail, ok } from "../response"; | ||
|
|
||
| export const llmSettingsRoutes = new Elysia({ prefix: "/settings" }) | ||
| .get("/llm-keys", async () => ok(await getLlmKeyStatus())) | ||
| .get("/llm-default-models", async () => ok(DEFAULT_PROVIDER_MODELS)) | ||
| .get("/llm-keys/:provider/models", async ({ params, query, set }: any) => { | ||
| const provider = String(params.provider); | ||
| if (!(LLM_PROVIDERS as readonly string[]).includes(provider)) { | ||
| set.status = 400; | ||
| return fail(`provider must be one of: ${LLM_PROVIDERS.join(", ")}`); | ||
| } | ||
| const existing = await getDecryptedLlmKey(provider); | ||
| if (!existing) { | ||
| set.status = 404; | ||
| return fail("Provider key not configured"); | ||
| } | ||
| const refresh = query?.refresh === "true" || existing.models.length === 0; | ||
| if (refresh) { | ||
| const models = await fetchProviderModels({ | ||
| provider, | ||
| apiKey: existing.apiKey, | ||
| baseUrl: existing.baseUrl, | ||
| }); | ||
| if (models.length > 0) { | ||
| await updateLlmModels(provider, models); | ||
| return ok({ provider, models, cached: false }); | ||
| } | ||
| } | ||
| return ok({ provider, models: existing.models, cached: true }); | ||
| }) | ||
| .post("/llm-keys/:provider/sync", async ({ params, set }: any) => { | ||
| const provider = String(params.provider); | ||
| if (!(LLM_PROVIDERS as readonly string[]).includes(provider)) { | ||
| set.status = 400; | ||
| return fail(`provider must be one of: ${LLM_PROVIDERS.join(", ")}`); | ||
| } | ||
| const existing = await getDecryptedLlmKey(provider); | ||
| if (!existing) { | ||
| set.status = 404; | ||
| return fail("Provider key not configured"); | ||
| } | ||
| const models = await fetchProviderModels({ | ||
| provider, | ||
| apiKey: existing.apiKey, | ||
| baseUrl: existing.baseUrl, | ||
| }); | ||
| await updateLlmModels(provider, models); | ||
| return ok({ provider, models }, `Synced ${models.length} models for ${provider}`); | ||
| }) | ||
| .put("/llm-keys", async ({ body, set }: any) => { | ||
| const provider = String(body?.provider ?? ""); | ||
| if (!(LLM_PROVIDERS as readonly string[]).includes(provider)) { | ||
| set.status = 400; | ||
| return fail(`provider must be one of: ${LLM_PROVIDERS.join(", ")}`); | ||
| } | ||
| if (body?.apiKey !== undefined && typeof body.apiKey !== "string") { | ||
| set.status = 400; | ||
| return fail("apiKey must be a string"); | ||
| } | ||
| const existing = await getDecryptedLlmKey(provider); | ||
| if (provider === "custom") { | ||
| if (!body?.baseURL && !existing?.baseUrl) { | ||
| set.status = 400; | ||
| return fail("baseURL is required for the custom provider"); | ||
| } | ||
| } | ||
| const apiKey = | ||
| typeof body?.apiKey === "string" && body.apiKey.length > 0 ? body.apiKey : provider === "ollama" ? "ollama" : ""; | ||
| const effectiveBaseUrl = body?.baseURL !== undefined ? body.baseURL : existing?.baseUrl; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| const baseChanged = body?.baseURL !== undefined && body.baseURL !== existing?.baseUrl; | ||
| if (baseChanged && !apiKey && existing?.apiKey) { | ||
| set.status = 400; | ||
| return fail("apiKey is required when changing baseURL"); | ||
| } | ||
| const effectiveApiKey = apiKey || existing?.apiKey || ""; | ||
|
|
||
| let models: string[] | undefined = Array.isArray(body?.models) ? body.models.map(String) : undefined; | ||
| if (!models || models.length === 0) { | ||
| try { | ||
| const pulled = await fetchProviderModels({ | ||
| provider, | ||
| apiKey: effectiveApiKey, | ||
| baseUrl: effectiveBaseUrl, | ||
| }); | ||
| if (pulled.length > 0) { | ||
| models = pulled; | ||
| } | ||
| } catch { | ||
| models = existing?.models ?? undefined; | ||
| } | ||
| } | ||
|
|
||
| const status = await upsertLlmKey({ | ||
| provider, | ||
| apiKey, | ||
| baseURL: body?.baseURL, | ||
| models, | ||
| }); | ||
| return ok(status, "LLM provider key updated"); | ||
| }) | ||
| .delete("/llm-keys/:provider", async ({ params, set }: any) => { | ||
| const deleted = await deleteLlmKey(String(params.provider)); | ||
| if (!deleted) { | ||
| set.status = 404; | ||
| return fail("LLM provider key not found"); | ||
| } | ||
| return ok(null, "LLM provider key deleted"); | ||
| }); | ||
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,84 @@ | ||
| import { afterAll, beforeAll, describe, expect, it, mock } from "bun:test"; | ||
| import { drizzle } from "drizzle-orm/node-postgres"; | ||
| import type { Pool } from "pg"; | ||
| import { setDbProvider } from "../db-provider"; | ||
| import * as schema from "../schema"; | ||
| import { createTestPool, truncateAllTables } from "../test-helper"; | ||
| import { | ||
| createDiagRun, | ||
| finishDiagRun, | ||
| getDiagRun, | ||
| getStagePayload, | ||
| listActiveDiagRuns, | ||
| listStageResults, | ||
| markInterruptedDiagRuns, | ||
| recordStageResult, | ||
| } from "../repo/diag-runs"; | ||
|
|
||
| let pool: Pool; | ||
|
|
||
| mock.restore(); | ||
|
|
||
| beforeAll(async () => { | ||
| pool = createTestPool(); | ||
| const db = drizzle(pool, { schema }); | ||
| setDbProvider(async () => db); | ||
| await truncateAllTables(pool); | ||
| await pool.query( | ||
| `INSERT INTO projects (id, name, source_type, created_at, updated_at) | ||
| VALUES ('proj-diagruns', 'DiagRuns Project', 'git', NOW(), NOW()) ON CONFLICT DO NOTHING`, | ||
| ); | ||
| await pool.query( | ||
| `INSERT INTO deployments (id, project_id, source_type, source_ref, status, created_at, updated_at) | ||
| VALUES ('dep-x', 'proj-diagruns', 'git', 'https://github.com/test/repo.git', 'failed', NOW(), NOW()), | ||
| ('dep-dup', 'proj-diagruns', 'git', 'https://github.com/test/repo.git', 'failed', NOW(), NOW()) | ||
| ON CONFLICT DO NOTHING`, | ||
| ); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| try { | ||
| await truncateAllTables(pool); | ||
| } finally { | ||
| await pool.end(); | ||
| } | ||
| }); | ||
|
|
||
| describe("diag-runs", () => { | ||
| it("creates, finds and finishes runs", async () => { | ||
| const run = await createDiagRun({ deploymentId: "dep-x", commitSha: "abc", provider: "groq", model: "m" }); | ||
| expect(run.status).toBe("running"); | ||
| expect(run.currentStage).toBeNull(); | ||
|
|
||
| await recordStageResult(run.id, "triage", { failingStage: "build" }); | ||
| expect(await getStagePayload(run.id, "triage")).toEqual({ failingStage: "build" }); | ||
|
|
||
| await recordStageResult(run.id, "triage", { failingStage: "deploy" }); | ||
| expect(await getStagePayload(run.id, "triage")).toEqual({ failingStage: "deploy" }); | ||
| expect((await listStageResults(run.id)).filter((s) => s.stage === "triage")).toHaveLength(1); | ||
|
|
||
| await finishDiagRun(run.id, "done", "user-source", { cause: "user-source" }, null); | ||
| const done = await getDiagRun(run.id); | ||
| expect(done?.status).toBe("done"); | ||
| expect(done?.cause).toBe("user-source"); | ||
| expect(done?.report).toEqual({ cause: "user-source" }); | ||
| }); | ||
|
|
||
| it("rejects duplicate runs for the same deployment and commit", async () => { | ||
| await createDiagRun({ deploymentId: "dep-dup", commitSha: "", provider: "groq", model: "m" }); | ||
| await expect( | ||
| createDiagRun({ deploymentId: "dep-dup", commitSha: "", provider: "groq", model: "m" }), | ||
| ).rejects.toThrow(); | ||
| }); | ||
|
|
||
| it("lists active runs and marks interrupted ones as failed", async () => { | ||
| const run = await createDiagRun({ deploymentId: "dep-x", commitSha: "active-1", provider: "ollama", model: "m" }); | ||
| const active = await listActiveDiagRuns(); | ||
| const found = active.find((r) => r.id === run.id); | ||
| expect(found).toMatchObject({ deploymentId: "dep-x", projectName: "DiagRuns Project", provider: "ollama" }); | ||
|
|
||
| expect(await markInterruptedDiagRuns()).toBeGreaterThanOrEqual(1); | ||
| expect((await getDiagRun(run.id))?.status).toBe("error"); | ||
| expect(await listActiveDiagRuns()).toEqual([]); | ||
| }); | ||
| }); |
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,73 @@ | ||
| import { afterAll, beforeAll, describe, expect, it, mock } from "bun:test"; | ||
| import { drizzle } from "drizzle-orm/node-postgres"; | ||
| import type { Pool } from "pg"; | ||
| import { setDbProvider } from "../db-provider"; | ||
| import * as schema from "../schema"; | ||
| import { createTestPool, truncateAllTables } from "../test-helper"; | ||
| import { deleteLlmKey, getDecryptedLlmKey, getLlmKeyStatus, updateLlmModels, upsertLlmKey } from "../repo/llm-keys"; | ||
|
|
||
| let pool: Pool; | ||
|
|
||
| mock.restore(); | ||
|
|
||
| beforeAll(async () => { | ||
| pool = createTestPool(); | ||
| const db = drizzle(pool, { schema }); | ||
| setDbProvider(async () => db); | ||
| await truncateAllTables(pool); | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| try { | ||
| await truncateAllTables(pool); | ||
| } finally { | ||
| await pool.end(); | ||
| } | ||
| }); | ||
|
|
||
| describe("llm-keys", () => { | ||
| it("stores encrypted and reports status without the secret", async () => { | ||
| const status = await upsertLlmKey({ | ||
| provider: "groq", | ||
| apiKey: "gsk-secret-1", | ||
| models: ["llama-3.3-70b-versatile"], | ||
| }); | ||
| expect(status.provider).toBe("groq"); | ||
| expect(status.configured).toBe(true); | ||
| expect(status.models).toEqual(["llama-3.3-70b-versatile"]); | ||
| expect(JSON.stringify(status)).not.toContain("gsk-secret-1"); | ||
|
|
||
| const all = await getLlmKeyStatus(); | ||
| expect(all.find((s) => s.provider === "groq")?.configured).toBe(true); | ||
| expect(JSON.stringify(all)).not.toContain("gsk-secret-1"); | ||
| }); | ||
|
|
||
| it("round-trips the decrypted key", async () => { | ||
| await upsertLlmKey({ provider: "openai", apiKey: "sk-secret-2" }); | ||
| const rec = await getDecryptedLlmKey("openai"); | ||
| expect(rec?.apiKey).toBe("sk-secret-2"); | ||
| expect(await getDecryptedLlmKey("missing")).toBeNull(); | ||
| }); | ||
|
|
||
| it("keeps the old key when apiKey is empty", async () => { | ||
| await upsertLlmKey({ provider: "groq", apiKey: "gsk-secret-1" }); | ||
| const status = await upsertLlmKey({ provider: "groq", apiKey: "", models: ["other-model"] }); | ||
| expect(status.configured).toBe(true); | ||
| expect(status.models).toEqual(["other-model"]); | ||
| expect((await getDecryptedLlmKey("groq"))?.apiKey).toBe("gsk-secret-1"); | ||
| }); | ||
|
|
||
| it("updates models for a provider", async () => { | ||
| await upsertLlmKey({ provider: "gemini", apiKey: "gem-sec-1" }); | ||
| const updated = await updateLlmModels("gemini", ["gemini-2.5-flash", "gemini-2.5-pro"]); | ||
| expect(updated?.models).toEqual(["gemini-2.5-flash", "gemini-2.5-pro"]); | ||
| expect(await updateLlmModels("nonexistent", ["model"])).toBeNull(); | ||
| }); | ||
|
|
||
| it("deletes keys", async () => { | ||
| await upsertLlmKey({ provider: "anthropic", apiKey: "sk-ant-1" }); | ||
| expect(await deleteLlmKey("anthropic")).toBe(true); | ||
| expect(await deleteLlmKey("anthropic")).toBe(false); | ||
| expect((await getLlmKeyStatus()).find((s) => s.provider === "anthropic")).toBeUndefined(); | ||
| }); | ||
| }); |
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.