@ansvar/singapore-law-mcp
Version:
Complete Singapore law database — 523 Acts, 28K+ provisions from Singapore Statutes Online (sso.agc.gov.sg) with full-text search, definitions, and citation support
62 lines • 2.35 kB
JavaScript
/**
* Drift detection for Singapore Law MCP.
*
* Checks if upstream SSO content has changed since last ingestion.
* Uses the golden-hashes.json fixture to verify content integrity.
*/
import { readFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const hashesPath = join(__dirname, '../fixtures/golden-hashes.json');
async function main() {
console.log('Singapore Law MCP — Drift Detection');
console.log('====================================\n');
const fixture = JSON.parse(readFileSync(hashesPath, 'utf-8'));
console.log(`Checking ${fixture.provisions.length} provisions...\n`);
let passed = 0;
let failed = 0;
let skipped = 0;
for (const hash of fixture.provisions) {
if (hash.expected_sha256 === 'COMPUTE_ON_FIRST_INGEST') {
console.log(` SKIP ${hash.id}: Not yet ingested`);
skipped++;
continue;
}
try {
const response = await fetch(hash.upstream_url, {
headers: { 'User-Agent': 'Singapore-Law-MCP/1.0 drift-detect' },
});
if (response.status !== 200) {
console.log(` WARN ${hash.id}: HTTP ${response.status}`);
failed++;
continue;
}
const body = await response.text();
if (hash.expected_snippet && body.toLowerCase().includes(hash.expected_snippet.toLowerCase())) {
console.log(` OK ${hash.id}: Snippet found`);
passed++;
}
else {
console.log(` DRIFT ${hash.id}: Expected snippet "${hash.expected_snippet}" not found`);
failed++;
}
}
catch (error) {
const msg = error instanceof Error ? error.message : String(error);
console.log(` ERROR ${hash.id}: ${msg}`);
failed++;
}
}
console.log(`\nResults: ${passed} passed, ${failed} failed, ${skipped} skipped`);
if (failed > 0) {
console.log('\nDrift detected! Data may need re-ingestion.');
process.exit(1);
}
}
main().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});
//# sourceMappingURL=drift-detect.js.map