Files
proffesor-for-testing__agen…/tests/unit/shared/c4-confidence.test.ts
T
Dragan Spiridonov 9fd18ed00a feat(code-intelligence): first-class C4 architecture diagrams (ADR-112)
Consolidate C4 diagram generation onto a single engine and expose it to
users via CLI and MCP, with a deterministic confidence gate and real
Knowledge-Graph-derived relationships.

- Consolidation (C1/C6): C4ModelService is the single render/analyze/store
  engine; the bridge delegates and FAILS LOUD on a render error instead of
  silently degrading. Duplicate inline generators removed.
- C2: real component relationships from the Knowledge Graph (AST import/call
  edges) replace the naming heuristic; project-scoped via a new KG basePath
  so repos outside cwd don't trip the path-traversal guard.
- C3: deterministic confidence gate (high/medium/low + reasons) on every
  diagram — surfaces the detector's known limits instead of hiding them.
- C4/C5: `aqe code c4` CLI + `qe/code/c4` MCP tool (generate/search),
  verified at MCP-CLI parity and through the protocol-server bridge.
- Search: generate persists embeddings (opt-in `enableC4Embeddings`, on for
  MCP) so `qe/code/c4 search` returns hits in the standard flow.
- Fixed pre-existing lint in touched files (require->import, unused catches).

Docs: ADR-112 + docs/guides/c4-architecture-diagrams.md. tsc + lint clean;
C4 surface fully green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-27 11:27:25 +00:00

53 lines
2.6 KiB
TypeScript

/**
* ADR-112 — C4 confidence gate unit tests.
*
* Deterministic gate that turns the detector's known limits into a surfaced
* signal. Covers the boundary conditions that flip the level.
*/
import { describe, it, expect } from 'vitest';
import {
assessC4Confidence,
C4_LOC_DEGRADE_THRESHOLD,
} from '../../../src/shared/c4-model/confidence';
describe('assessC4Confidence', () => {
it('should_return_low_with_a_verify_reason_when_no_components_detected', () => {
const a = assessC4Confidence({ componentsDetected: 0, relationshipsDetected: 0, externalSystemsDetected: 0, filesAnalyzed: 0 });
expect(a.level).toBe('low');
expect(a.score).toBe(0);
expect(a.reasons.join(' ')).toMatch(/empty|verify/i);
});
it('should_be_deterministic_for_identical_inputs', () => {
const inputs = { componentsDetected: 6, relationshipsDetected: 5, externalSystemsDetected: 2, filesAnalyzed: 40 };
expect(assessC4Confidence(inputs)).toEqual(assessC4Confidence(inputs));
});
it('should_rate_high_when_components_relationships_and_external_systems_are_rich', () => {
const a = assessC4Confidence({ componentsDetected: 8, relationshipsDetected: 8, externalSystemsDetected: 2, filesAnalyzed: 60 });
expect(a.level).toBe('high');
expect(a.score).toBeGreaterThanOrEqual(0.7);
});
it('should_penalize_missing_relationships_as_unverified_structure', () => {
const withRels = assessC4Confidence({ componentsDetected: 6, relationshipsDetected: 6, externalSystemsDetected: 0, filesAnalyzed: 30 });
const noRels = assessC4Confidence({ componentsDetected: 6, relationshipsDetected: 0, externalSystemsDetected: 0, filesAnalyzed: 30 });
expect(noRels.score).toBeLessThan(withRels.score);
expect(noRels.reasons.join(' ')).toMatch(/no relationships/i);
});
it('should_downgrade_large_repos_past_the_LOC_degrade_threshold', () => {
const small = assessC4Confidence({ componentsDetected: 8, relationshipsDetected: 8, externalSystemsDetected: 2, filesAnalyzed: 60, totalLoc: 5_000 });
const large = assessC4Confidence({ componentsDetected: 8, relationshipsDetected: 8, externalSystemsDetected: 2, filesAnalyzed: 60, totalLoc: C4_LOC_DEGRADE_THRESHOLD + 1 });
expect(large.score).toBeLessThan(small.score);
expect(large.reasons.join(' ')).toMatch(/large|draft/i);
});
it('should_always_append_a_draft_warning_when_not_high', () => {
const a = assessC4Confidence({ componentsDetected: 2, relationshipsDetected: 0, externalSystemsDetected: 0, filesAnalyzed: 4 });
expect(a.level).not.toBe('high');
expect(a.reasons.join(' ')).toMatch(/draft|verify/i);
});
});