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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@
"verify": "node ./scripts/check-architecture.mts && knip && vp check . && vp run skills:lint && vp run smoke:pack && vp test run --coverage"
},
"dependencies": {
"@effect/platform-node": "4.1.2",
"@effect/platform-node-shared": "4.1.2",
"@effect/platform-node": "4.1.4",
"@effect/platform-node-shared": "4.1.4",
"@sentry/core": "10.78.0",
"cli-table3": "^0.6.5",
"effect": "4.1.2",
"effect": "4.1.4",
"i18next": "^26.7.2"
},
"devDependencies": {
"@effect/vitest": "4.1.2",
"@effect/vitest": "4.1.4",
"@oxlint/plugins": "1.91.0",
"@putdotio/sdk": "15.0.1",
"@putdotio/sdk": "16.0.1",
"@types/node": "^26.1.0",
"@uinaf/oxlint-plugin-no-comments": "1.1.0",
"@uinaf/skillcheck": "1.7.7",
Expand All @@ -78,6 +78,6 @@
},
"packageManager": "pnpm@12.18.0",
"inlinedDependencies": {
"@putdotio/sdk": "15.0.1"
"@putdotio/sdk": "16.0.1"
}
}
76 changes: 38 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions skills/putio-cli/references/guardrails.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ copies the HTTP status into `statusCode` when the body is malformed, so matching
and `errorType` matching the operation's known missing-file type. Unknown,
empty, or unrelated types do not qualify; neither does prose.

Title `Unexpected response from put.io` means a successful response broke the
API contract: malformed, not JSON, or missing a requested field, which
`error.details` names as `["missing field", "<name>"]`. Retry once, then report
it. Title `Invalid request` means the input was rejected before any request.

If a command fails:

1. Re-run with structured output.
Expand Down
1 change: 1 addition & 0 deletions skills/putio-cli/references/writes.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ Rules:
- Take required keys from `describe`; never guess names.
- Treat every `sdk call` operation as potentially mutating and inspect its dry-run before `--execute`.
- `sdk call` args are the SDK function's positional parameters and must match its input schema. A mismatch fails with title `Invalid SDK arguments` before any request; `error.details` names the `operation` and the schema `issue` with its path.
- Bulk selections (`downloadLinks.create`, `sharing.clone`, `sharing.shareFiles`, `zips.create`) need `ids` or a `cursor`; `zips.create` names them `file_ids`.
- `files upload` sends to `PUTIO_CLI_UPLOAD_BASE_URL`, or upload.put.io with the default API base. With a custom `PUTIO_CLI_API_BASE_URL` and no upload base, it fails before sending anything; set both together.
48 changes: 46 additions & 2 deletions src/command-paths.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ const routeReads = (api: FixtureApi) => {
"GET /v2/files/search",
ok({ cursor: null, files: [file(2, "movie.mkv", { file_type: "VIDEO", size: 42 })], total: 1 }),
);
api.route("GET /v2/transfers/list", ok({ cursor: null, transfers: [transfer(7, "ubuntu.iso")] }));
api.route(
"GET /v2/transfers/list",
ok({ cursor: null, total: 1, transfers: [transfer(7, "ubuntu.iso")] }),
);
api.route("GET /v2/transfers/7", ok({ transfer: transfer(7, "ubuntu.iso", "COMPLETED") }));
};

Expand Down Expand Up @@ -612,6 +615,33 @@ describe("reads", () => {
]);
});

it("names the missing field when a transfers page omits its total", async () => {
api.route("GET /v2/transfers/list", ok({ cursor: null, transfers: [] }));

const run = await putio("transfers", "list", "--output", "json");

expect(run.exitCode).toBe(1);
expect(run.stdout).toBe("");
expect(stderrJson(run).error).toMatchObject({
details: [["missing field", "total"]],
message: "put.io returned data the CLI did not expect.",
title: "Unexpected response from put.io",
});
});

it("reports a successful response that is not JSON as an unexpected response", async () => {
api.route("GET /v2/files/list", () => ({ body: "<html>", contentType: "text/html" }));

const run = await putio("files", "list", "--output", "json");

expect(run.exitCode).toBe(1);
expect(run.stdout).toBe("");
expect(stderrJson(run).error).toMatchObject({
message: "put.io returned data the CLI did not expect.",
title: "Unexpected response from put.io",
});
});

