import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { test } from "vitest";

const source = readFileSync(
	join(
		process.cwd(),
		"packages/coding-agent/src/modes/interactive/interactive-mode.ts",
	),
	"utf-8",
);

test("interactive_tui_autoreload_uses_existing_reload_path", () => {
	assert.match(
		source,
		/Purpose: make the TUI pick up SF's own code\/resource fixes/,
	);
	assert.match(source, /private startAutoReloadWatcher\(\): void/);
	assert.match(source, /private async checkAutoReload\(\): Promise<void>/);
	assert.match(source, /await this\.handleReloadCommand\(\)/);
});

test("interactive_tui_runtime_reload_exits_for_launcher_restart", () => {
	const reloadStart = source.indexOf("private async handleReloadCommand()");
	assert.ok(reloadStart >= 0, "handleReloadCommand should exist");
	const reloadBody = source.slice(reloadStart, reloadStart + 1200);

	assert.match(reloadBody, /computeInteractiveRuntimeFingerprint\(\)/);
	assert.match(reloadBody, /process\.exit\(INTERACTIVE_RELOAD_EXIT_CODE\)/);
});
