mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-10 08:05:14 +02:00
fix(cli): add public ingest copy sanitizers
This commit is contained in:
parent
98371def48
commit
38ba88176c
2 changed files with 94 additions and 0 deletions
52
packages/cli/src/public-ingest-copy.test.ts
Normal file
52
packages/cli/src/public-ingest-copy.test.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
publicDatabaseIngestMessage,
|
||||
publicIngestOutputLine,
|
||||
publicQueryHistoryMessage,
|
||||
} from './public-ingest-copy.js';
|
||||
|
||||
describe('public ingest copy sanitizers', () => {
|
||||
it('maps database scan progress into schema-context wording', () => {
|
||||
expect(publicDatabaseIngestMessage('Preparing scan')).toBe('Preparing database ingest');
|
||||
expect(publicDatabaseIngestMessage('Inspecting database schema')).toBe('Reading database schema');
|
||||
expect(publicDatabaseIngestMessage('Writing schema artifacts')).toBe('Writing schema context');
|
||||
expect(publicDatabaseIngestMessage('Enriching schema metadata')).toBe('Building enriched schema context');
|
||||
});
|
||||
|
||||
it('maps database scan failure text into public database ingest wording', () => {
|
||||
expect(
|
||||
publicDatabaseIngestMessage(
|
||||
'KTX scan enrichment failed after structural scan completed: embedding service timed out',
|
||||
),
|
||||
).toBe('Database enrichment failed after schema context completed: embedding service timed out');
|
||||
expect(publicDatabaseIngestMessage('structural scan wrote partial artifacts')).toBe(
|
||||
'schema context wrote partial artifacts',
|
||||
);
|
||||
expect(publicDatabaseIngestMessage('scan results may be less complete')).toBe(
|
||||
'database context may be less complete',
|
||||
);
|
||||
});
|
||||
|
||||
it('maps query-history adapter progress into public wording', () => {
|
||||
expect(publicQueryHistoryMessage('Fetching source files for warehouse/historic-sql', 'warehouse')).toBe(
|
||||
'Fetching query history for warehouse',
|
||||
);
|
||||
expect(publicQueryHistoryMessage('Curating warehouse/historic-sql work units', 'warehouse')).toBe(
|
||||
'Curating warehouse query history work units',
|
||||
);
|
||||
expect(publicQueryHistoryMessage('historic SQL local ingest failed', 'warehouse')).toBe(
|
||||
'query history local ingest failed',
|
||||
);
|
||||
});
|
||||
|
||||
it('sanitizes captured public output lines across database and query-history internals', () => {
|
||||
expect(
|
||||
publicIngestOutputLine(
|
||||
'KTX scan enrichment failed after structural scan completed in raw-sources/warehouse/live-database/sync-1',
|
||||
),
|
||||
).toBe('Database enrichment failed after schema context completed in raw-sources/warehouse/database schema/sync-1');
|
||||
expect(publicIngestOutputLine('Historic SQL local ingest requires a configured reader')).toBe(
|
||||
'query history local ingest requires a configured reader',
|
||||
);
|
||||
});
|
||||
});
|
||||
42
packages/cli/src/public-ingest-copy.ts
Normal file
42
packages/cli/src/public-ingest-copy.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
function escapeRegExp(value: string): string {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
const DATABASE_INGEST_REPLACEMENTS: Array<[RegExp, string]> = [
|
||||
[/\bPreparing scan\b/gi, 'Preparing database ingest'],
|
||||
[/\bInspecting database schema\b/gi, 'Reading database schema'],
|
||||
[/\bWriting schema artifacts\b/gi, 'Writing schema context'],
|
||||
[/\bEnriching schema metadata\b/gi, 'Building enriched schema context'],
|
||||
[
|
||||
/\bKTX scan enrichment failed after structural scan completed\b/gi,
|
||||
'Database enrichment failed after schema context completed',
|
||||
],
|
||||
[/\bstructural scan\b/gi, 'schema context'],
|
||||
[/\benriched scan\b/gi, 'deep database ingest'],
|
||||
[/\bscan results\b/gi, 'database context'],
|
||||
];
|
||||
|
||||
export function publicDatabaseIngestMessage(message: string): string {
|
||||
return DATABASE_INGEST_REPLACEMENTS.reduce(
|
||||
(current, [pattern, replacement]) => current.replace(pattern, replacement),
|
||||
message,
|
||||
);
|
||||
}
|
||||
|
||||
export function publicQueryHistoryMessage(message: string, connectionId?: string): string {
|
||||
let current = message;
|
||||
if (connectionId && connectionId.length > 0) {
|
||||
const escapedConnectionId = escapeRegExp(connectionId);
|
||||
current = current
|
||||
.replace(
|
||||
new RegExp(`Fetching source files for ${escapedConnectionId}/historic-sql`, 'i'),
|
||||
`Fetching query history for ${connectionId}`,
|
||||
)
|
||||
.replace(`${connectionId}/historic-sql`, `${connectionId} query history`);
|
||||
}
|
||||
return current.replace(/\bhistoric-sql\b/g, 'query history').replace(/\bhistoric SQL\b/gi, 'query history');
|
||||
}
|
||||
|
||||
export function publicIngestOutputLine(line: string): string {
|
||||
return publicQueryHistoryMessage(publicDatabaseIngestMessage(line)).replace(/\blive-database\b/g, 'database schema');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue