4a58aa1657
- Type renames: CIConfig → CIAgentConfig, DEFAULT_CI_CONFIG → DEFAULT_CIAGENT_CONFIG - Type renames: CiMetadata → CIAgentMetadata, ParsedCiCommit → ParsedCIAgentCommit - Function renames: initCI → initCIAgent, isCIInitialized → isCIAgentInitialized - Function renames: extractCiBlock → extractCIAgentBlock, parseCiBlock → parseCIAgentBlock - Class renames: CiFiles → CIAgentFiles - Import paths: ci-files.js → ciagent-files.js - Directory paths: .ci/ → .ciagent/ across all source and test files - Check names: ".ci directory exists" → ".ciagent directory exists" - Check names: "CI config valid" → "CIAgent config valid" - Temp dir names: ci-*-test- → ciagent-*-test- - CLI examples: "ci init" → "ciagent init" - Fix deepMerge infinite recursion bug in config.ts - ---ci---/---/ci--- block markers preserved unchanged - All 31 test suites, 370 tests passing ---ci--- phase: 1 milestone: v0.5 plan: 07 task: 07-01-01 status: execute ---/ci---
112 lines
4.5 KiB
TypeScript
112 lines
4.5 KiB
TypeScript
import * as fs from "node:fs";
|
|
import * as path from "node:path";
|
|
import * as os from "node:os";
|
|
import { StructuralVerification } from "../verification/structural.js";
|
|
|
|
describe("StructuralVerification", () => {
|
|
let tempDir: string;
|
|
|
|
beforeEach(() => {
|
|
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "ciagent-structural-test-"));
|
|
});
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
});
|
|
|
|
function setupProjectStructure(hasCIDir = true, hasRoadmap = true, hasCIAgentConfig = true, hasSpec = true) {
|
|
if (hasCIDir) {
|
|
const ciDir = path.join(tempDir, ".ciagent");
|
|
fs.mkdirSync(ciDir, { recursive: true });
|
|
if (hasRoadmap) {
|
|
fs.writeFileSync(path.join(ciDir, "ROADMAP.md"), "# Roadmap\n\n## Phases\n\n### Phase 1: Init\n**Goal**: Set up project\n**Status**: not_started\n");
|
|
}
|
|
}
|
|
if (hasCIAgentConfig) {
|
|
const ciDir = path.join(tempDir, ".ciagent");
|
|
fs.mkdirSync(ciDir, { recursive: true });
|
|
fs.writeFileSync(path.join(ciDir, "config.json"), JSON.stringify({ autonomy: { level: "full" } }, null, 2));
|
|
}
|
|
if (hasSpec) {
|
|
const specDir = path.join(tempDir, ".ciagent");
|
|
if (!fs.existsSync(specDir)) fs.mkdirSync(specDir, { recursive: true });
|
|
fs.writeFileSync(path.join(specDir, "specification.md"), "# Project\n## Objective\nBuild a REST API for task management\n\n## Requirements\n- User auth\n- CRUD\n");
|
|
}
|
|
}
|
|
|
|
it("passes when all structural elements exist", async () => {
|
|
setupProjectStructure(true, true, true, true);
|
|
const verifier = new StructuralVerification();
|
|
const result = await verifier.verify(tempDir, 1);
|
|
|
|
expect(result.layer).toBe(1);
|
|
expect(result.name).toBe("Structural");
|
|
expect(result.checks.length).toBeGreaterThan(0);
|
|
|
|
const phaseDirCheck = result.checks.find((c) => c.name === ".ciagent directory exists");
|
|
expect(phaseDirCheck?.status).toBe("pass");
|
|
|
|
const planCheck = result.checks.find((c) => c.name === "ROADMAP.md exists");
|
|
expect(planCheck?.status).toBe("pass");
|
|
|
|
const configCheck = result.checks.find((c) => c.name === "CIAgent config valid");
|
|
expect(configCheck?.status).toBe("pass");
|
|
|
|
const specCheck = result.checks.find((c) => c.name === "Specification exists");
|
|
expect(specCheck?.status).toBe("pass");
|
|
});
|
|
|
|
it("fails when .ci directory is missing", async () => {
|
|
setupProjectStructure(false, false, false, false);
|
|
const verifier = new StructuralVerification();
|
|
const result = await verifier.verify(tempDir, 1);
|
|
|
|
const phaseDirCheck = result.checks.find((c) => c.name === ".ciagent directory exists");
|
|
expect(phaseDirCheck?.status).toBe("fail");
|
|
});
|
|
|
|
it("warns when ROADMAP.md is missing", async () => {
|
|
setupProjectStructure(true, false, true, true);
|
|
const verifier = new StructuralVerification();
|
|
const result = await verifier.verify(tempDir, 1);
|
|
|
|
const planCheck = result.checks.find((c) => c.name === "ROADMAP.md exists");
|
|
expect(planCheck?.status).toBe("warning");
|
|
});
|
|
|
|
it("fails when CI config has invalid JSON", async () => {
|
|
const ciDir = path.join(tempDir, ".ciagent");
|
|
fs.mkdirSync(ciDir, { recursive: true });
|
|
fs.writeFileSync(path.join(ciDir, "config.json"), "not valid json{{{");
|
|
fs.mkdirSync(path.join(tempDir, ".ciagent"), { recursive: true });
|
|
|
|
const verifier = new StructuralVerification();
|
|
const result = await verifier.verify(tempDir, 1);
|
|
|
|
const configCheck = result.checks.find((c) => c.name === "CIAgent config valid");
|
|
expect(configCheck?.status).toBe("fail");
|
|
});
|
|
|
|
it("detects TODO/FIXME patterns in source files", async () => {
|
|
const srcDir = path.join(tempDir, "src");
|
|
fs.mkdirSync(srcDir, { recursive: true });
|
|
fs.writeFileSync(path.join(srcDir, "app.ts"), "export function main() { /* TODO: implement */ }");
|
|
const ciDir = path.join(tempDir, ".ciagent");
|
|
fs.mkdirSync(ciDir, { recursive: true });
|
|
fs.writeFileSync(path.join(ciDir, "config.json"), "{}");
|
|
fs.writeFileSync(path.join(ciDir, "specification.md"), "# Test\n## Objective\nBuild it");
|
|
|
|
const verifier = new StructuralVerification();
|
|
const result = await verifier.verify(tempDir, 1);
|
|
|
|
const stubsCheck = result.checks.find((c) => c.name === "No stubs/TODOs");
|
|
expect(stubsCheck?.status).toMatch(/warning|fail/);
|
|
});
|
|
|
|
it("reports duration", async () => {
|
|
setupProjectStructure(true, true, true, true);
|
|
const verifier = new StructuralVerification();
|
|
const result = await verifier.verify(tempDir, 1);
|
|
expect(result.duration_ms).toBeGreaterThanOrEqual(0);
|
|
});
|
|
}); |