Skip to content

An open-source, faster Devin alternative

TypeScript

Align Flue repository tool input bounds

Igor Zalutski31e47d7bc44a
diff --git a/sdks/flue/src/repo.test.ts b/sdks/flue/src/repo.test.ts
index 1093487f..9636b813 100644
--- a/sdks/flue/src/repo.test.ts
+++ b/sdks/flue/src/repo.test.ts
@@ -79,7 +79,7 @@ describe("ocRepoTools contract", () => {
const add = tool("add_source");
expect(
v.safeParse(add.input, {
- repository: "repo_1",
+ repository: "repo_0123456789abcdef01234567",
ref: "main",
name: "app",
}).success,
@@ -87,6 +87,12 @@ describe("ocRepoTools contract", () => {
expect(
v.safeParse(add.input, { repository: "", ref: "main" }).success,
).toBe(false);
+ expect(
+ v.safeParse(add.input, {
+ repository: "owner/repo",
+ ref: "x".repeat(256),
+ }).success,
+ ).toBe(false);
const publish = tool("github_publish_pull_request");
expect(
@@ -104,6 +110,21 @@ describe("ocRepoTools contract", () => {
idempotency_key: "model-controlled",
}).success,
).toBe(false);
+ for (const invalid of [
+ { source: "Bad Source", title: "Document setup", base: "main" },
+ { source: "app", title: " ", base: "main" },
+ { source: "app", title: "x".repeat(257), base: "main" },
+ {
+ source: "app",
+ title: "Document setup",
+ body: "x".repeat(65_537),
+ base: "main",
+ },
+ { source: "app", title: "Document setup", base: "../main" },
+ { source: "app", title: "Document setup", base: "bad ref" },
+ ]) {
+ expect(v.safeParse(publish.input, invalid).success).toBe(false);
+ }
});
});
@@ -308,7 +329,11 @@ describe("add_source HTTP fixture", () => {
vi.stubGlobal("fetch", fetchSpy);
const result = await tool("add_source").run({
- input: { repository: "repo_1", ref: "main", name: "app" },
+ input: {
+ repository: "repo_0123456789abcdef01234567",
+ ref: "main",
+ name: "app",
+ },
});
expect(result).toEqual({
@@ -332,7 +357,7 @@ describe("add_source HTTP fixture", () => {
"content-type": "application/json",
},
body: JSON.stringify({
- repository: "repo_1",
+ repository: "repo_0123456789abcdef01234567",
ref: "main",
name: "app",
}),
@@ -357,7 +382,11 @@ describe("add_source HTTP fixture", () => {
await expect(
tool("add_source").run({
- input: { repository: "repo_1", ref: "main", name: "app" },
+ input: {
+ repository: "repo_0123456789abcdef01234567",
+ ref: "main",
+ name: "app",
+ },
}),
).rejects.toThrow("repository API returned an invalid response");
});
diff --git a/sdks/flue/src/repo.ts b/sdks/flue/src/repo.ts
index 745e2ff7..0142589d 100644
--- a/sdks/flue/src/repo.ts
+++ b/sdks/flue/src/repo.ts
@@ -87,6 +87,25 @@ const SourceNameSchema = v.pipe(
v.regex(/^[a-z0-9][a-z0-9_-]{0,63}$/),
);
+const RepositoryTargetSchema = v.pipe(
+ v.string(),
+ v.regex(
+ /^(?:repo_[a-z0-9]{24}|[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})\/[A-Za-z0-9._-]{1,100})$/,
+ ),
+);
+
+const RefSchema = v.pipe(
+ v.string(),
+ v.minLength(1),
+ v.maxLength(255),
+);
+
+const PullRequestBaseSchema = v.pipe(
+ v.string(),
+ v.regex(/^[A-Za-z0-9][A-Za-z0-9._/-]{0,254}$/),
+ v.check((ref) => !ref.includes(".."), "base cannot contain '..'"),
+);
+
const AddSourceSuccessSchema = v.pipe(
v.strictObject({
ok: v.literal(true),
@@ -181,15 +200,13 @@ const ListWorkingReposInputSchema = v.strictObject({
const AddSourceInputSchema = v.strictObject({
repository: v.pipe(
- v.string(),
- v.minLength(1),
+ RepositoryTargetSchema,
v.description(
"An exact repo_… id returned by list_working_repos, or exact owner/repository coordinates from that list.",
),
),
ref: v.pipe(
- v.string(),
- v.minLength(1),
+ RefSchema,
v.description("The branch, tag, or commit to pin."),
),
name: v.optional(
@@ -204,17 +221,19 @@ const AddSourceInputSchema = v.strictObject({
const PublishPullRequestInputSchema = v.strictObject({
source: v.pipe(
- v.string(),
- v.minLength(1),
+ SourceNameSchema,
v.description(
"The source name returned by add_source, not a path or repository guess.",
),
),
- title: v.pipe(v.string(), v.minLength(1)),
- body: v.optional(v.string()),
- base: v.pipe(
+ title: v.pipe(
v.string(),
- v.minLength(1),
+ v.maxLength(256),
+ v.check((title) => title.trim().length > 0, "title cannot be blank"),
+ ),
+ body: v.optional(v.pipe(v.string(), v.maxLength(65_536))),
+ base: v.pipe(
+ PullRequestBaseSchema,
v.description("Exact target branch for the pull request."),
),
draft: v.optional(v.boolean()),