mirror of
https://github.com/teamchong/pxpipe.git
synced 2026-07-22 02:02:51 +02:00
fix(factsheet): prioritize labeled assignments
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
/** ReDoS-safe extraction patterns (each global). Ordered most- to least-specific so the
|
||||
* longest, most-identifying tokens are kept first when the substring filter runs. */
|
||||
const PATTERNS: readonly RegExp[] = [
|
||||
/\b[A-Z][A-Z0-9_]{2,}=[^\s)"'<>]+/g, // semantic LABEL=value pair (preserve association)
|
||||
/\bhttps?:\/\/[^\s)"'<>]+/g, // URLs
|
||||
/\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/g, // UUID
|
||||
/(?:[\w@~+-]+)?(?:\/[\w.@+-]+)+\.[A-Za-z]\w{0,8}\b/g, // path with a file extension (multi-dot ok: .test.ts)
|
||||
@@ -62,10 +63,12 @@ const SHAPE_FLAG = /^--?[A-Za-z][\w-]+$/; // CLI flag
|
||||
const SHAPE_NUM = /^\d[\d,_]*$|^\d+\.\d+$/; // port / large or separated number / decimal
|
||||
const SHAPE_URL = /^https?:\/\//;
|
||||
const SHAPE_CAMEL = /^(?:[a-z]+|[A-Z][a-z0-9]+)(?:[A-Z][a-z0-9]*)+$/; // tokenLedgerShard / getUserById
|
||||
const SHAPE_ASSIGNMENT = /^[A-Z][A-Z0-9_]{2,}=\S+$/; // ACTIVE_MANIFEST=/path
|
||||
|
||||
/** Lower tier = higher keep-priority. Pure function of the token → deterministic. */
|
||||
function priorityTier(tok: string): 0 | 1 | 2 {
|
||||
if (
|
||||
SHAPE_ASSIGNMENT.test(tok) ||
|
||||
SHAPE_HEX.test(tok) ||
|
||||
SHAPE_UUID.test(tok) ||
|
||||
SHAPE_CONST.test(tok) ||
|
||||
|
||||
@@ -50,6 +50,27 @@ describe('factsheet extraction', () => {
|
||||
expect(extractFactSheetTokens(many).length).toBeLessThanOrEqual(96);
|
||||
});
|
||||
|
||||
it('prioritizes uppercase-labeled assignment values over anonymous hex log noise', () => {
|
||||
const noise = Array.from({ length: 180 }, (_, i) =>
|
||||
`trace8=${(0x10000000 + i * 7919).toString(16)} queue=${10000 + i}`,
|
||||
);
|
||||
const targetPath = '/srv/sol-pilot/releases/alpha-07/config/runtime-map.json';
|
||||
const text = [
|
||||
...noise.slice(0, 60),
|
||||
'DEPLOYMENT_FINGERPRINT=c7a1e90b4d2f',
|
||||
'RUNTIME_FIELD=retryBudgetSeconds',
|
||||
`ACTIVE_MANIFEST=${targetPath}`,
|
||||
'CONTROL_PORT=47831',
|
||||
...noise.slice(60),
|
||||
].join('\n');
|
||||
const toks = extractFactSheetTokens(text);
|
||||
expect(toks).toContain('DEPLOYMENT_FINGERPRINT=c7a1e90b4d2f');
|
||||
expect(toks).toContain('RUNTIME_FIELD=retryBudgetSeconds');
|
||||
expect(toks).toContain(`ACTIVE_MANIFEST=${targetPath}`);
|
||||
expect(toks).toContain('CONTROL_PORT=47831');
|
||||
expect(toks.length).toBeLessThanOrEqual(96);
|
||||
});
|
||||
|
||||
it('protects short high-consequence tokens from eviction by long URLs', () => {
|
||||
// 80 long doc-URLs (well over the 96-token budget) plus a short commit SHA and a port —
|
||||
// the exact shape that silently dropped the SHA a coding agent needed off the image.
|
||||
|
||||
Reference in New Issue
Block a user