-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsource-maps-detect-agentic.test.ts
More file actions
201 lines (180 loc) · 5.43 KB
/
Copy pathsource-maps-detect-agentic.test.ts
File metadata and controls
201 lines (180 loc) · 5.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import {
coerceReport,
SOURCE_MAPS_TARGETS,
} from '@lib/programs/error-tracking-upload-source-maps/detect-agentic';
import { AUTOMATABLE_VARIANTS } from '@lib/programs/error-tracking-upload-source-maps/detect';
describe('SOURCE_MAPS_TARGETS precedence', () => {
const ids = SOURCE_MAPS_TARGETS.map((t) => t.id);
const rank = (id: string) => ids.indexOf(id);
it('covers every automatable variant exactly once', () => {
for (const variant of AUTOMATABLE_VARIANTS) {
expect(ids.filter((id) => id === variant)).toHaveLength(1);
}
});
it('ranks unsupported native guards ahead of the iOS target', () => {
expect(SOURCE_MAPS_TARGETS).toContainEqual({ id: 'ios', name: 'iOS' });
for (const nativeGuard of ['react-native', 'flutter', 'android']) {
expect(rank(nativeGuard)).toBeLessThan(rank('ios'));
}
expect(rank('ios')).toBeLessThan(rank('nextjs'));
});
it('ranks bundlers ahead of the generic React variant', () => {
// A React app built with Vite must resolve to `vite` (bundler-plugin
// upload), not the generic `react` posthog-cli path — the regression that
// shipped a posthog-cli setup into a Vite project.
for (const bundler of ['vite', 'webpack', 'rollup']) {
expect(rank(bundler)).toBeLessThan(rank('react'));
}
});
it('ranks opinionated frameworks ahead of bundlers', () => {
for (const fw of ['nextjs', 'nuxt', 'angular']) {
expect(rank(fw)).toBeLessThan(rank('vite'));
}
});
it('ranks the generic web fallback last among JS targets', () => {
for (const other of ['react', 'node', 'vite']) {
expect(rank(other)).toBeLessThan(rank('web'));
}
});
});
describe('coerceReport', () => {
it('marks a supported project with a PostHog SDK as instrumentable', () => {
const report = coerceReport({
repoType: 'single',
projects: [
{
path: '.',
framework: 'Next.js',
targetId: 'nextjs',
hasPostHog: true,
},
],
});
expect(report.repoType).toBe('single');
expect(report.projects).toHaveLength(1);
const p = report.projects[0];
expect(p.variant).toBe('nextjs');
expect(p.instrumentable).toBe(true);
expect(p.reason).toBeUndefined();
});
it('retains an iOS project with PostHog as instrumentable', () => {
const report = coerceReport({
repoType: 'single',
projects: [
{
path: '.',
framework: 'iOS',
targetId: 'ios',
hasPostHog: true,
},
],
});
expect(report.projects[0]).toEqual({
path: '.',
framework: 'iOS',
variant: 'ios',
hasPostHog: true,
instrumentable: true,
});
});
it('blocks an iOS project that has no PostHog SDK yet', () => {
const report = coerceReport({
repoType: 'single',
projects: [
{
path: '.',
framework: 'iOS',
targetId: 'ios',
hasPostHog: false,
},
],
});
expect(report.projects[0]).toEqual(
expect.objectContaining({
variant: 'ios',
hasPostHog: false,
instrumentable: false,
reason: expect.stringMatching(/no posthog sdk/i),
}),
);
});
it.each(['React Native', 'Expo', 'Flutter', 'Android'])(
'blocks a native %s project misclassified as iOS',
(framework) => {
const report = coerceReport({
repoType: 'single',
projects: [
{
path: '.',
framework,
targetId: 'ios',
hasPostHog: true,
},
],
});
expect(report.projects[0]).toEqual(
expect.objectContaining({
variant: null,
instrumentable: false,
reason: expect.stringMatching(/isn't supported/i),
}),
);
},
);
it('blocks a supported project that has no PostHog SDK yet', () => {
const report = coerceReport({
repoType: 'single',
projects: [
{
path: '.',
framework: 'Next.js',
targetId: 'nextjs',
hasPostHog: false,
},
],
});
const p = report.projects[0];
expect(p.instrumentable).toBe(false);
expect(p.reason).toMatch(/no posthog sdk/i);
});
it('clamps unknown / unsupported variants to null and blocks them', () => {
const report = coerceReport({
repoType: 'monorepo',
projects: [
// not in the automatable set
{
path: 'apps/mobile',
framework: 'React Native',
targetId: 'react-native',
hasPostHog: true,
},
// garbage value
{
path: 'apps/api',
framework: 'Rust',
targetId: 'rocket',
hasPostHog: true,
},
],
});
for (const p of report.projects) {
expect(p.variant).toBeNull();
expect(p.instrumentable).toBe(false);
expect(p.reason).toMatch(/isn't supported/i);
}
});
it('defaults missing / malformed fields safely', () => {
const report = coerceReport({ projects: [{}] });
expect(report.repoType).toBe('single');
const p = report.projects[0];
expect(p.path).toBe('.');
expect(p.framework).toBe('Unknown');
expect(p.variant).toBeNull();
expect(p.hasPostHog).toBe(false);
expect(p.instrumentable).toBe(false);
});
it('returns an empty report when projects is absent', () => {
expect(coerceReport({}).projects).toEqual([]);
expect(coerceReport(null).projects).toEqual([]);
});
});