/**
 * Smoke test for memoryExtraction diagnostics in headless-query output.
 *
 * Source-level guard: the query snapshot exposes recent extraction attempts
 * and their failure_class so operators can inspect memory closeout health
 * without sqlite3 or interactive /memory status.
 */

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));
const querySrc = readFileSync(
	join(__dirname, "..", "headless-query.ts"),
	"utf-8",
);

test("QuerySnapshot type declares memoryExtraction section", () => {
	assert.match(querySrc, /memoryExtraction\?:/);
	assert.match(querySrc, /total_attempts:\s*number/);
	assert.match(querySrc, /subsystem_pause:/);
	assert.match(querySrc, /paused:\s*boolean/);
	assert.match(querySrc, /recent_attempts:/);
	assert.match(querySrc, /failure_class:\s*string \| null/);
});

test("buildQuerySnapshot reads memory extraction attempts", () => {
	assert.match(querySrc, /listMemoryExtractionAttempts\(5\)/);
	assert.match(querySrc, /memory_extraction_attempts/);
	assert.match(querySrc, /failure_class/);
	assert.match(querySrc, /failure_class = 'auth'/);
});
