@jwilger/pi-development-system 0.10.0 → 0.10.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/package.json
CHANGED
|
@@ -39,8 +39,9 @@ This skill is how to work so that gate never fires.
|
|
|
39
39
|
## When RED is not required
|
|
40
40
|
|
|
41
41
|
RED is for **adding or changing first-party production behaviour** when no existing
|
|
42
|
-
failing test already proves the required change. These are exempt, and
|
|
43
|
-
|
|
42
|
+
failing test already proves the required change. These are exempt. Docs, config, test and generated files are
|
|
43
|
+
exempt by path, so the gate never asks. For the rest, *name* the exemption in a
|
|
44
|
+
recorded departure (scope `slice`; one departure covers the slice):
|
|
44
45
|
|
|
45
46
|
- docs or metadata only
|
|
46
47
|
- functionality removal (the proof is that nothing still depends on it)
|
|
@@ -85,8 +85,17 @@ function kindOf(line: string): Kind | undefined {
|
|
|
85
85
|
return matched.find((k) => k.marker === "#![allow(") ?? matched[0];
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
/** A rustfmt-wrapped `#[allow(\n lint,\n reason = "...",\n)]`: the reason sits on a later line. */
|
|
89
|
+
function wrappedReason(lines: readonly string[], index: number): boolean {
|
|
90
|
+
const attr = lines.slice(index, index + 8);
|
|
91
|
+
const end = attr.findIndex((l) => l.includes(")]"));
|
|
92
|
+
const text = (end < 0 ? attr : attr.slice(0, end + 1)).join(" ");
|
|
93
|
+
return long(lastGroup(/reason\s*=\s*"([^"]*)"/, text));
|
|
94
|
+
}
|
|
95
|
+
|
|
88
96
|
function reasonOf(kind: Kind, lines: readonly string[], index: number): boolean {
|
|
89
97
|
const line = lines[index] ?? "";
|
|
98
|
+
if (/^\s*#!?\[(?:allow|expect)\(\s*$/.test(line) && wrappedReason(lines, index)) return true;
|
|
90
99
|
const match = kind.pattern.exec(line);
|
|
91
100
|
const after = match === null ? "" : line.slice(match.index + match[0].length);
|
|
92
101
|
return (
|
package/src/core/path-class.ts
CHANGED
|
@@ -9,8 +9,9 @@ const DOCS_EXT = /\.(?:md|mdx|rst|txt|adoc)$/i;
|
|
|
9
9
|
const DOCS_NAME = /^(?:LICENSE|LICENCE|CHANGELOG|NOTICE|AUTHORS|CONTRIBUTING)(?:\..*)?$/i;
|
|
10
10
|
const CONFIG_EXT = /\.(?:json|jsonc|toml|ya?ml|ini|cfg|conf|env|properties)$/i;
|
|
11
11
|
const CONFIG_NAME = /^(?:Dockerfile|Makefile|justfile|Rakefile|Gemfile|Procfile)$/i;
|
|
12
|
+
// Build output directories only count at the repo root; `src/build/` is usually real source.
|
|
12
13
|
const GENERATED_DIR =
|
|
13
|
-
/(?:^|\/)(?:node_modules|dist|target|build|coverage|
|
|
14
|
+
/(?:^|\/)(?:node_modules|__generated__|\.next)\/|^(?:dist|target|build|coverage|vendor|generated)\//;
|
|
14
15
|
const GENERATED_FILE =
|
|
15
16
|
/(?:\.generated\.|\.gen\.|\.min\.[cm]?js$|\.pb\.go$|\.snap$|(?:^|\/)(?:package-lock\.json|Cargo\.lock|pnpm-lock\.yaml|yarn\.lock|bun\.lockb?)$|\.lock$)/;
|
|
16
17
|
|
package/src/core/test-runner.ts
CHANGED
|
@@ -52,8 +52,15 @@ export type ResultLike = {
|
|
|
52
52
|
readonly isError: boolean;
|
|
53
53
|
readonly text: string;
|
|
54
54
|
readonly structured?: unknown;
|
|
55
|
+
/** The command that ran; used to tell whether its exit status could have been masked. */
|
|
56
|
+
readonly command?: string;
|
|
55
57
|
};
|
|
56
58
|
|
|
59
|
+
/** A pipe or sequence makes the shell report the last command's status, not the runner's. */
|
|
60
|
+
const MASKS_STATUS = /\||;/;
|
|
61
|
+
const FAILURE_MARKERS =
|
|
62
|
+
/^# fail [1-9]|test result: FAILED|\b[1-9]\d* (?:failed|failing)\b|^FAILED\b|^FAIL\b|\bnot ok\b/m;
|
|
63
|
+
|
|
57
64
|
const isRecord = (v: unknown): v is Record<string, unknown> =>
|
|
58
65
|
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
59
66
|
|
|
@@ -64,7 +71,10 @@ export function exitCodeOf(result: ResultLike): number {
|
|
|
64
71
|
}
|
|
65
72
|
const line = /Command exited with code (\d+)\s*$/.exec(result.text);
|
|
66
73
|
if (line?.[1] !== undefined) return Number(line[1]);
|
|
67
|
-
|
|
74
|
+
if (result.isError) return 1;
|
|
75
|
+
// `npm test | tail` exits 0 whatever the tests did; trust the output over the masked status.
|
|
76
|
+
const masked = result.command !== undefined && MASKS_STATUS.test(result.command);
|
|
77
|
+
return masked && FAILURE_MARKERS.test(result.text) ? 1 : 0;
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
/** The last few non-empty output lines, redacted and bounded: what the runner said at the end. */
|
|
@@ -10,6 +10,13 @@ export type RedFirstGuardDeps = { pi: ExtensionAPI; state: SessionState };
|
|
|
10
10
|
|
|
11
11
|
const GATE_ID = "tdd.red-first";
|
|
12
12
|
|
|
13
|
+
/** Test code written inside a source file (Rust `#[cfg(test)]`/`#[test]`): that edit is the RED step itself. */
|
|
14
|
+
const INLINE_TEST = /#\[(?:cfg\(test\)|test|tokio::test|rstest)\]/;
|
|
15
|
+
|
|
16
|
+
const newText = (
|
|
17
|
+
input: { content: string } | { edits: ReadonlyArray<{ newText: string }> },
|
|
18
|
+
): string => ("content" in input ? input.content : input.edits.map((e) => e.newText).join("\n"));
|
|
19
|
+
|
|
13
20
|
/** Exemption classes a machine cannot see; the departure names which one applies (research 02). */
|
|
14
21
|
const JUDGED_EXEMPTIONS =
|
|
15
22
|
"functionality removal, documented third-party behaviour, a change already shown by a failing test, " +
|
|
@@ -34,6 +41,7 @@ export function registerRedFirstGuard(deps: RedFirstGuardDeps): void {
|
|
|
34
41
|
if (lastTestRun !== undefined && lastTestRun.exitCode !== 0) return undefined;
|
|
35
42
|
const path = normalizeRepoPath(ctx.cwd, event.input.path, homedir());
|
|
36
43
|
if (classifyPath(path) !== "source") return undefined;
|
|
44
|
+
if (INLINE_TEST.test(newText(event.input))) return undefined;
|
|
37
45
|
if (departure.hasOpen()) {
|
|
38
46
|
departure.consume();
|
|
39
47
|
return undefined;
|