/**
 * Regression test for #3471: headless-query must load extensions from
 * the synced agent directory, not directly from src/resources/.
 */

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

const __dirname = dirname(fileURLToPath(import.meta.url));

test("headless-query resolves from agent extensions dir (#3471)", () => {
	const src = readFileSync(join(__dirname, "..", "headless-query.ts"), "utf-8");
	assert.ok(
		src.includes("agentExtensionsDir") || src.includes(".sf/agent"),
		"headless-query must resolve from synced agent directory",
	);
});

test("cli.ts calls initResources before headless (#3471)", () => {
	const src = readFileSync(join(__dirname, "..", "cli.ts"), "utf-8");
	const headlessBlock = src.slice(src.indexOf("sf headless"));
	const initIdx = headlessBlock.indexOf("initResources");
	const runIdx = headlessBlock.indexOf("runHeadless");
	assert.ok(initIdx !== -1, "initResources must be called before headless");
	assert.ok(initIdx < runIdx, "initResources must come before runHeadless");
});
