import test from "node:test"
import assert from "node:assert/strict"
import { readFileSync } from "node:fs"

const ipcSource = readFileSync(new URL("../src/main/ipc.ts", import.meta.url), "utf8")
const indexSource = readFileSync(new URL("../src/main/index.ts", import.meta.url), "utf8")

test("desktop IPC wires tasks:list-by-date to TaskPanelService", () => {
  assert.match(ipcSource, /taskPanelService\.listByDate\(date\)/)
  assert.doesNotMatch(ipcSource, /tasksListByDate,\s*async \(\) => \[\]/)
  assert.match(indexSource, /new TaskPanelService\(systemSummary\.userDataPath\)/)
})

test("workspace-entry success paths archive xhs and douyin executions without throwing", () => {
  assert.match(ipcSource, /recordWorkspaceTaskPanelExecution/)
  assert.match(ipcSource, /xiaohongshu\|xhs\|小红书/)
  assert.match(ipcSource, /douyin\|抖音\|tiktok/)
})

test("task panel expert matching prioritizes project id before filesystem path", () => {
  assert.match(ipcSource, /const normalizedProjectId = projectId\.trim\(\)\.toLowerCase\(\)/)
  assert.match(ipcSource, /const projectBaseName = path\.basename\(projectRoot\)\.toLowerCase\(\)/)
  assert.match(ipcSource, /isXhsProject\(normalizedProjectId\)/)
  assert.match(ipcSource, /isDouyinProject\(normalizedProjectId\)/)
  assert.doesNotMatch(ipcSource, /`\$\{projectId\} \$\{path\.basename\(projectRoot\)\} \$\{projectRoot\}`/)
})
