Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions scripts/gallery-audit/copilot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { spawnSync } from 'node:child_process';
import { readFileSync } from 'node:fs';
import { stripVTControlCharacters } from 'node:util';
import { jsonrepair } from 'jsonrepair';
import { normalizeUrl } from './normalize.mjs';

const CONFIDENCE = new Set(['high', 'medium', 'low']);
const NEW_VERDICTS = new Set(['include', 'review', 'exclude']);
Expand Down Expand Up @@ -84,6 +85,7 @@ function validateItem(item, expectedIndex, expectedUrl, kind) {
if (typeof item.relatedUrl !== 'string' || /\s/.test(item.relatedUrl)) throw new Error(`${kind} classification has invalid relatedUrl`);
const related = new URL(item.relatedUrl);
if (!['http:', 'https:'].includes(related.protocol) || (related.pathname.includes('&') && !related.search)) throw new Error(`${kind} classification has invalid relatedUrl`);
item.relatedUrl = normalizeUrl(item.relatedUrl);
}
item.url = expectedUrl;
}
Expand Down
68 changes: 68 additions & 0 deletions scripts/gallery-audit/test/audit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,74 @@ test('rejects empty Copilot classification criteria', () => {
assert.match(result.error, /invalid criteria/);
});

test('turns localized Copilot retirement URLs into a valid actionable proposal', () => {
const catalog = [
catalogEntry({ title: 'Vector search', source: 'https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/vector-search' }),
catalogEntry({ title: 'RAG applications', source: 'https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/rag' }),
];
const existingEntries = catalog.map((entry, catalogIndex) => ({ catalogIndex, url: entry.source }));
const classification = runCopilotClassification({
candidates: [],
existingEntries,
catalog,
execute: () => ({
status: 0,
stderr: '',
stdout: JSON.stringify({
newContent: [],
existingContent: existingEntries.map((entry, index) => ({
catalogIndex: entry.catalogIndex,
url: entry.url,
verdict: 'retire-proposed', confidence: 'high',
criteria: ['redirected to excluded product'],
evidence: 'Content now redirects to Azure DocumentDB.',
relatedUrl: `https://learn.microsoft.com/en-us/azure/documentdb/${index === 0 ? 'vector-search' : 'rag'}`,
})),
}),
}),
});

assert.equal(classification.status, 'complete');
const auditEntries = catalog.map((entry, catalogIndex) => ({
catalogIndex,
title: entry.title,
url: entry.source,
outcome: 'review',
reasonCodes: ['excluded-product'],
httpStatus: 200,
finalUrl: entry.source.replace('/azure/cosmos-db/mongodb/vcore/', '/azure/documentdb/'),
duplicates: { exact: [], normalized: [] },
classification: classification.classification.existingContent[catalogIndex],
}));
const result = planCatalogPromotion({
catalog,
retiredCatalog: [],
candidateReport: { candidates: [] },
auditReport: { entries: auditEntries },
sourcesDocument: { sources: [] },
policy,
now: new Date('2026-09-23T18:58:04Z'),
});
validatePromotionResult(result);

const actionableCount = result.additions.length + result.updates.length + result.retirements.length;
assert.equal(actionableCount, 2);
assert.equal(result.catalog.length, 0);
assert.equal(result.retiredCatalog.length, 2);
assert.deepEqual(result.retirements.map((entry) => entry.replacementUrl), [
'https://learn.microsoft.com/azure/documentdb/vector-search',
'https://learn.microsoft.com/azure/documentdb/rag',
]);
assert.notDeepEqual(result.catalog, catalog);

const summary = promotionMarkdown(result, '2026-09-23T18:58:04.000Z');
assert.match(summary, /Retirements: 2/);
assert.match(summary, /Reason: Content now redirects to Azure DocumentDB\./);
assert.match(summary, /Reason codes: excluded-product/);
assert.match(summary, /Criteria: redirected to excluded product/);
assert.match(summary, /edited issue body is the source of truth/);
});

test('rejects malformed retirement replacement URLs', () => {
const existingEntries = [{ catalogIndex: 0, url: 'https://example.com/old' }];
for (const relatedUrl of [
Expand Down
Loading