CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history
editor-ai-commit.test.ts
Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.
| c81b57c | 1 | /** |
| 2 | * Smoke tests for the new AI commit-message endpoint: | |
| 3 | * POST /:owner/:repo/ai/commit-message | |
| 4 | * | |
| 5 | * The route requires write access. Anonymous and bogus-bearer callers | |
| 6 | * should never see a 200 / leaked AI body. | |
| 7 | */ | |
| 8 | ||
| 9 | import { describe, it, expect } from "bun:test"; | |
| 10 | import app from "../app"; | |
| 11 | ||
| 12 | describe("POST /:owner/:repo/ai/commit-message — auth guard", () => { | |
| 13 | it("redirects to /login when unauthenticated", async () => { | |
| 14 | const res = await app.request( | |
| 15 | "/alice/demo/ai/commit-message", | |
| 16 | { | |
| 17 | method: "POST", | |
| 18 | headers: { "content-type": "application/x-www-form-urlencoded" }, | |
| 19 | body: "ref=main&filePath=README.md&content=hello", | |
| 20 | redirect: "manual", | |
| 21 | } | |
| 22 | ); | |
| 23 | expect([301, 302, 303, 307, 401, 403, 404, 503]).toContain(res.status); | |
| 24 | if (res.status === 302 || res.status === 303 || res.status === 307) { | |
| 25 | const loc = res.headers.get("location") || ""; | |
| 26 | expect(loc).toContain("/login"); | |
| 27 | } | |
| 28 | }); | |
| 29 | ||
| 30 | it("rejects bogus bearer tokens", async () => { | |
| 31 | const res = await app.request( | |
| 32 | "/alice/demo/ai/commit-message", | |
| 33 | { | |
| 34 | method: "POST", | |
| 35 | headers: { | |
| 36 | "content-type": "application/x-www-form-urlencoded", | |
| 37 | authorization: "Bearer glct_definitely-not-valid", | |
| 38 | }, | |
| 39 | body: "ref=main&filePath=README.md&content=hello", | |
| 40 | } | |
| 41 | ); | |
| 42 | expect([401, 403, 404, 503]).toContain(res.status); | |
| 43 | }); | |
| 44 | }); |