@payconductor/houndsman 0.2.0 → 0.4.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 +18 -6
- package/package.json +1 -1
- package/src/cli/arg-parser.ts +8 -0
- package/src/cli/commands/command.ts +23 -0
- package/src/cli/commands/context-command.ts +40 -0
- package/src/cli/commands/doctor-command.ts +60 -0
- package/src/cli/commands/findings-command.ts +38 -0
- package/src/cli/commands/help-command.ts +13 -0
- package/src/cli/commands/registry.ts +34 -0
- package/src/cli/commands/review-command.ts +21 -0
- package/src/cli/commands/server-command.ts +37 -0
- package/src/cli/commands/setup-command.ts +34 -0
- package/src/cli/commands/watchdog-command.ts +34 -0
- package/src/cli/help.ts +47 -0
- package/src/cli/index.ts +60 -268
- package/src/core/arg-parser.ts +48 -0
- package/src/core/commands/context.ts +29 -13
- package/src/core/commands/findings.ts +185 -260
- package/src/core/commands/review.ts +21 -39
- package/src/core/commands/scaffold.ts +189 -80
- package/src/core/commands/setup.ts +16 -11
- package/src/core/commands/update.ts +7 -7
- package/src/core/commands/watchdog.ts +8 -80
- package/src/core/config.ts +24 -25
- package/src/core/defaults.ts +20 -0
- package/src/core/diff-source.ts +1 -13
- package/src/core/doc-discoverer.ts +25 -15
- package/src/core/domain/budget.ts +42 -0
- package/src/core/domain/classification.ts +94 -0
- package/src/core/domain/diff.ts +53 -0
- package/src/core/domain/watchdog.ts +96 -0
- package/src/core/engine/carryover.ts +67 -0
- package/src/core/engine/houndsman-engine.ts +65 -0
- package/src/core/engine/review-scope.ts +95 -0
- package/src/core/engine/review-session.ts +79 -0
- package/src/core/file-classifier.ts +11 -67
- package/src/core/findings-state.ts +193 -100
- package/src/core/git-revision.ts +14 -40
- package/src/core/git-runner.ts +46 -0
- package/src/core/github-review.ts +4 -33
- package/src/core/jev/jev-candidates.ts +49 -35
- package/src/core/orchestrator.ts +247 -421
- package/src/core/paths.ts +26 -11
- package/src/core/pr-context.ts +39 -51
- package/src/core/project-config.ts +56 -0
- package/src/core/renderers/batch-presenter.ts +40 -0
- package/src/core/renderers/brief-renderer.ts +23 -0
- package/src/core/renderers/findings-presenter.ts +74 -0
- package/src/core/renderers/manifest-writer.ts +123 -0
- package/src/core/renderers/report-renderer.ts +66 -0
- package/src/core/renderers/verify-presenter.ts +50 -0
- package/src/core/renderers/watchdog-presenter.ts +100 -0
- package/src/core/report-builder.ts +12 -7
- package/src/core/run-layout.ts +8 -0
- package/src/core/run-status.ts +29 -59
- package/src/core/services/clock.ts +12 -0
- package/src/core/services/file-classifier.ts +34 -0
- package/src/core/services/fix-batch-builder.ts +13 -0
- package/src/core/services/gh-client.ts +54 -0
- package/src/core/services/git-repository.ts +139 -0
- package/src/core/services/project-files.ts +91 -0
- package/src/core/services/verifier.ts +58 -0
- package/src/core/storage/factory.ts +24 -0
- package/src/core/storage/file/file-storage.ts +269 -0
- package/src/core/storage/paths.ts +64 -0
- package/src/core/storage/repo-identity.ts +70 -0
- package/src/core/storage/sqlite/mappers.ts +160 -0
- package/src/core/storage/sqlite/schema.ts +108 -0
- package/src/core/storage/sqlite/sqlite-storage.ts +427 -0
- package/src/core/storage/types.ts +143 -0
- package/src/core/storage/work-area.ts +191 -0
- package/src/core/verify.ts +2 -1
- package/src/core/watchdog-registry.ts +58 -16
- package/src/index.ts +57 -6
- package/src/server/artifacts.ts +8 -61
- package/src/server/client/ArtifactsPanel.tsx +137 -23
- package/src/server/client/FindingCard.tsx +37 -6
- package/src/server/client/MarkdownText.tsx +101 -0
- package/src/server/client/SubmitModal.tsx +9 -4
- package/src/server/client/code-highlight.ts +422 -0
- package/src/server/client/constants.ts +130 -24
- package/src/server/client/json-highlight.ts +55 -0
- package/src/server/client/markdown.ts +153 -0
- package/src/server/client/types.ts +23 -0
- package/src/server/index.ts +155 -245
- package/src/server/run-repository.ts +299 -0
- package/src/skill/OUTPUT-FORMAT.md +6 -4
- package/src/skill/README.md +22 -14
- package/src/skill/SETUP.md +4 -4
- package/src/skill/fix.md +5 -5
- package/src/skill/hunt.md +27 -18
- package/src/skill/train.md +1 -1
- package/src/skill/verify.md +5 -5
- package/src/tests/__snapshots__/baseline.test.ts.snap +825 -0
- package/src/tests/baseline.test.ts +555 -493
- package/src/tests/cli.test.ts +40 -19
- package/src/tests/code-highlight.test.ts +123 -0
- package/src/tests/domain.test.ts +328 -0
- package/src/tests/findings-commands.test.ts +153 -131
- package/src/tests/findings-state.test.ts +6 -3
- package/src/tests/fixtures/fake-project.ts +0 -1
- package/src/tests/infrastructure.test.ts +205 -0
- package/src/tests/markdown.test.ts +89 -0
- package/src/tests/review-scripts.test.ts +8 -5
- package/src/tests/run-status.test.ts +33 -23
- package/src/tests/server.test.ts +108 -75
- package/src/tests/storage.test.ts +386 -0
|
@@ -1,493 +1,555 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Baseline de comportamento (Fase 0 do refactor OO).
|
|
3
|
-
*
|
|
4
|
-
* Congela a saída observável do motor — briefs, relatórios, camada gerada e
|
|
5
|
-
* artefatos de `prepare`/`finalize` — para provar que o refactor não muda
|
|
6
|
-
* comportamento. Qualquer divergência nesses snapshots é uma regressão.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { describe, expect, test } from "bun:test";
|
|
10
|
-
import { createHash } from "node:crypto";
|
|
11
|
-
import {
|
|
12
|
-
mkdirSync,
|
|
13
|
-
mkdtempSync,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
rmSync,
|
|
17
|
-
statSync,
|
|
18
|
-
writeFileSync,
|
|
19
|
-
} from "node:fs";
|
|
20
|
-
import { tmpdir } from "node:os";
|
|
21
|
-
import { join, relative } from "node:path";
|
|
22
|
-
import { renderBrief } from "../core/brief";
|
|
23
|
-
import {
|
|
24
|
-
createScaffoldContext,
|
|
25
|
-
syncGeneratedFiles,
|
|
26
|
-
writeUserLayer,
|
|
27
|
-
} from "../core/commands/scaffold";
|
|
28
|
-
import { defineHoundsmanConfig } from "../core/config";
|
|
29
|
-
import { defaultOptions, finalize, prepare } from "../core/orchestrator";
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
import
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.replace(
|
|
80
|
-
.replace(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
id: "id-
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
{
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
],
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
"
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
git(cwd, ["
|
|
335
|
-
git(cwd, ["config", "
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
writeFileSync(join(cwd, "src", "alpha", "
|
|
339
|
-
writeFileSync(join(cwd, "
|
|
340
|
-
|
|
341
|
-
git(cwd, ["
|
|
342
|
-
git(cwd, ["
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
);
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
git(cwd, ["
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
process.chdir(cwd);
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
"
|
|
458
|
-
"
|
|
459
|
-
"
|
|
460
|
-
"
|
|
461
|
-
"
|
|
462
|
-
"
|
|
463
|
-
"
|
|
464
|
-
"
|
|
465
|
-
"
|
|
466
|
-
"
|
|
467
|
-
"
|
|
468
|
-
"
|
|
469
|
-
"
|
|
470
|
-
"
|
|
471
|
-
"
|
|
472
|
-
"
|
|
473
|
-
"
|
|
474
|
-
"
|
|
475
|
-
"
|
|
476
|
-
"
|
|
477
|
-
"
|
|
478
|
-
"
|
|
479
|
-
"
|
|
480
|
-
"
|
|
481
|
-
"
|
|
482
|
-
"
|
|
483
|
-
"
|
|
484
|
-
"
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Baseline de comportamento (Fase 0 do refactor OO).
|
|
3
|
+
*
|
|
4
|
+
* Congela a saída observável do motor — briefs, relatórios, camada gerada e
|
|
5
|
+
* artefatos de `prepare`/`finalize` — para provar que o refactor não muda
|
|
6
|
+
* comportamento. Qualquer divergência nesses snapshots é uma regressão.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, expect, test } from "bun:test";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import {
|
|
12
|
+
mkdirSync,
|
|
13
|
+
mkdtempSync,
|
|
14
|
+
readdirSync,
|
|
15
|
+
readFileSync,
|
|
16
|
+
rmSync,
|
|
17
|
+
statSync,
|
|
18
|
+
writeFileSync,
|
|
19
|
+
} from "node:fs";
|
|
20
|
+
import { tmpdir } from "node:os";
|
|
21
|
+
import { join, relative } from "node:path";
|
|
22
|
+
import { renderBrief } from "../core/brief";
|
|
23
|
+
import {
|
|
24
|
+
createScaffoldContext,
|
|
25
|
+
syncGeneratedFiles,
|
|
26
|
+
writeUserLayer,
|
|
27
|
+
} from "../core/commands/scaffold";
|
|
28
|
+
import { defineHoundsmanConfig } from "../core/config";
|
|
29
|
+
import { defaultOptions, finalize, prepare, reviewContext } from "../core/orchestrator";
|
|
30
|
+
import { displayPath } from "../core/paths";
|
|
31
|
+
import {
|
|
32
|
+
type MergedFinding,
|
|
33
|
+
renderDomainReport,
|
|
34
|
+
renderReport,
|
|
35
|
+
type WatchdogReport,
|
|
36
|
+
} from "../core/report-builder";
|
|
37
|
+
import { resolveRepoIdentity } from "../core/storage/repo-identity";
|
|
38
|
+
import { SQLiteStorageProvider } from "../core/storage/sqlite/sqlite-storage";
|
|
39
|
+
import { defineWatchdog } from "../core/types";
|
|
40
|
+
import * as facade from "../index";
|
|
41
|
+
|
|
42
|
+
// ---------------------------------------------------------------------------
|
|
43
|
+
// Config baseline (projeto fake, 1 watchdog para artefatos determinísticos)
|
|
44
|
+
// ---------------------------------------------------------------------------
|
|
45
|
+
|
|
46
|
+
const baselineWatchdog = defineWatchdog({
|
|
47
|
+
id: "alpha",
|
|
48
|
+
name: "Alpha",
|
|
49
|
+
description: "Watchdog baseline.",
|
|
50
|
+
scope: "src/alpha/**",
|
|
51
|
+
classify: [{ value: "^src/alpha/" }],
|
|
52
|
+
rules: [
|
|
53
|
+
{ severity: "blocking", text: "Nunca usar `any`." },
|
|
54
|
+
{ severity: "attention", text: "Promover: validar a entrada." },
|
|
55
|
+
],
|
|
56
|
+
contextFiles: ["README.md"],
|
|
57
|
+
breakingChange: true,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const baselineConfig = defineHoundsmanConfig({
|
|
61
|
+
projectName: "Baseline",
|
|
62
|
+
watchdogs: { alpha: baselineWatchdog },
|
|
63
|
+
exclusions: [/^dist\//],
|
|
64
|
+
docMappings: [[/^src\//, ["README.md"]]],
|
|
65
|
+
alwaysIncludeDocs: ["README.md"],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// ---------------------------------------------------------------------------
|
|
69
|
+
// Helpers
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
|
|
72
|
+
/** Substitui valores voláteis (ids, timestamps, SHAs) por marcadores estáveis. */
|
|
73
|
+
function normalizeArtifacts(text: string): string {
|
|
74
|
+
return text
|
|
75
|
+
.replace(
|
|
76
|
+
/"(createdAt|updatedAt|generatedAt|startedAt|at)": "[^"]*"/g,
|
|
77
|
+
'"$1": "<timestamp>"',
|
|
78
|
+
)
|
|
79
|
+
.replace(/"\d{4}-\d{2}-\d{2}T[^"]*"/g, '"<timestamp>"')
|
|
80
|
+
.replace(
|
|
81
|
+
/\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b/g,
|
|
82
|
+
"<uuid>",
|
|
83
|
+
)
|
|
84
|
+
.replace(/\b[0-9a-f]{40}\b/g, "<sha>")
|
|
85
|
+
.replace(/\b[0-9a-f]{16}\b/g, "<fingerprint>")
|
|
86
|
+
.replace(/\b[0-9a-f]{10}\b/g, "<id>")
|
|
87
|
+
.replace(/\d{4}-\d{2}-\d{2}/g, "<date>");
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Lista recursiva de arquivos (caminhos relativos, ordenados). */
|
|
91
|
+
function listFiles(root: string): string[] {
|
|
92
|
+
const files: string[] = [];
|
|
93
|
+
const walk = (dir: string): void => {
|
|
94
|
+
for (const name of readdirSync(dir)) {
|
|
95
|
+
const full = join(dir, name);
|
|
96
|
+
if (statSync(full).isDirectory()) walk(full);
|
|
97
|
+
else files.push(relative(root, full).replace(/\\/g, "/"));
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
walk(root);
|
|
101
|
+
return files.sort();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Executa git no diretório e devolve stdout (lança em falha). */
|
|
105
|
+
function git(cwd: string, args: string[]): string {
|
|
106
|
+
const result = Bun.spawnSync(["git", ...args], {
|
|
107
|
+
cwd,
|
|
108
|
+
stdout: "pipe",
|
|
109
|
+
stderr: "pipe",
|
|
110
|
+
});
|
|
111
|
+
if (result.exitCode !== 0) {
|
|
112
|
+
throw new Error(`git ${args.join(" ")}: ${result.stderr.toString()}`);
|
|
113
|
+
}
|
|
114
|
+
return result.stdout.toString();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
// Brief
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
|
|
121
|
+
describe("baseline — brief", () => {
|
|
122
|
+
test("defaultRenderBrief (contexto, churn, overflow, candidatos e deletados)", () => {
|
|
123
|
+
const brief = renderBrief(baselineWatchdog, {
|
|
124
|
+
watchdogId: "alpha",
|
|
125
|
+
files: ["src/alpha/a.ts", "src/alpha/b.ts"],
|
|
126
|
+
statuses: {
|
|
127
|
+
"src/alpha/a.ts": { status: "modified" },
|
|
128
|
+
"src/alpha/b.ts": { status: "added" },
|
|
129
|
+
},
|
|
130
|
+
churn: {
|
|
131
|
+
"src/alpha/a.ts": { additions: 3, deletions: 1 },
|
|
132
|
+
"src/alpha/b.ts": { additions: 2, deletions: 0 },
|
|
133
|
+
},
|
|
134
|
+
overflow: ["src/alpha/c.ts"],
|
|
135
|
+
deleted: ["src/alpha/old.ts"],
|
|
136
|
+
branch: "feature/x",
|
|
137
|
+
outputPath: "/workspace/work/review-x/findings/alpha.json",
|
|
138
|
+
outputFormatPath: ".houndsman/core/skill/OUTPUT-FORMAT.md",
|
|
139
|
+
docs: ["AGENTS.md", "README.md"],
|
|
140
|
+
context: {
|
|
141
|
+
objective: "Entregar X",
|
|
142
|
+
motivation: "Reduzir Y",
|
|
143
|
+
changeSummary: ["Faz A", "Remove B"],
|
|
144
|
+
},
|
|
145
|
+
candidates: [
|
|
146
|
+
{
|
|
147
|
+
file: "src/alpha/a.ts",
|
|
148
|
+
severity: "blocking",
|
|
149
|
+
confidence: 0.82,
|
|
150
|
+
rule: "Nunca usar `any`.",
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(brief).toMatchSnapshot();
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// ---------------------------------------------------------------------------
|
|
160
|
+
// Relatório
|
|
161
|
+
// ---------------------------------------------------------------------------
|
|
162
|
+
|
|
163
|
+
const reports: WatchdogReport[] = [
|
|
164
|
+
{
|
|
165
|
+
watchdogId: "alpha",
|
|
166
|
+
reviewedFiles: ["src/alpha/a.ts", "src/alpha/b.ts"],
|
|
167
|
+
skipped: ["src/alpha/c.ts"],
|
|
168
|
+
findings: [
|
|
169
|
+
{
|
|
170
|
+
rule: "Nunca usar `any`.",
|
|
171
|
+
severity: "blocking",
|
|
172
|
+
file: "src/alpha/a.ts",
|
|
173
|
+
line: 1,
|
|
174
|
+
message: "any detectado",
|
|
175
|
+
action: "tipar",
|
|
176
|
+
evidence: "export const a: any = 1;",
|
|
177
|
+
id: "id-alpha",
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
rule: "Promover: validar a entrada.",
|
|
181
|
+
severity: "attention",
|
|
182
|
+
file: "src/alpha/b.ts",
|
|
183
|
+
line: 2,
|
|
184
|
+
message: "sem validação",
|
|
185
|
+
action: "adicionar schema",
|
|
186
|
+
id: "id-beta",
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
watchdogId: "beta",
|
|
192
|
+
reviewedFiles: ["src/beta/x.test.ts"],
|
|
193
|
+
skipped: [],
|
|
194
|
+
findings: [],
|
|
195
|
+
},
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
const merged: MergedFinding[] = [
|
|
199
|
+
{ ...reports[0].findings[0], watchdogs: ["alpha"] },
|
|
200
|
+
{ ...reports[0].findings[1], watchdogs: ["alpha", "beta"] },
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
const reportContext = {
|
|
204
|
+
available: true,
|
|
205
|
+
source: {
|
|
206
|
+
number: 42,
|
|
207
|
+
title: "Entrega X",
|
|
208
|
+
url: "https://example.test/pull/42",
|
|
209
|
+
head: "feature/x",
|
|
210
|
+
base: "main",
|
|
211
|
+
},
|
|
212
|
+
objective: "Entregar X",
|
|
213
|
+
motivation: "Reduzir Y",
|
|
214
|
+
changeSummary: ["Faz A", "Remove B"],
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
describe("baseline — relatório", () => {
|
|
218
|
+
test("renderReport consolidado", () => {
|
|
219
|
+
const md = renderReport(
|
|
220
|
+
"feature/x",
|
|
221
|
+
reports,
|
|
222
|
+
merged,
|
|
223
|
+
{ classified: { alpha: ["src/alpha/a.ts", "src/alpha/b.ts"], beta: [] } },
|
|
224
|
+
reportContext,
|
|
225
|
+
[
|
|
226
|
+
{
|
|
227
|
+
watchdogId: "alpha",
|
|
228
|
+
rule: "Nunca usar `any`.",
|
|
229
|
+
severity: "blocking",
|
|
230
|
+
file: "src/alpha/a.ts",
|
|
231
|
+
confidence: 0.82,
|
|
232
|
+
questionKey: "alpha::rule-0",
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
(id) => (id === "alpha" ? "Alpha" : "Beta"),
|
|
236
|
+
[
|
|
237
|
+
{
|
|
238
|
+
id: "alpha",
|
|
239
|
+
name: "Alpha",
|
|
240
|
+
file: "review.alpha.md",
|
|
241
|
+
findings: 2,
|
|
242
|
+
reviewedFiles: 2,
|
|
243
|
+
expectedFiles: 2,
|
|
244
|
+
},
|
|
245
|
+
],
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
expect(normalizeArtifacts(md)).toMatchSnapshot();
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("renderDomainReport isolado", () => {
|
|
252
|
+
const md = renderDomainReport(
|
|
253
|
+
"feature/x",
|
|
254
|
+
reports[0],
|
|
255
|
+
merged,
|
|
256
|
+
2,
|
|
257
|
+
reportContext,
|
|
258
|
+
(id) => (id === "alpha" ? "Alpha" : "Beta"),
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
expect(normalizeArtifacts(md)).toMatchSnapshot();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// ---------------------------------------------------------------------------
|
|
266
|
+
// Camada gerada pelo setup/update
|
|
267
|
+
// ---------------------------------------------------------------------------
|
|
268
|
+
|
|
269
|
+
/** Arquivos-template cujo conteúdo precisa permanecer idêntico. */
|
|
270
|
+
const TEMPLATE_FILES = [
|
|
271
|
+
"houndsman.config.ts",
|
|
272
|
+
".houndsman/core/types.ts",
|
|
273
|
+
".houndsman/watchdogs/example.ts",
|
|
274
|
+
".houndsman/watchdogs/index.ts",
|
|
275
|
+
".houndsman/exclusions.ts",
|
|
276
|
+
".houndsman/doc-mappings.ts",
|
|
277
|
+
".houndsman/.gitignore",
|
|
278
|
+
".agents/skills/houndsman/SKILL.md",
|
|
279
|
+
".claude/skills/houndsman/SKILL.md",
|
|
280
|
+
];
|
|
281
|
+
|
|
282
|
+
describe("baseline — camada gerada", () => {
|
|
283
|
+
test("setup gera os mesmos arquivos e conteúdos", () => {
|
|
284
|
+
const cwd = mkdtempSync(join(tmpdir(), "houndsman-baseline-scaffold-"));
|
|
285
|
+
try {
|
|
286
|
+
const ctx = createScaffoldContext(cwd, ["--name", "acme"], false);
|
|
287
|
+
writeUserLayer(ctx);
|
|
288
|
+
syncGeneratedFiles(ctx);
|
|
289
|
+
|
|
290
|
+
const files = listFiles(cwd);
|
|
291
|
+
expect(files).toMatchSnapshot();
|
|
292
|
+
|
|
293
|
+
const contents = Object.fromEntries(
|
|
294
|
+
TEMPLATE_FILES.map((file) => [
|
|
295
|
+
file,
|
|
296
|
+
readFileSync(join(cwd, file), "utf8"),
|
|
297
|
+
]),
|
|
298
|
+
);
|
|
299
|
+
expect(contents).toMatchSnapshot();
|
|
300
|
+
|
|
301
|
+
// Assets copiados (skill docs): hash estável, sem colar o markdown inteiro.
|
|
302
|
+
const skillDocs = files
|
|
303
|
+
.filter((file) => file.startsWith(".houndsman/core/skill/"))
|
|
304
|
+
.map((file) => ({
|
|
305
|
+
file,
|
|
306
|
+
sha256: createHash("sha256")
|
|
307
|
+
.update(readFileSync(join(cwd, file), "utf8"))
|
|
308
|
+
.digest("hex")
|
|
309
|
+
.slice(0, 16),
|
|
310
|
+
}));
|
|
311
|
+
expect(skillDocs).toMatchSnapshot();
|
|
312
|
+
} finally {
|
|
313
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// ---------------------------------------------------------------------------
|
|
319
|
+
// prepare → findings → finalize (end-to-end em repo git temporário)
|
|
320
|
+
// ---------------------------------------------------------------------------
|
|
321
|
+
|
|
322
|
+
describe("baseline — artefatos de prepare/finalize", () => {
|
|
323
|
+
test("gera classification, brief, manifest, review e state", async () => {
|
|
324
|
+
const cwd = mkdtempSync(join(tmpdir(), "houndsman-baseline-run-"));
|
|
325
|
+
const originalCwd = process.cwd();
|
|
326
|
+
const originalHome = process.env.HOUNDSMAN_HOME;
|
|
327
|
+
let storage: SQLiteStorageProvider | null = null;
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
git(cwd, ["init", "-b", "main"]);
|
|
331
|
+
git(cwd, ["config", "user.email", "baseline@example.test"]);
|
|
332
|
+
git(cwd, ["config", "user.name", "Baseline"]);
|
|
333
|
+
// Evita assinatura de commit (ex.: 1Password) no repo temporário.
|
|
334
|
+
git(cwd, ["config", "commit.gpgsign", "false"]);
|
|
335
|
+
git(cwd, ["config", "tag.gpgsign", "false"]);
|
|
336
|
+
mkdirSync(join(cwd, "src", "alpha"), { recursive: true });
|
|
337
|
+
writeFileSync(join(cwd, "src", "alpha", "a.ts"), "export const a = 1;\n");
|
|
338
|
+
writeFileSync(join(cwd, "src", "alpha", "old.ts"), "export const old = 1;\n");
|
|
339
|
+
writeFileSync(join(cwd, "README.md"), "# Baseline\n");
|
|
340
|
+
git(cwd, ["add", "."]);
|
|
341
|
+
git(cwd, ["commit", "-m", "initial"]);
|
|
342
|
+
const base = git(cwd, ["rev-parse", "HEAD"]).trim();
|
|
343
|
+
|
|
344
|
+
writeFileSync(
|
|
345
|
+
join(cwd, "src", "alpha", "a.ts"),
|
|
346
|
+
"export const a: any = 1;\nexport const b = 2;\n",
|
|
347
|
+
);
|
|
348
|
+
writeFileSync(join(cwd, "src", "alpha", "b.ts"), "export const b = 3;\n");
|
|
349
|
+
rmSync(join(cwd, "src", "alpha", "old.ts"));
|
|
350
|
+
git(cwd, ["add", "-A"]);
|
|
351
|
+
git(cwd, ["commit", "-m", "change"]);
|
|
352
|
+
|
|
353
|
+
const opts = {
|
|
354
|
+
...defaultOptions(),
|
|
355
|
+
base,
|
|
356
|
+
head: "HEAD",
|
|
357
|
+
noJev: true,
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
process.env.HOUNDSMAN_HOME = join(cwd, ".home");
|
|
361
|
+
process.chdir(cwd);
|
|
362
|
+
|
|
363
|
+
const config = {
|
|
364
|
+
...baselineConfig,
|
|
365
|
+
storage: {
|
|
366
|
+
provider: "sqlite" as const,
|
|
367
|
+
path: join(cwd, "houndsman.db"),
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
storage = new SQLiteStorageProvider(join(cwd, "houndsman.db"));
|
|
371
|
+
const repo = resolveRepoIdentity();
|
|
372
|
+
const review = storage.getOrCreateReview({
|
|
373
|
+
repo,
|
|
374
|
+
branch: "main",
|
|
375
|
+
slug: "main",
|
|
376
|
+
});
|
|
377
|
+
const ctx = reviewContext(storage, review);
|
|
378
|
+
const homeDisplay = displayPath(cwd);
|
|
379
|
+
const escapedCwd = cwd.replace(/\\/g, "\\\\");
|
|
380
|
+
const normalize = (text: string): string =>
|
|
381
|
+
normalizeArtifacts(
|
|
382
|
+
text
|
|
383
|
+
.replaceAll(escapedCwd, "<cwd>")
|
|
384
|
+
.replaceAll(cwd, "<cwd>")
|
|
385
|
+
.replaceAll(cwd.replace(/\\/g, "/"), "<cwd>")
|
|
386
|
+
.replaceAll(cwd.replace(/\\/g, "/").toLowerCase(), "<cwd>")
|
|
387
|
+
.replaceAll(homeDisplay, "<cwd>"),
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
const prepared = await prepare(opts, "main", config, ctx);
|
|
391
|
+
expect(normalize(prepared.messages.join("\n"))).toMatchSnapshot();
|
|
392
|
+
|
|
393
|
+
for (const name of ["classification.json", "manifest.json"]) {
|
|
394
|
+
const artifact = storage.readArtifact(review.id, name);
|
|
395
|
+
expect(normalize(artifact?.content ?? "")).toMatchSnapshot(name);
|
|
396
|
+
}
|
|
397
|
+
const workBrief = readFileSync(ctx.work.briefFile("alpha"), "utf8");
|
|
398
|
+
const briefArtifact = storage.readArtifact(review.id, "briefs/alpha.md");
|
|
399
|
+
expect(briefArtifact?.content).toBe(workBrief);
|
|
400
|
+
expect(normalize(briefArtifact?.content ?? "")).toMatchSnapshot(
|
|
401
|
+
"briefs/alpha.md",
|
|
402
|
+
);
|
|
403
|
+
|
|
404
|
+
writeFileSync(
|
|
405
|
+
ctx.work.findingFile("alpha"),
|
|
406
|
+
`${JSON.stringify(
|
|
407
|
+
{
|
|
408
|
+
watchdogId: "alpha",
|
|
409
|
+
reviewedFiles: ["src/alpha/a.ts", "src/alpha/b.ts"],
|
|
410
|
+
skipped: [],
|
|
411
|
+
findings: [
|
|
412
|
+
{
|
|
413
|
+
rule: "Nunca usar `any`.",
|
|
414
|
+
severity: "blocking",
|
|
415
|
+
file: "src/alpha/a.ts",
|
|
416
|
+
line: 1,
|
|
417
|
+
message: "any detectado",
|
|
418
|
+
action: "tipar",
|
|
419
|
+
evidence: "export const a: any = 1;",
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
},
|
|
423
|
+
null,
|
|
424
|
+
2,
|
|
425
|
+
)}\n`,
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
const finalized = finalize(opts, "main", config, ctx);
|
|
429
|
+
expect(normalize(finalized.messages.join("\n"))).toMatchSnapshot();
|
|
430
|
+
|
|
431
|
+
for (const name of ["review.md", "review.alpha.md"]) {
|
|
432
|
+
const artifact = storage.readArtifact(review.id, name);
|
|
433
|
+
expect(normalize(artifact?.content ?? "")).toMatchSnapshot(name);
|
|
434
|
+
}
|
|
435
|
+
expect(
|
|
436
|
+
normalize(JSON.stringify(storage.readFindings(review.id), null, 2)),
|
|
437
|
+
).toMatchSnapshot("state.json");
|
|
438
|
+
expect(
|
|
439
|
+
normalize(JSON.stringify(storage.getReview(review.id), null, 2)),
|
|
440
|
+
).toMatchSnapshot("run.json");
|
|
441
|
+
} finally {
|
|
442
|
+
storage?.close();
|
|
443
|
+
process.chdir(originalCwd);
|
|
444
|
+
if (originalHome === undefined) delete process.env.HOUNDSMAN_HOME;
|
|
445
|
+
else process.env.HOUNDSMAN_HOME = originalHome;
|
|
446
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
447
|
+
}
|
|
448
|
+
}, 30_000);
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// ---------------------------------------------------------------------------
|
|
452
|
+
// Contrato da API pública (facade src/index.ts)
|
|
453
|
+
// ---------------------------------------------------------------------------
|
|
454
|
+
|
|
455
|
+
/** Símbolos que consumidores importam de `@payconductor/houndsman`. */
|
|
456
|
+
const REQUIRED_EXPORTS = [
|
|
457
|
+
"PROCEDURE",
|
|
458
|
+
"SEVERITY_EMOJI",
|
|
459
|
+
"SEVERITY_ORDER",
|
|
460
|
+
"FINDING_DECISIONS",
|
|
461
|
+
"FINDING_EXEC_STATES",
|
|
462
|
+
"FINDINGS_STATE_VERSION",
|
|
463
|
+
"FindingsStateStore",
|
|
464
|
+
"FindingsRepository",
|
|
465
|
+
"FindingsState",
|
|
466
|
+
"Finding",
|
|
467
|
+
"Classification",
|
|
468
|
+
"Diff",
|
|
469
|
+
"DocDiscoverer",
|
|
470
|
+
"FileClassifier",
|
|
471
|
+
"GhClient",
|
|
472
|
+
"GitRepository",
|
|
473
|
+
"ProjectConfig",
|
|
474
|
+
"ProjectFiles",
|
|
475
|
+
"Watchdog",
|
|
476
|
+
"WatchdogRegistry",
|
|
477
|
+
"systemClock",
|
|
478
|
+
"HoundsmanServer",
|
|
479
|
+
"HoundsmanEngine",
|
|
480
|
+
"ReviewWorkArea",
|
|
481
|
+
"SQLiteStorageProvider",
|
|
482
|
+
"FileStorageProvider",
|
|
483
|
+
"createStorage",
|
|
484
|
+
"createMemoryStorage",
|
|
485
|
+
"resolveRepoIdentity",
|
|
486
|
+
"buildRepoIdentity",
|
|
487
|
+
"normalizeRemote",
|
|
488
|
+
"ReviewSession",
|
|
489
|
+
"ReviewScopeResolver",
|
|
490
|
+
"buildCarryover",
|
|
491
|
+
"mergeCarryover",
|
|
492
|
+
"RunRepository",
|
|
493
|
+
"ArgParser",
|
|
494
|
+
"ProjectScaffolder",
|
|
495
|
+
"FixBatchBuilder",
|
|
496
|
+
"BriefRenderer",
|
|
497
|
+
"ReportRenderer",
|
|
498
|
+
"ManifestWriter",
|
|
499
|
+
"applyFindingUpdate",
|
|
500
|
+
"assetPath",
|
|
501
|
+
"buildAnchor",
|
|
502
|
+
"buildStateFromFindings",
|
|
503
|
+
"checkRegistry",
|
|
504
|
+
"churnOf",
|
|
505
|
+
"classifyEntries",
|
|
506
|
+
"classifyRange",
|
|
507
|
+
"collectChurn",
|
|
508
|
+
"collectDiff",
|
|
509
|
+
"compareFindings",
|
|
510
|
+
"createRequestHandler",
|
|
511
|
+
"defaultRenderBrief",
|
|
512
|
+
"defineHoundsmanConfig",
|
|
513
|
+
"defineWatchdog",
|
|
514
|
+
"emptyState",
|
|
515
|
+
"fileReader",
|
|
516
|
+
"filterFindings",
|
|
517
|
+
"findWatchdog",
|
|
518
|
+
"fingerprintOf",
|
|
519
|
+
"getWatchdog",
|
|
520
|
+
"getWatchdogContext",
|
|
521
|
+
"hashKey",
|
|
522
|
+
"isExcludedPath",
|
|
523
|
+
"loadConfig",
|
|
524
|
+
"locateAnchor",
|
|
525
|
+
"matchWatchdogs",
|
|
526
|
+
"newFindingId",
|
|
527
|
+
"normalizeLine",
|
|
528
|
+
"parseDiffIndex",
|
|
529
|
+
"parseEntries",
|
|
530
|
+
"parseNumstat",
|
|
531
|
+
"reanchor",
|
|
532
|
+
"relFromRoot",
|
|
533
|
+
"renderBrief",
|
|
534
|
+
"renderDomainReport",
|
|
535
|
+
"reorder",
|
|
536
|
+
"resolveConfigPath",
|
|
537
|
+
"resolveJevConcurrency",
|
|
538
|
+
"resolveMaxFilesPerBrief",
|
|
539
|
+
"runFindingsCommand",
|
|
540
|
+
"runVerifyCommand",
|
|
541
|
+
"selectByBudget",
|
|
542
|
+
"severityRank",
|
|
543
|
+
"sortByRisk",
|
|
544
|
+
"startServer",
|
|
545
|
+
"summarize",
|
|
546
|
+
"syncState",
|
|
547
|
+
] as const;
|
|
548
|
+
|
|
549
|
+
describe("baseline — API pública", () => {
|
|
550
|
+
test("a facade mantém todos os símbolos exportados", () => {
|
|
551
|
+
for (const name of REQUIRED_EXPORTS) {
|
|
552
|
+
expect(facade).toHaveProperty(name);
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
});
|