Skip to content

Commit 43e41d9

Browse files
authored
Do not proceed if ggt runs in unsupported terminal environments (#1907)
1 parent 00f2155 commit 43e41d9

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

.changeset/gold-bikes-dance.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"ggt": patch
3+
---
4+
5+
Check the terminal environment before proceeding when running ggt
6+
7+
We don't want to allow users to run `ggt` in places where terminal commands can be run in the Gadget editor.
8+
9+
This change checks for special environment variables specific to Gadget and exits early if they are detected.

spec/ggt.spec.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { inspect } from "node:util";
2-
import { assert, beforeEach, describe, expect, it } from "vitest";
2+
import { assert, beforeEach, describe, expect, it, vi } from "vitest";
33
import * as root from "../src/commands/root.js";
44
import { ggt } from "../src/ggt.js";
55
import * as command from "../src/services/command/command.js";
@@ -11,6 +11,8 @@ import { PromiseSignal } from "../src/services/util/promise.js";
1111
import type { AnyFunction } from "../src/services/util/types.js";
1212
import { testCtx } from "./__support__/context.js";
1313
import { mock } from "./__support__/mock.js";
14+
import { expectStdout } from "./__support__/output.js";
15+
import { expectProcessExit } from "./__support__/process.js";
1416

1517
describe("ggt", () => {
1618
beforeEach(() => {
@@ -46,4 +48,11 @@ describe("ggt", () => {
4648

4749
await aborted;
4850
});
51+
52+
it("exits early if running in the Gadget editor's terminal", async () => {
53+
vi.stubEnv("GADGET_EDITOR_TERMINAL_SESSION_ID", "123");
54+
55+
await expectProcessExit(() => ggt(testCtx), 1);
56+
expectStdout().toEqual("Running ggt in the Gadget editor's terminal is not supported.\n");
57+
});
4958
});

src/ggt.ts

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { activeSpinner, spin } from "./services/output/spinner.js";
1010
import { installJsonExtensions } from "./services/util/json.js";
1111

1212
export const ggt = async (ctx = Context.init({ name: "ggt" })): Promise<void> => {
13+
if (process.env["GADGET_EDITOR_TERMINAL_SESSION_ID"]) {
14+
println("Running ggt in the Gadget editor's terminal is not supported.");
15+
return process.exit(1);
16+
}
17+
1318
try {
1419
const rootArgs = parseArgs(root.args, { argv: process.argv.slice(2), permissive: true });
1520

0 commit comments

Comments
 (0)