tdd-enforcer 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,12 +105,13 @@ export function registerHooks(pi: ExtensionAPI): void {
105
105
 
106
106
  const existingText = event.content.map((c) => ("text" in c ? c.text : "")).join("");
107
107
  return {
108
+ isError: true,
108
109
  content: [
109
110
  {
110
111
  type: "text",
111
112
  text:
112
113
  existingText +
113
- `\n\n⚠️ ${phase.toUpperCase()}: bash modified locked files: ${violations.join(", ")}\n` +
114
+ `\n\n ${phase.toUpperCase()}: bash modified locked files: ${violations.join(", ")}\n` +
114
115
  `next_tdd_phase blocked until reverted. ` +
115
116
  `Inspect with: cd .pi/tdd && git diff HEAD -- ${violations[0]}`,
116
117
  },
@@ -0,0 +1,73 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { mkdirSync, writeFileSync, rmSync, readFileSync, existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { tmpdir } from "node:os";
5
+ import { tddLog } from "./log.js";
6
+
7
+ function setup() {
8
+ const dir = join(tmpdir(), `tdd-log-test-${Date.now()}`);
9
+ mkdirSync(dir, { recursive: true });
10
+ return dir;
11
+ }
12
+
13
+ function teardown(dir: string) {
14
+ rmSync(dir, { recursive: true, force: true });
15
+ }
16
+
17
+ describe("tddLog", () => {
18
+ it("creates the log file if it doesn't exist", () => {
19
+ const dir = setup();
20
+ tddLog(dir, "INFO", "hello");
21
+ expect(existsSync(join(dir, "tdd.log"))).toBe(true);
22
+ teardown(dir);
23
+ });
24
+
25
+ it("appends multiple lines", () => {
26
+ const dir = setup();
27
+ tddLog(dir, "INFO", "line one");
28
+ tddLog(dir, "DEBUG", "line two");
29
+ const content = readFileSync(join(dir, "tdd.log"), "utf-8");
30
+ const lines = content.trim().split("\n");
31
+ expect(lines).toHaveLength(2);
32
+ expect(lines[0]).toContain("[INFO]");
33
+ expect(lines[0]).toContain("line one");
34
+ expect(lines[1]).toContain("[DEBUG]");
35
+ expect(lines[1]).toContain("line two");
36
+ teardown(dir);
37
+ });
38
+
39
+ it("includes data as JSON when provided", () => {
40
+ const dir = setup();
41
+ tddLog(dir, "INFO", "with data", { key: "val", num: 42 });
42
+ const content = readFileSync(join(dir, "tdd.log"), "utf-8");
43
+ expect(content).toContain('{"key":"val","num":42}');
44
+ teardown(dir);
45
+ });
46
+
47
+ it("trims to last 1000 lines when exceeded", () => {
48
+ const dir = setup();
49
+ for (let i = 0; i < 1005; i++) {
50
+ tddLog(dir, "DEBUG", `line ${i}`);
51
+ }
52
+ const content = readFileSync(join(dir, "tdd.log"), "utf-8");
53
+ const lines = content.trim().split("\n");
54
+ expect(lines).toHaveLength(1000);
55
+ expect(lines[0]).toContain("line 5");
56
+ expect(lines[999]).toContain("line 1004");
57
+ teardown(dir);
58
+ });
59
+
60
+ it("does not throw on invalid tddDir", () => {
61
+ expect(() => tddLog("/nonexistent/path/tdd", "INFO", "fail")).not.toThrow();
62
+ });
63
+
64
+ it("handles missing data field gracefully", () => {
65
+ const dir = setup();
66
+ tddLog(dir, "WARN", "no data");
67
+ const content = readFileSync(join(dir, "tdd.log"), "utf-8");
68
+ expect(content).toContain("[WARN]");
69
+ expect(content).toContain("no data");
70
+ expect(content).not.toContain("{}");
71
+ teardown(dir);
72
+ });
73
+ });
@@ -19,8 +19,8 @@ export function tddLog(
19
19
 
20
20
  // Trim to last MAX_LINES
21
21
  const content = readFileSync(logPath, "utf-8");
22
- const lines = content.split("\n");
23
- if (lines.length > MAX_LINES + 1) {
22
+ const lines = content.trimEnd().split("\n");
23
+ if (lines.length > MAX_LINES) {
24
24
  const trimmed = lines.slice(-MAX_LINES).join("\n") + "\n";
25
25
  writeFileSync(logPath, trimmed, "utf-8");
26
26
  }
@@ -1,3 +1,4 @@
1
+ import { join } from "node:path";
1
2
  import { Type } from "typebox";
2
3
  import { execSync } from "node:child_process";
3
4
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
@@ -15,7 +16,7 @@ import {
15
16
  import type { TestRunner, Phase } from "../../engine/index.js";
16
17
  import { getNudgePrompt } from "./prompts.js";
17
18
  import { loadTddState } from "./helpers.js";
18
-
19
+ import { tddLog } from "./log.js";
19
20
 
20
21
  export function registerTools(pi: ExtensionAPI): void {
21
22
  pi.registerTool({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tdd-enforcer",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "type": "module",
5
5
  "keywords": [
6
6
  "pi-package"