From 07e10627c80dcbdf541084fa5d3d17de57e2b794 Mon Sep 17 00:00:00 2001 From: Altay Date: Thu, 12 Nov 2026 19:54:07 +0300 Subject: [PATCH 1/2] fix: stop reporting invalid input as a crash, gate on Effect diagnostics Validators that throw ran outside Effect.try in several command handlers, so a typo such as `putio files hls-manifest 0` became a defect and raised a crash report. They now fail as CliCommandInputError. The command-path harness records crash reports and expects none on an expected failure. `download-links create` without a selection prints its own message again. @effect/tsgo adds the Effect correctness and strict diagnostics to `vp run check`, the verify gate and the staged hook. The fixes they asked for are equivalent forms. Rules that would change exported shapes or that the dynamic SDK call cannot satisfy are off by file in vite.config.ts. tsconfig lists the unstable Effect modules the CLI accepts and no longer asks for declaration output nothing consumes. @effect/tsgo and its platform packages are exempt from the pnpm release age: 0.68.1 is under a day old. --- AGENTS.md | 7 ++- CONTRIBUTING.md | 7 ++- knip.json | 2 +- package.json | 5 +- pnpm-lock.yaml | 73 +++++++++++++++++++++++++++ pnpm-workspace.yaml | 2 + renovate.json | 10 +++- scripts/smoke-packed-install.mts | 2 +- src/cli.test.ts | 2 +- src/cli.ts | 8 ++- src/command-paths.test.ts | 10 ++++ src/commands/auth.ts | 67 ++++++++++--------------- src/commands/download-links.test.ts | 2 +- src/commands/download-links.ts | 14 +++--- src/commands/files.ts | 78 ++++++++++++++++------------- src/commands/sdk.ts | 18 +++---- src/internal/auth-flow.test.ts | 2 +- src/internal/auth-flow.ts | 4 +- src/internal/command-specs.ts | 4 +- src/internal/command.test.ts | 2 +- src/internal/command.ts | 34 ++++++------- src/internal/local-upload.ts | 8 ++- src/internal/sdk-operation-args.ts | 2 +- src/internal/state.test.ts | 7 ++- src/internal/state.ts | 34 +++++-------- src/test-support/run-cli.ts | 17 ++++++- tsconfig.json | 20 ++++++-- vite.config.ts | 34 ++++++++++++- 28 files changed, 309 insertions(+), 166 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 11838b7..449d98d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -23,9 +23,14 @@ The installed version's guide is `node_modules/effect/AGENTS.md`; consult it for the APIs the change touches, and search `node_modules/effect/src` for anything it does not cover. Keep the pinned `effect` version. +`@effect/tsgo` adds Effect diagnostics to lint. Bare `vp check` cannot load them +and stops at `Unknown plugin: effecttsgo`; use `pnpm exec vp run check`. Rule +overrides are in [vite.config.ts](vite.config.ts), the unstable modules the CLI +accepts in [tsconfig.json](tsconfig.json). + ## Proof -- Docs only: `pnpm exec vp check .`, plus `pnpm exec vp run skills:lint` for `skills/*`; no runtime proof. +- Docs only: `pnpm exec vp run check`, plus `pnpm exec vp run skills:lint` for `skills/*`; no runtime proof. - Source change: `pnpm exec vp run verify`. Prefer in-process tests unless the process boundary is the behavior under test; add command-path coverage when the `effect/cli` command boundary changes. - Commands, flags, output, auth, or config persistence: also `pnpm exec vp run build`, then drive the changed command with the `verify-putio-cli` skill, which sandboxes the binary against a fixture API. - Standalone binary bundling: `pnpm exec vp run build:sea`, then `pnpm exec vp run verify:sea`. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6728a40..f33dcbd 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -40,8 +40,11 @@ in [AGENTS.md](AGENTS.md#proof). ## Effect Versions -Keep `effect` and every `@effect/*` package in [`package.json`](package.json) on -one exact version; Renovate's shared `effect` group moves them together. The +Keep `effect` and every `@effect/*` runtime and test package in +[`package.json`](package.json) on one exact version; Renovate's shared `effect` +group moves them together. `@effect/tsgo` versions separately and moves in its +own group, because each release supports a fixed set of Oxlint and TypeScript +versions. The `@putdotio/sdk>effect` override in [`pnpm-workspace.yaml`](https://github.com/putdotio/putio-cli/blob/main/pnpm-workspace.yaml) holds the SDK on that version; `smoke:pack` fails if the packed install diff --git a/knip.json b/knip.json index 93d6678..83b3fe9 100644 --- a/knip.json +++ b/knip.json @@ -2,5 +2,5 @@ "$schema": "https://unpkg.com/knip@6/schema.json", "entry": ["src/index.ts", "src/bin.ts", "src/sea.ts", ".agents/skills/*/scripts/*.mjs"], "ignore": ["tools/oxlint/anti-slop/**"], - "ignoreDependencies": ["@effect/platform-node-shared", "postject"] + "ignoreDependencies": ["@effect/language-service", "@effect/platform-node-shared", "postject"] } diff --git a/package.json b/package.json index 3a534d0..878798d 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ "scripts": { "build": "vp pack", "build:sea": "node ./scripts/build-sea.mts", - "check": "vp check .", + "check": "effect-tsgo vp check .", "check:architecture": "node ./scripts/check-architecture.mts", "check:dead-code": "knip", "coverage": "vp test run --coverage", @@ -46,7 +46,7 @@ "test": "vp test", "prepublishOnly": "npm run build", "verify:sea": "node ./scripts/verify-sea.mjs", - "verify": "node ./scripts/check-architecture.mts && knip && vp check . && vp run skills:lint && vp run smoke:pack && vp test run --coverage" + "verify": "node ./scripts/check-architecture.mts && knip && effect-tsgo vp check . && vp run skills:lint && vp run smoke:pack && vp test run --coverage" }, "dependencies": { "@effect/platform-node": "4.1.4", @@ -57,6 +57,7 @@ "i18next": "^26.7.2" }, "devDependencies": { + "@effect/tsgo": "0.68.1", "@effect/vitest": "4.1.4", "@oxlint/plugins": "1.91.0", "@putdotio/sdk": "16.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7ab2ba5..1bdb8d2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -199,6 +199,9 @@ importers: specifier: ^26.7.2 version: 26.7.2(typescript@7.0.2) devDependencies: + '@effect/tsgo': + specifier: 0.68.1 + version: 0.68.1 '@effect/vitest': specifier: 4.1.4 version: 4.1.4(effect@4.1.4)(vitest@5.1.0) @@ -296,6 +299,45 @@ packages: effect: ^4.1.4 redis: '>=5.1.0 <7.0.0' + '@effect/tsgo-darwin-arm64@0.68.1': + resolution: {integrity: sha512-G1jbH4HY07ZmiaZDeDshbIbl1Uqk5xPe5he0xYlOsoostQo94ockJQ5NpGRzSzMCMyypXRw91JYMcLWkFjv8Xw==} + cpu: [arm64] + os: [darwin] + + '@effect/tsgo-darwin-x64@0.68.1': + resolution: {integrity: sha512-d+MfXIXaDMAVycq0BSJL3BEKhVnt4bu4BuEhuh8K1bFetARx4CSY/LFUsez6ZbSIcj0ULpnYf9ROmJEhCBagFA==} + cpu: [x64] + os: [darwin] + + '@effect/tsgo-linux-arm64@0.68.1': + resolution: {integrity: sha512-KfNno5pvOvXNdEyJBZmalErcbJ/C7vaj/d60eM1xuoWgzIzjz2M0+Lsnkcl3qms1diM2a8yYdUIgmREL8VYOuQ==} + cpu: [arm64] + os: [linux] + + '@effect/tsgo-linux-arm@0.68.1': + resolution: {integrity: sha512-nhvq22/tGwdfISV7ZS4iqYyaBdPq8xFc7z+YmEEU37Y+I4gtBzNsX688Cd3SzAjfPTbQSRMCnp+BF4kft7rPSw==} + cpu: [arm] + os: [linux] + + '@effect/tsgo-linux-x64@0.68.1': + resolution: {integrity: sha512-GYGnGN8gfs+LZ7Csn7hSGllPfcDU/bAsoggBySPEDiUQXEqAwbkMJHBTtAKURwVVs9qdMZTnj+Uc+b0kuOWMsg==} + cpu: [x64] + os: [linux] + + '@effect/tsgo-win32-arm64@0.68.1': + resolution: {integrity: sha512-2GiZWSnB32MQLgZUoDj7W2t88+tinkCF3WphXlHzairAEtTYoX9cBlCrDLEZ9La3uNAfmooZ8AReKLQtOigvZg==} + cpu: [arm64] + os: [win32] + + '@effect/tsgo-win32-x64@0.68.1': + resolution: {integrity: sha512-HjvFHWpyyAIJ1yozzi8PCPo2KOZ4tCjyFCxgWhNOH4hmvbKtLFBl/Iw6t6LtIbeOkdDDkGLD2Q3lxmLRKE7hgw==} + cpu: [x64] + os: [win32] + + '@effect/tsgo@0.68.1': + resolution: {integrity: sha512-/5zgc4EzB3ca9w8M09C8hNZcKChWVw29lIiBGfeLAz+TYFUETp2XqOSdT+GZIJlQlr0roFpQsdvJCq0RUPvNog==} + hasBin: true + '@effect/vitest@4.1.4': resolution: {integrity: sha512-AKpZ6zKihCRhY7hDbiQ2yp/krw+afIkxDRjFMwwzMiyhd0iYk0WaHa9J6GGC7TUF/C7HP2dZyMVq5xC0Qm/2/g==} peerDependencies: @@ -2009,6 +2051,37 @@ snapshots: - bufferutil - utf-8-validate + '@effect/tsgo-darwin-arm64@0.68.1': + optional: true + + '@effect/tsgo-darwin-x64@0.68.1': + optional: true + + '@effect/tsgo-linux-arm64@0.68.1': + optional: true + + '@effect/tsgo-linux-arm@0.68.1': + optional: true + + '@effect/tsgo-linux-x64@0.68.1': + optional: true + + '@effect/tsgo-win32-arm64@0.68.1': + optional: true + + '@effect/tsgo-win32-x64@0.68.1': + optional: true + + '@effect/tsgo@0.68.1': + optionalDependencies: + '@effect/tsgo-darwin-arm64': 0.68.1 + '@effect/tsgo-darwin-x64': 0.68.1 + '@effect/tsgo-linux-arm': 0.68.1 + '@effect/tsgo-linux-arm64': 0.68.1 + '@effect/tsgo-linux-x64': 0.68.1 + '@effect/tsgo-win32-arm64': 0.68.1 + '@effect/tsgo-win32-x64': 0.68.1 + '@effect/vitest@4.1.4(effect@4.1.4)(vitest@5.1.0)': dependencies: effect: 4.1.4 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index f8f5464..b7a1bb0 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -8,6 +8,8 @@ allowBuilds: minimumReleaseAgeExclude: - "@putdotio/*" + - "@effect/tsgo" + - "@effect/tsgo-*" catalog: vite: npm:@voidzero-dev/vite-plus-core@1.5.0 vitest: 5.1.0 diff --git a/renovate.json b/renovate.json index e5f12a0..0b70375 100644 --- a/renovate.json +++ b/renovate.json @@ -1,4 +1,12 @@ { "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": ["github>putdotio/.github:renovate-vite-plus"] + "extends": ["github>putdotio/.github:renovate-vite-plus"], + "packageRules": [ + { + "description": "@effect/tsgo supports a fixed set of Oxlint and TypeScript versions, so it moves on its own instead of with the effect group", + "matchPackageNames": ["@effect/tsgo"], + "groupName": "effect-tsgo", + "groupSlug": "effect-tsgo" + } + ] } diff --git a/scripts/smoke-packed-install.mts b/scripts/smoke-packed-install.mts index 41a3ac0..b639952 100644 --- a/scripts/smoke-packed-install.mts +++ b/scripts/smoke-packed-install.mts @@ -47,7 +47,7 @@ const UseResult = Schema.Struct({ const TransfersList = Schema.Struct({ cursor: Schema.NullOr(Schema.String), - total: Schema.Number, + total: Schema.Finite, transfers: Schema.Array(Schema.Unknown), }); diff --git a/src/cli.test.ts b/src/cli.test.ts index e9766fe..bf734ff 100644 --- a/src/cli.test.ts +++ b/src/cli.test.ts @@ -397,7 +397,7 @@ describe("cli argv parsing", () => { profile: "automation", }); - const afterUse = Schema.decodeUnknownSync(PersistedProfileSelectionSchema)( + const afterUse = Schema.decodeSync(PersistedProfileSelectionSchema)( await readFile(useResult.configPath, "utf8"), ); diff --git a/src/cli.ts b/src/cli.ts index cbe0198..dd49980 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,5 +1,5 @@ import { CliError, Command } from "effect/cli"; -import { Console, Effect, Predicate, Result, type Scope } from "effect"; +import { Console, Data, Effect, Predicate, Result, type Scope } from "effect"; import packageJson from "../package.json"; import { authCommand, rejectInlineAuthToken } from "./commands/auth.js"; @@ -159,6 +159,10 @@ type CliCommandEnvironment = | CliState | Scope.Scope; +class CliUsageError extends Data.TaggedError("CliUsageError")<{ + readonly message: string; +}> {} + export const runCli: ( args: ReadonlyArray, ) => Effect.Effect = Effect.fn("putio.cli.run")(function* ( @@ -199,7 +203,7 @@ export const runCli: ( return replayBufferedConsole(currentConsole, entries); } - return Effect.fail(new Error(formatCliParserError(error))); + return Effect.fail(new CliUsageError({ message: formatCliParserError(error) })); }, (error) => Effect.fail(error), ), diff --git a/src/command-paths.test.ts b/src/command-paths.test.ts index 8d2c52f..d301e91 100644 --- a/src/command-paths.test.ts +++ b/src/command-paths.test.ts @@ -206,6 +206,7 @@ const expectFailure = (run: CliRun, message: string | RegExp) => { expect(stderrJson(run).error).toMatchObject({ message: Predicate.isString(message) ? message : expect.stringMatching(message), }); + expect(run.crashReports).toEqual([]); }; let api: FixtureApi; @@ -781,6 +782,15 @@ describe("pagination", () => { }); }); +describe("download links", () => { + it("asks for a selection when download-links create has none", async () => { + const run = await putio("download-links", "create", "--output", "json"); + + expectFailure(run, "Provide at least one --id or a --cursor to create download links."); + expect(api.requests).toEqual([]); + }); +}); + describe("file writes", () => { it("creates a folder", async () => { api.route("POST /v2/files/create-folder", ok({ file: file(42, "Projects", { parent_id: 9 }) })); diff --git a/src/commands/auth.ts b/src/commands/auth.ts index 13ae641..7a9937e 100644 --- a/src/commands/auth.ts +++ b/src/commands/auth.ts @@ -27,6 +27,7 @@ import { withAuthedSdk, writeDryRunPlan, CliCommandInputError, + checkCommandInput, } from "../internal/command.js"; import { dryRunFlag, @@ -185,12 +186,10 @@ const promptForToken = Effect.gen(function* () { const runtimeService = yield* CliRuntime; if (!runtimeService.isInteractiveTerminal) { - return yield* Effect.fail( - new CliCommandInputError({ - message: - "`auth login --token` needs an interactive terminal. Pipe the token into `auth login --token-stdin` instead.", - }), - ); + return yield* new CliCommandInputError({ + message: + "`auth login --token` needs an interactive terminal. Pipe the token into `auth login --token-stdin` instead.", + }); } const token = yield* Prompt.run( @@ -228,18 +227,13 @@ const loginWithExistingToken = (options: { const runtime = yield* resolveCliRuntimeConfig(); const apiBaseUrl = runtime.apiBaseUrl; - const selectedProfile = yield* Effect.try({ - try: () => resolveProfileInput(options.profile), - catch: (error) => error, - }); + const selectedProfile = yield* checkCommandInput(() => resolveProfileInput(options.profile)); const rawToken = yield* options.source === "stdin" ? readTokenFromStdin : promptForToken; const token = rawToken.trim(); if (token.length === 0) { - return yield* Effect.fail( - new CliCommandInputError({ message: "No token was provided to `auth login`." }), - ); + return yield* new CliCommandInputError({ message: "No token was provided to `auth login`." }); } yield* validateExistingToken(apiBaseUrl, token); @@ -303,10 +297,7 @@ const authStatus = Command.make( { output: outputOption, profile: profileOption }, ({ output, profile }) => Effect.gen(function* () { - const selectedProfile = yield* Effect.try({ - try: () => resolveProfileInput(profile), - catch: (error) => error, - }); + const selectedProfile = yield* checkCommandInput(() => resolveProfileInput(profile)); const status = yield* getAuthStatus({ profile: selectedProfile }); @@ -328,20 +319,16 @@ const authLogin = Command.make( Effect.gen(function* () { if (tokenPrompt || tokenStdin) { if (tokenPrompt && tokenStdin) { - return yield* Effect.fail( - new CliCommandInputError({ - message: "Use either `--token` or `--token-stdin` for `auth login`, not both.", - }), - ); + return yield* new CliCommandInputError({ + message: "Use either `--token` or `--token-stdin` for `auth login`, not both.", + }); } if (open || Option.isSome(timeoutSeconds)) { - return yield* Effect.fail( - new CliCommandInputError({ - message: - "`--open` and `--timeout-seconds` apply to the device-link flow, not to `--token` or `--token-stdin`.", - }), - ); + return yield* new CliCommandInputError({ + message: + "`--open` and `--timeout-seconds` apply to the device-link flow, not to `--token` or `--token-stdin`.", + }); } return yield* loginWithExistingToken({ @@ -361,10 +348,7 @@ const authLogin = Command.make( const runtime = yield* resolveCliRuntimeConfig(); const apiBaseUrl = runtime.apiBaseUrl; - const selectedProfile = yield* Effect.try({ - try: () => resolveProfileInput(profile), - catch: (error) => error, - }); + const selectedProfile = yield* checkCommandInput(() => resolveProfileInput(profile)); const timeoutMs = Option.getOrElse(timeoutSeconds, () => 120) * 1_000; const authFlow = yield* resolveAuthFlowConfig(); @@ -453,10 +437,7 @@ const authLogout = Command.make( { output: outputOption, profile: profileOption }, ({ output, profile }) => Effect.gen(function* () { - const selectedProfile = yield* Effect.try({ - try: () => resolveProfileInput(profile), - catch: (error) => error, - }); + const selectedProfile = yield* checkCommandInput(() => resolveProfileInput(profile)); const { cleared, @@ -485,7 +466,11 @@ const authPreview = Command.make( ({ code, open, output }) => Effect.gen(function* () { const authFlow = yield* resolveAuthFlowConfig(); - const previewCode = validateResourceIdentifier("`auth preview --code`", code); + + const previewCode = yield* checkCommandInput(() => + validateResourceIdentifier("`auth preview --code`", code), + ); + const linkUrl = buildDeviceLinkUrl(previewCode, authFlow.webAppUrl); yield* writeOutput( @@ -526,7 +511,9 @@ const authApprove = Command.make( schema: AuthApproveInputSchema, }); - const approvedCode = validateResourceIdentifier("`auth approve` code", input.code.trim()); + const approvedCode = yield* checkCommandInput(() => + validateResourceIdentifier("`auth approve` code", input.code.trim()), + ); if (dryRun) { return yield* writeDryRunPlan("auth approve", { code: approvedCode }, getOption(output)); @@ -567,7 +554,7 @@ const authProfilesUse = Command.make( { output: outputOption, profile: profileArgument }, ({ output, profile }) => Effect.gen(function* () { - const selectedProfile = validateProfileArgument(profile); + const selectedProfile = yield* checkCommandInput(() => validateProfileArgument(profile)); const result = yield* useProfile(selectedProfile); yield* writeOutput(result, getOption(output), (value) => @@ -581,7 +568,7 @@ const authProfilesRemove = Command.make( { output: outputOption, profile: profileArgument }, ({ output, profile }) => Effect.gen(function* () { - const selectedProfile = validateProfileArgument(profile); + const selectedProfile = yield* checkCommandInput(() => validateProfileArgument(profile)); const result = yield* removeProfile(selectedProfile); yield* writeOutput(result, getOption(output), (value) => diff --git a/src/commands/download-links.test.ts b/src/commands/download-links.test.ts index 9a41058..0188905 100644 --- a/src/commands/download-links.test.ts +++ b/src/commands/download-links.test.ts @@ -63,7 +63,7 @@ describe("resolveDownloadLinksCreateInput", () => { }); it("accepts raw json that matches the create schema", () => { - const input = Schema.decodeUnknownSync(DownloadLinksCreateInputSchema)({ + const input = Schema.decodeSync(DownloadLinksCreateInputSchema)({ cursor: "cursor-1", excludeIds: [2], ids: [1], diff --git a/src/commands/download-links.ts b/src/commands/download-links.ts index 07be290..b46f674 100644 --- a/src/commands/download-links.ts +++ b/src/commands/download-links.ts @@ -1,8 +1,10 @@ import { Command } from "effect/cli"; import { DownloadLinksCreateInputSchema, type FilesBulkSelection } from "@putdotio/sdk"; -import { Data, Effect, Option, Predicate, Schema } from "effect"; +import { Effect, Option, Predicate, Schema } from "effect"; import { + checkCommandInput, + CliCommandInputError, defineIntegerOption, defineRepeatedIntegerOption, defineTextOption, @@ -30,10 +32,6 @@ import { withTerminalLoader } from "../internal/loader-service.js"; import { writeOutput } from "../internal/output-service.js"; import { renderDownloadLinksTerminal } from "../internal/terminal/download-links-terminal.js"; -class DownloadLinksCommandError extends Data.TaggedError("DownloadLinksCommandError")<{ - readonly message: string; -}> {} - const cursorConfig = defineTextOption("cursor", { optional: true }); const downloadLinksIdConfig = defineIntegerOption("id"); const idsConfig = defineRepeatedIntegerOption("id"); @@ -68,7 +66,7 @@ export const resolveDownloadLinksCreateInput = ( return { cursor: input.cursor, excludeIds, ids }; } - throw new DownloadLinksCommandError({ + throw new CliCommandInputError({ message: "Provide at least one --id or a --cursor to create download links.", }); }; @@ -94,7 +92,9 @@ const downloadLinksCreate = Command.make( }), json, schema: DownloadLinksCreateInputSchema, - }).pipe(Effect.map(resolveDownloadLinksCreateInput)); + }).pipe( + Effect.flatMap((value) => checkCommandInput(() => resolveDownloadLinksCreateInput(value))), + ); if (dryRun) { return yield* writeDryRunPlan("download-links create", input, getOption(output)); diff --git a/src/commands/files.ts b/src/commands/files.ts index d907832..45abf3a 100644 --- a/src/commands/files.ts +++ b/src/commands/files.ts @@ -24,6 +24,7 @@ import { writeDryRunPlan, writeReadOutput, writeReadPages, + checkCommandInput, } from "../internal/command.js"; import { dryRunFlag, @@ -355,10 +356,12 @@ const filesMkdir = Command.make( json, schema: FilesMkdirInputSchema, }).pipe( - Effect.map((value) => ({ - ...value, - name: validateNameLikeInput("`files mkdir --name`", value.name), - })), + Effect.flatMap((value) => + checkCommandInput(() => ({ + ...value, + name: validateNameLikeInput("`files mkdir --name`", value.name), + })), + ), ); if (dryRun) { @@ -401,31 +404,32 @@ const filesUpload = Command.make( json, schema: FilesUploadInputSchema, }).pipe( - Effect.map((value) => ({ - ...value, - file_name: - value.file_name === undefined - ? undefined - : validateNameLikeInput( - "`files upload --file-name`", - requiredNonEmptyText( - value.file_name, - "Expected `files upload --file-name` to be a non-empty string.", + Effect.flatMap((value) => + checkCommandInput(() => ({ + ...value, + file_name: + value.file_name === undefined + ? undefined + : validateNameLikeInput( + "`files upload --file-name`", + requiredNonEmptyText( + value.file_name, + "Expected `files upload --file-name` to be a non-empty string.", + ), ), - ), - parent_id: optionalNonNegativeInteger( - value.parent_id, - "Expected `files upload --parent-id` to be a non-negative integer.", - ), - path: validateLocalPathInput("`files upload --path`", value.path), - })), + parent_id: optionalNonNegativeInteger( + value.parent_id, + "Expected `files upload --parent-id` to be a non-negative integer.", + ), + path: validateLocalPathInput("`files upload --path`", value.path), + })), + ), ); const prepared = yield* inspectLocalUpload(input.path); - const resolvedFileName = validateNameLikeInput( - "`files upload --file-name`", - input.file_name ?? prepared.fileName, + const resolvedFileName = yield* checkCommandInput(() => + validateNameLikeInput("`files upload --file-name`", input.file_name ?? prepared.fileName), ); const plan = { @@ -481,10 +485,12 @@ const filesRename = Command.make( json, schema: FilesRenameInputSchema, }).pipe( - Effect.map((value) => ({ - ...value, - name: validateNameLikeInput("`files rename --name`", value.name), - })), + Effect.flatMap((value) => + checkCommandInput(() => ({ + ...value, + name: validateNameLikeInput("`files rename --name`", value.name), + })), + ), ); if (dryRun) { @@ -659,9 +665,11 @@ const filesStartFromGet = Command.make( }, ({ fields, fileId, output }) => Effect.gen(function* () { - const validatedFileId = requiredPositiveInteger( - fileId, - "Expected `files start-from get` file-id to be a positive integer.", + const validatedFileId = yield* checkCommandInput(() => + requiredPositiveInteger( + fileId, + "Expected `files start-from get` file-id to be a positive integer.", + ), ); const controls = yield* resolveReadOutputControls({ @@ -796,9 +804,11 @@ const filesHlsManifest = Command.make( }, ({ fields, fileId, maxSubtitleCount, original, output, subtitleLanguages }) => Effect.gen(function* () { - const validatedFileId = requiredPositiveInteger( - fileId, - "Expected `files hls-manifest` file-id to be a positive integer.", + const validatedFileId = yield* checkCommandInput(() => + requiredPositiveInteger( + fileId, + "Expected `files hls-manifest` file-id to be a positive integer.", + ), ); const controls = yield* resolveReadOutputControls({ diff --git a/src/commands/sdk.ts b/src/commands/sdk.ts index 42765b3..681fbdd 100644 --- a/src/commands/sdk.ts +++ b/src/commands/sdk.ts @@ -13,6 +13,7 @@ import { withAuthedSdk, writeDryRunPlan, CliCommandInputError, + checkCommandInput, } from "../internal/command.js"; import { dryRunFlag, @@ -138,10 +139,7 @@ const sdkCall = Command.make( }, ({ args, dryRun, execute, json, operation, output }) => Effect.gen(function* () { - const mode = yield* Effect.try({ - try: () => resolveExecutionMode(dryRun, execute), - catch: (error) => error, - }); + const mode = yield* checkCommandInput(() => resolveExecutionMode(dryRun, execute)); const input = yield* resolveMutationInput({ buildFromFlags: () => ({ @@ -158,10 +156,7 @@ const sdkCall = Command.make( schema: SdkCallInputSchema, }).pipe(Effect.map(resolveInput)); - yield* Effect.try({ - try: () => resolveSdkOperation(sdk, input.operation), - catch: (error) => error, - }); + yield* checkCommandInput(() => resolveSdkOperation(sdk, input.operation)); const operationArgs = yield* decodeSdkOperationArgs(input.operation, input.args); @@ -186,10 +181,9 @@ const sdkCall = Command.make( ), ); - const normalized = yield* Effect.try({ - try: () => normalizeSdkOperationResult(input.operation, result), - catch: (error) => error, - }); + const normalized = yield* checkCommandInput(() => + normalizeSdkOperationResult(input.operation, result), + ); yield* writeOutput( { diff --git a/src/internal/auth-flow.test.ts b/src/internal/auth-flow.test.ts index f2c8d35..3607f09 100644 --- a/src/internal/auth-flow.test.ts +++ b/src/internal/auth-flow.test.ts @@ -204,7 +204,7 @@ describe("waitForDeviceToken", () => { const result = yield* Effect.result( waitForDeviceToken({ code: "ABCD1234", - checkCodeMatch: () => Effect.fail(new Error("boom")), + checkCodeMatch: () => Effect.fail("boom"), }), ); diff --git a/src/internal/auth-flow.ts b/src/internal/auth-flow.ts index d0249d1..568d001 100644 --- a/src/internal/auth-flow.ts +++ b/src/internal/auth-flow.ts @@ -19,9 +19,9 @@ export const buildDeviceLinkUrl = (code: string, webAppUrl: string = DEFAULT_PUT export const openBrowser = (url: string): Effect.Effect => Effect.flatMap(CliRuntime, (runtime) => runtime.openExternal(url)); -export const waitForDeviceToken = (options: { +export const waitForDeviceToken = (options: { readonly code: string; - readonly checkCodeMatch: (code: string) => Effect.Effect; + readonly checkCodeMatch: (code: string) => Effect.Effect; readonly pollIntervalMs?: number; readonly timeoutMs?: number; }): Effect.Effect => diff --git a/src/internal/command-specs.ts b/src/internal/command-specs.ts index 2db461f..a9795f8 100644 --- a/src/internal/command-specs.ts +++ b/src/internal/command-specs.ts @@ -27,7 +27,7 @@ const JsonScalarSchema = Schema.Struct({ const JsonEnumValueSchema = Schema.Union([ Schema.String, - Schema.Number, + Schema.Finite, Schema.Boolean, Schema.Null, ] as const); @@ -88,7 +88,7 @@ const JsonInputSpecSchema: Schema.Codec = Schema.Union([ const CommandOptionSchema = Schema.Struct({ choices: Schema.optional(Schema.Array(NonEmptyStringSchema)), defaultValue: Schema.optional( - Schema.Union([NonEmptyStringSchema, Schema.Number, Schema.Boolean] as const), + Schema.Union([NonEmptyStringSchema, Schema.Finite, Schema.Boolean] as const), ), description: Schema.optional(NonEmptyStringSchema), name: NonEmptyStringSchema, diff --git a/src/internal/command.test.ts b/src/internal/command.test.ts index 1d33631..38b17ed 100644 --- a/src/internal/command.test.ts +++ b/src/internal/command.test.ts @@ -43,7 +43,7 @@ describe("parseRepeatedIntegers", () => { describe("decodeJsonOption", () => { const schema = Schema.Struct({ - ids: Schema.Array(Schema.Number), + ids: Schema.Array(Schema.Finite), }); it("decodes valid json input", async () => { diff --git a/src/internal/command.ts b/src/internal/command.ts index 02f4d10..0dfea0d 100644 --- a/src/internal/command.ts +++ b/src/internal/command.ts @@ -449,8 +449,11 @@ const tryCommandInput = (try_: () => A, fallbackMessage: string) => catch: (error) => mapInputError(error, fallbackMessage), }); +export const checkCommandInput = (check: () => A) => + tryCommandInput(check, "Unable to resolve the command input."); + export const decodeJsonOption = (schema: Schema.Codec, raw: string) => - Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown))(raw).pipe( + Schema.decodeEffect(Schema.fromJsonString(Schema.Unknown))(raw).pipe( Effect.mapError( () => new CliCommandInputError({ @@ -458,13 +461,14 @@ export const decodeJsonOption = (schema: Schema.Codec, raw: string) => }), ), Effect.flatMap((value) => - Effect.try({ - try: () => Schema.decodeUnknownSync(schema)(value), - catch: () => - new CliCommandInputError({ - message: "Expected `--json` to match the command input schema.", - }), - }), + Schema.decodeUnknownEffect(schema)(value).pipe( + Effect.mapError( + () => + new CliCommandInputError({ + message: "Expected `--json` to match the command input schema.", + }), + ), + ), ), ); @@ -474,11 +478,7 @@ export const resolveMutationInput = (input: { readonly json: Option.Option; }) => Option.match(input.json, { - onNone: () => - Effect.try({ - try: input.buildFromFlags, - catch: (error) => mapInputError(error, "Unable to resolve the command input."), - }), + onNone: () => checkCommandInput(input.buildFromFlags), onSome: (raw) => decodeJsonOption(input.schema, raw), }); @@ -825,11 +825,9 @@ export const withAuthedUploadSdk = (program: AuthedSdkProgram) (isDefaultApiBaseUrl(auth.apiBaseUrl) ? DEFAULT_PUTIO_UPLOAD_BASE_URL : undefined); if (uploadBaseUrl === undefined) { - return yield* Effect.fail( - new CliCommandInputError({ - message: `Set ${ENV_UPLOAD_BASE_URL} to upload while the API base URL is ${auth.apiBaseUrl}.`, - }), - ); + return yield* new CliCommandInputError({ + message: `Set ${ENV_UPLOAD_BASE_URL} to upload while the API base URL is ${auth.apiBaseUrl}.`, + }); } return yield* provideAuthedSdk(auth, uploadBaseUrl, program); diff --git a/src/internal/local-upload.ts b/src/internal/local-upload.ts index 288f39c..561189e 100644 --- a/src/internal/local-upload.ts +++ b/src/internal/local-upload.ts @@ -21,11 +21,9 @@ export const inspectLocalUpload = (inputPath: string) => const info = yield* fileSystem.stat(resolvedPath).pipe(Effect.mapError(unreadableUploadFile)); if (info.type !== "File") { - return yield* Effect.fail( - new CliCommandInputError({ - message: "Expected the upload path to point to a regular file.", - }), - ); + return yield* new CliCommandInputError({ + message: "Expected the upload path to point to a regular file.", + }); } yield* fileSystem diff --git a/src/internal/sdk-operation-args.ts b/src/internal/sdk-operation-args.ts index a487fd6..d3bd1e8 100644 --- a/src/internal/sdk-operation-args.ts +++ b/src/internal/sdk-operation-args.ts @@ -427,7 +427,7 @@ export const decodeSdkOperationArgs = (operation: string, args: ReadonlyArray argumentsError(operation, formatIssue(error.issue).replaceAll(/\n\s*/gu, " ")), ), diff --git a/src/internal/state.test.ts b/src/internal/state.test.ts index 6770006..367dc67 100644 --- a/src/internal/state.test.ts +++ b/src/internal/state.test.ts @@ -160,10 +160,9 @@ describe("resolveConfigPath", () => { const exits = await Effect.runPromise( provideConfig( - Effect.all( - [...writers, ...readers].map((effect) => Effect.exit(effect)), - { concurrency: "unbounded" }, - ), + Effect.forEach([...writers, ...readers], (effect) => Effect.exit(effect), { + concurrency: "unbounded", + }), ), ); diff --git a/src/internal/state.ts b/src/internal/state.ts index f4711ae..36e6d9d 100644 --- a/src/internal/state.ts +++ b/src/internal/state.ts @@ -239,7 +239,7 @@ const validateProfileNameEffect = (profile: string) => }); const validateOptionalProfileNameEffect = (profile: string | undefined) => - profile === undefined ? Effect.succeed(undefined) : validateProfileNameEffect(profile); + profile === undefined ? Effect.undefined : validateProfileNameEffect(profile); const validatePersistedConfig = (state: PutioCliConfig) => { validateOptionalProfileName(state.default_profile); @@ -903,21 +903,17 @@ const resolveAuthStateEffect = ( if (selectedProfile) { if (state === null) { - return yield* Effect.fail( - new AuthStateError({ - message: `No put.io token is configured for profile \`${selectedProfile}\`. Set PUTIO_CLI_TOKEN or run \`putio auth login --profile ${selectedProfile}\`.`, - }), - ); + return yield* new AuthStateError({ + message: `No put.io token is configured for profile \`${selectedProfile}\`. Set PUTIO_CLI_TOKEN or run \`putio auth login --profile ${selectedProfile}\`.`, + }); } const profile = state?.profiles?.[selectedProfile]; if (profile === undefined || !Predicate.isString(profile.auth_token)) { - return yield* Effect.fail( - new AuthStateError({ - message: `No put.io token is configured for profile \`${selectedProfile}\`. Set PUTIO_CLI_TOKEN or run \`putio auth login --profile ${selectedProfile}\`.`, - }), - ); + return yield* new AuthStateError({ + message: `No put.io token is configured for profile \`${selectedProfile}\`. Set PUTIO_CLI_TOKEN or run \`putio auth login --profile ${selectedProfile}\`.`, + }); } return { @@ -930,11 +926,9 @@ const resolveAuthStateEffect = ( } if (state === null || !Predicate.isString(state.auth_token)) { - return yield* Effect.fail( - new AuthStateError({ - message: "No put.io token is configured. Set PUTIO_CLI_TOKEN or run `putio auth login`.", - }), - ); + return yield* new AuthStateError({ + message: "No put.io token is configured. Set PUTIO_CLI_TOKEN or run `putio auth login`.", + }); } return { @@ -964,11 +958,9 @@ const useProfileEffect = ( const state = yield* loadPersistedStateEffect(runtime.configPath); if (state?.profiles?.[profileName] === undefined) { - return yield* Effect.fail( - new AuthStateError({ - message: `Auth profile \`${profileName}\` does not exist. Run \`putio auth login --profile ${profileName}\` first.`, - }), - ); + return yield* new AuthStateError({ + message: `Auth profile \`${profileName}\` does not exist. Run \`putio auth login --profile ${profileName}\` first.`, + }); } const nextState: PutioCliConfig = { diff --git a/src/test-support/run-cli.ts b/src/test-support/run-cli.ts index acfb587..34798b3 100644 --- a/src/test-support/run-cli.ts +++ b/src/test-support/run-cli.ts @@ -20,7 +20,7 @@ import { import { runCli } from "../cli.js"; import { CliServicesLive } from "../internal/app-layer.js"; -import { CrashReportingDisabledLive } from "../internal/crash-reporting.js"; +import { CliCrashReporter, type CrashKind } from "../internal/crash-reporting.js"; import { handleCliCause } from "../internal/main.js"; import { cliRuntimeLayer } from "../internal/runtime.js"; @@ -210,6 +210,7 @@ export type CliRun = { /** The persisted config after the run, parsed; undefined when no file exists. */ readonly config: unknown; readonly configPath: string; + readonly crashReports: ReadonlyArray; readonly exitCode: number; readonly openedUrls: ReadonlyArray; readonly stderr: string; @@ -280,6 +281,17 @@ export const runPutio = async ( writeStdout: (message) => stdout.push(message), }); + const crashReports: CrashKind[] = []; + + const crashReporterLayer = Layer.succeed(CliCrashReporter, { + capture: (kind) => { + crashReports.push(kind); + + return Promise.resolve(); + }, + decision: { enabled: true }, + }); + const stdioLayer = Stdio.layerTest({ stdin: options.stdin === undefined @@ -304,7 +316,7 @@ export const runPutio = async ( Effect.provide( CliServicesLive.pipe( Layer.provideMerge(runtimeLayer), - Layer.merge(CrashReportingDisabledLive), + Layer.merge(crashReporterLayer), Layer.merge(stdioLayer), Layer.merge(terminalLayer), ), @@ -324,6 +336,7 @@ export const runPutio = async ( return { config, configPath, + crashReports, exitCode, openedUrls, stderr: stderr.join(""), diff --git a/tsconfig.json b/tsconfig.json index 3e1ff84..75ce1f9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,12 +11,26 @@ "types": ["node"], "strict": true, "noUnusedLocals": true, - "declaration": true, - "emitDeclarationOnly": true, + "noEmit": true, "esModuleInterop": true, "isolatedModules": true, "verbatimModuleSyntax": true, - "skipLibCheck": true + "skipLibCheck": true, + "plugins": [ + { + "name": "@effect/language-service", + "allowedUnstableApis": [ + "@effect/platform-node", + "@effect/vitest", + "effect/cli", + "effect/FileSystem", + "effect/Path", + "effect/PlatformError", + "effect/Stdio", + "effect/Terminal" + ] + } + ] }, "include": ["src", "scripts/**/*.ts", "scripts/**/*.mts", "vite.config.ts"] } diff --git a/vite.config.ts b/vite.config.ts index 184ade5..97a3366 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,3 +1,4 @@ +import { correctness, strict } from "@effect/tsgo/oxlint-presets"; import { defineConfig } from "vite-plus"; import { resolveCrashReportingBuildDefines } from "./src/internal/crash-reporting-config.ts"; @@ -43,6 +44,7 @@ export default defineConfig({ ignorePatterns: agentToolingIgnores, }, lint: { + extends: [correctness, strict], options: { typeAware: true, typeCheck: true, @@ -53,7 +55,37 @@ export default defineConfig({ { name: "anti-slop-effect", specifier: "./tools/oxlint/anti-slop/effect/index.ts" }, { name: "uinaf", specifier: "@uinaf/oxlint-plugin-no-comments" }, ], + overrides: [ + { + files: [ + "**/*.test.ts", + "src/test-support/**", + "src/bin.ts", + "src/sea.ts", + "src/cli.ts", + "src/commands/sdk.ts", + "src/internal/main.ts", + "src/internal/sdk-operations.ts", + ], + rules: { + "effecttsgo/any-unknown-in-error-context": "off", + }, + }, + { + files: ["src/internal/sdk-operations.ts"], + rules: { + "effecttsgo/unsafe-effect-type-assertion": "off", + }, + }, + { + files: ["src/internal/state.ts"], + rules: { + "effecttsgo/leaking-requirements": "off", + }, + }, + ], rules: { + "effecttsgo/lazy-effect": "off", "oxc/no-accumulating-spread": "error", "anti-slop/no-array-filter-map": "error", "anti-slop/no-reduce-accumulator-copy": "error", @@ -100,7 +132,7 @@ export default defineConfig({ }, }, staged: { - "*.{js,ts,tsx,mjs,cjs,mts,cts}": "vp check --fix", + "*.{js,ts,tsx,mjs,cjs,mts,cts}": "effect-tsgo vp check --fix", }, test: { exclude: ["**/node_modules/**", "**/.git/**", ".claude/worktrees/**", "scripts/**/*.test.ts"], From f6e6e609e68be2a33b6748fd6f1ed60b75735edd Mon Sep 17 00:00:00 2001 From: Altay Date: Thu, 12 Nov 2026 20:05:53 +0300 Subject: [PATCH 2/2] chore: fail the gate on unknown error channels and unsafe Effect casts The correctness preset only warns, and warnings do not fail the check. AGENTS.md links unshipped files by URL. --- AGENTS.md | 4 ++-- vite.config.ts | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 449d98d..15c7fc8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -25,8 +25,8 @@ does not cover. Keep the pinned `effect` version. `@effect/tsgo` adds Effect diagnostics to lint. Bare `vp check` cannot load them and stops at `Unknown plugin: effecttsgo`; use `pnpm exec vp run check`. Rule -overrides are in [vite.config.ts](vite.config.ts), the unstable modules the CLI -accepts in [tsconfig.json](tsconfig.json). +overrides are in [vite.config.ts](https://github.com/putdotio/putio-cli/blob/main/vite.config.ts), the unstable modules the CLI +accepts in [tsconfig.json](https://github.com/putdotio/putio-cli/blob/main/tsconfig.json). ## Proof diff --git a/vite.config.ts b/vite.config.ts index 97a3366..8469a6b 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -85,7 +85,9 @@ export default defineConfig({ }, ], rules: { + "effecttsgo/any-unknown-in-error-context": "error", "effecttsgo/lazy-effect": "off", + "effecttsgo/unsafe-effect-type-assertion": "error", "oxc/no-accumulating-spread": "error", "anti-slop/no-array-filter-map": "error", "anti-slop/no-reduce-accumulator-copy": "error",