generated-detection.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * Regression coverage for the generated-file detector that drives
  3. * symbol-disambiguation down-ranking. Locked here because the suffix
  4. * list is a contract: if a future edit drops `.pb.go`, the cosmos-sdk
  5. * trace endpoint regresses to the gRPC stub (see
  6. * `project_go_multi_module_audit` memory + the audit in #N/A).
  7. */
  8. import { describe, it, expect } from 'vitest';
  9. import { isGeneratedFile } from '../src/extraction/generated-detection';
  10. describe('isGeneratedFile', () => {
  11. it('classifies Go protobuf / gRPC / pulsar / mock outputs as generated', () => {
  12. expect(isGeneratedFile('api/cosmos/bank/v1beta1/tx_grpc.pb.go')).toBe(true);
  13. expect(isGeneratedFile('x/bank/types/tx.pb.go')).toBe(true);
  14. expect(isGeneratedFile('api/cosmos/bank/v1beta1/tx.pulsar.go')).toBe(true);
  15. // cosmos-sdk uses `<base>_mocks.go`; mockgen's default is `mock_<src>.go`;
  16. // many projects use `<base>_mock.go`. All three are mockgen output.
  17. expect(isGeneratedFile('x/auth/testutil/expected_keepers_mocks.go')).toBe(true);
  18. expect(isGeneratedFile('internal/foo_mock.go')).toBe(true);
  19. expect(isGeneratedFile('mock_keeper.go')).toBe(true);
  20. });
  21. it('does not flag the hand-written keeper as generated', () => {
  22. expect(isGeneratedFile('x/bank/keeper/msg_server.go')).toBe(false);
  23. expect(isGeneratedFile('x/bank/keeper/send.go')).toBe(false);
  24. });
  25. it('catches common cross-language codegen suffixes', () => {
  26. expect(isGeneratedFile('app/foo.generated.ts')).toBe(true);
  27. expect(isGeneratedFile('app/foo.generated.tsx')).toBe(true);
  28. expect(isGeneratedFile('proto/bar_pb2.py')).toBe(true);
  29. expect(isGeneratedFile('proto/bar_pb2_grpc.py')).toBe(true);
  30. expect(isGeneratedFile('lib/baz.pb.cc')).toBe(true);
  31. expect(isGeneratedFile('lib/baz.pb.h')).toBe(true);
  32. expect(isGeneratedFile('lib/quux.g.dart')).toBe(true);
  33. expect(isGeneratedFile('lib/quux.freezed.dart')).toBe(true);
  34. });
  35. it('leaves ordinary source files alone', () => {
  36. expect(isGeneratedFile('src/index.ts')).toBe(false);
  37. expect(isGeneratedFile('src/components/Foo.tsx')).toBe(false);
  38. expect(isGeneratedFile('lib/main.dart')).toBe(false);
  39. expect(isGeneratedFile('cmd/server/main.go')).toBe(false);
  40. expect(isGeneratedFile('app/db.py')).toBe(false);
  41. });
  42. });