it.each([
["json", (run: CliRun) => stdoutJson(run)],
["ndjson", (run: CliRun) => stdoutLines(run)[0]],
Expand Down Expand Up @@ -687,7 +717,7 @@ describe("pagination", () => {
{
args: ["transfers", "list"],
continuePath: "/v2/transfers/list/continue",
first: { path: "GET /v2/transfers/list", page: {} },
first: { path: "GET /v2/transfers/list", page: { total: 3 } },
itemKey: "transfers",
items: [transfer(7, "ubuntu.iso"), transfer(8, "fedora.iso"), transfer(9, "debian.iso")],
},
Expand Down Expand Up @@ -1262,6 +1292,20 @@ describe("sdk call", () => {
],
["--dry-run", "missing argument", "transfers.get", "[]", "Missing key at [0]"],
["--dry-run", "argument for a nullary operation", "zips.list", "[1]", /at \[0\]/],
["--dry-run", "no selection", "downloadLinks.create", "[{}]", /Missing key/],
["--dry-run", "no selection", "sharing.clone", '[{"parentId":0}]', /Missing key/],
[
"--dry-run",
"no selection",
"sharing.shareFiles",
'[{"target":{"type":"everyone"}}]',
/Missing key/,
],
["--dry-run", "no selection", "zips.create", '[{"exclude_ids":[1]}]', /Missing key/],
["--dry-run", "empty ids", "downloadLinks.create", '[{"ids":[]}]', /length of at least 1/],
["--dry-run", "non-positive id", "sharing.clone", '[{"ids":[0]}]', /greater than 0/],
["--dry-run", "empty cursor", "zips.create", '[{"cursor":""}]', /length of at least 1/],
["--dry-run", "negative parent", "sharing.clone", '[{"ids":[1],"parentId":-1}]', /parentId/],
])("rejects %s args with %s before any request", async (mode, _label, operation, args, issue) => {
const run = await putio(
"sdk",
Expand Down
29 changes: 16 additions & 13 deletions src/commands/download-links.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Command } from "effect/cli";
import { DownloadLinksCreateInputSchema } from "@putdotio/sdk";
import { DownloadLinksCreateInputSchema, type FilesBulkSelection } from "@putdotio/sdk";
import { Data, Effect, Option, Predicate, Schema } from "effect";

import {
Expand Down Expand Up @@ -54,20 +54,23 @@ export type DownloadLinksCreateInput = Schema.Schema.Type<typeof DownloadLinksCr
const selectionIds = (value: ReadonlyArray<number> | string | undefined) =>
value === undefined || Predicate.isString(value) ? [] : value;

export const resolveDownloadLinksCreateInput = (input: DownloadLinksCreateInput) => {
const normalized = {
cursor: input.cursor,
excludeIds: toOptionalIds(selectionIds(input.excludeIds)),
ids: toOptionalIds(selectionIds(input.ids)),
};

if (!normalized.cursor && !normalized.ids) {
throw new DownloadLinksCommandError({
message: "Provide at least one --id or a --cursor to create download links.",
});
export const resolveDownloadLinksCreateInput = (
input: DownloadLinksCreateInput,
): FilesBulkSelection => {
const excludeIds = toOptionalIds(selectionIds(input.excludeIds));
const ids = toOptionalIds(selectionIds(input.ids));

if (ids !== undefined) {
return { cursor: input.cursor, excludeIds, ids };
}

if (input.cursor) {
return { cursor: input.cursor, excludeIds, ids };
}

return normalized;
throw new DownloadLinksCommandError({
message: "Provide at least one --id or a --cursor to create download links.",
});
};

const downloadLinksCreate = Command.make(
Expand Down
8 changes: 4 additions & 4 deletions src/commands/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ const NonBlankStringSchema = Schema.String.check(
),
);

const NonEmptyIdsSchema = Schema.Array(Schema.Number).check(Schema.isNonEmpty());
const NonEmptyIdsSchema = Schema.Array(Schema.Finite).check(Schema.isNonEmpty());
const PositiveIntegerSchema = Schema.Int.check(Schema.isGreaterThan(0));
const NonNegativeIntegerSchema = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));

const FilesMkdirInputSchema = Schema.Struct({
name: NonBlankStringSchema,
parent_id: Schema.optional(Schema.Number),
parent_id: Schema.optional(Schema.Finite),
});

const FilesRenameInputSchema = Schema.Struct({
file_id: Schema.Number,
file_id: Schema.Finite,
name: NonBlankStringSchema,
});

Expand All @@ -137,7 +137,7 @@ const FilesDeleteInputSchema = Schema.Struct({

const FilesMoveInputSchema = Schema.Struct({
ids: NonEmptyIdsSchema,
parent_id: Schema.Number,
parent_id: Schema.Finite,
});

const FilesUploadInputSchema = Schema.Struct({
Expand Down
Loading