Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <path>` in its summary); restores stripped
# trailing newlines in place (AGT-4406)
Expand Down
55 changes: 55 additions & 0 deletions src/agents/pipelineGuards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
12 changes: 6 additions & 6 deletions src/agents/pipelineGuards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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<GuardResult> {
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.`,
Expand All @@ -813,7 +813,7 @@ async function runReformatScopeGuard(projectPath: string): Promise<GuardResult>
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) };
}

/**
Expand Down
27 changes: 27 additions & 0 deletions src/agents/reformatMix.ts
Original file line number Diff line number Diff line change
@@ -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.'];
}
Loading