buildproof 3.12.3 → 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 +7 -1
- package/core/ci.js +28 -1
- package/core/integrity.js +44 -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
|
@@ -148,7 +148,13 @@ async function main() {
|
|
|
148
148
|
if (cmd === 'ci' || cmd === 'spec') { // pull request check (Team+) / spec check (Pro+): no background service needed
|
|
149
149
|
const ci = require('../core/ci');
|
|
150
150
|
const folder = positional[0] || process.cwd();
|
|
151
|
-
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
|
+
}
|
|
152
158
|
const lic = ci.licensed(require('../core/license'), cmd);
|
|
153
159
|
if (!lic.ok) out(`CANNOT_CHECK ${lic.why}`, 2);
|
|
154
160
|
const base = typeof flag('base') === 'string' ? flag('base') : null;
|
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/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/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": {
|