v0.2.0: Git-native architecture (#1)

This commit was merged in pull request #1.
This commit is contained in:
2026-05-29 12:59:45 +00:00
parent 9cf5c000d9
commit 6e637e4af0
50 changed files with 5852 additions and 135 deletions
+234 -19
View File
@@ -1,5 +1,18 @@
import * as fs from "node:fs";
import * as path from "node:path";
import { VerificationLayer, VerificationResult, VerificationCheck } from "./types.js";
const TEST_FRAMEWORK_PATTERNS = [
{ name: "Jest", pattern: /jest\.config\.(js|ts|mjs|cjs)|"jest":\s*\{|describe\s*\(|it\s*\(|test\s*\(/ },
{ name: "Mocha", pattern: /mocha|describe\s*\(|it\s*\(/ },
{ name: "Vitest", pattern: /vitest\.config\.(ts|js)|from\s+['"]vitest['"]/ },
];
const MUST_HAVE_KEYWORDS = [
"must", "shall", "required", "needs to", "has to", "will",
"should", "critical", "essential", "mandatory", "necessary",
];
export class BehavioralVerification extends VerificationLayer {
readonly layer = 2;
readonly name = "Behavioral";
@@ -8,31 +21,233 @@ export class BehavioralVerification extends VerificationLayer {
const start = Date.now();
const checks: VerificationCheck[] = [];
checks.push({
name: "Unit tests pass",
status: "skipped",
message: "Test generation and execution not yet implemented",
});
checks.push({
name: "Integration tests pass",
status: "skipped",
message: "Integration test generation not yet implemented",
});
checks.push({
name: "Must-have requirements covered",
status: "skipped",
message: "Requirement coverage analysis not yet implemented",
});
checks.push(this.checkTestFramework(projectPath));
checks.push(this.checkTestFiles(projectPath));
checks.push(this.checkSpecificationRequirements(projectPath));
checks.push(this.checkPlanMustHaves(projectPath, phase));
checks.push(this.checkCodeHasExports(projectPath));
const passed = checks.every((c) => c.status !== "fail");
return {
layer: this.layer,
name: this.name,
passed: true,
passed,
checks,
summary: `Behavioral verification layer (placeholder)`,
summary: `${checks.filter((c) => c.status === "pass").length}/${checks.length} checks passed`,
duration_ms: Date.now() - start,
};
}
private checkTestFramework(projectPath: string): VerificationCheck {
const packageJsonPath = path.join(projectPath, "package.json");
if (!fs.existsSync(packageJsonPath)) {
return this.check("Test framework detected", "skipped", "No package.json found");
}
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
const devDeps = Object.keys(packageJson.devDependencies || {});
const deps = Object.keys(packageJson.dependencies || {});
const allDeps = [...devDeps, ...deps];
const testDeps = allDeps.filter((d) =>
["jest", "mocha", "vitest", "jasmine", "ava", "tape"].includes(d)
);
if (testDeps.length > 0) {
return this.check(
"Test framework detected",
"pass",
`Found test framework(s): ${testDeps.join(", ")}`
);
}
const configFiles = ["jest.config.js", "jest.config.ts", "vitest.config.ts", "vitest.config.js", ".mocharc.yml", ".mocharc.json"];
const foundConfig = configFiles.filter((f) => fs.existsSync(path.join(projectPath, f)));
if (foundConfig.length > 0) {
return this.check(
"Test framework detected",
"pass",
`Found test config: ${foundConfig.join(", ")}`
);
}
return this.check(
"Test framework detected",
"warning",
"No test framework found in dependencies or config files"
);
}
private checkTestFiles(projectPath: string): VerificationCheck {
const testDirs = ["src", "test", "tests", "__tests__"];
const testFiles: string[] = [];
for (const dir of testDirs) {
const fullPath = path.join(projectPath, dir);
if (fs.existsSync(fullPath)) {
testFiles.push(...this.findTestFiles(fullPath, projectPath));
}
}
if (testFiles.length === 0) {
return this.check(
"Test files exist",
"warning",
"No test files found. Behavioral verification cannot run without tests."
);
}
return this.check(
"Test files exist",
"pass",
`Found ${testFiles.length} test file(s)`
);
}
private checkSpecificationRequirements(projectPath: string): VerificationCheck {
const specPath = path.join(projectPath, ".ci", "specification.md");
if (!fs.existsSync(specPath)) {
return this.check(
"Specification requirements traceable",
"skipped",
"No specification file found"
);
}
const content = fs.readFileSync(specPath, "utf-8");
const requirements = content
.split("\n")
.filter((line) => line.trim().startsWith("- "))
.map((line) => line.trim().slice(2));
const mustHaves = requirements.filter((r) =>
MUST_HAVE_KEYWORDS.some((kw) => r.toLowerCase().includes(kw))
);
if (mustHaves.length === 0 && requirements.length === 0) {
return this.check(
"Specification requirements traceable",
"warning",
"No requirements found in specification"
);
}
return this.check(
"Specification requirements traceable",
"pass",
`Found ${requirements.length} requirement(s), ${mustHaves.length} must-have(s)`
);
}
private checkPlanMustHaves(projectPath: string, phase: number): VerificationCheck {
const planPath = path.join(
projectPath,
".planning",
"phases",
`phase-${phase}`,
"PLAN.md"
);
if (!fs.existsSync(planPath)) {
return this.check(
"Plan must-haves covered",
"skipped",
`No PLAN.md found for phase ${phase}`
);
}
const content = fs.readFileSync(planPath, "utf-8");
const hasMustHaves = content.toLowerCase().includes("must");
const hasTasks = content.includes("- [") || content.includes("* [");
if (!hasTasks && !hasMustHaves) {
return this.check(
"Plan must-haves covered",
"warning",
"PLAN.md has no tasks or must-have items"
);
}
return this.check(
"Plan must-haves covered",
"pass",
"PLAN.md contains task definitions"
);
}
private checkCodeHasExports(projectPath: string): VerificationCheck {
const srcDir = path.join(projectPath, "src");
if (!fs.existsSync(srcDir)) {
return this.check("Source code has exports", "skipped", "No src/ directory found");
}
const tsFiles = this.collectTsFiles(srcDir);
const filesWithoutExports: string[] = [];
for (const file of tsFiles) {
const content = fs.readFileSync(file, "utf-8");
const hasExport = /\bexport\s+/.test(content);
if (!hasExport && content.trim().length > 0) {
filesWithoutExports.push(path.relative(projectPath, file));
}
}
if (filesWithoutExports.length === 0) {
return this.check(
"Source code has exports",
"pass",
`All ${tsFiles.length} source files have exports`
);
}
if (filesWithoutExports.length > tsFiles.length * 0.5) {
return this.check(
"Source code has exports",
"warning",
`${filesWithoutExports.length}/${tsFiles.length} files have no exports`
);
}
return this.check(
"Source code has exports",
"pass",
`Most files export symbols (${tsFiles.length - filesWithoutExports.length}/${tsFiles.length})`
);
}
private collectTsFiles(dir: string): string[] {
const files: string[] = [];
if (!fs.existsSync(dir)) return files;
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory() && entry.name !== "node_modules") {
files.push(...this.collectTsFiles(fullPath));
} else if (entry.name.endsWith(".ts") && !entry.name.endsWith(".d.ts") && !entry.name.endsWith(".test.ts")) {
files.push(fullPath);
}
}
return files;
}
private findTestFiles(dir: string, projectPath: string): string[] {
const files: string[] = [];
if (!fs.existsSync(dir)) return files;
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory() && entry.name !== "node_modules") {
files.push(...this.findTestFiles(fullPath, projectPath));
} else if (
entry.name.endsWith(".test.ts") ||
entry.name.endsWith(".test.js") ||
entry.name.endsWith(".spec.ts") ||
entry.name.endsWith(".spec.js")
) {
files.push(path.relative(projectPath, fullPath));
}
}
return files;
}
}