@leolastforce/chalice-test-methods 0.0.0-stage → 0.1.0
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/README.md +34 -2
- package/index.ts +74 -0
- package/package.json +32 -5
package/README.md
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
-
|
|
1
|
+
> Chalice package, check out github.com/leolastforce/Chalice
|
|
2
|
+
# Test methods
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
## Overview on how test methods works
|
|
5
|
+
Test Methods lets a project describe how its tests should be run, then gives those instructions to Chalice before it starts working on a prompt.
|
|
6
|
+
|
|
7
|
+
## Why use this?
|
|
8
|
+
The main incentive is that you can enable and disable the instructions unlike AGENTS.md without really having to explicitly tell the agent to or not to run tests with whatever contents TESTMETHODS.md contains.
|
|
9
|
+
|
|
10
|
+
It isn't inherently a strong feature, more so quality of life, nonetheless, it doesn't hurt to just leave it blank! (that's what /goal said and look what happened to it lol)
|
|
11
|
+
|
|
12
|
+
TLDR: TESTMETHODS.md separates optional test-execution instructions from general project guidance.
|
|
13
|
+
|
|
14
|
+
## Setup
|
|
15
|
+
Create a TESTMETHODS.md file in the project's root.
|
|
16
|
+
|
|
17
|
+
> Example:
|
|
18
|
+
```md
|
|
19
|
+
Before considering a feature complete:
|
|
20
|
+
- Run the unit tests.
|
|
21
|
+
- Run the formatter.
|
|
22
|
+
- Run the type checker.
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Session control
|
|
26
|
+
|
|
27
|
+
Test-method prompting is enabled by default when `TESTMETHODS.md` contains content. Use the command below to control it for the current session:
|
|
28
|
+
|
|
29
|
+
```text
|
|
30
|
+
/dotestmethods toggle prompting
|
|
31
|
+
/dotestmethods true enable prompting
|
|
32
|
+
/dotestmethods false disable prompting
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
The setting is stored in the session tree, so it follows the current session history. If `TESTMETHODS.md` is missing or empty, no test-method instructions are added (grass is green).
|
package/index.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
4
|
+
|
|
5
|
+
const TEST_METHODS_ENTRY_TYPE = "session-test-methods";
|
|
6
|
+
const TEST_METHODS_FILE_NAME = "TESTMETHODS.md";
|
|
7
|
+
|
|
8
|
+
interface SessionTestMethodsEntry {
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface TestMethodsState {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readSessionState(ctx: ExtensionContext): TestMethodsState {
|
|
17
|
+
let enabled = true;
|
|
18
|
+
|
|
19
|
+
for (const entry of ctx.sessionManager.getBranch()) {
|
|
20
|
+
if (entry.type !== "custom" || entry.customType !== TEST_METHODS_ENTRY_TYPE) continue;
|
|
21
|
+
|
|
22
|
+
const data = entry.data as SessionTestMethodsEntry | undefined;
|
|
23
|
+
if (typeof data?.enabled === "boolean") enabled = data.enabled;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return { enabled };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function readProjectTestMethods(ctx: ExtensionContext): string | undefined {
|
|
30
|
+
const path = join(ctx.cwd, TEST_METHODS_FILE_NAME);
|
|
31
|
+
if (!existsSync(path)) return undefined;
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const content = readFileSync(path, "utf8").trim();
|
|
35
|
+
return content || undefined;
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default function testMethodsExtension(pi: ExtensionAPI): void {
|
|
42
|
+
|
|
43
|
+
pi.registerCommand("dotestmethods", {
|
|
44
|
+
description: "Enables or disables test-method prompting for the session",
|
|
45
|
+
handler: async (args, ctx) => {
|
|
46
|
+
const value = args.trim().toLowerCase();
|
|
47
|
+
if (value !== "" && value !== "true" && value !== "false") {
|
|
48
|
+
ctx.ui.notify("Usage: /dotestmethods [true|false] (omit to toggle)", "info");
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const enabled = value === "" ? !readSessionState(ctx).enabled : value === "true";
|
|
53
|
+
pi.appendEntry<SessionTestMethodsEntry>(TEST_METHODS_ENTRY_TYPE, { enabled });
|
|
54
|
+
ctx.ui.notify(`Test-method prompting ${enabled ? "enabled" : "disabled"} for this session`, "info");
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
pi.on("before_agent_start", async (event, ctx) => {
|
|
59
|
+
const state = readSessionState(ctx);
|
|
60
|
+
if (!state.enabled) return;
|
|
61
|
+
|
|
62
|
+
const projectMethods = readProjectTestMethods(ctx);
|
|
63
|
+
if (!projectMethods) return;
|
|
64
|
+
|
|
65
|
+
const sources = [`Project test methods (from ${TEST_METHODS_FILE_NAME}):\n${projectMethods}`];
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
systemPrompt: [
|
|
69
|
+
event.systemPrompt,
|
|
70
|
+
`Test methods and testing requirements:\n\nFollow the applicable test methods below. When implementing a feature, run the required test method(s) before considering the feature complete.\n\n${sources.join("\n\n")}`,
|
|
71
|
+
].join("\n\n"),
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@leolastforce/chalice-test-methods",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Chalice module for the simple and soon to be hated TESTMETHODS.md feature",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"chalice",
|
|
9
|
+
"pi-package"
|
|
10
|
+
],
|
|
11
|
+
"pi": {
|
|
12
|
+
"extensions": [
|
|
13
|
+
"./index.ts"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.ts"
|
|
18
|
+
],
|
|
19
|
+
"peerDependencies": {
|
|
20
|
+
"@earendil-works/pi-coding-agent": "*"
|
|
21
|
+
},
|
|
22
|
+
"peerDependenciesMeta": {
|
|
23
|
+
"@earendil-works/pi-coding-agent": {
|
|
24
|
+
"optional": true
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"engines": {
|
|
28
|
+
"node": ">=22.19.0"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
}
|
|
33
|
+
}
|