GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(source-control): accept Cursor Origin URLs in repo lookup and sur… · pingdotgg/t3code@129c352

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/source-control-cursor-origin/src/server
    • OriginCli.ts
    • OriginSourceControlProvider.ts
    • originRepositoryLookup.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/source-control-cursor-origin/src/server/OriginCli.ts‎

Copy file name to clipboardExpand all lines: packages/source-control-cursor-origin/src/server/OriginCli.ts
+48Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export class OriginCliError extends Schema.TaggedError<OriginCliError>()("Origin
3636
operation: Schema.String,
3737
cwd: Schema.String,
3838
detail: Schema.String,
39+
userFacingDetail: Schema.optional(Schema.String),
3940
reason: Schema.Literals([
4041
"missing-tool",
4142
"unauthenticated",
@@ -90,6 +91,53 @@ export function originRepositoryPath(repository: string): string {
9091
return `/v1/origin/repos/${repository.split("/").map(encodeURIComponent).join("/")}`;
9192
}
9293

94+
const ORIGIN_WEB_REPOSITORY_PATH = /^\/codebase\/([^/]+\/[^/]+?)(?:\/(?:tree|blob)\/.+)?\/?$/u;
95+
96+
const INVALID_REPOSITORY_SEGMENT = /[\s:@?#\\]/u;
97+
98+
function normalizeOriginRepositoryPath(path: string): string | null {
99+
const segments = path
100+
.replace(/\/+$/u, "")
101+
.replace(/\.git$/iu, "")
102+
.split("/");
103+
if (
104+
segments.length !== 2 ||
105+
segments.some(
106+
(segment) =>
107+
segment === "" ||
108+
segment === "." ||
109+
segment === ".." ||
110+
INVALID_REPOSITORY_SEGMENT.test(segment),
111+
)
112+
) {
113+
return null;
114+
}
115+
return segments.join("/");
116+
}
117+
118+
/** Parses `owner/name` or a Cursor Origin git/web URL into `owner/name`. */
119+
export function parseOriginRepository(input: string): string | null {
120+
const trimmed = input.trim();
121+
if (trimmed.length === 0) return null;
122+
if (parseGitRemoteHost(trimmed)?.hostname === CURSOR_ORIGIN_GIT_HOST) {
123+
const remotePath = repositoryPathFromRemoteUrl(trimmed);
124+
return remotePath === null ? null : normalizeOriginRepositoryPath(remotePath);
125+
}
126+
const url = URL.parse(trimmed);
127+
if (url !== null) {
128+
const hostname = url.hostname.toLowerCase();
129+
if (
130+
(url.protocol !== "https:" && url.protocol !== "http:") ||
131+
(hostname !== "cursor.com" && hostname !== "www.cursor.com")
132+
) {
133+
return null;
134+
}
135+
const webPath = ORIGIN_WEB_REPOSITORY_PATH.exec(url.pathname)?.[1];
136+
return webPath === undefined ? null : normalizeOriginRepositoryPath(webPath);
137+
}
138+
return normalizeOriginRepositoryPath(trimmed);
139+
}
140+
93141
/** The message an Origin error body carries, Connect-style or REST-style. */
94142
function errorBodyMessage(body: string): string | null {
95143
const decoded = decodeJsonResult(
Collapse file

‎packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts‎

Copy file name to clipboardExpand all lines: packages/source-control-cursor-origin/src/server/OriginSourceControlProvider.ts
+27-2Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,37 @@ export const make = Effect.gen(function* () {
221221

222222
getRepositoryCloneUrls: Effect.fn("OriginSourceControlProvider.getRepositoryCloneUrls")(
223223
function* (input) {
224+
const repositoryName = OriginCli.parseOriginRepository(input.repository);
225+
if (repositoryName === null) {
226+
const detail = "Specify an Origin repository as owner/name or a Cursor Origin URL.";
227+
return yield* new OriginCli.OriginCliError({
228+
operation: "getRepositoryCloneUrls",
229+
cwd: input.cwd,
230+
reason: "failed",
231+
detail,
232+
userFacingDetail: detail,
233+
});
234+
}
224235
const repository = yield* getRepository(
225236
input.cwd,
226-
input.repository,
237+
repositoryName,
227238
"getRepositoryCloneUrls",
239+
).pipe(
240+
Effect.mapError((error) =>
241+
error.reason === "not-found"
242+
? new OriginCli.OriginCliError({
243+
...error,
244+
userFacingDetail: SourceControlProvider.repositoryNotFoundDetail(repositoryName),
245+
})
246+
: error.httpStatus === 403
247+
? new OriginCli.OriginCliError({
248+
...error,
249+
userFacingDetail: `Your Cursor account does not have access to ${SourceControlProvider.transportSafeSourceControlErrorValue(repositoryName)} on Origin. Ask the repository owner for access and try again.`,
250+
})
251+
: error,
252+
),
228253
);
229-
return cloneUrls(repository, input.repository);
254+
return cloneUrls(repository, repositoryName);
230255
},
231256
(effect, input) =>
232257
effect.pipe(
Collapse file

‎packages/source-control-cursor-origin/src/server/originRepositoryLookup.test.ts‎

Copy file name to clipboard
+184Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import { assert, describe, it } from "@effect/vitest";
2+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
3+
import * as Effect from "effect/Effect";
4+
import * as Layer from "effect/Layer";
5+
import * as Schema from "effect/Schema";
6+
import * as SourceControlHost from "@t3tools/source-control-core/server/SourceControlHost";
7+
import * as SourceControlProvider from "@t3tools/source-control-core/server/SourceControlProvider";
8+
9+
import * as OriginCli from "./OriginCli.ts";
10+
import * as OriginSourceControlProvider from "./OriginSourceControlProvider.ts";
11+
12+
type HostService = SourceControlHost.SourceControlHost["Service"];
13+
14+
const unusedService = <T extends object>(name: string): T =>
15+
new Proxy({} as T, {
16+
get: (_, property) => () => Effect.die(`unexpected ${name}.${String(property)} call`),
17+
});
18+
19+
const makeProvider = (api: OriginCli.OriginCli["Service"]["api"]) =>
20+
OriginSourceControlProvider.make.pipe(
21+
Effect.provide(
22+
Layer.mergeAll(
23+
NodeFileSystem.layer,
24+
Layer.succeed(SourceControlHost.SourceControlHost, {
25+
settings: unusedService<HostService["settings"]>("host.settings"),
26+
process: unusedService<HostService["process"]>("host.process"),
27+
git: unusedService<HostService["git"]>("host.git"),
28+
}),
29+
Layer.mock(OriginCli.OriginCli)({ api }),
30+
),
31+
),
32+
);
33+
34+
describe("OriginSourceControlProvider.getRepositoryCloneUrls", () => {
35+
it.effect("normalizes owner/name and Cursor Origin URLs before querying the API", () =>
36+
Effect.gen(function* () {
37+
const requestedPaths: Array<string> = [];
38+
const provider = yield* makeProvider((input, schema) => {
39+
requestedPaths.push(input.path);
40+
return Schema.decodeEffect(schema)({ name: "mic-mute-tray" }).pipe(Effect.orDie);
41+
});
42+
43+
const validInputs = [
44+
"bedair81/mic-mute-tray",
45+
" bedair81/mic-mute-tray.git ",
46+
"https://origin.cursor.com/bedair81/mic-mute-tray.git",
47+
"https://origin.cursor.com/bedair81/mic-mute-tray/",
48+
"[email protected]:bedair81/mic-mute-tray.git",
49+
"ssh://[email protected]/bedair81/mic-mute-tray.git",
50+
"https://cursor.com/codebase/bedair81/mic-mute-tray",
51+
"https://www.cursor.com/codebase/bedair81/mic-mute-tray/",
52+
"https://cursor.com/codebase/bedair81/mic-mute-tray/tree/main",
53+
"https://cursor.com/codebase/bedair81/mic-mute-tray/blob/main/README.md",
54+
];
55+
56+
for (const repository of validInputs) {
57+
const result = yield* provider.getRepositoryCloneUrls({ cwd: "/repo", repository });
58+
assert.deepStrictEqual(
59+
result,
60+
{
61+
nameWithOwner: "bedair81/mic-mute-tray",
62+
url: "https://origin.cursor.com/bedair81/mic-mute-tray.git",
63+
sshUrl: "https://origin.cursor.com/bedair81/mic-mute-tray.git",
64+
},
65+
repository,
66+
);
67+
}
68+
69+
assert.deepStrictEqual(
70+
requestedPaths,
71+
validInputs.map(() => "/v1/origin/repos/bedair81/mic-mute-tray"),
72+
);
73+
}),
74+
);
75+
76+
it.effect("rejects malformed or foreign repository inputs with user-facing guidance", () =>
77+
Effect.gen(function* () {
78+
let apiCalls = 0;
79+
const provider = yield* makeProvider(() => {
80+
apiCalls += 1;
81+
return Effect.die("api should not be called for invalid repository input");
82+
});
83+
84+
const invalidInputs = [
85+
"",
86+
"mic-mute-tray",
87+
"bedair81/mic-mute-tray/tree/main",
88+
"https://origin.cursor.com/bedair81/mic-mute-tray/tree/main",
89+
"https://cursor.com/codebase/bedair81",
90+
"https://cursor.com/settings/billing",
91+
"https://github.com/bedair81/mic-mute-tray",
92+
"[email protected]:bedair81/mic-mute-tray.git",
93+
"bedair81/.git",
94+
"../secret",
95+
];
96+
97+
for (const repository of invalidInputs) {
98+
const error = yield* Effect.flip(
99+
provider.getRepositoryCloneUrls({ cwd: "/repo", repository }),
100+
);
101+
assert.strictEqual(
102+
SourceControlProvider.userFacingSourceControlDetail(error.cause),
103+
"Specify an Origin repository as owner/name or a Cursor Origin URL.",
104+
repository,
105+
);
106+
}
107+
108+
assert.strictEqual(apiCalls, 0);
109+
}),
110+
);
111+
112+
it.effect("surfaces not-found and no-access details without exposing raw upstream errors", () =>
113+
Effect.gen(function* () {
114+
const notFoundProvider = yield* makeProvider(() =>
115+
Effect.fail(
116+
new OriginCli.OriginCliError({
117+
operation: "getRepositoryCloneUrls",
118+
cwd: "/repo",
119+
reason: "not-found",
120+
httpStatus: 404,
121+
detail: "repository not found",
122+
}),
123+
),
124+
);
125+
126+
const notFound = yield* Effect.flip(
127+
notFoundProvider.getRepositoryCloneUrls({
128+
cwd: "/repo",
129+
repository: "https://origin.cursor.com/bedair81/missing.git",
130+
}),
131+
);
132+
assert.strictEqual(
133+
SourceControlProvider.userFacingSourceControlDetail(notFound.cause),
134+
SourceControlProvider.repositoryNotFoundDetail("bedair81/missing"),
135+
);
136+
137+
const forbiddenProvider = yield* makeProvider(() =>
138+
Effect.fail(
139+
new OriginCli.OriginCliError({
140+
operation: "getRepositoryCloneUrls",
141+
cwd: "/repo",
142+
reason: "failed",
143+
httpStatus: 403,
144+
detail: "You do not have access to bedair81/mic-mute-tray on Origin.",
145+
}),
146+
),
147+
);
148+
149+
const forbidden = yield* Effect.flip(
150+
forbiddenProvider.getRepositoryCloneUrls({
151+
cwd: "/repo",
152+
repository: "https://cursor.com/codebase/bedair81/mic-mute-tray/tree/main",
153+
}),
154+
);
155+
assert.strictEqual(
156+
SourceControlProvider.userFacingSourceControlDetail(forbidden.cause),
157+
"Your Cursor account does not have access to bedair81/mic-mute-tray on Origin. Ask the repository owner for access and try again.",
158+
);
159+
160+
const serverErrorProvider = yield* makeProvider(() =>
161+
Effect.fail(
162+
new OriginCli.OriginCliError({
163+
operation: "getRepositoryCloneUrls",
164+
cwd: "/repo",
165+
reason: "failed",
166+
httpStatus: 500,
167+
detail: "upstream internal details",
168+
}),
169+
),
170+
);
171+
172+
const serverError = yield* Effect.flip(
173+
serverErrorProvider.getRepositoryCloneUrls({
174+
cwd: "/repo",
175+
repository: "bedair81/mic-mute-tray",
176+
}),
177+
);
178+
assert.strictEqual(
179+
SourceControlProvider.userFacingSourceControlDetail(serverError.cause),
180+
undefined,
181+
);
182+
}),
183+
);
184+
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.