Skip to content

Commit 7a5af36

Browse files
only21milclaude
andcommitted
fix(server): keep tea's claim when a login sits below the mount
The static tea spec gave no answer when tea listed a login below the remote's mount. With logins at a host and at a group on it, a remote under the host's own login then went unrecognized, though main claimed it. The spec now claims what matchForgejoLogin picks and marks the verdict unsettled, as the managed refiner does, so it is still never cached for a sibling remote. CLI refiners now return the same verdict and settled flag as managed ones. GitLab's refiner gives the same three answers in that form. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e6be0da commit 7a5af36

5 files changed

Lines changed: 68 additions & 39 deletions

File tree

‎packages/source-control-core/src/server/discovery.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ export type SourceControlCliDiscoverySpec = SourceControlDiscoverySpecBase & {
4545
readonly remoteRefinementArgs?: ReadonlyArray<string>;
4646
readonly probeTimeoutMs?: number;
4747
readonly parseAuth: (input: SourceControlAuthProbeInput) => SourceControlProviderAuth;
48-
/** Null when the CLI's output answers no for the remote, undefined when it does not answer. */
48+
/** Unsettled when the CLI's output does not answer for this remote, as opposed to answering no. */
4949
readonly refineUnknownRemote?: (
5050
input: SourceControlUnknownRemoteRefinementInput,
51-
) => SourceControlProviderInfo | null | undefined;
51+
) => UnknownRemoteVerdict;
5252
};
5353

5454
export type SourceControlApiDiscoverySpec = SourceControlDiscoverySpecBase & {
@@ -353,14 +353,14 @@ export const refineUnknownRemoteProvider = Effect.fn("refineUnknownRemoteProvide
353353
})
354354
.pipe(
355355
Effect.map((auth) => {
356-
const provider = spec.refineUnknownRemote({
356+
const verdict = spec.refineUnknownRemote({
357357
cwd: input.cwd,
358358
context,
359359
auth,
360360
});
361361
// Output cut at the limit may have lost the part that answers for this remote.
362362
const complete = !auth.stdoutTruncated && !auth.stderrTruncated;
363-
return { provider: provider ?? null, settled: provider !== undefined && complete };
363+
return { provider: verdict.provider, settled: verdict.settled && complete };
364364
}),
365365
// A CLI that is not installed answers no for every checkout.
366366
Effect.catchIf(isMissingExecutable, () =>

‎packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts‎

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,14 +582,17 @@ it.effect("discovers Forgejo accounts and retains the server port", () =>
582582
),
583583
});
584584
assert.deepStrictEqual(refined, {
585-
kind: SourceControlProviderKind.make("forgejo"),
586-
name: "Forgejo / Gitea",
587-
baseUrl: "http://forgejo.local:3000",
585+
provider: {
586+
kind: SourceControlProviderKind.make("forgejo"),
587+
name: "Forgejo / Gitea",
588+
baseUrl: "http://forgejo.local:3000",
589+
},
590+
settled: true,
588591
});
589592
}),
590593
);
591594

592-
it("does not answer from a tea login list with a login below the remote's mount", () => {
595+
it("does not settle a tea login list with a login below the remote's mount", () => {
593596
const refine = (remoteUrl: string, urls: ReadonlyArray<string>) =>
594597
ForgejoSourceControlProvider.discovery.refineUnknownRemote({
595598
cwd: "/repo",
@@ -606,14 +609,29 @@ it("does not answer from a tea login list with a login below the remote's mount"
606609
encodeJson(urls.map((url) => ({ name: url, url, user: "maria", default: "false" }))),
607610
),
608611
});
609-
const urls = ["https://git.example.internal/forge", "https://git.example.internal/forge/group"];
610-
// The group login serves forge/group/a and not forge/other/b, so the answer depends on the path.
611-
assert.isUndefined(refine("https://git.example.internal/forge/group/a.git", urls));
612-
assert.isUndefined(refine("https://git.example.internal/forge/other/b.git", urls));
613-
assert.strictEqual(
614-
refine("https://git.example.internal/forge/other/b.git", urls.slice(0, 1))?.baseUrl,
615-
"https://git.example.internal/forge",
616-
);
612+
const forgejo = (baseUrl: string) => ({
613+
kind: SourceControlProviderKind.make("forgejo"),
614+
name: "Forgejo / Gitea",
615+
baseUrl,
616+
});
617+
for (const mount of ["", "/forge"]) {
618+
const above = `https://git.example.internal${mount}`;
619+
const urls = [above, `${above}/group`];
620+
// The group login serves group/a and not other/b, so the answer depends on the path. The
621+
// login above it still claims other/b.
622+
assert.deepStrictEqual(refine(`${above}/other/b.git`, urls), {
623+
provider: forgejo(above),
624+
settled: false,
625+
});
626+
assert.deepStrictEqual(refine(`${above}/group/a.git`, urls), {
627+
provider: null,
628+
settled: false,
629+
});
630+
assert.deepStrictEqual(refine(`${above}/other/b.git`, urls.slice(0, 1)), {
631+
provider: forgejo(above),
632+
settled: true,
633+
});
634+
}
617635
});
618636

619637
it.effect("does not choose a default Forgejo login across ambiguous SSH server ports", () =>
@@ -665,7 +683,7 @@ it.effect("does not choose a default Forgejo login across ambiguous SSH server p
665683
},
666684
auth: processOutput(yield* encodeJsonEffect(logins)),
667685
});
668-
assert.strictEqual(refined?.baseUrl, "http://forgejo.local:4000");
686+
assert.strictEqual(refined.provider?.baseUrl, "http://forgejo.local:4000");
669687
const https = ForgejoCli.parseForgejoRemote("http://forgejo.local:4000/maria/project.git");
670688
assert.isNotNull(https);
671689
assert.strictEqual(ForgejoCli.matchForgejoLogin(logins, https!)?.name, "two");

‎packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.ts‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ export const discovery = {
6161
},
6262
refineUnknownRemote: (input) => {
6363
const remote = ForgejoCli.parseForgejoRemote(input.context.remoteUrl);
64-
if (!remote) return null;
64+
if (!remote) return { provider: null, settled: true };
6565
const logins = ForgejoCli.parseForgejoLogins(input.auth.stdout);
66-
if (hasLoginBelowMount(logins, remote)) return undefined;
6766
const login = ForgejoCli.matchForgejoLogin(logins, remote, input.context.requestedHost);
68-
return login
69-
? {
70-
kind: SourceControlProviderKind.make("forgejo"),
71-
name: "Forgejo / Gitea",
72-
baseUrl: login.url,
73-
}
74-
: null;
67+
return {
68+
provider: login
69+
? {
70+
kind: SourceControlProviderKind.make("forgejo"),
71+
name: "Forgejo / Gitea",
72+
baseUrl: login.url,
73+
}
74+
: null,
75+
settled: !hasLoginBelowMount(logins, remote),
76+
};
7577
},
7678
installHint:
7779
"Install `fj` 0.6 or later from https://codeberg.org/forgejo-contrib/forgejo-cli and run `fj --host <server-url> auth add-token`, or install `tea` 0.16 or later from https://gitea.com/gitea/tea and run `tea login add` for each Forgejo or Gitea server.",

‎packages/source-control-gitlab/src/server/GitLabSourceControlProvider.test.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ self-hosted.example.test
186186
});
187187

