@payconductor/houndsman 0.5.0 → 0.6.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 +24 -4
- package/assets/grammars/tree-sitter-javascript.wasm +0 -0
- package/assets/grammars/tree-sitter-tsx.wasm +0 -0
- package/assets/grammars/tree-sitter-typescript.wasm +0 -0
- package/assets/grammars/web-tree-sitter.wasm +0 -0
- package/package.json +11 -3
- package/src/cli/commands/command.ts +5 -0
- package/src/cli/commands/doctor-command.ts +116 -24
- package/src/cli/commands/hunt-command.ts +25 -0
- package/src/cli/help.ts +17 -1
- package/src/cli/index.ts +10 -6
- package/src/core/ai/ai-client.ts +221 -0
- package/src/core/ai/ai-sdk-model-provider.ts +101 -0
- package/src/core/ai/errors.ts +36 -0
- package/src/core/ai/features/brief-enricher.ts +62 -0
- package/src/core/ai/features/classifier.ts +50 -0
- package/src/core/ai/features/context-summarizer.ts +31 -0
- package/src/core/ai/features/pre-analyzer.ts +51 -0
- package/src/core/ai/features/verifier.ts +45 -0
- package/src/core/ai/index.ts +56 -0
- package/src/core/ai/model-factory.ts +137 -0
- package/src/core/ai/prompts/base.ts +36 -0
- package/src/core/ai/prompts/brief.ts +87 -0
- package/src/core/ai/prompts/classification.ts +36 -0
- package/src/core/ai/prompts/context.ts +29 -0
- package/src/core/ai/prompts/pre-analysis.ts +49 -0
- package/src/core/ai/prompts/verify.ts +40 -0
- package/src/core/ai/schemas.ts +110 -0
- package/src/core/ai/types.ts +76 -0
- package/src/core/ai/usage-budget.ts +75 -0
- package/src/core/ai/usage-recorder.ts +79 -0
- package/src/core/assets.ts +16 -0
- package/src/core/ast/diff.ts +220 -0
- package/src/core/ast/impact.ts +127 -0
- package/src/core/ast/parser.ts +167 -0
- package/src/core/ast/service.ts +233 -0
- package/src/core/ast/symbols.ts +294 -0
- package/src/core/ast/types.ts +125 -0
- package/src/core/brief.ts +138 -0
- package/src/core/commands/findings.ts +59 -1
- package/src/core/commands/review.ts +2 -0
- package/src/core/commands/scaffold.ts +159 -10
- package/src/core/commands/update.ts +5 -3
- package/src/core/config.ts +85 -0
- package/src/core/defaults.ts +27 -0
- package/src/core/domain/watchdog.ts +43 -5
- package/src/core/engine/houndsman-engine.ts +16 -1
- package/src/core/engine/review-scope.ts +52 -6
- package/src/core/engine/review-session.ts +27 -2
- package/src/core/env.ts +101 -0
- package/src/core/file-classifier.ts +25 -4
- package/src/core/jev/jev-client.ts +8 -7
- package/src/core/jev/jev-verify.ts +2 -1
- package/src/core/logging/index.ts +17 -0
- package/src/core/logging/logger.ts +187 -0
- package/src/core/orchestrator.ts +357 -9
- package/src/core/project-config.ts +123 -1
- package/src/core/registry-check.ts +148 -6
- package/src/core/renderers/manifest-writer.ts +33 -0
- package/src/core/rule-text.ts +97 -0
- package/src/core/services/file-classifier.ts +10 -3
- package/src/core/services/verifier.ts +14 -3
- package/src/core/storage/paths.ts +6 -5
- package/src/core/storage/types.ts +6 -0
- package/src/core/storage/work-area.ts +12 -0
- package/src/core/types.ts +37 -1
- package/src/core/verify.ts +17 -5
- package/src/harness/README.md +15 -0
- package/src/harness/agent/agent-context.ts +33 -0
- package/src/harness/agent/agent-errors.ts +30 -0
- package/src/harness/agent/agent-factory.ts +45 -0
- package/src/harness/agent/agent-reporter.ts +34 -0
- package/src/harness/agent/agent-result.ts +16 -0
- package/src/harness/agent/agent-runner.ts +32 -0
- package/src/harness/agent/agent-scheduler.ts +37 -0
- package/src/harness/agent/review-agent.ts +391 -0
- package/src/harness/config/harness-config.ts +84 -0
- package/src/harness/hunt/hunt-harness.ts +83 -0
- package/src/harness/hunt/hunt-options.ts +75 -0
- package/src/harness/hunt/hunt-result.ts +17 -0
- package/src/harness/hunt/hunt-session.ts +372 -0
- package/src/harness/hunt/review-planner.ts +98 -0
- package/src/harness/index.ts +36 -0
- package/src/harness/investigation/agent-state.ts +134 -0
- package/src/harness/investigation/evidence-verifier.ts +129 -0
- package/src/harness/investigation/evidence.ts +110 -0
- package/src/harness/investigation/finding-critic.ts +96 -0
- package/src/harness/investigation/investigation-planner.ts +118 -0
- package/src/harness/investigation/investigation-task.ts +10 -0
- package/src/harness/investigation/review-journal.ts +87 -0
- package/src/harness/investigation/rule-analyzer.ts +178 -0
- package/src/harness/investigation/rule-signals.ts +110 -0
- package/src/harness/prompts/agent-schemas.ts +57 -0
- package/src/harness/prompts/reviewer-prompt-builder.ts +101 -0
- package/src/harness/prompts/states/conclude-prompt.ts +16 -0
- package/src/harness/prompts/states/investigate-prompt.ts +37 -0
- package/src/harness/prompts/states/orient-prompt.ts +15 -0
- package/src/harness/prompts/states/verify-prompt.ts +22 -0
- package/src/harness/tools/agent-tool.ts +102 -0
- package/src/harness/tools/builtin/changed-symbols-tool.ts +48 -0
- package/src/harness/tools/builtin/doc-context-tool.ts +74 -0
- package/src/harness/tools/builtin/file-outline-tool.ts +66 -0
- package/src/harness/tools/builtin/find-references-tool.ts +66 -0
- package/src/harness/tools/builtin/find-symbol-tool.ts +91 -0
- package/src/harness/tools/builtin/helpers.ts +115 -0
- package/src/harness/tools/builtin/impact-tool.ts +48 -0
- package/src/harness/tools/builtin/imports-exports-tool.ts +53 -0
- package/src/harness/tools/builtin/index.ts +59 -0
- package/src/harness/tools/builtin/list-files-tool.ts +85 -0
- package/src/harness/tools/builtin/pr-context-tool.ts +41 -0
- package/src/harness/tools/builtin/read-file-range-tool.ts +73 -0
- package/src/harness/tools/builtin/rule-signals-tool.ts +36 -0
- package/src/harness/tools/builtin/search-code-tool.ts +65 -0
- package/src/harness/tools/builtin/symbol-context-tool.ts +106 -0
- package/src/harness/tools/builtin/tests-for-symbol-tool.ts +61 -0
- package/src/harness/tools/path-guard.ts +90 -0
- package/src/harness/tools/result-limiter.ts +49 -0
- package/src/harness/tools/secret-redactor.ts +54 -0
- package/src/harness/tools/tool-cache.ts +50 -0
- package/src/harness/tools/tool-call-budget.ts +60 -0
- package/src/harness/tools/tool-context.ts +5 -0
- package/src/harness/tools/tool-middleware.ts +105 -0
- package/src/harness/tools/tool-policy.ts +51 -0
- package/src/harness/tools/tool-registry.ts +112 -0
- package/src/harness/tools/tool-result.ts +15 -0
- package/src/harness/tools/toolbox.ts +36 -0
- package/src/harness/validation/finding-validator.ts +119 -0
- package/src/index.ts +46 -0
- package/src/server/client/utils/constants.ts +27 -5
- package/src/server/client/utils/types.ts +6 -0
- package/src/server/index.ts +3 -2
- package/src/skill/OUTPUT-FORMAT.md +12 -0
- package/src/skill/SETUP.md +6 -2
- package/src/skill/hunt.md +14 -2
- package/src/skill/verify.md +1 -1
- package/src/tests/__snapshots__/baseline.test.ts.snap +96 -14
- package/src/tests/ai-core.test.ts +120 -0
- package/src/tests/ai-features.test.ts +183 -0
- package/src/tests/ast.test.ts +335 -0
- package/src/tests/env.test.ts +69 -0
- package/src/tests/fallback.test.ts +172 -0
- package/src/tests/fixtures/fake-agent-tools.ts +69 -0
- package/src/tests/fixtures/fake-investigation.ts +64 -0
- package/src/tests/fixtures/fake-model-provider.ts +48 -0
- package/src/tests/harness-agent.test.ts +122 -0
- package/src/tests/harness-investigation.test.ts +206 -0
- package/src/tests/harness-tools.test.ts +148 -0
- package/src/tests/hunt-command.test.ts +212 -0
- package/src/tests/logger.test.ts +83 -0
- package/src/tests/review-scope.test.ts +11 -11
- package/src/tests/rule-analyzer.test.ts +61 -0
- package/src/tests/tool-contracts.test.ts +82 -0
- package/src/tests/verify.test.ts +1 -1
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `hunt` — parser de flags, dry-run e fluxo completo com provider fake.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { afterAll, describe, expect, test } from "bun:test";
|
|
6
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { tmpdir } from "node:os";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { defineHoundsmanConfig } from "../core/config";
|
|
10
|
+
import { HoundsmanEngine } from "../core/engine/houndsman-engine";
|
|
11
|
+
import { SilentLogger } from "../core/logging";
|
|
12
|
+
import { defineWatchdog } from "../core/types";
|
|
13
|
+
import { HuntHarness } from "../harness/hunt/hunt-harness";
|
|
14
|
+
import { parseHuntArgs } from "../harness/hunt/hunt-options";
|
|
15
|
+
import { FakeModelProvider } from "./fixtures/fake-model-provider";
|
|
16
|
+
|
|
17
|
+
const RULE = "Nunca usar `any`.";
|
|
18
|
+
|
|
19
|
+
const configBase = defineHoundsmanConfig({
|
|
20
|
+
projectName: "Hunt",
|
|
21
|
+
watchdogs: {
|
|
22
|
+
alpha: defineWatchdog({
|
|
23
|
+
id: "alpha",
|
|
24
|
+
name: "Alpha",
|
|
25
|
+
description: "Watchdog do hunt.",
|
|
26
|
+
scope: "src/alpha/**",
|
|
27
|
+
classify: [{ value: "^src/alpha/" }],
|
|
28
|
+
rules: [{ severity: "blocking", text: RULE }],
|
|
29
|
+
contextFiles: [],
|
|
30
|
+
}),
|
|
31
|
+
},
|
|
32
|
+
exclusions: [],
|
|
33
|
+
docMappings: [],
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("parseHuntArgs", () => {
|
|
37
|
+
test("flags e defaults", () => {
|
|
38
|
+
const options = parseHuntArgs([
|
|
39
|
+
"--base",
|
|
40
|
+
"origin/main",
|
|
41
|
+
"--head",
|
|
42
|
+
"abc",
|
|
43
|
+
"--watchdog",
|
|
44
|
+
"alpha",
|
|
45
|
+
"--full",
|
|
46
|
+
"--no-ast",
|
|
47
|
+
"--resume",
|
|
48
|
+
"--allow-partial",
|
|
49
|
+
"--dry-run",
|
|
50
|
+
"--fail-on-blocking",
|
|
51
|
+
"--max-calls",
|
|
52
|
+
"7",
|
|
53
|
+
"--concurrency",
|
|
54
|
+
"3",
|
|
55
|
+
"--model",
|
|
56
|
+
"m",
|
|
57
|
+
]);
|
|
58
|
+
expect(options.base).toBe("origin/main");
|
|
59
|
+
expect(options.head).toBe("abc");
|
|
60
|
+
expect(options.watchdog).toBe("alpha");
|
|
61
|
+
expect(options.full).toBe(true);
|
|
62
|
+
expect(options.noAst).toBe(true);
|
|
63
|
+
expect(options.noJev).toBe(true);
|
|
64
|
+
expect(options.resume).toBe(true);
|
|
65
|
+
expect(options.allowPartial).toBe(true);
|
|
66
|
+
expect(options.dryRun).toBe(true);
|
|
67
|
+
expect(options.failOnBlocking).toBe(true);
|
|
68
|
+
expect(options.maxCalls).toBe(7);
|
|
69
|
+
expect(options.concurrency).toBe(3);
|
|
70
|
+
expect(options.model).toBe("m");
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
// Repo git temporário
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
|
|
78
|
+
const cwd = mkdtempSync(join(tmpdir(), "houndsman-hunt-"));
|
|
79
|
+
const originalCwd = process.cwd();
|
|
80
|
+
const originalHome = process.env.HOUNDSMAN_HOME;
|
|
81
|
+
const originalKey = process.env.HOUNDSMAN_DEEP_SEEK_API_KEY;
|
|
82
|
+
let base = "";
|
|
83
|
+
|
|
84
|
+
function git(args: string[]): string {
|
|
85
|
+
const result = Bun.spawnSync(["git", ...args], {
|
|
86
|
+
cwd,
|
|
87
|
+
stdout: "pipe",
|
|
88
|
+
stderr: "pipe",
|
|
89
|
+
});
|
|
90
|
+
if (result.exitCode !== 0) {
|
|
91
|
+
throw new Error(`git ${args.join(" ")}: ${result.stderr.toString()}`);
|
|
92
|
+
}
|
|
93
|
+
return result.stdout.toString();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function setupRepo(): void {
|
|
97
|
+
git(["init", "-b", "main"]);
|
|
98
|
+
git(["config", "user.email", "hunt@example.test"]);
|
|
99
|
+
git(["config", "user.name", "Hunt"]);
|
|
100
|
+
git(["config", "commit.gpgsign", "false"]);
|
|
101
|
+
mkdirSync(join(cwd, "src", "alpha"), { recursive: true });
|
|
102
|
+
writeFileSync(join(cwd, "src/alpha/a.ts"), "export const a = 1;\n");
|
|
103
|
+
git(["add", "."]);
|
|
104
|
+
git(["commit", "-m", "initial"]);
|
|
105
|
+
base = git(["rev-parse", "HEAD"]).trim();
|
|
106
|
+
writeFileSync(join(cwd, "src/alpha/a.ts"), "export const a: any = 1;\n");
|
|
107
|
+
git(["add", "-A"]);
|
|
108
|
+
git(["commit", "-m", "change"]);
|
|
109
|
+
process.env.HOUNDSMAN_HOME = join(cwd, ".home");
|
|
110
|
+
process.chdir(cwd);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function engine(): HoundsmanEngine {
|
|
114
|
+
return new HoundsmanEngine({
|
|
115
|
+
...configBase,
|
|
116
|
+
storage: { provider: "sqlite", path: join(cwd, "houndsman.db") },
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setupRepo();
|
|
121
|
+
afterAll(() => {
|
|
122
|
+
process.chdir(originalCwd);
|
|
123
|
+
if (originalHome === undefined) delete process.env.HOUNDSMAN_HOME;
|
|
124
|
+
else process.env.HOUNDSMAN_HOME = originalHome;
|
|
125
|
+
if (originalKey === undefined) delete process.env.HOUNDSMAN_DEEP_SEEK_API_KEY;
|
|
126
|
+
else process.env.HOUNDSMAN_DEEP_SEEK_API_KEY = originalKey;
|
|
127
|
+
rmSync(cwd, { recursive: true, force: true });
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe("hunt", () => {
|
|
131
|
+
test("dry-run lista watchdogs sem chamar IA", async () => {
|
|
132
|
+
const instance = engine();
|
|
133
|
+
try {
|
|
134
|
+
const harness = await HuntHarness.from(
|
|
135
|
+
instance,
|
|
136
|
+
parseHuntArgs(["--base", base, "--head", "HEAD", "--dry-run"]),
|
|
137
|
+
new SilentLogger(),
|
|
138
|
+
);
|
|
139
|
+
const result = await harness.run();
|
|
140
|
+
expect(result.status).toBe("dry-run");
|
|
141
|
+
expect(result.messages.join("\n")).toContain("alpha");
|
|
142
|
+
} finally {
|
|
143
|
+
instance.close();
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test("sem chave e sem --dry-run falha com mensagem clara", async () => {
|
|
148
|
+
delete process.env.HOUNDSMAN_DEEP_SEEK_API_KEY;
|
|
149
|
+
const instance = engine();
|
|
150
|
+
try {
|
|
151
|
+
await expect(
|
|
152
|
+
HuntHarness.from(
|
|
153
|
+
instance,
|
|
154
|
+
parseHuntArgs(["--base", base, "--head", "HEAD"]),
|
|
155
|
+
new SilentLogger(),
|
|
156
|
+
),
|
|
157
|
+
).rejects.toThrow(/hunt exige IA configurada/);
|
|
158
|
+
} finally {
|
|
159
|
+
instance.close();
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("provider fake investiga, grava findings e finaliza", async () => {
|
|
164
|
+
const provider = new FakeModelProvider(async (request, index) => {
|
|
165
|
+
if (index === 0) return { hypotheses: ["any"] };
|
|
166
|
+
if (index === 1) return { taskIds: ["rule-0"] };
|
|
167
|
+
const tool = request.tools?.read_file_range;
|
|
168
|
+
if (!tool) throw new Error("read_file_range ausente");
|
|
169
|
+
const parsed = JSON.parse(
|
|
170
|
+
await tool.execute({ path: "src/alpha/a.ts", startLine: 1, endLine: 1 }),
|
|
171
|
+
) as { evidence?: { id: string }[] };
|
|
172
|
+
return {
|
|
173
|
+
findingDrafts: [
|
|
174
|
+
{
|
|
175
|
+
rule: RULE,
|
|
176
|
+
severity: "blocking",
|
|
177
|
+
file: "src/alpha/a.ts",
|
|
178
|
+
line: 1,
|
|
179
|
+
message: "any detectado",
|
|
180
|
+
action: "tipar",
|
|
181
|
+
evidenceIds: [parsed.evidence?.[0]?.id].filter(Boolean),
|
|
182
|
+
confidence: 0.9,
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
coverage: [{ rule: RULE, status: "checked" }],
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
const instance = engine();
|
|
189
|
+
try {
|
|
190
|
+
const harness = await HuntHarness.from(
|
|
191
|
+
instance,
|
|
192
|
+
parseHuntArgs(["--base", base, "--head", "HEAD"]),
|
|
193
|
+
new SilentLogger(),
|
|
194
|
+
provider,
|
|
195
|
+
);
|
|
196
|
+
const result = await harness.run();
|
|
197
|
+
expect(result.status).toBe("completed");
|
|
198
|
+
expect(result.blockers).toBe(1);
|
|
199
|
+
const review = instance.storage.readArtifact(result.reviewId, "review.md");
|
|
200
|
+
expect(review?.content).toContain("any detectado");
|
|
201
|
+
const transcript = instance.storage.readArtifact(
|
|
202
|
+
result.reviewId,
|
|
203
|
+
"harness-transcript.json",
|
|
204
|
+
);
|
|
205
|
+
expect(transcript?.content).toContain("VERIFY");
|
|
206
|
+
const usage = instance.storage.readArtifact(result.reviewId, "ai-usage.json");
|
|
207
|
+
expect(usage?.content).toContain('"calls"');
|
|
208
|
+
} finally {
|
|
209
|
+
instance.close();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logger único: cor opcional, spinner em não-TTY e tabela.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from "bun:test";
|
|
6
|
+
import { Logger, SilentLogger } from "../core/logging";
|
|
7
|
+
|
|
8
|
+
function memoryStream(): { stream: NodeJS.WritableStream; text: () => string } {
|
|
9
|
+
let content = "";
|
|
10
|
+
const stream = {
|
|
11
|
+
write(chunk: string) {
|
|
12
|
+
content += chunk;
|
|
13
|
+
return true;
|
|
14
|
+
},
|
|
15
|
+
isTTY: false,
|
|
16
|
+
} as unknown as NodeJS.WritableStream;
|
|
17
|
+
return { stream, text: () => content };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
describe("Logger", () => {
|
|
21
|
+
test("escreve texto puro quando color=false e sem TTY", () => {
|
|
22
|
+
const out = memoryStream();
|
|
23
|
+
const err = memoryStream();
|
|
24
|
+
const logger = new Logger({
|
|
25
|
+
stdout: out.stream,
|
|
26
|
+
stderr: err.stream,
|
|
27
|
+
color: false,
|
|
28
|
+
isTTY: false,
|
|
29
|
+
});
|
|
30
|
+
logger.info("info");
|
|
31
|
+
logger.success("ok");
|
|
32
|
+
logger.warn("aviso");
|
|
33
|
+
logger.error("falhou");
|
|
34
|
+
logger.step("passo");
|
|
35
|
+
const text = `${out.text()}${err.text()}`;
|
|
36
|
+
expect(text).toContain("info");
|
|
37
|
+
expect(text).toContain("ok");
|
|
38
|
+
expect(text).toContain("aviso");
|
|
39
|
+
expect(text).toContain("falhou");
|
|
40
|
+
expect(text).toContain("passo");
|
|
41
|
+
expect(text).not.toContain("\u001b[");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("spinner é nulo em não-TTY", () => {
|
|
45
|
+
const out = memoryStream();
|
|
46
|
+
const logger = new Logger({ stdout: out.stream, isTTY: false });
|
|
47
|
+
expect(logger.spinner("x")).toBeNull();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("quiet suprime info/sucesso mas não erro", () => {
|
|
51
|
+
const out = memoryStream();
|
|
52
|
+
const err = memoryStream();
|
|
53
|
+
const logger = new Logger({
|
|
54
|
+
stdout: out.stream,
|
|
55
|
+
stderr: err.stream,
|
|
56
|
+
quiet: true,
|
|
57
|
+
color: false,
|
|
58
|
+
});
|
|
59
|
+
logger.info("info");
|
|
60
|
+
logger.success("ok");
|
|
61
|
+
logger.error("erro");
|
|
62
|
+
expect(out.text()).toBe("");
|
|
63
|
+
expect(err.text()).toContain("erro");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("tabela alinha colunas", () => {
|
|
67
|
+
const out = memoryStream();
|
|
68
|
+
const logger = new Logger({ stdout: out.stream, color: false });
|
|
69
|
+
logger.table([
|
|
70
|
+
["id", "findings"],
|
|
71
|
+
["alpha", "2"],
|
|
72
|
+
]);
|
|
73
|
+
expect(out.text()).toContain("id");
|
|
74
|
+
expect(out.text()).toContain("alpha");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("SilentLogger não escreve e executa withSpinner", async () => {
|
|
78
|
+
const logger = new SilentLogger();
|
|
79
|
+
logger.info("x");
|
|
80
|
+
const result = await logger.withSpinner("x", async () => 42);
|
|
81
|
+
expect(result).toBe(42);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -111,12 +111,12 @@ function makeRepo(): Repo {
|
|
|
111
111
|
// ---------------------------------------------------------------------------
|
|
112
112
|
|
|
113
113
|
describe("ReviewScopeResolver", () => {
|
|
114
|
-
test("mesmo commit revisado vira no-op (sem tocar no git)", () => {
|
|
114
|
+
test("mesmo commit revisado vira no-op (sem tocar no git)", async () => {
|
|
115
115
|
const sha = "a".repeat(40);
|
|
116
|
-
const scope = new ReviewScopeResolver(
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
);
|
|
116
|
+
const scope = await new ReviewScopeResolver(
|
|
117
|
+
options(),
|
|
118
|
+
fakeHoundsmanConfig,
|
|
119
|
+
).resolve(stateWith(sha), sha);
|
|
120
120
|
|
|
121
121
|
expect(scope.kind).toBe("noop");
|
|
122
122
|
if (scope.kind !== "noop") throw new Error("esperava noop");
|
|
@@ -124,12 +124,12 @@ describe("ReviewScopeResolver", () => {
|
|
|
124
124
|
expect(scope.headSha).toBe(sha);
|
|
125
125
|
});
|
|
126
126
|
|
|
127
|
-
test("`--full` re-revisa o mesmo commit", () => {
|
|
127
|
+
test("`--full` re-revisa o mesmo commit", async () => {
|
|
128
128
|
const repo = makeRepo();
|
|
129
129
|
const originalCwd = process.cwd();
|
|
130
130
|
try {
|
|
131
131
|
process.chdir(repo.cwd);
|
|
132
|
-
const scope = new ReviewScopeResolver(
|
|
132
|
+
const scope = await new ReviewScopeResolver(
|
|
133
133
|
options({ base: repo.base, full: true }),
|
|
134
134
|
fakeHoundsmanConfig,
|
|
135
135
|
).resolve(stateWith(repo.head), repo.head);
|
|
@@ -144,7 +144,7 @@ describe("ReviewScopeResolver", () => {
|
|
|
144
144
|
}
|
|
145
145
|
});
|
|
146
146
|
|
|
147
|
-
test("delta revisa só os arquivos alterados e carrega o resto", () => {
|
|
147
|
+
test("delta revisa só os arquivos alterados e carrega o resto", async () => {
|
|
148
148
|
const repo = makeRepo();
|
|
149
149
|
const originalCwd = process.cwd();
|
|
150
150
|
try {
|
|
@@ -153,7 +153,7 @@ describe("ReviewScopeResolver", () => {
|
|
|
153
153
|
abcdef1234: findingState({ file: "src/alpha/keep.ts" }),
|
|
154
154
|
fedcba4321: findingState({ file: "src/alpha/a.ts" }),
|
|
155
155
|
});
|
|
156
|
-
const scope = new ReviewScopeResolver(
|
|
156
|
+
const scope = await new ReviewScopeResolver(
|
|
157
157
|
options({ base: repo.base }),
|
|
158
158
|
fakeHoundsmanConfig,
|
|
159
159
|
).resolve(previous, repo.head);
|
|
@@ -172,13 +172,13 @@ describe("ReviewScopeResolver", () => {
|
|
|
172
172
|
}
|
|
173
173
|
});
|
|
174
174
|
|
|
175
|
-
test("histórico reescrito (HEAD sem ancestrais comuns) cai no completo", () => {
|
|
175
|
+
test("histórico reescrito (HEAD sem ancestrais comuns) cai no completo", async () => {
|
|
176
176
|
const repo = makeRepo();
|
|
177
177
|
const originalCwd = process.cwd();
|
|
178
178
|
try {
|
|
179
179
|
process.chdir(repo.cwd);
|
|
180
180
|
// `repo.head` não é ancestral de `repo.base` → revisão completa.
|
|
181
|
-
const scope = new ReviewScopeResolver(
|
|
181
|
+
const scope = await new ReviewScopeResolver(
|
|
182
182
|
options({ base: repo.base }),
|
|
183
183
|
fakeHoundsmanConfig,
|
|
184
184
|
).resolve(stateWith(repo.head), repo.base);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RuleAnalyzer — polaridade, categoria, sinais e hints.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from "bun:test";
|
|
6
|
+
import { RuleAnalyzer } from "../harness/investigation/rule-analyzer";
|
|
7
|
+
|
|
8
|
+
const analyzer = new RuleAnalyzer();
|
|
9
|
+
|
|
10
|
+
describe("RuleAnalyzer", () => {
|
|
11
|
+
test("detecta polaridade explícita", () => {
|
|
12
|
+
const [avoid, promote] = analyzer.analyze([
|
|
13
|
+
{ severity: "blocking", text: "Evitar: chamar banco diretamente em rotas." },
|
|
14
|
+
{ severity: "attention", text: "Promover: usar `logger` estruturado." },
|
|
15
|
+
]);
|
|
16
|
+
expect(avoid?.intent).toBe("avoid");
|
|
17
|
+
expect(promote?.intent).toBe("promote");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("classifica categoria por keywords", () => {
|
|
21
|
+
const [data, tests] = analyzer.analyze([
|
|
22
|
+
{
|
|
23
|
+
severity: "attention",
|
|
24
|
+
text: "Evitar: query direta no banco sem migration.",
|
|
25
|
+
},
|
|
26
|
+
{ severity: "nit", text: "Promover: cobertura de teste no handler." },
|
|
27
|
+
]);
|
|
28
|
+
expect(data?.category).toBe("data");
|
|
29
|
+
expect(tests?.category).toBe("tests");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("extrai sinais de backticks e hints (confiança alta)", () => {
|
|
33
|
+
const [analysis] = analyzer.analyze([
|
|
34
|
+
{
|
|
35
|
+
severity: "blocking",
|
|
36
|
+
text: "Evitar: usar `db.query` fora do service.",
|
|
37
|
+
hints: {
|
|
38
|
+
symbols: ["OrderService"],
|
|
39
|
+
imports: ["db"],
|
|
40
|
+
checks: ["symbol_context"],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
]);
|
|
44
|
+
expect(analysis?.confidence).toBe("high");
|
|
45
|
+
expect(analysis?.signals.some((signal) => signal.value === "OrderService")).toBe(
|
|
46
|
+
true,
|
|
47
|
+
);
|
|
48
|
+
expect(analysis?.signals.some((signal) => signal.value === "db")).toBe(true);
|
|
49
|
+
expect(analysis?.checks.some((check) => check.tool === "symbol_context")).toBe(
|
|
50
|
+
true,
|
|
51
|
+
);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("keywords ignoram stopwords", () => {
|
|
55
|
+
const [analysis] = analyzer.analyze([
|
|
56
|
+
{ severity: "nit", text: "Nunca usar any em produção" },
|
|
57
|
+
]);
|
|
58
|
+
expect(analysis?.keywords).not.toContain("nunca");
|
|
59
|
+
expect(analysis?.keywords).toContain("produção");
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract test das tools built-in: metadata, schema e erros estruturados.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, expect, test } from "bun:test";
|
|
6
|
+
import { AstService } from "../core/ast/service";
|
|
7
|
+
import { Watchdog } from "../core/domain/watchdog";
|
|
8
|
+
import { SilentReporter } from "../harness/agent/agent-reporter";
|
|
9
|
+
import { AgentState } from "../harness/investigation/agent-state";
|
|
10
|
+
import type { ToolContext } from "../harness/tools/agent-tool";
|
|
11
|
+
import { BuiltinToolsModule } from "../harness/tools/builtin";
|
|
12
|
+
import { ToolCache } from "../harness/tools/tool-cache";
|
|
13
|
+
import { ToolCallBudget } from "../harness/tools/tool-call-budget";
|
|
14
|
+
import { ToolMiddleware } from "../harness/tools/tool-middleware";
|
|
15
|
+
import { ToolRegistry } from "../harness/tools/tool-registry";
|
|
16
|
+
import { fakeAgentContext } from "./fixtures/fake-investigation";
|
|
17
|
+
import { fakeHoundsmanConfig } from "./fixtures/fake-project";
|
|
18
|
+
|
|
19
|
+
function registry(): ToolRegistry {
|
|
20
|
+
const value = new ToolRegistry();
|
|
21
|
+
value.registerModule(new BuiltinToolsModule());
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function context(): ToolContext {
|
|
26
|
+
return {
|
|
27
|
+
repoRoot: process.cwd(),
|
|
28
|
+
watchdog: new Watchdog(fakeHoundsmanConfig.watchdogs.alpha),
|
|
29
|
+
diff: { byFile: new Map(), churn: new Map() },
|
|
30
|
+
ast: new AstService(fakeHoundsmanConfig),
|
|
31
|
+
state: new AgentState(),
|
|
32
|
+
budget: new ToolCallBudget(20, 10),
|
|
33
|
+
cache: new ToolCache(),
|
|
34
|
+
logger: new SilentReporter(),
|
|
35
|
+
agent: fakeAgentContext({ repoRoot: process.cwd() }),
|
|
36
|
+
rules: new Map(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
describe("contratos das tools", () => {
|
|
41
|
+
test("todas declaram metadata read-only e capabilities", () => {
|
|
42
|
+
for (const tool of registry().list()) {
|
|
43
|
+
expect(tool.metadata.name.length).toBeGreaterThan(0);
|
|
44
|
+
expect(tool.metadata.description.length).toBeGreaterThan(0);
|
|
45
|
+
expect(tool.metadata.readOnly).toBe(true);
|
|
46
|
+
expect(tool.metadata.capabilities.length).toBeGreaterThan(0);
|
|
47
|
+
expect(tool.metadata.cost).toBeGreaterThanOrEqual(1);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("nenhuma tool devolve arquivo inteiro por padrão", () => {
|
|
52
|
+
// `read_file_range` exige faixa explícita.
|
|
53
|
+
const range = registry().get("read_file_range");
|
|
54
|
+
expect(range?.inputSchema.safeParse({ path: "a.ts" }).success).toBe(false);
|
|
55
|
+
// `file_outline` só devolve metadados (não tem parâmetro de corpo).
|
|
56
|
+
const outline = registry().get("file_outline");
|
|
57
|
+
expect(outline?.inputSchema.safeParse({ path: "a.ts" }).success).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test("tools de arquivo devolvem erro estruturado (não lançam)", async () => {
|
|
61
|
+
const middleware = new ToolMiddleware();
|
|
62
|
+
for (const [name, input] of [
|
|
63
|
+
["read_file_range", { path: "../x", startLine: 1, endLine: 2 }],
|
|
64
|
+
["file_outline", { path: "../x" }],
|
|
65
|
+
["imports_exports", { file: "../x" }],
|
|
66
|
+
] as const) {
|
|
67
|
+
const result = await registry().execute(name, input, context(), middleware);
|
|
68
|
+
expect(result.ok).toBe(false);
|
|
69
|
+
expect(typeof result.error).toBe("string");
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("rule_signals devolve erro quando a regra não existe", async () => {
|
|
74
|
+
const result = await registry().execute(
|
|
75
|
+
"rule_signals",
|
|
76
|
+
{ rule: "regra inexistente" },
|
|
77
|
+
context(),
|
|
78
|
+
new ToolMiddleware(),
|
|
79
|
+
);
|
|
80
|
+
expect(result.ok).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
});
|
package/src/tests/verify.test.ts
CHANGED
|
@@ -158,7 +158,7 @@ describe("JevVerifier", () => {
|
|
|
158
158
|
]);
|
|
159
159
|
expect(outcome.checked).toBe(0);
|
|
160
160
|
expect(outcome.skipped).toBe(1);
|
|
161
|
-
expect(outcome.reason).toContain("
|
|
161
|
+
expect(outcome.reason).toContain("HOUNDSMAN_TYPE_SAFE_API_KEY");
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
test("sem casos ⇒ vazio", async () => {
|