buildproof 3.12.2 → 3.12.4
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 +1 -1
- package/bin/buildproof.js +19 -10
- package/core/ci.js +28 -1
- package/core/hunt-client.js +18 -3
- package/core/integrity.js +44 -2
- package/core/service.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ One-tap hooks (Projects -> AI tools, or `buildproof connect git,claude,cursor`):
|
|
|
27
27
|
Projects: Node / Web (npm scripts typecheck, lint, build, test) and Python (syntax check of every file without writing .pyc, ruff and mypy when configured, pytest or unittest).
|
|
28
28
|
Also (3.7.1): Go (go build, go vet, go test), Rust (cargo build, cargo test - also tests inside the source file), Java with Maven or Gradle (JUnit results), .NET (dotnet build, dotnet test), Ruby (syntax check, RSpec or Minitest), PHP (syntax check, PHPUnit). Each uses its own toolchain on your computer; a missing toolchain or unreadable test results is reported, never counted as proven.
|
|
29
29
|
|
|
30
|
-
Pull request checks (3.8.0; free trial, then Team and Enterprise): `buildproof ci --init` adds a GitHub workflow; every pull request is compared with its base branch - test-integrity rules on the changed files, build/test on both sides, fail-closed verdict in the job summary. A check that fails is run once more: if it then passes it is reported as FLAKY (not blamed on the pull request); `--no-retry` keeps it strict (3.11). Spec check (free trial, then Pro and up; `buildproof spec` locally or inside `buildproof ci`): `.buildproof/spec.md`, one requirement per line with the test that proves it (`- Free shipping from $50 => test: free shipping from 50`); a requirement without a passing test is never accepted. Live demo: https://buildproof.mgrprosnetwork.com/demo
|
|
30
|
+
Pull request checks (3.8.0; free trial, then Team and Enterprise): `buildproof ci --init` adds a GitHub workflow; every pull request is compared with its base branch - test-integrity rules on the changed files, build/test on both sides, fail-closed verdict in the job summary. A check that fails is run once more: if it then passes it is reported as FLAKY (not blamed on the pull request); `--no-retry` keeps it strict (3.11). Protect your base branch (GitHub: Settings > Branches > branch protection) so only pull requests can change it: the check compares against the base, and an agent that can push to the base directly could weaken the baseline too. Since 3.12.4 `buildproof ci --init` warns when it is not protected. Spec check (free trial, then Pro and up; `buildproof spec` locally or inside `buildproof ci`): `.buildproof/spec.md`, one requirement per line with the test that proves it (`- Free shipping from $50 => test: free shipping from 50`); a requirement without a passing test is never accepted. Live demo: https://buildproof.mgrprosnetwork.com/demo
|
|
31
31
|
|
|
32
32
|
Audit report (3.9.0; free trial, then Enterprise): `buildproof audit --since 2026-01-01` writes a signed HTML + JSON report of every accepted and rejected change; `buildproof audit --verify report.json` shows any later edit. Team dashboard (Team and Enterprise): `buildproof team` opens it; your licence key unlocks your own team's certificates.
|
|
33
33
|
|
package/bin/buildproof.js
CHANGED
|
@@ -33,7 +33,8 @@ const ROOT = path.resolve(__dirname, '..');
|
|
|
33
33
|
const config = require('../core/config');
|
|
34
34
|
|
|
35
35
|
const args = process.argv.slice(2);
|
|
36
|
-
const cmd = args[0] || 'help';
|
|
36
|
+
const cmd = ['-h', '--help'].includes(args[0]) ? 'help' : (args[0] || 'help');
|
|
37
|
+
if (['-v', '--version', 'version'].includes(cmd)) { console.log(require('../package.json').version); process.exit(0); }
|
|
37
38
|
const flag = (n) => { const a = args.find((x) => x === `--${n}` || x.startsWith(`--${n}=`)); return a == null ? null : a.includes('=') ? a.split('=').slice(1).join('=') : true; };
|
|
38
39
|
const hook = flag('hook');
|
|
39
40
|
const force = !!flag('force');
|
|
@@ -52,14 +53,15 @@ function readStdin() {
|
|
|
52
53
|
function parse(s) { try { return JSON.parse(s); } catch { return {}; } }
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
function api(method, p, body) {
|
|
56
|
+
function api(method, p, body, timeoutMs = 30 * 60 * 1000) {
|
|
56
57
|
const c = config.load();
|
|
57
58
|
return new Promise((resolve) => {
|
|
58
59
|
const data = body ? JSON.stringify(body) : null;
|
|
59
|
-
const req = http.request({ host: '127.0.0.1', port: c.port, path: p, method, headers: { authorization: `Bearer ${c.token}`, ...(data ? { 'content-type': 'application/json', 'content-length': Buffer.byteLength(data) } : {}) }, timeout:
|
|
60
|
+
const req = http.request({ host: '127.0.0.1', port: c.port, path: p, method, headers: { authorization: `Bearer ${c.token}`, ...(data ? { 'content-type': 'application/json', 'content-length': Buffer.byteLength(data) } : {}) }, timeout: timeoutMs }, (res) => {
|
|
60
61
|
let raw = ''; res.on('data', (d) => { raw += d; }); res.on('end', () => { try { resolve(JSON.parse(raw)); } catch { resolve({ ok: false, error: 'bad_response' }); } });
|
|
61
62
|
});
|
|
62
|
-
req.on('
|
|
63
|
+
req.on('timeout', () => req.destroy(new Error('timeout')));
|
|
64
|
+
req.on('error', (e) => resolve(e && e.message === 'timeout' ? { ok: false, error: 'no_answer' } : { ok: false, error: 'service_not_running', down: true }));
|
|
63
65
|
if (data) req.write(data);
|
|
64
66
|
req.end();
|
|
65
67
|
});
|
|
@@ -146,7 +148,13 @@ async function main() {
|
|
|
146
148
|
if (cmd === 'ci' || cmd === 'spec') { // pull request check (Team+) / spec check (Pro+): no background service needed
|
|
147
149
|
const ci = require('../core/ci');
|
|
148
150
|
const folder = positional[0] || process.cwd();
|
|
149
|
-
if (cmd === 'ci' && flag('init')) {
|
|
151
|
+
if (cmd === 'ci' && flag('init')) {
|
|
152
|
+
const r = ci.init(folder);
|
|
153
|
+
const bp = await ci.baseProtection(folder); // only advice: never fails the command
|
|
154
|
+
if (bp.protected === false) console.log(`Warning: ${bp.branch} is not protected. An agent that can push to ${bp.branch} can weaken the baseline too. Protect it so only pull requests can change it: https://github.com/${bp.repo}/settings/branches`);
|
|
155
|
+
else if (bp.protected === null && bp.repo) console.log(`Note: could not check whether ${bp.branch} is protected (${bp.note}). Make sure only pull requests can change it.`);
|
|
156
|
+
out(r.ok ? `CI_WORKFLOW ${r.file} - add your key as the BUILDPROOF_LICENSE secret` : `CI_WORKFLOW_EXISTS ${r.file}`, r.ok ? 0 : 1);
|
|
157
|
+
}
|
|
150
158
|
const lic = ci.licensed(require('../core/license'), cmd);
|
|
151
159
|
if (!lic.ok) out(`CANNOT_CHECK ${lic.why}`, 2);
|
|
152
160
|
const base = typeof flag('base') === 'string' ? flag('base') : null;
|
|
@@ -207,7 +215,7 @@ async function main() {
|
|
|
207
215
|
}
|
|
208
216
|
if (['license', 'activate', 'status', 'open'].includes(cmd)) { // these need the local service: start it if it is not running
|
|
209
217
|
const sv = await require('../core/service').ensure({ autostart: false });
|
|
210
|
-
if (!sv.ok) out(`DOWN BuildProof could not start on port ${sv.port} (if another program uses it, pick a free port: set MGR_PORT=38711)`, 1);
|
|
218
|
+
if (!sv.ok) out(sv.how === 'port_busy' ? `DOWN port ${sv.port} is used by another program, not BuildProof - pick a free port: set MGR_PORT=38711` : `DOWN BuildProof could not start on port ${sv.port} (if another program uses it, pick a free port: set MGR_PORT=38711)`, 1);
|
|
211
219
|
}
|
|
212
220
|
if (cmd === 'license' || cmd === 'activate') {
|
|
213
221
|
if (cmd === 'activate') {
|
|
@@ -228,8 +236,8 @@ async function main() {
|
|
|
228
236
|
const r = await api('POST', '/api/license', { key });
|
|
229
237
|
out(r.ok ? `ACTIVATED ${r.license.label} until ${String(r.license.expires).slice(0, 10)}` : `ACTIVATE_FAIL ${r.error}`, r.ok ? 0 : 1);
|
|
230
238
|
}
|
|
231
|
-
const r = await api('GET', '/api/license');
|
|
232
|
-
if (!r.ok) out(`DOWN ${r.error}`, 1);
|
|
239
|
+
const r = await api('GET', '/api/license', null, 15000);
|
|
240
|
+
if (!r.ok || !r.label) out(`DOWN ${r.error || 'unexpected answer on port ' + config.load().port}`, 1);
|
|
233
241
|
out(`LICENSE ${r.label} ${r.status}${r.daysLeft != null ? ' days_left=' + r.daysLeft : ''}${r.projects ? ' projects_max=' + r.projects : ''}`, r.status === 'expired' ? 1 : 0);
|
|
234
242
|
}
|
|
235
243
|
if (cmd === 'init') {
|
|
@@ -269,8 +277,9 @@ async function main() {
|
|
|
269
277
|
}
|
|
270
278
|
if (cmd === 'open') { const u = `http://127.0.0.1:${config.load().port || 38700}/connect`; openUrl(u); out('OPEN ' + u, 0); }
|
|
271
279
|
if (cmd === 'status') {
|
|
272
|
-
const r = await api('GET', '/api/status');
|
|
273
|
-
|
|
280
|
+
const r = await api('GET', '/api/status', null, 15000);
|
|
281
|
+
if (r.ok && typeof r.version !== 'string') out(`DOWN unexpected answer on port ${config.load().port}`, 1);
|
|
282
|
+
out(r.ok ? `BUILDPROOF v${r.version} AI=${r.ai && r.ai.ok ? 'OK' : 'DOWN'} fixes=${r.fixes} key=${r.fingerprint}` : `DOWN ${r.error}`, r.ok ? 0 : 1);
|
|
274
283
|
}
|
|
275
284
|
if (!['start', 'check', 'accept', 'rollback', 'connect', 'try'].includes(cmd)) {
|
|
276
285
|
out(fs.readFileSync(__filename, 'utf8').split('\n').slice(3, 22).map((l) => l.replace(/^ \* ?/, '')).join('\n'), cmd === 'help' ? 0 : 1);
|
package/core/ci.js
CHANGED
|
@@ -267,4 +267,31 @@ function init(root) {
|
|
|
267
267
|
return { ok: true, file: f };
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
|
|
270
|
+
/** Is the base branch protected on GitHub? An agent that can push to it can weaken the baseline too.
|
|
271
|
+
* Never fails: returns { protected: true|false|null, branch, repo, note }. */
|
|
272
|
+
function baseProtection(root, env = process.env) {
|
|
273
|
+
const { execFileSync } = require('child_process');
|
|
274
|
+
const git = (a) => { try { return execFileSync('git', a, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'], timeout: 5000 }).trim(); } catch { return ''; } };
|
|
275
|
+
const url = git(['remote', 'get-url', 'origin']);
|
|
276
|
+
const m = url.match(/(?:^|[@/])github\.com(?::\d+)?[:/]+([^/]+)\/([^/]+?)(?:\.git)?\/?$/i);
|
|
277
|
+
if (!m) return Promise.resolve({ protected: null, repo: url ? 'origin' : '', branch: 'your base branch', note: url ? 'not a github.com repository' : 'no git remote' });
|
|
278
|
+
const has = (ref) => !!git(['rev-parse', '--verify', '--quiet', ref]);
|
|
279
|
+
const branch = (git(['symbolic-ref', '--quiet', '--short', 'refs/remotes/origin/HEAD']).replace(/^origin\//, ''))
|
|
280
|
+
|| ['main', 'master'].find((b) => has('refs/remotes/origin/' + b)) || ['main', 'master'].find((b) => has('refs/heads/' + b)) || 'main';
|
|
281
|
+
const repo = `${m[1]}/${m[2]}`;
|
|
282
|
+
const token = env.GITHUB_TOKEN || env.GH_TOKEN || '';
|
|
283
|
+
return new Promise((resolve) => { try {
|
|
284
|
+
const req = require('https').request({ host: 'api.github.com', path: `/repos/${encodeURIComponent(m[1])}/${encodeURIComponent(m[2])}/branches/${encodeURIComponent(branch)}`, method: 'GET', timeout: 5000,
|
|
285
|
+
headers: { 'user-agent': 'buildproof', accept: 'application/vnd.github+json', ...(token ? { authorization: 'Bearer ' + token } : {}) } }, (res) => {
|
|
286
|
+
let b = ''; res.on('data', (d) => { b += d; });
|
|
287
|
+
res.on('end', () => { let j = null; try { j = JSON.parse(b); } catch { /* not json */ }
|
|
288
|
+
if (res.statusCode === 200 && j && typeof j.protected === 'boolean') resolve({ protected: j.protected, branch, repo });
|
|
289
|
+
else resolve({ protected: null, branch, repo, note: res.statusCode === 404 ? (token ? 'branch not found, or the token has no access' : 'private repository or branch not found: set GITHUB_TOKEN to check') : res.statusCode === 401 ? 'the GitHub token was refused' : res.statusCode === 403 ? 'GitHub rate limit or no access' : 'GitHub did not answer' }); });
|
|
290
|
+
});
|
|
291
|
+
req.on('timeout', () => req.destroy(new Error('timeout')));
|
|
292
|
+
req.on('error', () => resolve({ protected: null, branch, repo, note: 'GitHub not reachable' }));
|
|
293
|
+
req.end();
|
|
294
|
+
} catch { resolve({ protected: null, branch, repo, note: 'could not ask GitHub' }); } });
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
module.exports = { baseProtection, check, init, licensed, changesBetween, findBase, markdown, parseSpec, testNameIn, WORKFLOW };
|
package/core/hunt-client.js
CHANGED
|
@@ -52,8 +52,20 @@ function localLlm(cfg, env = process.env) {
|
|
|
52
52
|
};
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/** Is the customer's own model reachable (and pulled)? Checked before any code is sent. */
|
|
56
|
+
async function localReady(cfg, env = process.env) {
|
|
57
|
+
const endpoint = (env.BUILDPROOF_AI_URL || (cfg.ollama && cfg.ollama.endpoint) || 'http://127.0.0.1:11434').replace(/\/$/, '');
|
|
58
|
+
const model = env.BUILDPROOF_AI_MODEL || (cfg.ollama && cfg.ollama.model) || 'qwen3-coder:30b';
|
|
59
|
+
const r = await request('GET', endpoint + '/api/tags', {}, null, 3000);
|
|
60
|
+
if (r.code !== 200 || !r.j) return { ok: false, why: `no local AI model answers at ${endpoint} - install Ollama (ollama.com) and run: ollama pull ${model}, or use --cloud` };
|
|
61
|
+
const names = (Array.isArray(r.j.models) ? r.j.models : []).map((m) => (m && (m.name || m.model)) || '');
|
|
62
|
+
if (!names.some((n) => n === model || n === model + ':latest' || n.split(':')[0] === model)) return { ok: false, why: `the model ${model} is not pulled - run: ollama pull ${model}, or use --cloud` };
|
|
63
|
+
return { ok: true };
|
|
64
|
+
}
|
|
65
|
+
|
|
55
66
|
async function run({ root, base, cloud, intent, cfg, license, server, llm, log = () => {}, pollMs = 2000, maxMs = 40 * 60000 }) {
|
|
56
67
|
const headers = authHeaders(license);
|
|
68
|
+
if (!cloud && !llm) { const lr = await localReady(cfg || {}); if (!lr.ok) return { code: 2, text: 'CANNOT_HUNT ' + lr.why }; }
|
|
57
69
|
let a; try { a = archives(root, base); } catch (e) { return { code: 2, text: 'CANNOT_HUNT git: ' + String(e.message).split('\n')[0] }; }
|
|
58
70
|
const start = await request('POST', server + '/api/hunt', headers, { before: a.before, after: a.after, mode: cloud ? 'cloud' : 'local', intent }, 300000);
|
|
59
71
|
if (start.code !== 200 || !start.j || !start.j.ok) {
|
|
@@ -63,6 +75,7 @@ async function run({ root, base, cloud, intent, cfg, license, server, llm, log =
|
|
|
63
75
|
}
|
|
64
76
|
const id = start.j.id;
|
|
65
77
|
const ask = llm || localLlm(cfg || {});
|
|
78
|
+
let unanswered = 0;
|
|
66
79
|
log(`HUNT_STARTED ${id} mode=${start.j.mode}`);
|
|
67
80
|
const t0 = Date.now();
|
|
68
81
|
for (;;) {
|
|
@@ -71,7 +84,8 @@ async function run({ root, base, cloud, intent, cfg, license, server, llm, log =
|
|
|
71
84
|
if (st.code !== 200 || !st.j) { await sleep(pollMs); continue; }
|
|
72
85
|
for (const p of st.j.prompts || []) { // the server's AI questions, answered by the local model
|
|
73
86
|
const text = await ask(p.prompt);
|
|
74
|
-
await request('POST', `${server}/api/hunt/${id}/answer`, headers, { id: p.id, text }, 60000);
|
|
87
|
+
const sent = await request('POST', `${server}/api/hunt/${id}/answer`, headers, { id: p.id, text }, 60000);
|
|
88
|
+
if (!String(text || '').trim() || sent.code !== 200) unanswered += 1;
|
|
75
89
|
}
|
|
76
90
|
if (st.j.status === 'done' || st.j.status === 'error') {
|
|
77
91
|
const dir = path.join(root, '.buildproof'); fs.mkdirSync(dir, { recursive: true });
|
|
@@ -79,6 +93,7 @@ async function run({ root, base, cloud, intent, cfg, license, server, llm, log =
|
|
|
79
93
|
fs.writeFileSync(file, JSON.stringify({ report: st.j.report, certificate: st.j.certificate, signature: st.j.signature, algo: st.j.algo }, null, 2));
|
|
80
94
|
if (st.j.status === 'error') return { code: 2, text: `CANNOT_HUNT ${(st.j.report && st.j.report.error) || 'hunter error'}`, file };
|
|
81
95
|
const proven = (st.j.report.findings || []).filter((f) => f.proven);
|
|
96
|
+
if (!proven.length && unanswered) return { code: 2, text: `CANNOT_HUNT the AI model did not answer ${unanswered} question(s), so "no bugs" would not be honest - check your local model (ollama), or run with --cloud`, file };
|
|
82
97
|
const lines = proven.map((f) => ` - ${f.oracle} ${f.file}${f.line ? ':' + f.line : ''} ${f.why || ''}`);
|
|
83
98
|
return { code: proven.length ? 1 : 0, text: `${proven.length ? 'BUGS_PROVEN ' + proven.length : 'NO_PROVEN_BUGS'} files=${(st.j.report.files || []).length} report=${file}${lines.length ? '\n' + lines.join('\n') : ''}`, file, report: st.j.report };
|
|
84
99
|
}
|
|
@@ -93,11 +108,11 @@ async function credits({ license, server, buy, open }) {
|
|
|
93
108
|
const r = await request('POST', server + '/api/credits/order', headers, { pack: String(buy) });
|
|
94
109
|
if (r.code !== 200 || !r.j || !r.j.ok) return { code: 2, text: 'CANNOT_BUY ' + ((r.j && r.j.error) || 'server_unavailable') };
|
|
95
110
|
open(r.j.approve);
|
|
96
|
-
return { code: 0, text: `PAY ${r.j.checks} cloud checks for $${r.j.usd} in the
|
|
111
|
+
return { code: 0, text: `PAY ${r.j.checks} cloud checks for $${r.j.usd} in the checkout page that opened: ${r.j.approve}` };
|
|
97
112
|
}
|
|
98
113
|
const r = await request('GET', server + '/api/credits', headers);
|
|
99
114
|
if (r.code !== 200 || !r.j) return { code: 2, text: 'CANNOT_READ ' + ((r.j && r.j.error) || 'server_unavailable') };
|
|
100
115
|
return { code: 0, text: `CLOUD_CHECKS ${r.j.cloudChecks} (buy more: buildproof credits --buy 20)` };
|
|
101
116
|
}
|
|
102
117
|
|
|
103
|
-
module.exports = { run, credits, archives, authHeaders, localLlm };
|
|
118
|
+
module.exports = { run, credits, archives, authHeaders, localLlm, localReady };
|
package/core/integrity.js
CHANGED
|
@@ -192,6 +192,10 @@ function analyze({ root, beforeDir, changes, testFiles }) {
|
|
|
192
192
|
const inlineFiles = (changes || []).filter((c) => c.kind !== 'deleted' && /\.rs$/i.test(c.file) && INLINE_TESTS.test(read(path.join(root, c.file)) || '')).map((c) => c.file);
|
|
193
193
|
const getGroups = () => (groups || (groups = assertionGroups(root, [...(testFiles || []), ...inlineFiles])));
|
|
194
194
|
const add = (rule, file, detail) => findings.push({ rule, file, detail: String(detail || '').slice(0, 200), text: RULE_TEXT[rule] });
|
|
195
|
+
// names of the code files this change touched (not tests): a new test that mocks one of them is suspicious
|
|
196
|
+
const changedCode = (changes || []).filter((c) => c.kind !== 'deleted' && CODE_EXT.test(c.file) && !isTestFile(c.file))
|
|
197
|
+
.map((c) => ({ base: (path.basename(c.file).replace(/\.[^.]+$/, '').toLowerCase() === 'index' ? path.basename(path.dirname(c.file)) : path.basename(c.file).replace(/\.[^.]+$/, '')), file: c.file, src: c.kind === 'deleted' ? '' : (read(path.join(root, c.file)) || '') }))
|
|
198
|
+
.filter((x) => x.base.length >= 3 && !/^(index|main|mod|lib|init|__init__|utils?|helpers?)$/i.test(x.base));
|
|
195
199
|
for (const c of changes || []) {
|
|
196
200
|
const rel = c.file;
|
|
197
201
|
const before = c.kind === 'added' ? '' : read(path.join(beforeDir, rel));
|
|
@@ -274,8 +278,14 @@ function analyze({ root, beforeDir, changes, testFiles }) {
|
|
|
274
278
|
const goneAsserts = d.removed.filter((l) => ASSERT_RE.test(l));
|
|
275
279
|
if (goneAsserts.length) add('assertion_changed', rel, goneAsserts[0]);
|
|
276
280
|
}
|
|
277
|
-
// new mocks in an EXISTING test
|
|
278
|
-
|
|
281
|
+
// new mocks in an EXISTING test; in a brand-new test file only a mock of code this same change touched
|
|
282
|
+
// (a new test that mocks away the very code it should test proves nothing - mocking other things is fine)
|
|
283
|
+
let mock = c.kind === 'modified' ? d.added.find((l) => MOCK_RE.test(l)) : null;
|
|
284
|
+
if (!mock && c.kind === 'added') {
|
|
285
|
+
const i = d.added.findIndex((l) => mocksChangedModule(l, changedCode, rel));
|
|
286
|
+
// a partial mock keeps the real module (requireActual / importActual inside the factory, often on the next lines)
|
|
287
|
+
if (i >= 0 && !/requireActual|importActual|importOriginal/.test(d.added.slice(i, i + 6).join('\n'))) mock = d.added[i];
|
|
288
|
+
}
|
|
279
289
|
if (mock) add('mock_added', rel, mock);
|
|
280
290
|
const sil = d.added.find((l) => SILENCE_RE.test(l));
|
|
281
291
|
if (sil) add('checker_silenced', rel, sil);
|
|
@@ -302,6 +312,38 @@ function analyze({ root, beforeDir, changes, testFiles }) {
|
|
|
302
312
|
}
|
|
303
313
|
|
|
304
314
|
/** Multi-line pattern: count matches before vs after; report the first new one. */
|
|
315
|
+
/** Does this line mock away the very module this new test file is about?
|
|
316
|
+
* Only one precise form counts, so ordinary dependency mocks are never flagged:
|
|
317
|
+
* jest.mock / vi.mock / jest.doMock / mock.module('<relative path>') where the path, resolved from the test file,
|
|
318
|
+
* is a code file changed in the same change AND has the same name as the test file (fees.test.js mocking ./fees). */
|
|
319
|
+
function mocksChangedModule(line, changed, testRel = '') {
|
|
320
|
+
const l = String(line);
|
|
321
|
+
const js = l.match(/\b(?:jest|vi)\.(?:mock|doMock)\s*\(\s*(['"`])([^'"`]+)\1|\bmock\.module\s*\(\s*(['"`])([^'"`]+)\3/);
|
|
322
|
+
if (!js) return false;
|
|
323
|
+
const spec = js[2] || js[4];
|
|
324
|
+
if (!/^[./]/.test(spec)) return false; // a package or a Node built-in, not the project's own code
|
|
325
|
+
const strip = (f) => f.replace(/\\/g, '/').replace(/\.(c|m)?[jt]sx?$/i, '').replace(/\/index$/i, '').toLowerCase();
|
|
326
|
+
const t = String(testRel).replace(/\\/g, '/');
|
|
327
|
+
const target = strip(path.posix.normalize(path.posix.join(path.posix.dirname(t), spec)));
|
|
328
|
+
// the test's subject: fees.test.js / fees.spec.ts / __tests__/fees.js -> "fees"
|
|
329
|
+
const subject = path.posix.basename(t).replace(/\.(c|m)?[jt]sx?$/i, '').replace(/[._-](test|spec)s?$/i, '').toLowerCase();
|
|
330
|
+
if (!subject || target.split('/').pop() !== subject) return false;
|
|
331
|
+
if (/requireActual|importActual|importOriginal/.test(l)) return false; // partial mock: the real module stays in use
|
|
332
|
+
if (!changed.some((x) => /\.(c|m)?[jt]sx?$/i.test(x.file) && strip(x.file) === target)) return false;
|
|
333
|
+
// it must be the test's OWN file, not a same-named module in another layer (controllers/users.test.js -> ../services/users)
|
|
334
|
+
const tdir = path.posix.dirname(t).toLowerCase(); const targetDir = path.posix.dirname(target);
|
|
335
|
+
const TESTDIR = /^(__tests__|tests?|spec|specs)$/i;
|
|
336
|
+
if (targetDir === tdir) return true; // src/fees.test.js -> ./fees
|
|
337
|
+
if (TESTDIR.test(path.posix.basename(tdir)) && targetDir === path.posix.dirname(tdir)) return true; // src/__tests__/fees.js -> ../fees
|
|
338
|
+
const segs = tdir.split('/'); const i = segs.findIndex((x) => TESTDIR.test(x));
|
|
339
|
+
if (i >= 0) { // mirrored layout: test/a/fees.test.js -> src/a/fees ; only when the name is unique in the change
|
|
340
|
+
const rest = segs.slice(i + 1).join('/');
|
|
341
|
+
const same = changed.filter((x) => /\.(c|m)?[jt]sx?$/i.test(x.file) && strip(x.file).split('/').pop() === subject);
|
|
342
|
+
return same.length === 1 && (rest === '' || targetDir === rest || targetDir.endsWith('/' + rest));
|
|
343
|
+
}
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
|
|
305
347
|
function addedMatch(before, after, re) {
|
|
306
348
|
const g = new RegExp(re.source, re.flags.includes('g') ? re.flags : re.flags + 'g');
|
|
307
349
|
const mb = (before.match(g) || []).map(norm);
|
package/core/service.js
CHANGED
|
@@ -95,18 +95,21 @@ async function ensure({ autostart = true } = {}) {
|
|
|
95
95
|
const VERSION = require('../package.json').version;
|
|
96
96
|
let info = await healthInfo(cfg.port);
|
|
97
97
|
const older = (a, b) => { const x = String(a).split('.').map(Number), y = String(b).split('.').map(Number); for (let i = 0; i < 3; i++) { if ((x[i] || 0) !== (y[i] || 0)) return (x[i] || 0) < (y[i] || 0); } return false; };
|
|
98
|
-
if (info && info.ok && info.version && older(info.version, VERSION)) { // updated: replace the older service
|
|
98
|
+
if (info && info.ok === true && typeof info.version === 'string' && older(info.version, VERSION)) { // updated: replace the older service
|
|
99
99
|
if (stopOld(info)) {
|
|
100
100
|
for (let i = 0; i < 20 && info; i++) { await new Promise((r) => setTimeout(r, 300)); info = await healthInfo(cfg.port, 800); }
|
|
101
101
|
}
|
|
102
102
|
if (info) return { ok: true, how: `old-version-running(${info.version})`, autostart: null, port: cfg.port }; // could not replace it safely: keep using it
|
|
103
103
|
how = 'updated';
|
|
104
104
|
}
|
|
105
|
+
const isBp = (x) => !!(x && x.ok === true && typeof x.version === 'string');
|
|
106
|
+
if (info && !isBp(info)) return { ok: false, how: 'port_busy', port: cfg.port }; // another program answers on this port: never treat it as BuildProof
|
|
105
107
|
if (!info) {
|
|
106
108
|
startDetached();
|
|
107
109
|
if (how !== 'updated') how = 'started';
|
|
108
110
|
let ok = false;
|
|
109
|
-
|
|
111
|
+
const until = Date.now() + 20000; // at most 20 seconds, even when something on the port never answers
|
|
112
|
+
while (!ok && Date.now() < until) { await new Promise((r) => setTimeout(r, 500)); ok = isBp(await healthInfo(cfg.port, 1000)); }
|
|
110
113
|
if (!ok) return { ok: false, how: 'start_failed', port: cfg.port };
|
|
111
114
|
}
|
|
112
115
|
let auto = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "buildproof",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.4",
|
|
4
4
|
"description": "BuildProof - proof gate for AI-written code: test-integrity guard, fail-closed checks, scope lock, full rollback, signed certificates, local AI under supervision.",
|
|
5
5
|
"main": "core/server.js",
|
|
6
6
|
"scripts": {
|