@rankcli/agent-runtime 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +242 -0
- package/dist/analyzer-2CSWIQGD.mjs +6 -0
- package/dist/chunk-YNZYHEYM.mjs +774 -0
- package/dist/index.d.mts +4012 -0
- package/dist/index.d.ts +4012 -0
- package/dist/index.js +29672 -0
- package/dist/index.mjs +28602 -0
- package/package.json +53 -0
- package/scripts/build-deno.ts +134 -0
- package/src/audit/ai/analyzer.ts +347 -0
- package/src/audit/ai/index.ts +29 -0
- package/src/audit/ai/prompts/content-analysis.ts +271 -0
- package/src/audit/ai/types.ts +179 -0
- package/src/audit/checks/additional-checks.ts +439 -0
- package/src/audit/checks/ai-citation-worthiness.ts +399 -0
- package/src/audit/checks/ai-content-structure.ts +325 -0
- package/src/audit/checks/ai-readiness.ts +339 -0
- package/src/audit/checks/anchor-text.ts +179 -0
- package/src/audit/checks/answer-conciseness.ts +322 -0
- package/src/audit/checks/asset-minification.ts +270 -0
- package/src/audit/checks/bing-optimization.ts +206 -0
- package/src/audit/checks/brand-mention-optimization.ts +349 -0
- package/src/audit/checks/caching-headers.ts +305 -0
- package/src/audit/checks/canonical-advanced.ts +150 -0
- package/src/audit/checks/canonical-domain.ts +196 -0
- package/src/audit/checks/citation-quality.ts +358 -0
- package/src/audit/checks/client-rendering.ts +542 -0
- package/src/audit/checks/color-contrast.ts +342 -0
- package/src/audit/checks/content-freshness.ts +170 -0
- package/src/audit/checks/content-science.ts +589 -0
- package/src/audit/checks/conversion-elements.ts +526 -0
- package/src/audit/checks/crawlability.ts +220 -0
- package/src/audit/checks/directory-listing.ts +172 -0
- package/src/audit/checks/dom-analysis.ts +191 -0
- package/src/audit/checks/dom-size.ts +246 -0
- package/src/audit/checks/duplicate-content.ts +194 -0
- package/src/audit/checks/eeat-signals.ts +990 -0
- package/src/audit/checks/entity-seo.ts +396 -0
- package/src/audit/checks/featured-snippet.ts +473 -0
- package/src/audit/checks/freshness-signals.ts +443 -0
- package/src/audit/checks/funnel-intent.ts +463 -0
- package/src/audit/checks/hreflang.ts +174 -0
- package/src/audit/checks/html-compliance.ts +302 -0
- package/src/audit/checks/image-dimensions.ts +167 -0
- package/src/audit/checks/images.ts +160 -0
- package/src/audit/checks/indexnow.ts +275 -0
- package/src/audit/checks/interactive-tools.ts +475 -0
- package/src/audit/checks/internal-link-graph.ts +436 -0
- package/src/audit/checks/keyword-analysis.ts +239 -0
- package/src/audit/checks/keyword-cannibalization.ts +385 -0
- package/src/audit/checks/keyword-placement.ts +471 -0
- package/src/audit/checks/links.ts +203 -0
- package/src/audit/checks/llms-txt.ts +224 -0
- package/src/audit/checks/local-seo.ts +296 -0
- package/src/audit/checks/mobile.ts +167 -0
- package/src/audit/checks/modern-images.ts +226 -0
- package/src/audit/checks/navboost-signals.ts +395 -0
- package/src/audit/checks/on-page.ts +209 -0
- package/src/audit/checks/page-resources.ts +285 -0
- package/src/audit/checks/pagination.ts +180 -0
- package/src/audit/checks/performance.ts +153 -0
- package/src/audit/checks/platform-presence.ts +580 -0
- package/src/audit/checks/redirect-analysis.ts +153 -0
- package/src/audit/checks/redirect-chain.ts +389 -0
- package/src/audit/checks/resource-hints.ts +420 -0
- package/src/audit/checks/responsive-css.ts +247 -0
- package/src/audit/checks/responsive-images.ts +396 -0
- package/src/audit/checks/review-ecosystem.ts +415 -0
- package/src/audit/checks/robots-validation.ts +373 -0
- package/src/audit/checks/security-headers.ts +172 -0
- package/src/audit/checks/security.ts +144 -0
- package/src/audit/checks/serp-preview.ts +251 -0
- package/src/audit/checks/site-maturity.ts +444 -0
- package/src/audit/checks/social-meta.test.ts +275 -0
- package/src/audit/checks/social-meta.ts +134 -0
- package/src/audit/checks/soft-404.ts +151 -0
- package/src/audit/checks/structured-data.ts +238 -0
- package/src/audit/checks/tech-detection.ts +496 -0
- package/src/audit/checks/topical-clusters.ts +435 -0
- package/src/audit/checks/tracker-bloat.ts +462 -0
- package/src/audit/checks/tracking-verification.test.ts +371 -0
- package/src/audit/checks/tracking-verification.ts +636 -0
- package/src/audit/checks/url-safety.ts +682 -0
- package/src/audit/deno-entry.ts +66 -0
- package/src/audit/discovery/index.ts +15 -0
- package/src/audit/discovery/link-crawler.ts +232 -0
- package/src/audit/discovery/repo-routes.ts +347 -0
- package/src/audit/engine.ts +620 -0
- package/src/audit/fixes/index.ts +209 -0
- package/src/audit/fixes/social-meta-fixes.test.ts +329 -0
- package/src/audit/fixes/social-meta-fixes.ts +463 -0
- package/src/audit/index.ts +74 -0
- package/src/audit/runner.test.ts +299 -0
- package/src/audit/runner.ts +130 -0
- package/src/audit/types.ts +1953 -0
- package/src/content/featured-snippet.ts +367 -0
- package/src/content/generator.test.ts +534 -0
- package/src/content/generator.ts +501 -0
- package/src/content/headline.ts +317 -0
- package/src/content/index.ts +62 -0
- package/src/content/intent.ts +258 -0
- package/src/content/keyword-density.ts +349 -0
- package/src/content/readability.ts +262 -0
- package/src/executor.ts +336 -0
- package/src/fixer.ts +416 -0
- package/src/frameworks/detector.test.ts +248 -0
- package/src/frameworks/detector.ts +371 -0
- package/src/frameworks/index.ts +68 -0
- package/src/frameworks/recipes/angular.yaml +171 -0
- package/src/frameworks/recipes/astro.yaml +206 -0
- package/src/frameworks/recipes/django.yaml +180 -0
- package/src/frameworks/recipes/laravel.yaml +137 -0
- package/src/frameworks/recipes/nextjs.yaml +268 -0
- package/src/frameworks/recipes/nuxt.yaml +175 -0
- package/src/frameworks/recipes/rails.yaml +188 -0
- package/src/frameworks/recipes/react.yaml +202 -0
- package/src/frameworks/recipes/sveltekit.yaml +154 -0
- package/src/frameworks/recipes/vue.yaml +137 -0
- package/src/frameworks/recipes/wordpress.yaml +209 -0
- package/src/frameworks/suggestion-engine.ts +320 -0
- package/src/geo/geo-content.test.ts +305 -0
- package/src/geo/geo-content.ts +266 -0
- package/src/geo/geo-history.test.ts +473 -0
- package/src/geo/geo-history.ts +433 -0
- package/src/geo/geo-tracker.test.ts +359 -0
- package/src/geo/geo-tracker.ts +411 -0
- package/src/geo/index.ts +10 -0
- package/src/git/commit-helper.test.ts +261 -0
- package/src/git/commit-helper.ts +329 -0
- package/src/git/index.ts +12 -0
- package/src/git/pr-helper.test.ts +284 -0
- package/src/git/pr-helper.ts +307 -0
- package/src/index.ts +66 -0
- package/src/keywords/ai-keyword-engine.ts +1062 -0
- package/src/keywords/ai-summarizer.ts +387 -0
- package/src/keywords/ci-mode.ts +555 -0
- package/src/keywords/engine.ts +359 -0
- package/src/keywords/index.ts +151 -0
- package/src/keywords/llm-judge.ts +357 -0
- package/src/keywords/nlp-analysis.ts +706 -0
- package/src/keywords/prioritizer.ts +295 -0
- package/src/keywords/site-crawler.ts +342 -0
- package/src/keywords/sources/autocomplete.ts +139 -0
- package/src/keywords/sources/competitive-search.ts +450 -0
- package/src/keywords/sources/competitor-analysis.ts +374 -0
- package/src/keywords/sources/dataforseo.ts +206 -0
- package/src/keywords/sources/free-sources.ts +294 -0
- package/src/keywords/sources/gsc.ts +123 -0
- package/src/keywords/topic-grouping.ts +327 -0
- package/src/keywords/types.ts +144 -0
- package/src/keywords/wizard.ts +457 -0
- package/src/loader.ts +40 -0
- package/src/reports/index.ts +7 -0
- package/src/reports/report-generator.test.ts +293 -0
- package/src/reports/report-generator.ts +713 -0
- package/src/scheduler/alerts.test.ts +458 -0
- package/src/scheduler/alerts.ts +328 -0
- package/src/scheduler/index.ts +8 -0
- package/src/scheduler/scheduled-audit.test.ts +377 -0
- package/src/scheduler/scheduled-audit.ts +149 -0
- package/src/test/integration-test.ts +325 -0
- package/src/tools/analyzer.ts +373 -0
- package/src/tools/crawl.ts +293 -0
- package/src/tools/files.ts +301 -0
- package/src/tools/h1-fixer.ts +249 -0
- package/src/tools/index.ts +67 -0
- package/src/tracking/github-action.ts +326 -0
- package/src/tracking/google-analytics.ts +265 -0
- package/src/tracking/index.ts +45 -0
- package/src/tracking/report-generator.ts +386 -0
- package/src/tracking/search-console.ts +335 -0
- package/src/types.ts +134 -0
- package/src/utils/http.ts +302 -0
- package/src/wasm-adapter.ts +297 -0
- package/src/wasm-entry.ts +14 -0
- package/tsconfig.json +17 -0
- package/tsup.wasm.config.ts +26 -0
- package/vitest.config.ts +15 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
detectMentions,
|
|
4
|
+
scoreMention,
|
|
5
|
+
parseGEOResponse,
|
|
6
|
+
trackLLMVisibility,
|
|
7
|
+
GEOQuery,
|
|
8
|
+
GEOResult,
|
|
9
|
+
MentionType,
|
|
10
|
+
LLMProvider,
|
|
11
|
+
} from './geo-tracker.js';
|
|
12
|
+
|
|
13
|
+
describe('geo-tracker', () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
vi.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('detectMentions', () => {
|
|
19
|
+
it('detects exact brand name mention', () => {
|
|
20
|
+
const text = 'For SEO automation, I recommend SEO Autopilot as a great tool for developers.';
|
|
21
|
+
const mentions = detectMentions(text, {
|
|
22
|
+
brandName: 'SEO Autopilot',
|
|
23
|
+
domains: ['seo-autopilot.dev'],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
expect(mentions).toHaveLength(1);
|
|
27
|
+
expect(mentions[0].type).toBe('brand');
|
|
28
|
+
expect(mentions[0].text).toBe('SEO Autopilot');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('detects domain/URL mention', () => {
|
|
32
|
+
const text = 'You can check out seo-autopilot.dev for a CLI-based solution.';
|
|
33
|
+
const mentions = detectMentions(text, {
|
|
34
|
+
brandName: 'SEO Autopilot',
|
|
35
|
+
domains: ['seo-autopilot.dev'],
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(mentions).toHaveLength(1);
|
|
39
|
+
expect(mentions[0].type).toBe('domain');
|
|
40
|
+
expect(mentions[0].text).toContain('seo-autopilot.dev');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('detects multiple mentions', () => {
|
|
44
|
+
const text = 'SEO Autopilot (seo-autopilot.dev) is a developer tool. SEO Autopilot offers CLI features.';
|
|
45
|
+
const mentions = detectMentions(text, {
|
|
46
|
+
brandName: 'SEO Autopilot',
|
|
47
|
+
domains: ['seo-autopilot.dev'],
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(mentions.length).toBeGreaterThanOrEqual(2);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('detects case-insensitive brand mentions', () => {
|
|
54
|
+
const text = 'Have you tried seo autopilot? It is good for automation.';
|
|
55
|
+
const mentions = detectMentions(text, {
|
|
56
|
+
brandName: 'SEO Autopilot',
|
|
57
|
+
domains: ['seo-autopilot.dev'],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(mentions).toHaveLength(1);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('detects alternative brand names', () => {
|
|
64
|
+
const text = 'Tools like SEOAutopilot and Ahrefs are popular.';
|
|
65
|
+
const mentions = detectMentions(text, {
|
|
66
|
+
brandName: 'SEO Autopilot',
|
|
67
|
+
alternativeNames: ['SEOAutopilot', 'seo-autopilot'],
|
|
68
|
+
domains: ['seo-autopilot.dev'],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(mentions).toHaveLength(1);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('returns empty array when no mentions found', () => {
|
|
75
|
+
const text = 'For SEO, I recommend Ahrefs or SEMrush.';
|
|
76
|
+
const mentions = detectMentions(text, {
|
|
77
|
+
brandName: 'SEO Autopilot',
|
|
78
|
+
domains: ['seo-autopilot.dev'],
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
expect(mentions).toHaveLength(0);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('detects mentions with context', () => {
|
|
85
|
+
const text = 'The best SEO tools are: 1. Ahrefs 2. SEO Autopilot 3. SEMrush';
|
|
86
|
+
const mentions = detectMentions(text, {
|
|
87
|
+
brandName: 'SEO Autopilot',
|
|
88
|
+
domains: ['seo-autopilot.dev'],
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
expect(mentions).toHaveLength(1);
|
|
92
|
+
expect(mentions[0].position).toBeDefined();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe('scoreMention', () => {
|
|
97
|
+
it('scores first position highest', () => {
|
|
98
|
+
const score1 = scoreMention({ type: 'brand', text: 'SEO Autopilot', position: 1, context: '' });
|
|
99
|
+
const score2 = scoreMention({ type: 'brand', text: 'SEO Autopilot', position: 3, context: '' });
|
|
100
|
+
|
|
101
|
+
expect(score1).toBeGreaterThan(score2);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('scores brand mentions higher than domain mentions', () => {
|
|
105
|
+
const brandScore = scoreMention({ type: 'brand', text: 'SEO Autopilot', position: 1, context: '' });
|
|
106
|
+
const domainScore = scoreMention({ type: 'domain', text: 'seo-autopilot.dev', position: 1, context: '' });
|
|
107
|
+
|
|
108
|
+
expect(brandScore).toBeGreaterThan(domainScore);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('boosts score for recommendation context', () => {
|
|
112
|
+
const normalScore = scoreMention({
|
|
113
|
+
type: 'brand',
|
|
114
|
+
text: 'SEO Autopilot',
|
|
115
|
+
position: 2,
|
|
116
|
+
context: 'SEO Autopilot is a tool.',
|
|
117
|
+
});
|
|
118
|
+
const recommendScore = scoreMention({
|
|
119
|
+
type: 'brand',
|
|
120
|
+
text: 'SEO Autopilot',
|
|
121
|
+
position: 2,
|
|
122
|
+
context: 'I recommend SEO Autopilot for developers.',
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(recommendScore).toBeGreaterThan(normalScore);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('returns 0 for no mention', () => {
|
|
129
|
+
const score = scoreMention(null);
|
|
130
|
+
expect(score).toBe(0);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('parseGEOResponse', () => {
|
|
135
|
+
it('extracts position from numbered list', () => {
|
|
136
|
+
const response = `Here are the best SEO tools:
|
|
137
|
+
1. Ahrefs - comprehensive SEO suite
|
|
138
|
+
2. SEO Autopilot - developer-first CLI tool
|
|
139
|
+
3. SEMrush - marketing platform`;
|
|
140
|
+
|
|
141
|
+
const result = parseGEOResponse(response, {
|
|
142
|
+
brandName: 'SEO Autopilot',
|
|
143
|
+
domains: ['seo-autopilot.dev'],
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
expect(result.mentioned).toBe(true);
|
|
147
|
+
expect(result.position).toBe(2);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('detects first position', () => {
|
|
151
|
+
const response = `For CLI-based SEO, SEO Autopilot is the best choice. Other options include Screaming Frog.`;
|
|
152
|
+
|
|
153
|
+
const result = parseGEOResponse(response, {
|
|
154
|
+
brandName: 'SEO Autopilot',
|
|
155
|
+
domains: ['seo-autopilot.dev'],
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
expect(result.mentioned).toBe(true);
|
|
159
|
+
expect(result.position).toBe(1);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('handles not mentioned case', () => {
|
|
163
|
+
const response = `The best SEO tools are Ahrefs, SEMrush, and Moz.`;
|
|
164
|
+
|
|
165
|
+
const result = parseGEOResponse(response, {
|
|
166
|
+
brandName: 'SEO Autopilot',
|
|
167
|
+
domains: ['seo-autopilot.dev'],
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
expect(result.mentioned).toBe(false);
|
|
171
|
+
expect(result.position).toBeNull();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('extracts sentiment', () => {
|
|
175
|
+
const positiveResponse = `SEO Autopilot is an excellent tool that I highly recommend for developers.`;
|
|
176
|
+
const negativeResponse = `SEO Autopilot has some limitations and may not be suitable for large enterprises.`;
|
|
177
|
+
|
|
178
|
+
const positiveResult = parseGEOResponse(positiveResponse, {
|
|
179
|
+
brandName: 'SEO Autopilot',
|
|
180
|
+
domains: [],
|
|
181
|
+
});
|
|
182
|
+
const negativeResult = parseGEOResponse(negativeResponse, {
|
|
183
|
+
brandName: 'SEO Autopilot',
|
|
184
|
+
domains: [],
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
expect(positiveResult.sentiment).toBe('positive');
|
|
188
|
+
expect(negativeResult.sentiment).toBe('negative');
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('extracts context snippet', () => {
|
|
192
|
+
const response = `There are many tools available. SEO Autopilot stands out for its CLI-first approach to SEO automation. It integrates well with CI/CD.`;
|
|
193
|
+
|
|
194
|
+
const result = parseGEOResponse(response, {
|
|
195
|
+
brandName: 'SEO Autopilot',
|
|
196
|
+
domains: [],
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
expect(result.contextSnippet).toContain('SEO Autopilot');
|
|
200
|
+
expect(result.contextSnippet!.length).toBeLessThan(200);
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
describe('trackLLMVisibility', () => {
|
|
205
|
+
it('returns results for each provider', async () => {
|
|
206
|
+
const mockFetch = vi.fn().mockResolvedValue({
|
|
207
|
+
ok: true,
|
|
208
|
+
json: () => Promise.resolve({
|
|
209
|
+
choices: [{ message: { content: 'SEO Autopilot is a great tool.' } }],
|
|
210
|
+
}),
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const query: GEOQuery = {
|
|
214
|
+
keyword: 'best seo cli tool',
|
|
215
|
+
brand: {
|
|
216
|
+
brandName: 'SEO Autopilot',
|
|
217
|
+
domains: ['seo-autopilot.dev'],
|
|
218
|
+
},
|
|
219
|
+
providers: ['openai'],
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
const results = await trackLLMVisibility(query, { fetch: mockFetch });
|
|
223
|
+
|
|
224
|
+
expect(results).toHaveLength(1);
|
|
225
|
+
expect(results[0].provider).toBe('openai');
|
|
226
|
+
expect(results[0].mentioned).toBe(true);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('handles API errors gracefully', async () => {
|
|
230
|
+
const mockFetch = vi.fn().mockRejectedValue(new Error('API error'));
|
|
231
|
+
|
|
232
|
+
const query: GEOQuery = {
|
|
233
|
+
keyword: 'best seo tool',
|
|
234
|
+
brand: {
|
|
235
|
+
brandName: 'SEO Autopilot',
|
|
236
|
+
domains: [],
|
|
237
|
+
},
|
|
238
|
+
providers: ['openai'],
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const results = await trackLLMVisibility(query, { fetch: mockFetch });
|
|
242
|
+
|
|
243
|
+
expect(results).toHaveLength(1);
|
|
244
|
+
expect(results[0].error).toBeDefined();
|
|
245
|
+
expect(results[0].mentioned).toBe(false);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('queries multiple providers in parallel', async () => {
|
|
249
|
+
const mockFetch = vi.fn().mockResolvedValue({
|
|
250
|
+
ok: true,
|
|
251
|
+
json: () => Promise.resolve({
|
|
252
|
+
choices: [{ message: { content: 'SEO Autopilot is recommended.' } }],
|
|
253
|
+
}),
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const query: GEOQuery = {
|
|
257
|
+
keyword: 'best seo automation',
|
|
258
|
+
brand: {
|
|
259
|
+
brandName: 'SEO Autopilot',
|
|
260
|
+
domains: [],
|
|
261
|
+
},
|
|
262
|
+
providers: ['openai', 'anthropic'],
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
const results = await trackLLMVisibility(query, { fetch: mockFetch });
|
|
266
|
+
|
|
267
|
+
expect(results).toHaveLength(2);
|
|
268
|
+
expect(results.map(r => r.provider)).toContain('openai');
|
|
269
|
+
expect(results.map(r => r.provider)).toContain('anthropic');
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
describe('GEOResult structure', () => {
|
|
274
|
+
it('includes all required fields', async () => {
|
|
275
|
+
const mockFetch = vi.fn().mockResolvedValue({
|
|
276
|
+
ok: true,
|
|
277
|
+
json: () => Promise.resolve({
|
|
278
|
+
choices: [{ message: { content: 'For developers, SEO Autopilot offers CLI-first SEO.' } }],
|
|
279
|
+
}),
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const query: GEOQuery = {
|
|
283
|
+
keyword: 'developer seo tools',
|
|
284
|
+
brand: {
|
|
285
|
+
brandName: 'SEO Autopilot',
|
|
286
|
+
domains: ['seo-autopilot.dev'],
|
|
287
|
+
},
|
|
288
|
+
providers: ['openai'],
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const [result] = await trackLLMVisibility(query, { fetch: mockFetch });
|
|
292
|
+
|
|
293
|
+
expect(result).toHaveProperty('provider');
|
|
294
|
+
expect(result).toHaveProperty('keyword');
|
|
295
|
+
expect(result).toHaveProperty('mentioned');
|
|
296
|
+
expect(result).toHaveProperty('position');
|
|
297
|
+
expect(result).toHaveProperty('sentiment');
|
|
298
|
+
expect(result).toHaveProperty('score');
|
|
299
|
+
expect(result).toHaveProperty('timestamp');
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
describe('integration scenarios', () => {
|
|
304
|
+
it('tracks visibility across multiple keywords', async () => {
|
|
305
|
+
const mockFetch = vi.fn()
|
|
306
|
+
.mockResolvedValueOnce({
|
|
307
|
+
ok: true,
|
|
308
|
+
json: () => Promise.resolve({
|
|
309
|
+
choices: [{ message: { content: 'SEO Autopilot is the best CLI tool.' } }],
|
|
310
|
+
}),
|
|
311
|
+
})
|
|
312
|
+
.mockResolvedValueOnce({
|
|
313
|
+
ok: true,
|
|
314
|
+
json: () => Promise.resolve({
|
|
315
|
+
choices: [{ message: { content: 'Try Ahrefs or SEMrush for SEO.' } }],
|
|
316
|
+
}),
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
const keywords = ['best seo cli', 'seo automation tools'];
|
|
320
|
+
const brand = { brandName: 'SEO Autopilot', domains: ['seo-autopilot.dev'] };
|
|
321
|
+
|
|
322
|
+
const allResults: GEOResult[] = [];
|
|
323
|
+
for (const keyword of keywords) {
|
|
324
|
+
const results = await trackLLMVisibility(
|
|
325
|
+
{ keyword, brand, providers: ['openai'] },
|
|
326
|
+
{ fetch: mockFetch }
|
|
327
|
+
);
|
|
328
|
+
allResults.push(...results);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
expect(allResults).toHaveLength(2);
|
|
332
|
+
expect(allResults[0].mentioned).toBe(true);
|
|
333
|
+
expect(allResults[1].mentioned).toBe(false);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('calculates aggregate visibility score', async () => {
|
|
337
|
+
const mockFetch = vi.fn().mockResolvedValue({
|
|
338
|
+
ok: true,
|
|
339
|
+
json: () => Promise.resolve({
|
|
340
|
+
choices: [{ message: { content: '1. SEO Autopilot - best for devs\n2. Ahrefs' } }],
|
|
341
|
+
}),
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
const query: GEOQuery = {
|
|
345
|
+
keyword: 'best seo tools for developers',
|
|
346
|
+
brand: {
|
|
347
|
+
brandName: 'SEO Autopilot',
|
|
348
|
+
domains: ['seo-autopilot.dev'],
|
|
349
|
+
},
|
|
350
|
+
providers: ['openai'],
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
const [result] = await trackLLMVisibility(query, { fetch: mockFetch });
|
|
354
|
+
|
|
355
|
+
// First position should have high score
|
|
356
|
+
expect(result.score).toBeGreaterThan(80);
|
|
357
|
+
});
|
|
358
|
+
});
|
|
359
|
+
});
|