@izkac/forgekit 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/bin/forge.mjs +100 -0
- package/bin/forgekit.mjs +84 -0
- package/bin/review.mjs +82 -0
- package/package.json +46 -0
- package/scripts/prepack.mjs +78 -0
- package/scripts/run-tests.mjs +43 -0
- package/src/adr.mjs +236 -0
- package/src/adr.test.mjs +170 -0
- package/src/change.mjs +234 -0
- package/src/change.test.mjs +83 -0
- package/src/cleanup-sessions.mjs +70 -0
- package/src/config.mjs +103 -0
- package/src/defer.mjs +75 -0
- package/src/doctor.mjs +341 -0
- package/src/doctor.test.mjs +114 -0
- package/src/init.mjs +575 -0
- package/src/install.mjs +777 -0
- package/src/install.test.mjs +104 -0
- package/src/integrity-check.mjs +58 -0
- package/src/integrity.mjs +317 -0
- package/src/integrity.test.mjs +296 -0
- package/src/lib/workspaces.mjs +55 -0
- package/src/lib.mjs +138 -0
- package/src/models.defaults.json +41 -0
- package/src/new-session.mjs +82 -0
- package/src/openspec-overlays/README.md +19 -0
- package/src/openspec-overlays/openspec-apply-change-footer.md +14 -0
- package/src/openspec-overlays/opsx-apply-completion-step.md +1 -0
- package/src/openspec-overlays/opsx-apply-implement-step.md +11 -0
- package/src/paths.mjs +92 -0
- package/src/plan-engine.mjs +260 -0
- package/src/plan-engine.test.mjs +245 -0
- package/src/preferences.defaults.json +78 -0
- package/src/preferences.mjs +438 -0
- package/src/preferences.test.mjs +174 -0
- package/src/record-evidence.mjs +204 -0
- package/src/record-evidence.test.mjs +260 -0
- package/src/resolve-model.mjs +312 -0
- package/src/resolve-model.test.mjs +194 -0
- package/src/review/carryforward.mjs +413 -0
- package/src/review/carryforward.test.mjs +587 -0
- package/src/review/cli.test.mjs +117 -0
- package/src/review/export.mjs +172 -0
- package/src/review/export.test.mjs +197 -0
- package/src/review/fixtures/valid-review.json +42 -0
- package/src/review/lib.mjs +894 -0
- package/src/review/lib.test.mjs +266 -0
- package/src/review/merge-tentative.mjs +292 -0
- package/src/review/merge-tentative.test.mjs +363 -0
- package/src/review/new-review.mjs +200 -0
- package/src/review/render.mjs +108 -0
- package/src/review/schema-consistency.test.mjs +83 -0
- package/src/review/schema.json +196 -0
- package/src/review/signals.mjs +144 -0
- package/src/review/signals.test.mjs +62 -0
- package/src/score-cli.mjs +68 -0
- package/src/score.mjs +489 -0
- package/src/score.test.mjs +253 -0
- package/src/session-reminder.mjs +168 -0
- package/src/session-status.mjs +70 -0
- package/src/set-models.mjs +186 -0
- package/src/set-phase.mjs +177 -0
- package/src/set-phase.test.mjs +317 -0
- package/src/set-prefs.mjs +294 -0
- package/src/spine.mjs +91 -0
- package/src/triage-prompt.mjs +175 -0
- package/src/triage-prompt.test.mjs +50 -0
- package/src/vendor-openspec-overlays.mjs +176 -0
- package/src/vendor-openspec-overlays.test.mjs +62 -0
- package/vendor/skills/archive-to-adr/SKILL.md +149 -0
- package/vendor/skills/forge/SKILL.md +136 -0
- package/vendor/skills/forge/phases/brainstorm.md +23 -0
- package/vendor/skills/forge/phases/finish.md +87 -0
- package/vendor/skills/forge/phases/implement.md +76 -0
- package/vendor/skills/forge/phases/plan-openspec.md +40 -0
- package/vendor/skills/forge/phases/plan-specs.md +97 -0
- package/vendor/skills/forge/phases/review.md +25 -0
- package/vendor/skills/forge/phases/verify.md +120 -0
- package/vendor/skills/forge/references/forge-layout.md +85 -0
- package/vendor/skills/forge/references/pace.md +115 -0
- package/vendor/skills/forge/references/plan-routing.md +51 -0
- package/vendor/skills/forge/references/runtime-integrity.md +157 -0
- package/vendor/skills/forge/references/substantial-work.md +37 -0
- package/vendor/skills/forge/references/tdd-core.md +29 -0
- package/vendor/skills/forge/references/test-evidence.md +30 -0
- package/vendor/skills/forge/references/test-strategy.md +68 -0
- package/vendor/skills/forge/skills/NOTICE.md +17 -0
- package/vendor/skills/forge/skills/brainstorming/SKILL.md +120 -0
- package/vendor/skills/forge/skills/requesting-code-review/SKILL.md +67 -0
- package/vendor/skills/forge/skills/requesting-code-review/code-reviewer.md +146 -0
- package/vendor/skills/forge/skills/subagent-driven-development/SKILL.md +87 -0
- package/vendor/skills/forge/skills/systematic-debugging/SKILL.md +234 -0
- package/vendor/skills/forge/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/vendor/skills/forge/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/vendor/skills/forge/skills/systematic-debugging/find-polluter.sh +63 -0
- package/vendor/skills/forge/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/vendor/skills/forge/skills/test-driven-development/SKILL.md +290 -0
- package/vendor/skills/forge/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/vendor/skills/forge/skills/verification-before-completion/SKILL.md +59 -0
- package/vendor/skills/forge/subagents/final-reviewer-prompt.md +53 -0
- package/vendor/skills/forge/subagents/implementer-prompt.md +38 -0
- package/vendor/skills/forge/subagents/task-reviewer-prompt.md +61 -0
- package/vendor/skills/git-resolve-adr-conflict/SKILL.md +132 -0
- package/vendor/skills/thorough-code-review/SKILL.md +290 -0
- package/vendor/skills/thorough-code-review/examples/accepted-risks-janus.md +32 -0
- package/vendor/skills/thorough-code-review/examples.md +133 -0
- package/vendor/skills/thorough-code-review/reference/accepted-risks.md +26 -0
- package/vendor/skills/thorough-code-review/reference/lenses.md +96 -0
- package/vendor/skills/thorough-code-review/reference/phase1-scout.md +62 -0
- package/vendor/skills/thorough-code-review/reference/phase1c-coverage.md +44 -0
- package/vendor/skills/thorough-code-review/reference/phase2-skeptic.md +105 -0
- package/vendor/skills/thorough-code-review/reference/report-schema.json +222 -0
- package/vendor/skills/thorough-code-review/reference/report-template.md +115 -0
- package/vendor/skills/thorough-code-review/reference/severity-rubric.md +49 -0
- package/vendor/skills/thorough-code-review/reference/signals-preflight.md +55 -0
- package/vendor/templates/adr/README.md +7 -0
- package/vendor/templates/adr/decisions.md +141 -0
- package/vendor/templates/adr/hooks/check-pending-adrs.mjs +74 -0
- package/vendor/templates/adr/hooks/check-pending-adrs.sh +3 -0
- package/vendor/templates/adr/hooks/openspec-archive-agent-message.mjs +52 -0
- package/vendor/templates/adr/hooks/openspec-archive-agent-message.sh +3 -0
- package/vendor/templates/project/claude/commands/forge-apply.md +75 -0
- package/vendor/templates/project/claude/commands/forge-brainstorm.md +7 -0
- package/vendor/templates/project/claude/commands/forge-build.md +17 -0
- package/vendor/templates/project/claude/commands/forge-plan.md +12 -0
- package/vendor/templates/project/claude/commands/forge-skip.md +14 -0
- package/vendor/templates/project/claude/commands/forge-status.md +16 -0
- package/vendor/templates/project/claude/commands/forge.md +16 -0
- package/vendor/templates/project/claude/hooks/forge-prompt-hook.mjs +73 -0
- package/vendor/templates/project/claude/hooks/forge-session-start.mjs +19 -0
- package/vendor/templates/project/claude/hooks/forge-triage-hook.mjs +77 -0
- package/vendor/templates/project/claude/rules/forge.md +16 -0
- package/vendor/templates/project/codex/rules/forge.md +10 -0
- package/vendor/templates/project/cursor/commands/forge-apply.md +75 -0
- package/vendor/templates/project/cursor/commands/forge-brainstorm.md +10 -0
- package/vendor/templates/project/cursor/commands/forge-build.md +17 -0
- package/vendor/templates/project/cursor/commands/forge-plan.md +15 -0
- package/vendor/templates/project/cursor/commands/forge-skip.md +14 -0
- package/vendor/templates/project/cursor/commands/forge-status.md +16 -0
- package/vendor/templates/project/cursor/commands/forge.md +16 -0
- package/vendor/templates/project/cursor/hooks/forge-session-start.mjs +30 -0
- package/vendor/templates/project/cursor/hooks/forge-session-start.sh +3 -0
- package/vendor/templates/project/cursor/rules/forge.mdc +21 -0
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Export and validate thorough code review JSON sidecars for CI.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* review export [--file <json>] [--out <dir>] [--fail-on critical]
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import { pathToFileURL } from 'node:url';
|
|
12
|
+
import {
|
|
13
|
+
REVIEWS_DIR,
|
|
14
|
+
findLatestReviewJson,
|
|
15
|
+
formatSummary,
|
|
16
|
+
countOpenAtOrAbove,
|
|
17
|
+
renderMarkdown,
|
|
18
|
+
validateReport,
|
|
19
|
+
} from './lib.mjs';
|
|
20
|
+
|
|
21
|
+
const FAIL_ON_LEVELS = new Set(['critical', 'important', 'minor']);
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param {string[]} argv
|
|
25
|
+
*/
|
|
26
|
+
export function parseArgs(argv) {
|
|
27
|
+
const opts = {
|
|
28
|
+
file: null,
|
|
29
|
+
out: null,
|
|
30
|
+
failOn: null,
|
|
31
|
+
failOnCritical: false,
|
|
32
|
+
renderMd: false,
|
|
33
|
+
reviewsDir: REVIEWS_DIR,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
37
|
+
const arg = argv[i];
|
|
38
|
+
if (arg === '--file') {
|
|
39
|
+
opts.file = argv[++i];
|
|
40
|
+
} else if (arg === '--out') {
|
|
41
|
+
opts.out = argv[++i];
|
|
42
|
+
} else if (arg === '--render-md') {
|
|
43
|
+
opts.renderMd = true;
|
|
44
|
+
} else if (arg === '--fail-on') {
|
|
45
|
+
const level = argv[++i];
|
|
46
|
+
if (!FAIL_ON_LEVELS.has(level)) {
|
|
47
|
+
throw new Error(`unsupported --fail-on value: ${level} (expected critical|important|minor)`);
|
|
48
|
+
}
|
|
49
|
+
opts.failOn = level;
|
|
50
|
+
opts.failOnCritical = level === 'critical';
|
|
51
|
+
} else if (arg === '--reviews-dir') {
|
|
52
|
+
opts.reviewsDir = argv[++i];
|
|
53
|
+
} else if (arg === '--help' || arg === '-h') {
|
|
54
|
+
opts.help = true;
|
|
55
|
+
} else {
|
|
56
|
+
throw new Error(`unknown argument: ${arg}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return opts;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {ReturnType<typeof parseArgs>} opts
|
|
65
|
+
* @param {string} [cwd]
|
|
66
|
+
* @returns {{ exitCode: number; message: string }}
|
|
67
|
+
*/
|
|
68
|
+
export function runExport(opts, cwd = process.cwd()) {
|
|
69
|
+
const reviewsDir = path.resolve(cwd, opts.reviewsDir ?? REVIEWS_DIR);
|
|
70
|
+
const jsonPath = opts.file
|
|
71
|
+
? path.isAbsolute(opts.file)
|
|
72
|
+
? opts.file
|
|
73
|
+
: path.resolve(cwd, opts.file)
|
|
74
|
+
: findLatestReviewJson(reviewsDir);
|
|
75
|
+
|
|
76
|
+
if (!jsonPath) {
|
|
77
|
+
return { exitCode: 1, message: `no review JSON found in ${reviewsDir}` };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!fs.existsSync(jsonPath)) {
|
|
81
|
+
return { exitCode: 1, message: `file not found: ${jsonPath}` };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
let parsed;
|
|
85
|
+
try {
|
|
86
|
+
parsed = JSON.parse(fs.readFileSync(jsonPath, 'utf8'));
|
|
87
|
+
} catch (err) {
|
|
88
|
+
return { exitCode: 1, message: `invalid JSON: ${/** @type {Error} */ (err).message}` };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const validation = validateReport(parsed);
|
|
92
|
+
if (!validation.ok) {
|
|
93
|
+
return {
|
|
94
|
+
exitCode: 1,
|
|
95
|
+
message: `validation failed for ${jsonPath}:\n${validation.errors.map((e) => ` - ${e}`).join('\n')}`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const report = validation.report;
|
|
100
|
+
const lines = [`OK ${jsonPath}`, formatSummary(report)];
|
|
101
|
+
|
|
102
|
+
if (opts.renderMd) {
|
|
103
|
+
const mdPath = jsonPath.replace(/\.json$/, '.md');
|
|
104
|
+
fs.writeFileSync(mdPath, `${renderMarkdown(report)}\n`, 'utf8');
|
|
105
|
+
lines.push(`rendered: ${mdPath}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (opts.out) {
|
|
109
|
+
const outDir = path.resolve(cwd, opts.out);
|
|
110
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
111
|
+
const base = path.basename(jsonPath);
|
|
112
|
+
const mdBase = base.replace(/\.json$/, '.md');
|
|
113
|
+
const jsonDest = path.join(outDir, base);
|
|
114
|
+
const mdSrc = path.join(path.dirname(jsonPath), mdBase);
|
|
115
|
+
fs.copyFileSync(jsonPath, jsonDest);
|
|
116
|
+
if (fs.existsSync(mdSrc)) {
|
|
117
|
+
fs.copyFileSync(mdSrc, path.join(outDir, mdBase));
|
|
118
|
+
lines.push(`copied: ${jsonDest}, ${path.join(outDir, mdBase)}`);
|
|
119
|
+
} else {
|
|
120
|
+
lines.push(`copied: ${jsonDest} (no paired .md at ${mdSrc})`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const failLevel = opts.failOn ?? (opts.failOnCritical ? 'critical' : null);
|
|
125
|
+
if (failLevel) {
|
|
126
|
+
const openCount = countOpenAtOrAbove(report, failLevel);
|
|
127
|
+
if (openCount > 0) {
|
|
128
|
+
lines.push(`FAIL: ${openCount} open ${failLevel}+ finding(s)`);
|
|
129
|
+
return { exitCode: 1, message: lines.join('\n') };
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return { exitCode: 0, message: lines.join('\n') };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function printHelp() {
|
|
137
|
+
console.log(`Usage: review export [options]
|
|
138
|
+
|
|
139
|
+
Options:
|
|
140
|
+
--file <path> Review JSON (default: latest *-review.json in .reviews/)
|
|
141
|
+
--out <dir> Copy JSON (+ paired .md if present) to directory
|
|
142
|
+
--render-md (Re)generate the paired Markdown from the JSON first
|
|
143
|
+
--fail-on <level> Exit 1 if any open finding at/above level remains
|
|
144
|
+
(critical | important | minor)
|
|
145
|
+
--reviews-dir <dir> Reviews directory (default: .reviews)
|
|
146
|
+
-h, --help Show this help
|
|
147
|
+
`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function main() {
|
|
151
|
+
try {
|
|
152
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
153
|
+
if (opts.help) {
|
|
154
|
+
printHelp();
|
|
155
|
+
process.exit(0);
|
|
156
|
+
}
|
|
157
|
+
const result = runExport(opts);
|
|
158
|
+
console.log(result.message);
|
|
159
|
+
process.exit(result.exitCode);
|
|
160
|
+
} catch (err) {
|
|
161
|
+
console.error(/** @type {Error} */ (err).message);
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const isMain =
|
|
167
|
+
process.argv[1] &&
|
|
168
|
+
import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href;
|
|
169
|
+
|
|
170
|
+
if (isMain) {
|
|
171
|
+
main();
|
|
172
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { tmpdir } from 'node:os';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
import {
|
|
8
|
+
validateReport,
|
|
9
|
+
findLatestReviewJson,
|
|
10
|
+
countOpenCritical,
|
|
11
|
+
formatSummary,
|
|
12
|
+
} from './lib.mjs';
|
|
13
|
+
import { parseArgs, runExport } from './export.mjs';
|
|
14
|
+
|
|
15
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const fixturePath = path.join(__dirname, 'fixtures', 'valid-review.json');
|
|
17
|
+
|
|
18
|
+
function tmp(prefix) {
|
|
19
|
+
return fs.mkdtempSync(path.join(tmpdir(), prefix));
|
|
20
|
+
}
|
|
21
|
+
const validFixture = JSON.parse(fs.readFileSync(fixturePath, 'utf8'));
|
|
22
|
+
|
|
23
|
+
test('validateReport accepts valid fixture', () => {
|
|
24
|
+
const result = validateReport(validFixture);
|
|
25
|
+
assert.equal(result.ok, true);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('validateReport rejects missing review_id', () => {
|
|
29
|
+
const bad = { ...validFixture };
|
|
30
|
+
delete bad.review_id;
|
|
31
|
+
const result = validateReport(bad);
|
|
32
|
+
assert.equal(result.ok, false);
|
|
33
|
+
assert.ok(result.errors.some((e) => e.includes('review_id')));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('validateReport rejects reverify without parent_report', () => {
|
|
37
|
+
const bad = {
|
|
38
|
+
...validFixture,
|
|
39
|
+
kind: 'reverify',
|
|
40
|
+
findings: [
|
|
41
|
+
{
|
|
42
|
+
...validFixture.findings[0],
|
|
43
|
+
verdict: 'still_open',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
const result = validateReport(bad);
|
|
48
|
+
assert.equal(result.ok, false);
|
|
49
|
+
assert.ok(result.errors.some((e) => e.includes('parent_report')));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('countOpenCritical counts confirmed critical only', () => {
|
|
53
|
+
const withCritical = {
|
|
54
|
+
...validFixture,
|
|
55
|
+
findings: [
|
|
56
|
+
{
|
|
57
|
+
id: 'F-001',
|
|
58
|
+
lens: 'security',
|
|
59
|
+
location: 'a.ts:1',
|
|
60
|
+
claim: 'x',
|
|
61
|
+
severity: 'critical',
|
|
62
|
+
verdict: 'confirmed',
|
|
63
|
+
verdict_reason: 'real',
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
};
|
|
67
|
+
assert.equal(countOpenCritical(withCritical), 1);
|
|
68
|
+
assert.equal(countOpenCritical(validFixture), 0);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('parseArgs handles --fail-on critical', () => {
|
|
72
|
+
const opts = parseArgs(['--file', 'x.json', '--fail-on', 'critical']);
|
|
73
|
+
assert.equal(opts.failOnCritical, true);
|
|
74
|
+
assert.equal(opts.file, 'x.json');
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('runExport succeeds on fixture', () => {
|
|
78
|
+
const result = runExport({ file: fixturePath, out: null, failOnCritical: false });
|
|
79
|
+
assert.equal(result.exitCode, 0);
|
|
80
|
+
assert.ok(result.message.includes('OK'));
|
|
81
|
+
assert.ok(result.message.includes('review_id'));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('runExport --fail-on critical fails when critical confirmed', () => {
|
|
85
|
+
const tmpDir = tmp('review-export-');
|
|
86
|
+
try {
|
|
87
|
+
const criticalReport = {
|
|
88
|
+
...validFixture,
|
|
89
|
+
summary: { tentative_count: 1, confirmed: 1 },
|
|
90
|
+
findings: [
|
|
91
|
+
{
|
|
92
|
+
id: 'F-001',
|
|
93
|
+
lens: 'security',
|
|
94
|
+
location: 'a.ts:1',
|
|
95
|
+
claim: 'auth bypass',
|
|
96
|
+
severity: 'critical',
|
|
97
|
+
verdict: 'confirmed',
|
|
98
|
+
verdict_reason: 'missing check',
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
};
|
|
102
|
+
const jsonPath = path.join(tmpDir, '20260605-smoke-review.json');
|
|
103
|
+
fs.writeFileSync(jsonPath, JSON.stringify(criticalReport));
|
|
104
|
+
|
|
105
|
+
const result = runExport(
|
|
106
|
+
{ file: jsonPath, out: null, failOnCritical: true, reviewsDir: '.reviews' },
|
|
107
|
+
tmpDir,
|
|
108
|
+
);
|
|
109
|
+
assert.equal(result.exitCode, 1);
|
|
110
|
+
assert.ok(result.message.includes('open critical'));
|
|
111
|
+
} finally {
|
|
112
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('parseArgs accepts --fail-on important and --render-md', () => {
|
|
117
|
+
const opts = parseArgs(['--fail-on', 'important', '--render-md']);
|
|
118
|
+
assert.equal(opts.failOn, 'important');
|
|
119
|
+
assert.equal(opts.failOnCritical, false);
|
|
120
|
+
assert.equal(opts.renderMd, true);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('parseArgs rejects an unsupported --fail-on level', () => {
|
|
124
|
+
assert.throws(() => parseArgs(['--fail-on', 'nope']), /unsupported --fail-on/);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('runExport --fail-on important catches an open important finding', () => {
|
|
128
|
+
const tmpDir = tmp('review-important-');
|
|
129
|
+
try {
|
|
130
|
+
const report = {
|
|
131
|
+
...validFixture,
|
|
132
|
+
summary: { tentative_count: 1, confirmed: 1 },
|
|
133
|
+
findings: [
|
|
134
|
+
{
|
|
135
|
+
id: 'F-001',
|
|
136
|
+
lens: 'correctness',
|
|
137
|
+
location: 'a.ts:1',
|
|
138
|
+
claim: 'edge case',
|
|
139
|
+
severity: 'important',
|
|
140
|
+
verdict: 'confirmed',
|
|
141
|
+
verdict_reason: 'no guard',
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
};
|
|
145
|
+
const jsonPath = path.join(tmpDir, '20260605-imp-review.json');
|
|
146
|
+
fs.writeFileSync(jsonPath, JSON.stringify(report));
|
|
147
|
+
|
|
148
|
+
// critical gate passes (no critical), important gate fails
|
|
149
|
+
assert.equal(runExport({ file: jsonPath, failOn: 'critical' }, tmpDir).exitCode, 0);
|
|
150
|
+
const imp = runExport({ file: jsonPath, failOn: 'important' }, tmpDir);
|
|
151
|
+
assert.equal(imp.exitCode, 1);
|
|
152
|
+
assert.ok(imp.message.includes('open important+'));
|
|
153
|
+
} finally {
|
|
154
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test('runExport --render-md regenerates the paired markdown', () => {
|
|
159
|
+
const tmpDir = tmp('review-rendermd-');
|
|
160
|
+
try {
|
|
161
|
+
const jsonPath = path.join(tmpDir, '20260605-r-review.json');
|
|
162
|
+
fs.writeFileSync(jsonPath, JSON.stringify(validFixture));
|
|
163
|
+
const result = runExport({ file: jsonPath, renderMd: true }, tmpDir);
|
|
164
|
+
assert.equal(result.exitCode, 0, result.message);
|
|
165
|
+
assert.ok(fs.existsSync(jsonPath.replace(/\.json$/, '.md')));
|
|
166
|
+
assert.ok(result.message.includes('rendered:'));
|
|
167
|
+
} finally {
|
|
168
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test('findLatestReviewJson picks newest non-reverify file', () => {
|
|
173
|
+
const tmpDir = tmp('review-find-');
|
|
174
|
+
try {
|
|
175
|
+
const older = path.join(tmpDir, '20260101-old-review.json');
|
|
176
|
+
const newer = path.join(tmpDir, '20260201-new-review.json');
|
|
177
|
+
const reverify = path.join(tmpDir, '20260202-scope-reverify.json');
|
|
178
|
+
fs.writeFileSync(older, '{}');
|
|
179
|
+
fs.writeFileSync(newer, '{}');
|
|
180
|
+
fs.writeFileSync(reverify, '{}');
|
|
181
|
+
|
|
182
|
+
const olderTime = Date.now() - 10_000;
|
|
183
|
+
const newerTime = Date.now();
|
|
184
|
+
fs.utimesSync(older, olderTime / 1000, olderTime / 1000);
|
|
185
|
+
fs.utimesSync(newer, newerTime / 1000, newerTime / 1000);
|
|
186
|
+
|
|
187
|
+
assert.equal(findLatestReviewJson(tmpDir), newer);
|
|
188
|
+
} finally {
|
|
189
|
+
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('formatSummary includes scope and counts', () => {
|
|
194
|
+
const text = formatSummary(validFixture);
|
|
195
|
+
assert.ok(text.includes('checkout-sessions'));
|
|
196
|
+
assert.ok(text.includes('confirmed: 1'));
|
|
197
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"review_id": "20260605T160000Z-mercury-checkout-smoke",
|
|
3
|
+
"kind": "review",
|
|
4
|
+
"created_at": "2026-06-05T16:00:00.000Z",
|
|
5
|
+
"scope": {
|
|
6
|
+
"type": "paths",
|
|
7
|
+
"description": "services/mercury/src/services/checkout-sessions.ts",
|
|
8
|
+
"paths": ["services/mercury/src/services/checkout-sessions.ts"]
|
|
9
|
+
},
|
|
10
|
+
"lenses": ["security", "correctness"],
|
|
11
|
+
"summary": {
|
|
12
|
+
"tentative_count": 2,
|
|
13
|
+
"confirmed": 1,
|
|
14
|
+
"false_positive": 1,
|
|
15
|
+
"downgraded": 0,
|
|
16
|
+
"needs_decision": 0
|
|
17
|
+
},
|
|
18
|
+
"findings": [
|
|
19
|
+
{
|
|
20
|
+
"id": "F-001",
|
|
21
|
+
"lens": "correctness",
|
|
22
|
+
"location": "services/mercury/src/services/checkout-sessions.ts:42",
|
|
23
|
+
"claim": "Edge case not handled for empty cart",
|
|
24
|
+
"evidence": "snippet",
|
|
25
|
+
"severity": "important",
|
|
26
|
+
"phase1_confidence": "medium",
|
|
27
|
+
"verdict": "confirmed",
|
|
28
|
+
"verdict_reason": "No guard before total calculation; tests absent."
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "F-002",
|
|
32
|
+
"lens": "security",
|
|
33
|
+
"location": "services/mercury/src/services/checkout-sessions.ts:10",
|
|
34
|
+
"claim": "SQL injection via session id",
|
|
35
|
+
"evidence": "snippet",
|
|
36
|
+
"severity": "critical",
|
|
37
|
+
"phase1_confidence": "low",
|
|
38
|
+
"verdict": "false_positive",
|
|
39
|
+
"verdict_reason": "ORM parameterizes query; no raw SQL."
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
}
|