GitNexus/gitnexus/test/unit/detect-changes-format.test.ts
Kevin Rajan 5e6b79deba
fix(cli): do not call zero-symbol detect-changes a clean tree (#3138)
* fix(cli): do not call zero-symbol detect-changes a clean tree

Print backend summary.message and distinguish a parsed diff with no overlapping indexed symbols from an empty git diff. Pin --color=never so color.ui=always cannot hide +++ b/ headers.

* fix(cli): localize clean-tree detect-changes and skip no-overlap when partial

Production empty diffs carry English summary.message; route that through t() so zh-CN fires. Do not claim no indexed-symbol overlap on queryDegraded partial results. Pin formatter tests to en and cover the production payload shapes.

* fix(cli): prettier detect-changes-format and degraded eval assertion

---------

Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
2026-09-02 18:59:53 +01:00

92 lines
2.9 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { formatDetectChangesResult } from '../../src/cli/detect-changes-format.js';
import { setCliLanguage } from '../../src/cli/i18n/index.js';
describe('formatDetectChangesResult — zero-symbol honesty (#3131)', () => {
beforeEach(() => {
setCliLanguage('en');
});
afterEach(() => {
setCliLanguage(null);
});
it('prints backend parse-fail message instead of a generic all-clear', () => {
const text = formatDetectChangesResult({
partial: true,
summary: {
changed_count: 0,
affected_count: 0,
risk_level: 'unknown',
message: 'Could not parse the git diff output — no file headers recognised.',
},
});
expect(text).toContain('PARTIAL RESULT');
expect(text).toContain('Could not parse the git diff output');
expect(text).not.toContain('No changes detected.');
});
it('does not call a parsed diff with no symbol overlap a clean tree', () => {
const text = formatDetectChangesResult({
summary: {
changed_count: 0,
affected_count: 0,
changed_files: 1,
risk_level: 'low',
},
});
expect(text).toMatch(/Diff touched 1 file/);
expect(text).not.toContain('No changes detected.');
expect(text).not.toContain('PARTIAL RESULT');
});
it('does not claim no-overlap when a degraded query left changed_count at zero', () => {
const text = formatDetectChangesResult({
partial: true,
summary: {
changed_count: 0,
affected_count: 0,
changed_files: 1,
risk_level: 'unknown',
},
});
expect(text).toContain('PARTIAL RESULT');
expect(text).not.toMatch(/no indexed symbols overlap/i);
expect(text).not.toContain('No changes detected.');
});
it('keeps the clean-tree sentence only when git produced no files', () => {
const text = formatDetectChangesResult({
summary: { changed_count: 0, affected_count: 0, changed_files: 0, risk_level: 'none' },
});
expect(text).toBe('No changes detected.');
});
it('localizes the production clean-tree payload that carries English summary.message', () => {
setCliLanguage('zh-CN');
const text = formatDetectChangesResult({
summary: {
changed_count: 0,
affected_count: 0,
risk_level: 'none',
message: 'No changes detected.',
},
});
expect(text).toBe('未检测到变更。');
});
it('localizes confirmed no-overlap under GITNEXUS_LANG=zh-CN', () => {
setCliLanguage('zh-CN');
const text = formatDetectChangesResult({
summary: {
changed_count: 0,
affected_count: 0,
changed_files: 1,
risk_level: 'low',
},
});
expect(text).toContain('diff 触及 1 个文件');
expect(text).not.toContain('未检测到变更。');
expect(text).not.toContain('No changes detected.');
});
});