import assert from "node:assert/strict";
import { describe, it } from 'vitest';
import {
	installGenaiProxyExtension,
	resolveProxyPort,
} from "../proxy-command.ts";

describe("genai-proxy command boundary", () => {
	it("resolves default and explicit proxy ports from flag values", () => {
		const result = [resolveProxyPort(true), resolveProxyPort("8080")];

		assert.deepEqual(result, [3000, 8080]);
	});

	it("registers the startup flag and slash command", () => {
		const registeredFlags: Array<{
			name: string;
			type: string;
			allowNoValue: boolean;
			hasStartupHandler: boolean;
		}> = [];
		const registeredCommands: string[] = [];

		installGenaiProxyExtension({
			registerCommand: (name) => {
				registeredCommands.push(name);
			},
			registerFlag: (name, options) => {
				registeredFlags.push({
					name,
					type: options.type,
					allowNoValue: options.allowNoValue ?? false,
					hasStartupHandler: typeof options.onStartup === "function",
				});
			},
		});

		assert.deepEqual(
			{ flags: registeredFlags, commands: registeredCommands },
			{
				flags: [
					{
						name: "gemini-cli-proxy",
						type: "string",
						allowNoValue: true,
						hasStartupHandler: true,
					},
				],
				commands: ["genai-proxy"],
			},
		);
	});
});
