From e2017335eded892e9a59adea28e462e5d75af753 Mon Sep 17 00:00:00 2001 From: Heamanth_alturi <216673743+aihehye@users.noreply.github.com> Date: Sun, 22 Nov 2026 07:32:30 +0000 Subject: [PATCH 1/2] fix(server): surface npm min-release-age cutoff when device tool install is blocked --- apps/server/src/device/DeviceService.test.ts | 100 +++++++++++++++--- apps/server/src/device/DeviceService.ts | 35 +++--- .../server/src/device/DeviceToolchain.test.ts | 36 +++++++ apps/server/src/device/DeviceToolchain.ts | 34 +++++- packages/contracts/src/device.ts | 3 + 5 files changed, 176 insertions(+), 32 deletions(-) diff --git a/apps/server/src/device/DeviceService.test.ts b/apps/server/src/device/DeviceService.test.ts index 00e942f1e6df..4efcac5f4a2e 100644 --- a/apps/server/src/device/DeviceService.test.ts +++ b/apps/server/src/device/DeviceService.test.ts @@ -499,6 +499,54 @@ describe("device setup consent", () => { }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); + it.effect( + "names npm's release-age policy in host status when min-release-age blocks install", + () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-device-release-age-" }); + const installError = yield* ensureDeviceHub(baseDir).pipe( + Effect.provideService(ProcessRunner.ProcessRunner, { + run: () => + Effect.succeed({ + code: ChildProcessSpawner.ExitCode(1), + stdout: "", + stderr: [ + "npm error code ETARGET", + "npm error notarget No matching version found for expo-device-hub@0.26.1 with a date before 20/11/2026, 10:56:49 am.", + ].join("\n"), + timedOut: false, + stdoutTruncated: false, + stderrTruncated: false, + stdoutInvalidUtf8: false, + stderrInvalidUtf8: false, + }), + }), + Effect.flip, + ); + const { service, settings } = yield* fixture( + Effect.void, + undefined, + false, + new DeviceHost.DeviceHostError({ + hostId: LOCAL_DEVICE_HOST_ID, + step: "installing device support", + cause: installError, + }), + ); + yield* Ref.update(settings, (current) => ({ ...current, enableDeviceSupport: true })); + const detail = (yield* service.list).hostStatuses[LOCAL_DEVICE_HOST_ID]?.detail; + expect(detail).toContain("min-release-age"); + expect(detail).toContain("20/11/2026, 10:56:49 am"); + const unavailable = yield* service.readiness(LOCAL_DEVICE_HOST_ID).pipe(Effect.flip); + expect(unavailable._tag).toBe("DeviceHostUnavailableError"); + if (unavailable._tag === "DeviceHostUnavailableError") { + expect(unavailable.reason).toContain("min-release-age"); + expect(unavailable.reason).toContain("20/11/2026, 10:56:49 am"); + } + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), + ); + it.effect.each([ { name: "a Windows host", @@ -1868,7 +1916,7 @@ it.effect("reconciles SSH host settings without publishing no-op changes", () => ), ); -it.effect.each(["exit", "missing"] as const)( +it.effect.each(["exit", "missing", "release_age"] as const)( "a failed tool update reports a safe %s failure", (failure) => Effect.gen(function* () { @@ -1900,24 +1948,40 @@ it.effect.each(["exit", "missing"] as const)( stdoutInvalidUtf8: false, stderrInvalidUtf8: false, }; + const releaseAgeFailure = { + code: ChildProcessSpawner.ExitCode(1), + stdout: "", + stderr: [ + "npm warn registry https://private:credential@registry.example.test/expo-device-hub", + "npm error code ETARGET", + "npm error notarget No matching version found for expo-device-hub@0.26.1 with a date before 20/11/2026, 10:56:49 am.", + ].join("\n"), + timedOut: false, + stdoutTruncated: false, + stderrTruncated: false, + stdoutInvalidUtf8: false, + stderrInvalidUtf8: false, + }; const service = yield* DeviceService.make.pipe( Effect.provideService(DeviceHost.DeviceHost, host), Effect.provideService(ProcessRunner.ProcessRunner, { run: ({ command, args }) => failure === "exit" ? Effect.succeed(npmFailure) - : Effect.fail( - new ProcessRunner.ProcessSpawnError({ - command, - argumentCount: args.length, - cause: PlatformError.systemError({ - _tag: "NotFound", - module: "ChildProcess", - method: "spawn", - description: "private diagnostic text", + : failure === "release_age" + ? Effect.succeed(releaseAgeFailure) + : Effect.fail( + new ProcessRunner.ProcessSpawnError({ + command, + argumentCount: args.length, + cause: PlatformError.systemError({ + _tag: "NotFound", + module: "ChildProcess", + method: "spawn", + description: "private diagnostic text", + }), }), - }), - ), + ), }), Effect.provideService( HttpClient.HttpClient, @@ -1928,13 +1992,21 @@ it.effect.each(["exit", "missing"] as const)( const error = yield* service.updateTool("hub").pipe(Effect.flip); expect(error).toMatchObject({ _tag: "DeviceOperationError", - reason: failure === "exit" ? "command_failed" : "package_manager_missing", + reason: + failure === "exit" + ? "command_failed" + : failure === "release_age" + ? "release_age_blocked" + : "package_manager_missing", }); expect(error.message).toBe( failure === "exit" ? "Device update device tool failed: The device command failed (exit code 243)." - : "Device update device tool failed: Device support needs npm, which is not on the T3 server's PATH. Install npm (it comes with Node.js from nodejs.org), restart T3 Code, then retry.", + : failure === "release_age" + ? "Device update device tool failed: npm blocked installing device tools because of your npm release-age policy (min-release-age / before cutoff: 20/11/2026, 10:56:49 am). Wait until the release ages past that cutoff or adjust your npm config, then retry." + : "Device update device tool failed: Device support needs npm, which is not on the T3 server's PATH. Install npm (it comes with Node.js from nodejs.org), restart T3 Code, then retry.", ); + expect(error.message).not.toContain("private:credential"); }).pipe( Effect.provide( Layer.mergeAll( diff --git a/apps/server/src/device/DeviceService.ts b/apps/server/src/device/DeviceService.ts index cf8aece6745e..30f227a8aaa0 100644 --- a/apps/server/src/device/DeviceService.ts +++ b/apps/server/src/device/DeviceService.ts @@ -118,11 +118,26 @@ const isToolchainInstallError = Schema.is(DeviceToolchainInstallError); const actionableHostFailure = (error: DeviceHost.DeviceHostError): string | undefined => { if (error.step === "probe") return sshProbeFailureMessage(error); - if (isToolchainInstallError(error.cause) && error.cause.reason === "npm_not_found") + if (isToolchainInstallError(error.cause) && error.cause.reason !== undefined) return error.cause.message; return undefined; }; +const toolchainOperationError = (operation: string, cause: DeviceToolchainInstallError) => + new DeviceOperationError({ + operation, + reason: + cause.reason === "npm_not_found" + ? "package_manager_missing" + : cause.reason === "release_age_blocked" + ? "release_age_blocked" + : "command_failed", + // npm's stderr can carry registry credentials; expose only the reason, cutoff, and exit code. + ...(cause.exitCode !== undefined ? { exitCode: cause.exitCode } : {}), + ...(cause.releaseAgeCutoff !== undefined ? { releaseAgeCutoff: cause.releaseAgeCutoff } : {}), + cause, + }); + export interface DeviceScreenshot { readonly device: DeviceSummary; readonly png: Uint8Array; @@ -1319,11 +1334,7 @@ export const make = Effect.gen(function* () { reason: nodeRuntimeUnavailableMessage("Device automation"), cause: error, }) - : new DeviceOperationError({ - operation: "install agent CLI", - reason: "command_failed", - cause: error, - }), + : toolchainOperationError("install agent CLI", error), ), ); const launchers: AgentDeviceLaunchers = { @@ -1430,17 +1441,7 @@ export const make = Effect.gen(function* () { Effect.provideService(FileSystem.FileSystem, fs), Effect.provideService(Path.Path, path), Effect.provideService(ProcessRunner.ProcessRunner, runner), - Effect.mapError( - (cause) => - new DeviceOperationError({ - operation: "update device tool", - reason: - cause.reason === "npm_not_found" ? "package_manager_missing" : "command_failed", - // npm's stderr can carry registry credentials; expose only the reason and exit code. - ...(cause.exitCode !== undefined ? { exitCode: cause.exitCode } : {}), - cause, - }), - ), + Effect.mapError((cause) => toolchainOperationError("update device tool", cause)), ), launchers, ); diff --git a/apps/server/src/device/DeviceToolchain.test.ts b/apps/server/src/device/DeviceToolchain.test.ts index 78dc719b141e..0c0fad80fa26 100644 --- a/apps/server/src/device/DeviceToolchain.test.ts +++ b/apps/server/src/device/DeviceToolchain.test.ts @@ -44,6 +44,42 @@ it.effect("failed installation cleans staging and exposes only a safe failure me }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); +it.effect( + "names npm's release-age cutoff on ETARGET date-cutoff failures without leaking stderr", + () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const baseDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-device-release-age-" }); + const result = { + code: ChildProcessSpawner.ExitCode(1), + stdout: "", + stderr: [ + "npm warn registry https://private:credential@example.test/package", + "npm error code ETARGET", + "npm error notarget No matching version found for expo-device-hub@0.26.1 with a date before 20/11/2026, 10:56:49 am.", + "npm error notarget In most cases you or one of your dependencies are requesting a package version that doesn't exist.", + ].join("\n"), + timedOut: false, + stdoutTruncated: false, + stderrTruncated: false, + stdoutInvalidUtf8: false, + stderrInvalidUtf8: false, + }; + const error = yield* ensureDeviceHub(baseDir).pipe( + Effect.provideService(ProcessRunner.ProcessRunner, { + run: () => Effect.succeed(result), + }), + Effect.flip, + ); + expect(error.reason).toBe("release_age_blocked"); + expect(error.releaseAgeCutoff).toBe("20/11/2026, 10:56:49 am"); + expect(error.message).toContain("min-release-age"); + expect(error.message).toContain("20/11/2026, 10:56:49 am"); + expect(error.message).not.toContain("private:credential"); + expect(error.cause).toBe(result); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), +); + it.effect("inventory reports only completed versions without installing the required version", () => Effect.gen(function* () { const fs = yield* FileSystem.FileSystem; diff --git a/apps/server/src/device/DeviceToolchain.ts b/apps/server/src/device/DeviceToolchain.ts index 7b041a54502c..75336b31fdd5 100644 --- a/apps/server/src/device/DeviceToolchain.ts +++ b/apps/server/src/device/DeviceToolchain.ts @@ -37,13 +37,20 @@ export class DeviceToolchainInstallError extends Schema.TaggedError error.cause instanceof PlatformError.PlatformError && error.cause.reason._tag === "NotFound"; +const NPM_ETARGET_PATTERN = /^npm (?:error|ERR!) code ETARGET\b/m; +const NPM_RELEASE_AGE_CUTOFF_PATTERN = + /^npm (?:error|ERR!) notarget No matching version found for [^\s]+ with a date before ([^\r\n]+?)\.?$/m; + +const parseReleaseAgeCutoff = ( + stderr: string, +): { readonly blocked: true; readonly cutoff?: string } | null => { + if (!NPM_ETARGET_PATTERN.test(stderr)) return null; + const match = NPM_RELEASE_AGE_CUTOFF_PATTERN.exec(stderr); + if (!match) return null; + const rawCutoff = match[1]?.trim(); + const cutoff = + rawCutoff && rawCutoff.length <= 64 && !rawCutoff.includes("://") && !rawCutoff.includes("@") + ? rawCutoff + : undefined; + return cutoff ? { blocked: true, cutoff } : { blocked: true }; +}; + const installTool = Effect.fn("DeviceToolchain.installTool")(function* ( spec: ToolSpec, paths: DeviceToolPaths, @@ -158,10 +183,17 @@ const installTool = Effect.fn("DeviceToolchain.installTool")(function* ( ), ); if (result.code !== 0) { + const releaseAge = parseReleaseAgeCutoff(result.stderr); return yield* new DeviceToolchainInstallError({ tool: spec.name, step: "running npm install", exitCode: Number(result.code), + ...(releaseAge + ? { + reason: "release_age_blocked" as const, + ...(releaseAge.cutoff !== undefined ? { releaseAgeCutoff: releaseAge.cutoff } : {}), + } + : {}), cause: result, }); } diff --git a/packages/contracts/src/device.ts b/packages/contracts/src/device.ts index ab77114980b9..af08d1748caa 100644 --- a/packages/contracts/src/device.ts +++ b/packages/contracts/src/device.ts @@ -589,8 +589,10 @@ export class DeviceOperationError extends Schema.TaggedError Date: Sun, 22 Nov 2026 08:00:36 +0000 Subject: [PATCH 2/2] fix(server): address CodeRabbit review feedback on release-age message and test assertion --- apps/server/src/device/DeviceService.test.ts | 16 ++++++++++------ apps/server/src/device/DeviceToolchain.ts | 2 +- packages/contracts/src/device.ts | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/apps/server/src/device/DeviceService.test.ts b/apps/server/src/device/DeviceService.test.ts index 4efcac5f4a2e..343a4347fa7a 100644 --- a/apps/server/src/device/DeviceService.test.ts +++ b/apps/server/src/device/DeviceService.test.ts @@ -1998,14 +1998,18 @@ it.effect.each(["exit", "missing", "release_age"] as const)( : failure === "release_age" ? "release_age_blocked" : "package_manager_missing", + ...(failure === "release_age" ? { releaseAgeCutoff: "20/11/2026, 10:56:49 am" } : {}), }); - expect(error.message).toBe( - failure === "exit" - ? "Device update device tool failed: The device command failed (exit code 243)." - : failure === "release_age" - ? "Device update device tool failed: npm blocked installing device tools because of your npm release-age policy (min-release-age / before cutoff: 20/11/2026, 10:56:49 am). Wait until the release ages past that cutoff or adjust your npm config, then retry." + if (failure === "release_age") { + expect(error.message).toContain("min-release-age"); + expect(error.message).toContain("20/11/2026, 10:56:49 am"); + } else { + expect(error.message).toBe( + failure === "exit" + ? "Device update device tool failed: The device command failed (exit code 243)." : "Device update device tool failed: Device support needs npm, which is not on the T3 server's PATH. Install npm (it comes with Node.js from nodejs.org), restart T3 Code, then retry.", - ); + ); + } expect(error.message).not.toContain("private:credential"); }).pipe( Effect.provide( diff --git a/apps/server/src/device/DeviceToolchain.ts b/apps/server/src/device/DeviceToolchain.ts index 75336b31fdd5..0c924ef92ac2 100644 --- a/apps/server/src/device/DeviceToolchain.ts +++ b/apps/server/src/device/DeviceToolchain.ts @@ -49,7 +49,7 @@ export class DeviceToolchainInstallError extends Schema.TaggedError