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
91 changes: 27 additions & 64 deletions packages/cli/src/commands/agents/create/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,32 @@
import { afterEach, describe, expect, mock, test } from "bun:test";
import { afterEach, describe, expect, test } from "bun:test";
import { withLocalHostService } from "../../../lib/host/test-helpers";
import createAgentCommand from "./command";

let runInput: Record<string, unknown> | undefined;
let transcriptInput: Record<string, unknown> | undefined;
let transcriptText = "";
let transcriptFails = false;
let bindings: Array<Record<string, unknown>> = [];

const hostTarget = () => ({
hostId: "host-1",
client: {
terminal: {
transcript: {
query: async (input: Record<string, unknown>) => {
transcriptInput = input;
if (transcriptFails) throw new Error("host unreachable");
return { text: transcriptText, source: "stream", streamBytes: 42 };
},
},
},
terminalAgents: {
listByWorkspace: { query: async () => bindings },
},
settings: {
agentConfigs: {
list: {
query: async () => [
{ id: "config-1", presetId: "claude", label: "Claude" },
],
},
},
},
agents: {
run: {
mutate: async (input: Record<string, unknown>) => {
runInput = input;
return {
kind: "terminal",
sessionId: "terminal-1",
label: "Codex",
};
},
},
},
const WORKSPACE_ID = "00000000-0000-4000-8000-000000000001";

withLocalHostService("org-1", {
"workspace.list": () => [{ id: WORKSPACE_ID }],
"terminal.transcript": (input) => {
transcriptInput = input;
if (transcriptFails) throw new Error("host unreachable");
return { text: transcriptText, source: "stream", streamBytes: 42 };
},
"terminalAgents.listByWorkspace": () => bindings,
"settings.agentConfigs.list": () => [
{ id: "config-1", presetId: "claude", label: "Claude" },
],
"agents.run": (input) => {
runInput = input;
return { kind: "terminal", sessionId: "terminal-1", label: "Codex" };
},
});

mock.module("../../../lib/host-workspaces", () => ({
resolveWorkspaceTarget: async () => ({
hostId: "host-1",
workspace: { id: "00000000-0000-4000-8000-000000000001" },
target: hostTarget(),
}),
}));

mock.module("../../../lib/host-target", () => ({
requireHostTarget: () => "host-1",
resolveHostTarget: hostTarget,
}));

mock.module("../../../lib/upload-attachments", () => ({
uploadAttachments: async () => [],
}));

const { default: createAgentCommand } = await import("./command");

function invoke(
effort?: string,
overrides: Record<string, unknown> = { prompt: "Review this diff" },
Expand All @@ -75,8 +38,8 @@ function invoke(
} as never,
args: {} as never,
options: {
workspace: "00000000-0000-4000-8000-000000000001",
host: "host-1",
workspace: WORKSPACE_ID,
local: true,
agent: "codex",
effort,
...overrides,
Expand All @@ -101,7 +64,7 @@ describe("agents create", () => {
});

expect(runInput).toEqual({
workspaceId: "00000000-0000-4000-8000-000000000001",
workspaceId: WORKSPACE_ID,
agent: "codex",
prompt: "Review this diff",
model: "gpt-5.6-sol",
Expand All @@ -114,7 +77,7 @@ describe("agents create", () => {
await invoke("xhigh");

expect(runInput).toEqual({
workspaceId: "00000000-0000-4000-8000-000000000001",
workspaceId: WORKSPACE_ID,
agent: "codex",
prompt: "Review this diff",
model: undefined,
Expand All @@ -127,7 +90,7 @@ describe("agents create", () => {
await invoke();

expect(runInput).toEqual({
workspaceId: "00000000-0000-4000-8000-000000000001",
workspaceId: WORKSPACE_ID,
agent: "codex",
prompt: "Review this diff",
model: undefined,
Expand All @@ -140,7 +103,7 @@ describe("agents create", () => {
await invoke(undefined, { resumeSession: "abc-123" });

expect(runInput).toEqual({
workspaceId: "00000000-0000-4000-8000-000000000001",
workspaceId: WORKSPACE_ID,
agent: "codex",
prompt: "",
resumeSessionId: "abc-123",
Expand All @@ -154,7 +117,7 @@ describe("agents create", () => {
await invoke(undefined, { forkSession: "thread-source" });

expect(runInput).toEqual({
workspaceId: "00000000-0000-4000-8000-000000000001",
workspaceId: WORKSPACE_ID,
agent: "codex",
prompt: "",
forkSessionId: "thread-source",
Expand Down Expand Up @@ -192,7 +155,7 @@ describe("agents create", () => {
await invoke(undefined, { fromTerminal: "terminal-source" });

expect(transcriptInput).toEqual({
workspaceId: "00000000-0000-4000-8000-000000000001",
workspaceId: WORKSPACE_ID,
terminalId: "terminal-source",
});
const prompt = String(runInput?.prompt);
Expand Down
11 changes: 4 additions & 7 deletions packages/cli/src/commands/browser/open/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { describe, expect, mock, test } from "bun:test";
import { withLocalHostService } from "../../../lib/host/test-helpers";
import command from "./command";

const open = mock(async (input: { url: string }) => ({
paneId: "pane-1",
url: input.url,
}));
mock.module("../shared", () => ({
resolveBrowserTarget: async () => ({
client: { browser: { open: { mutate: open } } },
}),
}));
const { default: command } = await import("./command");
withLocalHostService("org-1", { "browser.open": open as never });

function invoke(show?: boolean, target?: string) {
return command.run({
ctx: {} as never,
ctx: { config: { organizationId: "org-1" }, bearer: "bearer" } as never,
args: {} as never,
options: {
workspace: "agent-workspace",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/config/check/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { command } from "../../../lib/command";
import { SUPERSET_CONFIG_PATH } from "../../../lib/config";
import { getSupersetConfigPath } from "../../../lib/config";
import {
type ConfigCheckResult,
checkConfigFile,
Expand All @@ -22,7 +22,7 @@ export default command({
"Validate the config file under ~/.superset before a hand edit or a bad restore surfaces as an auth failure; exits 1 on an error",
skipMiddleware: true,
run: async () => {
const result = checkConfigFile(SUPERSET_CONFIG_PATH);
const result = checkConfigFile(getSupersetConfigPath());
if (!result.valid) process.exitCode = 1;
return { data: result, message: describe(result) };
},
Expand Down
22 changes: 7 additions & 15 deletions packages/cli/src/commands/scripts/add/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
import { writeConfig } from "../../../lib/config";
import { readSettingsRow } from "../../../lib/settings";
import {
createLocalSettingsDb,
withTempSupersetHome,
} from "../../../lib/settings/test-helpers";

let activeOrganizationId: string | undefined = "org-a";

const realConfig = await import("../../../lib/config");
mock.module("../../../lib/config", () => ({
...realConfig,
readConfig: () => ({ organizationId: activeOrganizationId }),
}));

const { default: addScriptCommand } = await import("./command");
const { default: scriptsMeta } = await import("../meta");
import scriptsMeta from "../meta";
import addScriptCommand from "./command";

const home = withTempSupersetHome("superset-cli-script-command-");
let previousOrgOverride: string | undefined;
Expand All @@ -35,10 +27,10 @@ function invoke(overrides: Record<string, unknown> = {}) {
beforeEach(() => {
previousOrgOverride = process.env.SUPERSET_ORGANIZATION_ID;
delete process.env.SUPERSET_ORGANIZATION_ID;
activeOrganizationId = "org-a";
// Port 9 (discard) has no listener, so no desktop app acknowledges.
process.env.DESKTOP_NOTIFICATIONS_PORT = "9";
createLocalSettingsDb(home.dir);
writeConfig({ organizationId: "org-a" });
});

afterEach(() => {
Expand Down Expand Up @@ -78,13 +70,13 @@ describe("scripts add", () => {
});

test("requires an active organization", async () => {
activeOrganizationId = undefined;
writeConfig({});
await expect(invoke()).rejects.toThrow(/No active organization/);
expect(readSettingsRow()).toBeUndefined();
});

test("honors the SUPERSET_ORGANIZATION_ID override like other commands", async () => {
activeOrganizationId = undefined;
writeConfig({});
process.env.SUPERSET_ORGANIZATION_ID = "org-env";
await invoke();
expect(
Expand Down
22 changes: 7 additions & 15 deletions packages/cli/src/commands/scripts/manage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,28 @@ import {
beforeEach,
describe,
expect,
mock,
test,
} from "bun:test";
import { writeConfig } from "../../lib/config";
import { readSettingsRow } from "../../lib/settings";
import { writeSettings } from "../../lib/settings/local-settings";
import {
createLocalSettingsDb,
withTempSupersetHome,
} from "../../lib/settings/test-helpers";
import addCommand from "./add/command";
import deleteCommand from "./delete/command";
import editCommand from "./edit/command";
import listCommand from "./list/command";

let activeOrganizationId: string | undefined = "org-a";
let desktopRefreshed = false;

const realConfig = await import("../../lib/config");
mock.module("../../lib/config", () => ({
...realConfig,
readConfig: () => ({ organizationId: activeOrganizationId }),
}));

const desktop = Bun.serve({
port: 0,
fetch: () => new Response(null, { status: desktopRefreshed ? 200 : 503 }),
});
afterAll(() => desktop.stop(true));

const { default: addCommand } = await import("./add/command");
const { default: listCommand } = await import("./list/command");
const { default: editCommand } = await import("./edit/command");
const { default: deleteCommand } = await import("./delete/command");

const home = withTempSupersetHome("superset-cli-scripts-manage-");
let previousOrgOverride: string | undefined;

Expand Down Expand Up @@ -70,10 +62,10 @@ function seedImported() {
beforeEach(() => {
previousOrgOverride = process.env.SUPERSET_ORGANIZATION_ID;
delete process.env.SUPERSET_ORGANIZATION_ID;
activeOrganizationId = "org-a";
desktopRefreshed = false;
process.env.DESKTOP_NOTIFICATIONS_PORT = String(desktop.port);
createLocalSettingsDb(home.dir);
writeConfig({ organizationId: "org-a" });
});

afterEach(() => {
Expand Down Expand Up @@ -185,7 +177,7 @@ describe("scripts edit", () => {

test("requires an active organization", async () => {
seedImported();
activeOrganizationId = undefined;
writeConfig({});
await expect(
run(editCommand, { args: { id: "gh-1" }, options: { name: "x" } }),
).rejects.toThrow(/No active organization/);
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/start/command.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as p from "@clack/prompts";
import { boolean, CLIError, number, string } from "@superset/cli-framework";
import { command } from "../../lib/command";
import { SUPERSET_CONFIG_PATH } from "../../lib/config";
import { getSupersetConfigPath } from "../../lib/config";
import { waitForUnresponsiveHost } from "../../lib/host/liveness";
import {
isProcessAlive,
Expand Down Expand Up @@ -65,7 +65,7 @@ export default command({
organizationId: organization.id,
sessionToken: ctx.bearer,
authConfigPath:
ctx.authSource === "oauth" ? SUPERSET_CONFIG_PATH : undefined,
ctx.authSource === "oauth" ? getSupersetConfigPath() : undefined,
api: ctx.api,
port: options.port,
daemon: options.daemon ?? false,
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/commands/start/manifest-liveness.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ process.env.SUPERSET_HOME_DIR = tempHome;
// before the manifest check under test ever runs.
delete process.env.SUPERSET_ORGANIZATION_ID;

// Imports below must come after SUPERSET_HOME_DIR is set: config.ts and
// manifest.ts both read it once at module load.
const { readManifest, writeManifest } = await import("../../lib/host/manifest");
const startCommand = (await import("./command")).default;

Expand Down
10 changes: 6 additions & 4 deletions packages/cli/src/commands/status/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterAll, describe, expect, mock, test } from "bun:test";
import { afterAll, afterEach, describe, expect, mock, test } from "bun:test";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
Expand All @@ -8,9 +8,9 @@ const originalSupersetHomeDir = process.env.SUPERSET_HOME_DIR;
const tempHome = mkdtempSync(join(tmpdir(), "superset-cli-status-"));
process.env.SUPERSET_HOME_DIR = tempHome;

// Imports below must come after SUPERSET_HOME_DIR is set: config.ts and
// manifest.ts both read it once at module load.
const { writeManifest } = await import("../../lib/host/manifest");
const { removeManifest, writeManifest } = await import(
"../../lib/host/manifest"
);
const statusCommand = (await import("./command")).default;

afterAll(() => {
Expand All @@ -24,6 +24,8 @@ afterAll(() => {

const ORG = { id: "org-1", slug: "org-1", name: "Palette" };

afterEach(() => removeManifest(ORG.id));

function makeCtx(): CliContext {
const query = mock(async () => [ORG]);
const hostListQuery = mock(async () => []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { buildTree, routeCommand } from "@superset/cli-framework";

// The cloud availability check caches to SUPERSET_HOME_DIR, read at import.
const previousHome = process.env.SUPERSET_HOME_DIR;
const home = mkdtempSync(join(tmpdir(), "superset-ws-archive-"));
process.env.SUPERSET_HOME_DIR = home;
Expand Down
Loading
Loading