Skip to content

Commit caf6b70

Browse files
committed
fix(cli): auth login --device works without a terminal
1 parent 6feb4be commit caf6b70

2 files changed

Lines changed: 12 additions & 13 deletions

File tree

‎packages/cli/src/commands/auth/login.test.ts‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,10 @@ describe("auth login", () => {
440440
expect(deviceAuth.start).toHaveBeenCalledOnce();
441441
});
442442

443-
it("refuses device authorization when either terminal stream is not a TTY", async () => {
444-
Object.defineProperty(process.stdout, "isTTY", {
445-
configurable: true,
446-
value: undefined,
447-
});
448-
await expect(runCommand({ device: true })).rejects.toThrow(/Invalid command usage/);
449-
expect(deviceAuth.start).not.toHaveBeenCalled();
443+
it("runs device authorization without a terminal, where only a URL and code are printed", async () => {
444+
Object.defineProperty(process.stdin, "isTTY", { configurable: true, value: undefined });
445+
Object.defineProperty(process.stdout, "isTTY", { configurable: true, value: undefined });
446+
await runCommand({ device: true });
447+
expect(deviceAuth.start).toHaveBeenCalledOnce();
450448
});
451449
});

‎packages/cli/src/commands/auth/login.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { failCommand, failUsage, requestCliExit } from "../../utils/commandResult.js";
2-
import { envFlagEnabled, isAttendedTerminal, isCI } from "../../utils/attendedTerminal.js";
2+
import { envFlagEnabled, isCI } from "../../utils/attendedTerminal.js";
33
import { isAgentDriven } from "../../telemetry/agent_runtime.js";
44
/**
55
* `hyperframes auth login` — sign in to HeyGen.
@@ -70,7 +70,8 @@ export default defineCommand({
7070
},
7171
device: {
7272
type: "boolean",
73-
description: "Use an attended device code (for SSH/headless terminals; never for CI).",
73+
description:
74+
"Use a device code approved in any browser (for SSH, headless or agent-run terminals; never for CI).",
7475
},
7576
},
7677
// fallow-ignore-next-line complexity
@@ -123,19 +124,19 @@ function agentShellOnThisMachine(): boolean {
123124
return !isCI() && isAgentDriven();
124125
}
125126

126-
function assertAttendedDeviceFlow(): void {
127-
if (!isAttendedTerminal()) {
127+
function assertDeviceFlowAllowed(): void {
128+
if (isCI()) {
128129
console.error(
129130
c.error(
130-
"`--device` requires an attended terminal and is disabled in CI. Use an API key or workload credential for automation.",
131+
"`--device` needs a person to approve it and is disabled in CI. Use an API key or workload credential for automation.",
131132
),
132133
);
133134
failUsage();
134135
}
135136
}
136137

137138
async function runDeviceLogin(): Promise<void> {
138-
assertAttendedDeviceFlow();
139+
assertDeviceFlowAllowed();
139140
assertOAuthConfiguredOrExit();
140141
const { trackAuthLoginStarted, trackAuthLoginCompleted, trackAuthLoginFailed, identifyUser } =
141142
await import("../../telemetry/index.js");

0 commit comments

Comments
 (0)