Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions packages/contracts/src/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,25 @@ import {
const decodeProjectCreatePayload = Schema.decodeUnknownSync(ProjectCreatePayload);
const decodeProjectUpdatePayload = Schema.decodeUnknownSync(ProjectUpdatePayload);
const decodeProjectMutation = Schema.decodeUnknownSync(ProjectMutation);
const decodeProjectReadFileInput = Schema.decodeUnknownSync(ProjectReadFileInput);
const decodeProjectWriteFileInput = Schema.decodeUnknownSync(ProjectWriteFileInput);

describe("project RPC errors", () => {
it("accepts deeply nested file paths longer than 512 characters", () => {
const relativePath = ["a".repeat(200), "b".repeat(200), "c".repeat(110), "demo.txt"].join("/");
expect(relativePath).toHaveLength(521);
const cwd = "/workspace";
expect(decodeProjectReadFileInput({ cwd, relativePath })).toEqual({
cwd,
relativePath,
});
expect(decodeProjectWriteFileInput({ cwd, relativePath, contents: "edited" })).toEqual({
cwd,
relativePath,
contents: "edited",
});
});

it("keeps whitespace in file paths across the wire", () => {
const roundTrip = <S extends Schema.Codec<unknown, unknown>>(schema: S, value: S["Type"]) =>
Schema.decodeUnknownSync(schema)(Schema.encodeSync(schema)(value));
Expand Down
7 changes: 3 additions & 4 deletions packages/contracts/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import {
const PROJECT_SEARCH_ENTRIES_MAX_LIMIT = 200;
const PROJECT_SEARCH_CONTENTS_MAX_LIMIT = 500;
export const PROJECT_SEARCH_CONTENTS_QUERY_MAX_LENGTH = 256;
const PROJECT_WRITE_FILE_PATH_MAX_LENGTH = 512;
const PROJECT_READ_FILE_PATH_MAX_LENGTH = 512;
const PROJECT_FILE_PATH_MAX_LENGTH = 4096;

export const ProjectScriptIcon = Schema.Literals([
"play",
Expand Down Expand Up @@ -478,7 +477,7 @@ export class ProjectListEntriesError extends Schema.TaggedError<ProjectListEntri
export const ProjectReadFileInput = Schema.Struct({
cwd: TrimmedNonEmptyString,
// Workspace-relative or absolute host path; only workspace-relative paths are writable.
relativePath: Schema.NonEmptyString.check(Schema.isMaxLength(PROJECT_READ_FILE_PATH_MAX_LENGTH)),
relativePath: Schema.NonEmptyString.check(Schema.isMaxLength(PROJECT_FILE_PATH_MAX_LENGTH)),
// Optional files can be absent without failing the read.
allowMissing: Schema.optional(Schema.Boolean),
});
Expand Down Expand Up @@ -555,7 +554,7 @@ export class ProjectReadFileError extends Schema.TaggedError<ProjectReadFileErro

export const ProjectWriteFileInput = Schema.Struct({
cwd: TrimmedNonEmptyString,
relativePath: Schema.NonEmptyString.check(Schema.isMaxLength(PROJECT_WRITE_FILE_PATH_MAX_LENGTH)),
relativePath: Schema.NonEmptyString.check(Schema.isMaxLength(PROJECT_FILE_PATH_MAX_LENGTH)),
contents: Schema.String,
});
export type ProjectWriteFileInput = typeof ProjectWriteFileInput.Type;
Expand Down
Loading