tdd-enforcer 0.2.9 → 0.3.1
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.
- package/adapters/pi/index.test.ts +19 -28
- package/adapters/pi/index.ts +17 -11
- package/package.json +1 -1
|
@@ -430,10 +430,8 @@ describe("handleBeforeAgentStart", () => {
|
|
|
430
430
|
};
|
|
431
431
|
}
|
|
432
432
|
|
|
433
|
-
function
|
|
434
|
-
|
|
435
|
-
} {
|
|
436
|
-
return { systemPromptOptions: { promptGuidelines: [] } };
|
|
433
|
+
function _makeEvent(): { systemPrompt: string } {
|
|
434
|
+
return { systemPrompt: "" };
|
|
437
435
|
}
|
|
438
436
|
|
|
439
437
|
beforeEach(() => {
|
|
@@ -441,7 +439,7 @@ describe("handleBeforeAgentStart", () => {
|
|
|
441
439
|
mockLoadTddState = vi.fn();
|
|
442
440
|
});
|
|
443
441
|
|
|
444
|
-
it("
|
|
442
|
+
it("returns instructions when TDD enabled", async () => {
|
|
445
443
|
mockLoadTddState.mockReturnValue({
|
|
446
444
|
ok: true,
|
|
447
445
|
state: { enabled: true, current: "red" },
|
|
@@ -452,39 +450,32 @@ describe("handleBeforeAgentStart", () => {
|
|
|
452
450
|
timeoutSeconds: 30,
|
|
453
451
|
},
|
|
454
452
|
});
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
event as any,
|
|
453
|
+
const result = await handleBeforeAgentStart(
|
|
454
|
+
{ systemPrompt: "" } as any,
|
|
458
455
|
{ cwd: "/test" } as any,
|
|
459
456
|
makeDeps(),
|
|
460
457
|
);
|
|
461
|
-
expect(
|
|
462
|
-
expect(
|
|
463
|
-
|
|
464
|
-
);
|
|
465
|
-
expect(
|
|
466
|
-
"next_tdd_phase",
|
|
467
|
-
);
|
|
468
|
-
expect(event.systemPromptOptions.promptGuidelines[2]).toContain(
|
|
469
|
-
"cycle so reverting is cheap",
|
|
470
|
-
);
|
|
458
|
+
expect(result).toBeDefined();
|
|
459
|
+
expect(result?.systemPrompt).toContain("TDD enforcement");
|
|
460
|
+
expect(result?.systemPrompt).toContain("locked files will be blocked");
|
|
461
|
+
expect(result?.systemPrompt).toContain("cycle so reverting is cheap");
|
|
462
|
+
expect(result?.systemPrompt).not.toContain("next_tdd_phase");
|
|
471
463
|
});
|
|
472
464
|
|
|
473
|
-
it("
|
|
465
|
+
it("returns undefined when TDD not setup", async () => {
|
|
474
466
|
mockLoadTddState.mockReturnValue({
|
|
475
467
|
ok: false,
|
|
476
468
|
reason: "Missing .pi/tdd/",
|
|
477
469
|
});
|
|
478
|
-
const
|
|
479
|
-
|
|
480
|
-
event as any,
|
|
470
|
+
const result = await handleBeforeAgentStart(
|
|
471
|
+
{ systemPrompt: "" } as any,
|
|
481
472
|
{ cwd: "/test" } as any,
|
|
482
473
|
makeDeps(),
|
|
483
474
|
);
|
|
484
|
-
expect(
|
|
475
|
+
expect(result).toBeUndefined();
|
|
485
476
|
});
|
|
486
477
|
|
|
487
|
-
it("
|
|
478
|
+
it("returns disabled message when TDD was disabled", async () => {
|
|
488
479
|
mockLoadTddState.mockReturnValue({
|
|
489
480
|
ok: true,
|
|
490
481
|
state: { enabled: false, current: "red" },
|
|
@@ -495,12 +486,12 @@ describe("handleBeforeAgentStart", () => {
|
|
|
495
486
|
timeoutSeconds: 30,
|
|
496
487
|
},
|
|
497
488
|
});
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
event as any,
|
|
489
|
+
const result = await handleBeforeAgentStart(
|
|
490
|
+
{ systemPrompt: "" } as any,
|
|
501
491
|
{ cwd: "/test" } as any,
|
|
502
492
|
makeDeps(),
|
|
503
493
|
);
|
|
504
|
-
expect(
|
|
494
|
+
expect(result).toBeDefined();
|
|
495
|
+
expect(result?.systemPrompt).toContain("was disabled");
|
|
505
496
|
});
|
|
506
497
|
});
|
package/adapters/pi/index.ts
CHANGED
|
@@ -149,22 +149,28 @@ export async function handleTddStatus(
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
export async function handleBeforeAgentStart(
|
|
152
|
-
event: {
|
|
153
|
-
systemPromptOptions: { promptGuidelines: string[] };
|
|
154
|
-
},
|
|
152
|
+
event: { systemPrompt: string },
|
|
155
153
|
ctx: { cwd: string },
|
|
156
154
|
deps: {
|
|
157
155
|
loadTddState: typeof loadTddState;
|
|
158
156
|
},
|
|
159
|
-
): Promise<
|
|
157
|
+
): Promise<{ systemPrompt: string } | undefined> {
|
|
160
158
|
const tdd = deps.loadTddState(ctx.cwd);
|
|
161
|
-
if (!tdd.ok
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
if (!tdd.ok) return;
|
|
160
|
+
|
|
161
|
+
if (tdd.state.enabled) {
|
|
162
|
+
return {
|
|
163
|
+
systemPrompt:
|
|
164
|
+
event.systemPrompt +
|
|
165
|
+
"\n\nYou are working under TDD enforcement. Each phase restricts which files you can modify — locked files will be blocked automatically.\n" +
|
|
166
|
+
"Minimise the scope of each TDD cycle so reverting is cheap.",
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
systemPrompt:
|
|
171
|
+
event.systemPrompt +
|
|
172
|
+
"\n\nTDD enforcement was disabled. File restrictions are no longer enforced.",
|
|
173
|
+
};
|
|
168
174
|
}
|
|
169
175
|
|
|
170
176
|
export async function handleTddJump(
|