fix(context): tolerate a trailing /api/v1 in the base URL

The client (gitea-js) appends /api/v1 to the base URL itself, so a
GITEA_AXI_API_URL that already carries it — a natural guess given the
variable's name — doubled the segment and failed as a spurious
REPO_NOT_FOUND. Normalize the base URL by stripping a trailing /api/v1
(and any trailing slashes) on both the env-URL and tea-login paths, so the
host base and the /api/v1 endpoint both resolve.
This commit is contained in:
2026-07-19 09:41:13 -04:00
parent f9125e099d
commit dd58cd9dad
2 changed files with 63 additions and 3 deletions

View File

@@ -1,4 +1,6 @@
import { afterEach, describe, expect, it } from "vitest";
import { resolveRepoContext } from "../src/context.js";
import type { CliDeps } from "../src/deps.js";
import { startFixtureServer, type FixtureServer } from "./fixture-server.js";
import { runCliTest, testModeEnv } from "./harness.js";
@@ -117,3 +119,49 @@ describe("context overrides", () => {
expect(exitCode).toBe(0);
});
});
describe("apiUrl normalization", () => {
function depsWithApiUrl(apiUrl: string): CliDeps {
return {
env: {
GITEA_AXI_API_URL: apiUrl,
GITEA_AXI_REPO: "acme/widgets",
GITEA_AXI_TOKEN: "test-token",
},
cwd: process.cwd(),
globals: {},
};
}
it("strips a trailing /api/v1 suffix from the host base", async () => {
const context = await resolveRepoContext(
depsWithApiUrl("https://git.example.com/api/v1"),
);
expect(context.apiUrl).toBe("https://git.example.com");
});
it("strips a trailing /api/v1/ with a trailing slash", async () => {
const context = await resolveRepoContext(
depsWithApiUrl("https://git.example.com/api/v1/"),
);
expect(context.apiUrl).toBe("https://git.example.com");
});
it("leaves a host base without an /api/v1 suffix unchanged", async () => {
const context = await resolveRepoContext(
depsWithApiUrl("https://git.example.com"),
);
expect(context.apiUrl).toBe("https://git.example.com");
});
it("strips a lone trailing slash from the host base", async () => {
const context = await resolveRepoContext(
depsWithApiUrl("https://git.example.com/"),
);
expect(context.apiUrl).toBe("https://git.example.com");
});
});