From 9befedc148522e525434c1a78379657e2c2fb33a Mon Sep 17 00:00:00 2001 From: Heewon Oh Date: Sun, 15 Nov 2026 07:42:13 +0900 Subject: [PATCH] =?UTF-8?q?feat(gate):=20reformat-only=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=EA=B3=BC=20=EC=8B=A4=EC=A7=88=20=EB=B3=80=EA=B2=BD?= =?UTF-8?q?=EC=9D=B4=20=ED=95=9C=20=EB=B3=80=EA=B2=BD=EC=97=90=20=EC=84=9E?= =?UTF-8?q?=EC=9D=B4=EB=A9=B4=20=EB=B0=9C=ED=96=89=20=EB=B3=B4=EB=A5=98=20?= =?UTF-8?q?(AGT-4899)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.example.yaml | 2 +- src/agents/pipelineGuards.test.ts | 55 +++++++++++++++++++++++++++++++ src/agents/pipelineGuards.ts | 12 +++---- src/agents/reformatMix.ts | 27 +++++++++++++++ 4 files changed, 89 insertions(+), 7 deletions(-) create mode 100644 src/agents/reformatMix.ts diff --git a/config.example.yaml b/config.example.yaml index b7b02352..9f441f52 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -338,7 +338,7 @@ autonomous: contractEvidenceCheck: true # block self-referential contract tests without producer/consumer evidence (INT-2388 #2) verifiedMetricEvidenceCheck: true # block verified evidence deletion / metric changes without distributions (INT-2388 #4) deadModuleCheck: true # warn on new modules nothing imports/calls (INT-2388 #5) - reformatCheck: true # warn on reformat-only files / oversized diffs (INT-2388 #6) + reformatCheck: true # warn on reformat-only files / oversized diffs (INT-2388 #6); block reformat mixed with substantive changes (AGT-4899) rewriteCheck: true # block an unacknowledged whole-file rewrite (>30% of a 20+ line file deleted; # the worker may declare `REWRITE: ` in its summary); restores stripped # trailing newlines in place (AGT-4406) diff --git a/src/agents/pipelineGuards.test.ts b/src/agents/pipelineGuards.test.ts index 7cc85a4d..7cf36108 100644 --- a/src/agents/pipelineGuards.test.ts +++ b/src/agents/pipelineGuards.test.ts @@ -783,6 +783,61 @@ describe('pipelineGuards — INT-2388 deterministic guards', () => { expect(issues.length).toBe(0); }); + describe('reformat mixed with substantive changes (AGT-4899)', () => { + beforeEach(() => { + writeFileSync(join(repo, 'other.ts'), 'export const other = 2;\n'); + execFileSync('git', ['add', 'other.ts'], { cwd: repo }); + execFileSync('git', ['commit', '-m', 'add other'], { cwd: repo }); + }); + + it('holds publication when one change carries a reformat-only file and a substantive one', async () => { + writeFileSync(join(repo, 'base.ts'), ' export const base = 1;\n'); // reformat only + writeFileSync(join(repo, 'other.ts'), 'export const other = 3;\n'); // real change + const res = await runGuards(mockWorker(), repo, { reformatCheck: true }); + const result = res.results.find(r => r.guard === 'reformatScope')!; + expect(result.blocking).toBe(true); + expect(result.passed).toBe(false); + expect(res.allPassed).toBe(false); + const mixed = result.issues.find(i => i.startsWith('Reformat mixed'))!; + expect(mixed).toContain('reformat-only base.ts'); + expect(mixed).toContain('substantive other.ts'); + expect(mixed).toContain('commit the formatting separately'); + }); + + it('treats a new file as a substantive change next to a reformat', async () => { + writeFileSync(join(repo, 'base.ts'), ' export const base = 1;\n'); + writeFileSync(join(repo, 'fresh.ts'), 'export const fresh = 1;\n'); + const res = await runGuards(mockWorker(), repo, { reformatCheck: true }); + expect(res.allPassed).toBe(false); + }); + + it('passes a formatting-only change (advisory flag only)', async () => { + writeFileSync(join(repo, 'base.ts'), ' export const base = 1;\n'); + writeFileSync(join(repo, 'other.ts'), 'export const other = 2;\n'); + const res = await runGuards(mockWorker(), repo, { reformatCheck: true }); + const result = res.results.find(r => r.guard === 'reformatScope')!; + expect(result.blocking).toBe(false); + expect(res.allPassed).toBe(true); + }); + + it('passes a substantive-only change', async () => { + writeFileSync(join(repo, 'base.ts'), 'export const base = 2;\n'); + writeFileSync(join(repo, 'other.ts'), 'export const other = 3;\n'); + const res = await runGuards(mockWorker(), repo, { reformatCheck: true }); + expect(guardIssues(res, 'reformatScope')).toEqual([]); + expect(res.allPassed).toBe(true); + }); + + it('passes once the formatting is committed separately', async () => { + writeFileSync(join(repo, 'base.ts'), ' export const base = 1;\n'); + execFileSync('git', ['commit', '-am', 'style: reindent'], { cwd: repo }); + writeFileSync(join(repo, 'other.ts'), 'export const other = 3;\n'); + const res = await runGuards(mockWorker(), repo, { reformatCheck: true }); + expect(guardIssues(res, 'reformatScope')).toEqual([]); + expect(res.allPassed).toBe(true); + }); + }); + it('flags an oversized diff (tracked-line count)', async () => { // Large-diff uses tracked numstat; rewrite a committed file so the added // lines register (untracked new files count as 0 added — see guard note). diff --git a/src/agents/pipelineGuards.ts b/src/agents/pipelineGuards.ts index 623dddf6..86c92a43 100644 --- a/src/agents/pipelineGuards.ts +++ b/src/agents/pipelineGuards.ts @@ -16,6 +16,7 @@ import { isEphemeralWorktreeArtifact } from '../support/worktreeEphemeral.js'; import { inspectRewrites, describeRewrite } from './rewriteGuard.js'; import { figuresChangedInPlace, unsourcedFigures, uncitedApprovalClaims } from './claimEvidenceGuard.js'; import { claimsGate, unassertedReportedKeys, gateClaimIssue } from './gateClaimGuard.js'; +import { isMixedReformatIssue, mixedReformatIssues } from './reformatMix.js'; const execFileAsync = promisify(execFile); @@ -781,18 +782,17 @@ async function runVerifiedMetricEvidenceGuard( } /** - * Reformat/scope guard (INT-2388 defect #6): flag reformat-only files (whose - * diff vanishes under `git diff -w`) and unusually large diffs. Both inflate - * cross-PR conflict surface and hide the real change. Non-blocking — advisory. + * Reformat/scope guard (INT-2388 defect #6): flag reformat-only files (gone under + * `git diff -w`) and large diffs, which hide the real change. Advisory, except a + * reformat mixed with substantive changes blocks publication (AGT-4899). */ async function runReformatScopeGuard(projectPath: string): Promise { const guard = 'reformatScope'; const issues: string[] = []; const LARGE_DIFF_LINES = 1200; - try { const details = await getWorkingDiffDetail(projectPath); - + issues.push(...mixedReformatIssues(details)); for (const d of details.filter(d => d.whitespaceOnly)) { issues.push( `[${d.file}] reformat-only change (no semantic diff under -w) — move formatting to a separate commit to keep the PR scoped.`, @@ -813,7 +813,7 @@ async function runReformatScopeGuard(projectPath: string): Promise console.warn('[Guard:reformatScope] Error:', err); } - return { passed: issues.length === 0, guard, issues, blocking: false }; + return { passed: issues.length === 0, guard, issues, blocking: issues.some(isMixedReformatIssue) }; } /** diff --git a/src/agents/reformatMix.ts b/src/agents/reformatMix.ts new file mode 100644 index 00000000..da712632 --- /dev/null +++ b/src/agents/reformatMix.ts @@ -0,0 +1,27 @@ +// ============================================ +// OpenSwarm — reformat mixed with substantive changes (AGT-4899) +// ============================================ +// +// AGT-4190 defence 3. The uncommitted change becomes one publication commit; +// cgf-portal #218 buried four real edits among seven reformats there — the same +// outcome as dodging review. A formatting-only change and a substantive-only +// change both pass, so committing the formatting separately clears it. + +import type { FileDiffDetail } from '../support/gitTracker.js'; + +const MIXED_PREFIX = 'Reformat mixed with substantive changes:'; + +/** True for the issue `mixedReformatIssues` produces — the one that blocks. */ +export function isMixedReformatIssue(issue: string): boolean { + return issue.startsWith(MIXED_PREFIX); +} + +/** The blocking issue for a change that mixes reformat-only files with real ones (empty when not mixed). */ +export function mixedReformatIssues(details: FileDiffDetail[]): string[] { + const reformatOnly = details.filter(d => d.whitespaceOnly); + const substantive = details.filter(d => !d.whitespaceOnly && (d.isNew || d.added + d.deleted > 0)); + if (reformatOnly.length === 0 || substantive.length === 0) return []; + return [`${MIXED_PREFIX} reformat-only ${reformatOnly.map(d => d.file).join(', ')}; ` + + `substantive ${substantive.map(d => d.file).join(', ')}. Publication is held — commit the formatting ` + + 'separately (its own commit, or revert it), so the substantive diff can be reviewed on its own.']; +}