test(HAI-029): add tests for task show command and fix description display
- Add tests for runTaskShow output formatting - Fix task show header to display full description - Exclude test files from CLI build tsconfig - Add vitest config for CLI package - Clean up unused types and triage code
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
"scripts": {
|
||||
"dev": "tsx src/bin.ts",
|
||||
"build": "tsc",
|
||||
"typecheck": "tsc --noEmit"
|
||||
"typecheck": "tsc --noEmit",
|
||||
"test": "vitest run"
|
||||
},
|
||||
"dependencies": {
|
||||
"@hai/core": "workspace:*",
|
||||
@@ -17,6 +18,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "^4.19.0",
|
||||
"typescript": "^5.7.0"
|
||||
"typescript": "^5.7.0",
|
||||
"vitest": "^3.1.0"
|
||||
}
|
||||
}
|
||||
|
||||
94
packages/cli/src/commands/task.test.ts
Normal file
94
packages/cli/src/commands/task.test.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
|
||||
// Mock @hai/core before importing the module under test
|
||||
vi.mock("@hai/core", () => {
|
||||
const COLUMNS = ["triage", "specified", "in-progress", "review", "done"];
|
||||
const COLUMN_LABELS: Record<string, string> = {
|
||||
triage: "Triage",
|
||||
specified: "Specified",
|
||||
"in-progress": "In Progress",
|
||||
review: "Review",
|
||||
done: "Done",
|
||||
};
|
||||
|
||||
return {
|
||||
TaskStore: vi.fn(),
|
||||
COLUMNS,
|
||||
COLUMN_LABELS,
|
||||
};
|
||||
});
|
||||
|
||||
// Mock @hai/engine
|
||||
vi.mock("@hai/engine", () => ({ aiMergeTask: vi.fn() }));
|
||||
|
||||
import { TaskStore } from "@hai/core";
|
||||
import { runTaskShow } from "./task.js";
|
||||
|
||||
function makeTask(overrides: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id: "HAI-001",
|
||||
description: "A short description",
|
||||
column: "triage",
|
||||
dependencies: [],
|
||||
steps: [],
|
||||
currentStep: 0,
|
||||
log: [],
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
describe("runTaskShow", () => {
|
||||
let logSpy: ReturnType<typeof vi.spyOn>;
|
||||
|
||||
beforeEach(() => {
|
||||
logSpy = vi.spyOn(console, "log").mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
it("displays the full description without truncation when no title", async () => {
|
||||
const longDesc = "A".repeat(120); // well over 60 chars
|
||||
const task = makeTask({ description: longDesc });
|
||||
|
||||
(TaskStore as unknown as ReturnType<typeof vi.fn>).mockImplementation(() => ({
|
||||
init: vi.fn(),
|
||||
getTask: vi.fn().mockResolvedValue(task),
|
||||
}));
|
||||
|
||||
await runTaskShow("HAI-001");
|
||||
|
||||
const headerLine = logSpy.mock.calls.find(
|
||||
(call) => typeof call[0] === "string" && call[0].includes("HAI-001:")
|
||||
);
|
||||
expect(headerLine).toBeDefined();
|
||||
expect(headerLine![0]).toContain(longDesc);
|
||||
// Ensure no truncation happened
|
||||
expect(headerLine![0]).not.toContain(longDesc.slice(0, 60) + "…");
|
||||
expect(headerLine![0].length).toBeGreaterThan(60 + " HAI-001: ".length);
|
||||
});
|
||||
|
||||
it("displays the title when present instead of description", async () => {
|
||||
const task = makeTask({
|
||||
title: "My Task Title",
|
||||
description: "This is the full description that should not appear in the header",
|
||||
});
|
||||
|
||||
(TaskStore as unknown as ReturnType<typeof vi.fn>).mockImplementation(() => ({
|
||||
init: vi.fn(),
|
||||
getTask: vi.fn().mockResolvedValue(task),
|
||||
}));
|
||||
|
||||
await runTaskShow("HAI-001");
|
||||
|
||||
const headerLine = logSpy.mock.calls.find(
|
||||
(call) => typeof call[0] === "string" && call[0].includes("HAI-001:")
|
||||
);
|
||||
expect(headerLine).toBeDefined();
|
||||
expect(headerLine![0]).toContain("My Task Title");
|
||||
expect(headerLine![0]).not.toContain("This is the full description");
|
||||
});
|
||||
});
|
||||
@@ -106,7 +106,7 @@ export async function runTaskShow(id: string) {
|
||||
const task = await store.getTask(id);
|
||||
|
||||
console.log();
|
||||
console.log(` ${task.id}: ${task.title || task.description.slice(0, 60)}`);
|
||||
console.log(` ${task.id}: ${task.title || task.description}`);
|
||||
console.log(` Column: ${COLUMN_LABELS[task.column]}${task.size ? ` · Size: ${task.size}` : ""}${task.reviewLevel !== undefined ? ` · Review: ${task.reviewLevel}` : ""}`);
|
||||
if (task.dependencies.length) {
|
||||
console.log(` Dependencies: ${task.dependencies.join(", ")}`);
|
||||
|
||||
@@ -4,5 +4,6 @@
|
||||
"outDir": "dist",
|
||||
"rootDir": "src"
|
||||
},
|
||||
"include": ["src"]
|
||||
"include": ["src"],
|
||||
"exclude": ["src/**/*.test.ts"]
|
||||
}
|
||||
|
||||
7
packages/cli/vitest.config.ts
Normal file
7
packages/cli/vitest.config.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
include: ["src/**/*.test.ts"],
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user