188188
it("refines unknown GitLab remotes with mixed-case provider hosts", () => {
189-
const provider = GitLabSourceControlProvider.discovery.refineUnknownRemote?.({
189+
const verdict = GitLabSourceControlProvider.discovery.refineUnknownRemote?.({
190190
cwd: "/repo",
191191
context: {
192192
provider: {
@@ -207,10 +207,13 @@ it("refines unknown GitLab remotes with mixed-case provider hosts", () => {
207207
},
208208
});
209209

210-
assert.deepStrictEqual(provider, {
211-
kind: "gitlab",
212-
name: "GitLab Self-Hosted",
213-
baseUrl: "https://Self-Hosted.Example.Test",
210+
assert.deepStrictEqual(verdict, {
211+
provider: {
212+
kind: SourceControlProviderKind.make("gitlab"),
213+
name: "GitLab Self-Hosted",
214+
baseUrl: "https://Self-Hosted.Example.Test",
215+
},
216+
settled: true,
214217
});
215218
});
216219

‎packages/source-control-gitlab/src/server/GitLabSourceControlProvider.ts‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type SourceControlAuthProbeInput,
1616
type SourceControlCliDiscoverySpec,
1717
type SourceControlUnknownRemoteRefinementInput,
18+
type UnknownRemoteVerdict,
1819
} from "@t3tools/source-control-core/server/discovery";
1920
import { findAuthenticatedGitLabHost, parseGitLabAuthStatusHosts } from "./gitLabAuthStatus.ts";
2021

@@ -83,31 +84,36 @@ function parseGitLabAuth(input: SourceControlAuthProbeInput) {
8384
});
8485
}
8586

86-
function refineUnknownGitLabRemote(input: SourceControlUnknownRemoteRefinementInput) {
87+
function refineUnknownGitLabRemote(
88+
input: SourceControlUnknownRemoteRefinementInput,
89+
): UnknownRemoteVerdict {
8790
const host = input.context.provider.name.toLowerCase();
8891
const output = combinedAuthOutput(input.auth);
8992
const hosts = parseGitLabAuthStatusHosts(output);
9093
// Output that names no host and is not glab's never-logged-in answer (a config glab could not
9194
// read) says nothing about this one.
9295
if (hosts.length === 0) {
93-
return NO_GITLAB_LOGIN_PATTERN.test(output) ? null : undefined;
96+
return { provider: null, settled: NO_GITLAB_LOGIN_PATTERN.test(output) };
9497
}
9598
const records = hosts.filter((entry) => entry.host === host);
9699

97100
if (records.length === 0) {
98-
return null;
101+
return { provider: null, settled: true };
99102
}
100103
// A record for this host with no account (its API call failed or its token was rejected) means
101104
// glab could not confirm this host either way.
102105
if (!records.some((entry) => entry.account !== null)) {
103-
return undefined;
106+
return { provider: null, settled: false };
104107
}
105108

106109
return {
107-
kind: SourceControlProviderKind.make("gitlab"),
108-
name: "GitLab Self-Hosted",
109-
baseUrl: input.context.provider.baseUrl,
110-
} as const;
110+
provider: {
111+
kind: SourceControlProviderKind.make("gitlab"),
112+
name: "GitLab Self-Hosted",
113+
baseUrl: input.context.provider.baseUrl,
114+
},
115+
settled: true,
116+
};
111117
}
112118

113119
export const discovery = {

0 commit comments

Comments
 (0)